content
stringlengths
23
1.05M
pragma License (Unrestricted); -- implementation unit required by compiler with Ada.Real_Time; with System.Parameters; with System.Task_Info; with System.Tasks; package System.Tasking.Stages is -- required for task by compiler (s-tassta.ads) procedure Create_Task ( Priority : Integer; -- range -1 .. Any_Priority'Last; Size : Parameters.Size_Type; Secondary_Stack_Size : Parameters.Size_Type; Task_Info : System.Task_Info.Task_Info_Type; CPU : Integer; Relative_Deadline : Ada.Real_Time.Time_Span; Domain : Dispatching_Domain_Access; Num_Entries : Task_Entry_Index; Master : Master_Level; State : Task_Procedure_Access; Discriminants : Address; -- discriminants and Task_Id Elaborated : not null Tasks.Boolean_Access; Chain : in out Activation_Chain; Task_Image : String; Created_Task : out Task_Id); -- (optionally?) required for task by compiler (s-tassta.ads) procedure Complete_Activation; procedure Complete_Task; -- required for task by compiler (s-tassta.ads) procedure Activate_Tasks ( Chain_Access : not null access Activation_Chain); -- required for dynamic allocation of task by compiler (s-tassta.ads) procedure Expunge_Unactivated_Tasks (Chain : in out Activation_Chain) is null; pragma Inline (Expunge_Unactivated_Tasks); -- [gcc-7] can not skip calling null procedure -- required for dynamic deallocation of task by compiler (s-tassta.ads) procedure Free_Task (T : Task_Id); -- required for built-in-place of task by compiler (s-tassta.ads) procedure Move_Activation_Chain ( From, To : Activation_Chain_Access; New_Master : Master_ID); -- required for abort statement by compiler (s-tassta.ads) procedure Abort_Tasks (Tasks : Task_List); -- required for 'Terminated by compiler (s-tassta.ads) function Terminated (T : Task_Id) return Boolean; -- task type be expanded below: -- -- _chain : aliased Activation_Chain; -- xE : aliased Boolean := False; -- xZ : Size_Type := Unspecified_Size; -- type xV (... discriminants ...) is limited record -- _task_id : Task_Id; -- end record; -- procedure xvip ( -- _init : in out xV; -- _master : Master_Id; -- _chain : in out Activation_Chain; -- _task_name : String; -- ... discriminant parameters ...); -- procedure xt (_task : access xV); -- -- xE := True; -- x1 : xV (... discriminants ...); -- _master : constant Master_Id := Current_Master.all; -- xS : String := ...task name...; -- Activate_Tasks (_chain'Access); -- -- by -fdump-tree-all, task type be expanded below: -- -- /* initialization */ -- xvip ( -- struct xV &_init, -- system__tasking__master_id _master, -- struct system__tasking__activation_chain & _chain, -- struct _task_name, -- ... discriminant parameters ...) -- { -- ... store discriminant parameters into _init ... -- _init->_task_id = 0B; -- _init->_task_id = system.tasking.stages.create_task ( -- -1, /* priority */ -- xZ, /* size */ -- 2, /* pragma Task_Info */ -- -1, /* CPU */ -- 0, /* deadline */ -- 0, /* entry count */ -- _master, -- xt, /* task body */ -- _init, -- &xE, /* in out, elaboration flag */ -- _chain, /* Activation_Chain */ -- _task_name, -- &_init->_task_id, /* out */ -- 0); /* entry names */ -- } -- -- /* body */ -- xt (struct xV * const _task) -- { -- if(_task == 0) { .gnat_rcheck_00 (...location...) }; -- try -- { -- system.soft_links.abort_undefer (); -- system.tasking.stages.complete_activation (); -- ... user code ... -- } -- finally -- { -- system.soft_links.abort_defer (); -- system.tasking.stages.complete_task (); -- system.soft_links.abort_undefer (); -- } -- } -- GDB knows, but hard to implement. -- procedure Task_Wrapper (Self_ID : Task_Id); end System.Tasking.Stages;
-- -*- Mode: Ada -*- -- Filename : ether-forms.adb -- Description : Abstraction around the form data returned from the SCGI client (HTTP server). -- Author : Luke A. Guest -- Created On : Tue May 1 18:04:04 2012 with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; with AWS.URL; package body Ether.Forms is package US renames Ada.Strings.Unbounded; use type US.Unbounded_String; -- Split up each component from the QUERY_STRING and insert it into a Form object. procedure Decode_Query (Data : in String) is type States is (Is_Key, Is_Value); -- Length : Natural := Natural'First; -- Total : Natural := Natural'First + 1; State : States := Is_Key; Key : US.Unbounded_String; Value : US.Unbounded_String; begin if Data = "" then return; end if; for Index in Data'Range loop if Data (Index) = '&' or Data (Index) = '=' then if State = Is_Key then State := Is_Value; Put_Line ("Key : " & AWS.URL.Decode (US.To_String (Key))); Key := US.Null_Unbounded_String; elsif State = Is_Value then State := Is_Key; Put_Line ("Value : " & AWS.URL.Decode (US.To_String (Value))); Value := US.Null_Unbounded_String; end if; else -- Append to the correct variable. if State = Is_Key then Key := Key & Data (Index); elsif State = Is_Value then Value := Value & Data (Index); end if; end if; end loop; -- At the end of the string, we need to also determine which was completed - should -- always be the value! if State = Is_Key then raise Form_Error with "[Ether] Forms always end with a value, not a key."; elsif State = Is_Value then Put_Line ("Value : " & US.To_String (Value)); Value := US.Null_Unbounded_String; end if; end Decode_Query; procedure Decode_Content (Data : access String) is begin -- Find the boundary string from CONTENT_TYPE. -- Each part starts with the boundary string, so for each part, read this in, 1 line. -- Next line should be "Content-Disposition: ..." -- Should contain "form-data;" followed by form field data, name and possible filename. -- If there is a filename, the next line will be "Content-Type: ..." -- Then follows field data or the file data. -- When searching for boundary, there are 2 dashes followed by the boundary marker. null; end Decode_Content; end Ether.Forms;
pragma Style_Checks (Off); -- This spec has been automatically generated from ATSAMD51G19A.svd pragma Restrictions (No_Elaboration_Code); with HAL; with System; package SAM_SVD.DAC is pragma Preelaborate; --------------- -- Registers -- --------------- -- Control A type DAC_CTRLA_Register is record -- Software Reset SWRST : Boolean := False; -- Enable DAC Controller ENABLE : Boolean := False; -- unspecified Reserved_2_7 : HAL.UInt6 := 16#0#; end record with Volatile_Full_Access, Object_Size => 8, Bit_Order => System.Low_Order_First; for DAC_CTRLA_Register use record SWRST at 0 range 0 .. 0; ENABLE at 0 range 1 .. 1; Reserved_2_7 at 0 range 2 .. 7; end record; -- Reference Selection for DAC0/1 type CTRLB_REFSELSelect is (-- External reference unbuffered VREFPU, -- Analog supply VDDANA, -- External reference buffered VREFPB, -- Internal bandgap reference INTREF) with Size => 2; for CTRLB_REFSELSelect use (VREFPU => 0, VDDANA => 1, VREFPB => 2, INTREF => 3); -- Control B type DAC_CTRLB_Register is record -- Differential mode enable DIFF : Boolean := False; -- Reference Selection for DAC0/1 REFSEL : CTRLB_REFSELSelect := SAM_SVD.DAC.VDDANA; -- unspecified Reserved_3_7 : HAL.UInt5 := 16#0#; end record with Volatile_Full_Access, Object_Size => 8, Bit_Order => System.Low_Order_First; for DAC_CTRLB_Register use record DIFF at 0 range 0 .. 0; REFSEL at 0 range 1 .. 2; Reserved_3_7 at 0 range 3 .. 7; end record; -- DAC_EVCTRL_STARTEI array type DAC_EVCTRL_STARTEI_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_EVCTRL_STARTEI type DAC_EVCTRL_STARTEI_Field (As_Array : Boolean := False) is record case As_Array is when False => -- STARTEI as a value Val : HAL.UInt2; when True => -- STARTEI as an array Arr : DAC_EVCTRL_STARTEI_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_EVCTRL_STARTEI_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_EVCTRL_EMPTYEO array type DAC_EVCTRL_EMPTYEO_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_EVCTRL_EMPTYEO type DAC_EVCTRL_EMPTYEO_Field (As_Array : Boolean := False) is record case As_Array is when False => -- EMPTYEO as a value Val : HAL.UInt2; when True => -- EMPTYEO as an array Arr : DAC_EVCTRL_EMPTYEO_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_EVCTRL_EMPTYEO_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_EVCTRL_INVEI array type DAC_EVCTRL_INVEI_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_EVCTRL_INVEI type DAC_EVCTRL_INVEI_Field (As_Array : Boolean := False) is record case As_Array is when False => -- INVEI as a value Val : HAL.UInt2; when True => -- INVEI as an array Arr : DAC_EVCTRL_INVEI_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_EVCTRL_INVEI_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_EVCTRL_RESRDYEO array type DAC_EVCTRL_RESRDYEO_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_EVCTRL_RESRDYEO type DAC_EVCTRL_RESRDYEO_Field (As_Array : Boolean := False) is record case As_Array is when False => -- RESRDYEO as a value Val : HAL.UInt2; when True => -- RESRDYEO as an array Arr : DAC_EVCTRL_RESRDYEO_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_EVCTRL_RESRDYEO_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- Event Control type DAC_EVCTRL_Register is record -- Start Conversion Event Input DAC 0 STARTEI : DAC_EVCTRL_STARTEI_Field := (As_Array => False, Val => 16#0#); -- Data Buffer Empty Event Output DAC 0 EMPTYEO : DAC_EVCTRL_EMPTYEO_Field := (As_Array => False, Val => 16#0#); -- Enable Invertion of DAC 0 input event INVEI : DAC_EVCTRL_INVEI_Field := (As_Array => False, Val => 16#0#); -- Result Ready Event Output 0 RESRDYEO : DAC_EVCTRL_RESRDYEO_Field := (As_Array => False, Val => 16#0#); end record with Volatile_Full_Access, Object_Size => 8, Bit_Order => System.Low_Order_First; for DAC_EVCTRL_Register use record STARTEI at 0 range 0 .. 1; EMPTYEO at 0 range 2 .. 3; INVEI at 0 range 4 .. 5; RESRDYEO at 0 range 6 .. 7; end record; -- DAC_INTENCLR_UNDERRUN array type DAC_INTENCLR_UNDERRUN_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_INTENCLR_UNDERRUN type DAC_INTENCLR_UNDERRUN_Field (As_Array : Boolean := False) is record case As_Array is when False => -- UNDERRUN as a value Val : HAL.UInt2; when True => -- UNDERRUN as an array Arr : DAC_INTENCLR_UNDERRUN_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_INTENCLR_UNDERRUN_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_INTENCLR_EMPTY array type DAC_INTENCLR_EMPTY_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_INTENCLR_EMPTY type DAC_INTENCLR_EMPTY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- EMPTY as a value Val : HAL.UInt2; when True => -- EMPTY as an array Arr : DAC_INTENCLR_EMPTY_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_INTENCLR_EMPTY_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_INTENCLR_RESRDY array type DAC_INTENCLR_RESRDY_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_INTENCLR_RESRDY type DAC_INTENCLR_RESRDY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- RESRDY as a value Val : HAL.UInt2; when True => -- RESRDY as an array Arr : DAC_INTENCLR_RESRDY_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_INTENCLR_RESRDY_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_INTENCLR_OVERRUN array type DAC_INTENCLR_OVERRUN_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_INTENCLR_OVERRUN type DAC_INTENCLR_OVERRUN_Field (As_Array : Boolean := False) is record case As_Array is when False => -- OVERRUN as a value Val : HAL.UInt2; when True => -- OVERRUN as an array Arr : DAC_INTENCLR_OVERRUN_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_INTENCLR_OVERRUN_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- Interrupt Enable Clear type DAC_INTENCLR_Register is record -- Underrun 0 Interrupt Enable UNDERRUN : DAC_INTENCLR_UNDERRUN_Field := (As_Array => False, Val => 16#0#); -- Data Buffer 0 Empty Interrupt Enable EMPTY : DAC_INTENCLR_EMPTY_Field := (As_Array => False, Val => 16#0#); -- Result 0 Ready Interrupt Enable RESRDY : DAC_INTENCLR_RESRDY_Field := (As_Array => False, Val => 16#0#); -- Overrun 0 Interrupt Enable OVERRUN : DAC_INTENCLR_OVERRUN_Field := (As_Array => False, Val => 16#0#); end record with Volatile_Full_Access, Object_Size => 8, Bit_Order => System.Low_Order_First; for DAC_INTENCLR_Register use record UNDERRUN at 0 range 0 .. 1; EMPTY at 0 range 2 .. 3; RESRDY at 0 range 4 .. 5; OVERRUN at 0 range 6 .. 7; end record; -- DAC_INTENSET_UNDERRUN array type DAC_INTENSET_UNDERRUN_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_INTENSET_UNDERRUN type DAC_INTENSET_UNDERRUN_Field (As_Array : Boolean := False) is record case As_Array is when False => -- UNDERRUN as a value Val : HAL.UInt2; when True => -- UNDERRUN as an array Arr : DAC_INTENSET_UNDERRUN_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_INTENSET_UNDERRUN_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_INTENSET_EMPTY array type DAC_INTENSET_EMPTY_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_INTENSET_EMPTY type DAC_INTENSET_EMPTY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- EMPTY as a value Val : HAL.UInt2; when True => -- EMPTY as an array Arr : DAC_INTENSET_EMPTY_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_INTENSET_EMPTY_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_INTENSET_RESRDY array type DAC_INTENSET_RESRDY_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_INTENSET_RESRDY type DAC_INTENSET_RESRDY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- RESRDY as a value Val : HAL.UInt2; when True => -- RESRDY as an array Arr : DAC_INTENSET_RESRDY_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_INTENSET_RESRDY_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_INTENSET_OVERRUN array type DAC_INTENSET_OVERRUN_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_INTENSET_OVERRUN type DAC_INTENSET_OVERRUN_Field (As_Array : Boolean := False) is record case As_Array is when False => -- OVERRUN as a value Val : HAL.UInt2; when True => -- OVERRUN as an array Arr : DAC_INTENSET_OVERRUN_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_INTENSET_OVERRUN_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- Interrupt Enable Set type DAC_INTENSET_Register is record -- Underrun 0 Interrupt Enable UNDERRUN : DAC_INTENSET_UNDERRUN_Field := (As_Array => False, Val => 16#0#); -- Data Buffer 0 Empty Interrupt Enable EMPTY : DAC_INTENSET_EMPTY_Field := (As_Array => False, Val => 16#0#); -- Result 0 Ready Interrupt Enable RESRDY : DAC_INTENSET_RESRDY_Field := (As_Array => False, Val => 16#0#); -- Overrun 0 Interrupt Enable OVERRUN : DAC_INTENSET_OVERRUN_Field := (As_Array => False, Val => 16#0#); end record with Volatile_Full_Access, Object_Size => 8, Bit_Order => System.Low_Order_First; for DAC_INTENSET_Register use record UNDERRUN at 0 range 0 .. 1; EMPTY at 0 range 2 .. 3; RESRDY at 0 range 4 .. 5; OVERRUN at 0 range 6 .. 7; end record; -- DAC_INTFLAG_UNDERRUN array type DAC_INTFLAG_UNDERRUN_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_INTFLAG_UNDERRUN type DAC_INTFLAG_UNDERRUN_Field (As_Array : Boolean := False) is record case As_Array is when False => -- UNDERRUN as a value Val : HAL.UInt2; when True => -- UNDERRUN as an array Arr : DAC_INTFLAG_UNDERRUN_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_INTFLAG_UNDERRUN_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_INTFLAG_EMPTY array type DAC_INTFLAG_EMPTY_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_INTFLAG_EMPTY type DAC_INTFLAG_EMPTY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- EMPTY as a value Val : HAL.UInt2; when True => -- EMPTY as an array Arr : DAC_INTFLAG_EMPTY_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_INTFLAG_EMPTY_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_INTFLAG_RESRDY array type DAC_INTFLAG_RESRDY_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_INTFLAG_RESRDY type DAC_INTFLAG_RESRDY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- RESRDY as a value Val : HAL.UInt2; when True => -- RESRDY as an array Arr : DAC_INTFLAG_RESRDY_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_INTFLAG_RESRDY_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_INTFLAG_OVERRUN array type DAC_INTFLAG_OVERRUN_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_INTFLAG_OVERRUN type DAC_INTFLAG_OVERRUN_Field (As_Array : Boolean := False) is record case As_Array is when False => -- OVERRUN as a value Val : HAL.UInt2; when True => -- OVERRUN as an array Arr : DAC_INTFLAG_OVERRUN_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_INTFLAG_OVERRUN_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- Interrupt Flag Status and Clear type DAC_INTFLAG_Register is record -- Result 0 Underrun UNDERRUN : DAC_INTFLAG_UNDERRUN_Field := (As_Array => False, Val => 16#0#); -- Data Buffer 0 Empty EMPTY : DAC_INTFLAG_EMPTY_Field := (As_Array => False, Val => 16#0#); -- Result 0 Ready RESRDY : DAC_INTFLAG_RESRDY_Field := (As_Array => False, Val => 16#0#); -- Result 0 Overrun OVERRUN : DAC_INTFLAG_OVERRUN_Field := (As_Array => False, Val => 16#0#); end record with Volatile_Full_Access, Object_Size => 8, Bit_Order => System.Low_Order_First; for DAC_INTFLAG_Register use record UNDERRUN at 0 range 0 .. 1; EMPTY at 0 range 2 .. 3; RESRDY at 0 range 4 .. 5; OVERRUN at 0 range 6 .. 7; end record; -- DAC_STATUS_READY array type DAC_STATUS_READY_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_STATUS_READY type DAC_STATUS_READY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- READY as a value Val : HAL.UInt2; when True => -- READY as an array Arr : DAC_STATUS_READY_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_STATUS_READY_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_STATUS_EOC array type DAC_STATUS_EOC_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_STATUS_EOC type DAC_STATUS_EOC_Field (As_Array : Boolean := False) is record case As_Array is when False => -- EOC as a value Val : HAL.UInt2; when True => -- EOC as an array Arr : DAC_STATUS_EOC_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_STATUS_EOC_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- Status type DAC_STATUS_Register is record -- Read-only. DAC 0 Startup Ready READY : DAC_STATUS_READY_Field; -- Read-only. DAC 0 End of Conversion EOC : DAC_STATUS_EOC_Field; -- unspecified Reserved_4_7 : HAL.UInt4; end record with Volatile_Full_Access, Object_Size => 8, Bit_Order => System.Low_Order_First; for DAC_STATUS_Register use record READY at 0 range 0 .. 1; EOC at 0 range 2 .. 3; Reserved_4_7 at 0 range 4 .. 7; end record; -- DAC_SYNCBUSY_DATA array type DAC_SYNCBUSY_DATA_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_SYNCBUSY_DATA type DAC_SYNCBUSY_DATA_Field (As_Array : Boolean := False) is record case As_Array is when False => -- DATA as a value Val : HAL.UInt2; when True => -- DATA as an array Arr : DAC_SYNCBUSY_DATA_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_SYNCBUSY_DATA_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- DAC_SYNCBUSY_DATABUF array type DAC_SYNCBUSY_DATABUF_Field_Array is array (0 .. 1) of Boolean with Component_Size => 1, Size => 2; -- Type definition for DAC_SYNCBUSY_DATABUF type DAC_SYNCBUSY_DATABUF_Field (As_Array : Boolean := False) is record case As_Array is when False => -- DATABUF as a value Val : HAL.UInt2; when True => -- DATABUF as an array Arr : DAC_SYNCBUSY_DATABUF_Field_Array; end case; end record with Unchecked_Union, Size => 2; for DAC_SYNCBUSY_DATABUF_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- Synchronization Busy type DAC_SYNCBUSY_Register is record -- Read-only. Software Reset SWRST : Boolean; -- Read-only. DAC Enable Status ENABLE : Boolean; -- Read-only. Data DAC 0 DATA : DAC_SYNCBUSY_DATA_Field; -- Read-only. Data Buffer DAC 0 DATABUF : DAC_SYNCBUSY_DATABUF_Field; -- unspecified Reserved_6_31 : HAL.UInt26; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for DAC_SYNCBUSY_Register use record SWRST at 0 range 0 .. 0; ENABLE at 0 range 1 .. 1; DATA at 0 range 2 .. 3; DATABUF at 0 range 4 .. 5; Reserved_6_31 at 0 range 6 .. 31; end record; -- Current Control type DACCTRL_CCTRLSelect is (-- 100kSPS CC100K, -- 500kSPS CC1M, -- 1MSPS CC12M) with Size => 2; for DACCTRL_CCTRLSelect use (CC100K => 0, CC1M => 1, CC12M => 2); -- Refresh period type DACCTRL_REFRESHSelect is (-- Do not Refresh REFRESH_0, -- Refresh every 30 us REFRESH_1, -- Refresh every 60 us REFRESH_2, -- Refresh every 90 us REFRESH_3, -- Refresh every 120 us REFRESH_4, -- Refresh every 150 us REFRESH_5, -- Refresh every 180 us REFRESH_6, -- Refresh every 210 us REFRESH_7, -- Refresh every 240 us REFRESH_8, -- Refresh every 270 us REFRESH_9, -- Refresh every 300 us REFRESH_10, -- Refresh every 330 us REFRESH_11, -- Refresh every 360 us REFRESH_12, -- Refresh every 390 us REFRESH_13, -- Refresh every 420 us REFRESH_14, -- Refresh every 450 us REFRESH_15) with Size => 4; for DACCTRL_REFRESHSelect use (REFRESH_0 => 0, REFRESH_1 => 1, REFRESH_2 => 2, REFRESH_3 => 3, REFRESH_4 => 4, REFRESH_5 => 5, REFRESH_6 => 6, REFRESH_7 => 7, REFRESH_8 => 8, REFRESH_9 => 9, REFRESH_10 => 10, REFRESH_11 => 11, REFRESH_12 => 12, REFRESH_13 => 13, REFRESH_14 => 14, REFRESH_15 => 15); -- Sampling Rate type DACCTRL_OSRSelect is (-- No Over Sampling OSR_1, -- 2x Over Sampling Ratio OSR_2, -- 4x Over Sampling Ratio OSR_4, -- 8x Over Sampling Ratio OSR_8, -- 16x Over Sampling Ratio OSR_16, -- 32x Over Sampling Ratio OSR_32) with Size => 3; for DACCTRL_OSRSelect use (OSR_1 => 0, OSR_2 => 1, OSR_4 => 2, OSR_8 => 3, OSR_16 => 4, OSR_32 => 5); -- DAC n Control type DAC_DACCTRL_Register is record -- Left Adjusted Data LEFTADJ : Boolean := False; -- Enable DAC0 ENABLE : Boolean := False; -- Current Control CCTRL : DACCTRL_CCTRLSelect := SAM_SVD.DAC.CC100K; -- unspecified Reserved_4_4 : HAL.Bit := 16#0#; -- Standalone Filter FEXT : Boolean := False; -- Run in Standby RUNSTDBY : Boolean := False; -- Dithering Mode DITHER : Boolean := False; -- Refresh period REFRESH : DACCTRL_REFRESHSelect := SAM_SVD.DAC.REFRESH_0; -- unspecified Reserved_12_12 : HAL.Bit := 16#0#; -- Sampling Rate OSR : DACCTRL_OSRSelect := SAM_SVD.DAC.OSR_1; end record with Volatile_Full_Access, Object_Size => 16, Bit_Order => System.Low_Order_First; for DAC_DACCTRL_Register use record LEFTADJ at 0 range 0 .. 0; ENABLE at 0 range 1 .. 1; CCTRL at 0 range 2 .. 3; Reserved_4_4 at 0 range 4 .. 4; FEXT at 0 range 5 .. 5; RUNSTDBY at 0 range 6 .. 6; DITHER at 0 range 7 .. 7; REFRESH at 0 range 8 .. 11; Reserved_12_12 at 0 range 12 .. 12; OSR at 0 range 13 .. 15; end record; -- DAC n Control type DAC_DACCTRL_Registers is array (0 .. 1) of DAC_DACCTRL_Register; -- DAC n Data -- DAC n Data type DAC_DATA_Registers is array (0 .. 1) of HAL.UInt16; -- DAC n Data Buffer -- DAC n Data Buffer type DAC_DATABUF_Registers is array (0 .. 1) of HAL.UInt16; -- Debug Control type DAC_DBGCTRL_Register is record -- Debug Run DBGRUN : Boolean := False; -- unspecified Reserved_1_7 : HAL.UInt7 := 16#0#; end record with Volatile_Full_Access, Object_Size => 8, Bit_Order => System.Low_Order_First; for DAC_DBGCTRL_Register use record DBGRUN at 0 range 0 .. 0; Reserved_1_7 at 0 range 1 .. 7; end record; -- Filter Result -- Filter Result type DAC_RESULT_Registers is array (0 .. 1) of HAL.UInt16; ----------------- -- Peripherals -- ----------------- -- Digital-to-Analog Converter type DAC_Peripheral is record -- Control A CTRLA : aliased DAC_CTRLA_Register; -- Control B CTRLB : aliased DAC_CTRLB_Register; -- Event Control EVCTRL : aliased DAC_EVCTRL_Register; -- Interrupt Enable Clear INTENCLR : aliased DAC_INTENCLR_Register; -- Interrupt Enable Set INTENSET : aliased DAC_INTENSET_Register; -- Interrupt Flag Status and Clear INTFLAG : aliased DAC_INTFLAG_Register; -- Status STATUS : aliased DAC_STATUS_Register; -- Synchronization Busy SYNCBUSY : aliased DAC_SYNCBUSY_Register; -- DAC n Control DACCTRL : aliased DAC_DACCTRL_Registers; -- DAC n Data DATA : aliased DAC_DATA_Registers; -- DAC n Data Buffer DATABUF : aliased DAC_DATABUF_Registers; -- Debug Control DBGCTRL : aliased DAC_DBGCTRL_Register; -- Filter Result RESULT : aliased DAC_RESULT_Registers; end record with Volatile; for DAC_Peripheral use record CTRLA at 16#0# range 0 .. 7; CTRLB at 16#1# range 0 .. 7; EVCTRL at 16#2# range 0 .. 7; INTENCLR at 16#4# range 0 .. 7; INTENSET at 16#5# range 0 .. 7; INTFLAG at 16#6# range 0 .. 7; STATUS at 16#7# range 0 .. 7; SYNCBUSY at 16#8# range 0 .. 31; DACCTRL at 16#C# range 0 .. 31; DATA at 16#10# range 0 .. 31; DATABUF at 16#14# range 0 .. 31; DBGCTRL at 16#18# range 0 .. 7; RESULT at 16#1C# range 0 .. 31; end record; -- Digital-to-Analog Converter DAC_Periph : aliased DAC_Peripheral with Import, Address => DAC_Base; end SAM_SVD.DAC;
-- { dg-do compile } -- { dg-options "-gnatws -O3" } with Discr21_Pkg; use Discr21_Pkg; package body Discr21 is type Index is new Natural range 0 .. 100; type Arr is array (Index range <> ) of Position; type Rec(Size : Index := 1) is record A : Arr(1 .. Size); end record; Data : Rec; function To_V(pos : Position) return VPosition is begin return To_Position(pos.x, pos.y, pos.z); end; procedure Read(Data : Rec) is pos : VPosition := To_V (Data.A(1)); begin null; end; procedure Test is begin Read (Data); end; end Discr21;
with ada.text_io;use ada.text_io; procedure binary is -- the digits in base 2 bit : array (0..1) of string (1..1) := ("0","1"); -- the conversion function itself function bin_image (n : Natural) return string is (if n<2 then bit (n) else bin_image (n/2)&bit(n mod 2)); -- the values we want to test test_values : array (1..3) of Natural := (5,50,9000); begin for test of test_values loop put_line ("Output for"&test'img&" is "&bin_image (test)); end loop; end binary;
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Slim.Message_Visiters; with Slim.Messages.BUTN; package Slim.Players.Common_Play_Visiters is type Visiter (Player : not null access Players.Player) is abstract new Slim.Message_Visiters.Visiter with null record; overriding procedure BUTN (Self : in out Visiter; Message : not null access Slim.Messages.BUTN.BUTN_Message); procedure Update_Display (Self : in out Player); end Slim.Players.Common_Play_Visiters;
with Ada.Text_IO; with Ada.Text_IO.Text_Streams; with Ada.Streams.Stream_IO; with Ada.Command_Line; with Ada.Directories; with Ada.Characters; with Ada.Characters.Latin_1; with GNAT.OS_Lib; with Ada; use Ada; procedure Ada_Formatter is -- Nano formatting tool for the Ada language. use Ada.Text_IO; use Ada.Text_IO.Text_Streams; use GNAT.OS_Lib; use Ada.Command_Line; use Ada.Characters.Latin_1; -- formatter gnatpp -nM --separate-loop-then -c4 -rnb Pretty_Print_Command : String_Access := Locate_Exec_On_Path ("gnatpp"); Pretty_Print_Arguments : GNAT.OS_Lib.Argument_List := (new String'("-nM"), new String'("--separate-loop-then"), new String'("-c4"), new String'("-rnb")); Launch_Status : Boolean := False; Pointless_Character : Character := ' '; function Command_Arguments return GNAT.OS_Lib.Argument_List is Command_Words : GNAT.OS_Lib.Argument_List (1 .. Argument_Count) := (others => null); begin for N in 1 .. Argument_Count loop Command_Words (N) := new String'(Argument (N)); end loop; return Command_Words; end Command_Arguments; procedure Launch (Command : String; Arguments : GNAT.OS_Lib.Argument_List) is Launch_Arguments : GNAT.OS_Lib.Argument_List := Arguments; begin GNAT.OS_Lib.Spawn (Command, Launch_Arguments, Launch_Status); end Launch; begin if Pretty_Print_Command /= null then Put_Line ("" & CR); Launch (Pretty_Print_Command.all, Pretty_Print_Arguments & Command_Arguments); if not Launch_Status then Set_Exit_Status (Failure); Put_Line ("" & CR); String'Write (Stream (Current_Output), "Press any key to return to Nano."); Character'Read (Stream (Current_Input), Pointless_Character); else Set_Exit_Status (Success); end if; end if; for I in Pretty_Print_Arguments'Range loop Free (Pretty_Print_Arguments (I)); end loop; end Ada_Formatter;
-- -- Copyright (C) 2015-2017 secunet Security Networks AG -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program 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. -- with Ada.Unchecked_Conversion; with HW.Debug; with GNAT.Source_Info; with HW.GFX.DP_Defs; use type HW.Word8; package body HW.GFX.DP_Info is procedure Read_Caps (Link : in out DP_Link; Port : in T; Success : out Boolean) is Data : DP_Defs.Aux_Payload; Length : DP_Defs.Aux_Payload_Length; Caps_Size : constant := 15; begin pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); Length := Caps_Size; Aux_Ch.Aux_Read (Port => Port, Address => 16#00000#, Length => Length, Data => Data, Success => Success); Success := Success and Length = Caps_Size; if Length = Caps_Size then Link.Receiver_Caps.Rev := Data (0); case Data (1) is when 16#06# => Link.Receiver_Caps.Max_Link_Rate := DP_Bandwidth_1_62; when 16#0a# => Link.Receiver_Caps.Max_Link_Rate := DP_Bandwidth_2_7; when 16#14# => Link.Receiver_Caps.Max_Link_Rate := DP_Bandwidth_5_4; when others => if Data (1) > 16#14# then Link.Receiver_Caps.Max_Link_Rate := DP_Bandwidth_5_4; else Link.Receiver_Caps.Max_Link_Rate := DP_Bandwidth_1_62; end if; end case; case Data (2) and 16#1f# is when 0 | 1 => Link.Receiver_Caps.Max_Lane_Count := DP_Lane_Count_1; when 2 | 3 => Link.Receiver_Caps.Max_Lane_Count := DP_Lane_Count_2; when others => Link.Receiver_Caps.Max_Lane_Count := DP_Lane_Count_4; end case; Link.Receiver_Caps.TPS3_Supported := (Data (2) and 16#40#) /= 0; Link.Receiver_Caps.Enhanced_Framing := (Data (2) and 16#80#) /= 0; Link.Receiver_Caps.No_Aux_Handshake := (Data (3) and 16#40#) /= 0; Link.Receiver_Caps.Aux_RD_Interval := Data (14); pragma Debug (Debug.New_Line); pragma Debug (Debug.Put_Line ("DPCD:")); pragma Debug (Debug.Put_Reg8 (" Rev ", Data (0))); pragma Debug (Debug.Put_Reg8 (" Max_Link_Rate ", Data (1))); pragma Debug (Debug.Put_Reg8 (" Max_Lane_Count ", Data (2) and 16#1f#)); pragma Debug (Debug.Put_Reg8 (" TPS3_Supported ", Data (2) and 16#40#)); pragma Debug (Debug.Put_Reg8 (" Enhanced_Framing", Data (2) and 16#80#)); pragma Debug (Debug.Put_Reg8 (" No_Aux_Handshake", Data (3) and 16#40#)); pragma Debug (Debug.Put_Reg8 (" Aux_RD_Interval ", Data (14))); pragma Debug (Debug.New_Line); end if; end Read_Caps; procedure Minimum_Lane_Count (Link : in out DP_Link; Mode : in Mode_Type; Success : out Boolean) with Depends => ((Link, Success) => (Link, Mode)) is function Link_Pixel_Per_Second (Link_Rate : DP_Bandwidth) return Positive with Post => Pos64 (Link_Pixel_Per_Second'Result) <= ((DP_Symbol_Rate_Type'Last * 8) / 3) / BPC_Type'First is begin -- Link_Rate is brutto with 8/10 bit symbols; three colors pragma Assert (Positive (DP_Symbol_Rate (Link_Rate)) <= (Positive'Last / 8) * 3); pragma Assert ((Int64 (DP_Symbol_Rate (Link_Rate)) * 8) / 3 >= Int64 (BPC_Type'Last)); return Positive (((Int64 (DP_Symbol_Rate (Link_Rate)) * 8) / 3) / Int64 (Mode.BPC)); end Link_Pixel_Per_Second; Count : Natural; begin Count := Link_Pixel_Per_Second (Link.Bandwidth); Count := (Positive (Mode.Dotclock) + Count - 1) / Count; Success := True; case Count is when 1 => Link.Lane_Count := DP_Lane_Count_1; when 2 => Link.Lane_Count := DP_Lane_Count_2; when 3 | 4 => Link.Lane_Count := DP_Lane_Count_4; when others => Success := False; end case; end Minimum_Lane_Count; procedure Preferred_Link_Setting (Link : in out DP_Link; Mode : in Mode_Type; Success : out Boolean) is begin Link.Bandwidth := Link.Receiver_Caps.Max_Link_Rate; Link.Enhanced_Framing := Link.Receiver_Caps.Enhanced_Framing; Minimum_Lane_Count (Link, Mode, Success); Success := Success and Link.Lane_Count <= Link.Receiver_Caps.Max_Lane_Count; pragma Debug (not Success, Debug.Put_Line ("Mode requirements exceed available bandwidth!")); end Preferred_Link_Setting; procedure Next_Link_Setting (Link : in out DP_Link; Mode : in Mode_Type; Success : out Boolean) is begin if Link.Bandwidth > DP_Bandwidth'First then Link.Bandwidth := DP_Bandwidth'Pred (Link.Bandwidth); Minimum_Lane_Count (Link, Mode, Success); Success := Success and Link.Lane_Count <= Link.Receiver_Caps.Max_Lane_Count; else Success := False; end if; end Next_Link_Setting; procedure Dump_Link_Setting (Link : DP_Link) is begin Debug.Put ("Trying DP settings: Symbol Rate = "); Debug.Put_Int32 (Int32 (DP_Symbol_Rate (Link.Bandwidth))); Debug.Put ("; Lane Count = "); Debug.Put_Int32 (Int32 (Lane_Count_As_Integer (Link.Lane_Count))); Debug.New_Line; Debug.New_Line; end Dump_Link_Setting; ---------------------------------------------------------------------------- procedure Calculate_M_N (Link : in DP_Link; Mode : in Mode_Type; Data_M : out M_Type; Data_N : out N_Type; Link_M : out M_Type; Link_N : out N_Type) is DATA_N_MAX : constant := 16#800000#; LINK_N_MAX : constant := 16#100000#; subtype Calc_M_Type is Int64 range 0 .. 2 ** 36; subtype Calc_N_Type is Int64 range 0 .. 2 ** 36; subtype N_Rounded_Type is Int64 range 0 .. Int64'Max (DATA_N_MAX, LINK_N_MAX); M : Calc_M_Type; N : Calc_N_Type; procedure Cancel_M_N (M : in out Calc_M_Type; N : in out Calc_N_Type; N_Max : in N_Rounded_Type) with Depends => ((M, N) => (M, N, N_max)), Pre => (N > 0 and M in 0 .. Calc_M_Type'Last / 2), Post => (M <= M_N_Max and N <= M_N_Max) is Orig_N : constant Calc_N_Type := N; function Round_N (N : Calc_N_Type) return N_Rounded_Type with Post => (Round_N'Result <= N * 2) is RN : Calc_N_Type; RN2 : Calc_N_Type := N_Max; begin loop RN := RN2; RN2 := RN2 / 2; exit when RN2 < N; pragma Loop_Invariant (RN2 = RN / 2 and RN2 in N .. N_Max); end loop; return RN; end Round_N; begin N := Round_N (N); -- The automatic provers need a little nudge here. pragma Assert (if M <= Calc_M_Type'Last/2 and N <= Orig_N * 2 and Orig_N > 0 and M > 0 then M * N / Orig_N <= Calc_M_Type'Last); pragma Annotate (GNATprove, False_Positive, "assertion might fail", "The property cannot be proven automatically. An Isabelle proof is included as an axiom"); M := M * N / Orig_N; -- This loop is never hit for sane values (i.e. M <= N) but -- we have to make sure returned values are always in range. while M > M_N_Max loop pragma Loop_Invariant (N <= M_N_Max); M := M / 2; N := N / 2; end loop; end Cancel_M_N; begin pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); pragma Assert (3 * Mode.BPC * Mode.Dotclock in Pos64); M := 3 * Mode.BPC * Mode.Dotclock; pragma Assert (8 * DP_Symbol_Rate (Link.Bandwidth) * Lane_Count_As_Integer (Link.Lane_Count) in Pos64); N := 8 * DP_Symbol_Rate (Link.Bandwidth) * Lane_Count_As_Integer (Link.Lane_Count); Cancel_M_N (M, N, DATA_N_MAX); Data_M := M; Data_N := N; ------------------------------------------------------------------- M := Pos64 (Mode.Dotclock); N := Pos64 (DP_Symbol_Rate (Link.Bandwidth)); Cancel_M_N (M, N, LINK_N_MAX); Link_M := M; Link_N := N; end Calculate_M_N; ---------------------------------------------------------------------------- procedure Read_Link_Status (Port : in T; Status : out Link_Status; Success : out Boolean) is subtype Status_Index is DP_Defs.Aux_Payload_Index range 0 .. 5; subtype Status_Buffer is Buffer (Status_Index); function Buffer_As_Status is new Ada.Unchecked_Conversion (Source => Status_Buffer, Target => Link_Status); Data : DP_Defs.Aux_Payload; Length : DP_Defs.Aux_Payload_Length; begin pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); Length := Status_Index'Last + 1; Aux_Ch.Aux_Read (Port => Port, Address => 16#00202#, Length => Length, Data => Data, Success => Success); Success := Success and Length = Status_Index'Last + 1; Status := Buffer_As_Status (Data (Status_Index)); end Read_Link_Status; function All_CR_Done (Status : Link_Status; Link : DP_Link) return Boolean is CR_Done : Boolean := True; begin for Lane in Lane_Index range 0 .. Lane_Index (Lane_Count_As_Integer (Link.Lane_Count) - 1) loop CR_Done := CR_Done and Status.Lanes (Lane).CR_Done; end loop; return CR_Done; end All_CR_Done; function All_EQ_Done (Status : Link_Status; Link : DP_Link) return Boolean is EQ_Done : Boolean := True; begin for Lane in Lane_Index range 0 .. Lane_Index (Lane_Count_As_Integer (Link.Lane_Count) - 1) loop EQ_Done := EQ_Done and Status.Lanes (Lane).CR_Done and Status.Lanes (Lane).Channel_EQ_Done and Status.Lanes (Lane).Symbol_Locked; end loop; return EQ_Done and Status.Interlane_Align_Done; end All_EQ_Done; function Max_Requested_VS (Status : Link_Status; Link : DP_Link) return DP_Voltage_Swing is VS : DP_Voltage_Swing := DP_Voltage_Swing'First; begin for Lane in Lane_Index range 0 .. Lane_Index (Lane_Count_As_Integer (Link.Lane_Count) - 1) loop if Status.Adjust_Requests (Lane).Voltage_Swing > VS then VS := Status.Adjust_Requests (Lane).Voltage_Swing; end if; end loop; return VS; end Max_Requested_VS; function Max_Requested_Emph (Status : Link_Status; Link : DP_Link) return DP_Pre_Emph is Emph : DP_Pre_Emph := DP_Pre_Emph'First; begin for Lane in Lane_Index range 0 .. Lane_Index (Lane_Count_As_Integer (Link.Lane_Count) - 1) loop if Status.Adjust_Requests (Lane).Pre_Emph > Emph then Emph := Status.Adjust_Requests (Lane).Pre_Emph; end if; end loop; return Emph; end Max_Requested_Emph; end HW.GFX.DP_Info;
-- Copyright 2008-2016 Free Software Foundation, Inc. -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 3 of the License, or -- (at your option) any later version. -- -- This program 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 -- along with this program. If not, see <http://www.gnu.org/licenses/>. procedure Comp_Bug is type Number_T (Exists : Boolean := False) is record case Exists is when True => Value : Natural range 0 .. 255; when False => null; end case; end record; pragma Pack (Number_T); X : Number_T; -- brobecker/2007-09-06: At the time when this issue (G904-017) was -- reported, the problem only reproduced if the variable was declared -- inside a function (in other words, stored on stack). Although -- the issue probably still existed when I tried moving this variable -- to a package spec, the symptoms inside GDB disappeared. begin X := (Exists => True, Value => 10); if X.Exists then -- STOP X.Value := X.Value + 1; end if; end Comp_Bug;
pragma License (Unrestricted); with System.Machine_Code; package Machine_Code renames System.Machine_Code; -- If supported.
with Ada.Text_IO, Ada.Directories, Ada.Command_Line, Ada.IO_Exceptions; use Ada.Text_IO; procedure Remove_Lines_From_File is Temporary: constant String := ".tmp"; begin if Ada.Command_Line.Argument_Count /= 3 then raise Constraint_Error; end if; declare Filename: String := Ada.Command_Line.Argument(1); First: Positive := Integer'Value(Ada.Command_Line.Argument(2)); Last: Natural := Integer'Value(Ada.Command_Line.Argument(3)) + First - 1; Input, Output: File_Type; Line_Number: Positive := 1; begin Open(Input, In_File, Filename); -- open original file for reading Create(Output, Out_File, Filename & Temporary); -- write to temp. file while not End_Of_File(Input) loop declare Line: String := Get_Line(Input); begin if Line_Number < First or else Line_Number > Last then Put_Line(Output, Line); end if; end; Line_Number := Line_Number + 1; end loop; Close(Input); Close(Output); Ada.Directories.Rename(Old_Name => Filename & Temporary, New_Name => Filename); end; exception when Constraint_Error | Ada.IO_Exceptions.Name_Error => Put_Line("usage: " & Ada.Command_Line.Command_Name & " <filename> <first> <length>"); Put_Line(" opens <filename> for reading and " & "<filename>" & Temporary & " for temporary writing"); Put_Line(" requires first > 0, length >= 0"); end Remove_Lines_From_File;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- A D A . E X C E P T I O N S -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2006, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT 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 GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, -- -- Boston, MA 02110-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. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This version of Ada.Exceptions is a full Ada 95 version, but lacks the -- additional definitions of Exception_Name returning Wide_[Wide_]String. -- It is used for building the compiler and the basic tools, since these -- builds may be done with bootstrap compilers that cannot handle these -- additions. The full version of Ada.Exceptions can be found in the files -- a-except-2005.ads/adb, and is used for all other builds where full Ada -- 2005 functionality is required. in particular, it is used for building -- run times on all targets. pragma Polling (Off); -- We must turn polling off for this unit, because otherwise we get -- elaboration circularities with System.Exception_Tables. with System; use System; with System.Standard_Library; use System.Standard_Library; with System.Soft_Links; use System.Soft_Links; package body Ada.Exceptions is pragma Suppress (All_Checks); -- We definitely do not want exceptions occurring within this unit, or -- we are in big trouble. If an exceptional situation does occur, better -- that it not be raised, since raising it can cause confusing chaos. ----------------------- -- Local Subprograms -- ----------------------- -- Note: the exported subprograms in this package body are called directly -- from C clients using the given external name, even though they are not -- technically visible in the Ada sense. procedure Process_Raise_Exception (E : Exception_Id); pragma No_Return (Process_Raise_Exception); -- This is the lowest level raise routine. It raises the exception -- referenced by Current_Excep.all in the TSD, without deferring abort -- (the caller must ensure that abort is deferred on entry). procedure To_Stderr (S : String); pragma Export (Ada, To_Stderr, "__gnat_to_stderr"); -- Little routine to output string to stderr that is also used -- in the tasking run time. procedure To_Stderr (C : Character); pragma Inline (To_Stderr); pragma Export (Ada, To_Stderr, "__gnat_to_stderr_char"); -- Little routine to output a character to stderr, used by some of -- the separate units below. package Exception_Data is --------------------------------- -- Exception messages routines -- --------------------------------- procedure Set_Exception_C_Msg (Id : Exception_Id; Msg1 : System.Address; Line : Integer := 0; Msg2 : System.Address := System.Null_Address); -- This routine is called to setup the exception referenced by the -- Current_Excep field in the TSD to contain the indicated Id value -- and message. Msg1 is a null terminated string which is generated -- as the exception message. If line is non-zero, then a colon and -- the decimal representation of this integer is appended to the -- message. When Msg2 is non-null, a space and this additional null -- terminated string is added to the message. procedure Set_Exception_Msg (Id : Exception_Id; Message : String); -- This routine is called to setup the exception referenced by the -- Current_Excep field in the TSD to contain the indicated Id value -- and message. Message is a string which is generated as the -- exception message. -------------------------------------- -- Exception information subprogram -- -------------------------------------- function Exception_Information (X : Exception_Occurrence) return String; -- The format of the exception information is as follows: -- -- Exception_Name: <exception name> (as in Exception_Name) -- Message: <message> (only if Exception_Message is empty) -- PID=nnnn (only if != 0) -- Call stack traceback locations: (only if at least one location) -- <0xyyyyyyyy 0xyyyyyyyy ...> (is recorded) -- -- The lines are separated by a ASCII.LF character. -- The nnnn is the partition Id given as decimal digits. -- The 0x... line represents traceback program counter locations, in -- execution order with the first one being the exception location. It -- is present only -- -- The Exception_Name and Message lines are omitted in the abort -- signal case, since this is not really an exception. -- !! If the format of the generated string is changed, please note -- !! that an equivalent modification to the routine String_To_EO must -- !! be made to preserve proper functioning of the stream attributes. --------------------------------------- -- Exception backtracing subprograms -- --------------------------------------- -- What is automatically output when exception tracing is on is the -- usual exception information with the call chain backtrace possibly -- tailored by a backtrace decorator. Modifying Exception_Information -- itself is not a good idea because the decorated output is completely -- out of control and would break all our code related to the streaming -- of exceptions. We then provide an alternative function to compute -- the possibly tailored output, which is equivalent if no decorator is -- currently set: function Tailored_Exception_Information (X : Exception_Occurrence) return String; -- Exception information to be output in the case of automatic tracing -- requested through GNAT.Exception_Traces. -- -- This is the same as Exception_Information if no backtrace decorator -- is currently in place. Otherwise, this is Exception_Information with -- the call chain raw addresses replaced by the result of a call to the -- current decorator provided with the call chain addresses. pragma Export (Ada, Tailored_Exception_Information, "__gnat_tailored_exception_information"); -- This is currently used by System.Tasking.Stages end Exception_Data; package Exception_Traces is use Exception_Data; -- Imports Tailored_Exception_Information ---------------------------------------------- -- Run-Time Exception Notification Routines -- ---------------------------------------------- -- These subprograms provide a common run-time interface to trigger the -- actions required when an exception is about to be propagated (e.g. -- user specified actions or output of exception information). They are -- exported to be usable by the Ada exception handling personality -- routine when the GCC 3 mechanism is used. procedure Notify_Handled_Exception; pragma Export (C, Notify_Handled_Exception, "__gnat_notify_handled_exception"); -- This routine is called for a handled occurrence is about to be -- propagated. procedure Notify_Unhandled_Exception; pragma Export (C, Notify_Unhandled_Exception, "__gnat_notify_unhandled_exception"); -- This routine is called when an unhandled occurrence is about to be -- propagated. procedure Unhandled_Exception_Terminate; pragma No_Return (Unhandled_Exception_Terminate); -- This procedure is called to terminate execution following an -- unhandled exception. The exception information, including -- traceback if available is output, and execution is then -- terminated. Note that at the point where this routine is -- called, the stack has typically been destroyed. end Exception_Traces; package Exception_Propagation is procedure Setup_Exception (Excep : EOA; Current : EOA; Reraised : Boolean := False); -- Dummy routine used to share a-exexda.adb, do nothing. end Exception_Propagation; package Stream_Attributes is -------------------------------- -- Stream attributes routines -- -------------------------------- function EId_To_String (X : Exception_Id) return String; function String_To_EId (S : String) return Exception_Id; -- Functions for implementing Exception_Id stream attributes function EO_To_String (X : Exception_Occurrence) return String; function String_To_EO (S : String) return Exception_Occurrence; -- Functions for implementing Exception_Occurrence stream -- attributes end Stream_Attributes; procedure Raise_Current_Excep (E : Exception_Id); pragma No_Return (Raise_Current_Excep); pragma Export (C, Raise_Current_Excep, "__gnat_raise_nodefer_with_msg"); -- This is a simple wrapper to Process_Raise_Exception. -- -- This external name for Raise_Current_Excep is historical, and probably -- should be changed but for now we keep it, because gdb and gigi know -- about it. procedure Raise_Exception_No_Defer (E : Exception_Id; Message : String := ""); pragma Export (Ada, Raise_Exception_No_Defer, "ada__exceptions__raise_exception_no_defer"); pragma No_Return (Raise_Exception_No_Defer); -- Similar to Raise_Exception, but with no abort deferral procedure Raise_With_Msg (E : Exception_Id); pragma No_Return (Raise_With_Msg); pragma Export (C, Raise_With_Msg, "__gnat_raise_with_msg"); -- Raises an exception with given exception id value. A message -- is associated with the raise, and has already been stored in the -- exception occurrence referenced by the Current_Excep in the TSD. -- Abort is deferred before the raise call. procedure Raise_With_Location_And_Msg (E : Exception_Id; F : System.Address; L : Integer; M : System.Address := System.Null_Address); pragma No_Return (Raise_With_Location_And_Msg); -- Raise an exception with given exception id value. A filename and line -- number is associated with the raise and is stored in the exception -- occurrence and in addition a string message M is appended to -- this (if M is not null). procedure Raise_Constraint_Error (File : System.Address; Line : Integer); pragma No_Return (Raise_Constraint_Error); pragma Export (C, Raise_Constraint_Error, "__gnat_raise_constraint_error"); -- Raise constraint error with file:line information procedure Raise_Constraint_Error_Msg (File : System.Address; Line : Integer; Msg : System.Address); pragma No_Return (Raise_Constraint_Error_Msg); pragma Export (C, Raise_Constraint_Error_Msg, "__gnat_raise_constraint_error_msg"); -- Raise constraint error with file:line + msg information procedure Raise_Program_Error (File : System.Address; Line : Integer); pragma No_Return (Raise_Program_Error); pragma Export (C, Raise_Program_Error, "__gnat_raise_program_error"); -- Raise program error with file:line information procedure Raise_Program_Error_Msg (File : System.Address; Line : Integer; Msg : System.Address); pragma No_Return (Raise_Program_Error_Msg); pragma Export (C, Raise_Program_Error_Msg, "__gnat_raise_program_error_msg"); -- Raise program error with file:line + msg information procedure Raise_Storage_Error (File : System.Address; Line : Integer); pragma No_Return (Raise_Storage_Error); pragma Export (C, Raise_Storage_Error, "__gnat_raise_storage_error"); -- Raise storage error with file:line information procedure Raise_Storage_Error_Msg (File : System.Address; Line : Integer; Msg : System.Address); pragma No_Return (Raise_Storage_Error_Msg); pragma Export (C, Raise_Storage_Error_Msg, "__gnat_raise_storage_error_msg"); -- Raise storage error with file:line + reason msg information -- The exception raising process and the automatic tracing mechanism rely -- on some careful use of flags attached to the exception occurrence. The -- graph below illustrates the relations between the Raise_ subprograms -- and identifies the points where basic flags such as Exception_Raised -- are initialized. -- -- (i) signs indicate the flags initialization points. R stands for Raise, -- W for With, and E for Exception. -- -- R_No_Msg R_E R_Pe R_Ce R_Se -- | | | | | -- +--+ +--+ +---+ | +---+ -- | | | | | -- R_E_No_Defer(i) R_W_Msg(i) R_W_Loc -- | | | | -- +------------+ | +-----------+ +--+ -- | | | | -- | | | Set_E_C_Msg(i) -- | | | -- Raise_Current_Excep procedure Reraise; pragma No_Return (Reraise); pragma Export (C, Reraise, "__gnat_reraise"); -- Reraises the exception referenced by the Current_Excep field of -- the TSD (all fields of this exception occurrence are set). Abort -- is deferred before the reraise operation. -- Save_Occurrence variations: As the management of the private data -- attached to occurrences is delicate, wether or not pointers to such -- data has to be copied in various situations is better made explicit. -- The following procedures provide an internal interface to help making -- this explicit. procedure Save_Occurrence_No_Private (Target : out Exception_Occurrence; Source : Exception_Occurrence); -- Copy all the components of Source to Target, except the -- Private_Data pointer. procedure Transfer_Occurrence (Target : Exception_Occurrence_Access; Source : Exception_Occurrence); pragma Export (C, Transfer_Occurrence, "__gnat_transfer_occurrence"); -- Called from System.Tasking.RendezVous.Exceptional_Complete_RendezVous -- to setup Target from Source as an exception to be propagated in the -- caller task. Target is expected to be a pointer to the fixed TSD -- occurrence for this task. ----------------------------- -- Run-Time Check Routines -- ----------------------------- -- These routines are called from the runtime to raise a specific -- exception with a reason message attached. The parameters are -- the file name and line number in each case. The names are keyed -- to the codes defined in Types.ads and a-types.h (for example, -- the name Rcheck_05 refers to the Reason whose Pos code is 5). procedure Rcheck_00 (File : System.Address; Line : Integer); procedure Rcheck_01 (File : System.Address; Line : Integer); procedure Rcheck_02 (File : System.Address; Line : Integer); procedure Rcheck_03 (File : System.Address; Line : Integer); procedure Rcheck_04 (File : System.Address; Line : Integer); procedure Rcheck_05 (File : System.Address; Line : Integer); procedure Rcheck_06 (File : System.Address; Line : Integer); procedure Rcheck_07 (File : System.Address; Line : Integer); procedure Rcheck_08 (File : System.Address; Line : Integer); procedure Rcheck_09 (File : System.Address; Line : Integer); procedure Rcheck_10 (File : System.Address; Line : Integer); procedure Rcheck_11 (File : System.Address; Line : Integer); procedure Rcheck_12 (File : System.Address; Line : Integer); procedure Rcheck_13 (File : System.Address; Line : Integer); procedure Rcheck_14 (File : System.Address; Line : Integer); procedure Rcheck_15 (File : System.Address; Line : Integer); procedure Rcheck_16 (File : System.Address; Line : Integer); procedure Rcheck_17 (File : System.Address; Line : Integer); procedure Rcheck_18 (File : System.Address; Line : Integer); procedure Rcheck_19 (File : System.Address; Line : Integer); procedure Rcheck_20 (File : System.Address; Line : Integer); procedure Rcheck_21 (File : System.Address; Line : Integer); procedure Rcheck_22 (File : System.Address; Line : Integer); procedure Rcheck_23 (File : System.Address; Line : Integer); procedure Rcheck_24 (File : System.Address; Line : Integer); procedure Rcheck_25 (File : System.Address; Line : Integer); procedure Rcheck_26 (File : System.Address; Line : Integer); procedure Rcheck_27 (File : System.Address; Line : Integer); procedure Rcheck_28 (File : System.Address; Line : Integer); procedure Rcheck_29 (File : System.Address; Line : Integer); procedure Rcheck_30 (File : System.Address; Line : Integer); procedure Rcheck_31 (File : System.Address; Line : Integer); procedure Rcheck_32 (File : System.Address; Line : Integer); pragma Export (C, Rcheck_00, "__gnat_rcheck_00"); pragma Export (C, Rcheck_01, "__gnat_rcheck_01"); pragma Export (C, Rcheck_02, "__gnat_rcheck_02"); pragma Export (C, Rcheck_03, "__gnat_rcheck_03"); pragma Export (C, Rcheck_04, "__gnat_rcheck_04"); pragma Export (C, Rcheck_05, "__gnat_rcheck_05"); pragma Export (C, Rcheck_06, "__gnat_rcheck_06"); pragma Export (C, Rcheck_07, "__gnat_rcheck_07"); pragma Export (C, Rcheck_08, "__gnat_rcheck_08"); pragma Export (C, Rcheck_09, "__gnat_rcheck_09"); pragma Export (C, Rcheck_10, "__gnat_rcheck_10"); pragma Export (C, Rcheck_11, "__gnat_rcheck_11"); pragma Export (C, Rcheck_12, "__gnat_rcheck_12"); pragma Export (C, Rcheck_13, "__gnat_rcheck_13"); pragma Export (C, Rcheck_14, "__gnat_rcheck_14"); pragma Export (C, Rcheck_15, "__gnat_rcheck_15"); pragma Export (C, Rcheck_16, "__gnat_rcheck_16"); pragma Export (C, Rcheck_17, "__gnat_rcheck_17"); pragma Export (C, Rcheck_18, "__gnat_rcheck_18"); pragma Export (C, Rcheck_19, "__gnat_rcheck_19"); pragma Export (C, Rcheck_20, "__gnat_rcheck_20"); pragma Export (C, Rcheck_21, "__gnat_rcheck_21"); pragma Export (C, Rcheck_22, "__gnat_rcheck_22"); pragma Export (C, Rcheck_23, "__gnat_rcheck_23"); pragma Export (C, Rcheck_24, "__gnat_rcheck_24"); pragma Export (C, Rcheck_25, "__gnat_rcheck_25"); pragma Export (C, Rcheck_26, "__gnat_rcheck_26"); pragma Export (C, Rcheck_27, "__gnat_rcheck_27"); pragma Export (C, Rcheck_28, "__gnat_rcheck_28"); pragma Export (C, Rcheck_29, "__gnat_rcheck_29"); pragma Export (C, Rcheck_30, "__gnat_rcheck_30"); pragma Export (C, Rcheck_31, "__gnat_rcheck_31"); pragma Export (C, Rcheck_32, "__gnat_rcheck_32"); -- None of these procedures ever returns (they raise an exception!). By -- using pragma No_Return, we ensure that any junk code after the call, -- such as normal return epilog stuff, can be eliminated). pragma No_Return (Rcheck_00); pragma No_Return (Rcheck_01); pragma No_Return (Rcheck_02); pragma No_Return (Rcheck_03); pragma No_Return (Rcheck_04); pragma No_Return (Rcheck_05); pragma No_Return (Rcheck_06); pragma No_Return (Rcheck_07); pragma No_Return (Rcheck_08); pragma No_Return (Rcheck_09); pragma No_Return (Rcheck_10); pragma No_Return (Rcheck_11); pragma No_Return (Rcheck_12); pragma No_Return (Rcheck_13); pragma No_Return (Rcheck_14); pragma No_Return (Rcheck_15); pragma No_Return (Rcheck_16); pragma No_Return (Rcheck_17); pragma No_Return (Rcheck_18); pragma No_Return (Rcheck_19); pragma No_Return (Rcheck_20); pragma No_Return (Rcheck_21); pragma No_Return (Rcheck_22); pragma No_Return (Rcheck_23); pragma No_Return (Rcheck_24); pragma No_Return (Rcheck_25); pragma No_Return (Rcheck_26); pragma No_Return (Rcheck_27); pragma No_Return (Rcheck_28); pragma No_Return (Rcheck_29); pragma No_Return (Rcheck_30); pragma No_Return (Rcheck_32); --------------------------------------------- -- Reason Strings for Run-Time Check Calls -- --------------------------------------------- -- These strings are null-terminated and are used by Rcheck_nn. The -- strings correspond to the definitions for Types.RT_Exception_Code. use ASCII; Rmsg_00 : constant String := "access check failed" & NUL; Rmsg_01 : constant String := "access parameter is null" & NUL; Rmsg_02 : constant String := "discriminant check failed" & NUL; Rmsg_03 : constant String := "divide by zero" & NUL; Rmsg_04 : constant String := "explicit raise" & NUL; Rmsg_05 : constant String := "index check failed" & NUL; Rmsg_06 : constant String := "invalid data" & NUL; Rmsg_07 : constant String := "length check failed" & NUL; Rmsg_08 : constant String := "null Exception_Id" & NUL; Rmsg_09 : constant String := "null-exclusion check failed" & NUL; Rmsg_10 : constant String := "overflow check failed" & NUL; Rmsg_11 : constant String := "partition check failed" & NUL; Rmsg_12 : constant String := "range check failed" & NUL; Rmsg_13 : constant String := "tag check failed" & NUL; Rmsg_14 : constant String := "access before elaboration" & NUL; Rmsg_15 : constant String := "accessibility check failed" & NUL; Rmsg_16 : constant String := "all guards closed" & NUL; Rmsg_17 : constant String := "duplicated entry address" & NUL; Rmsg_18 : constant String := "explicit raise" & NUL; Rmsg_19 : constant String := "finalize/adjust raised exception" & NUL; Rmsg_20 : constant String := "implicit return with No_Return" & NUL; Rmsg_21 : constant String := "misaligned address value" & NUL; Rmsg_22 : constant String := "missing return" & NUL; Rmsg_23 : constant String := "overlaid controlled object" & NUL; Rmsg_24 : constant String := "potentially blocking operation" & NUL; Rmsg_25 : constant String := "stubbed subprogram called" & NUL; Rmsg_26 : constant String := "unchecked union restriction" & NUL; Rmsg_27 : constant String := "illegal use of remote access-to-" & "class-wide type, see RM E.4(18)" & NUL; Rmsg_28 : constant String := "empty storage pool" & NUL; Rmsg_29 : constant String := "explicit raise" & NUL; Rmsg_30 : constant String := "infinite recursion" & NUL; Rmsg_31 : constant String := "object too large" & NUL; Rmsg_32 : constant String := "restriction violation" & NUL; ----------------------- -- Polling Interface -- ----------------------- type Unsigned is mod 2 ** 32; Counter : Unsigned := 0; pragma Warnings (Off, Counter); -- This counter is provided for convenience. It can be used in Poll to -- perform periodic but not systematic operations. procedure Poll is separate; -- The actual polling routine is separate, so that it can easily -- be replaced with a target dependent version. ------------------------------ -- Current_Target_Exception -- ------------------------------ function Current_Target_Exception return Exception_Occurrence is begin return Null_Occurrence; end Current_Target_Exception; ------------------- -- EId_To_String -- ------------------- function EId_To_String (X : Exception_Id) return String renames Stream_Attributes.EId_To_String; ------------------ -- EO_To_String -- ------------------ -- We use the null string to represent the null occurrence, otherwise -- we output the Exception_Information string for the occurrence. function EO_To_String (X : Exception_Occurrence) return String renames Stream_Attributes.EO_To_String; ------------------------ -- Exception_Identity -- ------------------------ function Exception_Identity (X : Exception_Occurrence) return Exception_Id is begin -- Note that the following test used to be here for the original -- Ada 95 semantics, but these were modified by AI-241 to require -- returning Null_Id instead of raising Constraint_Error. -- if X.Id = Null_Id then -- raise Constraint_Error; -- end if; return X.Id; end Exception_Identity; --------------------------- -- Exception_Information -- --------------------------- function Exception_Information (X : Exception_Occurrence) return String is begin if X.Id = Null_Id then raise Constraint_Error; end if; return Exception_Data.Exception_Information (X); end Exception_Information; ----------------------- -- Exception_Message -- ----------------------- function Exception_Message (X : Exception_Occurrence) return String is begin if X.Id = Null_Id then raise Constraint_Error; end if; return X.Msg (1 .. X.Msg_Length); end Exception_Message; -------------------- -- Exception_Name -- -------------------- function Exception_Name (Id : Exception_Id) return String is begin if Id = null then raise Constraint_Error; end if; return To_Ptr (Id.Full_Name) (1 .. Id.Name_Length - 1); end Exception_Name; function Exception_Name (X : Exception_Occurrence) return String is begin return Exception_Name (X.Id); end Exception_Name; --------------------------- -- Exception_Name_Simple -- --------------------------- function Exception_Name_Simple (X : Exception_Occurrence) return String is Name : constant String := Exception_Name (X); P : Natural; begin P := Name'Length; while P > 1 loop exit when Name (P - 1) = '.'; P := P - 1; end loop; -- Return result making sure lower bound is 1 declare subtype Rname is String (1 .. Name'Length - P + 1); begin return Rname (Name (P .. Name'Length)); end; end Exception_Name_Simple; -------------------- -- Exception_Data -- -------------------- package body Exception_Data is separate; -- This package can be easily dummied out if we do not want the -- basic support for exception messages (such as in Ada 83). package body Exception_Propagation is procedure Setup_Exception (Excep : EOA; Current : EOA; Reraised : Boolean := False) is pragma Warnings (Off, Excep); pragma Warnings (Off, Current); pragma Warnings (Off, Reraised); begin null; end Setup_Exception; end Exception_Propagation; ---------------------- -- Exception_Traces -- ---------------------- package body Exception_Traces is separate; -- Depending on the underlying support for IO the implementation -- will differ. Moreover we would like to dummy out this package -- in case we do not want any exception tracing support. This is -- why this package is separated. ----------------------- -- Stream Attributes -- ----------------------- package body Stream_Attributes is separate; -- This package can be easily dummied out if we do not want the -- support for streaming Exception_Ids and Exception_Occurrences. ----------------------------- -- Process_Raise_Exception -- ----------------------------- procedure Process_Raise_Exception (E : Exception_Id) is pragma Inspection_Point (E); -- This is so the debugger can reliably inspect the parameter Jumpbuf_Ptr : constant Address := Get_Jmpbuf_Address.all; Excep : constant EOA := Get_Current_Excep.all; procedure builtin_longjmp (buffer : Address; Flag : Integer); pragma No_Return (builtin_longjmp); pragma Import (C, builtin_longjmp, "_gnat_builtin_longjmp"); begin -- WARNING: There should be no exception handler for this body -- because this would cause gigi to prepend a setup for a new -- jmpbuf to the sequence of statements in case of built-in sjljl. -- We would then always get this new buf in Jumpbuf_Ptr instead of the -- one for the exception we are handling, which would completely break -- the whole design of this procedure. -- If the jump buffer pointer is non-null, transfer control using -- it. Otherwise announce an unhandled exception (note that this -- means that we have no finalizations to do other than at the outer -- level). Perform the necessary notification tasks in both cases. if Jumpbuf_Ptr /= Null_Address then if not Excep.Exception_Raised then Excep.Exception_Raised := True; Exception_Traces.Notify_Handled_Exception; end if; builtin_longjmp (Jumpbuf_Ptr, 1); else Exception_Traces.Notify_Unhandled_Exception; Exception_Traces.Unhandled_Exception_Terminate; end if; end Process_Raise_Exception; ---------------------------- -- Raise_Constraint_Error -- ---------------------------- procedure Raise_Constraint_Error (File : System.Address; Line : Integer) is begin Raise_With_Location_And_Msg (Constraint_Error_Def'Access, File, Line); end Raise_Constraint_Error; -------------------------------- -- Raise_Constraint_Error_Msg -- -------------------------------- procedure Raise_Constraint_Error_Msg (File : System.Address; Line : Integer; Msg : System.Address) is begin Raise_With_Location_And_Msg (Constraint_Error_Def'Access, File, Line, Msg); end Raise_Constraint_Error_Msg; ------------------------- -- Raise_Current_Excep -- ------------------------- procedure Raise_Current_Excep (E : Exception_Id) is pragma Inspection_Point (E); -- This is so the debugger can reliably inspect the parameter when -- inserting a breakpoint at the start of this procedure. Id : Exception_Id := E; pragma Volatile (Id); pragma Warnings (Off, Id); -- In order to provide support for breakpoints on unhandled exceptions, -- the debugger will also need to be able to inspect the value of E from -- another (inner) frame. So we need to make sure that if E is passed in -- a register, its value is also spilled on stack. For this, we store -- the parameter value in a local variable, and add a pragma Volatile to -- make sure it is spilled. The pragma Warnings (Off) is needed because -- the compiler knows that Id is not referenced and that this use of -- pragma Volatile is peculiar! begin Process_Raise_Exception (E); end Raise_Current_Excep; --------------------- -- Raise_Exception -- --------------------- procedure Raise_Exception (E : Exception_Id; Message : String := "") is begin if E /= null then Exception_Data.Set_Exception_Msg (E, Message); Abort_Defer.all; Raise_Current_Excep (E); end if; -- Note: if E is null, then we simply return, which is correct Ada 95 -- semantics. If we are operating in Ada 2005 mode, then the expander -- generates a raise Constraint_Error immediately following the call -- to provide the required Ada 2005 semantics (see AI-329). We do it -- this way to avoid having run time dependencies on the Ada version. return; end Raise_Exception; ---------------------------- -- Raise_Exception_Always -- ---------------------------- procedure Raise_Exception_Always (E : Exception_Id; Message : String := "") is begin Exception_Data.Set_Exception_Msg (E, Message); Abort_Defer.all; Raise_Current_Excep (E); end Raise_Exception_Always; ------------------------------- -- Raise_From_Signal_Handler -- ------------------------------- procedure Raise_From_Signal_Handler (E : Exception_Id; M : System.Address) is begin Exception_Data.Set_Exception_C_Msg (E, M); Abort_Defer.all; Process_Raise_Exception (E); end Raise_From_Signal_Handler; ------------------------- -- Raise_Program_Error -- ------------------------- procedure Raise_Program_Error (File : System.Address; Line : Integer) is begin Raise_With_Location_And_Msg (Program_Error_Def'Access, File, Line); end Raise_Program_Error; ----------------------------- -- Raise_Program_Error_Msg -- ----------------------------- procedure Raise_Program_Error_Msg (File : System.Address; Line : Integer; Msg : System.Address) is begin Raise_With_Location_And_Msg (Program_Error_Def'Access, File, Line, Msg); end Raise_Program_Error_Msg; ------------------------- -- Raise_Storage_Error -- ------------------------- procedure Raise_Storage_Error (File : System.Address; Line : Integer) is begin Raise_With_Location_And_Msg (Storage_Error_Def'Access, File, Line); end Raise_Storage_Error; ----------------------------- -- Raise_Storage_Error_Msg -- ----------------------------- procedure Raise_Storage_Error_Msg (File : System.Address; Line : Integer; Msg : System.Address) is begin Raise_With_Location_And_Msg (Storage_Error_Def'Access, File, Line, Msg); end Raise_Storage_Error_Msg; --------------------------------- -- Raise_With_Location_And_Msg -- --------------------------------- procedure Raise_With_Location_And_Msg (E : Exception_Id; F : System.Address; L : Integer; M : System.Address := System.Null_Address) is begin Exception_Data.Set_Exception_C_Msg (E, F, L, M); Abort_Defer.all; Raise_Current_Excep (E); end Raise_With_Location_And_Msg; -------------------- -- Raise_With_Msg -- -------------------- procedure Raise_With_Msg (E : Exception_Id) is Excep : constant EOA := Get_Current_Excep.all; begin Excep.Exception_Raised := False; Excep.Id := E; Excep.Num_Tracebacks := 0; Excep.Cleanup_Flag := False; Excep.Pid := Local_Partition_ID; Abort_Defer.all; Raise_Current_Excep (E); end Raise_With_Msg; -------------------------------------- -- Calls to Run-Time Check Routines -- -------------------------------------- procedure Rcheck_00 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_00'Address); end Rcheck_00; procedure Rcheck_01 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_01'Address); end Rcheck_01; procedure Rcheck_02 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_02'Address); end Rcheck_02; procedure Rcheck_03 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_03'Address); end Rcheck_03; procedure Rcheck_04 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_04'Address); end Rcheck_04; procedure Rcheck_05 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_05'Address); end Rcheck_05; procedure Rcheck_06 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_06'Address); end Rcheck_06; procedure Rcheck_07 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_07'Address); end Rcheck_07; procedure Rcheck_08 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_08'Address); end Rcheck_08; procedure Rcheck_09 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_09'Address); end Rcheck_09; procedure Rcheck_10 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_10'Address); end Rcheck_10; procedure Rcheck_11 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_11'Address); end Rcheck_11; procedure Rcheck_12 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_12'Address); end Rcheck_12; procedure Rcheck_13 (File : System.Address; Line : Integer) is begin Raise_Constraint_Error_Msg (File, Line, Rmsg_13'Address); end Rcheck_13; procedure Rcheck_14 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_14'Address); end Rcheck_14; procedure Rcheck_15 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_15'Address); end Rcheck_15; procedure Rcheck_16 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_16'Address); end Rcheck_16; procedure Rcheck_17 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_17'Address); end Rcheck_17; procedure Rcheck_18 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_18'Address); end Rcheck_18; procedure Rcheck_19 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_19'Address); end Rcheck_19; procedure Rcheck_20 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_20'Address); end Rcheck_20; procedure Rcheck_21 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_21'Address); end Rcheck_21; procedure Rcheck_22 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_22'Address); end Rcheck_22; procedure Rcheck_23 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_23'Address); end Rcheck_23; procedure Rcheck_24 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_24'Address); end Rcheck_24; procedure Rcheck_25 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_25'Address); end Rcheck_25; procedure Rcheck_26 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_26'Address); end Rcheck_26; procedure Rcheck_27 (File : System.Address; Line : Integer) is begin Raise_Program_Error_Msg (File, Line, Rmsg_27'Address); end Rcheck_27; procedure Rcheck_28 (File : System.Address; Line : Integer) is begin Raise_Storage_Error_Msg (File, Line, Rmsg_28'Address); end Rcheck_28; procedure Rcheck_29 (File : System.Address; Line : Integer) is begin Raise_Storage_Error_Msg (File, Line, Rmsg_29'Address); end Rcheck_29; procedure Rcheck_30 (File : System.Address; Line : Integer) is begin Raise_Storage_Error_Msg (File, Line, Rmsg_30'Address); end Rcheck_30; procedure Rcheck_31 (File : System.Address; Line : Integer) is begin Raise_Storage_Error_Msg (File, Line, Rmsg_31'Address); end Rcheck_31; procedure Rcheck_32 (File : System.Address; Line : Integer) is begin Raise_Storage_Error_Msg (File, Line, Rmsg_32'Address); end Rcheck_32; ------------- -- Reraise -- ------------- procedure Reraise is Excep : constant EOA := Get_Current_Excep.all; begin Abort_Defer.all; Raise_Current_Excep (Excep.Id); end Reraise; ------------------------ -- Reraise_Occurrence -- ------------------------ procedure Reraise_Occurrence (X : Exception_Occurrence) is begin if X.Id /= null then Abort_Defer.all; Save_Occurrence_No_Private (Get_Current_Excep.all.all, X); Raise_Current_Excep (X.Id); end if; end Reraise_Occurrence; ------------------------------- -- Reraise_Occurrence_Always -- ------------------------------- procedure Reraise_Occurrence_Always (X : Exception_Occurrence) is begin Abort_Defer.all; Save_Occurrence_No_Private (Get_Current_Excep.all.all, X); Raise_Current_Excep (X.Id); end Reraise_Occurrence_Always; --------------------------------- -- Reraise_Occurrence_No_Defer -- --------------------------------- procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence) is begin Save_Occurrence_No_Private (Get_Current_Excep.all.all, X); Raise_Current_Excep (X.Id); end Reraise_Occurrence_No_Defer; --------------------- -- Save_Occurrence -- --------------------- procedure Save_Occurrence (Target : out Exception_Occurrence; Source : Exception_Occurrence) is begin Save_Occurrence_No_Private (Target, Source); end Save_Occurrence; function Save_Occurrence (Source : Exception_Occurrence) return EOA is Target : constant EOA := new Exception_Occurrence; begin Save_Occurrence (Target.all, Source); return Target; end Save_Occurrence; -------------------------------- -- Save_Occurrence_No_Private -- -------------------------------- procedure Save_Occurrence_No_Private (Target : out Exception_Occurrence; Source : Exception_Occurrence) is begin Target.Id := Source.Id; Target.Msg_Length := Source.Msg_Length; Target.Num_Tracebacks := Source.Num_Tracebacks; Target.Pid := Source.Pid; Target.Cleanup_Flag := Source.Cleanup_Flag; Target.Msg (1 .. Target.Msg_Length) := Source.Msg (1 .. Target.Msg_Length); Target.Tracebacks (1 .. Target.Num_Tracebacks) := Source.Tracebacks (1 .. Target.Num_Tracebacks); end Save_Occurrence_No_Private; ------------------------- -- Transfer_Occurrence -- ------------------------- procedure Transfer_Occurrence (Target : Exception_Occurrence_Access; Source : Exception_Occurrence) is begin -- Setup Target as an exception to be propagated in the calling task -- (rendezvous-wise), taking care not to clobber the associated private -- data. Target is expected to be a pointer to the calling task's -- fixed TSD occurrence, which is very different from Get_Current_Excep -- here because this subprogram is called from the called task. Save_Occurrence_No_Private (Target.all, Source); end Transfer_Occurrence; ------------------- -- String_To_EId -- ------------------- function String_To_EId (S : String) return Exception_Id renames Stream_Attributes.String_To_EId; ------------------ -- String_To_EO -- ------------------ function String_To_EO (S : String) return Exception_Occurrence renames Stream_Attributes.String_To_EO; ------------------------------ -- Raise_Exception_No_Defer -- ------------------------------ procedure Raise_Exception_No_Defer (E : Exception_Id; Message : String := "") is begin Exception_Data.Set_Exception_Msg (E, Message); -- Do not call Abort_Defer.all, as specified by the spec Raise_Current_Excep (E); end Raise_Exception_No_Defer; --------------- -- To_Stderr -- --------------- procedure To_Stderr (C : Character) is type int is new Integer; procedure put_char_stderr (C : int); pragma Import (C, put_char_stderr, "put_char_stderr"); begin put_char_stderr (Character'Pos (C)); end To_Stderr; procedure To_Stderr (S : String) is begin for J in S'Range loop if S (J) /= ASCII.CR then To_Stderr (S (J)); end if; end loop; end To_Stderr; end Ada.Exceptions;
with Asis.Clauses; with Asis.Elements; package body Asis_Adapter.Element.Clauses is ------------ -- EXPORTED: ------------ procedure Do_Pre_Child_Processing (Element : in Asis.Element; State : in out Class) is Parent_Name : constant String := Module_Name; Module_Name : constant String := Parent_Name & ".Do_Pre_Child_Processing"; Result : a_nodes_h.Clause_Struct := a_nodes_h.Support.Default_Clause_Struct; Clause_Kind : constant Asis.Clause_Kinds := Asis.Elements.Clause_Kind (Element); -- Supporting procedures are in alphabetical order (except -- Add_Common_Items comes last): procedure Add_Clause_Names is begin Add_Element_List (This => State, Elements_In => Asis.Clauses.Clause_Names (Element), Dot_Label_Name => "Clause_Name", List_Out => Result.Clause_Names, Add_Edges => True); end; procedure Add_Component_Clause_Position is ID : constant a_nodes_h.Expression_ID := Get_Element_ID (Asis.Clauses.Component_Clause_Position (Element)); begin State.Add_To_Dot_Label_And_Edge ("Component_Clause_Position",ID); Result.Component_Clause_Position := ID; end; procedure Add_Component_Clause_Range is ID : constant a_nodes_h.Element_ID := Get_Element_ID (Asis.Clauses.Component_Clause_Range (Element)); begin State.Add_To_Dot_Label_And_Edge ("Component_Clause_Range", ID); Result.Component_Clause_Range := ID; end; procedure Add_Has_Limited is Value : constant Boolean := Asis.Elements.Has_Limited (Element); begin State.Add_To_Dot_Label ("Has_Limited", Value); Result.Has_Limited := a_nodes_h.Support.To_bool (Value); end; --Clause_Struct takes a Name_ID procedure Add_Representation_Clause_Name is ID : constant a_nodes_h.Name_ID := Get_Element_ID (Asis.Clauses.Representation_Clause_Name (Element)); begin State.Add_To_Dot_Label_And_Edge ("Representation_Clause_Name", ID); Result.Representation_Clause_Name := ID; end; -- END Field support ----------------------------------------------------------------------- -- BEGIN record support: function Representation_Clause return a_nodes_h.Representation_Clause_Struct is Parent_Name : constant String := Module_Name; Module_Name : constant String := Parent_Name & ".Representation_Clause"; Result : a_nodes_h.Representation_Clause_Struct := a_nodes_h.Support.Default_Representation_Clause_Struct; Representation_Clause_Kind : constant Asis.Representation_Clause_Kinds := Asis.Elements.Representation_Clause_Kind (Element); -- Supporting procedures are in alphabetical order (except -- Add_Common_Items comes last): procedure Add_Component_Clauses is begin Add_Element_List (This => State, Elements_In => Asis.Clauses.Component_Clauses (Element), Dot_Label_Name => "Component_Clauses", List_Out => Result.Component_Clauses, Add_Edges => True); end; procedure Add_Mod_Clause_Expression is ID : constant a_nodes_h.Expression_ID := Get_Element_ID (Asis.Clauses.Mod_Clause_Expression (Element)); begin State.Add_To_Dot_Label_And_Edge ("Mod_Clause_Expression", ID); Result.Mod_Clause_Expression := ID; end; procedure Add_Pragmas is begin Add_Element_List (This => State, Elements_In => Asis.Elements.Pragmas (Element), Dot_Label_Name => "Pragmas", List_Out => Result.Pragmas, Add_Edges => True); end; procedure Add_Representation_Clause_Expression is ID : constant a_nodes_h.Expression_ID := Get_Element_ID (Asis.Clauses.Representation_Clause_Expression (Element)); begin State.Add_To_Dot_Label_And_Edge ("Representation_Clause_Expression", ID); Result.Representation_Clause_Expression := ID; end; procedure Add_Representation_Clause_Name is ID : constant a_nodes_h.Name_ID := Get_Element_ID (Asis.Clauses.Representation_Clause_Name (Element)); begin State.Add_To_Dot_Label_And_Edge ("Representation_Clause_Name", ID); Result.Representation_Clause_Name := ID; end; procedure Add_Common_Items is begin State.Add_To_Dot_Label("Representation_Clause_Kind", Representation_Clause_Kind'Image); Result.Representation_Clause_Kind := anhS.To_Representation_Clause_Kinds (Representation_Clause_Kind); Add_Representation_Clause_Name; end Add_Common_Items; use all type Asis.Representation_Clause_Kinds; begin If Representation_Clause_Kind /= Not_A_Representation_Clause then Add_Common_Items; end if; case Representation_Clause_Kind is when Not_A_Representation_Clause => raise Internal_Error with Module_Name & " called with: " & Clause_Kind'Image; when An_Attribute_Definition_Clause => Add_Representation_Clause_Expression; when An_Enumeration_Representation_Clause => Add_Representation_Clause_Expression; when A_Record_Representation_Clause => Add_Pragmas; Add_Mod_Clause_Expression; Add_Component_Clauses; when An_At_Clause => Add_Representation_Clause_Expression; end case; return Result; end Representation_Clause; procedure Add_Common_Items is begin State.Add_To_Dot_Label ("Clause_Kind", Clause_Kind'Image); Result.Clause_Kind := anhS.To_Clause_Kinds (Clause_Kind); end Add_Common_Items; use all type Asis.Clause_Kinds; begin If Clause_Kind /= Not_A_Clause then Add_Common_Items; end if; case Clause_Kind is when Not_A_Clause => raise Internal_Error with Module_Name & " called with: " & Clause_Kind'Image; when A_Use_Package_Clause => Add_Clause_Names; when A_Use_Type_Clause => Add_Clause_Names; when A_Use_All_Type_Clause => -- A2012 Add_Clause_Names; when A_With_Clause => Add_Has_Limited; Add_Clause_Names; when A_Representation_Clause => Result.Representation_Clause := Representation_Clause; when A_Component_Clause => Add_Representation_Clause_Name; Add_Component_Clause_Position; Add_Component_Clause_Range; end case; State.A_Element.Element_Kind := a_nodes_h.A_Clause; State.A_Element.the_union.clause := Result; end Do_Pre_Child_Processing; end Asis_Adapter.Element.Clauses;
----------------------------------------------------------------------- -- GtkAda - Ada95 binding for the Gimp Toolkit -- -- -- -- Copyright (C) 1998-1999 -- -- Emmanuel Briot, Joel Brobecker and Arnaud Charlet -- -- Copyright (C) 2003 ACT Europe -- -- Copyright (C) 2010, AdaCore -- -- -- -- This library is free software; you can redistribute it and/or -- -- modify it under the terms of the GNU General Public -- -- License as published by the Free Software Foundation; either -- -- version 2 of the License, or (at your option) any later version. -- -- -- -- This library 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 along with this library; if not, write to the -- -- Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- -- Boston, MA 02111-1307, USA. -- -- -- ----------------------------------------------------------------------- with Glib; use Glib; with Gtk; use Gtk; with Gtk.Adjustment; use Gtk.Adjustment; with Gtk.Button; use Gtk.Button; with Gtk.Check_Button; use Gtk.Check_Button; with Gtk.Dialog; use Gtk.Dialog; with Gtk.Label; use Gtk.Label; with Gtk.Combo_Box_Text; use Gtk.Combo_Box_Text; with Gtk.gEntry; use Gtk.gEntry; with Gtk.Text_View; use Gtk.Text_View; with Gtk.Handlers; use Gtk.Handlers; with Gtk.Widget; use Gtk.Widget; with Gtk.Window; use Gtk.Window; with Interfaces.C.Strings; with Gtk.Notebook; use Gtk.Notebook; package Common_Gtk is -- This package is created to avoid the instantiation of the -- generic packages for callbacks. This provides a much smaller -- executable -- It also contains services that are used in 2 or more examples -- of testgtk. package Widget_Handler is new Handlers.Callback (Gtk_Widget_Record); package User_Widget_Handler is new Handlers.User_Callback (Gtk_Widget_Record, Gtk_Widget); package Label_Handler is new Handlers.Callback (Gtk_Label_Record); package Label_return_Handler is new Handlers.return_Callback (Gtk_Label_Record, Boolean); package Notebook_Cb is new Handlers.Callback (Gtk_Notebook_Record); procedure enable_bold_Tabs_for (the_Notebook : in gtk_Notebook); package comboBox_Text_Handler is new Handlers.Callback (Gtk_Combo_Box_Text_Record); package Adj_Handler is new Handlers.Callback (Gtk_Adjustment_Record); package Check_Handler is new Handlers.Callback (Gtk_Check_Button_Record); package Button_Handler is new Handlers.Callback (Gtk_Button_Record); package Entry_Handler is new Handlers.Callback (Gtk_Entry_Record); -- package Text_Handler is new Handlers.Callback (Gtk_Text_Record); package Textview_Handler is new Handlers.Callback (Gtk_Text_View_Record); type Gtk_Window_Access is access all Gtk_Window; package Destroy_Handler is new Handlers.User_Callback (Gtk_Window_Record, Gtk_Window_Access); procedure Destroy_Window (Win : access Gtk.Window.Gtk_Window_Record'Class; Ptr : Gtk_Window_Access); type Gtk_Dialog_Access is access all Gtk_Dialog; package Destroy_Dialog_Handler is new Handlers.User_Callback (Gtk_Dialog_Record, Gtk_Dialog_Access); procedure Destroy_Dialog (Win : access Gtk_Dialog_Record'Class; Ptr : Gtk_Dialog_Access); -- procedure Build_Option_Menu -- (Omenu : out Gtk.Option_Menu.Gtk_Option_Menu; -- Gr : in out Widget_SList.GSlist; -- Items : Chars_Ptr_Array; -- History : Gint; -- Cb : Widget_Handler.Marshallers.Void_Marshaller.Handler); -- -- Builds an option menu with the given list of items. -- -- If 'History' is in Items'Range, then item number 'History' -- -- will be set to active. function Image_Of (I : Gint) return String; -- Returns the image of the given Gint. The leading spaces are -- stripped. package ICS renames Interfaces.C.Strings; Book_Open_Xpm : ICS.chars_ptr_array := (ICS.New_String ("16 16 4 1"), ICS.New_String (" c None s None"), ICS.New_String (". c black"), ICS.New_String ("X c #808080"), ICS.New_String ("o c white"), ICS.New_String (" "), ICS.New_String (" .. "), ICS.New_String (" .Xo. ... "), ICS.New_String (" .Xoo. ..oo. "), ICS.New_String (" .Xooo.Xooo... "), ICS.New_String (" .Xooo.oooo.X. "), ICS.New_String (" .Xooo.Xooo.X. "), ICS.New_String (" .Xooo.oooo.X. "), ICS.New_String (" .Xooo.Xooo.X. "), ICS.New_String (" .Xooo.oooo.X. "), ICS.New_String (" .Xoo.Xoo..X. "), ICS.New_String (" .Xo.o..ooX. "), ICS.New_String (" .X..XXXXX. "), ICS.New_String (" ..X....... "), ICS.New_String (" .. "), ICS.New_String (" ")); Book_Closed_Xpm : ICS.chars_ptr_array := (ICS.New_String ("16 16 6 1"), ICS.New_String (" c None s None"), ICS.New_String (". c black"), ICS.New_String ("X c red"), ICS.New_String ("o c yellow"), ICS.New_String ("O c #808080"), ICS.New_String ("# c white"), ICS.New_String (" "), ICS.New_String (" .. "), ICS.New_String (" ..XX. "), ICS.New_String (" ..XXXXX. "), ICS.New_String (" ..XXXXXXXX. "), ICS.New_String (".ooXXXXXXXXX. "), ICS.New_String ("..ooXXXXXXXXX. "), ICS.New_String (".X.ooXXXXXXXXX. "), ICS.New_String (".XX.ooXXXXXX.. "), ICS.New_String (" .XX.ooXXX..#O "), ICS.New_String (" .XX.oo..##OO. "), ICS.New_String (" .XX..##OO.. "), ICS.New_String (" .X.#OO.. "), ICS.New_String (" ..O.. "), ICS.New_String (" .. "), ICS.New_String (" ")); Mini_Page_Xpm : ICS.chars_ptr_array := (ICS.New_String ("16 16 4 1"), ICS.New_String (" c None s None"), ICS.New_String (". c black"), ICS.New_String ("X c white"), ICS.New_String ("O c #808080"), ICS.New_String (" "), ICS.New_String (" ....... "), ICS.New_String (" .XXXXX.. "), ICS.New_String (" .XoooX.X. "), ICS.New_String (" .XXXXX.... "), ICS.New_String (" .XooooXoo.o "), ICS.New_String (" .XXXXXXXX.o "), ICS.New_String (" .XooooooX.o "), ICS.New_String (" .XXXXXXXX.o "), ICS.New_String (" .XooooooX.o "), ICS.New_String (" .XXXXXXXX.o "), ICS.New_String (" .XooooooX.o "), ICS.New_String (" .XXXXXXXX.o "), ICS.New_String (" ..........o "), ICS.New_String (" oooooooooo "), ICS.New_String (" ")); Gtk_Mini_Xpm : ICS.chars_ptr_array := (ICS.New_String ("15 20 17 1"), ICS.New_String (" c None"), ICS.New_String (". c #14121F"), ICS.New_String ("+ c #278828"), ICS.New_String ("@ c #9B3334"), ICS.New_String ("# c #284C72"), ICS.New_String ("$ c #24692A"), ICS.New_String ("% c #69282E"), ICS.New_String ("& c #37C539"), ICS.New_String ("* c #1D2F4D"), ICS.New_String ("= c #6D7076"), ICS.New_String ("- c #7D8482"), ICS.New_String ("; c #E24A49"), ICS.New_String ("> c #515357"), ICS.New_String (", c #9B9C9B"), ICS.New_String ("' c #2FA232"), ICS.New_String (") c #3CE23D"), ICS.New_String ("! c #3B6CCB"), ICS.New_String (" "), ICS.New_String (" ***> "), ICS.New_String (" >.*!!!* "), ICS.New_String (" ***....#*= "), ICS.New_String (" *!*.!!!**!!# "), ICS.New_String (" .!!#*!#*!!!!# "), ICS.New_String (" @%#!.##.*!!$& "), ICS.New_String (" @;%*!*.#!#')) "), ICS.New_String (" @;;@%!!*$&)'' "), ICS.New_String (" @%.%@%$'&)$+' "), ICS.New_String (" @;...@$'*'*)+ "), ICS.New_String (" @;%..@$+*.')$ "), ICS.New_String (" @;%%;;$+..$)# "), ICS.New_String (" @;%%;@$$$'.$# "), ICS.New_String (" %;@@;;$$+))&* "), ICS.New_String (" %;;;@+$&)&* "), ICS.New_String (" %;;@'))+> "), ICS.New_String (" %;@'&# "), ICS.New_String (" >%$$ "), ICS.New_String (" >= ")); end Common_Gtk;
-- Ahven Unit Test Library -- -- Copyright (c) 2007-2009 Tero Koskinen <tero.koskinen@iki.fi> -- -- Permission to use, copy, modify, and distribute this software for any -- purpose with or without fee is hereby granted, provided that the above -- copyright notice and this permission notice appear in all copies. -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- package Ahven is Max_String_Len : constant := 160 * 10; -- SCz 2012-09-04. Max length of messages multiplied by 10 for exception traceback. Max_Long_String_Len : constant := 1024; Assertion_Error : exception; -- Exception, raised when Assert fails. Test_Skipped_Error : exception; -- Exception, raised when test is skipped procedure Assert (Condition : Boolean; Message : String); -- If Condition is false, Assert raises Assertion_Error -- with given Message. generic type Data_Type is private; with function Image (Item : Data_Type) return String is <>; procedure Assert_Equal (Actual : Data_Type; Expected : Data_Type; Message : String); -- If Expected /= Actual, Assert raises Assertion_Error -- with given Message + represenation of expected and acutal values procedure Fail (Message : String); -- Fail always raises Assertion_Error with given Message. procedure Skip (Message : String); -- Skip always raises Test_Skipped_Error with given Message. end Ahven;
-- Ada_GUI implementation based on Gnoga. Adapted 2021 -- -- -- GNOGA - The GNU Omnificent GUI for Ada -- -- -- -- G N O G A . G U I . B A S E -- -- -- -- B o d y -- -- -- -- -- -- Copyright (C) 2014 David Botton -- -- -- -- This library 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 3, or (at your option) any -- -- later version. This library 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. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are -- -- granted additional permissions described in the GCC Runtime Library -- -- Exception, version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- 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. -- -- -- -- For more information please go to http://www.gnoga.com -- ------------------------------------------------------------------------------ with Ada.Exceptions; with Ada.Strings.Fixed; with Ada.Unchecked_Deallocation; with Ada_GUI.Gnoga.Server.Connection; package body Ada_GUI.Gnoga.Gui is Mouse_Event_Script : constant String := "(e.clientX - e.target.getBoundingClientRect().left) + '|' + " & "(e.clientY - e.target.getBoundingClientRect().top) + '|' + " & "e.screenX + '|' + " & "e.screenY + '|' + e.which + '|' + e.altKey + '|' + " & "e.ctrlKey + '|' + e.shiftKey + '|' + e.metaKey + '|'"; -- e.buttons would be better but not supported currently outside -- of firefox and would always return 0 on Mac so using e.which. -- The use of offsetLeft and offsetTop is to correct the X and Y -- to the actual X,Y of the target. Keyboard_Event_Script : constant String := "e.keyCode + '|' + e.charCode + '|' + e.altKey + '|' + e.ctrlKey + '|'" & " + e.shiftKey + '|' + e.metaKey + '|'"; ---------------- -- Initialize -- ---------------- overriding procedure Initialize (Object : in out Base_Type) is begin Gnoga.Server.Connection.New_Unique_ID (Object.Unique_ID); end Initialize; -------------- -- Finalize -- -------------- overriding procedure Finalize (Object : in out Base_Type) is begin Object.Detach_From_Message_Queue; if not Gnoga.Server.Connection.Shutting_Down and Gnoga.Server.Connection.Valid (Object.Connection_ID) then if Object.Connection_ID /= No_Connection then if Object.ID_Type = Gnoga_ID then begin Gnoga.Server.Connection.Execute_Script (Object.Connection_ID, "delete gnoga['" & Object.ID & "'];"); exception when E : Gnoga.Server.Connection.Connection_Error => -- Socket error to browser Log ("Error connection " & Object.ID & " socket error to browser."); Log (Ada.Exceptions.Exception_Information (E)); end; end if; Object.Connection_ID := No_Connection; -- Cannot call Object.Parent (null); because the parent may be finalized Object.Parent_Object := null; end if; end if; exception when E : others => Log ("Error finalizing - " & Object.ID); Log (Ada.Exceptions.Exception_Information (E)); end Finalize; ---------- -- Free -- ---------- procedure Free (Object : in out Base_Type) is Dummy_P : Pointer_To_Base_Class := Object'Unchecked_Access; procedure Free_Object is new Ada.Unchecked_Deallocation (Base_Type'Class, Pointer_To_Base_Class); begin Free_Object (Dummy_P); end Free; ------------------------------------------------------------------------- -- Base_Type - Creation Methods ------------------------------------------------------------------------- ------------------------ -- Create_With_Script -- ------------------------ procedure Create_With_Script (Object : in out Base_Type; Connection_ID : in Gnoga.Connection_ID; ID : in String; Script : in String; ID_Type : in ID_Enumeration := DOM_ID) is begin if Object.Connection_ID /= No_Connection then raise Object_Already_Created; end if; Gnoga.Server.Connection.Execute_Script (ID => Connection_ID, Script => Script); Object.Attach (Connection_ID => Connection_ID, ID => ID, ID_Type => ID_Type); Object.Bind_Event (Event => "click", Message => "", Script => Mouse_Event_Script); Object.Bind_Event (Event => "contextmenu", Message => "", Script => Mouse_Event_Script, Cancel => True); Object.Bind_Event (Event => "dblclick", Message => "", Script => Mouse_Event_Script); Object.Bind_Event (Event => "keypress", Message => "", Script => Keyboard_Event_Script); Object.Bind_Event (Event => "resize", Message => ""); end Create_With_Script; ------------------------- -- Attach_Using_Parent -- ------------------------- procedure Attach_Using_Parent (Object : in out Base_Type; Parent : in Base_Type'Class; ID : in String; ID_Type : in ID_Enumeration := DOM_ID) is begin Object.Attach (Connection_ID => Parent.Connection_ID, ID => ID, ID_Type => ID_Type); end Attach_Using_Parent; ------------ -- Attach -- ------------ procedure Attach (Object : in out Base_Type; Connection_ID : in Gnoga.Connection_ID; ID : in String; ID_Type : in ID_Enumeration := DOM_ID) is begin Object.Web_ID := Ada.Strings.Unbounded.To_Unbounded_String (ID); Object.Connection_ID := Connection_ID; Object.ID_Type := ID_Type; Object.Attach_To_Message_Queue; end Attach; ------------------------------------------------------------------------- -- Base_Type - Properties ------------------------------------------------------------------------- --------------- -- Unique_ID -- --------------- function Unique_ID (Object : Base_Type) return Gnoga.Unique_ID is begin return Object.Unique_ID; end Unique_ID; ------------------- -- Connection_ID -- ------------------- function Connection_ID (Object : Base_Type) return Gnoga.Connection_ID is begin return Object.Connection_ID; end Connection_ID; procedure Connection_ID (Object : in out Base_Type; Value : in Gnoga.Connection_ID) is begin Object.Connection_ID := Value; end Connection_ID; ----------- -- Valid -- ----------- function Valid (Object : Base_Type) return Boolean is begin if Object.Connection_ID = No_Connection then return False; else return Gnoga.Server.Connection.Valid (Object.Connection_ID); end if; end Valid; -------- -- ID -- -------- function ID (Object : Base_Type) return String is begin return Ada.Strings.Unbounded.To_String (Object.Web_ID); end ID; procedure ID (Object : in out Base_Type; ID : in String; ID_Type : in ID_Enumeration) is begin Object.Web_ID := Ada.Strings.Unbounded.To_Unbounded_String (ID); Object.ID_Type := ID_Type; end ID; ------------- -- ID_Type -- ------------- function ID_Type (Object : Base_Type) return ID_Enumeration is begin return Object.ID_Type; end ID_Type; ------------------ -- DOM_Selector -- ------------------ function DOM_Selector (Object : Base_Type) return String is begin if Object.ID_Type = DOM_ID or Object.ID_Type = Gnoga_ID then return "#" & Object.ID; else return Object.ID; end if; end DOM_Selector; --------------------- -- Connection_Data -- --------------------- function Connection_Data (Object : Base_Type) return Pointer_to_Connection_Data_Class is begin return Gnoga.Server.Connection.Connection_Data (Object.Connection_ID); end Connection_Data; ------------ -- Parent -- ------------ function Parent (Object : Base_Type) return Pointer_To_Base_Class is begin return Object.Parent_Object; end Parent; procedure Parent (Object : in out Base_Type; Value : in out Base_Type'Class) is begin Object.Parent_Object := Value'Unchecked_Access; Value.On_Child_Added (Object); end Parent; procedure Parent (Object : in out Base_Type; Value : in Pointer_To_Base_Class) is begin Object.Parent_Object := Value; if Value /= null then Value.On_Child_Added (Object); end if; end Parent; ------------ -- Height -- ------------ procedure Height (Object : in out Base_Type; Value : in Integer) is begin Object.jQuery_Execute ("height(" & Left_Trim (Value'Img) & ");"); end Height; function Height (Object : Base_Type) return Integer is begin return Object.jQuery_Execute ("height();"); end Height; ----------- -- Width -- ----------- procedure Width (Object : in out Base_Type; Value : in Integer) is begin Object.jQuery_Execute ("width(" & Left_Trim (Value'Img) & ");"); end Width; function Width (Object : Base_Type) return Integer is begin return Object.jQuery_Execute ("width();"); end Width; -------------- -- Property -- -------------- procedure Property (Object : in out Base_Type; Name : in String; Value : in String) is begin Object.jQuery_Execute ("prop ('" & Name & "','" & Escape_Quotes (Value) & "');"); end Property; function Property (Object : Base_Type; Name : String) return String is begin return Object.jQuery_Execute ("prop ('" & Name & "');"); end Property; procedure Property (Object : in out Base_Type; Name : in String; Value : in Integer) is begin Object.jQuery_Execute ("prop ('" & Name & "'," & Value'Img & ");"); end Property; function Property (Object : Base_Type; Name : String) return Integer is begin return Object.jQuery_Execute ("prop ('" & Name & "');"); end Property; procedure Property (Object : in out Base_Type; Name : in String; Value : in Float) is begin Object.jQuery_Execute ("prop ('" & Name & "'," & Value'Img & ");"); end Property; function Property (Object : Base_Type; Name : String) return Float is begin return Object.jQuery_Execute ("prop ('" & Name & "');"); end Property; procedure Property (Object : in out Base_Type; Name : in String; Value : in Boolean) is begin Object.jQuery_Execute ("prop ('" & Name & "'," & Value'Img & ");"); end Property; function Property (Object : Base_Type; Name : String) return Boolean is begin return Object.Property (Name) = "true"; end Property; ------------- -- Dynamic -- ------------- procedure Dynamic (Object : in out Base_Type; Value : Boolean := True) is begin Object.Is_Dynamic := Value; end Dynamic; function Dynamic (Object : Base_Type) return Boolean is begin return Object.Is_Dynamic; end Dynamic; ------------------------------------------------------------------------- -- Base_Type - Methods ------------------------------------------------------------------------- ----------- -- Focus -- ----------- procedure Focus (Object : in out Base_Type) is begin Object.Execute ("focus();"); end Focus; ---------- -- Blur -- ---------- procedure Blur (Object : in out Base_Type) is begin Object.Execute ("blur();"); end Blur; ------------ -- Execute-- ------------ procedure Execute (Object : in out Base_Type; Method : in String) is begin Object.jQuery_Execute ("get(0)." & Method); end Execute; function Execute (Object : Base_Type; Method : in String) return String is begin return Object.jQuery_Execute ("get(0)." & Method); end Execute; function Execute (Object : Base_Type; Method : in String) return Integer is begin return Object.jQuery_Execute ("get(0)." & Method); end Execute; function Execute (Object : Base_Type; Method : in String) return Float is begin return Object.jQuery_Execute ("get(0)." & Method); end Execute; function Execute (Object : Base_Type; Method : in String) return Boolean is begin return Object.Execute (Method) = "true"; end Execute; ----------------------- -- Buffer_Connection -- ----------------------- function Buffer_Connection (Object : Base_Type) return Boolean is begin return Gnoga.Server.Connection.Buffer_Connection (Object.Connection_ID); end Buffer_Connection; procedure Buffer_Connection (Object : in out Base_Type; Value : in Boolean := True) is begin Gnoga.Server.Connection.Buffer_Connection (Object.Connection_ID, Value); end Buffer_Connection; ------------------ -- Flush_Buffer -- ------------------ procedure Flush_Buffer (Object : in out Base_Type) is begin Gnoga.Server.Connection.Flush_Buffer (Object.Connection_ID); end Flush_Buffer; ------------------------------------------------------------------------- -- Base_Type - Events ------------------------------------------------------------------------- ------------------------------------------------------------------------- -- Base_Type - Event Internals ------------------------------------------------------------------------- ---------------- -- Bind_Event -- ---------------- procedure Bind_Event (Object : in out Base_Type; Event : in String; Message : in String; Eval : in String := ""; Script : in String := ""; Cancel : in Boolean := False) is US : constant String := Object.Unique_ID'Img; Full_Message : constant String := US (US'First + 1 .. US'Last) & "|" & Event & "|" & Message; function If_Script return String; function Cancel_Event return String; function If_Script return String is begin if Script = "" then return ""; else return "+" & Script; end if; end If_Script; function Cancel_Event return String is begin if Cancel then return " return false;"; else return ""; end if; end Cancel_Event; begin Bind_Event_Script (Object => Object, Event => Event, Script => Eval & "ws.send ('" & Escape_Quotes (Full_Message) & "'" & If_Script & ");" & Cancel_Event); end Bind_Event; ----------------------- -- Bind_Event_Script -- ----------------------- procedure Bind_Event_Script (Object : in out Base_Type; Event : in String; Script : in String) is begin Object.jQuery_Execute ("on ('" & Event & "', function (e, data) {" & Script & "});"); end Bind_Event_Script; ------------------ -- Unbind_Event -- ------------------ procedure Unbind_Event (Object : in out Base_Type; Event : in String) is begin Object.jQuery_Execute ("off ('" & Event & "');"); end Unbind_Event; ----------------------------- -- Attach_To_Message_Queue -- ----------------------------- procedure Attach_To_Message_Queue (Object : in out Base_Type) is begin Gnoga.Server.Connection.Add_To_Message_Queue (Object); end Attach_To_Message_Queue; -------------------------------- -- Detach_From_Message_Queue -- -------------------------------- procedure Detach_From_Message_Queue (Object : in out Base_Type) is begin Gnoga.Server.Connection.Delete_From_Message_Queue (Object); end Detach_From_Message_Queue; --------------------- -- Script_Accessor -- --------------------- function Script_Accessor (Object : Base_Type) return String is begin return Script_Accessor (Object.ID, Object.ID_Type); end Script_Accessor; function Script_Accessor (ID : String; ID_Type : ID_Enumeration) return String is begin case ID_Type is when No_ID => raise Object_Was_Not_Created; when DOM_ID => return "#" & ID; when Script => return ID; when Gnoga_ID => return "gnoga['" & ID & "']"; end case; end Script_Accessor; ------------ -- jQuery -- ------------ function jQuery (Object : Base_Type) return String is begin case Object.ID_Type is when No_ID => raise Object_Was_Not_Created; when DOM_ID => return "$('" & Object.Script_Accessor & "')"; when Script | Gnoga_ID => return "$(" & Object.Script_Accessor & ")"; end case; end jQuery; -------------------- -- jQuery_Execute -- -------------------- procedure jQuery_Execute (Object : in out Base_Type; Method : String) is Message_Script : constant String := jQuery (Object) & "." & Method; begin Gnoga.Server.Connection.Execute_Script (ID => Object.Connection_ID, Script => Message_Script); end jQuery_Execute; function jQuery_Execute (Object : Base_Type; Method : String) return String is Message_Script : constant String := jQuery (Object) & "." & Method; begin return Gnoga.Server.Connection.Execute_Script (ID => Object.Connection_ID, Script => Message_Script); end jQuery_Execute; function jQuery_Execute (Object : Base_Type; Method : String) return Integer is use Ada.Strings.Fixed; R : constant String := Object.jQuery_Execute (Method); begin if Index (R, ".") > 0 then return Integer (Float'Value (R)); else return Integer'Value (R); end if; exception when E : others => Log ("Error jQuery_Execute converting to Integer (forced to 0)."); Log (Ada.Exceptions.Exception_Information (E)); return 0; end jQuery_Execute; function jQuery_Execute (Object : Base_Type; Method : String) return Float is R : constant String := Object.jQuery_Execute (Method); begin return Float'Value (R); exception when E : others => Log ("Error jQuery_Execute converting to Float (forced to 0.0)."); Log (Ada.Exceptions.Exception_Information (E)); return 0.0; end jQuery_Execute; end Ada_GUI.Gnoga.Gui;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2016, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ package body Bluetooth_Low_Energy.Beacon is function Make_Beacon_Packet (MAC : UInt8_Array; UUID : BLE_UUID; Major, Minor : UInt16; Power : Integer_8) return BLE_Packet is Pck : BLE_Packet; begin Set_Header (Pck, 16#42#); -- MAC Push (Pck, MAC); -- Flag length Push (Pck, UInt8 (2)); -- Flag type Push (Pck, UInt8 (1)); -- Flag Content Push (Pck, UInt8 (6)); -- Data length Push (Pck, UInt8 (16#1A#)); -- Data type Push (Pck, UInt8 (16#FF#)); -- Data header Push (Pck, (16#4C#, 16#00#, 16#02#, 16#15#)); -- UUID Push_UUID (Pck, UUID); -- Major Push (Pck, Major); -- Minor Push (Pck, Minor); -- Power Push (Pck, Power); return Pck; end Make_Beacon_Packet; end Bluetooth_Low_Energy.Beacon;
-- { dg-do compile } -- { dg-options "-O2 -fdump-tree-optimized" } function Volatile6 return Integer is type Vol is new Integer; pragma Volatile (Vol); V : Vol := 0; begin for J in 1 .. 10 loop V := V + 1; end loop; return Integer (V); end; -- { dg-final { scan-tree-dump "goto" "optimized" } }
------------------------------------------------------------------------------- -- LSE -- L-System Editor -- Author: Heziode -- -- License: -- MIT License -- -- Copyright (c) 2018 Quentin Dauprat (Heziode) <Heziode@protonmail.com> -- -- Permission is hereby granted, free of charge, to any person obtaining a -- copy of this software and associated documentation files (the "Software"), -- to deal in the Software without restriction, including without limitation -- the rights to use, copy, modify, merge, publish, distribute, sublicense, -- and/or sell copies of the Software, and to permit persons to whom the -- Software is furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in -- all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -- DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------- with Ada.Characters.Latin_1; with Ada.Float_Text_IO; with Ada.Strings; with LSE.Model.Grammar.Symbol; package body LSE.Model.L_System.L_System is package L renames Ada.Characters.Latin_1; package Symbol_List renames LSE.Model.Grammar.Symbol_Utils.P_List; procedure Initialize (This : out Instance; Axiom : LSE.Model.Grammar.Symbol_Utils.P_List.List; Angle : LSE.Utils.Angle.Angle; Rules : LSE.Model.L_System.Growth_Rule_Utils.P_List.List; Turtle : LSE.Model.IO.Turtle_Utils.Holder) is begin This := Instance '(State => 0, Current_State => 0, Axiom => Axiom, Angle => Angle, Rules => Rules, Current_Value => Axiom, Turtle => Turtle); end Initialize; function Get_State (This : Instance) return Natural is begin return This.State; end Get_State; procedure Set_State (This : out Instance; Value : Natural) is begin This.State := Value; end Set_State; function Get_LSystem (This : Instance) return String is use Ada.Strings; use Ada.Float_Text_IO; use LSE.Model.Grammar.Symbol; ------------------------ -- Methods prototype -- ------------------------ function Get_Rules (This : LSE.Model.L_System.Growth_Rule_Utils.P_List.List) return Unbounded_String; ----------------------------- -- Declaration of methods -- ----------------------------- function Get_Rules (This : LSE.Model.L_System.Growth_Rule_Utils.P_List.List) return Unbounded_String is Result : Unbounded_String := To_Unbounded_String (""); begin for Rule of This loop Result := Result & L.LF & To_Unbounded_String (Get_Representation (Rule.Get_Head) & "") & L.Space & Get_Symbol_List (Rule.Get_Body); end loop; return Result; end Get_Rules; --------------- -- Variables -- --------------- Angle_Str : String (1 .. LSE.Utils.Angle.Angle'Digits); begin Put (To => Angle_Str, Item => Float (This.Angle), Aft => 2, Exp => 0); return To_String (Trim (To_Unbounded_String (Angle_Str), Both) & L.LF & Get_Symbol_List (This.Axiom) & Get_Rules (This.Rules)); end Get_LSystem; function Get_Value (This : Instance) return String is begin return To_String (Get_Symbol_List (This.Current_Value)); end Get_Value; function Get_Value (This : Instance) return LSE.Model.Grammar.Symbol_Utils.P_List.List is begin return This.Current_Value; end Get_Value; function Get_Turtle (This : Instance) return LSE.Model.IO.Turtle_Utils.Holder is begin return This.Turtle; end Get_Turtle; procedure Set_Turtle (This : out Instance; Value : LSE.Model.IO.Turtle_Utils.Holder) is begin This.Turtle := Value; end Set_Turtle; procedure Develop (This : out Instance) is use LSE.Model.Grammar.Symbol; Position : Symbol_List.Cursor := Symbol_List.No_Element; Found : Boolean := False; Tmp_Index : Symbol_List.Cursor; Rule_Item : LSE.Model.Grammar.Symbol_Utils.Ptr.Holder; Item : LSE.Model.Grammar.Symbol_Utils.Ptr.Holder; begin if This.Current_State = This.State then if This.Turtle.Element.Get_Max_X = 0.0 and This.Turtle.Element.Get_Min_X = 0.0 then -- Get L-System dimensions This.Compute_Dimension; end if; return; elsif This.Current_State > This.State then This.Current_State := 0; This.Current_Value := This.Axiom; end if; while This.Current_State < This.State loop This.Current_State := This.Current_State + 1; Position := This.Current_Value.First; while Symbol_List.Has_Element (Position) loop Item := Symbol_List.Element (Position); for Rule of This.Rules loop Rule_Item := Rule.Get_Head; if Item.Element.Get_Representation = Rule_Item.Element.Get_Representation then for S of Rule.Get_Body loop Symbol_List.Insert (This.Current_Value, Position, S); end loop; Found := True; end if; end loop; Symbol_List.Next (Position); if Found then if Symbol_List.Has_Element (Position) then Tmp_Index := Symbol_List.Previous (Position); else Tmp_Index := Symbol_List.Last (This.Current_Value); end if; Symbol_List.Delete (This.Current_Value, Tmp_Index); Found := False; end if; end loop; end loop; -- Get L-System dimensions This.Compute_Dimension; end Develop; function Get_Symbol_List (This : LSE.Model.Grammar.Symbol_Utils.P_List.List) return Unbounded_String is Result : Unbounded_String := To_Unbounded_String (""); begin for S of This loop Result := Result & To_Unbounded_String (LSE.Model.Grammar.Symbol.Get_Representation ( LSE.Model.Grammar.Symbol_Utils .Ptr.Element (S)) & ""); end loop; return Result; end Get_Symbol_List; procedure Interpret (This : in out Instance; T : in out Holder) is begin if This.Get_LSystem'Length = 0 then return; end if; T.Reference.Set_Angle (This.Angle); T.Reference.Set_Max_X (This.Turtle.Element.Get_Max_X); T.Reference.Set_Max_Y (This.Turtle.Element.Get_Max_Y); T.Reference.Set_Min_X (This.Turtle.Element.Get_Min_X); T.Reference.Set_Min_Y (This.Turtle.Element.Get_Min_Y); T.Reference.Configure; for Item of This.Current_Value loop Item.Reference.Interpret (T); end loop; T.Reference.Draw; end Interpret; procedure Compute_Dimension (This : in out Instance) is begin This.Turtle.Reference.Set_Dry_Run (True); This.Interpret (This.Turtle); This.Turtle.Reference.Set_Dry_Run (False); end Compute_Dimension; end LSE.Model.L_System.L_System;
------------------------------------------------------------------------------- -- This file is part of libsparkcrypto. -- -- Copyright (C) 2018 Componolit GmbH -- Copyright (C) 2010, Alexander Senier -- Copyright (C) 2010, secunet Security Networks AG -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met: -- -- * Redistributions of source code must retain the above copyright notice, -- this list of conditions and the following disclaimer. -- -- * Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- -- * Neither the name of the nor the names of its contributors may be used -- to endorse or promote products derived from this software without -- specific prior written permission. -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS -- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -- POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------- with AUnit.Assertions; use AUnit.Assertions; with Util; use Util; with LSC.Internal.Types; with LSC.Internal.SHA256; with LSC.Internal.SHA512; use type LSC.Internal.Types.Word32_Array_Type; use type LSC.Internal.Types.Word64_Array_Type; pragma Style_Checks ("-s"); pragma Warnings (Off, "formal parameter ""T"" is not referenced"); package body LSC_Internal_Test_SHA2 is procedure Test_SHA256_One_Block (T : in out Test_Cases.Test_Case'Class) is SHA256_Ctx : LSC.Internal.SHA256.Context_Type; Hash : LSC.Internal.SHA256.SHA256_Hash_Type; Message : LSC.Internal.SHA256.Block_Type; begin -- FIPS 180-2, Appendix C: SHA-256 Examples -- C.1 SHA-256 Example (One-Block Message) SHA256_Ctx := LSC.Internal.SHA256.SHA256_Context_Init; Message := LSC.Internal.SHA256.Block_Type'(M (16#61626300#), others => 16#fedca987#); LSC.Internal.SHA256.Context_Finalize (SHA256_Ctx, Message, 24); Hash := LSC.Internal.SHA256.SHA256_Get_Hash (SHA256_Ctx); Assert (Hash = LSC.Internal.SHA256.SHA256_Hash_Type'(M (16#ba7816bf#), M (16#8f01cfea#), M (16#414140de#), M (16#5dae2223#), M (16#b00361a3#), M (16#96177a9c#), M (16#b410ff61#), M (16#f20015ad#)), "Hash differs"); end Test_SHA256_One_Block; procedure Test_SHA256_Multi_Block (T : in out Test_Cases.Test_Case'Class) is SHA256_Ctx : LSC.Internal.SHA256.Context_Type; Hash : LSC.Internal.SHA256.SHA256_Hash_Type; Message : LSC.Internal.SHA256.Block_Type; begin -- C.2 SHA-256 Example (Multi-Block Message) SHA256_Ctx := LSC.Internal.SHA256.SHA256_Context_Init; Message := LSC.Internal.SHA256.Block_Type'(M (16#61626364#), M (16#62636465#), M (16#63646566#), M (16#64656667#), M (16#65666768#), M (16#66676869#), M (16#6768696a#), M (16#68696a6b#), M (16#696a6b6c#), M (16#6a6b6c6d#), M (16#6b6c6d6e#), M (16#6c6d6e6f#), M (16#6d6e6f70#), M (16#6e6f7071#), M (16#0a000000#), others => 16#deadbeef#); LSC.Internal.SHA256.Context_Finalize (SHA256_Ctx, Message, 448); Hash := LSC.Internal.SHA256.SHA256_Get_Hash (SHA256_Ctx); Assert (Hash = LSC.Internal.SHA256.SHA256_Hash_Type'(M (16#248d6a61#), M (16#d20638b8#), M (16#e5c02693#), M (16#0c3e6039#), M (16#a33ce459#), M (16#64ff2167#), M (16#f6ecedd4#), M (16#19db06c1#)), "Hash differs"); end Test_SHA256_Multi_Block; procedure Test_SHA256_Long (T : in out Test_Cases.Test_Case'Class) is SHA256_Ctx : LSC.Internal.SHA256.Context_Type; Hash : LSC.Internal.SHA256.SHA256_Hash_Type; Message : LSC.Internal.SHA256.Block_Type; begin -- C.3 SHA-256 Example (Long Message) Message := LSC.Internal.SHA256.Block_Type'(others => M (16#61616161#)); SHA256_Ctx := LSC.Internal.SHA256.SHA256_Context_Init; for I in Natural range 1 .. 15625 loop LSC.Internal.SHA256.Context_Update (SHA256_Ctx, Message); end loop; LSC.Internal.SHA256.Context_Finalize (SHA256_Ctx, Message, 0); Hash := LSC.Internal.SHA256.SHA256_Get_Hash (SHA256_Ctx); Assert (Hash = LSC.Internal.SHA256.SHA256_Hash_Type'(M (16#cdc76e5c#), M (16#9914fb92#), M (16#81a1c7e2#), M (16#84d73e67#), M (16#f1809a48#), M (16#a497200e#), M (16#046d39cc#), M (16#c7112cd0#)), "Hash differ"); end Test_SHA256_Long; --------------------------------------------------------------------------- procedure Test_SHA384_One_Block (T : in out Test_Cases.Test_Case'Class) is SHA512_Ctx : LSC.Internal.SHA512.Context_Type; Hash : LSC.Internal.SHA512.SHA384_Hash_Type; Message : LSC.Internal.SHA512.Block_Type; begin -- FIPS 180-2, Appendix C: SHA-384 Examples -- D.1 SHA-384 Example (One-Block Message) SHA512_Ctx := LSC.Internal.SHA512.SHA384_Context_Init; Message := LSC.Internal.SHA512.Block_Type'(N (16#6162630000000000#), others => 16#deadbeefcafebabe#); LSC.Internal.SHA512.Context_Finalize (SHA512_Ctx, Message, 24); Hash := LSC.Internal.SHA512.SHA384_Get_Hash (SHA512_Ctx); Assert (Hash = LSC.Internal.SHA512.SHA384_Hash_Type'(N (16#cb00753f45a35e8b#), N (16#b5a03d699ac65007#), N (16#272c32ab0eded163#), N (16#1a8b605a43ff5bed#), N (16#8086072ba1e7cc23#), N (16#58baeca134c825a7#)), "Hash differs"); end Test_SHA384_One_Block; --------------------------------------------------------------------------- procedure Test_SHA384_Multi_Block (T : in out Test_Cases.Test_Case'Class) is SHA512_Ctx : LSC.Internal.SHA512.Context_Type; Hash : LSC.Internal.SHA512.SHA384_Hash_Type; Message : LSC.Internal.SHA512.Block_Type; begin -- D.2 SHA-384 Example (Multi-Block Message) SHA512_Ctx := LSC.Internal.SHA512.SHA384_Context_Init; Message := LSC.Internal.SHA512.Block_Type' (N (16#6162636465666768#), N (16#6263646566676869#), N (16#636465666768696a#), N (16#6465666768696a6b#), N (16#65666768696a6b6c#), N (16#666768696a6b6c6d#), N (16#6768696a6b6c6d6e#), N (16#68696a6b6c6d6e6f#), N (16#696a6b6c6d6e6f70#), N (16#6a6b6c6d6e6f7071#), N (16#6b6c6d6e6f707172#), N (16#6c6d6e6f70717273#), N (16#6d6e6f7071727374#), N (16#6e6f707172737475#), N (16#0000000000000000#), N (16#0000000000000000#)); LSC.Internal.SHA512.Context_Finalize (SHA512_Ctx, Message, 896); Hash := LSC.Internal.SHA512.SHA384_Get_Hash (SHA512_Ctx); Assert (Hash = LSC.Internal.SHA512.SHA384_Hash_Type'(N (16#09330c33f71147e8#), N (16#3d192fc782cd1b47#), N (16#53111b173b3b05d2#), N (16#2fa08086e3b0f712#), N (16#fcc7c71a557e2db9#), N (16#66c3e9fa91746039#)), "Hash differs"); end Test_SHA384_Multi_Block; --------------------------------------------------------------------------- procedure Test_SHA384_Long (T : in out Test_Cases.Test_Case'Class) is SHA512_Ctx : LSC.Internal.SHA512.Context_Type; Hash : LSC.Internal.SHA512.SHA384_Hash_Type; Message : LSC.Internal.SHA512.Block_Type; begin -- D.3 SHA-384 Example (Long Message) Message := LSC.Internal.SHA512.Block_Type'(others => N (16#6161616161616161#)); SHA512_Ctx := LSC.Internal.SHA512.SHA384_Context_Init; for I in Natural range 1 .. 7812 loop LSC.Internal.SHA512.Context_Update (SHA512_Ctx, Message); end loop; LSC.Internal.SHA512.Context_Finalize (SHA512_Ctx, Message, 512); Hash := LSC.Internal.SHA512.SHA384_Get_Hash (SHA512_Ctx); Assert (Hash = LSC.Internal.SHA512.SHA384_Hash_Type'(N (16#9d0e1809716474cb#), N (16#086e834e310a4a1c#), N (16#ed149e9c00f24852#), N (16#7972cec5704c2a5b#), N (16#07b8b3dc38ecc4eb#), N (16#ae97ddd87f3d8985#)), "Hash differs"); end Test_SHA384_Long; --------------------------------------------------------------------------- procedure Test_SHA512_One_Block (T : in out Test_Cases.Test_Case'Class) is SHA512_Ctx : LSC.Internal.SHA512.Context_Type; Hash : LSC.Internal.SHA512.SHA512_Hash_Type; Message : LSC.Internal.SHA512.Block_Type; begin -- FIPS 180-2, Appendix C: SHA-512 Examples -- C.1 SHA-512 Example (One-Block Message) SHA512_Ctx := LSC.Internal.SHA512.SHA512_Context_Init; Message := LSC.Internal.SHA512.Block_Type'(N (16#616263f4aabc124d#), others => 16#deadc0dedeadbeef#); LSC.Internal.SHA512.Context_Finalize (SHA512_Ctx, Message, 24); Hash := LSC.Internal.SHA512.SHA512_Get_Hash (SHA512_Ctx); Assert (Hash = LSC.Internal.SHA512.SHA512_Hash_Type'(N (16#ddaf35a193617aba#), N (16#cc417349ae204131#), N (16#12e6fa4e89a97ea2#), N (16#0a9eeee64b55d39a#), N (16#2192992a274fc1a8#), N (16#36ba3c23a3feebbd#), N (16#454d4423643ce80e#), N (16#2a9ac94fa54ca49f#)), "Hash differs"); end Test_SHA512_One_Block; --------------------------------------------------------------------------- procedure Test_SHA512_Multi_Block (T : in out Test_Cases.Test_Case'Class) is SHA512_Ctx : LSC.Internal.SHA512.Context_Type; Hash : LSC.Internal.SHA512.SHA512_Hash_Type; Message : LSC.Internal.SHA512.Block_Type; begin -- C.2 SHA-512 Example (Multi-Block Message) SHA512_Ctx := LSC.Internal.SHA512.SHA512_Context_Init; Message := LSC.Internal.SHA512.Block_Type' (N (16#6162636465666768#), N (16#6263646566676869#), N (16#636465666768696a#), N (16#6465666768696a6b#), N (16#65666768696a6b6c#), N (16#666768696a6b6c6d#), N (16#6768696a6b6c6d6e#), N (16#68696a6b6c6d6e6f#), N (16#696a6b6c6d6e6f70#), N (16#6a6b6c6d6e6f7071#), N (16#6b6c6d6e6f707172#), N (16#6c6d6e6f70717273#), N (16#6d6e6f7071727374#), N (16#6e6f707172737475#), N (16#f423ae49fac82234#), N (16#deadbeefcafe0000#)); LSC.Internal.SHA512.Context_Finalize (SHA512_Ctx, Message, 896); Hash := LSC.Internal.SHA512.SHA512_Get_Hash (SHA512_Ctx); Assert (Hash = LSC.Internal.SHA512.SHA512_Hash_Type'(N (16#8e959b75dae313da#), N (16#8cf4f72814fc143f#), N (16#8f7779c6eb9f7fa1#), N (16#7299aeadb6889018#), N (16#501d289e4900f7e4#), N (16#331b99dec4b5433a#), N (16#c7d329eeb6dd2654#), N (16#5e96e55b874be909#)), "Hash differs"); end Test_SHA512_Multi_Block; --------------------------------------------------------------------------- procedure Test_SHA512_Long (T : in out Test_Cases.Test_Case'Class) is SHA512_Ctx : LSC.Internal.SHA512.Context_Type; Hash : LSC.Internal.SHA512.SHA512_Hash_Type; Message : LSC.Internal.SHA512.Block_Type; begin -- C.3 SHA-512 Example (Long Message) Message := LSC.Internal.SHA512.Block_Type'(others => N (16#6161616161616161#)); SHA512_Ctx := LSC.Internal.SHA512.SHA512_Context_Init; for I in Natural range 1 .. 7812 loop LSC.Internal.SHA512.Context_Update (SHA512_Ctx, Message); end loop; LSC.Internal.SHA512.Context_Finalize (SHA512_Ctx, Message, 512); Hash := LSC.Internal.SHA512.SHA512_Get_Hash (SHA512_Ctx); Assert (Hash = LSC.Internal.SHA512.SHA512_Hash_Type'(N (16#e718483d0ce76964#), N (16#4e2e42c7bc15b463#), N (16#8e1f98b13b204428#), N (16#5632a803afa973eb#), N (16#de0ff244877ea60a#), N (16#4cb0432ce577c31b#), N (16#eb009c5c2c49aa2e#), N (16#4eadb217ad8cc09b#)), "Hash differs"); end Test_SHA512_Long; --------------------------------------------------------------------------- procedure Register_Tests (T : in out Test_Case) is use AUnit.Test_Cases.Registration; begin Register_Routine (T, Test_SHA256_One_Block'Access, "SHA-256 (One-Block Message)"); Register_Routine (T, Test_SHA256_Multi_Block'Access, "SHA-256 (Multi-Block Message)"); Register_Routine (T, Test_SHA256_Long'Access, "SHA-256 (Long Message)"); Register_Routine (T, Test_SHA384_One_Block'Access, "SHA-384 (One-Block Message)"); Register_Routine (T, Test_SHA384_Multi_Block'Access, "SHA-384 (Multi-Block Message)"); Register_Routine (T, Test_SHA384_Long'Access, "SHA-384 (Long Message)"); Register_Routine (T, Test_SHA512_One_Block'Access, "SHA-512 (One-Block Message)"); Register_Routine (T, Test_SHA512_Multi_Block'Access, "SHA-512 (Multi-Block Message)"); Register_Routine (T, Test_SHA512_Long'Access, "SHA-512 (Long Message)"); end Register_Tests; --------------------------------------------------------------------------- function Name (T : Test_Case) return Test_String is begin return Format ("SHA2"); end Name; end LSC_Internal_Test_SHA2;
------------------------------------------------------------------------------ -- G E L A G R A M M A R S -- -- Library for dealing with grammars for Gela project, -- -- a portable Ada compiler -- -- http://gela.ada-ru.org/ -- -- - - - - - - - - - - - - - - - -- -- Read copyright and license in gela.ads file -- ------------------------------------------------------------------------------ with League.String_Vectors; with League.Characters; package body Writers is New_Line : constant Wide_Wide_Character := Wide_Wide_Character'Val (10); ----------- -- Clear -- ----------- procedure Clear (Self : in out Writer) is begin Self.Text.Clear; Self.Last_Line.Clear; end Clear; procedure N (Self : in out Writer; Text : Wide_Wide_String) is begin Self.Last_Line.Append (Text); end N; procedure N (Self : in out Writer; Text : League.Strings.Universal_String) is begin Self.N (Text.To_Wide_Wide_String); end N; procedure N (Self : in out Writer; Text : Wide_Wide_String; Copy : in out Writer'Class) is begin Self.N (Text); Copy.N (Text); end N; procedure N (Self : in out Writer; Text : League.Strings.Universal_String; Copy : in out Writer'Class) is begin Self.N (Text); Copy.N (Text); end N; ------- -- N -- ------- procedure N (Self : in out Writer; Value : Natural) is Image : constant Wide_Wide_String := Natural'Wide_Wide_Image (Value); begin Self.N (Image (2 .. Image'Last)); end N; procedure N (Self : in out Writer; Value : Writer'Class) is Text : constant League.Strings.Universal_String := Value.Text; List : constant League.String_Vectors.Universal_String_Vector := Text.Split (New_Line); begin for J in 1 .. List.Length loop Self.P (List.Element (J)); end loop; end N; procedure P (Self : in out Writer; Text : Wide_Wide_String := ""; Copy : in out Writer'Class) is begin Self.P (Text); Copy.P (Text); end P; procedure P (Self : in out Writer; Text : League.Strings.Universal_String; Copy : in out Writer'Class) is begin Self.P (Text); Copy.P (Text); end P; procedure P (Self : in out Writer; Text : League.Strings.Universal_String) is begin if Text.Index (New_Line) > 0 then declare List : League.String_Vectors.Universal_String_Vector; begin List := Text.Split (New_Line); for J in 1 .. List.Length loop Self.P (List.Element (J)); end loop; end; else Self.P (Text.To_Wide_Wide_String); end if; end P; procedure P (Self : in out Writer; Text : Wide_Wide_String := "") is function Get_Prefix (X : League.Strings.Universal_String) return League.Strings.Universal_String; ---------------- -- Get_Prefix -- ---------------- function Get_Prefix (X : League.Strings.Universal_String) return League.Strings.Universal_String is use type League.Characters.Universal_Character; begin for J in 1 .. X.Length loop if X.Element (J) /= ' ' then return X.Slice (1, J - 1); end if; end loop; raise Constraint_Error; end Get_Prefix; begin Self.N (Text); if Self.Last_Line.Length > 78 then declare Length : Natural; List : constant League.String_Vectors.Universal_String_Vector := Self.Last_Line.Split ('.'); Prefix : League.Strings.Universal_String := Get_Prefix (Self.Last_Line); begin Self.Text.Append (List.Element (1)); Length := List.Element (1).Length; for J in 2 .. List.Length loop if Length + List.Element (J).Length < 78 then Self.Text.Append ('.'); Self.Text.Append (List.Element (J)); Length := Length + List.Element (J).Length + 1; else Self.Text.Append ('.'); Self.Text.Append (New_Line); Prefix.Append (" "); Self.Text.Append (Prefix); Self.Text.Append (List.Element (J)); Length := Prefix.Length + List.Element (J).Length; end if; end loop; end; else Self.Text.Append (Self.Last_Line); end if; Self.Last_Line.Clear; Self.Text.Append (New_Line); end P; ---------- -- Text -- ---------- function Text (Self : Writer) return League.Strings.Universal_String is use type League.Strings.Universal_String; begin return Self.Text & Self.Last_Line; end Text; end Writers;
pragma License (Unrestricted); -- extended unit package Ada.IO_Modes is -- Root types of File_Mode and for the parameters Form. pragma Pure; type File_Mode is (In_File, Out_File, Append_File); type Inout_File_Mode is (In_File, Inout_File, Out_File); -- Direct_IO -- the types for the parameters Form of Stream_IO type File_Shared_Spec is ( Allow, -- "shared=allow", "shared=yes", or "shared=no" Read_Only, -- "shared=read" Deny, -- "shared=deny" By_Mode); -- default type File_Shared is new File_Shared_Spec range Allow .. Deny; -- subtype File_Wait is Boolean; -- False as "wait=false", or default -- True as "wait=true" -- subtype File_Overwrite is Boolean; -- False as "overwrite=false" -- True as "overwrite=true", or default -- the types for the parameters Form of Text_IO type File_External_Base is ( Terminal, UTF_8, -- "external=utf-8", or "wcem=8" Locale, -- "external=dbcs", Windows only By_Target); -- default, UTF_8 in POSIX, or Locale in Windows type File_External_Spec is new File_External_Base range UTF_8 .. By_Target; type File_External is new File_External_Base range Terminal .. Locale; type File_New_Line_Spec is ( LF, -- "nl=lf" CR, -- "nl=cr" CR_LF, -- "nl=m" By_Target); -- default, LF in POSIX, or CR_LF in Windows type File_New_Line is new File_New_Line_Spec range LF .. CR_LF; end Ada.IO_Modes;
package GESTE_Fonts.FreeSerifBold5pt7b is Font : constant Bitmap_Font_Ref; private FreeSerifBold5pt7bBitmaps : aliased constant Font_Bitmap := ( 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#40#, 16#10#, 16#04#, 16#01#, 16#00#, 16#40#, 16#00#, 16#06#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#58#, 16#12#, 16#05#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#14#, 16#0F#, 16#81#, 16#40#, 16#F8#, 16#14#, 16#06#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#3C#, 16#0E#, 16#01#, 16#C0#, 16#A8#, 16#2E#, 16#07#, 16#00#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#32#, 16#0B#, 16#04#, 16#C1#, 16#EE#, 16#0A#, 16#85#, 16#C1#, 16#30#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#38#, 16#09#, 16#03#, 16#B0#, 16#E8#, 16#4C#, 16#1B#, 16#07#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#40#, 16#10#, 16#04#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#10#, 16#04#, 16#01#, 16#00#, 16#C0#, 16#10#, 16#04#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#80#, 16#10#, 16#02#, 16#00#, 16#80#, 16#20#, 16#08#, 16#04#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#1C#, 16#02#, 16#01#, 16#C0#, 16#20#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#00#, 16#40#, 16#7C#, 16#04#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#08#, 16#04#, 16#01#, 16#00#, 16#40#, 16#20#, 16#08#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#70#, 16#14#, 16#0D#, 16#83#, 16#60#, 16#D8#, 16#14#, 16#07#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#08#, 16#02#, 16#00#, 16#80#, 16#20#, 16#08#, 16#07#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#70#, 16#04#, 16#01#, 16#00#, 16#40#, 16#20#, 16#12#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#70#, 16#24#, 16#01#, 16#00#, 16#E0#, 16#18#, 16#04#, 16#0E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#10#, 16#1C#, 16#05#, 16#02#, 16#40#, 16#F8#, 16#04#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#70#, 16#20#, 16#06#, 16#01#, 16#C0#, 16#18#, 16#04#, 16#0E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#18#, 16#18#, 16#07#, 16#03#, 16#60#, 16#D8#, 16#16#, 16#07#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F8#, 16#24#, 16#01#, 16#00#, 16#40#, 16#20#, 16#08#, 16#02#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#70#, 16#36#, 16#0D#, 16#00#, 16#C0#, 16#D8#, 16#36#, 16#07#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#70#, 16#34#, 16#0D#, 16#83#, 16#60#, 16#70#, 16#0C#, 16#0C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#C0#, 16#C0#, 16#40#, 16#0E#, 16#00#, 16#40#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#1F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#04#, 16#00#, 16#E0#, 16#04#, 16#06#, 16#06#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#70#, 16#14#, 16#01#, 16#00#, 16#80#, 16#20#, 16#00#, 16#02#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1E#, 16#0B#, 16#44#, 16#B1#, 16#54#, 16#55#, 16#0F#, 16#81#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#10#, 16#04#, 16#03#, 16#80#, 16#E0#, 16#4C#, 16#1F#, 16#0C#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F8#, 16#1B#, 16#06#, 16#C1#, 16#E0#, 16#6C#, 16#1B#, 16#0F#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3A#, 16#19#, 16#8C#, 16#23#, 16#00#, 16#C0#, 16#18#, 16#83#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F8#, 16#19#, 16#06#, 16#61#, 16#98#, 16#66#, 16#19#, 16#0F#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FC#, 16#19#, 16#06#, 16#81#, 16#E0#, 16#68#, 16#19#, 16#0F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FC#, 16#19#, 16#06#, 16#01#, 16#C0#, 16#60#, 16#18#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3A#, 16#19#, 16#8C#, 16#03#, 16#3C#, 16#46#, 16#19#, 16#83#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FF#, 16#19#, 16#86#, 16#61#, 16#F8#, 16#66#, 16#19#, 16#8F#, 16#F0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F0#, 16#18#, 16#06#, 16#01#, 16#80#, 16#60#, 16#18#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#78#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#0C#, 16#0B#, 16#03#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FE#, 16#19#, 16#07#, 16#81#, 16#E0#, 16#6C#, 16#19#, 16#8F#, 16#F0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F0#, 16#18#, 16#06#, 16#01#, 16#80#, 16#60#, 16#19#, 16#0F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E1#, 16#98#, 16#C7#, 16#51#, 16#D4#, 16#59#, 16#16#, 16#4E#, 16#B8#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E6#, 16#1D#, 16#07#, 16#41#, 16#70#, 16#4C#, 16#11#, 16#0C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3C#, 16#19#, 16#8C#, 16#23#, 16#08#, 16#C2#, 16#19#, 16#83#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F8#, 16#1B#, 16#06#, 16#C1#, 16#E0#, 16#60#, 16#18#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3C#, 16#19#, 16#84#, 16#63#, 16#08#, 16#C2#, 16#11#, 16#82#, 16#40#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F8#, 16#1B#, 16#06#, 16#C1#, 16#E0#, 16#7C#, 16#1B#, 16#0F#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#70#, 16#12#, 16#04#, 16#01#, 16#E0#, 16#08#, 16#22#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FC#, 16#2D#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#0C#, 16#07#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F6#, 16#19#, 16#06#, 16#41#, 16#90#, 16#64#, 16#19#, 16#03#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E6#, 16#19#, 16#06#, 16#40#, 16#A0#, 16#38#, 16#06#, 16#01#, 16#00#, 16#40#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#EE#, 16#D1#, 16#26#, 16#69#, 16#BC#, 16#33#, 16#0C#, 16#C1#, 16#20#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FE#, 16#19#, 16#03#, 16#80#, 16#60#, 16#28#, 16#13#, 16#0E#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E6#, 16#19#, 16#02#, 16#80#, 16#E0#, 16#10#, 16#04#, 16#03#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#7C#, 16#22#, 16#01#, 16#80#, 16#C0#, 16#20#, 16#19#, 16#0F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#60#, 16#10#, 16#04#, 16#01#, 16#00#, 16#40#, 16#10#, 16#04#, 16#01#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#80#, 16#20#, 16#04#, 16#01#, 16#00#, 16#40#, 16#08#, 16#02#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E0#, 16#08#, 16#02#, 16#00#, 16#80#, 16#20#, 16#08#, 16#02#, 16#03#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#30#, 16#0C#, 16#04#, 16#81#, 16#20#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#30#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#00#, 16#40#, 16#30#, 16#34#, 16#0F#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#C0#, 16#10#, 16#07#, 16#81#, 16#20#, 16#48#, 16#12#, 16#03#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#07#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#18#, 16#06#, 16#07#, 16#83#, 16#60#, 16#D8#, 16#36#, 16#07#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#03#, 16#40#, 16#F0#, 16#30#, 16#07#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#70#, 16#10#, 16#0E#, 16#01#, 16#00#, 16#40#, 16#10#, 16#0E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#03#, 16#60#, 16#D0#, 16#1C#, 16#0F#, 16#82#, 16#20#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#C0#, 16#10#, 16#05#, 16#81#, 16#E0#, 16#58#, 16#16#, 16#0F#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#40#, 16#00#, 16#0C#, 16#01#, 16#00#, 16#40#, 16#10#, 16#0E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#00#, 16#06#, 16#00#, 16#80#, 16#20#, 16#08#, 16#02#, 16#00#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#C0#, 16#10#, 16#05#, 16#81#, 16#40#, 16#70#, 16#16#, 16#0F#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#C0#, 16#10#, 16#04#, 16#01#, 16#00#, 16#40#, 16#10#, 16#0E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#61#, 16#6C#, 16#5B#, 16#16#, 16#CF#, 16#B0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0D#, 16#81#, 16#E0#, 16#58#, 16#16#, 16#0F#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#03#, 16#60#, 16#D8#, 16#36#, 16#07#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#81#, 16#20#, 16#48#, 16#12#, 16#07#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#83#, 16#60#, 16#D8#, 16#36#, 16#07#, 16#80#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#01#, 16#00#, 16#40#, 16#10#, 16#0E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#02#, 16#40#, 16#60#, 16#24#, 16#0E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#10#, 16#0E#, 16#01#, 16#00#, 16#40#, 16#10#, 16#06#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0D#, 16#81#, 16#60#, 16#58#, 16#16#, 16#07#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#81#, 16#40#, 16#70#, 16#08#, 16#02#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0D#, 16#A1#, 16#70#, 16#5C#, 16#1B#, 16#02#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#81#, 16#40#, 16#20#, 16#14#, 16#0F#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#81#, 16#40#, 16#70#, 16#08#, 16#02#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#02#, 16#C0#, 16#60#, 16#14#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#80#, 16#40#, 16#10#, 16#04#, 16#01#, 16#00#, 16#40#, 16#10#, 16#04#, 16#01#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#40#, 16#10#, 16#04#, 16#01#, 16#00#, 16#40#, 16#10#, 16#04#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#00#, 16#60#, 16#08#, 16#02#, 16#00#, 16#80#, 16#20#, 16#08#, 16#02#, 16#01#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#60#, 16#06#, 16#00#, 16#00#, 16#00#); Font_D : aliased constant Bitmap_Font := ( Bytes_Per_Glyph => 15, Glyph_Width => 10, Glyph_Height => 12, Data => FreeSerifBold5pt7bBitmaps'Access); Font : constant Bitmap_Font_Ref := Font_D'Access; end GESTE_Fonts.FreeSerifBold5pt7b;
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr> -- MIT license. Please refer to the LICENSE file. with Ada.Exceptions; use Ada.Exceptions; with Ada.Calendar.Time_Zones; use Ada.Calendar.Time_Zones; private with Apsepp.Calendar; package Apsepp.Debug_Trace_Class is type Debug_Trace_Interfa is limited interface; not overriding function Message_W_Entity (Obj : Debug_Trace_Interfa; Message : String; Entity_Name : String) return String is abstract; not overriding function E_To_String (Obj : Debug_Trace_Interfa; E : Exception_Occurrence) return String is abstract; not overriding function Clock_String (Obj : Debug_Trace_Interfa; Reset_Elapsed : Boolean := False) return String is abstract; not overriding procedure Trace (Obj : in out Debug_Trace_Interfa; Message : String; Entity_Name : String := "") is null; not overriding procedure Trace_E (Obj : in out Debug_Trace_Interfa; E : Exception_Occurrence; Entity_Name : String := "") is null; not overriding procedure Set_Time_Zone (Obj : in out Debug_Trace_Interfa; Time_Zone : Time_Offset) is abstract; not overriding procedure Set_Local_Time_Zone (Obj : in out Debug_Trace_Interfa) is abstract; not overriding procedure Trace_Time (Obj : in out Debug_Trace_Interfa; Entity_Name : String := ""; Reset_Elapsed : Boolean := False) is null; private use Ada.Calendar, Apsepp.Calendar; ---------------------------------------------------------------------------- protected Reset_Date_Handler is procedure Set_Time_Zone (Time_Zone : Time_Offset); procedure Get (Date : out Time; Time_Zone : out Time_Offset; Elapsed_Time : out Duration; Reset : Boolean); private Offset : Time_Offset := 0; Reset_Date : Time := Time_First; end Reset_Date_Handler; ---------------------------------------------------------------------------- end Apsepp.Debug_Trace_Class;
----------------------------------------------------------------------- -- awa-commands-drivers -- Driver for AWA commands for server or admin tool -- Copyright (C) 2020 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with GNAT.Command_Line; with GNAT.Strings; with Util.Commands.Drivers; with Util.Commands.Parsers.GNAT_Parser; with Servlet.Server; with AWA.Applications; generic Driver_Name : String; type Container_Type is limited new Servlet.Server.Container with private; package AWA.Commands.Drivers is package Main_Driver is new Util.Commands.Drivers (Context_Type => Context_Type, Config_Parser => Util.Commands.Parsers.GNAT_Parser.Config_Parser, Driver_Name => Driver_Name); subtype Help_Command_Type is Main_Driver.Help_Command_Type; subtype Driver_Type is Main_Driver.Driver_Type; type Command_Type is abstract new Main_Driver.Command_Type with null record; -- Setup the command before parsing the arguments and executing it. overriding procedure Setup (Command : in out Command_Type; Config : in out GNAT.Command_Line.Command_Line_Configuration; Context : in out Context_Type); -- Write the help associated with the command. overriding procedure Help (Command : in out Command_Type; Name : in String; Context : in out Context_Type); type Application_Command_Type is abstract new Command_Type with record Application_Name : aliased GNAT.Strings.String_Access; end record; function Is_Application (Command : in Application_Command_Type; URI : in String) return Boolean; procedure Execute (Command : in out Application_Command_Type; Application : in out AWA.Applications.Application'Class; Args : in Argument_List'Class; Context : in out Context_Type) is abstract; -- Setup the command before parsing the arguments and executing it. overriding procedure Setup (Command : in out Application_Command_Type; Config : in out GNAT.Command_Line.Command_Line_Configuration; Context : in out Context_Type); overriding procedure Execute (Command : in out Application_Command_Type; Name : in String; Args : in Argument_List'Class; Context : in out Context_Type); -- Print the command usage. procedure Usage (Args : in Argument_List'Class; Context : in out Context_Type; Name : in String := ""); -- Execute the command with its arguments. procedure Execute (Name : in String; Args : in Argument_List'Class; Context : in out Context_Type); procedure Run (Context : in out Context_Type; Arguments : out Util.Commands.Dynamic_Argument_List); Driver : Drivers.Driver_Type; WS : Container_Type; end AWA.Commands.Drivers;
------------------------------------------------------------------------ -- Copyright (C) 2010-2020 by Heisenbug Ltd. (github@heisenbug.eu) -- -- This work is free. You can redistribute it and/or modify it under -- the terms of the Do What The Fuck You Want To Public License, -- Version 2, as published by Sam Hocevar. See the LICENSE file for -- more details. ------------------------------------------------------------------------ pragma License (Unrestricted); with Ada.Text_IO; with Msg_Producer; procedure Msg_Consumer is MESSAGE_RATE : constant := 1; Msg : Msg_Producer.Message; Msg_Board : Msg_Producer.BB_Mailbox.Object; -- Rename base class (root type) for easier view conversion. subtype Object is Msg_Producer.Int_Messaging.Object; begin Ada.Text_IO.Put_Line ("Start producing messages..."); Msg_Producer.Start (Msg_Rate => MESSAGE_RATE, MB => Msg_Board); Ada.Text_IO.Put_Line ("Start consuming messages..."); loop Msg_Producer.Int_Messaging.Read (Object'Class (Msg_Board), Msg); Ada.Text_IO.Put (Msg_Producer.Message'Image (Msg)); -- If Msg_Board is an instance of Whiteboard, Erase should be -- called from time to time or else we're just looping around -- eating all CPU. -- delay 1.0; end loop; end Msg_Consumer;
with datos; use datos; procedure Insertar_en_psicion_N ( L : in out Lista; Num : in Integer ) is begin end Insertar_en_psicion_N;
pragma License (Unrestricted); -- implementation unit required by compiler package System.WCh_WtS is pragma Pure; -- (s-wchcon.ads) type WC_Encoding_Method is range 1 .. 6; -- required for T'Wide_Value by compiler (s-wchwts.ads) function Wide_String_To_String ( S : Wide_String; EM : WC_Encoding_Method) return String; -- required for T'Wide_Wide_Value by compiler (s-wchwts.ads) function Wide_Wide_String_To_String ( S : Wide_Wide_String; EM : WC_Encoding_Method) return String; end System.WCh_WtS;
-- { dg-do compile } -- { dg-options "-O2" } with System; procedure Memtrap is X : integer; for X'address use System.Null_Address; begin X := 12; exception when others => null; end; -- { dg-final { scan-assembler "__gnat_begin_handler|__gnat_raise_nodefer" } }
-- Auto_Counters_Tests -- Unit tests for Auto_Counters packages -- Copyright (c) 2016, James Humphry - see LICENSE file for details with Auto_Counters_Suite; with AUnit.Run; with AUnit.Reporter.Text; procedure Auto_Counters_Tests is procedure Run is new AUnit.Run.Test_Runner (Auto_Counters_Suite.Suite); Reporter : AUnit.Reporter.Text.Text_Reporter; begin AUnit.Reporter.Text.Set_Use_ANSI_Colors(Reporter, True); Run (Reporter); end Auto_Counters_Tests;
with Ada.Text_IO; procedure Hamming is generic type Int_Type is private; Zero : Int_Type; One : Int_Type; Two : Int_Type; Three : Int_Type; Five : Int_Type; with function "mod" (Left, Right : Int_Type) return Int_Type is <>; with function "/" (Left, Right : Int_Type) return Int_Type is <>; with function "+" (Left, Right : Int_Type) return Int_Type is <>; function Get_Hamming (Position : Positive) return Int_Type; function Get_Hamming (Position : Positive) return Int_Type is function Is_Hamming (Number : Int_Type) return Boolean is Temporary : Int_Type := Number; begin while Temporary mod Two = Zero loop Temporary := Temporary / Two; end loop; while Temporary mod Three = Zero loop Temporary := Temporary / Three; end loop; while Temporary mod Five = Zero loop Temporary := Temporary / Five; end loop; return Temporary = One; end Is_Hamming; Result : Int_Type := One; Previous : Positive := 1; begin while Previous /= Position loop Result := Result + One; if Is_Hamming (Result) then Previous := Previous + 1; end if; end loop; return Result; end Get_Hamming; -- up to 2**32 - 1 function Integer_Get_Hamming is new Get_Hamming (Int_Type => Integer, Zero => 0, One => 1, Two => 2, Three => 3, Five => 5); -- up to 2**64 - 1 function Long_Long_Integer_Get_Hamming is new Get_Hamming (Int_Type => Long_Long_Integer, Zero => 0, One => 1, Two => 2, Three => 3, Five => 5); begin Ada.Text_IO.Put ("1) First 20 Hamming numbers: "); for I in 1 .. 20 loop Ada.Text_IO.Put (Integer'Image (Integer_Get_Hamming (I))); end loop; Ada.Text_IO.New_Line; Ada.Text_IO.Put_Line ("2) 1_691st Hamming number: " & Integer'Image (Integer_Get_Hamming (1_691))); -- even Long_Long_Integer overflows here Ada.Text_IO.Put_Line ("3) 1_000_000st Hamming number: " & Long_Long_Integer'Image (Long_Long_Integer_Get_Hamming (1_000_000))); end Hamming;
-- part of ParserTools, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "copying.txt" with Ada.Strings.Hash; package body Text is function "&" (Left, Right : Reference) return String is (Ada.Strings.Unbounded.To_String (Left) & Ada.Strings.Unbounded.To_String (Right)); function Hash (Object : Reference) return Ada.Containers.Hash_Type is (Ada.Strings.Hash (Ada.Strings.Unbounded.To_String (Object))); end Text;
with Arena_Pools; use Arena_Pools; procedure Test_Allocator is Pool : Arena_Pools.Arena (1024); type Integer_Ptr is access Integer; for Integer_Ptr'Storage_Pool use Pool; X : Integer_Ptr := new Integer'(1); Y : Integer_Ptr := new Integer'(2); Z : Integer_Ptr; begin Z := new Integer; Z.all := X.all + Y.all; end Test_Allocator;
----------------------------------------------------------------------- -- awa-wikis-parsers -- Wiki parser -- Copyright (C) 2011, 2012, 2013, 2014, 2015 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- package body AWA.Wikis.Parsers is use AWA.Wikis.Documents; use Ada.Strings.Wide_Wide_Unbounded; -- Peek the next character from the wiki text buffer. procedure Peek (P : in out Parser; Token : out Wide_Wide_Character); -- Put back the character so that it will be returned by the next call to Peek. procedure Put_Back (P : in out Parser; Token : in Wide_Wide_Character); -- Flush the wiki text that was collected in the text buffer. procedure Flush_Text (P : in out Parser); -- Append a character to the wiki text buffer. procedure Parse_Text (P : in out Parser; Token : in Wide_Wide_Character); -- Parse the beginning or the end of a double character sequence. This procedure -- is instantiated for several format types (bold, italic, superscript, subscript, code). -- Example: -- --name-- **bold** ~~strike~~ generic Format : Format_Type; procedure Parse_Double_Format (P : in out Parser; Token : in Wide_Wide_Character); -- Parse the beginning or the end of a single character sequence. This procedure -- is instantiated for several format types (bold, italic, superscript, subscript, code). -- Example: -- _name_ *bold* `code` generic Format : Format_Type; procedure Parse_Single_Format (P : in out Parser; Token : in Wide_Wide_Character); -- Parse an italic, bold or bold + italic sequence. -- Example: -- ''name'' (italic) -- '''name''' (bold) -- '''''name''''' (bold+italic) procedure Parse_Bold_Italic (P : in out Parser; Token : in Wide_Wide_Character); -- Parse a line break. -- Example: -- \\ (Creole) -- %%% (Dotclear) procedure Parse_Line_Break (P : in out Parser; Token : in Wide_Wide_Character); -- Parse a link. -- Example: -- [name] -- [name|url] -- [name|url|language] -- [name|url|language|title] -- [[link]] -- [[link|name]] -- ------------------------------ procedure Parse_Link (P : in out Parser; Token : in Wide_Wide_Character); -- Parse a space and take necessary formatting actions. -- Example: -- item1 item2 => add space in text buffer -- ' * item' => start a bullet list (Google) -- ' # item' => start an ordered list (Google) -- ' item' => preformatted text (Google, Creole) procedure Parse_Space (P : in out Parser; Token : in Wide_Wide_Character); -- Parse a wiki heading. The heading could start with '=' or '!'. -- The trailing equals are ignored. -- Example: -- == Level 2 == -- !!! Level 3 procedure Parse_Header (P : in out Parser; Token : in Wide_Wide_Character); -- Parse an image. -- Example: -- ((url|alt text)) -- ((url|alt text|position)) -- ((url|alt text|position||description)) procedure Parse_Image (P : in out Parser; Token : in Wide_Wide_Character); -- Parse a quote. -- Example: -- {{name}} -- {{name|language}} -- {{name|language|url}} procedure Parse_Quote (P : in out Parser; Token : in Wide_Wide_Character); procedure Parse_Token (P : in out Parser; Table : in Parser_Table); procedure Parse_End_Line (P : in out Parser; Token : in Wide_Wide_Character); procedure Parse_Preformatted (P : in out Parser; Token : in Wide_Wide_Character); -- Parse a blockquote. -- Example: -- >>>quote level 3 -- >>quote level 2 -- >quote level 1 procedure Parse_Blockquote (P : in out Parser; Token : in Wide_Wide_Character); procedure Parse_List (P : in out Parser; Token : in Wide_Wide_Character); procedure Toggle_Format (P : in out Parser; Format : in Format_Type); -- ------------------------------ -- Peek the next character from the wiki text buffer. -- ------------------------------ procedure Peek (P : in out Parser; Token : out Wide_Wide_Character) is begin if P.Has_Pending then -- Return the pending character. Token := P.Pending; P.Has_Pending := False; elsif P.Is_Eof then -- Return a \n on end of file (this simplifies the implementation). Token := LF; else -- Get the next character. P.Reader.Read_Char (Token, P.Is_Eof); if P.Is_Eof then Token := LF; end if; end if; end Peek; -- ------------------------------ -- Put back the character so that it will be returned by the next call to Peek. -- ------------------------------ procedure Put_Back (P : in out Parser; Token : in Wide_Wide_Character) is begin P.Pending := Token; P.Has_Pending := True; end Put_Back; -- ------------------------------ -- Flush the wiki text that was collected in the text buffer. -- ------------------------------ procedure Flush_Text (P : in out Parser) is begin if Length (P.Text) > 0 then P.Document.Add_Text (P.Text, P.Format); P.Text := Null_Unbounded_Wide_Wide_String; end if; end Flush_Text; -- ------------------------------ -- Append a character to the wiki text buffer. -- ------------------------------ procedure Parse_Text (P : in out Parser; Token : in Wide_Wide_Character) is begin Append (P.Text, Token); P.Empty_Line := False; end Parse_Text; -- ------------------------------ -- Parse a pre-formatted text which starts either by a space or by a sequence -- of characters. Example: -- {{{ -- pre-formatted -- }}} -- ' pre-formattted' -- ------------------------------ procedure Parse_Preformatted (P : in out Parser; Token : in Wide_Wide_Character) is C : Wide_Wide_Character; Stop_Token : Wide_Wide_Character; Format : Unbounded_Wide_Wide_String; Col : Natural; begin if Token /= ' ' then Peek (P, C); if C /= Token then Parse_Text (P, Token); Put_Back (P, C); return; end if; Peek (P, C); if C /= Token then Parse_Text (P, Token); Parse_Text (P, Token); Put_Back (P, C); return; end if; elsif not P.Is_Dotclear or else not P.Empty_Line then Parse_Text (P, Token); return; end if; Flush_Text (P); if Token = ' ' then Col := 1; while not P.Is_Eof loop Peek (P, C); if Col = 0 then if C /= ' ' then Put_Back (P, C); exit; end if; Col := Col + 1; elsif C = LF or C = CR then Col := 0; Append (P.Text, C); else Col := Col + 1; Append (P.Text, C); end if; end loop; else Peek (P, C); if Token = '{' then if C /= LF and C /= CR then Put_Back (P, C); P.Format (CODE) := True; return; end if; elsif Token = '}' then Put_Back (P, C); P.Format (CODE) := True; return; elsif Token /= ' ' then while not P.Is_Eof and C /= LF and C /= CR loop Append (Format, C); Peek (P, C); end loop; end if; if Token = '{' then Stop_Token := '}'; else Stop_Token := Token; end if; Col := 0; while not P.Is_Eof loop Peek (P, C); if Stop_Token = C and Col = 0 then Peek (P, C); if C = Stop_Token then Peek (P, C); exit when C = Stop_Token; end if; Append (P.Text, Stop_Token); Col := Col + 1; elsif C = LF or C = CR then Col := 0; else Col := Col + 1; end if; Append (P.Text, C); end loop; end if; P.Empty_Line := True; P.Document.Add_Preformatted (P.Text, Format); P.Text := Null_Unbounded_Wide_Wide_String; P.Document.Add_Paragraph; P.In_Paragraph := True; end Parse_Preformatted; -- ------------------------------ -- Parse a wiki heading. The heading could start with '=' or '!'. -- The trailing equals are ignored. -- Example: -- == Level 2 == -- !!! Level 3 -- ------------------------------ procedure Parse_Header (P : in out Parser; Token : in Wide_Wide_Character) is Header : Unbounded_Wide_Wide_String; C : Wide_Wide_Character; Level : Integer := 1; begin if not P.Empty_Line then Parse_Text (P, Token); return; end if; while Level <= 6 loop Peek (P, C); exit when C /= Token; Level := Level + 1; end loop; -- Ignore spaces after '=' signs while C = ' ' or C = HT loop Peek (P, C); end loop; loop Append (Header, C); Peek (P, C); exit when C = LF or C = CR; end loop; -- Remove the spaces and '=' at end of header string. declare Len : Natural := Length (Header); Ignore_Token : Boolean := True; Seen_Token : Boolean := False; begin while Len > 0 loop C := Element (Header, Len); if C = Token then exit when not Ignore_Token; Seen_Token := True; elsif C = ' ' or C = HT then Ignore_Token := not Seen_Token; else exit; end if; Delete (Header, Len, Len); Len := Len - 1; end loop; end; -- dotclear header is the opposite of Creole for the level. Level := Level + P.Header_Offset; if Level < 0 then Level := -Level; end if; if Level = 0 then Level := 1; end if; Flush_Text (P); P.Document.Add_Header (Header, Level); P.Empty_Line := True; P.In_Paragraph := False; end Parse_Header; -- ------------------------------ -- Parse a link. -- Example: -- [name] -- [name|url] -- [name|url|language] -- [name|url|language|title] -- [[link]] -- [[link|name]] -- ------------------------------ procedure Parse_Link (P : in out Parser; Token : in Wide_Wide_Character) is -- Parse a link component procedure Parse_Link_Token (Into : in out Unbounded_Wide_Wide_String); Link : Unbounded_Wide_Wide_String; Title : Unbounded_Wide_Wide_String; Language : Unbounded_Wide_Wide_String; Link_Title : Unbounded_Wide_Wide_String; C : Wide_Wide_Character; procedure Parse_Link_Token (Into : in out Unbounded_Wide_Wide_String) is begin loop Peek (P, C); if C = P.Escape_Char then Peek (P, C); else exit when C = LF or C = CR or C = ']' or C = '|'; end if; Append (Into, C); end loop; end Parse_Link_Token; begin -- If links have the form '[[link]]', check the second bracket. if P.Link_Double_Bracket then Peek (P, C); if C /= Token then Append (P.Text, Token); Put_Back (P, C); return; end if; end if; Parse_Link_Token (Title); if C = '|' then Parse_Link_Token (Link); if C = '|' then Parse_Link_Token (Language); if C = '|' then Parse_Link_Token (Link_Title); end if; end if; end if; if P.Link_Double_Bracket then Peek (P, C); if C /= ']' then Put_Back (P, C); end if; elsif C /= ']' then Put_Back (P, C); end if; P.Empty_Line := False; Flush_Text (P); P.Document.Add_Link (Title, Link, Language, Link_Title); Peek (P, C); if not P.Is_Eof then if C = CR or C = LF then Append (P.Text, C); end if; Put_Back (P, C); end if; end Parse_Link; -- ------------------------------ -- Parse a quote. -- Example: -- {{name}} -- {{name|language}} -- {{name|language|url}} -- ------------------------------ procedure Parse_Quote (P : in out Parser; Token : in Wide_Wide_Character) is -- Parse a quote component procedure Parse_Quote_Token (Into : in out Unbounded_Wide_Wide_String); Link : Unbounded_Wide_Wide_String; Quote : Unbounded_Wide_Wide_String; Language : Unbounded_Wide_Wide_String; C : Wide_Wide_Character; procedure Parse_Quote_Token (Into : in out Unbounded_Wide_Wide_String) is begin loop Peek (P, C); if C = P.Escape_Char then Peek (P, C); else exit when C = LF or C = CR or C = '}' or C = '|'; end if; Append (Into, C); end loop; end Parse_Quote_Token; begin Peek (P, C); if C /= Token then Append (P.Text, Token); Put_Back (P, C); return; end if; Parse_Quote_Token (Quote); if C = '|' then Parse_Quote_Token (Language); if C = '|' then Parse_Quote_Token (Link); end if; end if; if C /= '}' then Put_Back (P, C); end if; Flush_Text (P); P.Document.Add_Quote (Quote, Link, Language); Peek (P, C); if C /= '}' then Put_Back (P, C); end if; end Parse_Quote; -- ------------------------------ -- Parse an image. -- Example: -- ((url|alt text)) -- ((url|alt text|position)) -- ((url|alt text|position||description)) -- ------------------------------ procedure Parse_Image (P : in out Parser; Token : in Wide_Wide_Character) is -- Parse a image component procedure Parse_Image_Token (Into : in out Unbounded_Wide_Wide_String); Link : Unbounded_Wide_Wide_String; Alt : Unbounded_Wide_Wide_String; Position : Unbounded_Wide_Wide_String; Desc : Unbounded_Wide_Wide_String; C : Wide_Wide_Character; procedure Parse_Image_Token (Into : in out Unbounded_Wide_Wide_String) is begin loop Peek (P, C); if C = P.Escape_Char then Peek (P, C); else exit when C = LF or C = CR or C = ')' or C = '|'; end if; Append (Into, C); end loop; end Parse_Image_Token; begin Peek (P, C); if C /= Token then Append (P.Text, Token); Put_Back (P, C); return; end if; Parse_Image_Token (Link); if C = '|' then Parse_Image_Token (Alt); if C = '|' then Parse_Image_Token (Position); if C = '|' then Parse_Image_Token (Desc); end if; end if; end if; if C /= ')' then Put_Back (P, C); end if; Flush_Text (P); P.Document.Add_Image (Link, Alt, Position, Desc); Peek (P, C); if C /= ')' then Put_Back (P, C); end if; end Parse_Image; procedure Toggle_Format (P : in out Parser; Format : in Format_Type) is begin Flush_Text (P); P.Format (Format) := not P.Format (Format); end Toggle_Format; -- ------------------------------ -- Parse the beginning or the end of a single character sequence. This procedure -- is instantiated for several format types (bold, italic, superscript, subscript, code). -- Example: -- _name_ *bold* `code` -- ------------------------------ procedure Parse_Single_Format (P : in out Parser; Token : in Wide_Wide_Character) is pragma Unreferenced (Token); begin Toggle_Format (P, Format); end Parse_Single_Format; procedure Parse_Single_Italic is new Parse_Single_Format (ITALIC); procedure Parse_Single_Bold is new Parse_Single_Format (BOLD); procedure Parse_Single_Code is new Parse_Single_Format (CODE); procedure Parse_Single_Superscript is new Parse_Single_Format (SUPERSCRIPT); -- procedure Parse_Single_Subscript is new Parse_Single_Format (SUBSCRIPT); -- procedure Parse_Single_Strikeout is new Parse_Single_Format (STRIKEOUT); -- ------------------------------ -- Parse the beginning or the end of a double character sequence. This procedure -- is instantiated for several format types (bold, italic, superscript, subscript, code). -- Example: -- --name-- **bold** ~~strike~~ -- ------------------------------ procedure Parse_Double_Format (P : in out Parser; Token : in Wide_Wide_Character) is C : Wide_Wide_Character; begin Peek (P, C); if C = Token then Toggle_Format (P, Format); else Parse_Text (P, Token); Put_Back (P, C); end if; end Parse_Double_Format; procedure Parse_Double_Italic is new Parse_Double_Format (ITALIC); procedure Parse_Double_Bold is new Parse_Double_Format (BOLD); procedure Parse_Double_Code is new Parse_Double_Format (CODE); -- procedure Parse_Double_Superscript is new Parse_Double_Format (SUPERSCRIPT); procedure Parse_Double_Subscript is new Parse_Double_Format (SUBSCRIPT); procedure Parse_Double_Strikeout is new Parse_Double_Format (STRIKEOUT); -- ------------------------------ -- Parse an italic, bold or bold + italic sequence. -- Example: -- ''name'' (italic) -- '''name''' (bold) -- '''''name''''' (bold+italic) -- ------------------------------ procedure Parse_Bold_Italic (P : in out Parser; Token : in Wide_Wide_Character) is C : Wide_Wide_Character; Count : Natural := 1; begin loop Peek (P, C); exit when C /= Token; Count := Count + 1; end loop; if Count > 10 then Count := Count mod 10; if Count = 0 then Put_Back (P, C); return; end if; end if; case Count is when 1 => Parse_Text (P, Token); when 2 => Toggle_Format (P, ITALIC); when 3 => Toggle_Format (P, BOLD); when 4 => Toggle_Format (P, BOLD); Parse_Text (P, Token); when 5 => Toggle_Format (P, BOLD); Toggle_Format (P, ITALIC); when others => null; end case; Put_Back (P, C); end Parse_Bold_Italic; procedure Parse_List (P : in out Parser; Token : in Wide_Wide_Character) is C : Wide_Wide_Character; Level : Natural := 1; begin if not P.Empty_Line then Parse_Text (P, Token); return; end if; loop Peek (P, C); exit when C /= '#' and C /= '*'; Level := Level + 1; end loop; Flush_Text (P); P.Document.Add_List_Item (Level, Token = '#'); -- Ignore the first white space after the list item. if C /= ' ' and C /= HT then Put_Back (P, C); end if; end Parse_List; -- ------------------------------ -- Parse a blockquote. -- Example: -- >>>quote level 3 -- >>quote level 2 -- >quote level 1 -- ------------------------------ procedure Parse_Blockquote (P : in out Parser; Token : in Wide_Wide_Character) is C : Wide_Wide_Character; Level : Natural := 1; begin if not P.Empty_Line then Parse_Text (P, Token); return; end if; loop Peek (P, C); exit when C /= '>'; Level := Level + 1; end loop; Flush_Text (P); P.Empty_Line := True; P.Quote_Level := Level; P.Document.Add_Blockquote (Level); -- Ignore the first white space after the quote character. if C /= ' ' and C /= HT then Put_Back (P, C); end if; end Parse_Blockquote; -- ------------------------------ -- Parse a space and take necessary formatting actions. -- Example: -- item1 item2 => add space in text buffer -- ' * item' => start a bullet list (Google) -- ' # item' => start an ordered list (Google) -- ' item' => preformatted text (Google, Creole) -- ------------------------------ procedure Parse_Space (P : in out Parser; Token : in Wide_Wide_Character) is C : Wide_Wide_Character; begin if P.Empty_Line then loop Peek (P, C); exit when C /= ' ' and C /= HT; end loop; if C = '*' or C = '#' then Parse_List (P, C); elsif C = CR or C = LF then Parse_End_Line (P, C); else Put_Back (P, C); Parse_Preformatted (P, Token); end if; else Append (P.Text, Token); end if; end Parse_Space; procedure Parse_End_Line (P : in out Parser; Token : in Wide_Wide_Character) is C : Wide_Wide_Character := Token; Count : Positive := 1; begin if P.Is_Eof then return; end if; while not P.Is_Eof loop Peek (P, C); exit when C /= CR and C /= LF; if C = Token then Count := Count + 1; end if; end loop; Put_Back (P, C); if Count >= 2 then Flush_Text (P); -- Finish the active blockquotes if a new paragraph is started on an empty line. if P.Quote_Level > 0 then P.Document.Add_Blockquote (0); P.Quote_Level := 0; end if; P.Document.Add_Paragraph; P.In_Paragraph := True; elsif Length (P.Text) > 0 or not P.Empty_Line then Append (P.Text, Token); end if; -- Finish the active blockquotes if a new paragraph is started immediately after -- the blockquote. if P.Quote_Level > 0 and C /= '>' then Flush_Text (P); P.Document.Add_Blockquote (0); P.Quote_Level := 0; end if; P.Empty_Line := True; end Parse_End_Line; -- ------------------------------ -- Parse a line break. -- Example: -- \\ (Creole) -- %%% (Dotclear) -- ------------------------------ procedure Parse_Line_Break (P : in out Parser; Token : in Wide_Wide_Character) is C : Wide_Wide_Character; begin Peek (P, C); -- Check for escape character if Token = P.Escape_Char then Parse_Text (P, C); return; end if; if C /= Token then Parse_Text (P, Token); Put_Back (P, C); return; end if; -- Check for a third '%'. if P.Is_Dotclear then Peek (P, C); if C /= Token then Parse_Text (P, Token); Parse_Text (P, Token); Put_Back (P, C); return; end if; end if; P.Empty_Line := True; Flush_Text (P); P.Document.Add_Line_Break; end Parse_Line_Break; Google_Wiki_Table : constant Parser_Table := ( 16#0A# => Parse_End_Line'Access, 16#0D# => Parse_End_Line'Access, Character'Pos (' ') => Parse_Space'Access, Character'Pos ('=') => Parse_Header'Access, Character'Pos ('*') => Parse_Single_Bold'Access, Character'Pos ('_') => Parse_Single_Italic'Access, Character'Pos ('`') => Parse_Single_Code'Access, Character'Pos ('^') => Parse_Single_Superscript'Access, Character'Pos ('~') => Parse_Double_Strikeout'Access, Character'Pos (',') => Parse_Double_Subscript'Access, Character'Pos ('[') => Parse_Link'Access, Character'Pos ('\') => Parse_Line_Break'Access, Character'Pos ('#') => Parse_List'Access, Character'Pos ('{') => Parse_Preformatted'Access, Character'Pos ('}') => Parse_Preformatted'Access, others => Parse_Text'Access ); Dotclear_Wiki_Table : constant Parser_Table := ( 16#0A# => Parse_End_Line'Access, 16#0D# => Parse_End_Line'Access, Character'Pos (' ') => Parse_Space'Access, Character'Pos ('!') => Parse_Header'Access, Character'Pos ('_') => Parse_Double_Bold'Access, Character'Pos (''') => Parse_Double_Italic'Access, Character'Pos ('@') => Parse_Double_Code'Access, Character'Pos ('^') => Parse_Single_Superscript'Access, Character'Pos ('-') => Parse_Double_Strikeout'Access, Character'Pos ('+') => Parse_Double_Strikeout'Access, Character'Pos (',') => Parse_Double_Subscript'Access, Character'Pos ('[') => Parse_Link'Access, Character'Pos ('\') => Parse_Line_Break'Access, Character'Pos ('{') => Parse_Quote'Access, Character'Pos ('#') => Parse_List'Access, Character'Pos ('*') => Parse_List'Access, Character'Pos ('(') => Parse_Image'Access, Character'Pos ('/') => Parse_Preformatted'Access, Character'Pos ('%') => Parse_Line_Break'Access, Character'Pos ('>') => Parse_Blockquote'Access, others => Parse_Text'Access ); Creole_Wiki_Table : constant Parser_Table := ( 16#0A# => Parse_End_Line'Access, 16#0D# => Parse_End_Line'Access, Character'Pos (' ') => Parse_Space'Access, Character'Pos ('=') => Parse_Header'Access, Character'Pos ('*') => Parse_Double_Bold'Access, Character'Pos ('/') => Parse_Double_Italic'Access, Character'Pos ('@') => Parse_Double_Code'Access, Character'Pos ('^') => Parse_Single_Superscript'Access, Character'Pos ('-') => Parse_Double_Strikeout'Access, Character'Pos ('+') => Parse_Double_Strikeout'Access, Character'Pos (',') => Parse_Double_Subscript'Access, Character'Pos ('[') => Parse_Link'Access, Character'Pos ('\') => Parse_Line_Break'Access, Character'Pos ('#') => Parse_List'Access, Character'Pos ('{') => Parse_Image'Access, Character'Pos ('%') => Parse_Line_Break'Access, others => Parse_Text'Access ); Mediawiki_Wiki_Table : constant Parser_Table := ( 16#0A# => Parse_End_Line'Access, 16#0D# => Parse_End_Line'Access, Character'Pos (' ') => Parse_Space'Access, Character'Pos ('=') => Parse_Header'Access, Character'Pos (''') => Parse_Bold_Italic'Access, Character'Pos ('[') => Parse_Link'Access, Character'Pos ('\') => Parse_Line_Break'Access, Character'Pos ('{') => Parse_Quote'Access, Character'Pos ('#') => Parse_List'Access, Character'Pos ('*') => Parse_List'Access, others => Parse_Text'Access ); Misc_Wiki_Table : constant Parser_Table := ( 16#0A# => Parse_End_Line'Access, 16#0D# => Parse_End_Line'Access, Character'Pos (' ') => Parse_Space'Access, Character'Pos ('=') => Parse_Header'Access, Character'Pos ('*') => Parse_Single_Bold'Access, Character'Pos ('_') => Parse_Single_Italic'Access, Character'Pos ('`') => Parse_Single_Code'Access, Character'Pos ('^') => Parse_Single_Superscript'Access, Character'Pos ('~') => Parse_Double_Strikeout'Access, Character'Pos (',') => Parse_Double_Subscript'Access, Character'Pos ('[') => Parse_Link'Access, Character'Pos ('\') => Parse_Line_Break'Access, Character'Pos ('#') => Parse_List'Access, Character'Pos ('@') => Parse_Double_Code'Access, others => Parse_Text'Access ); -- ------------------------------ -- Parse the wiki text contained in <b>Text</b> according to the wiki syntax -- specified in <b>Syntax</b> and invoke the document reader procedures defined -- by <b>into</b>. -- ------------------------------ procedure Parse (Into : in AWA.Wikis.Documents.Document_Reader_Access; Text : in Wide_Wide_String; Syntax : in Wiki_Syntax_Type := SYNTAX_MIX) is type Wide_Input is new Input with record Pos : Positive; end record; procedure Read_Char (Buf : in out Wide_Input; Token : out Wide_Wide_Character; Is_Eof : out Boolean); procedure Read_Char (Buf : in out Wide_Input; Token : out Wide_Wide_Character; Is_Eof : out Boolean) is begin if Buf.Pos > Text'Last then Is_Eof := True; Token := CR; else Token := Text (Buf.Pos); Buf.Pos := Buf.Pos + 1; Is_Eof := False; end if; end Read_Char; P : Parser; Buffer : aliased Wide_Input; begin Buffer.Pos := Text'First; P.Document := Into; P.Empty_Line := True; P.Format := (others => False); P.Is_Eof := False; P.Has_Pending := False; P.Reader := Buffer'Unchecked_Access; P.Link_Double_Bracket := False; P.Escape_Char := '~'; case Syntax is when SYNTAX_GOOGLE => Parse_Token (P, Google_Wiki_Table); when SYNTAX_DOTCLEAR => P.Is_Dotclear := True; P.Escape_Char := '\'; P.Header_Offset := -6; Parse_Token (P, Dotclear_Wiki_Table); when SYNTAX_CREOLE => P.Link_Double_Bracket := True; Parse_Token (P, Creole_Wiki_Table); when SYNTAX_MEDIA_WIKI | SYNTAX_PHPBB => Parse_Token (P, Mediawiki_Wiki_Table); when SYNTAX_MIX => P.Is_Dotclear := True; Parse_Token (P, Misc_Wiki_Table); end case; end Parse; procedure Parse_Token (P : in out Parser; Table : in Parser_Table) is C : Wide_Wide_Character; begin P.Document.Add_Paragraph; P.In_Paragraph := True; while not P.Is_Eof loop Peek (P, C); if C > '~' then Parse_Text (P, C); else Table (Wide_Wide_Character'Pos (C)).all (P, C); end if; end loop; Flush_Text (P); P.Document.Finish; end Parse_Token; end AWA.Wikis.Parsers;
with Ada.Text_IO; use Ada.Text_IO; with Ada.Numerics.Discrete_Random; procedure Test_Bogosort is generic type Ordered is private; type List is array (Positive range <>) of Ordered; with function "<" (L, R : Ordered) return Boolean is <>; procedure Bogosort (Data : in out List); procedure Bogosort (Data : in out List) is function Sorted return Boolean is begin for I in Data'First..Data'Last - 1 loop if not (Data (I) < Data (I + 1)) then return False; end if; end loop; return True; end Sorted; subtype Index is Integer range Data'Range; package Dices is new Ada.Numerics.Discrete_Random (Index); use Dices; Dice : Generator; procedure Shuffle is J : Index; Temp : Ordered; begin for I in Data'Range loop J := Random (Dice); Temp := Data (I); Data (I) := Data (J); Data (J) := Temp; end loop; end Shuffle; begin while not Sorted loop Shuffle; end loop; end Bogosort; type List is array (Positive range <>) of Integer; procedure Integer_Bogosort is new Bogosort (Integer, List); Sequence : List := (7,6,3,9); begin Integer_Bogosort (Sequence); for I in Sequence'Range loop Put (Integer'Image (Sequence (I))); end loop; end Test_Bogosort;
-- { dg-do run } -- { dg-options "-gnat12 -gnatVa" } procedure In_Out_Parameter4 is type Enum is (E_Undetermined, E_Down, E_Up); subtype Status_T is Enum range E_Down .. E_Up; function Recurse (Val : in out Integer) return Status_T is Result : Status_T; procedure Dummy (I : in out Integer) is begin null; end; begin if Val > 500 then Val := Val - 1; Result := Recurse (Val); return Result; else return E_UP; end if; end; Val : Integer := 501; S : Status_T; begin S := Recurse (Val); end;
with Ada.Command_Line; package body MyCommandLine is -- note we do not want SPARK to analyse this implementation since -- Ada.Command_Line is not able to be handled by the SPARK Prover function Command_Name return String is begin return Ada.Command_Line.Command_Name; end Command_Name; function Argument_Count return Natural is begin return Ada.Command_Line.Argument_Count; end Argument_Count; function Argument(Number : in Positive) return String is begin return Ada.Command_Line.Argument(Number); end Argument; end MyCommandLine;
-- Standard Ada library specification -- Copyright (c) 2003-2018 Maxim Reznik <reznikmm@gmail.com> -- Copyright (c) 2004-2016 AXE Consultants -- Copyright (c) 2004, 2005, 2006 Ada-Europe -- Copyright (c) 2000 The MITRE Corporation, Inc. -- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc. -- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual --------------------------------------------------------------------------- generic type Real is digits <>; package Ada.Numerics.Generic_Real_Arrays is pragma Pure (Generic_Real_Arrays); -- Types type Real_Vector is array (Integer range <>) of Real'Base; type Real_Matrix is array (Integer range <>, Integer range <>) of Real'Base; -- Subprograms for Real_Vector types -- Real_Vector arithmetic operations function "+" (Right : in Real_Vector) return Real_Vector; function "-" (Right : in Real_Vector) return Real_Vector; function "abs" (Right : in Real_Vector) return Real_Vector; function "+" (Left : in Real_Vector; Right : Real_Vector) return Real_Vector; function "-" (Left : in Real_Vector; Right : Real_Vector) return Real_Vector; function "*" (Left : in Real_Vector; Right : Real_Vector) return Real'Base; function "abs" (Right : in Real_Vector) return Real'Base; -- Real_Vector scaling operations function "*" (Left : in Real'Base; Right : in Real_Vector) return Real_Vector; function "*" (Left : in Real_Vector; Right : in Real'Base) return Real_Vector; function "/" (Left : in Real_Vector; Right : in Real'Base) return Real_Vector; -- Other Real_Vector operations function Unit_Vector (Index : in Integer; Order : in Positive; First : in Integer := 1) return Real_Vector; -- Subprograms for Real_Matrix types -- Real_Matrix arithmetic operations function "+" (Right : in Real_Matrix) return Real_Matrix; function "-" (Right : in Real_Matrix) return Real_Matrix; function "abs" (Right : in Real_Matrix) return Real_Matrix; function Transpose (X : in Real_Matrix) return Real_Matrix; function "+" (Left : in Real_Matrix; Right : in Real_Matrix) return Real_Matrix; function "-" (Left : in Real_Matrix; Right : in Real_Matrix) return Real_Matrix; function "*" (Left : in Real_Matrix; Right : in Real_Matrix) return Real_Matrix; function "*" (Left : in Real_Matrix; Right : in Real_Vector) return Real_Matrix; function "*" (Left : in Real_Vector; Right : in Real_Matrix) return Real_Vector; function "*" (Left : in Real_Matrix; Right : in Real_Vector) return Real_Vector; -- Real_Matrix scaling operations function "*" (Left : in Real'Base; Right : in Real_Matrix) return Real_Matrix; function "*" (Left : in Real_Matrix; Right : in Real'Base) return Real_Matrix; function "/" (Left : in Real_Matrix; Right : in Real'Base) return Real_Matrix; -- Real_Matrix inversion and related operations function Solve (A : in Real_Matrix; X : in Real_Vector) return Real_Vector; function Solve (A : in Real_Matrix; X : in Real_Matrix) return Real_Matrix; function Inverse (A : in Real_Matrix) return Real_Matrix; function Determinant (A : in Real_Matrix) return Real'Base; -- Eigenvalues and vectors of a real symmetric matrix function Eigenvalues (A : in Real_Matrix) return Real_Vector; procedure Eigensystem (A : in Real_Matrix; Values : out Real_Vector; Vectors : out Real_Matrix); -- Other Real_Matrix operations function Unit_Matrix (Order : Positive; First_1 : Integer := 1; First_2 : Integer := 1) return Real_Matrix; end Ada.Numerics.Generic_Real_Arrays;
with Ada.Real_Time; use Ada.Real_Time; with Ada.Text_IO;use Ada.Text_IO; with Ada.Dispatching; use Ada.Dispatching; procedure Periodic is Interval : Time_Span := Milliseconds(30); Next : Time; begin Next := Clock + Interval; loop Put_Line("Delay 30 ms" ); delay until Next; Next := Next + Interval; end loop; end Periodic;
------------------------------------------------------------------------------ -- -- -- JSON Parser/Constructor -- -- -- -- ------------------------------------------------------------------------ -- -- -- -- Copyright (C) 2020-2021, ANNEXI-STRAYLINE Trans-Human Ltd. -- -- All rights reserved. -- -- -- -- Original Contributors: -- -- * Richard Wai (ANNEXI-STRAYLINE) -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- -- -- * Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- This package implements the JSON parser finite state machine used by -- both codec deserialization private generic type JSON_String_Buffer is limited private; type JSON_String_Buffer_Config is private; -- A buffer in which to store member names and string values during -- parsing. -- -- This is also the value that is Export'ed for string outputs and -- member names. -- -- If an exception is raised when executing any of the following operations, -- the parser halts with an appropriate error condition. with procedure Setup_Buffer (Target: in out JSON_String_Buffer; Config: in JSON_String_Buffer_Config) is null; -- Setup_Buffer will be invoked by the Parser_FSM's Setup_Buffers operation, -- on each internal buffer. Config will be transfered from Setup_Buffers. -- This is specifically to allow the Unbounded_Codec's custom Slab_Strings. with procedure Clear (Target: in out JSON_String_Buffer); with procedure Append (Target: in out JSON_String_Buffer; Source: in JSON_String_Value); with procedure Export (Source: in out JSON_String_Buffer; Target: out JSON_String_Buffer); -- Export shall copy the contents of Source to Target, and may or may not -- Clear Source. Clear will be invoked under the assumption that Export -- Does NOT clear Source. String_Chunk_Size: in Positive := 100; -- The size of an internal state buffer that is filled before being -- appended to a JSON_String_Buffer. Larger sizes will minimze the -- number of calls to Append, with the trade off of a proportionatly -- increased size of Parser_State package JSON.Parser_Machine is -- Basic operation: When intialized or Reset, the FSM is expecting any valid -- structure start ('{' or '['), after which time it issues a Push. This is -- the "Root" item of the blob. -- -- Note that the parser will indicate Done once it encouteres the matching -- "Pop" condition, instead of indicating Pop. type Parser_FSM is limited private; type Operator_Indication is (Ready, -- Machine is happy, but has nothing to output yet. Additional input -- should be fed into the machine until the indication changes. Output_Member, -- Machine has completed the parse of a new non-structural member value -- that must be extracted from the machine and appended to the current -- branch of the deserialized tree. -- -- Legal JSON requires that all object members have a name. The machine -- has therefore parsed the members name, which can be extracted via -- Member_Name. -- -- The Value can be extracted via Output_Kind and Output_Value -- -- After obtaining the output, the operator should continue with the -- next Feed Output_Element, -- Machine has encountered the next element of the current array, which -- can be extracted via Value_Kind and Value. Array elements cannot have -- names, and so the operator must not invoke Push, -- Machine has encountered a new object or array which should be appended -- to the current tree, and forms a parent node for a new branch upon -- which subsequent Extract values should be appended. -- -- The operator can query the type of the new child structure via -- Current_Structure_Kind. If the new structure was a member of an -- object, the name (which is required for valid JSON), can be extracted -- via Output_Name -- -- After preparing the new branch, the operator should continue with the -- next Feed Pop, -- Machine has encountered the end of the object or array that is the -- current branch of the deserialized tree (but not the branch under -- root). Subsequent Extract values should be appended to the branch -- containing the parent node of the current (pre-Pop) branch. -- -- After returning to the parent branch, the operator must invoked -- Acknowledge_Pop before continuing with the next Feed Done, -- The parser has completed deserializing an entire JSON object. Invalid); -- Invalid: The input was found to be invalid. procedure Setup_Buffers (Machine: in out Parser_FSM; Config : in JSON_String_Buffer_Config); -- This loads Config into Machine, and invokes Setup_Buffer on all internal -- State machine buffers. This procedure only needs to be called if -- Setup_Buffer needs to be called for declared JSON_String_Buffer objects -- -- This does NOT need to be invoked after a Reset procedure Configure_Limits (Machine: in out Parser_FSM; Limits : in Codec_Limits); -- Configures Limits for the Machine. This configuration is NOT cleared on -- Reset (Limits cannot be cleared if set) function Last_Indication (Machine: Parser_FSM) return Operator_Indication; -- Returns the "current" indication of the Machine, which was set after the -- last operation where Indication is an out parameter. type Text_Position is record Line : Positive := 1; Column: Integer := 0; Overflow: Boolean := False; -- If Line/Column reach their limits, Overflow is set to True, -- and no further attempt is made to increment the overflowed -- value (which will be at Positive/Natural'Last). This is to -- prevent potential large json strings that could "wrongly" -- (and inexplicably) invalidate the machine due to an -- exception end record; function Last_Position (Machine: Parser_FSM) return Text_Position; -- Returns the total number of characters fed into the FSM since it was -- last initialized/reset. This will be the last inputted character of the -- serialized JSON text function Current_Structure_Kind (Machine: Parser_FSM) return JSON_Structure_Kind; -- Returns that kind of structure the Machine belives it is currently -- "inside" of. procedure Feed (Machine : in out Parser_FSM; Input : in Wide_Wide_Character; Indication: out Operator_Indication) with Pre => Last_Indication (Machine) = Ready; -- Feed shall be called sequentially with the next character of the -- JSON object string after reacting to Indication as appropriate, -- until Indication is Pop, Output, or Push (which requires special operator -- action and acknowledment), or Halt (which indicates the parsing cannot -- continue). -- -- If Indication is not Ready, the machine operator must act on -- the indication before executing the next Feed procedure Acknowledge_Pop (Machine : in out Parser_FSM; Popped_To : in JSON_Structure_Kind; Indication: out Operator_Indication) with Pre => Last_Indication (Machine) = Pop, Post => Indication = Ready and Current_Structure_Kind (Machine) = Popped_To; -- Must be called when the Indication is Pop. Popped_To shall be the -- kind of the level popped to. See the Pop Operator_Indication value above. -- -- This implicitly causes the Indication to transition from Pop to Ready. procedure Acknowledge_Push (Machine : in out Parser_FSM; Indication: out Operator_Indication) with Pre => Last_Indication (Machine) = Push, Post => Indication = Ready; -- Must be called when the Indication is Push. Push_Kind is the kind of the -- structure that should be pushed downed into before proceeding. -- -- This implicitly causes the Indication to transition from Pop to Ready. procedure Output_Name (Machine: in out Parser_FSM; Target : out JSON_String_Buffer) with Pre => Last_Indication (Machine) in Output_Member | Push; -- Name is cleared during this operation (Export is invoked for the internal -- buffer -> Target). -- -- Output_Name should only be invoked when Indication = Output_Member, -- or Indication = Push and the "previous" level (pre-push) is a -- JSON_Object. These must be checked by the operator, or subsequent name -- output may be corrupted function Output_Kind (Machine: Parser_FSM) return JSON_Value_Kind with Pre => Last_Indication (Machine) in Output_Member | Output_Element, Post => Output_Kind'Result not in JSON_Structure_Kind; procedure Output_Value (Machine: in out Parser_FSM; Target : out JSON_String_Buffer) with Pre => Output_Kind (Machine) = JSON_String; -- The output is cleared with this operation, but the output must still be -- Acknowledged function Output_Value (Machine: Parser_FSM) return Boolean with Pre => Output_Kind (Machine) = JSON_Boolean; function Output_Value (Machine: Parser_FSM) return JSON_Integer_Value with Pre => Output_Kind (Machine) = JSON_Integer; function Output_Value (Machine: Parser_FSM) return JSON_Float_Value with Pre => Output_Kind (Machine) = JSON_Float; procedure Acknowledge_Output (Machine : in out Parser_FSM; Indication: out Operator_Indication) with Pre => Last_Indication (Machine) in Output_Member | Output_Element, Post => Indication in Invalid | Ready | Pop; -- Must be called when the Indication is Output_Member or Output_Element. -- The output value can be obtained through the relevent operations before -- the output is acknowledged. function Invalid_Reason (Machine: Parser_FSM) return String with Pre => Last_Indication (Machine) = Invalid; -- Returns a string describing the invalidating condition that halted the -- machine procedure Emergency_Stop (Machine: in out Parser_FSM) with Post => Last_Indication (Machine) = Invalid; -- Causes the FSM to immediately become Invalid, but only if it was not -- already Invalid or Done. Invalid_Reason will return -- "Operator invoked Emergency Stop." procedure Reset (Machine: in out Parser_FSM) with Post => Last_Indication (Machine) = Ready; -- Resets the machine state only. This means that any configured limits -- remain. JSON_String_Buffers are NOT cleared, but if underlying -- storage needs to be reclaimed, it is safe to re-invoke Setup_Buffers -- after Reset. Such buffers will be cleared when first used after a -- Reset. -- -- Setup_Buffers should be invoked after Reset. private Integer_Max: constant := JSON_Integer_Value'Wide_Wide_Width; Float_Max : constant := JSON_Float_Value'Wide_Wide_Width; type Machine_State is -- All expected input is explicitly specified (including ignoring of -- Whitespace). Any input not specified by each state always causes: -- -- State -> Halt, -- Indication -> Invalid (Start_Value, -- Machine is expecting the start of a value (any JSON_Value_Kind), -- after skipping any whitespace -- -- '{': -- Level -> Level + 1 -- Level_Kind -> JSON_Object -- In_Name -> True -- State -> Output -- Indication -> Push -- -- '[': -- Level -> Level + 1 -- Level_Kind -> JSON_Array -- In_Name -> False -- State -> Output -- Indication -> Push -- -- (If Level = 0, then only '{' or '[' are accepted) -- -- 'n': -- State -> In_Null (tail feed) -- -- 't': -- State -> In_True (tail feed) -- -- 'f': -- State -> In_False (tail feed) -- -- '-' | '0-9': -- State -> In_Integer (tail feed) -- -- '"': -- State -> In_String -- Indication -> Ready In_Null, -- Continue to fill Code_Buffer expecting to build towards a contents -- of exactly "null" -- -- (Acceptible input): -- Indication -> Ready -- -- ',' | '}' | ']': -- State -> Output -- Indication -> Output_Member/Element In_True, -- Continue to fill Code_Buffer expecting to build towards a contents -- of exactly "true" -- -- (Acceptible input): -- Indication -> Ready -- -- ',' | '}' | ']': -- State -> Output -- Indication -> Output_Member/Element In_False, -- Continue to fill Code_Buffer expecting to build towards a contents -- of exactly "false" -- -- (Acceptible input): -- Indication -> Ready -- -- ',' | '}' | ']': -- State -> Output -- Indication -> Output_Member/Element In_Integer, -- Expecting a JSON_Integer value. Note that JSON_Integer and JSON_Float -- literals are essentially compatible with Ada numeric literals, except -- that exponent is always 'E' (never 'e') -- -- ['0']: -- (assert if IB_Level = IB'First then IB(IB'First) /= '0') -- Indication -> Ready -- -- ['1' - '9']: -- Indication -> Ready -- -- '-': -- (assert IB_Level = IB'First - 1) -- Indication -> Ready -- -- '.': -- State -> In_Float -- Indication -> Ready -- -- 'e' | 'E': -- State -> In_Integer_Exponent -- Indication -> Ready -- -- ',' | ']' | '}' -- State -> Ouput -- Indication -> Output_Member/Element In_Float, -- Before transitioning to this state, In_Integer has already copied the -- buffer to the float buffer, and has appended the decimal point. This -- state simply collects the fractional value -- -- ['0' - '9']: -- Indication -> Ready -- -- 'e' | 'E': -- State -> In_Float_Exponent -- Indication -> Ready In_Integer_Exponent, -- This is a special case, but allowed by JSON. An example is "1E100". -- This is not a valid Ada literal, so the state machine will attempt to -- convert the exponent value into a corresponding number of zeros that -- are appended to the literal. -- -- If '-' follows 'e', "e-" is replaced with ".0e-", and the state is -- set to be In_Float_Exponent -- -- '-': -- State -> In_Float_Exponent -- -- ',' | ']' | '}': -- State -> Output -- Indication -> Output_Member/Element -- In_Float_Exponent, -- Following 'e', we continue to copy in a valid exponent value -- -- ['-' | '+' | '0' - '9']: -- Indication -> Ready -- -- ',' | ']' | '}': -- State -> Output -- Indication -> Output_Member/Element Start_String, -- Expecting the start of a string. Whitespace is ignored -- -- '"': -- State -> In_String -- Indication -> Ready In_String, -- We are inside of a string. -- -- '"': -- State -> -- In_Name = True? -- In_Name -> False, -- State -> After_Name -- Indication -> Ready -- In_Name = False? -- State -> Output -- Indication -> Output_(Member/Element) -- -- '\': -- State -> In_String_Escape In_String_Escape, -- We are expecting a valid escape sequence, which -- will get built up into Code_Buffer iff Input is not one of the valid -- escaped characters. -- -- [Any valy valid escaped character]: -- State -> In_String -- -- 'u': -- CB_Level -> 0 -- State -> In_Unicode_Escape -- -- Indication -> Ready In_Unicode_Escape, -- We are expecting exactly a 4-digit hexadecimal string. -- -- [hex digit]: -- CB_Level = < 4? -- State -> In_Unicode_Escape -- CB_Level = 4 -- State -> In_String -- -- Indication -> Ready After_Name, -- We are expecting a ':', ignoring Whitespace. -- -- ':': -- In_Name -> False, -- State -> Start_Value, -- Indication -> Ready End_Value, -- Entered from Acknowledge_Output or Acknowledge_Pop -- -- Depending on the Kind of the acknowledge condition, End_Value -- decides if it should transition into After_Value on next feed, -- or immediately with a tail feed -- -- For strings, literals, and pops, After_Value requires a new -- feed. -- -- For numbers After_Value takes a tail-feed. -- -- This logic could have just been put in Acknowledge_Output or -- Acknowledge_Pop, but it seemd more proper to keeps as much of -- the state transition logic in one place as possible -- (Acknowledge_Push is a notable exception) After_Push, -- Entered from Acknowledge_Push, requiring a new feed. -- The purpose of this state is to accomodate empty structures. -- -- Ignoring whitespace. -- -- ']' | '}': -- State -> After_Value (tail feed) -- -- (others): -- State -> Start_Value (tail feed) After_Value, -- We are expecting ',', ']', or '}', ignoring Whitepace. -- -- ',': -- Level_Kind = JSON_Object? -- In_Name -> True -- State -> Start_String -- -- Level_Kind = JSON_Array? -- In_Name -> False -- State -> Start_Value -- -- Indication -> Ready -- -- ']': -- (Assert Level_Kind = JSON_Array) -- State -> Output -- Indication -> Pop -- -- '}': -- (Assert Level_Kind = JSON_Object) -- State -> Output -- Indication -> Pop Output, -- We are waiting for the user to obtain the last value, after which -- we can transition into After_Value directly Halt); -- Feed never enters on this state. -- Indication informs the reason for Halt, and should be either -- Done, or Invalid type Parser_FSM is limited record State : Machine_State := Start_Value; Indication: Operator_Indication := Ready; Error : access constant String := null; Input : Wide_Wide_Character; Position : Text_Position; -- Position indicates the position in the JSON stream of the most -- Recently inputed character. Position is incremented on entry to -- Feed, and can be used to identify offending input for invalid -- JSON streams Last_Was_CR: Boolean := False; -- Last_Was_CR is set to True if the previous Input was -- Carriage_Return, and State does not indicate that the machine is -- currently processing a string value. This is used to collapse a -- CR+LF sequence in whitespace, and increment Position.Line -- appropriately. This value is always set to False after processing -- new Input, unless it is a CR character. This value is used and -- modified by Feed only, and the state machine itself does not regard -- it. -- -- Input is always passed to the FSM which decides if the input is -- legal. Last_Was_CR is only used to decide when to (and when not to) -- increment the Position.Line value. Invalid sequences like a single -- CR or CR+LF will probably mangle the position counter, but if are -- valid JSON, will not invalidate the FSM. Level : Natural := 0; Level_Kind: JSON_Structure_Kind := JSON_Object; -- Current tree level and kind Value_Kind : JSON_Value_Kind; In_Name : Boolean; Name_Output : JSON_String_Buffer; Boolean_Output: Boolean; String_Output: JSON_String_Buffer; -- Contains accepted String value input Scratch_Buffer: JSON_String_Value (1 .. String_Chunk_Size); SB_Level: Natural; Code_Buffer: Wide_Wide_String (1 .. 6); CB_Level: Natural; -- Buffers input that is expected to be -- * A unicode excape sequence ("\u0000") -- * "true", "false" or "null" -- -- It might be possible to use the Scratch_Buffer for the needs -- of Code_Buffer, but doing so would be needlessly (probably -- dangerously) complex. Integer_Buffer: Wide_Wide_String (1 .. Integer_Max); IB_Level: Natural; Integer_Output: JSON_Integer_Value; -- Buffers the input specific to an Integer value Float_Buffer: Wide_Wide_String (1 .. Float_Max); FB_Level: Natural; Float_Output: JSON_Float_Value; Limits : Codec_Limits; Limits_Enabled: Boolean := False; -- Limits to be enforced by the machine String_Total: Natural := 0; -- The current number of characters within the string currently being -- deserialized (In_String et all), either a name or value. This is -- used to compare against the specified Limits, if enabled. Entity_Total: Natural := 0; -- The total number of output cycles (values parsed) since the -- machines was initialized. This is used to compare against the -- specified Limits, if enabled. end record; end JSON.Parser_Machine;
----------------------------------------------------------------------- -- GtkAda - Ada95 binding for Gtk+/Gnome -- -- -- -- Copyright (C) 2010-2011, AdaCore -- -- -- -- This library is free software; you can redistribute it and/or -- -- modify it under the terms of the GNU General Public -- -- License as published by the Free Software Foundation; either -- -- version 2 of the License, or (at your option) any later version. -- -- -- -- This library 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 along with this library; if not, write to the -- -- Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- -- Boston, MA 02111-1307, USA. -- -- -- ----------------------------------------------------------------------- -- <description> -- Gtk.Builder - Build an interface from an XML UI definition as produced by -- the Glade-3 GUI builder. -- -- Note that GtkAda provides a higher-level API for using the GUI builder, -- in Gtkada.Builder. -- -- A Gtk_Builder is an auxiliary object that reads textual descriptions of a -- user interface and instantiates the described objects. To pass a -- description to a Gtk_Builder, call Add_From_File or Add_From_String. -- These subprograms can be called multiple times; the builder merges the -- content of all descriptions. -- -- A Gtk_Builder holds a reference to all objects that it has constructed and -- drops these references when it is finalized. This finalization can cause -- the destruction of non-widget objects or widgets which are not contained -- in a toplevel window. For toplevel windows constructed by a builder, it is -- the responsibility of the user to call Gtk.Widget.Destroy to get rid of -- them and all the widgets they contain. -- -- The subprograms Get_Object and Get_Widget can be used to access the widgets -- in the interface by the names assigned to them inside the UI description. -- Toplevel windows returned by this subprogram will stay around until the -- user explicitly destroys them with Gtk.Widget.Destroy. -- Other widgets will either be part of a larger hierarchy constructed by -- the builder (in which case you should not have to worry about their -- lifecycle), or without a parent, in which case they have to be added -- to some container to make use of them. Non-widget objects need to be -- reffed with Glib.Object.Ref to keep them beyond the lifespan of the -- builder. -- -- The subprogram Connect_Signals_Full can be used to connect handlers to the -- named signals in the description. -- </description> -- <group>GUI Builder</group> -- <c_version>2.16.6</c_version> with System; with Interfaces.C.Strings; with Glib; with Glib.Error; with Glib.Object; with Glib.Properties; with Gtk.Widget; package Gtk.Builder is type Gtk_Builder_Record is new Glib.Object.GObject_Record with private; type Gtk_Builder is access all Gtk_Builder_Record'Class; function Get_Type return GType; procedure Gtk_New (Builder : out Gtk_Builder); procedure Initialize (Builder : access Gtk_Builder_Record'Class); -- Creates a new Gtk_Builder object. function Error_Quark return GQuark; function Add_From_File (Builder : access Gtk_Builder_Record; Filename : String) return Glib.Error.GError; -- Parses a file containing a Gtk_Builder UI definition and merges it with -- the current contents of builder. -- Returns: A GError if an error occured, otherwise null. function Add_From_String (Builder : access Gtk_Builder_Record; Buffer : String; Length : Gsize) return Glib.Error.GError; -- Parses a string containing a Gtk_Builder UI definition and merges it -- with the current contents of Builder. -- Returns: A GError if an error occured, otherwise null. function Get_Object (Builder : access Gtk_Builder_Record; Object_Name : String) return Glib.Object.GObject; -- Gets the object named Object_Name. Note that this function does not -- increment the reference count of the returned object. Returns null -- if it could not be found in the object tree. -- See also Get_Widget below. function Get_Widget (Builder : access Gtk_Builder_Record; Name : String) return Gtk.Widget.Gtk_Widget; -- Utility function to retrieve a widget created by Builder. -- Returns null if no widget was found with the given name. ------------------------ -- Connecting signals -- ------------------------ -- The following is a low-level binding to Gtk+. -- -- You should not need to use this directly. Instead, use a -- Gtkada.Builder.Gtkada_Builder and use the procedures Register_Handler -- to connect your callbacks to signals defined in the GUI builder. type Gtk_Builder_Connect_Func is access procedure (Builder : System.Address; Object : System.Address; Signal_Name : Interfaces.C.Strings.chars_ptr; Handler_Name : Interfaces.C.Strings.chars_ptr; Connect_Object : System.Address; Flags : Glib.G_Connect_Flags; User_Data : System.Address); pragma Convention (C, Gtk_Builder_Connect_Func); -- This is the signature of a subprogram used to connect signals. It is -- used by the Connect_Signals and Connect_Signals_Full methods. -- -- Parameters: -- Builder: The address of a Gtk_Builder -- Object: The object to connect a signal to -- Signal_Name: The name of the signal -- Handler_Name: The name of the handler -- Connect_Object: The internal address of a GObject -- Flags: G_Connect_Flags to use -- User_Data: user data procedure Connect_Signals_Full (Builder : access Gtk_Builder_Record; Signal_Function : Gtk_Builder_Connect_Func; User_Data : System.Address); -- This function can be thought of the interpreted language binding -- version of Connect_Signals, except that it does not require GModule -- to function correctly. ---------------- -- Properties -- ---------------- -- <properties> -- Name: Translation_Domain_Property -- Type: String -- Descr: The translation domain used by gettext -- -- </properties> Translation_Domain_Property : constant Glib.Properties.Property_String; private type Gtk_Builder_Record is new Glib.Object.GObject_Record with null record; Translation_Domain_Property : constant Glib.Properties.Property_String := Glib.Properties.Build ("translation-domain"); pragma Import (C, Error_Quark, "gtk_builder_error_quark"); pragma Import (C, Get_Type, "gtk_builder_get_type"); end Gtk.Builder;
-- Standard Ada library specification -- Copyright (c) 2004-2016 AXE Consultants -- Copyright (c) 2004, 2005, 2006 Ada-Europe -- Copyright (c) 2000 The MITRE Corporation, Inc. -- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc. -- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual --------------------------------------------------------------------------- package Ada.Strings.UTF_Encoding.Conversions is pragma Pure (Conversions); -- Conversions between various encoding schemes function Convert (Item : UTF_String; Input_Scheme : Encoding_Scheme; Output_Scheme : Encoding_Scheme; Output_BOM : Boolean := False) return UTF_String; function Convert (Item : UTF_String; Input_Scheme : Encoding_Scheme; Output_BOM : Boolean := False) return UTF_16_Wide_String; function Convert (Item : UTF_8_String; Output_BOM : Boolean := False) return UTF_16_Wide_String; function Convert (Item : UTF_16_Wide_String; Output_Scheme : Encoding_Scheme; Output_BOM : Boolean := False) return UTF_String; function Convert (Item : UTF_16_Wide_String; Output_BOM : Boolean := False) return UTF_8_String; end Ada.Strings.UTF_Encoding.Conversions;
with Ada.Text_IO; use Ada.Text_IO; with Ada.Text_IO.Text_Streams; use Ada.Text_IO; with Ada.Streams; use Ada.Streams; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Command_Line; use Ada.Command_Line; with AWS.Default; with AWS.Net; use AWS; with AWS.Net.SSL; use AWS.Net; with Aids.Env; use Aids; procedure Freenode is type Irc_Credentials is record Host : Unbounded_String; Port : Positive; Nick : Unbounded_String; Pass : Unbounded_String; Channel : Unbounded_String; end record; procedure Print_Irc_Credentials(C: in Irc_Credentials) is begin Put_Line("Host: " & To_String(C.Host)); Put_Line("Port: " & Positive'Image(C.Port)); Put_Line("Nick: " & To_String(C.Nick)); Put_Line("Pass: [REDACTED]"); Put_Line("Channel: " & To_String(C.Channel)); end; function Irc_Credentials_From_File(File_Path: String) return Irc_Credentials is E: Env.Typ := Env.Slurp(File_Path); Result: Irc_Credentials; Env_Key_Not_Found : exception; procedure Extract_String(Key: in Unbounded_String; Value: out Unbounded_String) is begin if not Env.Find(E, Key, Value) then raise Env_Key_Not_Found with (File_Path & ": key `" & To_String(Key) & "` not found"); end if; end; procedure Extract_Positive(Key: in Unbounded_String; Value: out Positive) is S: Unbounded_String; begin if not Env.Find(E, Key, s) then raise Env_Key_Not_Found with (File_Path & ": key `" & To_String(Key) & "` not found"); end if; Value := Positive'Value(To_String(S)); end; begin Extract_String(To_Unbounded_String("HOST"), Result.Host); Extract_Positive(To_Unbounded_String("PORT"), Result.Port); Extract_String(To_Unbounded_String("NICK"), Result.Nick); Extract_String(To_Unbounded_String("PASS"), Result.Pass); Extract_String(To_Unbounded_String("CHANNEL"), Result.Channel); return Result; end; function Chunk_Image(Chunk: Stream_Element_Array) return String is Result : String(1..Integer(Chunk'Length)); Index : Natural := 1; begin for I in Chunk'Range loop Result(Index) := Character'Val(Natural(Chunk(I))); Index := Index + 1; end loop; return Result; end; function String_To_Chunk(S: in String) return Stream_Element_Array is First: Stream_Element_Offset := Stream_Element_Offset(S'First); Last: Stream_Element_Offset := Stream_Element_Offset(S'Last); Result: Stream_Element_Array(First..Last); begin for Index in S'Range loop Result(Stream_Element_Offset(Index)) := Stream_Element(Character'Pos(S(Index))); end loop; return Result; end; procedure Send_Line(Client: in out SSL.Socket_Type; Line: in String) is begin Client.Send(String_To_Chunk(Line & Character'Val(13) & Character'Val(10))); end; -- NOTE: stolen from https://github.com/AdaCore/aws/blob/master/regtests/0243_sshort/sshort.adb#L156 procedure Secure_Connection(Credentials: Irc_Credentials) is Client: SSL.Socket_Type; Config: SSL.Config; begin Put_Line("Establishing secure (Kapp) connection to " & To_String(Credentials.Host) & ":" & Integer'Image(Credentials.Port)); SSL.Initialize(Config, ""); Client.Set_Config(Config); Client.Connect(To_String(Credentials.Host), Credentials.Port); Send_Line(Client, "PASS oauth:" & To_String(Credentials.Pass)); Send_Line(Client, "NICK " & To_String(Credentials.Nick)); Send_Line(Client, "JOIN " & To_String(Credentials.Channel)); Send_Line(Client, "PRIVMSG " & To_String(Credentials.Channel) & " :tsodinPog"); while true loop declare Chunk: Stream_Element_Array := Client.Receive; begin Put(Chunk_Image(Chunk)); end; end loop; end; Not_Enough_Arguments: exception; begin if Argument_Count < 1 then raise Not_Enough_Arguments; end if; declare Twitch: Irc_Credentials := Irc_Credentials_From_File(Argument(1)); begin Secure_Connection(Twitch); end; end;
-- SPDX-FileCopyrightText: 2020 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ---------------------------------------------------------------- with League.Strings; with Jupyter.Kernels; procedure Jupyter.Start_Kernel (Kernel : in out Jupyter.Kernels.Kernel'Class; File : League.Strings.Universal_String);
with lace.Subject.local; package lace_demo_Keyboard -- -- Provides a simulated keyboard which periodically emits 'key' events. -- is function as_event_Subject return lace.Subject.local.view; procedure start; procedure stop; end lace_demo_Keyboard;
with AAA.Strings; with CLIC.Subcommand; with CLIC.TTY; package CLIC_Ex.Commands.Topics.Example is type Instance is new CLIC.Subcommand.Help_Topic with null record; overriding function Name (This : Instance) return CLIC.Subcommand.Identifier is ("topic_example"); overriding function Title (This : Instance) return String is ("Just an example of CLIC help topic"); overriding function Content (This : Instance) return AAA.Strings.Vector is (AAA.Strings.Empty_Vector .Append ("Not " & CLIC.TTY.Dim ("much") & " to see here...")); end CLIC_Ex.Commands.Topics.Example;
------------------------------------------------------------------------------ -- G E L A A S I S -- -- ASIS implementation for Gela project, a portable Ada compiler -- -- http://gela.ada-ru.org -- -- - - - - - - - - - - - - - - - -- -- -- -- This specification is derived from the Ada Semantic Interface -- -- Specification Standard (ISO/IEC 15291) and ASIS 1999 Issues. -- -- -- -- The copyright notice and the license provisions that follow apply to the -- -- part following the private keyword. -- -- -- -- Read copyright and license at the end of this file -- ------------------------------------------------------------------------------ -- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $ ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -- 16 package Asis.Definitions ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- package Asis.Definitions is pragma Preelaborate; ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -- Asis.Definitions encapsulates a set of queries that operate on -- A_Definition and An_Association elements. ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -- 16.1 function Corresponding_Type_Operators ------------------------------------------------------------------------------- -- |ER A_Type_Definition - 3.2.1 ------------------------------------------------------------------------------- function Corresponding_Type_Operators (Type_Definition : in Asis.Type_Definition) return Asis.Declaration_List; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the type to query -- -- Returns a list of operators. These include all predefined operators, and -- all user-defined operator overloads, that have been implicitly or -- explicitly declared for the type. (Reference Manual 7.3.1(2)) -- -- This list includes only operators appropriate for the type, from the set: -- and or xor = /= < <= > >= + - & * / mod rem ** abs not -- -- Returns a Nil_Element_List if there are no predefined or overloaded -- operators for the type. -- -- Returns a Nil_Element_List if the implementation does not provide -- such implicit declarations. -- -- The Enclosing_Element for each implicit declaration is the declaration -- (type or object) that declared the type. -- -- If a user-defined equality operator has -- been defined, an Ada implementation has two choices when dealing with an -- instance of the "/=" operator. a) treat A/=B as NOT(A=B), b) implicitly -- create a "/=" operator. Implementations that take the second alternative -- will include this implicit inequality operation in their result. -- Implementations that choose the first alternative are encouraged to hide -- this choice beneath the ASIS interface and to "fake" an inequality -- operation. Failing that, the function call, representing the NOT -- operation, must have Is_Part_Of_Implicit = True so that an ASIS application -- can tell the difference between a user-specified NOT(A=B) and an -- implementation-specific A/=B transformation. -- -- Appropriate Definition_Kinds: -- A_Type_Definition -- A_Private_Type_Definition -- A_Tagged_Private_Type_Definition -- A_Private_Extension_Definition -- A_Task_Definition -- A_Protected_Definition -- A_Formal_Type_Definition -- -- Returns Declaration_Kinds: -- A_Function_Declaration -- A_Function_Body_Declaration -- A_Function_Body_Stub -- A_Function_Renaming_Declaration -- A_Function_Instantiation -- A_Formal_Function_Declaration -- -- |IP Implementation Permissions: -- |IP -- |IP The result may or may not include language defined operators that have -- |IP been overridden by user-defined overloads. Operators that are totally -- |IP hidden, in all contexts, by user-defined operators may be omitted from -- |IP the list. -- |IP -- |IP Some implementations do not represent all forms of implicit -- |IP declarations such that elements representing them can be easily -- |IP provided. An implementation can choose whether or not to construct -- |IP and provide artificial declarations for implicitly declared elements. -- -- |ER------------------------------------------------------------------------ -- |ER A_Derived_Type_Definition - 3.4 -- |CR -- |CR Child elements returned by: -- |CR function Parent_Subtype_Indication -- |ER------------------------------------------------------------------------ -- |ER A_Derived_Record_Extension_Definition - 3.4 -- |CR -- |CR Child elements returned by: -- |CR function Parent_Subtype_Indication -- |CR function Record_Definition -- ------------------------------------------------------------------------------- -- 16.2 function Parent_Subtype_Indication ------------------------------------------------------------------------------- function Parent_Subtype_Indication (Type_Definition : in Asis.Type_Definition) return Asis.Subtype_Indication; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the derived_type_definition to query -- -- Returns the parent_subtype_indication following the reserved word "new". -- -- Appropriate Type_Kinds: -- A_Derived_Type_Definition -- A_Derived_Record_Extension_Definition -- -- Returns Definition_Kinds: -- A_Subtype_Indication -- ------------------------------------------------------------------------------- -- 16.3 function Record_Definition ------------------------------------------------------------------------------- function Record_Definition (Type_Definition : in Asis.Type_Definition) return Asis.Definition; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the definition to query -- -- Returns the record definition of the type_definition. -- -- Appropriate Type_Kinds: -- A_Derived_Record_Extension_Definition -- A_Record_Type_Definition -- A_Tagged_Record_Type_Definition -- -- Returns Definition_Kinds: -- A_Record_Definition -- A_Null_Record_Definition -- ------------------------------------------------------------------------------- -- 16.4 function Implicit_Inherited_Declarations ------------------------------------------------------------------------------- function Implicit_Inherited_Declarations (Definition : in Asis.Definition) return Asis.Declaration_List; ------------------------------------------------------------------------------- -- Definition - Specifies the derived type to query -- -- Returns a list of Is_Part_Of_Implicit inherited enumeration literals, -- discriminants, components, protected subprograms, or entries of a -- derived_type_definition whose parent type is an enumeration type, or a -- composite type other than an array type. See Reference Manual 3.4(10-14). -- -- Returns a Nil_Element_List if the root type of derived_type_definition is -- not an enumeration, record, task, or protected type. -- -- Returns a Nil_Element_List if the implementation does not provide -- such implicit declarations. -- -- The Enclosing_Element for each of the implicit declarations is the -- Declaration argument. -- -- Appropriate Definition_Kinds: -- A_Type_Definition -- A_Private_Extension_Definition -- A_Formal_Type_Definition -- -- Appropriate Type_Kinds: -- A_Derived_Type_Definition -- A_Derived_Record_Extension_Definition -- -- Appropriate Formal_Type_Kinds: -- A_Formal_Derived_Type_Definition -- -- Returns Declaration_Kinds: -- -- An_Enumeration_Literal_Specification -- A_Discriminant_Specification -- A_Component_Declaration -- A_Procedure_Declaration -- A_Function_Declaration -- An_Entry_Declaration -- -- |IP Implementation Permissions: -- |IP -- |IP Some implementations do not represent all forms of implicit -- |IP declarations such that elements representing them can be easily -- |IP provided. An implementation can choose whether or not to construct -- |IP and provide artificial declarations for implicitly declared elements. -- -- |AN Application Note: -- |AN -- |AN This query returns only implicit inherited entry declarations for -- |AN derived task types. All representation clauses and pragmas associated -- |AN with the entries of the original task type (the root type of the -- |AN derived task type) apply to the inherited entries. Those are available -- |AN by examining the original type or by calling Corresponding_Pragmas and -- |AN Corresponding_Representation_Clauses. These functions will return the -- |AN pragmas and clauses from the original type. -- ------------------------------------------------------------------------------- -- 16.5 function Implicit_Inherited_Subprograms ------------------------------------------------------------------------------- function Implicit_Inherited_Subprograms (Definition : in Asis.Definition) return Asis.Declaration_List; ------------------------------------------------------------------------------- -- Definition - Specifies the derived type to query -- -- Returns the list of user-defined inherited primitive subprograms that have -- been implicitly declared for the derived_type_definition. -- -- The list result does not include hidden inherited subprograms (Reference -- Manual 8.3). -- -- Returns a Nil_Element_List if there are no inherited subprograms for the -- derived type. -- -- Returns a Nil_Element_List if the implementation does not provide -- such implicit declarations. -- -- The Enclosing_Element for each of the subprogram declarations is the -- Definition argument. -- -- Appropriate Definition_Kinds: -- A_Type_Definition -- A_Private_Extension_Definition -- A_Formal_Type_Definition -- -- Appropriate Type_Kinds: -- A_Derived_Type_Definition -- A_Derived_Record_Extension_Definition -- An_Interface_Type_Definition (by Gela) -- -- Appropriate Formal_Type_Kinds: -- A_Formal_Derived_Type_Definition -- A_Formal_Interface_Type_Definition (by Gela) -- -- Returns Declaration_Kinds: -- A_Function_Declaration -- A_Procedure_Declaration -- -- |IP Implementation Permissions: -- |IP -- |IP Some implementations do not represent all forms of implicit -- |IP declarations such that elements representing them can be easily -- |IP provided. An implementation can choose whether or not to construct -- |IP and provide artificial declarations for implicitly declared elements. -- ------------------------------------------------------------------------------- -- 16.6 function Corresponding_Parent_Subtype ------------------------------------------------------------------------------- function Corresponding_Parent_Subtype (Type_Definition : in Asis.Type_Definition) return Asis.Declaration; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the derived_type_definition to query -- -- Returns the parent subtype declaration of the derived_type_definition. -- The parent subtype is defined by the parent_subtype_indication. -- -- Appropriate Type_Kinds: -- A_Derived_Type_Definition -- A_Derived_Record_Extension_Definition -- -- Returns Declaration_Kinds: -- An_Ordinary_Type_Declaration -- A_Task_Type_Declaration -- A_Protected_Type_Declaration -- A_Subtype_Declaration -- A_Formal_Type_Declaration -- An_Incomplete_Type_Declaration -- A_Private_Type_Declaration -- A_Private_Extension_Declaration -- ------------------------------------------------------------------------------- -- 16.7 function Corresponding_Root_Type ------------------------------------------------------------------------------- function Corresponding_Root_Type (Type_Definition : in Asis.Type_Definition) return Asis.Declaration; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the derived_type_definition to query -- -- This function recursively unwinds all type derivations and subtyping to -- arrive at a full_type_declaration that is neither a derived type nor a -- subtype. -- -- In case of numeric types, this function always returns some user-defined -- type, not an implicitly defined root type corresponding to -- A_Root_Type_Definition. The only ways to get implicitly declared numeric -- root or universal types are to ask for the type of a universal expression -- or from the parameter and result profile of a predefined operation working -- with numeric types. -- -- Appropriate Type_Kinds: -- A_Derived_Type_Definition -- A_Derived_Record_Extension_Definition -- -- Returns Declaration_Kinds: -- An_Ordinary_Type_Declaration -- A_Task_Type_Declaration -- A_Protected_Type_Declaration -- A_Formal_Type_Declaration -- A_Private_Type_Declaration -- A_Private_Extension_Declaration -- ------------------------------------------------------------------------------- -- 16.8 function Corresponding_Type_Structure ------------------------------------------------------------------------------- function Corresponding_Type_Structure (Type_Definition : in Asis.Type_Definition) return Asis.Declaration; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the derived_type_definition to query -- -- Returns the type structure from which the specified type definition has -- been derived. This function will recursively unwind derivations and -- subtyping until the type_declaration derives a change of representation or -- is no longer derived. See Reference Manual 13.6. -- -- Appropriate Type_Kinds: -- A_Derived_Type_Definition -- A_Derived_Record_Extension_Definition -- -- Returns Declaration_Kinds: -- An_Ordinary_Type_Declaration -- A_Task_Type_Declaration -- A_Protected_Type_Declaration -- A_Formal_Type_Declaration -- A_Private_Type_Declaration -- A_Private_Extension_Declaration -- -- |ER------------------------------------------------------------------------ -- |ER An_Enumeration_Type_Definition - 3.5.1 -- |CR -- |CR Child elements returned by: -- |CR function Enumeration_Literal_Declarations -- ------------------------------------------------------------------------------- -- 16.9 function Enumeration_Literal_Declarations ------------------------------------------------------------------------------- function Enumeration_Literal_Declarations (Type_Definition : in Asis.Type_Definition) return Asis.Declaration_List; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the enumeration type definition to query -- -- Returns a list of the literals declared in an enumeration_type_definition, -- in their order of appearance. -- -- Appropriate Type_Kinds: -- An_Enumeration_Type_Definition -- -- Returns Declaration_Kinds: -- An_Enumeration_Literal_Specification -- -- |ER------------------------------------------------------------------------ -- |ER A_Signed_Integer_Type_Definition - 3.5.4 -- |CR -- |CR Child elements returned by: -- |CR function Integer_Constraint -- ------------------------------------------------------------------------------- -- 16.10 function Integer_Constraint ------------------------------------------------------------------------------- function Integer_Constraint (Type_Definition : in Asis.Type_Definition) return Asis.Range_Constraint; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the signed_integer_type_definition to query -- -- Returns the range_constraint of the signed_integer_type_definition. -- -- Appropriate Type_Kinds: -- A_Signed_Integer_Type_Definition -- -- Returns Constraint_Kinds: -- A_Simple_Expression_Range -- -- |ER------------------------------------------------------------------------ -- |ER A_Modular_Type_Definition - 3.5.4 -- |CR -- |CR Child elements returned by: -- |CR function Mod_Static_Expression -- ------------------------------------------------------------------------------- -- 16.11 function Mod_Static_Expression ------------------------------------------------------------------------------- function Mod_Static_Expression (Type_Definition : in Asis.Type_Definition) return Asis.Expression; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the modular_type_definition to query -- -- Returns the static_expression following the reserved word "mod". -- -- Appropriate Type_Kinds: -- A_Modular_Type_Definition -- -- Returns Element_Kinds: -- An_Expression -- -- |ER------------------------------------------------------------------------ -- |ER A_Floating_Point_Definition - 3.5.7 -- |CR -- |CR Child elements returned by: -- |CR functions Digits_Expression and Real_Range_Constraint -- -- |ER------------------------------------------------------------------------ -- |ER A_Decimal_Fixed_Point_Definition - 3.5.9 -- |CR -- |CR Child elements returned by: -- |CR functions Digits_Expression, Delta_Expression, and -- |CR Real_Range_Constraint -- ------------------------------------------------------------------------------- -- 16.12 function Digits_Expression ------------------------------------------------------------------------------- function Digits_Expression (Definition : in Asis.Definition) return Asis.Expression; ------------------------------------------------------------------------------- -- Definition - Specifies the definition to query -- -- Returns the static_expression following the reserved word "digits". -- -- Appropriate Type_Kinds: -- A_Floating_Point_Definition -- A_Decimal_Fixed_Point_Definition -- -- Appropriate Definition_Kinds: -- A_Constraint -- Appropriate Constraint_Kinds: -- A_Digits_Constraint -- -- Returns Element_Kinds: -- An_Expression -- -- |ER------------------------------------------------------------------------ -- |ER An_Ordinary_Fixed_Point_Definition - 3.5.9 -- |CR -- |CR Child elements returned by: -- |CR function Delta_Expression -- ------------------------------------------------------------------------------- -- 16.13 function Delta_Expression ------------------------------------------------------------------------------- function Delta_Expression (Definition : in Asis.Definition) return Asis.Expression; ------------------------------------------------------------------------------- -- Definition - Specifies the definition to query -- -- Returns the static_expression following the reserved word "delta". -- -- Appropriate Type_Kinds: -- An_Ordinary_Fixed_Point_Definition -- A_Decimal_Fixed_Point_Definition -- -- Appropriate Definition_Kinds: -- A_Constraint -- Appropriate Constraint_Kinds: -- A_Delta_Constraint -- -- Returns Element_Kinds: -- An_Expression -- ------------------------------------------------------------------------------- -- 16.14 function Real_Range_Constraint ------------------------------------------------------------------------------- function Real_Range_Constraint (Definition : in Asis.Definition) return Asis.Range_Constraint; ------------------------------------------------------------------------------- -- Definition - Specifies the definition to query -- -- Returns the real_range_specification range_constraint of the definition. -- -- Returns a Nil_Element if there is no explicit range_constraint. -- -- Appropriate Type_Kinds: -- A_Floating_Point_Definition -- An_Ordinary_Fixed_Point_Definition -- A_Decimal_Fixed_Point_Definition -- -- Appropriate Definition_Kinds: -- A_Constraint -- Appropriate Constraint_Kinds: -- A_Digits_Constraint -- A_Delta_Constraint -- -- Returns Constraint_Kinds: -- Not_A_Constraint -- A_Simple_Expression_Range -- -- |ER------------------------------------------------------------------------ -- |ER An_Unconstrained_Array_Definition 3.6 -- |CR -- |CR Child elements returned by: -- |CR functions Index_Subtype_Definitions and Array_Component_Definition -- ------------------------------------------------------------------------------- -- 16.15 function Index_Subtype_Definitions ------------------------------------------------------------------------------- function Index_Subtype_Definitions (Type_Definition : in Asis.Type_Definition) return Asis.Expression_List; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the array_type_definition to query -- -- Returns a list of the index_subtype_definition subtype mark names for -- an unconstrained_array_definition, in their order of appearance. -- -- Appropriate Type_Kinds: -- An_Unconstrained_Array_Definition -- -- Appropriate Formal_Type_Kinds: -- A_Formal_Unconstrained_Array_Definition -- -- Returns Expression_Kinds: -- An_Identifier -- A_Selected_Component -- -- |ER------------------------------------------------------------------------ -- |ER A_Constrained_Array_Definition 3.6 -- |CR -- |CR Child elements returned by: -- |CR function Discrete_Subtype_Definitions -- |CR function Array_Component_Definition -- ------------------------------------------------------------------------------- -- 16.16 function Discrete_Subtype_Definitions ------------------------------------------------------------------------------- function Discrete_Subtype_Definitions (Type_Definition : in Asis.Type_Definition) return Asis.Definition_List; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the array_type_definition to query -- -- Returns the list of Discrete_Subtype_Definition elements of a -- constrained_array_definition, in their order of appearance. -- -- Appropriate Type_Kinds: -- A_Constrained_Array_Definition -- -- Appropriate Formal_Type_Kinds: -- A_Formal_Constrained_Array_Definition -- -- Returns Definition_Kinds: -- A_Discrete_Subtype_Definition -- ------------------------------------------------------------------------------- -- 16.17 function Array_Component_Definition ------------------------------------------------------------------------------- function Array_Component_Definition (Type_Definition : in Asis.Type_Definition) return Asis.Component_Definition; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the array_type_definition to query -- -- Returns the Component_Definition of the array_type_definition. -- -- Appropriate Type_Kinds: -- An_Unconstrained_Array_Definition -- A_Constrained_Array_Definition -- -- Appropriate Formal_Type_Kinds: -- A_Formal_Unconstrained_Array_Definition -- A_Formal_Constrained_Array_Definition -- -- Returns Definition_Kinds: -- A_Component_Definition -- -- |ER------------------------------------------------------------------------ -- |ER A_Record_Type_Definition - 3.8 -- |ER A_Tagged_Record_Type_Definition - 3.8 -- |CR -- |CR Child elements returned by: -- |CR function Record_Definition -- |ER------------------------------------------------------------------------ -- |ER An_Access_Type_Definition - 3.10 -- |CR -- |CR Child elements returned by: -- |CR function Access_To_Object_Definition -- |CR function Access_To_Subprogram_Parameter_Profile -- |CR function Access_To_Function_Result_Profile (obsolete) -- ------------------------------------------------------------------------------- -- 16.18 function Access_To_Object_Definition ------------------------------------------------------------------------------- function Access_To_Object_Definition (Type_Definition : in Asis.Type_Definition) return Asis.Subtype_Indication; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the Access_Type_Definition to query -- -- Returns the subtype_indication following the reserved word "access". -- -- Appropriate Type_Kinds: -- An_Access_Type_Definition. -- -- Appropriate Formal_Type_Kinds: -- A_Formal_Access_Type_Definition -- -- Appropriate Access_Type_Kinds: -- A_Pool_Specific_Access_To_Variable -- An_Access_To_Variable -- An_Access_To_Constant -- -- Returns Element_Kinds: -- A_Subtype_Indication -- ------------------------------------------------------------------------------- -- 16.xx function Anonymous_Access_To_Object_Subtype_Mark ------------------------------------------------------------------------------- function Anonymous_Access_To_Object_Subtype_Mark (Definition : Asis.Definition) return Asis.Name; ------------------------------------------------------------------------------- -- Definition - Specifies the anonymous access definition to query. -- -- Returns the subtype_mark following the reserved word(s) "access" or -- "access constant". -- -- Appropriate Definition_Kinds: -- An_Access_Definition. -- -- Appropriate Access_Definition_Kinds: -- An_Anonymous_Access_To_Variable -- An_Anonymous_Access_To_Constant -- -- Returns Expression_Kinds: -- An_Identifier -- A_Selected_Component -- An_Attribute_Reference -- ------------------------------------------------------------------------------- -- 16.19 function Access_To_Subprogram_Parameter_Profile ------------------------------------------------------------------------------- function Access_To_Subprogram_Parameter_Profile (Type_Definition : in Asis.Type_Definition) return Asis.Parameter_Specification_List; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the Access_Type_Definition to query -- -- Returns a list of parameter_specification elements in the formal part of -- the parameter_profile in the access_to_subprogram_definition. -- -- Returns a Nil_Element_List if the parameter_profile has no formal part. -- -- Results of this query may vary across ASIS implementations. Some -- implementations normalize all multiple name parameter_specification -- elements into an equivalent sequence of corresponding single name -- parameter_specification elements. See Reference Manual 3.3.1(7). -- -- Appropriate Type_Kinds: -- An_Access_Type_Definition. -- A_Formal_Access_Type_Definition. -- -- -- Appropriate Access_Type_Kinds: -- An_Access_To_Procedure -- An_Access_To_Protected_Procedure -- An_Access_To_Function -- An_Access_To_Protected_Function -- -- Appropriate Access_Definition_Kinds -- An_Anonymous_Access_To_Procedure -- An_Anonymous_Access_To_Protected_Procedure -- An_Anonymous_Access_To_Function -- An_Anonymous_Access_To_Protected_Function -- -- Returns Declaration_Kinds: -- A_Parameter_Specification -- ------------------------------------------------------------------------------- -- 16.20 function Access_To_Function_Result_Subtype ------------------------------------------------------------------------------- function Access_To_Function_Result_Subtype (Definition : in Asis.Definition) return Asis.Definition; ------------------------------------------------------------------------------- -- Definition specifies the Access_Type_Definition or -- Access_Definition to query. -- -- Returns a definition that corresponds to the result subtype of the -- access-to-function type, as specified by a subtype_indication (with -- no specified constraint) or an access_definition. -- -- Appropriate Definition_Kinds: -- A_Type_Definition -- An_Access_Definition -- -- Appropriate Type_Kinds: -- An_Access_Type_Definition -- A_Formal_Access_Type_Definition -- -- Appropriate Access_Type_Kinds: -- An_Access_To_Function -- An_Access_To_Protected_Function -- -- Appropriate Access_Definition_Kinds: -- An_Anonymous_Access_To_Function -- An_Anonymous_Access_To_Protected_Function -- -- Returns Definition_Kinds: -- A_Subtype_Indication -- An_Access_Definition -- ------------------------------------------------------------------------------- -- 16.20 function Access_To_Function_Result_Profile (obsolete) ------------------------------------------------------------------------------- function Access_To_Function_Result_Profile (Type_Definition : in Asis.Type_Definition) return Asis.Expression; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the Access_Type_Definition to query -- -- Returns the subtype_mark expression for the return type for the access -- function. -- -- Appropriate Type_Kinds: -- An_Access_Type_Definition -- A_Formal_Access_Type_Definition -- -- Appropriate Access_Type_Kinds: -- An_Access_To_Function -- An_Access_To_Protected_Function -- -- Returns Expression_Kinds: -- An_Identifier -- A_Selected_Component -- -- |ER------------------------------------------------------------------------ -- |ER A_Root_Type_Definition - 3.5.4(9), 3.5.6(2) - No child elements -- |ER------------------------------------------------------------------------ -- |ER A_Subtype_Indication - 3.3.2 -- |CR -- |CR Child elements returned by: -- |CR function Subtype_Mark -- |CR function Subtype_Constraint -- ------------------------------------------------------------------------------- -- 16.21 function Subtype_Mark ------------------------------------------------------------------------------- function Subtype_Mark (Definition : in Asis.Definition) return Asis.Expression; ------------------------------------------------------------------------------- -- Definition - Specifies the definition to query -- -- Returns the subtype_mark expression of the definition. -- -- Appropriate Definition_Kinds: -- A_Subtype_Indication -- A_Discrete_Subtype_Definition -- Appropriate Discrete_Range_Kinds: -- A_Discrete_Subtype_Indication -- A_Discrete_Range -- Appropriate Discrete_Range_Kinds: -- A_Discrete_Subtype_Indication -- A_Formal_Type_Definition -- Appropriate Formal_Type_Kinds: -- A_Formal_Derived_Type_Definition -- -- Returns Expression_Kinds: -- An_Identifier -- A_Selected_Component -- An_Attribute_Reference -- ------------------------------------------------------------------------------- -- 16.22 function Subtype_Constraint ------------------------------------------------------------------------------- function Subtype_Constraint (Definition : in Asis.Definition) return Asis.Constraint; ------------------------------------------------------------------------------- -- Definition - Specifies the definition to query -- -- Returns the constraint of the subtype_indication. -- -- Returns a Nil_Element if no explicit constraint is present. -- -- Appropriate Definition_Kinds: -- A_Subtype_Indication -- A_Discrete_Subtype_Definition -- Appropriate Discrete_Range_Kinds: -- A_Discrete_Subtype_Indication -- A_Discrete_Range -- Appropriate Discrete_Range_Kinds: -- A_Discrete_Subtype_Indication -- -- Returns Definition_Kinds: -- Not_A_Definition -- A_Constraint -- -- |AN Application Note: -- |AN -- |AN When an unconstrained subtype indication for a type having -- |AN discriminants with default values is used, a Nil_Element is -- |AN returned by this function. Use the queries Subtype_Mark, and -- |AN Corresponding_Name_Declaration [, and Corresponding_First_Subtype] -- |AN to obtain the declaration defining the defaults. -- -- |ER------------------------------------------------------------------------ -- |ER A_Constraint - 3.2.2 -- |ER -- |ER A_Simple_Expression_Range - 3.5 -- |CR -- |CR Child elements returned by: -- |CR function Lower_Bound -- |CR function Upper_Bound -- ------------------------------------------------------------------------------- -- 16.23 function Lower_Bound ------------------------------------------------------------------------------- function Lower_Bound (Constraint : in Asis.Range_Constraint) return Asis.Expression; ------------------------------------------------------------------------------- -- Constraint - Specifies the range_constraint or discrete_range to query -- -- Returns the simple_expression for the lower bound of the range. -- -- Appropriate Constraint_Kinds: -- A_Simple_Expression_Range -- -- Appropriate Discrete_Range_Kinds: -- A_Discrete_Simple_Expression_Range -- -- Returns Element_Kinds: -- An_Expression -- ------------------------------------------------------------------------------- -- 16.24 function Upper_Bound ------------------------------------------------------------------------------- function Upper_Bound (Constraint : in Asis.Range_Constraint) return Asis.Expression; ------------------------------------------------------------------------------- -- Constraint - Specifies the range_constraint or discrete_range to query -- -- Returns the simple_expression for the upper bound of the range. -- -- Appropriate Constraint_Kinds: -- A_Simple_Expression_Range -- -- Appropriate Discrete_Range_Kinds: -- A_Discrete_Simple_Expression_Range -- -- Returns Element_Kinds: -- An_Expression -- -- |ER------------------------------------------------------------------------ -- |ER A_Range_Attribute_Reference - 3.5 -- |CR -- |CR Child elements returned by: -- |CR function Range_Attribute -- ------------------------------------------------------------------------------- -- 16.25 function Range_Attribute ------------------------------------------------------------------------------- function Range_Attribute (Constraint : in Asis.Range_Constraint) return Asis.Expression; ------------------------------------------------------------------------------- -- Constraint - Specifies the range_attribute_reference or -- discrete_range attribute_reference to query -- -- Returns the range_attribute_reference expression of the range. -- -- Appropriate Constraint_Kinds: -- A_Range_Attribute_Reference -- -- Appropriate Discrete_Range_Kinds: -- A_Discrete_Range_Attribute_Reference -- -- Returns Expression_Kinds: -- An_Attribute_Reference -- -- |ER------------------------------------------------------------------------ -- |ER A_Digits_Constraint - 3.5.9 -- |CR -- |CR Child elements returned by: -- |CR function Digits_Expression -- |CR function Real_Range_Constraint -- |ER------------------------------------------------------------------------ -- |ER A_Delta_Constraint - J.3 -- |CR -- |CR Child elements returned by: -- |CR function Delta_Expression -- |CR function Real_Range_Constraint -- |CR------------------------------------------------------------------------ -- |ER An_Index_Constraint - 3.6.1 -- |CR -- |CR Child elements returned by: -- |CR function Discrete_Ranges -- ------------------------------------------------------------------------------- -- 16.26 function Discrete_Ranges ------------------------------------------------------------------------------- function Discrete_Ranges (Constraint : in Asis.Constraint) return Asis.Discrete_Range_List; ------------------------------------------------------------------------------- -- Constraint - Specifies the array index_constraint to query -- -- Returns the list of discrete_range components for an index_constraint, -- in their order of appearance. -- -- Appropriate Constraint_Kinds: -- An_Index_Constraint -- -- Returns Definition_Kinds: -- A_Discrete_Range -- -- |ER------------------------------------------------------------------------ -- |ER A_Discriminant_Constraint - 3.7.1 -- |CR -- |CR Child elements returned by: -- |CR function Discriminant_Associations -- ------------------------------------------------------------------------------- -- 16.27 function Discriminant_Associations ------------------------------------------------------------------------------- function Discriminant_Associations (Constraint : in Asis.Constraint; Normalized : in Boolean := False) return Asis.Discriminant_Association_List; ------------------------------------------------------------------------------- -- Constraint - Specifies the discriminant_constraint to query -- Normalized - Specifies whether the normalized form is desired -- -- Returns a list of the discriminant_association elements of the -- discriminant_constraint. -- -- Returns a Nil_Element_List if there are no discriminant_association -- elements. -- -- An unnormalized list contains only explicit associations ordered as they -- appear in the program text. Each unnormalized association has a list of -- discriminant_selector_name elements and an explicit expression. -- -- A normalized list contains artificial associations representing all -- explicit associations. It has a length equal to the number of -- discriminant_specification elements of the known_discriminant_part. -- The order of normalized associations matches the order of -- discriminant_specification elements. -- -- Each normalized association represents a one on one mapping of a -- discriminant_specification to the explicit expression. A normalized -- association has one A_Defining_Name component that denotes the -- discriminant_specification, and one An_Expression component that is the -- explicit expression. -- -- Appropriate Constraint_Kinds: -- A_Discriminant_Constraint -- -- Returns Association_Kinds: -- A_Discriminant_Association -- -- |IR Implementation Requirements: -- |IR -- |IR Normalized associations are Is_Normalized and Is_Part_Of_Implicit. -- |IR Normalized associations are never Is_Equal to unnormalized -- |IR associations. -- -- |IP Implementation Permissions: -- |IP -- |IP An implementation may choose to normalize its internal representation -- |IP to use the defining_identifier element instead of the -- |IP discriminant_selector_name element. -- |IP -- |IP If so, this query will return Is_Normalized associations even if -- |IP Normalized is False, and the query Discriminant_Associations_Normalized -- |IP will return True. -- -- |AN Application Note: -- |AN -- |AN It is not possible to obtain either a normalized or unnormalized -- |AN Discriminant_Association list for an unconstrained record or derived -- |AN subtype_indication where the discriminant_association elements are -- |AN supplied by default; there is no constraint to query, and a -- |AN Nil_Element is returned from the query Subtype_Constraint. -- -- |ER------------------------------------------------------------------------ -- |ER A_Component_Definition - 3.6 -- |CR -- |CR Child elements returned by: -- |CR function Component_Subtype_Indication -- ------------------------------------------------------------------------------- -- 16.28 function Component_Subtype_Indication ------------------------------------------------------------------------------- function Component_Subtype_Indication (Component_Definition : in Asis.Component_Definition) return Asis.Subtype_Indication; ------------------------------------------------------------------------------- -- Component_Definition - Specifies the Component_Definition to query -- -- Returns the subtype_indication of the Component_Definition. -- -- Appropriate Definition_Kinds: -- A_Component_Definition -- -- Returns Definition_Kinds: -- A_Subtype_Indication -- -- |ER------------------------------------------------------------------------ -- |ER A_Discrete_Subtype_Definition - 3.6 -- |ER A_Discrete_Range - 3.6.1 -- |ER -- |ER A_Discrete_Subtype_Indication -- |CR -- |CR Child elements returned by: -- |CR function Subtype_Mark -- |CR function Subtype_Constraint -- |CR -- |CR A_Discrete_Simple_Expression_Range -- |CR -- |CR Child elements returned by: -- |CR function Lower_Bound -- |CR function Upper_Bound -- |ER -- |ER------------------------------------------------------------------------ -- |ER A_Discrete_Range_Attribute_Reference - 3.5 -- |CR -- |CR Child elements returned by: -- |CR function Range_Attribute -- |ER------------------------------------------------------------------------ -- |ER An_Unknown_Discriminant_Part - 3.7 - No child elements -- |ER------------------------------------------------------------------------ -- |ER A_Known_Discriminant_Part - 3.7 -- |CR -- |CR Child elements returned by: -- |CR function Discriminants -- ------------------------------------------------------------------------------- -- 16.29 function Discriminants ------------------------------------------------------------------------------- function Discriminants (Definition : in Asis.Definition) return Asis.Discriminant_Specification_List; ------------------------------------------------------------------------------- -- Definition - Specifies the known_discriminant_part to query -- -- Returns a list of discriminant_specification elements, in their order -- of appearance. -- -- Results of this query may vary across ASIS implementations. Some -- implementations normalize all multi-name discriminant_specification -- elements into an equivalent sequence of single name -- discriminant_specification elements. See Reference Manual 3.3.1(7). -- -- Appropriate Definition_Kinds: -- A_Known_Discriminant_Part -- -- Returns Declaration_Kinds: -- A_Discriminant_Specification -- -- |ER------------------------------------------------------------------------ -- |ER A_Record_Definition - 3.8 -- |CR -- |CR Child elements returned by: -- |CR function Record_Components -- |CR function Implicit_Components -- ------------------------------------------------------------------------------- -- 16.30 function Record_Components ------------------------------------------------------------------------------- function Record_Components (Definition : in Asis.Definition; Include_Pragmas : in Boolean := False) return Asis.Record_Component_List; ------------------------------------------------------------------------------- -- Definition - Specifies the record_definition or variant to query -- Include_Pragmas - Specifies whether pragmas are to be returned -- -- Returns a list of the components and pragmas of the record_definition or -- variant, in their order of appearance. -- -- Declarations are not returned for implementation-defined components of the -- record_definition. See Reference Manual 13.5.1 (15). These components are -- not normally visible to the ASIS application. However, they can be -- obtained with the query Implicit_Components. -- -- Appropriate Definition_Kinds: -- A_Record_Definition -- A_Variant -- -- Returns Element_Kinds: -- A_Pragma -- A_Declaration -- A_Definition -- A_Clause -- -- Returns Declaration_Kinds: -- A_Component_Declaration -- -- Returns Definition_Kinds: -- A_Null_Component -- A_Variant_Part -- -- Returns Representation_Clause_Kinds: -- An_Attribute_Definition_Clause -- ------------------------------------------------------------------------------- -- 16.31 function Implicit_Components ------------------------------------------------------------------------------- function Implicit_Components (Definition : in Asis.Definition) return Asis.Record_Component_List; ------------------------------------------------------------------------------- -- Definition - Specifies the record_definition or variant to query -- -- Returns a list of all implicit implementation-defined components of the -- record_definition or variant. The Enclosing_Element of each component is -- the Definition argument. Each component is Is_Part_Of_Implicit. -- -- Returns a Nil_Element_List if there are no implicit implementation-defined -- components or if the ASIS implementation does not support such -- implicit declarations. -- -- Appropriate Definition_Kinds: -- A_Record_Definition -- A_Variant -- -- Returns Element_Kinds: -- A_Declaration -- -- Returns Declaration_Kinds: -- A_Component_Declaration -- -- |IP Implementation Permissions: -- |IP -- |IP Some implementations do not represent all forms of implicit -- |IP declarations such that elements representing them can be easily -- |IP provided. An implementation can choose whether or not to construct -- |IP and provide artificial declarations for implicitly declared elements. -- |IP -- |IP Use the query Implicit_Components_Supported to determine if the -- |IP implementation provides implicit record components. -- -- |ER------------------------------------------------------------------------ -- |ER A_Null_Record_Definition - 3.8 - No child elements -- |ER------------------------------------------------------------------------ -- |ER A_Variant_Part - 3.8.1 -- |CR -- |CR Child elements returned by: -- |CR function Discriminant_Direct_Name -- |CR function Variants -- ------------------------------------------------------------------------------- -- 16.32 function Discriminant_Direct_Name ------------------------------------------------------------------------------- function Discriminant_Direct_Name (Variant_Part : in Asis.Record_Component) return Asis.Name; ------------------------------------------------------------------------------- -- Variant_Part - Specifies the variant_part to query -- -- Returns the Discriminant_Direct_Name of the variant_part. -- -- Appropriate Definition_Kinds: -- A_Variant_Part -- -- Returns Expression_Kinds: -- An_Identifier -- ------------------------------------------------------------------------------- -- 16.33 function Variants ------------------------------------------------------------------------------- function Variants (Variant_Part : in Asis.Record_Component; Include_Pragmas : in Boolean := False) return Asis.Variant_List; ------------------------------------------------------------------------------- -- Variant_Part - Specifies the variant_part to query -- Include_Pragmas - Specifies whether pragmas are to be returned -- -- Returns a list of variants that make up the record component, in their -- order of appearance. -- -- The only pragmas returned are those following the reserved word "is" -- and preceding the reserved word "when" of first variant, and those between -- following variants. -- -- Appropriate Definition_Kinds: -- A_Variant_Part -- -- Returns Element_Kinds: -- A_Pragma -- A_Definition -- -- Returns Definition_Kinds: -- A_Variant -- -- |ER------------------------------------------------------------------------ -- |ER A_Variant - 3.8.1 -- |CR -- |CR Child elements returned by: -- |CR function Variant_Choices -- |CR function Record_Components -- |CR function Implicit_Components -- ------------------------------------------------------------------------------- -- 16.34 function Variant_Choices ------------------------------------------------------------------------------- function Variant_Choices (Variant : in Asis.Variant) return Asis.Element_List; ------------------------------------------------------------------------------- -- Variant - Specifies the variant to query -- -- Returns the discrete_choice_list elements, in their order of appearance. -- Choices are either an expression, a discrete range, or an others choice. -- -- Appropriate Definition_Kinds: -- A_Variant -- -- Returns Element_Kinds: -- An_Expression -- A_Definition -- -- Returns Definition_Kinds: -- A_Discrete_Range -- An_Others_Choice -- -- |ER------------------------------------------------------------------------ -- |ER A_Private_Type_Definition - 7.3 - No child elements -- |ER A_Tagged_Private_Type_Definition - 7.3 - No child elements -- |ER------------------------------------------------------------------------ -- |ER A_Private_Extension_Definition - 7.3 -- |CR -- |CR Child elements returned by: -- |CR function Ancestor_Subtype_Indication -- ------------------------------------------------------------------------------- -- 16.35 function Ancestor_Subtype_Indication ------------------------------------------------------------------------------- function Ancestor_Subtype_Indication (Definition : in Asis.Definition) return Asis.Subtype_Indication; ------------------------------------------------------------------------------- -- Definition - Specifies the definition to query -- -- Returns the ancestor_subtype_indication following the reserved word "new" -- in the private_extension_declaration. -- -- Appropriate Definition_Kinds: -- A_Private_Extension_Definition -- -- Returns Definition_Kinds: -- A_Subtype_Indication -- -- |ER------------------------------------------------------------------------ -- |ER A_Task_Definition - 9.1 -- |ER A_Protected_Definition - 9.4 -- |CR -- |CR Child elements returned by: -- |CR functions Visible_Part_Items and Private_Part_Items -- ------------------------------------------------------------------------------- -- 16.36 function Visible_Part_Items ------------------------------------------------------------------------------- function Visible_Part_Items (Definition : in Asis.Definition; Include_Pragmas : in Boolean := False) return Asis.Declarative_Item_List; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the type_definition to query -- Include_Pragmas - Specifies whether pragmas are to be returned -- -- Returns a list of declarations, representation clauses, and pragmas -- in the visible part of the task or protected definition, in their order -- of appearance. The list does not include discriminant_specification -- elements of the known_discriminant_part, if any, of the protected type -- or task type declaration. -- -- Returns a Nil_Element_List if there are no items. -- -- Appropriate Definition_Kinds: -- A_Task_Definition -- A_Protected_Definition -- -- Returns Element_Kinds: -- A_Pragma -- A_Declaration -- A_Clause -- ------------------------------------------------------------------------------- -- 16.37 function Private_Part_Items ------------------------------------------------------------------------------- function Private_Part_Items (Definition : in Asis.Definition; Include_Pragmas : in Boolean := False) return Asis.Declarative_Item_List; ------------------------------------------------------------------------------- -- Type_Definition - Specifies the task type definition to query -- Include_Pragmas - Specifies whether pragmas are to be returned -- -- Returns a list of declarations, representation clauses, and pragmas in -- the private part of the task or protected definition, in their order -- of appearance. -- -- Returns a Nil_Element_List if there are no items. -- -- Appropriate Definition_Kinds: -- A_Task_Definition -- A_Protected_Definition -- -- Returns Element_Kinds: -- A_Pragma -- A_Declaration -- A_Clause -- ------------------------------------------------------------------------------- -- 16.38 function Is_Private_Present ------------------------------------------------------------------------------- function Is_Private_Present (Definition : in Asis.Definition) return Boolean; ------------------------------------------------------------------------------- -- Definition - Specifies the definition to query -- -- Returns True if the argument is a task_definition or a protected_definition -- that has a reserved word "private" marking the beginning of a -- (possibly empty) private part. -- -- Returns False for any definition without a private part. -- Returns False for any unexpected Element. -- -- Expected Definition_Kinds: -- A_Task_Definition -- A_Protected_Definition -- -- |ER------------------------------------------------------------------------ -- |ER A_Formal_Type_Definition - 12.5 -- |ER -- |ER A_Formal_Private_Type_Definition - 12.5.1 - No child elements -- |ER A_Formal_Tagged_Private_Type_Definition - 12.5.1 - No child elements -- |ER -- |ER A_Formal_Derived_Type_Definition -- |CR Child elements returned by: -- |CR function Subtype_Mark -- -- |ER------------------------------------------------------------------------ -- |ER A_Formal_Discrete_Type_Definition - 12.5.2 - No child elements -- |ER A_Formal_Signed_Integer_Type_Definition - 12.5.2 - No child elements -- |ER A_Formal_Modular_Type_Definition - 12.5.2 - No child elements -- |ER A_Formal_Floating_Point_Definition - 12.5.2 - No child elements -- |ER A_Formal_Ordinary_Fixed_Point_Definition - 12.5.2 - No child elements -- |ER A_Formal_Decimal_Fixed_Point_Definition - 12.5.2 - No child elements -- |ER------------------------------------------------------------------------ -- |ER A_Formal_Unconstrained_Array_Definition - 12.5.3 -- |CR -- |CR Child elements returned by: -- |CR function Index_Subtype_Definitions -- |CR function Array_Component_Definition -- |ER------------------------------------------------------------------------ -- |ER A_Formal_Constrained_Array_Definition - 12.5.3 -- |CR -- |CR Child elements returned by: -- |CR function Discrete_Subtype_Definitions -- |CR function Array_Component_Definition -- |ER------------------------------------------------------------------------ -- |ER A_Formal_Access_Type_Definition - 12.5.4 -- |CR -- |CR Child elements returned by: -- |CR function Access_To_Object_Definition -- |CR function Access_To_Subprogram_Parameter_Profile -- |CR function Access_To_Function_Result_Profile -- ------------------------------------------------------------------------------- -- 16.xx function Progenitor_List ------------------------------------------------------------------------------- function Progenitor_List (Type_Definition : Asis.Definition) return Asis.Name_List; ------------------------------------------------------------------------------- -- Type_Definition - specifies the definition to query. -- -- Returns a list of subtype marks making up the interface_list in the -- argument definition, in their order of appearance. -- -- Appropriate Type_Kinds: -- A_Derived_Record_Extension_Definition -- An_Interface_Type_Definition -- -- Appropriate Formal_Type_Kinds: -- A_Formal_Derived_Type_Definition -- A_Formal_Interface_Type_Definition -- -- Returns Expression_Kinds: -- An_Identifier -- A_Selected_Component -- ------------------------------------------------------------------------------- -- 16.xx function Is_Task_Definition_Present ------------------------------------------------------------------------------- function Is_Task_Definition_Present (Definition : in Asis.Definition) return Boolean; ------------------------------------------------------------------------------- -- Definition specifies the definition element to query. -- -- Returns True if the element has a task_definition that is given explicitly. -- -- Returns False for any other Element including a Nil_Element. -- -- Note: Is_Task_Definition_Present is used to determine whether the -- original text was "Task T;" (for which it returns False) or -- "Task T is end T;" (for which it returns True). -- -- Expected Definition_Kinds: -- A_Task_Definition -- ------------------------------------------------------------------------------- end Asis.Definitions; ------------------------------------------------------------------------------ -- Copyright (c) 2006-2013, Maxim Reznik -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met: -- -- * Redistributions of source code must retain the above copyright notice, -- this list of conditions and the following disclaimer. -- * Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- * Neither the name of the Maxim Reznik, IE nor the names of its -- contributors may be used to endorse or promote products derived from -- this software without specific prior written permission. -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -- POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------
-- -- Copyright (C) 2015 secunet Security Networks AG -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program 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. -- with HW.Time; with HW.GFX.GMA.Registers; package body HW.GFX.GMA.PLLs.WRPLL is ---------------------------------------------------------------------------- -- -- Divider calculation as found in Linux' i915 driver -- -- Copyright (C) 2012 Intel Corporation -- -- Permission is hereby granted, free of charge, to any person obtaining a -- copy of this software and associated documentation files (the "Software"), -- to deal in the Software without restriction, including without limitation -- the rights to use, copy, modify, merge, publish, distribute, sublicense, -- and/or sell copies of the Software, and to permit persons to whom the -- Software is furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice (including the next -- paragraph) shall be included in all copies or substantial portions of the -- Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -- IN THE SOFTWARE. -- -- Authors: -- Eugeni Dodonov <eugeni.dodonov@intel.com> -- LC_FREQ : constant := 2700; -- in MHz LC_FREQ_2K : constant := LC_FREQ * 2000; -- in 500Hz P_MIN : constant := 2; P_MAX : constant := 62; -- i915 says 64, but this would overflow 6-bit P_INC : constant := 2; -- Constraints for PLL good behavior REF_MIN : constant := 48; REF_MAX : constant := 400; VCO_MIN : constant := 2400; VCO_MAX : constant := 4800; type R2_Range is new Natural range 0 .. LC_FREQ * 2 / REF_MIN; type N2_Range is new Natural range 0 .. VCO_MAX * Natural (R2_Range'Last) / LC_FREQ; type P_Range is new Natural range 0 .. P_MAX; type RNP is record P : P_Range; N2 : N2_Range; R2 : R2_Range; end record; Invalid_RNP : constant RNP := RNP'(0, 0, 0); function Get_Budget_For_Freq (Clock : HW.GFX.Frequency_Type) return Word64 is Result : Word64; begin case Clock is when 25175000 | 25200000 | 27000000 | 27027000 | 37762500 | 37800000 | 40500000 | 40541000 | 54000000 | 54054000 | 59341000 | 59400000 | 72000000 | 74176000 | 74250000 | 81000000 | 81081000 | 89012000 | 89100000 | 108000000 | 108108000 | 111264000 | 111375000 | 148352000 | 148500000 | 162000000 | 162162000 | 222525000 | 222750000 | 296703000 | 297000000 => Result := 0; when 233500000 | 245250000 | 247750000 | 253250000 | 298000000 => Result := 1500; when 169128000 | 169500000 | 179500000 | 202000000 => Result := 2000; when 256250000 | 262500000 | 270000000 | 272500000 | 273750000 | 280750000 | 281250000 | 286000000 | 291750000 => Result := 4000; when 267250000 | 268500000 => Result := 5000; when others => Result := 1000; end case; return Result; end Get_Budget_For_Freq; procedure Update_RNP (Freq_2K : in Word64; Budget : in Word64; R2 : in R2_Range; N2 : in N2_Range; P : in P_Range; Best : in out RNP) with Depends => (Best =>+ (Freq_2K, Budget, R2, N2, P)) is use type HW.Word64; function Abs_Diff (A, B : Word64) return Word64 is Result : Word64; begin if A > B then Result := A - B; else Result := B - A; end if; return Result; end Abs_Diff; A, B, C, D, Diff, Diff_Best : Word64; begin -- No best (r,n,p) yet */ if Best.P = 0 then Best.P := P; Best.N2 := N2; Best.R2 := R2; else -- Config clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to -- freq2k. -- -- delta = 1e6 * -- abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) / -- freq2k; -- -- and we would like delta <= budget. -- -- If the discrepancy is above the PPM-based budget, always prefer to -- improve upon the previous solution. However, if you're within the -- budget, try to maximize Ref * VCO, that is N / (P * R^2). A := Freq_2K * Budget * Word64 (P) * Word64 (R2); B := Freq_2K * Budget * Word64 (Best.P) * Word64 (Best.R2); Diff := Abs_Diff (Freq_2K * Word64 (P) * Word64 (R2), LC_FREQ_2K * Word64 (N2)); Diff_Best := Abs_Diff (Freq_2K * Word64 (Best.P) * Word64 (Best.R2), LC_FREQ_2K * Word64 (Best.N2)); C := 1000000 * Diff; D := 1000000 * Diff_Best; if A < C and B < D then -- If both are above the Budget, pick the closer if Word64 (Best.P) * Word64 (Best.R2) * Diff < Word64 (P) * Word64 (R2) * Diff_Best then Best.P := P; Best.N2 := N2; Best.R2 := R2; end if; elsif A >= C and B < D then -- If A is below the threshold but B is above it? Update. Best.P := P; Best.N2 := N2; Best.R2 := R2; elsif A >= C and B >= D then -- Both are below the limit, so pick the higher N2/(R2*R2) if Word64 (N2) * Word64 (Best.R2) * Word64 (Best.R2) > Word64 (Best.N2) * Word64 (R2) * Word64 (R2) then Best.P := P; Best.N2 := N2; Best.R2 := R2; end if; end if; -- Otherwise A < C && B >= D, do nothing end if; end Update_RNP; procedure Calculate_WRPLL (Clock : in HW.GFX.Frequency_Type; R2_Out : out R2_Range; N2_Out : out N2_Range; P_Out : out P_Range) with Global => null, Pre => True, Post => True is use type HW.Word64; Freq_2K : Word64; Budget : Word64; Best : RNP := Invalid_RNP; begin Freq_2K := Word64 (Clock) / 100; -- PLL output should be 5x -- the pixel clock Budget := Get_Budget_For_Freq (Clock); -- Special case handling for 540MHz pixel clock: bypass WR PLL entirely -- and directly pass the LC PLL to it. */ if Freq_2K = 5400000 then N2_Out := 2; P_Out := 1; R2_Out := 2; else -- Ref = LC_FREQ / R, where Ref is the actual reference input seen by -- the WR PLL. -- -- We want R so that REF_MIN <= Ref <= REF_MAX. -- Injecting R2 = 2 * R gives: -- REF_MAX * r2 > LC_FREQ * 2 and -- REF_MIN * r2 < LC_FREQ * 2 -- -- Which means the desired boundaries for r2 are: -- LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN -- for R2 in R2_Range range LC_FREQ * 2 / REF_MAX + 1 .. LC_FREQ * 2 / REF_MIN loop -- VCO = N * Ref, that is: VCO = N * LC_FREQ / R -- -- Once again we want VCO_MIN <= VCO <= VCO_MAX. -- Injecting R2 = 2 * R and N2 = 2 * N, we get: -- VCO_MAX * r2 > n2 * LC_FREQ and -- VCO_MIN * r2 < n2 * LC_FREQ) -- -- Which means the desired boundaries for n2 are: -- VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ for N2 in N2_Range range N2_Range (VCO_MIN * Natural (R2) / LC_FREQ + 1) .. N2_Range (VCO_MAX * Natural (R2) / LC_FREQ) loop for P_Fract in Natural range P_MIN / P_INC .. P_MAX / P_INC loop Update_RNP (Freq_2K, Budget, R2, N2, P_Range (P_Fract * P_INC), Best); end loop; end loop; end loop; N2_Out := Best.N2; P_Out := Best.P; R2_Out := Best.R2; end if; end Calculate_WRPLL; -- ---------------------------------------------------------------------------- type Regs is array (WRPLLs) of Registers.Registers_Index; WRPLL_CTL : constant Regs := Regs'(Registers.WRPLL_CTL_1, Registers.WRPLL_CTL_2); WRPLL_CTL_PLL_ENABLE : constant := 1 * 2 ** 31; WRPLL_CTL_SELECT_LCPLL : constant := 3 * 2 ** 28; function WRPLL_CTL_DIVIDER_FEEDBACK (N2 : N2_Range) return Word32 is begin return Word32 (N2) * 2 ** 16; end WRPLL_CTL_DIVIDER_FEEDBACK; function WRPLL_CTL_DIVIDER_POST (P : P_Range) return Word32 is begin return Word32 (P) * 2 ** 8; end WRPLL_CTL_DIVIDER_POST; function WRPLL_CTL_DIVIDER_REFERENCE (R2 : R2_Range) return Word32 is begin return Word32 (R2) * 2 ** 0; end WRPLL_CTL_DIVIDER_REFERENCE; ---------------------------------------------------------------------------- procedure On (PLL : in WRPLLs; Target_Clock : in Frequency_Type; Success : out Boolean) is R2 : R2_Range; N2 : N2_Range; P : P_Range; begin Calculate_WRPLL (Target_Clock, R2, N2, P); Registers.Write (Register => WRPLL_CTL (PLL), Value => WRPLL_CTL_PLL_ENABLE or WRPLL_CTL_SELECT_LCPLL or WRPLL_CTL_DIVIDER_FEEDBACK (N2) or WRPLL_CTL_DIVIDER_POST (P) or WRPLL_CTL_DIVIDER_REFERENCE (R2)); Registers.Posting_Read (WRPLL_CTL (PLL)); Time.U_Delay (20); Success := True; end On; procedure Off (PLL : WRPLLs) is begin Registers.Unset_Mask (WRPLL_CTL (PLL), WRPLL_CTL_PLL_ENABLE); end Off; end HW.GFX.GMA.PLLs.WRPLL;
----------------------------------------------------------------------- -- awa-settings-modules-tests -- Unit tests for settings module -- Copyright (C) 2013, 2019 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Util.Test_Caller; with Util.Measures; with Security.Contexts; with AWA.Tests.Helpers.Users; with AWA.Tests.Helpers.Contexts; package body AWA.Settings.Modules.Tests is package Caller is new Util.Test_Caller (Test, "Settings.Services"); procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is begin Caller.Add_Test (Suite, "Test AWA.Settings.Get_User_Setting", Test_Get_User_Setting'Access); Caller.Add_Test (Suite, "Test AWA.Settings.Set_User_Setting", Test_Set_User_Setting'Access); Caller.Add_Test (Suite, "Test AWA.Settings.Get_User_Setting (perf)", Test_Perf_User_Setting'Access); end Add_Tests; -- ------------------------------ -- Test getting a user setting. -- ------------------------------ procedure Test_Get_User_Setting (T : in out Test) is Sec_Ctx : Security.Contexts.Security_Context; Context : AWA.Tests.Helpers.Contexts.Service_Context; begin AWA.Tests.Helpers.Users.Login (Context, Sec_Ctx, "test-setting@test.com"); for I in 1 .. 10 loop declare Name : constant String := "setting-" & Natural'Image (I); R : constant Integer := AWA.Settings.Get_User_Setting (Name, I); begin Util.Tests.Assert_Equals (T, I, R, "Invalid Get_User_Setting result"); end; end loop; end Test_Get_User_Setting; -- ------------------------------ -- Test saving a user setting. -- ------------------------------ procedure Test_Set_User_Setting (T : in out Test) is Sec_Ctx : Security.Contexts.Security_Context; Context : AWA.Tests.Helpers.Contexts.Service_Context; begin AWA.Tests.Helpers.Users.Login (Context, Sec_Ctx, "test-setting@test.com"); for I in 1 .. 10 loop declare Name : constant String := "setting-" & Natural'Image (I); R : Integer; begin AWA.Settings.Set_User_Setting (Name, I); R := AWA.Settings.Get_User_Setting (Name, 0); Util.Tests.Assert_Equals (T, I, R, "Invalid Set_User_Setting result"); end; end loop; end Test_Set_User_Setting; -- ------------------------------ -- Test performance on user setting. -- ------------------------------ procedure Test_Perf_User_Setting (T : in out Test) is Sec_Ctx : Security.Contexts.Security_Context; Context : AWA.Tests.Helpers.Contexts.Service_Context; Ident : constant String := Util.Tests.Get_Uuid; begin AWA.Tests.Helpers.Users.Login (Context, Sec_Ctx, "test-setting@test.com"); -- First pass has to look in the database for the user setting. -- Second pass finds the setting in the cache. for Pass in 1 .. 2 loop declare Value : Integer; Stamp : Util.Measures.Stamp; begin for I in 1 .. 100 loop Value := AWA.Settings.Get_User_Setting ("perf-" & Integer'Image (I) & Ident, I); Util.Tests.Assert_Equals (T, I, Value, "Invalid setting returned"); end loop; Util.Measures.Report (Stamp, "Getting a user setting (100 times) pass" & Integer'Image (Pass)); end; end loop; declare Stamp : Util.Measures.Stamp; begin for I in 1 .. 100 loop AWA.Settings.Set_User_Setting ("perf-" & Integer'Image (I) & Ident, I); end loop; Util.Measures.Report (Stamp, "Saving and creating user setting (100 times)"); end; -- Erase the session cache. Context.Session_Attributes.Clear; -- Get the user setting that have been created. declare Value : Integer; Stamp : Util.Measures.Stamp; begin for I in 1 .. 100 loop Value := AWA.Settings.Get_User_Setting ("perf-" & Integer'Image (I) & Ident, -1); Util.Tests.Assert_Equals (T, I, Value, "Invalid setting returned"); end loop; Util.Measures.Report (Stamp, "Getting a user setting (100 times) load from DB"); end; end Test_Perf_User_Setting; end AWA.Settings.Modules.Tests;
with Ada.Text_IO, Ada.Strings.Unbounded, Ada.Strings.Unbounded.Text_IO, Ada.Characters.Handling; use Ada.Text_IO, Ada.Strings.Unbounded, Ada.Strings.Unbounded.Text_IO, Ada.Characters.Handling; procedure Hello is Name : Unbounded_String; Input : Character; function Title_Case (Str : in String) return String is Result : String(Str'Range); LastCharacterWasSpace : Boolean := True; begin for C in Str'Range loop if Str(C) = ' ' then LastCharacterWasSpace := True; Result(C) := Str(C); elsif LastCharacterWasSpace then Result(C) := To_Upper(Str(C)); LastCharacterWasSpace := False; else Result(C) := To_Lower(Str(C)); LastCharacterWasSpace := False; end if; end loop; return Result; end Title_Case; begin Put_Line("It's the Hello World example."); loop Put_Line("What's your name?"); Get_Line(Name); Put_Line("Hello " & Title_Case(To_String(Name)) & "!"); Put_Line("It's a me, Mario!"); Put_Line("Again? (Y/N)"); Get(Input); Skip_Line; exit when Input /= 'y' and Input /= 'Y'; end loop; end Hello;
with Ada.Text_IO, tools; use Ada.Text_IO; package body hauntedhouse is subtype Index is Positive range 1..5; package Ind_Generator is new tools.Random_Generator(Index); function GetRandPos return Position is begin return (Ind_Generator.GetRandom,Ind_Generator.GetRandom); end GetRandPos; function GetField(pos:Position) return Fields is begin return House(pos.x,pos.y); end GetField; function IsWall(pos: Position) return Boolean is begin return GetField(pos) = W; end IsWall; function IsCorridor(pos: Position) return Boolean is begin return GetField(pos) = C; end IsCorridor; function IsCorrect(pos: Position) return Boolean is begin if (pos.x>=Index'First and then pos.x<=Index'Last and then pos.y>=Index'First and then pos.y<=Index'Last) then return not IsWall(pos); else return false; end if; end IsCorrect; end hauntedhouse;
-- SPDX-FileCopyrightText: 2021 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- package Regions.Symbols is pragma Pure; type Symbol is mod 2 ** 32; -- Symbol is case-insensitive representation of identifiers, operators -- and character literals end Regions.Symbols;
-- Generated at 2014-10-01 17:18:35 +0000 by Natools.Static_Hash_Maps -- from src/natools-s_expressions-templates-generic_integers-maps.sx with Natools.Static_Maps.S_Expressions.Templates.Integers.MC; with Natools.Static_Maps.S_Expressions.Templates.Integers.AC; function Natools.Static_Maps.S_Expressions.Templates.Integers.T return Boolean is begin for I in Map_1_Keys'Range loop if Natools.Static_Maps.S_Expressions.Templates.Integers.MC.Hash (Map_1_Keys (I).all) /= I then return False; end if; end loop; for I in Map_2_Keys'Range loop if Natools.Static_Maps.S_Expressions.Templates.Integers.AC.Hash (Map_2_Keys (I).all) /= I then return False; end if; end loop; return True; end Natools.Static_Maps.S_Expressions.Templates.Integers.T;
with Ada.Text_Io; use Ada.Text_Io; package body PMap is task body pmap_apply is value : Integer; Func : func_type; begin accept PortIn(ValIn : in Integer; FuncIn : in not null func_type) do value := ValIn; Func := FuncIn; end PortIn; value := Func(value); Put_Line(Integer'Image(value)); accept PortOut(ValOut : out Integer) do ValOut := value; end PortOut; end pmap_apply; task body pmap_task is List, List_modified : vector_ptr; Func : func_type; Kids : pmap_applies_access; val : Integer; begin accept PortIn(ValIn : in vector_ptr; FuncIn : in not null func_type) do List := ValIn; Func := FuncIn; end PortIn; --Put_Line(Integer'Image(List'Length)); List_modified := new vector(List'range); Kids := new pmap_applies(List'range); for i in List'range loop Kids(i).PortIn(List(i), Func); end loop; for i in List'range loop Kids(i).PortOut(val); List_modified(i) := val; --Put_Line(Integer'Image(val)); end loop; accept PortOut(ValOut : out vector_ptr) do ValOut := List_modified; end PortOut; end pmap_task; function example1 (X : in Integer) return Integer is begin return x + 10; end example1; function pmap (List : in vector_ptr) return vector_ptr is task1 : pmap_task; output : vector_ptr; begin task1.PortIn(List, example1'Access); task1.PortOut(output); return(output); end pmap; end PMap;
-- Copyright (c) 2016 onox <denkpadje@gmail.com> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. with JSON.Types; with JSON.Streams; generic with package Types is new JSON.Types (<>); package JSON.Tokenizers with SPARK_Mode => On is pragma Preelaborate; type Token_Kind is (Begin_Array_Token, Begin_Object_Token, End_Array_Token, End_Object_Token, Name_Separator_Token, Value_Separator_Token, String_Token, Integer_Token, Float_Token, Boolean_Token, Null_Token, EOF_Token, Invalid_Token); type Token (Kind : Token_Kind := Invalid_Token) is record case Kind is when String_Token => String_Offset, String_Length : Streams.AS.Stream_Element_Offset; when Integer_Token => Integer_Value : Types.Integer_Type; when Float_Token => Float_Value : Types.Float_Type; when Boolean_Token => Boolean_Value : Boolean; when others => null; end case; end record; procedure Read_Token (Stream : in out Streams.Stream'Class; Next_Token : out Token; Expect_EOF : Boolean := False) with Post => Next_Token.Kind /= Invalid_Token and Expect_EOF = (Next_Token.Kind = EOF_Token); Tokenizer_Error : exception; end JSON.Tokenizers;
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- S Y S T E M . T E X T _ I O -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2017, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- Uart I/O for Raspberry PI 2 using PL011 (aka uart0) with System; with Interfaces.Raspberry_Pi; with System.Machine_Code; package body System.Text_IO is use Interfaces; use Interfaces.Raspberry_Pi; --------- -- Get -- --------- function Get return Character is begin return Character'Val (PL011_Registers.DR and 16#ff#); end Get; ---------------- -- Initialize -- ---------------- procedure Initialize is use Interfaces.Raspberry_Pi.PL011_Bits; Sel : Unsigned_32; begin Initialized := True; -- Disable UART PL011_Registers.CR := 0; -- Wait for end of TX and RX. if False then while (PL011_Registers.FR and FR_BUSY) /= 0 loop null; end loop; while (PL011_Registers.FR and FR_RXFE) = 0 loop Sel := PL011_Registers.DR; end loop; end if; -- Use GPIO 14 & 15 Sel := GPIO_Registers.GPFSEL1; -- GPIO14: alt0 Sel := Sel and not (7 * 2**12); Sel := Sel or (4 * 2**12); -- GPIO15: alt0 Sel := Sel and not (7 * 2**15); Sel := Sel or (4 * 2**15); GPIO_Registers.GPFSEL1 := Sel; -- Disable pull-up/down on all GPIOs. GPIO_Registers.GPPUD := 0; -- Clock pull-up for I in 1 .. 150 loop System.Machine_Code.Asm ("nop", Volatile => True); end loop; GPIO_Registers.GPPUDCLK0 := 2**14 + 2**15; for I in 1 .. 150 loop System.Machine_Code.Asm ("nop", Volatile => True); end loop; GPIO_Registers.GPPUDCLK0 := 0; -- Freq = 46_000_000, baud = 115_200 -- Freq / baud ~= 26 + 3/64 PL011_Registers.IBRD := 26; PL011_Registers.FBRD := 3; -- 8n1, FIFO en PL011_Registers.LCRH := 16#70#; -- Clear interrupts PL011_Registers.ICR := 16#3ff#; -- Enable PL011_Registers.CR := 16#301#; end Initialize; ----------------- -- Is_Rx_Ready -- ----------------- function Is_Rx_Ready return Boolean is begin return (PL011_Registers.FR and PL011_Bits.FR_RXFE) = 0; end Is_Rx_Ready; ----------------- -- Is_Tx_Ready -- ----------------- function Is_Tx_Ready return Boolean is begin return (PL011_Registers.FR and PL011_Bits.FR_TXFF) = 0; end Is_Tx_Ready; --------- -- Put -- --------- procedure Put (C : Character) is begin -- Send the character PL011_Registers.DR := Character'Pos (C); end Put; ---------------------------- -- Use_Cr_Lf_For_New_Line -- ---------------------------- function Use_Cr_Lf_For_New_Line return Boolean is begin return True; end Use_Cr_Lf_For_New_Line; end System.Text_IO;
-- MIT License -- Copyright (c) 2021 Stephen Merrony -- Permission is hereby granted, free of charge, to any person obtaining a copy -- of this software and associated documentation files (the "Software"), to deal -- in the Software without restriction, including without limitation the rights -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -- copies of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- The above copyright notice and this permission notice shall be included in all -- copies or substantial portions of the Software. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. with Ada.Direct_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Interfaces; use Interfaces; with DG_Types; use DG_Types; package Devices.Disk6061 is Surfaces_Per_Disk : constant Integer := 19; Cylinders_Per_Disk : constant Integer := 815; -- i.e. Tracks Sectors_Per_Track : constant Integer := 24; Words_Per_Sector : constant Integer := 256; Bytes_Per_Sector : constant Integer := Words_Per_Sector * 2; Sectors_Per_Disk : constant Integer := Surfaces_Per_Disk * Sectors_Per_Track * Cylinders_Per_Disk; Physical_Byte_Size : constant Integer := Sectors_Per_Disk * Bytes_Per_Sector; -- Cmd_T vals are in numeric order - do not change! type Cmd_T is (Read, Recal, Seek, Stop, Offset_Fwd, Offset_Rev, Write_Disable, Release, Trespass, Set_Alt_Mode_1, Set_Alt_Mode_2, No_Op, Verify, Read_Buffers, Write, Format); type Ins_Mode is (Normal, Alt_1, Alt_2); Drive_Stat_Drive_Fault : Word_T := 2#0000_0000_0000_0001#; Drive_Stat_Write_Fault : Word_T := 2#0000_0000_0000_0010#; Drive_Stat_Clock_Fault : Word_T := 2#0000_0000_0000_0100#; Drive_Stat_Posn_Fault : Word_T := 2#0000_0000_0000_1000#; Drive_Stat_Pack_Unsafe : Word_T := 2#0000_0000_0001_0000#; Drive_Stat_Power_Fault : Word_T := 2#0000_0000_0010_0000#; Drive_Stat_Illegal_Cmd : Word_T := 2#0000_0000_0100_0000#; Drive_Stat_Invalid_Addr : Word_T := 2#0000_0000_1000_0000#; Drive_Stat_Unused : Word_T := 2#0000_0001_0000_0000#; Drive_Stat_Write_Dis : Word_T := 2#0000_0010_0000_0000#; Drive_Stat_Offset : Word_T := 2#0000_0100_0000_0000#; Drive_Stat_Busy : Word_T := 2#0000_1000_0000_0000#; Drive_Stat_Ready : Word_T := 2#0001_0000_0000_0000#; Drive_Stat_Trespassed : Word_T := 2#0010_0000_0000_0000#; Drive_Stat_Reserved : Word_T := 2#0100_0000_0000_0000#; Drive_Stat_Invalid : Word_T := 2#1000_0000_0000_0000#; RW_Stat_RW_Fault : Word_T := 2#0000_0000_0000_0001#; RW_Stat_Late : Word_T := 2#0000_0000_0000_0010#; RW_Stat_RW_Timeout : Word_T := 2#0000_0000_0000_0100#; RW_Stat_Verify : Word_T := 2#0000_0000_0000_1000#; RW_Stat_Surf_Sect : Word_T := 2#0000_0000_0001_0000#; RW_Stat_Cylinder : Word_T := 2#0000_0000_0010_0000#; RW_Stat_Bad_sector : Word_T := 2#0000_0000_0100_0000#; RW_Stat_ECC : Word_T := 2#0000_0000_1000_0000#; RW_Stat_Illegal_Sector : Word_T := 2#0000_0001_0000_0000#; RW_Stat_Parity : Word_T := 2#0000_0010_0000_0000#; RW_Stat_Drive_3_Done : Word_T := 2#0000_0100_0000_0000#; RW_Stat_Drive_2_Done : Word_T := 2#0000_1000_0000_0000#; RW_Stat_Drive_1_Done : Word_T := 2#0001_0000_0000_0000#; RW_Stat_Drive_0_Done : Word_T := 2#0010_0000_0000_0000#; RW_Stat_RW_Done : Word_T := 2#0100_0000_0000_0000#; RW_Stat_Control_Full : Word_T := 2#1000_0000_0000_0000#; type Sector is array (0 .. Words_Per_Sector - 1) of Word_T; package Sector_IO is new Ada.Direct_IO (Sector); use Sector_IO; type State_Rec is record -- Emulator internals... Image_Attached : Boolean; Image_Filename : Unbounded_String; Image_File : Sector_IO.File_Type; Reads, Writes : Unsigned_64; Read_Buff, Write_Buff : Sector; Debug_Logging : Boolean; -- DG Data... Cmd_Drv_Addr : Byte_T; Command : Word_T; Drive : Word_T; Map_Enabled : Boolean; Mem_Addr : Word_T; EMA : Word_T; Cylinder : Word_T; Surface, Sector : Word_T; Sector_Cnt : Integer_8; ECC : Dword_T; Drive_Status : Word_T; RW_Status : Word_T; Instruction_Mode : Ins_Mode; Last_DOA_Was_Seek : Boolean; end record; -- the data reported to the status collector type Status_Rec is record Image_Attached : Boolean; Image_Filename : Unbounded_String; Cylinder : Word_T; Surface, Sector : Word_T; Reads, Writes : Unsigned_64; end record; protected Drives is procedure Init (Debug_Logging : in Boolean); procedure Reset; procedure Attach (Unit : in Natural; Image_Name : in String; OK : out Boolean); procedure Data_In (ABC : in IO_Reg_T; IO_Flag : in IO_Flag_T; Datum : out Word_T); procedure Data_Out (Datum : in Word_T; ABC : in IO_Reg_T; IO_Flag : in IO_Flag_T); procedure Set_Logging (Log : in Boolean); function Get_Status return Status_Rec; procedure Load_DKBT; private State : State_Rec; end Drives; procedure Create_Blank (Image_Name : in String; OK : out Boolean); task Status_Sender is entry Start; end Status_Sender; Not_Yet_Implemented : exception; end Devices.Disk6061;
----------------------------------------------------------------------- -- wi2wic-rest -- REST entry points -- Copyright (C) 2020 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Wiki.Strings; with Wiki.Streams; with Wiki.Parsers; with Wiki.Filters.Html; with Wiki.Render.Html; with Wiki.Render.Wiki; with Wiki.Streams.Html.Stream; with Util.Http.Clients; with Util.Strings; with Servlet.Rest.Operation; package body Wi2wic.Rest is use type Wiki.Wiki_Syntax; URI_Prefix : constant String := "/v1"; package API_Import is new Servlet.Rest.Operation (Handler => Import'Access, Method => Servlet.Rest.POST, URI => URI_Prefix & "/import/{target}"); package API_Convert is new Servlet.Rest.Operation (Handler => Convert'Access, Method => Servlet.Rest.POST, URI => URI_Prefix & "/converter/{format}/{target}"); package API_Render is new Servlet.Rest.Operation (Handler => Render'Access, Method => Servlet.Rest.POST, URI => URI_Prefix & "/render/{format}"); Invalid_Format : exception; function Get_Syntax (Name : in String) return Wiki.Wiki_Syntax is begin if Name = "markdown" then return Wiki.SYNTAX_MARKDOWN; elsif Name = "dotclear" then return Wiki.SYNTAX_DOTCLEAR; elsif Name = "creoler" then return Wiki.SYNTAX_CREOLE; elsif Name = "mediawiki" then return Wiki.SYNTAX_MEDIA_WIKI; elsif Name = "html" then return Wiki.SYNTAX_HTML; else raise Invalid_Format; end if; end Get_Syntax; procedure Import_Doc (Doc : in out Wiki.Documents.Document; Syntax : in Wiki.Wiki_Syntax; Stream : in out Servlet.Streams.Input_Stream'Class) is type Input_Stream is new Wiki.Streams.Input_Stream with null record; -- Read one character from the input stream and return False to the <tt>Eof</tt> indicator. -- When there is no character to read, return True in the <tt>Eof</tt> indicator. overriding procedure Read (Input : in out Input_Stream; Char : out Wiki.Strings.WChar; Eof : out Boolean); overriding procedure Read (Input : in out Input_Stream; Char : out Wiki.Strings.WChar; Eof : out Boolean) is begin Stream.Read (Char); Eof := Stream.Is_Eof; exception when others => Eof := True; end Read; Html_Filter : aliased Wiki.Filters.Html.Html_Filter_Type; In_Stream : aliased Input_Stream; Engine : Wiki.Parsers.Parser; begin Html_Filter.Hide (Wiki.FOOTER_TAG); Html_Filter.Hide (Wiki.HEAD_TAG); Html_Filter.Hide (Wiki.HEADER_TAG); Html_Filter.Hide (Wiki.ADDRESS_TAG); Html_Filter.Hide (Wiki.IFRAME_TAG); Engine.Set_Syntax (Syntax); Engine.Add_Filter (Html_Filter'Unchecked_Access); Engine.Parse (In_Stream'Unchecked_Access, Doc); end Import_Doc; procedure Render_Doc (Doc : in out Wiki.Documents.Document; Syntax : in Wiki.Wiki_Syntax; Output : in out Servlet.Rest.Output_Stream'Class) is type Output_Stream is limited new Wiki.Streams.Output_Stream with null record; -- Write the string to the output stream. overriding procedure Write (Stream : in out Output_Stream; Content : in Wiki.Strings.WString); -- Write a single character to the output stream. overriding procedure Write (Stream : in out Output_Stream; Char : in Wiki.Strings.WChar); -- Write the string to the output stream. overriding procedure Write (Stream : in out Output_Stream; Content : in Wiki.Strings.WString) is begin Output.Write_Wide (Content); end Write; -- Write a single character to the output stream. overriding procedure Write (Stream : in out Output_Stream; Char : in Wiki.Strings.WChar) is begin Output.Write_Wide (Char); end Write; Out_Stream : aliased Output_Stream; Renderer : Wiki.Render.Wiki.Wiki_Renderer; begin Renderer.Set_Output_Stream (Out_Stream'Unchecked_Access, Syntax); Renderer.Render (Doc); end Render_Doc; procedure Render_Html (Doc : in out Wiki.Documents.Document; Output : in out Servlet.Rest.Output_Stream'Class) is type Output_Stream is limited new Wiki.Streams.Output_Stream with null record; -- Write the string to the output stream. overriding procedure Write (Stream : in out Output_Stream; Content : in Wiki.Strings.WString); -- Write a single character to the output stream. overriding procedure Write (Stream : in out Output_Stream; Char : in Wiki.Strings.WChar); -- Write the string to the output stream. overriding procedure Write (Stream : in out Output_Stream; Content : in Wiki.Strings.WString) is begin Output.Write_Wide (Content); end Write; -- Write a single character to the output stream. overriding procedure Write (Stream : in out Output_Stream; Char : in Wiki.Strings.WChar) is begin Output.Write_Wide (Char); end Write; package Html_Stream is new Wiki.Streams.Html.Stream (Output_Stream); Out_Stream : aliased Html_Stream.Html_Output_Stream; Renderer : Wiki.Render.Html.Html_Renderer; begin Renderer.Set_Render_TOC (True); Renderer.Set_Output_Stream (Out_Stream'Unchecked_Access); Renderer.Render (Doc); end Render_Html; -- ------------------------------ -- Import an HTML content by getting the HTML content from a URL -- and convert to the target wiki syntax. -- ------------------------------ procedure Import (Req : in out Servlet.Requests.Request'Class; Reply : in out Servlet.Responses.Response'Class; Stream : in out Servlet.Rest.Output_Stream'Class) is Doc : Wiki.Documents.Document; Target : constant String := Req.Get_Path_Parameter (1); URL : constant String := Req.Get_Parameter ("url"); Syntax : Wiki.Wiki_Syntax; Download : Util.Http.Clients.Client; Content : Util.Http.Clients.Response; begin Syntax := Get_Syntax (Target); if not Util.Strings.Starts_With (URL, "http://") and not Util.Strings.Starts_With (URL, "https://") then Reply.Set_Status (Util.Http.SC_BAD_REQUEST); return; end if; Download.Add_Header ("X-Requested-By", "wi2wic"); Download.Set_Timeout (5.0); begin Download.Get (URL, Content); exception when Util.Http.Clients.Connection_Error => Reply.Set_Status (Util.Http.SC_REQUEST_TIMEOUT); return; when others => Reply.Set_Status (Util.Http.SC_EXPECTATION_FAILED); return; end; declare Html_Filter : aliased Wiki.Filters.Html.Html_Filter_Type; Engine : Wiki.Parsers.Parser; Data : constant String := Content.Get_Body; begin Html_Filter.Hide (Wiki.FOOTER_TAG); Html_Filter.Hide (Wiki.HEAD_TAG); Html_Filter.Hide (Wiki.HEADER_TAG); Html_Filter.Hide (Wiki.ADDRESS_TAG); Html_Filter.Hide (Wiki.IFRAME_TAG); Engine.Set_Syntax (Wiki.SYNTAX_HTML); Engine.Add_Filter (Html_Filter'Unchecked_Access); Engine.Parse (Data, Doc); end; Render_Doc (Doc, Syntax, Stream); exception when Invalid_Format => Reply.Set_Status (Util.Http.SC_NOT_FOUND); end Import; -- ------------------------------ -- Convert a Wiki text from one format to another. -- ------------------------------ procedure Convert (Req : in out Servlet.Requests.Request'Class; Reply : in out Servlet.Responses.Response'Class; Stream : in out Servlet.Rest.Output_Stream'Class) is Doc : Wiki.Documents.Document; Format : constant String := Req.Get_Path_Parameter (1); Target : constant String := Req.Get_Path_Parameter (2); begin Import_Doc (Doc, Get_Syntax (Format), Req.Get_Input_Stream.all); Render_Doc (Doc, Get_Syntax (Target), Stream); exception when Invalid_Format => Reply.Set_Status (Util.Http.SC_NOT_FOUND); end Convert; -- ------------------------------ -- Render the Wiki content in HTML. -- ------------------------------ procedure Render (Req : in out Servlet.Requests.Request'Class; Reply : in out Servlet.Responses.Response'Class; Stream : in out Servlet.Rest.Output_Stream'Class) is Doc : Wiki.Documents.Document; Format : constant String := Req.Get_Path_Parameter (1); begin Import_Doc (Doc, Get_Syntax (Format), Req.Get_Input_Stream.all); Render_Html (Doc, Stream); exception when Invalid_Format => Reply.Set_Status (Util.Http.SC_NOT_FOUND); end Render; procedure Register (Server : in out Servlet.Core.Servlet_Registry'Class) is begin Servlet.Rest.Register (Server, API_Convert.Definition); Servlet.Rest.Register (Server, API_Render.Definition); Servlet.Rest.Register (Server, API_Import.Definition); end Register; end Wi2wic.Rest;
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- A D A . T A S K _ A T T R I B U T E S -- -- -- -- B o d y -- -- -- -- $Revision$ -- -- -- Copyright (C) 1991-2000 Florida State University -- -- -- -- GNARL is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNARL is distributed in the hope that it will be useful, but WITH- -- -- OUT 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 GNARL; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, 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. -- -- -- -- GNARL was developed by the GNARL team at Florida State University. It is -- -- now maintained by Ada Core Technologies Inc. in cooperation with Florida -- -- State University (http://www.gnat.com). -- -- -- ------------------------------------------------------------------------------ -- The following notes are provided in case someone decides the -- implementation of this package is too complicated, or too slow. -- Please read this before making any "simplifications". -- Correct implementation of this package is more difficult than one -- might expect. After considering (and coding) several alternatives, -- we settled on the present compromise. Things we do not like about -- this implementation include: -- - It is vulnerable to bad Task_ID values, to the extent of -- possibly trashing memory and crashing the runtime system. -- - It requires dynamic storage allocation for each new attribute value, -- except for types that happen to be the same size as System.Address, -- or shorter. -- - Instantiations at other than the library level rely on being able to -- do down-level calls to a procedure declared in the generic package body. -- This makes it potentially vulnerable to compiler changes. -- The main implementation issue here is that the connection from -- task to attribute is a potential source of dangling references. -- When a task goes away, we want to be able to recover all the storage -- associated with its attributes. The Ada mechanism for this is -- finalization, via controlled attribute types. For this reason, -- the ARM requires finalization of attribute values when the -- associated task terminates. -- This finalization must be triggered by the tasking runtime system, -- during termination of the task. Given the active set of instantiations -- of Ada.Task_Attributes is dynamic, the number and types of attributes -- belonging to a task will not be known until the task actually terminates. -- Some of these types may be controlled and some may not. The RTS must find -- some way to determine which of these attributes need finalization, and -- invoke the appropriate finalization on them. -- One way this might be done is to create a special finalization chain -- for each task, similar to the finalization chain that is used for -- controlled objects within the task. This would differ from the usual -- finalization chain in that it would not have a LIFO structure, since -- attributes may be added to a task at any time during its lifetime. -- This might be the right way to go for the longer term, but at present -- this approach is not open, since GNAT does not provide such special -- finalization support. -- Lacking special compiler support, the RTS is limited to the -- normal ways an application invokes finalization, i.e. -- a) Explicit call to the procedure Finalize, if we know the type -- has this operation defined on it. This is not sufficient, since -- we have no way of determining whether a given generic formal -- Attribute type is controlled, and no visibility of the associated -- Finalize procedure, in the generic body. -- b) Leaving the scope of a local object of a controlled type. -- This does not help, since the lifetime of an instantiation of -- Ada.Task_Attributes does not correspond to the lifetimes of the -- various tasks which may have that attribute. -- c) Assignment of another value to the object. This would not help, -- since we then have to finalize the new value of the object. -- d) Unchecked deallocation of an object of a controlled type. -- This seems to be the only mechanism available to the runtime -- system for finalization of task attributes. -- We considered two ways of using unchecked deallocation, both based -- on a linked list of that would hang from the task control block. -- In the first approach the objects on the attribute list are all derived -- from one controlled type, say T, and are linked using an access type to -- T'Class. The runtime system has an Unchecked_Deallocation for T'Class -- with access type T'Class, and uses this to deallocate and finalize all -- the items in the list. The limitation of this approach is that each -- instantiation of the package Ada.Task_Attributes derives a new record -- extension of T, and since T is controlled (RM 3.9.1 (3)), instantiation -- is only allowed at the library level. -- In the second approach the objects on the attribute list are of -- unrelated but structurally similar types. Unchecked conversion is -- used to circument Ada type checking. Each attribute-storage node -- contains not only the attribute value and a link for chaining, but -- also a pointer to a descriptor for the corresponding instantiation -- of Task_Attributes. The instantiation-descriptor contains a -- pointer to a procedure that can do the correct deallocation and -- finalization for that type of attribute. On task termination, the -- runtime system uses the pointer to call the appropriate deallocator. -- While this gets around the limitation that instantiations be at -- the library level, it relies on an implementation feature that -- may not always be safe, i.e. that it is safe to call the -- Deallocate procedure for an instantiation of Ada.Task_Attributes -- that no longer exists. In general, it seems this might result in -- dangling references. -- Another problem with instantiations deeper than the library level -- is that there is risk of storage leakage, or dangling references -- to reused storage. That is, if an instantiation of Ada.Task_Attributes -- is made within a procedure, what happens to the storage allocated for -- attributes, when the procedure call returns? Apparently (RM 7.6.1 (4)) -- any such objects must be finalized, since they will no longer be -- accessible, and in general one would expect that the storage they occupy -- would be recovered for later reuse. (If not, we would have a case of -- storage leakage.) Assuming the storage is recovered and later reused, -- we have potentially dangerous dangling references. When the procedure -- containing the instantiation of Ada.Task_Attributes returns, there -- may still be unterminated tasks with associated attribute values for -- that instantiation. When such tasks eventually terminate, the RTS -- will attempt to call the Deallocate procedure on them. If the -- corresponding storage has already been deallocated, when the master -- of the access type was left, we have a potential disaster. This -- disaster is compounded since the pointer to Deallocate is probably -- through a "trampoline" which will also have been destroyed. -- For this reason, we arrange to remove all dangling references -- before leaving the scope of an instantiation. This is ugly, since -- it requires traversing the list of all tasks, but it is no more ugly -- than a similar traversal that we must do at the point of instantiation -- in order to initialize the attributes of all tasks. At least we only -- need to do these traversals if the type is controlled. -- We chose to defer allocation of storage for attributes until the -- Reference function is called or the attribute is first set to a value -- different from the default initial one. This allows a potential -- savings in allocation, for attributes that are not used by all tasks. -- For efficiency, we reserve space in the TCB for a fixed number of -- direct-access attributes. These are required to be of a size that -- fits in the space of an object of type System.Address. Because -- we must use unchecked bitwise copy operations on these values, they -- cannot be of a controlled type, but that is covered automatically -- since controlled objects are too large to fit in the spaces. -- We originally deferred the initialization of these direct-access -- attributes, just as we do for the indirect-access attributes, and -- used a per-task bit vector to keep track of which attributes were -- currently defined for that task. We found that the overhead of -- maintaining this bit-vector seriously slowed down access to the -- attributes, and made the fetch operation non-atomic, so that even -- to read an attribute value required locking the TCB. Therefore, -- we now initialize such attributes for all existing tasks at the time -- of the attribute instantiation, and initialize existing attributes -- for each new task at the time it is created. -- The latter initialization requires a list of all the instantiation -- descriptors. Updates to this list, as well as the bit-vector that -- is used to reserve slots for attributes in the TCB, require mutual -- exclusion. That is provided by the lock -- System.Tasking.Task_Attributes.All_Attrs_L. -- One special problem that added complexity to the design is that -- the per-task list of indirect attributes contains objects of -- different types. We use unchecked pointer conversion to link -- these nodes together and access them, but the records may not have -- identical internal structure. Initially, we thought it would be -- enough to allocate all the common components of the records at the -- front of each record, so that their positions would correspond. -- Unfortunately, GNAT adds "dope" information at the front of a record, -- if the record contains any controlled-type components. -- -- This means that the offset of the fields we use to link the nodes is -- at different positions on nodes of different types. To get around this, -- each attribute storage record consists of a core node and wrapper. -- The core nodes are all of the same type, and it is these that are -- linked together and generally "seen" by the RTS. Each core node -- contains a pointer to its own wrapper, which is a record that contains -- the core node along with an attribute value, approximately -- as follows: -- type Node; -- type Node_Access is access all Node; -- type Node_Access; -- type Access_Wrapper is access all Wrapper; -- type Node is record -- Next : Node_Access; -- ... -- Wrapper : Access_Wrapper; -- end record; -- type Wrapper is record -- Noed : aliased Node; -- Value : aliased Attribute; -- the generic formal type -- end record; -- Another interesting problem is with the initialization of -- the instantiation descriptors. Originally, we did this all via -- the Initialize procedure of the descriptor type and code in the -- package body. It turned out that the Initialize procedure needed -- quite a bit of information, including the size of the attribute -- type, the initial value of the attribute (if it fits in the TCB), -- and a pointer to the deallocator procedure. These needed to be -- "passed" in via access discriminants. GNAT was having trouble -- with access discriminants, so all this work was moved to the -- package body. with Ada.Task_Identification; -- used for Task_Id -- Null_Task_ID -- Current_Task with System.Error_Reporting; -- used for Shutdown; with System.Storage_Elements; -- used for Integer_Address with System.Task_Primitives.Operations; -- used for Write_Lock -- Unlock -- Lock/Unlock_All_Tasks_List with System.Tasking; -- used for Access_Address -- Task_ID -- Direct_Index_Vector -- Direct_Index with System.Tasking.Initialization; -- used for Defer_Abortion -- Undefer_Abortion -- Initialize_Attributes_Link -- Finalize_Attributes_Link with System.Tasking.Task_Attributes; -- used for Access_Node -- Access_Dummy_Wrapper -- Deallocator -- Instance -- Node -- Access_Instance with Ada.Exceptions; -- used for Raise_Exception with Unchecked_Conversion; with Unchecked_Deallocation; pragma Elaborate_All (System.Tasking.Task_Attributes); -- to ensure the initialization of object Local (below) will work package body Ada.Task_Attributes is use System.Error_Reporting, System.Tasking.Initialization, System.Tasking, System.Tasking.Task_Attributes, Ada.Exceptions; use type System.Tasking.Access_Address; package POP renames System.Task_Primitives.Operations; --------------------------- -- Unchecked Conversions -- --------------------------- pragma Warnings (Off); -- These unchecked conversions can give warnings when alignments -- are incorrect, but they will not be used in such cases anyway, -- so the warnings can be safely ignored. -- The following type corresponds to Dummy_Wrapper, -- declared in System.Tasking.Task_Attributes. type Wrapper; type Access_Wrapper is access all Wrapper; function To_Attribute_Handle is new Unchecked_Conversion (Access_Address, Attribute_Handle); -- For reference to directly addressed task attributes type Access_Integer_Address is access all System.Storage_Elements.Integer_Address; function To_Attribute_Handle is new Unchecked_Conversion (Access_Integer_Address, Attribute_Handle); -- For reference to directly addressed task attributes function To_Access_Address is new Unchecked_Conversion (Access_Node, Access_Address); -- To store pointer to list of indirect attributes function To_Access_Node is new Unchecked_Conversion (Access_Address, Access_Node); -- To fetch pointer to list of indirect attributes function To_Access_Wrapper is new Unchecked_Conversion (Access_Dummy_Wrapper, Access_Wrapper); -- To fetch pointer to actual wrapper of attribute node function To_Access_Dummy_Wrapper is new Unchecked_Conversion (Access_Wrapper, Access_Dummy_Wrapper); -- To store pointer to actual wrapper of attribute node function To_Task_ID is new Unchecked_Conversion (Task_Identification.Task_Id, Task_ID); -- To access TCB of identified task Null_ID : constant Task_ID := To_Task_ID (Task_Identification.Null_Task_Id); -- ??? need comments on use and purpose type Local_Deallocator is access procedure (P : in out Access_Node); function To_Lib_Level_Deallocator is new Unchecked_Conversion (Local_Deallocator, Deallocator); -- To defeat accessibility check pragma Warnings (On); ------------------------ -- Storage Management -- ------------------------ procedure Deallocate (P : in out Access_Node); -- Passed to the RTS via unchecked conversion of a pointer to -- permit finalization and deallocation of attribute storage nodes -------------------------- -- Instantiation Record -- -------------------------- Local : aliased Instance; -- Initialized in package body type Wrapper is record Noed : aliased Node; Value : aliased Attribute := Initial_Value; -- The generic formal type, may be controlled end record; procedure Free is new Unchecked_Deallocation (Wrapper, Access_Wrapper); procedure Deallocate (P : in out Access_Node) is T : Access_Wrapper := To_Access_Wrapper (P.Wrapper); begin Free (T); exception when others => pragma Assert (Shutdown ("Exception in Deallocate")); null; end Deallocate; --------------- -- Reference -- --------------- function Reference (T : Task_Identification.Task_Id := Task_Identification.Current_Task) return Attribute_Handle is TT : Task_ID := To_Task_ID (T); Error_Message : constant String := "Trying to get the reference of a"; begin if TT = Null_ID then Raise_Exception (Program_Error'Identity, Error_Message & "null task"); end if; if TT.Common.State = Terminated then Raise_Exception (Tasking_Error'Identity, Error_Message & "terminated task"); end if; begin Defer_Abortion; POP.Write_Lock (All_Attrs_L'Access); if Local.Index /= 0 then POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; return To_Attribute_Handle (TT.Direct_Attributes (Local.Index)'Access); else declare P : Access_Node := To_Access_Node (TT.Indirect_Attributes); W : Access_Wrapper; begin while P /= null loop if P.Instance = Access_Instance'(Local'Unchecked_Access) then POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; return To_Access_Wrapper (P.Wrapper).Value'Access; end if; P := P.Next; end loop; -- Unlock All_Attrs_L here to follow the lock ordering rule -- that prevent us from using new (i.e the Global_Lock) while -- holding any other lock. POP.Unlock (All_Attrs_L'Access); W := new Wrapper' ((null, Local'Unchecked_Access, null), Initial_Value); POP.Write_Lock (All_Attrs_L'Access); P := W.Noed'Unchecked_Access; P.Wrapper := To_Access_Dummy_Wrapper (W); P.Next := To_Access_Node (TT.Indirect_Attributes); TT.Indirect_Attributes := To_Access_Address (P); POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; return W.Value'Access; end; end if; pragma Assert (Shutdown ("Should never get here in Reference")); return null; exception when others => POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; raise; end; exception when Tasking_Error | Program_Error => raise; when others => raise Program_Error; end Reference; ------------------ -- Reinitialize -- ------------------ procedure Reinitialize (T : Task_Identification.Task_Id := Task_Identification.Current_Task) is TT : Task_ID := To_Task_ID (T); Error_Message : constant String := "Trying to Reinitialize a"; begin if TT = Null_ID then Raise_Exception (Program_Error'Identity, Error_Message & "null task"); end if; if TT.Common.State = Terminated then Raise_Exception (Tasking_Error'Identity, Error_Message & "terminated task"); end if; if Local.Index = 0 then declare P, Q : Access_Node; W : Access_Wrapper; begin Defer_Abortion; POP.Write_Lock (All_Attrs_L'Access); Q := To_Access_Node (TT.Indirect_Attributes); while Q /= null loop if Q.Instance = Access_Instance'(Local'Unchecked_Access) then if P = null then TT.Indirect_Attributes := To_Access_Address (Q.Next); else P.Next := Q.Next; end if; W := To_Access_Wrapper (Q.Wrapper); Free (W); POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; return; end if; P := Q; Q := Q.Next; end loop; POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; exception when others => POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; end; else Set_Value (Initial_Value, T); end if; exception when Tasking_Error | Program_Error => raise; when others => raise Program_Error; end Reinitialize; --------------- -- Set_Value -- --------------- procedure Set_Value (Val : Attribute; T : Task_Identification.Task_Id := Task_Identification.Current_Task) is TT : Task_ID := To_Task_ID (T); Error_Message : constant String := "Trying to Set the Value of a"; begin if TT = Null_ID then Raise_Exception (Program_Error'Identity, Error_Message & "null task"); end if; if TT.Common.State = Terminated then Raise_Exception (Tasking_Error'Identity, Error_Message & "terminated task"); end if; begin Defer_Abortion; POP.Write_Lock (All_Attrs_L'Access); if Local.Index /= 0 then To_Attribute_Handle (TT.Direct_Attributes (Local.Index)'Access).all := Val; POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; return; else declare P : Access_Node := To_Access_Node (TT.Indirect_Attributes); W : Access_Wrapper; begin while P /= null loop if P.Instance = Access_Instance'(Local'Unchecked_Access) then To_Access_Wrapper (P.Wrapper).Value := Val; POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; return; end if; P := P.Next; end loop; -- Unlock TT here to follow the lock ordering rule that -- prevent us from using new (i.e the Global_Lock) while -- holding any other lock. POP.Unlock (All_Attrs_L'Access); W := new Wrapper' ((null, Local'Unchecked_Access, null), Val); POP.Write_Lock (All_Attrs_L'Access); P := W.Noed'Unchecked_Access; P.Wrapper := To_Access_Dummy_Wrapper (W); P.Next := To_Access_Node (TT.Indirect_Attributes); TT.Indirect_Attributes := To_Access_Address (P); end; end if; POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; exception when others => POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; raise; end; return; exception when Tasking_Error | Program_Error => raise; when others => raise Program_Error; end Set_Value; ----------- -- Value -- ----------- function Value (T : Task_Identification.Task_Id := Task_Identification.Current_Task) return Attribute is Result : Attribute; TT : Task_ID := To_Task_ID (T); Error_Message : constant String := "Trying to get the Value of a"; begin if TT = Null_ID then Raise_Exception (Program_Error'Identity, Error_Message & "null task"); end if; if TT.Common.State = Terminated then Raise_Exception (Program_Error'Identity, Error_Message & "terminated task"); end if; begin if Local.Index /= 0 then Result := To_Attribute_Handle (TT.Direct_Attributes (Local.Index)'Access).all; else declare P : Access_Node; begin Defer_Abortion; POP.Write_Lock (All_Attrs_L'Access); P := To_Access_Node (TT.Indirect_Attributes); while P /= null loop if P.Instance = Access_Instance'(Local'Unchecked_Access) then POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; return To_Access_Wrapper (P.Wrapper).Value; end if; P := P.Next; end loop; Result := Initial_Value; POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; exception when others => POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; raise; end; end if; return Result; end; exception when Tasking_Error | Program_Error => raise; when others => raise Program_Error; end Value; -- Start of elaboration code for package Ada.Task_Attributes begin -- This unchecked conversion can give warnings when alignments -- are incorrect, but they will not be used in such cases anyway, -- so the warnings can be safely ignored. pragma Warnings (Off); Local.Deallocate := To_Lib_Level_Deallocator (Deallocate'Access); pragma Warnings (On); declare Two_To_J : Direct_Index_Vector; begin Defer_Abortion; POP.Write_Lock (All_Attrs_L'Access); -- Add this instantiation to the list of all instantiations. Local.Next := System.Tasking.Task_Attributes.All_Attributes; System.Tasking.Task_Attributes.All_Attributes := Local'Unchecked_Access; -- Try to find space for the attribute in the TCB. Local.Index := 0; Two_To_J := 2 ** Direct_Index'First; if Attribute'Size <= System.Address'Size then for J in Direct_Index loop if (Two_To_J and In_Use) /= 0 then -- Reserve location J for this attribute In_Use := In_Use or Two_To_J; Local.Index := J; -- This unchecked conversions can give a warning when the -- the alignment is incorrect, but it will not be used in -- such a case anyway, so the warning can be safely ignored. pragma Warnings (Off); To_Attribute_Handle (Local.Initial_Value'Access).all := Initial_Value; pragma Warnings (On); exit; end if; Two_To_J := Two_To_J * 2; end loop; end if; -- Need protection of All_Tasks_L for updating links to -- per-task initialization and finalization routines, -- in case some task is being created or terminated concurrently. POP.Lock_All_Tasks_List; -- Attribute goes directly in the TCB if Local.Index /= 0 then -- Replace stub for initialization routine -- that is called at task creation. Initialization.Initialize_Attributes_Link := System.Tasking.Task_Attributes.Initialize_Attributes'Access; -- Initialize the attribute, for all tasks. declare C : System.Tasking.Task_ID := System.Tasking.All_Tasks_List; begin while C /= null loop POP.Write_Lock (C); C.Direct_Attributes (Local.Index) := System.Storage_Elements.To_Address (Local.Initial_Value); POP.Unlock (C); C := C.Common.All_Tasks_Link; end loop; end; -- Attribute goes into a node onto a linked list else -- Replace stub for finalization routine -- that is called at task termination. Initialization.Finalize_Attributes_Link := System.Tasking.Task_Attributes.Finalize_Attributes'Access; end if; POP.Unlock_All_Tasks_List; POP.Unlock (All_Attrs_L'Access); Undefer_Abortion; exception when others => null; pragma Assert (Shutdown ("Exception in task attribute initializer")); -- If we later decide to allow exceptions to propagate, we need to -- not only release locks and undefer abortion, we also need to undo -- any initializations that succeeded up to this point, or we will -- risk a dangling reference when the task terminates. end; end Ada.Task_Attributes;
with Ada.Numerics.Discrete_Random; package body Set_Puzzle is package Rand is new Ada.Numerics.Discrete_Random(Three); R: Rand.Generator; function Locate(Some: Cards; C: Card) return Natural is -- returns index of card C in Some, or 0 if not found begin for I in Some'Range loop if C = Some(I) then return I; end if; end loop; return 0; end Locate; procedure Deal_Cards(Dealt: out Cards) is function Random_Card return Card is (Rand.Random(R), Rand.Random(R), Rand.Random(R), Rand.Random(R)); begin for I in Dealt'Range loop -- draw a random card until different from all card previously drawn Dealt(I) := Random_Card; -- draw random card while Locate(Dealt(Dealt'First .. I-1), Dealt(I)) /= 0 loop -- Dealt(I) has been drawn before Dealt(I) := Random_Card; -- draw another random card end loop; end loop; end Deal_Cards; procedure Find_Sets(Given: Cards) is function To_Set(A, B: Card) return Card is -- returns the unique card C, which would make a set with A and B C: Card; begin for I in 1 .. 4 loop if A(I) = B(I) then C(I) := A(I); -- all three the same else C(I) := 6 - A(I) - B(I); -- all three different; end if; end loop; return C; end To_Set; X: Natural; begin for I in Given'Range loop for J in Given'First .. I-1 loop X := Locate(Given, To_Set(Given(I), Given(J))); if I < X then -- X=0 is no set, 0 < X < I is a duplicate Do_Something(Given, (J, I, X)); end if; end loop; end loop; end Find_Sets; function To_String(C: Card) return String is Col: constant array(Three) of String(1..6) := ("Red ", "Green ", "Purple"); Sym: constant array(Three) of String(1..8) := ("Oval ", "Squiggle", "Diamond "); Num: constant array(Three) of String(1..5) := ("One ", "Two ", "Three"); Sha: constant array(Three) of String(1..7) := ("Solid ", "Open ", "Striped"); begin return (Col(C(1)) & " " & Sym(C(2)) & " " & Num(C(3)) & " " & Sha(C(4))); end To_String; begin Rand.Reset(R); end Set_Puzzle;
with Server; with Ada.Text_IO; procedure Client is begin Ada.Text_IO.Put_Line ("Calling Foo..."); Server.Foo; Ada.Text_IO.Put_Line ("Calling Bar: " & Integer'Image (Server.Bar)); end Client;
-- Copyright 2016 Steven Stewart-Gallus -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -- implied. See the License for the specific language governing -- permissions and limitations under the License. with System; with Interfaces.C; use Interfaces.C; with Interfaces.C.Strings; with Libc.Stdint; with Libc.Stddef; with Pulse.Mainloop.API; with Pulse.Def; with Pulse.Proplist; with Pulse.Sample; package Pulse.Context with Spark_Mode => Off is type pa_context is limited private; type pa_context_access is access all pa_context; type pa_context_notify_cb_t is access procedure (c : pa_context_access; userdata : System.Address); pragma Convention (C, pa_context_notify_cb_t); -- /usr/include/pulse/context.h:159 type pa_context_success_cb_t is access procedure (arg1 : System.Address; arg2 : int; arg3 : System.Address); pragma Convention (C, pa_context_success_cb_t); -- /usr/include/pulse/context.h:162 type pa_context_event_cb_t is access procedure (arg1 : System.Address; arg2 : Interfaces.C.Strings.chars_ptr; arg3 : System.Address; arg4 : System.Address); pragma Convention (C, pa_context_event_cb_t); -- /usr/include/pulse/context.h:169 function pa_context_new (mainloop : access Pulse.Mainloop.API.pa_mainloop_api; name : Interfaces.C.Strings.chars_ptr) return pa_context_access; -- /usr/include/pulse/context.h:174 pragma Import (C, pa_context_new, "pa_context_new"); function pa_context_new_with_proplist (mainloop : access Pulse.Mainloop.API.pa_mainloop_api; name : Interfaces.C.Strings.chars_ptr; proplist : Pulse.Proplist.pa_proplist_access) return pa_context_access; -- /usr/include/pulse/context.h:179 pragma Import (C, pa_context_new_with_proplist, "pa_context_new_with_proplist"); procedure pa_context_unref (c : pa_context_access); -- /usr/include/pulse/context.h:182 pragma Import (C, pa_context_unref, "pa_context_unref"); function pa_context_ref (c : pa_context_access) return System.Address; -- /usr/include/pulse/context.h:185 pragma Import (C, pa_context_ref, "pa_context_ref"); procedure pa_context_set_state_callback (c : pa_context_access; cb : pa_context_notify_cb_t; userdata : System.Address); -- /usr/include/pulse/context.h:188 pragma Import (C, pa_context_set_state_callback, "pa_context_set_state_callback"); procedure pa_context_set_event_callback (p : System.Address; cb : pa_context_event_cb_t; userdata : System.Address); -- /usr/include/pulse/context.h:192 pragma Import (C, pa_context_set_event_callback, "pa_context_set_event_callback"); function pa_context_errno (c : pa_context_access) return int; -- /usr/include/pulse/context.h:195 pragma Import (C, pa_context_errno, "pa_context_errno"); function pa_context_is_pending (c : pa_context_access) return int; -- /usr/include/pulse/context.h:198 pragma Import (C, pa_context_is_pending, "pa_context_is_pending"); function pa_context_get_state (c : pa_context_access) return Pulse.Def.pa_context_state_t; -- /usr/include/pulse/context.h:201 pragma Import (C, pa_context_get_state, "pa_context_get_state"); function pa_context_connect (c : pa_context_access; server : Interfaces.C.Strings.chars_ptr; flags : Pulse.Def.pa_context_flags_t; api : access constant Pulse.Def.pa_spawn_api) return int; -- /usr/include/pulse/context.h:211 pragma Import (C, pa_context_connect, "pa_context_connect"); procedure pa_context_disconnect (c : pa_context_access); -- /usr/include/pulse/context.h:214 pragma Import (C, pa_context_disconnect, "pa_context_disconnect"); function pa_context_drain (c : pa_context_access; cb : pa_context_notify_cb_t; userdata : System.Address) return System.Address; -- /usr/include/pulse/context.h:217 pragma Import (C, pa_context_drain, "pa_context_drain"); function pa_context_exit_daemon (c : pa_context_access; cb : pa_context_success_cb_t; userdata : System.Address) return System.Address; -- /usr/include/pulse/context.h:222 pragma Import (C, pa_context_exit_daemon, "pa_context_exit_daemon"); function pa_context_set_default_sink (c : pa_context_access; name : Interfaces.C.Strings.chars_ptr; cb : pa_context_success_cb_t; userdata : System.Address) return System.Address; -- /usr/include/pulse/context.h:225 pragma Import (C, pa_context_set_default_sink, "pa_context_set_default_sink"); function pa_context_set_default_source (c : pa_context_access; name : Interfaces.C.Strings.chars_ptr; cb : pa_context_success_cb_t; userdata : System.Address) return System.Address; -- /usr/include/pulse/context.h:228 pragma Import (C, pa_context_set_default_source, "pa_context_set_default_source"); function pa_context_is_local (c : pa_context_access) return int; -- /usr/include/pulse/context.h:231 pragma Import (C, pa_context_is_local, "pa_context_is_local"); function pa_context_set_name (c : pa_context_access; name : Interfaces.C.Strings.chars_ptr; cb : pa_context_success_cb_t; userdata : System.Address) return System.Address; -- /usr/include/pulse/context.h:234 pragma Import (C, pa_context_set_name, "pa_context_set_name"); function pa_context_get_server (c : pa_context_access) return Interfaces.C.Strings .chars_ptr; -- /usr/include/pulse/context.h:237 pragma Import (C, pa_context_get_server, "pa_context_get_server"); function pa_context_get_protocol_version (c : pa_context_access) return Libc.Stdint.uint32_t; -- /usr/include/pulse/context.h:240 pragma Import (C, pa_context_get_protocol_version, "pa_context_get_protocol_version"); function pa_context_get_server_protocol_version (c : pa_context_access) return Libc.Stdint.uint32_t; -- /usr/include/pulse/context.h:243 pragma Import (C, pa_context_get_server_protocol_version, "pa_context_get_server_protocol_version"); function pa_context_proplist_update (c : pa_context_access; mode : Pulse.Proplist.pa_update_mode_t; p : System.Address; cb : pa_context_success_cb_t; userdata : System.Address) return System.Address; -- /usr/include/pulse/context.h:250 pragma Import (C, pa_context_proplist_update, "pa_context_proplist_update"); function pa_context_proplist_remove (c : pa_context_access; keys : System.Address; cb : pa_context_success_cb_t; userdata : System.Address) return System.Address; -- /usr/include/pulse/context.h:253 pragma Import (C, pa_context_proplist_remove, "pa_context_proplist_remove"); function pa_context_get_index (s : System.Address) return Libc.Stdint.uint32_t; -- /usr/include/pulse/context.h:258 pragma Import (C, pa_context_get_index, "pa_context_get_index"); function pa_context_rttime_new (c : pa_context_access; usec : Pulse.Sample.pa_usec_t; cb : Pulse.Mainloop.API.pa_time_event_cb_t; userdata : System.Address) return System.Address; -- /usr/include/pulse/context.h:262 pragma Import (C, pa_context_rttime_new, "pa_context_rttime_new"); procedure pa_context_rttime_restart (c : pa_context_access; e : System.Address; usec : Pulse.Sample.pa_usec_t); -- /usr/include/pulse/context.h:266 pragma Import (C, pa_context_rttime_restart, "pa_context_rttime_restart"); function pa_context_get_tile_size (c : pa_context_access; ss : access constant Pulse.Sample.pa_sample_spec) return Libc.Stddef.size_t; -- /usr/include/pulse/context.h:281 pragma Import (C, pa_context_get_tile_size, "pa_context_get_tile_size"); private type pa_context is limited record null; end record; end Pulse.Context;
-- CA2002A0M.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- CHECK THAT SUBUNITS HAVING DIFFERENT ANCESTOR LIBRARY UNITS CAN HAVE -- THE SAME NAME. -- SEPARATE FILES ARE: -- CA2002A0M THE MAIN PROCEDURE, WITH SEPARATE LIBRARY -- PACKAGES (CA2002A1) AND (CA2002A2). -- CA2002A1 SUBUNIT BODIES FOR STUBS IN PACKAGE CA2002A1. -- CA2002A2 SUBUNIT BODIES FOR STUBS IN PACKAGE CA2002A2. -- BHS 8/02/84 PACKAGE CA2002A1 IS PROCEDURE PROC (X : OUT INTEGER); FUNCTION FUN RETURN BOOLEAN; PACKAGE PKG IS I : INTEGER; PROCEDURE PKG_PROC (XX : IN OUT INTEGER); END PKG; END CA2002A1; PACKAGE BODY CA2002A1 IS PROCEDURE PROC (X : OUT INTEGER) IS SEPARATE; FUNCTION FUN RETURN BOOLEAN IS SEPARATE; PACKAGE BODY PKG IS SEPARATE; END CA2002A1; PACKAGE CA2002A2 IS PROCEDURE PROC (Y : OUT INTEGER); FUNCTION FUN (Z : INTEGER := 3) RETURN BOOLEAN; PACKAGE PKG IS I : INTEGER; PROCEDURE PKG_PROC (YY : IN OUT INTEGER); END PKG; END CA2002A2; PACKAGE BODY CA2002A2 IS PROCEDURE PROC (Y : OUT INTEGER) IS SEPARATE; FUNCTION FUN (Z : INTEGER := 3) RETURN BOOLEAN IS SEPARATE; PACKAGE BODY PKG IS SEPARATE; END CA2002A2; WITH CA2002A1, CA2002A2; WITH REPORT; USE REPORT; PROCEDURE CA2002A0M IS BEGIN TEST ("CA2002A", "SUBUNITS WITH DIFFERENT ANCESTORS " & "CAN HAVE THE SAME NAME"); DECLARE VAR1 : INTEGER; USE CA2002A1; BEGIN PROC (VAR1); IF VAR1 /= 1 THEN FAILED ("CA2002A1 PROCEDURE NOT INVOKED CORRECTLY"); END IF; IF NOT FUN THEN FAILED ("CA2002A1 FUNCTION NOT INVOKED CORRECTLY"); END IF; IF PKG.I /= 1 THEN FAILED ("CA2202A1 PKG VARIABLE NOT ACCESSED CORRECTLY"); END IF; VAR1 := 5; PKG.PKG_PROC (VAR1); IF VAR1 /= 4 THEN FAILED ("CA2002A1 PKG SUBUNIT NOT INVOKED CORRECTLY"); END IF; END; DECLARE VAR2 : INTEGER; USE CA2002A2; BEGIN PROC (VAR2); IF VAR2 /= 2 THEN FAILED ("CA2002A2 PROCEDURE NOT INVOKED CORRECTLY"); END IF; IF FUN THEN FAILED ("CA2002A2 FUNCTION NOT INVOKED CORRECTLY"); END IF; IF PKG.I /= 2 THEN FAILED ("CA2002A2 PKG VARIABLE NOT ACCESSED CORRECTLY"); END IF; VAR2 := 3; PKG.PKG_PROC (VAR2); IF VAR2 /= 4 THEN FAILED ("CA2002A2 PKG SUBUNIT NOT INVOKED CORRECTLY"); END IF; END; RESULT; END CA2002A0M;
procedure Quadratic_Bezier ( Picture : in out Image; P1, P2, P3 : Point; Color : Pixel; N : Positive := 20 ) is Points : array (0..N) of Point; begin for I in Points'Range loop declare T : constant Float := Float (I) / Float (N); A : constant Float := (1.0 - T)**2; B : constant Float := 2.0 * T * (1.0 - T); C : constant Float := T**2; begin Points (I).X := Positive (A * Float (P1.X) + B * Float (P2.X) + C * Float (P3.X)); Points (I).Y := Positive (A * Float (P1.Y) + B * Float (P2.Y) + C * Float (P3.Y)); end; end loop; for I in Points'First..Points'Last - 1 loop Line (Picture, Points (I), Points (I + 1), Color); end loop; end Quadratic_Bezier;
------------------------------------------------------------------------------ -- -- -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS -- -- -- -- S Y S T E M . I N T E R R U P T _ M A N A G E M E N T -- -- -- -- S p e c -- -- -- -- $Revision$ -- -- -- Copyright (C) 1991-2001 Free Software Foundation, Inc. -- -- -- -- GNARL is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNARL is distributed in the hope that it will be useful, but WITH- -- -- OUT 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 GNARL; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, 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. -- -- -- -- GNARL was developed by the GNARL team at Florida State University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- -- This is the Alpha/VMS version of this package. -- -- This package encapsulates and centralizes information about -- all uses of interrupts (or signals), including the -- target-dependent mapping of interrupts (or signals) to exceptions. -- PLEASE DO NOT add any with-clauses to this package. -- This is designed to work for both tasking and non-tasking systems, -- without pulling in any of the tasking support. -- PLEASE DO NOT remove the Elaborate_Body pragma from this package. -- Elaboration of this package should happen early, as most other -- initializations depend on it. -- Forcing immediate elaboration of the body also helps to enforce -- the design assumption that this is a second-level -- package, just one level above System.OS_Interface, with no -- cross-dependences. -- PLEASE DO NOT put any subprogram declarations with arguments of -- type Interrupt_ID into the visible part of this package. -- The type Interrupt_ID is used to derive the type in Ada.Interrupts, -- and adding more operations to that type would be illegal according -- to the Ada Reference Manual. (This is the reason why the signals sets -- below are implemented as visible arrays rather than functions.) with System.OS_Interface; -- used for Signal -- sigset_t package System.Interrupt_Management is pragma Elaborate_Body; type Interrupt_Mask is limited private; type Interrupt_ID is new System.OS_Interface.Signal; type Interrupt_Set is array (Interrupt_ID) of Boolean; -- The following objects serve as constants, but are initialized -- in the body to aid portability. This permits us -- to use more portable names for interrupts, -- where distinct names may map to the same interrupt ID value. -- For example, suppose SIGRARE is a signal that is not defined on -- all systems, but is always reserved when it is defined. -- If we have the convention that ID zero is not used for any "real" -- signals, and SIGRARE = 0 when SIGRARE is not one of the locally -- supported signals, we can write -- Reserved (SIGRARE) := true; -- and the initialization code will be portable. Abort_Task_Interrupt : Interrupt_ID; -- The interrupt that is used to implement task abortion, -- if an interrupt is used for that purpose. -- This is one of the reserved interrupts. Keep_Unmasked : Interrupt_Set := (others => False); -- Keep_Unmasked (I) is true iff the interrupt I is -- one that must be kept unmasked at all times, -- except (perhaps) for short critical sections. -- This includes interrupts that are mapped to exceptions -- (see System.Interrupt_Exceptions.Is_Exception), but may also -- include interrupts (e.g. timer) that need to be kept unmasked -- for other reasons. -- Where interrupts are implemented as OS signals, and signal masking -- is per-task, the interrupt should be unmasked in ALL TASKS. Reserve : Interrupt_Set := (others => False); -- Reserve (I) is true iff the interrupt I is one that -- cannot be permitted to be attached to a user handler. -- The possible reasons are many. For example, -- it may be mapped to an exception, used to implement task abortion, -- or used to implement time delays. Keep_Masked : Interrupt_Set := (others => False); -- Keep_Masked (I) is true iff the interrupt I must always be masked. -- Where interrupts are implemented as OS signals, and signal masking -- is per-task, the interrupt should be masked in ALL TASKS. -- There might not be any interrupts in this class, depending on -- the environment. For example, if interrupts are OS signals -- and signal masking is per-task, use of the sigwait operation -- requires the signal be masked in all tasks. procedure Initialize_Interrupts; -- On systems where there is no signal inheritance between tasks (e.g -- VxWorks, GNU/LinuxThreads), this procedure is used to initialize -- interrupts handling in each task. Otherwise this function should -- only be called by initialize in this package body. private use type System.OS_Interface.unsigned_long; type Interrupt_Mask is new System.OS_Interface.sigset_t; -- Interrupts on VMS are implemented with a mailbox. A QIO read is -- registered on the Rcv channel and the interrupt occurs by registering -- a QIO write on the Snd channel. The maximum number of pending -- interrupts is arbitrarily set at 1000. One nice feature of using -- a mailbox is that it is trivially extendable to cross process -- interrupts. Rcv_Interrupt_Chan : System.OS_Interface.unsigned_short := 0; Snd_Interrupt_Chan : System.OS_Interface.unsigned_short := 0; Interrupt_Mailbox : Interrupt_ID := 0; Interrupt_Bufquo : System.OS_Interface.unsigned_long := 1000 * (Interrupt_ID'Size / 8); end System.Interrupt_Management;
with Class1; use Class1; package Class2 is type Class3 is record someClass1 : Class1.Class1; end record; end Class2;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- P R J . C O M -- -- -- -- S p e c -- -- -- -- $Revision$ -- -- -- Copyright (C) 1992-2000 Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT 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 GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- The following package declares data types for GNAT project. -- These data types are used in the bodies of the Prj hierarchy. with GNAT.HTable; with Table; with Types; use Types; package Prj.Com is -- At one point, this package was private. -- It cannot be private, because it is used outside of -- the Prj hierarchy. Tool_Name : Name_Id := No_Name; Current_Verbosity : Verbosity := Default; type Spec_Or_Body is (Specification, Body_Part); type File_Name_Data is record Name : Name_Id := No_Name; Path : Name_Id := No_Name; Project : Project_Id := No_Project; Needs_Pragma : Boolean := False; end record; -- File and Path name of a spec or body. type File_Names_Data is array (Spec_Or_Body) of File_Name_Data; type Unit_Id is new Nat; No_Unit : constant Unit_Id := 0; type Unit_Data is record Name : Name_Id := No_Name; File_Names : File_Names_Data; end record; -- File and Path names of a unit, with a reference to its -- GNAT Project File. package Units is new Table.Table (Table_Component_Type => Unit_Data, Table_Index_Type => Unit_Id, Table_Low_Bound => 1, Table_Initial => 100, Table_Increment => 100, Table_Name => "Prj.Com.Units"); type Header_Num is range 0 .. 2047; function Hash is new GNAT.HTable.Hash (Header_Num => Header_Num); function Hash (Name : Name_Id) return Header_Num; function Hash (Name : String_Id) return Header_Num; package Units_Htable is new GNAT.HTable.Simple_HTable (Header_Num => Header_Num, Element => Unit_Id, No_Element => No_Unit, Key => Name_Id, Hash => Hash, Equal => "="); end Prj.Com;
with Date_Package; use Date_Package; with Ada.Text_IO; use Ada.Text_IO; procedure Lab4a is type Dates is array (1..10) of Date_Type; procedure Test_Get(Date: out Date_Type) is begin loop begin Get(Date); exit; exception when YEAR_ERROR => Put_Line("FEL: YEAR_ERROR"); when MONTH_ERROR => Put_Line("FEL: MONTH_ERROR"); when DAY_ERROR => Put_Line("FEL: DAY_ERROR"); when FORMAT_ERROR => Put_Line("FEL: FORMAT_ERROR"); end; end loop; end Test_Get; Date: Date_Type; begin Put("Ange ett datum: "); Test_Get(Date); Put("Ett datum: "); Put(Date); New_Line; end Lab4a;
with HAL; use HAL; with HiFive1.LEDs; use HiFive1.LEDs; with FE310; with FE310.CLINT; with FE310.Time; use FE310.Time; with Interfaces; use Interfaces; with IO; with SPARKNaCl; use SPARKNaCl; with SPARKNaCl.Core; use SPARKNaCl.Core; with SPARKNaCl.Stream; use SPARKNaCl.Stream; with TweetNaCl_API; with RISCV.CSR; use RISCV.CSR; with FE310.Performance_Monitor; use FE310.Performance_Monitor; procedure TCore is subtype U64 is Unsigned_64; C1, C2 : Byte_Seq (0 .. 2047); N : HSalsa20_Nonce; K : Salsa20_Key; T1, T2 : UInt64; Total_Time : Unsigned_64; CPU_Hz1, CPU_Hz2 : UInt32; procedure Report; procedure Report is begin IO.Put_Line ("Total time: ", Total_Time); end Report; procedure Tweet_HSalsa20 (C : out Byte_Seq; -- Output stream N : in HSalsa20_Nonce; -- Nonce K : in Salsa20_Key); -- Key procedure Tweet_HSalsa20 (C : out Byte_Seq; N : in HSalsa20_Nonce; K : in Salsa20_Key) is begin TweetNaCl_API.HSalsa20 (C, U64 (C'Length), N, K); end Tweet_HSalsa20; begin CPU_Hz1 := FE310.CPU_Frequency; -- The SPI flash clock divider should be as small as possible to increase -- the execution speed of instructions that are not yet in the instruction -- cache. FE310.Set_SPI_Flash_Clock_Divider (2); -- Load the internal oscillator factory calibration to be sure it -- oscillates at a known frequency. FE310.Load_Internal_Oscilator_Calibration; -- Use the HiFive1 16 MHz crystal oscillator which is more acurate than the -- internal oscillator. FE310.Use_Crystal_Oscillator; HiFive1.LEDs.Initialize; CPU_Hz2 := FE310.CPU_Frequency; IO.Put_Line ("CPU Frequency reset was: ", U64 (CPU_Hz1)); IO.Put_Line ("CPU Frequency now is: ", U64 (CPU_Hz2)); FE310.Performance_Monitor.Set_Commit_Events (3, No_Commit_Events); FE310.Performance_Monitor.Set_Commit_Events (4, No_Commit_Events); Turn_On (Red_LED); T1 := FE310.CLINT.Machine_Time; T2 := FE310.CLINT.Machine_Time; IO.Put_Line ("Null timing test:", U64 (T2 - T1)); T1 := Mcycle.Read; Delay_S (1); T2 := Mcycle.Read; IO.Put_Line ("One second test (CYCLE): ", U64 (T2 - T1)); T1 := Minstret.Read; Delay_S (1); T2 := Minstret.Read; IO.Put_Line ("One second test (INSTRET):", U64 (T2 - T1)); T1 := FE310.CLINT.Machine_Time; Delay_S (1); T2 := FE310.CLINT.Machine_Time; IO.Put_Line ("One second test (CLINT): ", U64 (T2 - T1)); IO.Put_Line ("SPARKNaCl.Stream.HSalsa20 test"); -- Arbitrary nonce. N := (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23); -- Arbitrary key Construct (K, Bytes_32'(5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1)); T1 := Mcycle.Read; SPARKNaCl.Stream.HSalsa20 (C1, N, K); T2 := Mcycle.Read; Total_Time := Unsigned_64 (T2 - T1); Report; Turn_Off (Red_LED); Turn_On (Green_LED); IO.New_Line; IO.Put_Line ("TweetNaCl.Core test"); T1 := Mcycle.Read; Tweet_HSalsa20 (C2, N, K); T2 := Mcycle.Read; Total_Time := Unsigned_64 (T2 - T1); Report; if C1 = C2 then IO.Put ("Pass"); else IO.Put ("Fail"); end if; IO.New_Line; IO.New_Line; Turn_Off (Green_LED); -- Blinky! loop Turn_On (Red_LED); Delay_S (1); Turn_Off (Red_LED); Turn_On (Green_LED); Delay_S (1); Turn_Off (Green_LED); Turn_On (Blue_LED); Delay_S (1); Turn_Off (Blue_LED); end loop; end TCore;
#if RENAMED then with Text_IO; use Text_IO; #else with Ada.Text_IO; use Ada.Text_IO; #end if; procedure preproc is begin Put_Line("Hello World"); end preproc;
with Ada.Finalization; with Interfaces.C; with Interfaces.C.Strings; with System; package LADSPA is pragma Preelaborate; package C renames Interfaces.C; Version : constant String := "1.1"; Version_Major : constant := 1; Version_Minor : constant := 1; subtype Data is C.C_float; -- /usr/include/ladspa.h:84 type Data_Ptr is access all Data with Convention => C; type Data_Array is array (C.unsigned_long range <>) of aliased Data with Convention => C; -- As defined in C, this is an int, which is signed! In Ada, it must be unsigned. type All_Properties is mod 2 ** C.int'Size with -- /usr/include/ladspa.h:94 Convention => C; -- See ladspa.h for description of each. Real_Time : constant All_Properties := 1; In_Place_Broken : constant All_Properties := 2; Hard_RT_Capable : constant All_Properties := 4; -- arg-macro: function LADSPA_IS_REALTIME (x) -- return (x) and LADSPA_PROPERTY_REALTIME; -- arg-macro: function LADSPA_IS_INPLACE_BROKEN (x) -- return (x) and LADSPA_PROPERTY_INPLACE_BROKEN; -- arg-macro: function LADSPA_IS_HARD_RT_CAPABLE (x) -- return (x) and LADSPA_PROPERTY_HARD_RT_CAPABLE; -- As above, re All_Properties. type All_Port_Descriptors is mod 2 ** C.int'Size with -- /usr/include/ladspa.h:152 Convention => C; -- See ladspa.h for description of each. Input : constant All_Port_Descriptors := 1; Output : constant All_Port_Descriptors := 2; Control : constant All_Port_Descriptors := 4; Audio : constant All_Port_Descriptors := 8; -- arg-macro: function LADSPA_IS_PORT_INPUT (x) -- return (x) and LADSPA_PORT_INPUT; -- arg-macro: function LADSPA_IS_PORT_OUTPUT (x) -- return (x) and LADSPA_PORT_OUTPUT; -- arg-macro: function LADSPA_IS_PORT_CONTROL (x) -- return (x) and LADSPA_PORT_CONTROL; -- arg-macro: function LADSPA_IS_PORT_AUDIO (x) -- return (x) and LADSPA_PORT_AUDIO; -- As above, re All_Properties. type Port_Range_Hint_Descriptors is mod 2 ** C.int'Size with -- /usr/include/ladspa.h:200 Convention => C; -- See ladspa.h for description of each. Bounded_Below : constant Port_Range_Hint_Descriptors := 16#1#; Bounded_Above : constant Port_Range_Hint_Descriptors := 16#2#; Toggled : constant Port_Range_Hint_Descriptors := 16#4#; Sample_Rate : constant Port_Range_Hint_Descriptors := 16#8#; Logarithmic : constant Port_Range_Hint_Descriptors := 16#10#; Integer : constant Port_Range_Hint_Descriptors := 16#20#; -- Is "Integer" in C, which is a keyword in Ada. Default_Mask : constant Port_Range_Hint_Descriptors := 16#3C0#; Default_None : constant Port_Range_Hint_Descriptors := 16#0#; Default_Minimum : constant Port_Range_Hint_Descriptors := 16#40#; Default_Low : constant Port_Range_Hint_Descriptors := 16#80#; Default_Middle : constant Port_Range_Hint_Descriptors := 16#C0#; Default_High : constant Port_Range_Hint_Descriptors := 16#100#; Default_Maximum : constant Port_Range_Hint_Descriptors := 16#140#; Default_0 : constant Port_Range_Hint_Descriptors := 16#200#; Default_1 : constant Port_Range_Hint_Descriptors := 16#240#; Default_100 : constant Port_Range_Hint_Descriptors := 16#280#; Default_440 : constant Port_Range_Hint_Descriptors := 16#2C0#; -- arg-macro: function LADSPA_IS_HINT_BOUNDED_BELOW (x) -- return (x) and LADSPA_HINT_BOUNDED_BELOW; -- arg-macro: function LADSPA_IS_HINT_BOUNDED_ABOVE (x) -- return (x) and LADSPA_HINT_BOUNDED_ABOVE; -- arg-macro: function LADSPA_IS_HINT_TOGGLED (x) -- return (x) and LADSPA_HINT_TOGGLED; -- arg-macro: function LADSPA_IS_HINT_SAMPLE_RATE (x) -- return (x) and LADSPA_HINT_SAMPLE_RATE; -- arg-macro: function LADSPA_IS_HINT_LOGARITHMIC (x) -- return (x) and LADSPA_HINT_LOGARITHMIC; -- arg-macro: function LADSPA_IS_HINT_INTEGER (x) -- return (x) and LADSPA_HINT_INTEGER; -- arg-macro: function LADSPA_IS_HINT_HAS_DEFAULT (x) -- return (x) and LADSPA_HINT_DEFAULT_MASK; -- arg-macro: function LADSPA_IS_HINT_DEFAULT_MINIMUM (x) -- return ((x) and LADSPA_HINT_DEFAULT_MASK) = LADSPA_HINT_DEFAULT_MINIMUM; -- arg-macro: function LADSPA_IS_HINT_DEFAULT_LOW (x) -- return ((x) and LADSPA_HINT_DEFAULT_MASK) = LADSPA_HINT_DEFAULT_LOW; -- arg-macro: function LADSPA_IS_HINT_DEFAULT_MIDDLE (x) -- return ((x) and LADSPA_HINT_DEFAULT_MASK) = LADSPA_HINT_DEFAULT_MIDDLE; -- arg-macro: function LADSPA_IS_HINT_DEFAULT_HIGH (x) -- return ((x) and LADSPA_HINT_DEFAULT_MASK) = LADSPA_HINT_DEFAULT_HIGH; -- arg-macro: function LADSPA_IS_HINT_DEFAULT_MAXIMUM (x) -- return ((x) and LADSPA_HINT_DEFAULT_MASK) = LADSPA_HINT_DEFAULT_MAXIMUM; -- arg-macro: function LADSPA_IS_HINT_DEFAULT_0 (x) -- return ((x) and LADSPA_HINT_DEFAULT_MASK) = LADSPA_HINT_DEFAULT_0; -- arg-macro: function LADSPA_IS_HINT_DEFAULT_1 (x) -- return ((x) and LADSPA_HINT_DEFAULT_MASK) = LADSPA_HINT_DEFAULT_1; -- arg-macro: function LADSPA_IS_HINT_DEFAULT_100 (x) -- return ((x) and LADSPA_HINT_DEFAULT_MASK) = LADSPA_HINT_DEFAULT_100; -- arg-macro: function LADSPA_IS_HINT_DEFAULT_440 (x) -- return ((x) and LADSPA_HINT_DEFAULT_MASK) = LADSPA_HINT_DEFAULT_440; type All_Port_Range_Hints is record Hint_Descriptor : aliased Port_Range_Hint_Descriptors; Lower_Bound : aliased Data; Upper_Bound : aliased Data; end record with Convention => C_Pass_By_Copy; -- Helper package. -- TODO: There's got to be a better name for this! generic type Port_Type is (<>); package Port_Information is type Descriptor_Array is array (Port_Type) of All_Port_Descriptors with Convention => C; type Name_Array is array (Port_Type) of aliased C.Strings.chars_ptr with Convention => C; type Range_Hint_Array is array (Port_Type) of All_Port_Range_Hints with Convention => C; end Port_Information; type Base_Handle is null record with -- /usr/include/ladspa.h:363 Convention => C; type Handles is access all Base_Handle with Convention => C; type Descriptors; type Instantiators is access function (Descriptor : access constant Descriptors; Sample_Rate : C.unsigned_long) return Handles with Convention => C; type Port_Connectors is access procedure (Instance : in Handles; Port : in C.unsigned_long; Data_Location : in Data_Ptr) with Convention => C; type Activators is access procedure (Instance : in Handles) with Convention => C; type Deactivators is access procedure (Instance : in Handles) with Convention => C; type Runners is access procedure (Instance : in Handles; Sample_Count : in C.unsigned_long) with Convention => C; -- type Adding_Runners is access procedure (Instance : in out Handles; Sample_Count : in unsigned_long) with -- Convention => C; type Gain_Adding_Runners is access procedure (Instance : in Handles; Gain : in Data) with Convention => C; type Cleaners is access procedure (Instance : in Handles) with Convention => C; type Port_Name_Array_Ptr is not null access constant C.Strings.chars_ptr; type Descriptors is record Unique_ID : aliased C.unsigned_long; Label : C.Strings.chars_ptr; Properties : aliased All_Properties; Name : C.Strings.chars_ptr; Maker : C.Strings.chars_ptr; Copyright : C.Strings.chars_ptr; Port_Count : aliased C.unsigned_long; Port_Descriptors : System.Address; -- access All_Port_Descriptors; Port_Names : Port_Name_Array_Ptr; Port_Range_Hints : System.Address; -- access constant All_Port_Range_Hints; Implementation_Data : System.Address; Instantiate : Instantiators; Connect_Port : Port_Connectors; Activate : Activators; Run : Runners; Run_Adding : Runners; Set_Run_Adding_Gain : Gain_Adding_Runners; Deactivate : Deactivators; Clean_Up : Cleaners; end record with Convention => C_Pass_By_Copy; -- This is required so that on finalisation of the library (unload), the globally allocated data is destroyed. type Root_Descriptors is abstract new Ada.Finalization.Limited_Controlled with record Data : aliased Descriptors; end record; overriding procedure Finalize (Self : in out Root_Descriptors); type Descriptor_Functions is access function (Index : C.unsigned_long) return access constant Descriptors with Convention => C; -- /usr/include/ladspa.h:593 end LADSPA;
-- -- Copyright 2018 The wookey project team <wookey@ssi.gouv.fr> -- - Ryad Benadjila -- - Arnauld Michelizza -- - Mathieu Renard -- - Philippe Thierry -- - Philippe Trebuchet -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- with system; package soc.dwt with spark_mode => on is pragma assertion_policy (pre => IGNORE, post => IGNORE, assert => IGNORE); ----------------------------------------------------- -- SPARK ghost functions and procedures ----------------------------------------------------- function init_is_done return boolean; function check_32bits_overflow return boolean with ghost; -------------------------------------------------- -- The Data Watchpoint and Trace unit (DWT) -- -- (Cf. ARMv7-M Arch. Ref. Manual, C1.8, p.779) -- -------------------------------------------------- -- Reset the DWT-based timer procedure reset_timer with pre => not init_is_done; -- Start the DWT timer. The register is counting the number of CPU cycles procedure start_timer with pre => not init_is_done; -- Stop the DWT timer procedure stop_timer with pre => init_is_done; -- Periodically check the DWT CYCCNT register for overflow. This permit -- to detect each time an overflow happends and increment the -- overflow counter to keep a valid 64 bit time value -- precondition check that the package has been initialized and that -- dwt_loop doesn't overflow procedure ovf_manage with --pre => check_32bits_overflow, inline_always; -- Initialize the DWT module procedure init with pre => not init_is_done; -- Get the DWT timer (without overflow support, keep a 32bit value) procedure get_cycles_32(cycles : out unsigned_32) with inline, pre => init_is_done; -- Get the DWT timer with overflow support. permits linear measurement -- on 64 bits cycles time window (approx. 1270857 days) procedure get_cycles (cycles : out unsigned_64) with pre => init_is_done; procedure get_microseconds (micros : out unsigned_64) with inline, pre => init_is_done; procedure get_milliseconds (milli : out unsigned_64) with inline, pre => init_is_done; private -- -- Control register -- type t_DWT_CTRL is record CYCCNTENA : boolean; -- Enables CYCCNT POSTPRESET : bits_4; POSTINIT : bits_4; CYCTAP : bit; SYNCTAP : bits_2; PCSAMPLENA : bit; reserved_13_15 : bits_3; EXCTRCENA : bit; CPIEVTENA : bit; EXCEVTENA : bit; SLEEPEVTENA : bit; LSUEVTENA : bit; FOLDEVTENA : bit; CYCEVTENA : bit; reserved_23 : bit; NOPRFCNT : bit; NOCYCCNT : bit; NOEXTTRIG : bit; NOTRCPKT : bit; NUMCOMP : bits_4; end record with size => 32; for t_DWT_CTRL use record CYCCNTENA at 0 range 0 .. 0; POSTPRESET at 0 range 1 .. 4; POSTINIT at 0 range 5 .. 8; CYCTAP at 0 range 9 .. 9; SYNCTAP at 0 range 10 .. 11; PCSAMPLENA at 0 range 12 .. 12; reserved_13_15 at 0 range 13 .. 15; EXCTRCENA at 0 range 16 .. 16; CPIEVTENA at 0 range 17 .. 17; EXCEVTENA at 0 range 18 .. 18; SLEEPEVTENA at 0 range 19 .. 19; LSUEVTENA at 0 range 20 .. 20; FOLDEVTENA at 0 range 21 .. 21; CYCEVTENA at 0 range 22 .. 22; reserved_23 at 0 range 23 .. 23; NOPRFCNT at 0 range 24 .. 24; NOCYCCNT at 0 range 25 .. 25; NOEXTTRIG at 0 range 26 .. 26; NOTRCPKT at 0 range 27 .. 27; NUMCOMP at 0 range 28 .. 31; end record; DWT_CONTROL : t_DWT_CTRL with import, volatile, address => system'to_address (16#E000_1000#); -- -- CYCCNT register -- subtype t_DWT_CYCCNT is unsigned_32; DWT_CYCCNT : t_DWT_CYCCNT with import, volatile, address => system'to_address (16#E000_1004#); -- Specify the package state. Set to true by init(). init_done : boolean := false; -- -- DWT CYCCNT register overflow counting -- This permit to support incremental getcycle -- with a time window of 64bits length (instead of 32bits) -- dwt_loops : unsigned_64; -- -- Last measured DWT CYCCNT. Compared with current measurement, -- we can detect if the register has generated an overflow or not -- last_dwt : unsigned_32; -------------------------------------------------- -- CoreSight Software Lock registers -- -- Ref.: -- -- - ARMv7-M Arch. Ref. Manual, D1.1, p.826) -- -- - CoreSight Arch. Spec. B2.5.9, p.48 -- -------------------------------------------------- -- -- Lock Access Register (LAR) -- LAR : unsigned_32 with import, volatile, address => system'to_address (16#E000_1FB0#); LAR_ENABLE_WRITE_KEY : constant := 16#C5AC_CE55#; --------------------------------------------------------- -- Debug Exception and Monitor Control Register, DEMCR -- -- (Cf. ARMv7-M Arch. Ref. Manual, C1.6.5, p.765) -- --------------------------------------------------------- type t_DEMCR is record VC_CORERESET : boolean; -- Reset Vector Catch enabled reserved_1_3 : bits_3; VC_MMERR : boolean; -- Debug trap on a MemManage exception VC_NOCPERR : boolean; -- Debug trap on a UsageFault exception caused by an access to a -- Coprocessor VC_CHKERR : boolean; -- Debug trap on a UsageFault exception caused by a checking error VC_STATERR : boolean; -- Debug trap on a UsageFault exception caused by a state information -- error VC_BUSERR : boolean; -- Debug trap on a BusFault exception VC_INTERR : boolean; -- Debug trap on a fault occurring during exception entry or exception -- return VC_HARDERR : boolean; -- Debug trap on a HardFault exception reserved_11_15 : bits_5; MON_EN : boolean; -- DebugMonitor exception enabled MON_PEND : boolean; -- Sets or clears the pending state of the -- DebugMonitor exception MON_STEP : boolean; -- Step the processor MON_REQ : boolean; -- DebugMonitor semaphore bit reserved_20_23 : bits_4; TRCENA : boolean; -- DWT and ITM units enabled end record with size => 32; for t_DEMCR use record VC_CORERESET at 0 range 0 .. 0; reserved_1_3 at 0 range 1 .. 3; VC_MMERR at 0 range 4 .. 4; VC_NOCPERR at 0 range 5 .. 5; VC_CHKERR at 0 range 6 .. 6; VC_STATERR at 0 range 7 .. 7; VC_BUSERR at 0 range 8 .. 8; VC_INTERR at 0 range 9 .. 9; VC_HARDERR at 0 range 10 .. 10; reserved_11_15 at 0 range 11 .. 15; MON_EN at 0 range 16 .. 16; MON_PEND at 0 range 17 .. 17; MON_STEP at 0 range 18 .. 18; MON_REQ at 0 range 19 .. 19; reserved_20_23 at 0 range 20 .. 23; TRCENA at 0 range 24 .. 24; end record; DEMCR : t_DEMCR with import, volatile, address => system'to_address (16#E000_EDFC#); end soc.dwt;
-- (C) Copyright 1999 by John Halleck,All rights reserved. -- Basic Transformation functions of NSA's Secure Hash Algorithm -- This is part of a project at http://www.cc.utah.edu/~nahaj/ package body SHA.Process_Data is Default_Context : Context; -- Standard context for people that don't need -- -- to hash more than one stream at a time; --------------------------------------------------------------------------- -- Totally local functions. -- Raw transformation of the data. procedure Transform (Given : in out Context); -- This is the basic work horse of the standard. Everything else here -- is just frame around this. -- Align data and place in buffer. (Arbitrary chunks.) procedure Graft_On (Given : in out Context; Raw : Unsigned_32; Size : Bit_Index; Increment_Count : Boolean := True); --------------------------------------------------------------------------- -- On with the show ----------------------------------------- -- Quick and easy routine for the most common simple case. function Digest_A_String (Given : String) return Digest is Temp : Context; -- Let's make this totally independent of anything -- -- else the user may be doing. Result : Digest; begin Initialize (Temp); for I in Given'First .. Given'Last loop Add (Byte (Character'Pos (Given (I))), Temp); end loop; Finalize (Result, Temp); return Result; end Digest_A_String; -- Start out the buffer with a good starting state. -- Note that there are assumptions ALL over the code that the -- buffer starts out with zeros. procedure Initialize is begin if Default_Context.Initialized then raise SHA_Second_Initialize; end if; Default_Context := Initial_Value; Default_Context.Initialized := True; end Initialize; procedure Initialize (Given : in out Context) is begin if Given.Initialized then raise SHA_Second_Initialize; end if; Given := Initial_Value; Given.Initialized := True; end Initialize; -- Procedures to add to the data being hashed. procedure Add (Data : Bit) is begin if not Default_Context.Initialized then raise SHA_Not_Initialized; end if; Graft_On (Default_Context, Unsigned_32 (Data), 1); end Add; procedure Add (Data : Bit; Given : in out Context) is begin if not Given.Initialized then raise SHA_Not_Initialized; end if; Graft_On (Given, Unsigned_32 (Data), 1); end Add; procedure Add (Data : Byte) is begin if not Default_Context.Initialized then raise SHA_Not_Initialized; end if; Graft_On (Default_Context, Unsigned_32 (Data), 8); end Add; procedure Add (Data : Byte; Given : in out Context) is begin if not Given.Initialized then raise SHA_Not_Initialized; end if; Graft_On (Given, Unsigned_32 (Data), 8); end Add; procedure Add (Data : Word) is begin if not Default_Context.Initialized then raise SHA_Not_Initialized; end if; Graft_On (Default_Context, Unsigned_32 (Data), 16); end Add; procedure Add (Data : Word; Given : in out Context) is begin if not Given.Initialized then raise SHA_Not_Initialized; end if; Graft_On (Given, Unsigned_32 (Data), 16); end Add; procedure Add (Data : Long) is begin if not Default_Context.Initialized then raise SHA_Not_Initialized; end if; Graft_On (Default_Context, Unsigned_32 (Data), 32); end Add; procedure Add (Data : Long; Given : in out Context) is begin if not Given.Initialized then raise SHA_Not_Initialized; end if; Graft_On (Given, Unsigned_32 (Data), 32); end Add; procedure Add (Data : Long; Size : Bit_Index) is begin if not Default_Context.Initialized then raise SHA_Not_Initialized; end if; Graft_On (Default_Context, Unsigned_32 (Data), Size); end Add; procedure Add (Data : Long; Size : Bit_Index; Given : in out Context) is begin if not Given.Initialized then raise SHA_Not_Initialized; end if; Graft_On (Given, Unsigned_32 (Data), Size); end Add; -- Get the final digest. function Finalize return Digest is Result : Digest; begin Finalize (Result, Default_Context); return Result; end Finalize; procedure Finalize (Result : out Digest) is begin Finalize (Result, Default_Context); end Finalize; procedure Finalize (Result : out Digest; Given : in out Context) is begin if not Given.Initialized then raise SHA_Not_Initialized; end if; -- The standard requires the Data be padded with a single 1 bit. Graft_On (Given, 1, 1, False); -- We may have to make room for the count to be put on the last block. if Given.Next_Word >= Given.Data'Last - 1 then -- Room for the count? if not (Given.Next_Word = Given.Data'Last - 1 and then Given.Remaining_Bits = 32) then Transform (Given); end if; end if; -- Ok, now we can just add the count on. Given.Data (Given.Data'Last - 1) := Given.Count_High; Given.Data (Given.Data'Last) := Given.Count_Low; -- And now we just transform that. Transform (Given); -- Ok, we are done. Given.Initialized := False; -- One aught not to reused this without -- appropriate re-initialization. Result := Given.Current; end Finalize; --------------------------------------------------------------------------- -- Actually put the bits we have into the buffer properly aligned. procedure Graft_On (Given : in out Context; Raw : Unsigned_32; Size : Bit_Index; Increment_Count : Boolean := True) is Offset : Integer range -31 .. 32; -- How far to move to align this? Overflow : Bit_Index := 0; -- How much is into the next word? Remainder : Unsigned_32 := 0; -- What data has to be done in cleanup? Value : Unsigned_32 := Raw; -- What value are we Really working with? begin pragma Inline (Graft_On); -- Huh? if Size = 0 then return; end if; -- How do we have to align the data to fit? Offset := Integer (Given.Remaining_Bits) -- Amount used - Integer (Size); -- Minus amount we have. if Offset > 0 then Value := Shift_Left (Value, Offset); elsif Offset < 0 then Remainder := Shift_Left (Value, 32 + Offset); -- -- Really "- -Offset" Value := Shift_Right (Value, -Offset); Overflow := Bit_Index (-Offset); end if; -- Insert the actual value into the table. Given.Data (Given.Next_Word) := Given.Data (Given.Next_Word) or Value; -- Update where we are in the table. if Offset > 0 then -- Not on a word boundry Given.Remaining_Bits := Given.Remaining_Bits - Size; elsif Given.Next_Word < Data_Buffer'Last then Given.Next_Word := Given.Next_Word + 1; Given.Remaining_Bits := 32; else Transform (Given); -- Also clears everything out of the buffer. end if; -- Handle anything that overflows into the next word. if Overflow /= 0 then Given.Data (Given.Next_Word) := Given.Data (Given.Next_Word) or Remainder; Given.Remaining_Bits := 32 - Overflow; end if; if Increment_Count then Given.Count_Low := Given.Count_Low + Unsigned_32 (Size); if Given.Count_Low < Unsigned_32 (Size) then Given.Count_High := Given.Count_High + 1; if Given.Count_High = 0 then raise SHA_Overflow; end if; -- The standard is only defined up to a total size of what -- you are hashing of 2**64 bits. end if; end if; end Graft_On; --------------------------------------------------------------------------- -- The actual SHA transformation of a block of data. -- Yes, it is cryptic... But it is a pretty much direct transliteration -- of the standard, variable names and all. procedure Transform (Given : in out Context) is Temp : Unsigned_32; -- Buffer to work in. type Work_Buffer is array (0 .. 79) of Unsigned_32; W : Work_Buffer; -- How much is filled from the data, how much is filled by expansion. Fill_Start : constant := Work_Buffer'First + Data_Buffer'Length; Data_End : constant := Fill_Start - 1; A : Unsigned_32 := Given.Current (0); B : Unsigned_32 := Given.Current (1); C : Unsigned_32 := Given.Current (2); D : Unsigned_32 := Given.Current (3); E : Unsigned_32 := Given.Current (4); begin for I in Work_Buffer'First .. Data_End loop W (I) := Given.Data (Word_Range (I)); end loop; for I in Fill_Start .. Work_Buffer'Last loop W (I) := Rotate_Left ( W (I - 3) xor W (I - 8) xor W (I - 14) xor W (I - 16), 1 ); end loop; for I in Work_Buffer'Range loop Temp := W (I) + Rotate_Left (A, 5) + E; case I is when 0 .. 19 => Temp := Temp + 16#5A827999# + ((B and C) or ((not B) and D)); when 20 .. 39 => Temp := Temp + 16#6ED9EBA1# + (B xor C xor D); when 40 .. 59 => Temp := Temp + 16#8F1BBCDC# + ((B and C) or (B and D) or (C and D)); when 60 .. 79 => Temp := Temp + 16#CA62C1D6# + (B xor C xor D); end case; E := D; D := C; C := Rotate_Right (B, 2); -- The standard really says rotate left 30. B := A; A := Temp; end loop; Given.Current := (Given.Current (0) + A, Given.Current (1) + B, Given.Current (2) + C, Given.Current (3) + D, Given.Current (4) + E ); Given.Remaining_Bits := 32; Given.Next_Word := 0; Given.Data := (others => 0); -- *THIS MUST BE DONE* end Transform; end SHA.Process_Data;
pragma License (Unrestricted); -- extended unit package Ada.Enumeration is -- Interfaces.C.Pointers-like utilities for enumeration types. pragma Pure; generic type Enum is (<>); type Distance is range <>; package Arithmetic is function "+" (Left : Enum; Right : Distance) return Enum with Convention => Intrinsic; function "+" (Left : Distance; Right : Enum) return Enum with Convention => Intrinsic; function "-" (Left : Enum; Right : Distance) return Enum with Convention => Intrinsic; function "-" (Left, Right : Enum) return Distance with Convention => Intrinsic; pragma Pure_Function ("+"); pragma Pure_Function ("-"); pragma Inline_Always ("+"); pragma Inline_Always ("-"); procedure Increment (Ref : in out Enum) with Convention => Intrinsic; procedure Decrement (Ref : in out Enum) with Convention => Intrinsic; pragma Inline_Always (Increment); pragma Inline_Always (Decrement); end Arithmetic; end Ada.Enumeration;
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- package body Torrent is ----------- -- Image -- ----------- function Image (Value : SHA1) return SHA1_Image is use type Ada.Streams.Stream_Element; use type Ada.Streams.Stream_Element_Offset; Hex_Digit : constant array (Ada.Streams.Stream_Element range 0 .. 15) of Wide_Wide_Character := ("0123456789ABCDEF"); begin return S : SHA1_Image do for J in Value'Range loop declare Index : constant Natural := 1 + Natural (J - Value'First) * 2; begin S (Index) := Hex_Digit (Value (J) / 16); S (Index + 1) := Hex_Digit (Value (J) mod 16); end; end loop; end return; end Image; end Torrent;
WITH Text_IO; WITH My_Int_IO; WITH My_Flt_IO; WITH Math; PROCEDURE SquareRoots IS -- Illustrates the square root function provided by Math MaxNumber : CONSTANT Positive := 20; FltNum : Float; BEGIN -- SquareRoots Text_IO.Put (Item => "Number Square Root"); Text_IO.New_Line; Text_IO.Put (Item => "------ -----------"); Text_IO.New_Line; FltNum := 1.0; FOR Number IN 1..MaxNumber LOOP My_Int_IO.Put (Item => Number, Width => 3); My_Flt_IO.Put (Item => Math.Sqrt (Float(Number)), Fore => 7, Aft => 5, Exp => 0); My_Flt_IO.Put (Item => Math.Sqrt (FltNum), Fore => 7, Aft => 5, Exp => 0); Text_IO.New_Line; FltNum := FltNum + 1.0; END LOOP; END SquareRoots;
with Interfaces.C; use Interfaces.C; with System; package Mysql.My_list is pragma Preelaborate; -- arg-macro: function list_rest (a) -- return (a).next; -- arg-macro: function list_push (a, b) -- return a):=list_cons((b),(a); -- Copyright (C) 2000 MySQL AB -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; version 2 of the License. -- This program 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 -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- /usr/include/mysql/my_list.h:24:19 type st_list is record prev : access st_list; next : access st_list; data : System.Address; end record; pragma Convention (C, st_list); subtype LIST is st_list; type List_Walk_Action is access function (arg1 : System.Address; arg2 : System.Address) return int; function list_add (arg1 : access st_list; arg2 : access st_list) return access st_list; pragma Import (C, list_add, "list_add"); function list_delete (arg1 : access st_list; arg2 : access st_list) return access st_list; pragma Import (C, list_delete, "list_delete"); function list_cons (arg1 : System.Address; arg2 : access st_list) return access st_list; pragma Import (C, list_cons, "list_cons"); function list_reverse (arg1 : access st_list) return access st_list; pragma Import (C, list_reverse, "list_reverse"); procedure list_free (arg1 : access st_list; arg2 : unsigned); pragma Import (C, list_free, "list_free"); function list_length (arg1 : access st_list) return unsigned; pragma Import (C, list_length, "list_length"); end Mysql.My_list;
-- Copyright (c) 2020-2021 Bartek thindil Jasicki <thindil@laeran.pl> -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- -- This program 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 -- along with this program. If not, see <http://www.gnu.org/licenses/>. with Ada.Directories; use Ada.Directories; with Ada.Strings; use Ada.Strings; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO; use Ada.Text_IO; with Interfaces.C; use Interfaces.C; with Interfaces.C.Strings; use Interfaces.C.Strings; with GNAT.Directory_Operations; use GNAT.Directory_Operations; with CArgv; with Tcl; use Tcl; with Tcl.Ada; use Tcl.Ada; with Tcl.Tk.Ada; use Tcl.Tk.Ada; with Tcl.Tk.Ada.Font; with Tcl.Tk.Ada.Grid; with Tcl.Tk.Ada.TtkStyle; use Tcl.Tk.Ada.TtkStyle; with Tcl.Tk.Ada.Widgets; use Tcl.Tk.Ada.Widgets; with Tcl.Tk.Ada.Widgets.Canvas; use Tcl.Tk.Ada.Widgets.Canvas; with Tcl.Tk.Ada.Widgets.Menu; use Tcl.Tk.Ada.Widgets.Menu; with Tcl.Tk.Ada.Widgets.Text; use Tcl.Tk.Ada.Widgets.Text; with Tcl.Tk.Ada.Widgets.Toplevel.MainWindow; use Tcl.Tk.Ada.Widgets.Toplevel.MainWindow; with Tcl.Tk.Ada.Widgets.TtkEntry; use Tcl.Tk.Ada.Widgets.TtkEntry; with Tcl.Tk.Ada.Widgets.TtkEntry.TtkComboBox; use Tcl.Tk.Ada.Widgets.TtkEntry.TtkComboBox; with Tcl.Tk.Ada.Widgets.TtkEntry.TtkSpinBox; use Tcl.Tk.Ada.Widgets.TtkEntry.TtkSpinBox; with Tcl.Tk.Ada.Widgets.TtkFrame; use Tcl.Tk.Ada.Widgets.TtkFrame; with Tcl.Tk.Ada.Widgets.TtkLabel; use Tcl.Tk.Ada.Widgets.TtkLabel; with Tcl.Tk.Ada.Winfo; use Tcl.Tk.Ada.Winfo; with Tcl.Tk.Ada.Wm; use Tcl.Tk.Ada.Wm; with Tcl.Tklib.Ada.Tooltip; use Tcl.Tklib.Ada.Tooltip; with Config; use Config; with CoreUI; use CoreUI; with Combat.UI; use Combat.UI; with Game; use Game; with Maps.UI; use Maps.UI; with Ships; use Ships; with Themes; use Themes; with Utils.UI; use Utils.UI; package body GameOptions is -- ****it* GameOptions/GameOptions.Accel_Data -- FUNCTION -- Data for showing keyboard shortcuts -- PARAMETERS -- ShortCut - Keyboard shortcut -- EntryName - Name of the text entry which will be showing this shortcut -- SOURCE type Accel_Data is record ShortCut: Unbounded_String; EntryName: Unbounded_String; end record; -- **** -- ****iv* GameOptions/GameOptions.Accels -- FUNCTION -- Array with data to show keyboard shortcuts -- SOURCE Accels: array(1 .. 49) of Accel_Data := (1 => (MenuAccelerators(1), To_Unbounded_String(".menu.shipinfo")), 2 => (MenuAccelerators(2), To_Unbounded_String(".menu.orders")), 3 => (MenuAccelerators(3), To_Unbounded_String(".menu.crafts")), 4 => (MenuAccelerators(4), To_Unbounded_String(".menu.messages")), 5 => (MenuAccelerators(5), To_Unbounded_String(".menu.knowledge")), 6 => (MenuAccelerators(6), To_Unbounded_String(".menu.waitorders")), 7 => (MenuAccelerators(7), To_Unbounded_String(".menu.gamestats")), 8 => (MenuAccelerators(8), To_Unbounded_String(".menu.help")), 9 => (MenuAccelerators(9), To_Unbounded_String(".menu.gameoptions")), 10 => (MenuAccelerators(10), To_Unbounded_String(".menu.quit")), 11 => (MenuAccelerators(11), To_Unbounded_String(".menu.resign")), 12 => (MapAccelerators(1), To_Unbounded_String(".menu.menu")), 13 => (MapAccelerators(2), To_Unbounded_String(".map.mapoptions")), 14 => (MapAccelerators(3), To_Unbounded_String(".map.zoomin")), 15 => (MapAccelerators(4), To_Unbounded_String(".map.zoomout")), 16 => (MapAccelerators(5), To_Unbounded_String(".movement.upleft")), 17 => (MapAccelerators(6), To_Unbounded_String(".movement.up")), 18 => (MapAccelerators(7), To_Unbounded_String(".movement.upright")), 19 => (MapAccelerators(8), To_Unbounded_String(".movement.left")), 20 => (MapAccelerators(10), To_Unbounded_String(".movement.wait")), 21 => (MapAccelerators(9), To_Unbounded_String(".movement.right")), 22 => (MapAccelerators(11), To_Unbounded_String(".movement.downleft")), 23 => (MapAccelerators(12), To_Unbounded_String(".movement.down")), 24 => (MapAccelerators(13), To_Unbounded_String(".movement.downright")), 25 => (MapAccelerators(14), To_Unbounded_String(".movement.moveto")), 26 => (MapAccelerators(15), To_Unbounded_String(".map.center")), 27 => (MapAccelerators(16), To_Unbounded_String(".map.centerhomebase")), 28 => (MapAccelerators(17), To_Unbounded_String(".map.mapupleft")), 29 => (MapAccelerators(18), To_Unbounded_String(".map.mapup")), 30 => (MapAccelerators(19), To_Unbounded_String(".map.mapupright")), 31 => (MapAccelerators(20), To_Unbounded_String(".map.mapleft")), 32 => (MapAccelerators(21), To_Unbounded_String(".map.mapright")), 33 => (MapAccelerators(22), To_Unbounded_String(".map.mapdownleft")), 34 => (MapAccelerators(23), To_Unbounded_String(".map.mapdown")), 35 => (MapAccelerators(24), To_Unbounded_String(".map.mapdownright")), 36 => (MapAccelerators(25), To_Unbounded_String(".map.cursorupleft")), 37 => (MapAccelerators(26), To_Unbounded_String(".map.cursorup")), 38 => (MapAccelerators(27), To_Unbounded_String(".map.cursorupright")), 39 => (MapAccelerators(28), To_Unbounded_String(".map.cursorleft")), 40 => (MapAccelerators(29), To_Unbounded_String(".map.cursorright")), 41 => (MapAccelerators(30), To_Unbounded_String(".map.cursordownleft")), 42 => (MapAccelerators(31), To_Unbounded_String(".map.cursordown")), 43 => (MapAccelerators(32), To_Unbounded_String(".map.cursordownright")), 44 => (MapAccelerators(33), To_Unbounded_String(".map.clickmouse")), 45 => (MapAccelerators(34), To_Unbounded_String(".movement.fullstop")), 46 => (MapAccelerators(35), To_Unbounded_String(".movement.quarterspeed")), 47 => (MapAccelerators(36), To_Unbounded_String(".movement.halfspeed")), 48 => (MapAccelerators(37), To_Unbounded_String(".movement.fullspeed")), 49 => (FullScreenAccel, To_Unbounded_String(".interface.fullscreenkey"))); -- **** -- ****o* GameOptions/GameOptions.Show_Options_Tab_Command -- FUNCTION -- Show the selected options tab -- PARAMETERS -- ClientData - Custom data send to the command. Unused -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. Unused -- Argv - Values of arguments passed to the command. Unused -- RESULT -- This function always return TCL_OK -- COMMANDS -- ShowOptionsTab -- SOURCE function Show_Options_Tab_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Show_Options_Tab_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(ClientData, Argc, Argv); OptionsCanvas: constant Tk_Canvas := Get_Widget(Main_Paned & ".optionsframe.canvas", Interp); OptionsFrame: constant Ttk_Frame := Get_Widget(OptionsCanvas & ".options", Interp); Frame: constant Ttk_Frame := Get_Widget(OptionsFrame & "." & Tcl_GetVar(Interp, "newtab")); OldFrame: constant Ttk_Frame := Get_Widget(Tcl.Tk.Ada.Grid.Grid_Slaves(OptionsFrame, "-row 1")); begin Tcl.Tk.Ada.Grid.Grid_Remove(OldFrame); Tcl.Tk.Ada.Grid.Grid(Frame, "-sticky nwes -padx 10"); Tcl_Eval(Interp, "update"); configure (OptionsCanvas, "-scrollregion [list " & BBox(OptionsCanvas, "all") & "]"); return TCL_OK; end Show_Options_Tab_Command; -- ****o* GameOptions/GameOptions.Show_Options_Command -- FUNCTION -- Show the game options to the player -- PARAMETERS -- ClientData - Custom data send to the command. -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- ShowOptions -- SOURCE function Show_Options_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Show_Options_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is OptionsFrame: Ttk_Frame := Get_Widget(Main_Paned & ".optionsframe", Interp); OptionsCanvas: constant Tk_Canvas := Get_Widget(OptionsFrame & ".canvas", Interp); Label: Ttk_Label; ComboBox_Widget: Ttk_ComboBox; SpinBox_Widget: Ttk_SpinBox; KeyEntry: Ttk_Entry; ThemesList: Unbounded_String; type Widget_Data is record Name: Unbounded_String; Value: Unbounded_String; end record; Labels_Array: constant array(1 .. 4) of Widget_Data := ((To_Unbounded_String("data"), Data_Directory), (To_Unbounded_String("save"), Save_Directory), (To_Unbounded_String("docs"), Doc_Directory), (To_Unbounded_String("mods"), Mods_Directory)); Checkbox_Array: constant array(1 .. 11) of Widget_Data := ((To_Unbounded_String(OptionsCanvas & ".options.general.autorest"), To_Unbounded_String(if Game_Settings.Auto_Rest then "1" else "0")), (To_Unbounded_String(OptionsCanvas & ".options.general.autocenter"), To_Unbounded_String(if Game_Settings.Auto_Center then "1" else "0")), (To_Unbounded_String(OptionsCanvas & ".options.general.autoreturn"), To_Unbounded_String(if Game_Settings.Auto_Return then "1" else "0")), (To_Unbounded_String(OptionsCanvas & ".options.general.autofinish"), To_Unbounded_String(if Game_Settings.Auto_Finish then "1" else "0")), (To_Unbounded_String (OptionsCanvas & ".options.general.autoaskforbases"), To_Unbounded_String (if Game_Settings.Auto_Ask_For_Bases then "1" else "0")), (To_Unbounded_String (OptionsCanvas & ".options.general.autoaskforevents"), To_Unbounded_String (if Game_Settings.Auto_Ask_For_Events then "1" else "0")), (To_Unbounded_String (OptionsCanvas & ".options.interface.rightbutton"), To_Unbounded_String (if Game_Settings.Right_Button then "1" else "0")), (To_Unbounded_String (OptionsCanvas & ".options.interface.showtooltips"), To_Unbounded_String (if Game_Settings.Show_Tooltips then "1" else "0")), (To_Unbounded_String (OptionsCanvas & ".options.interface.showmessages"), To_Unbounded_String (if Game_Settings.Show_Last_Messages then "1" else "0")), (To_Unbounded_String(OptionsCanvas & ".options.interface.fullscreen"), To_Unbounded_String(if Game_Settings.Full_Screen then "1" else "0")), (To_Unbounded_String (OptionsCanvas & ".options.interface.shownumbers"), To_Unbounded_String (if Game_Settings.Show_Numbers then "1" else "0"))); SpinBox_Array: constant array(1 .. 10) of Widget_Data := ((To_Unbounded_String(OptionsCanvas & ".options.general.fuel"), To_Unbounded_String(Natural'Image(Game_Settings.Low_Fuel))), (To_Unbounded_String(OptionsCanvas & ".options.general.drinks"), To_Unbounded_String(Natural'Image(Game_Settings.Low_Drinks))), (To_Unbounded_String(OptionsCanvas & ".options.general.food"), To_Unbounded_String(Natural'Image(Game_Settings.Low_Food))), (To_Unbounded_String (OptionsCanvas & ".options.general.messageslimit"), To_Unbounded_String(Natural'Image(Game_Settings.Messages_Limit))), (To_Unbounded_String (OptionsCanvas & ".options.general.savedmessages"), To_Unbounded_String(Natural'Image(Game_Settings.Saved_Messages))), (To_Unbounded_String (OptionsCanvas & ".options.interface.closemessages"), To_Unbounded_String (Natural'Image(Game_Settings.Auto_Close_Messages_Time))), (To_Unbounded_String(OptionsCanvas & ".options.interface.mapfont"), To_Unbounded_String(Natural'Image(Game_Settings.Map_Font_Size))), (To_Unbounded_String (OptionsCanvas & ".options.interface.interfacefont"), To_Unbounded_String (Natural'Image(Game_Settings.Interface_Font_Size))), (To_Unbounded_String(OptionsCanvas & ".options.interface.helpfont"), To_Unbounded_String(Natural'Image(Game_Settings.Help_Font_Size))), (To_Unbounded_String(OptionsCanvas & ".options.interface.listslimit"), To_Unbounded_String(Natural'Image(Game_Settings.Lists_Limit)))); ComboBox_Array: constant array(Positive range <>) of Widget_Data := ((To_Unbounded_String(OptionsCanvas & ".options.general.speed"), To_Unbounded_String (Natural'Image(Ship_Speed'Pos(Game_Settings.Undock_Speed) - 1))), (To_Unbounded_String(OptionsCanvas & ".options.general.automovestop"), To_Unbounded_String (Natural'Image (Auto_Move_Break'Pos(Game_Settings.Auto_Move_Stop)))), (To_Unbounded_String (OptionsCanvas & ".options.general.messagesorder"), To_Unbounded_String (Natural'Image (Messages_Order_Type'Pos(Game_Settings.Messages_Order)))), (To_Unbounded_String(OptionsCanvas & ".options.general.autosave"), To_Unbounded_String (Natural'Image(Auto_Save_Type'Pos(Game_Settings.Auto_Save))))); begin Label.Interp := Interp; ComboBox_Widget.Interp := Interp; Tcl_SetVar(Interp, "newtab", "general"); if Winfo_Get(OptionsCanvas, "exists") = "0" then Tcl_EvalFile (Get_Context, To_String(Data_Directory) & "ui" & Dir_Separator & "options.tcl"); Bind(OptionsFrame, "<Configure>", "{ResizeCanvas %W.canvas %w %h}"); for Path_Label of Labels_Array loop Label.Name := New_String (Widget_Image(OptionsCanvas) & ".options.info." & To_String(Path_Label.Name)); configure (Label, "-text {" & Full_Name(To_String(Path_Label.Value)) & " }"); end loop; Load_Themes_Loop : for Theme of Themes_List loop Append(ThemesList, " {" & Theme.Name & "}"); end loop Load_Themes_Loop; ComboBox_Widget.Name := New_String(OptionsFrame & ".canvas.options.interface.theme"); configure (ComboBox_Widget, "-values [list" & To_String(ThemesList) & "]"); elsif Winfo_Get(OptionsCanvas, "ismapped") = "1" then Tcl.Tk.Ada.Grid.Grid_Remove(Close_Button); Entry_Configure(GameMenu, "Help", "-command {ShowHelp general}"); ShowSkyMap(True); return TCL_OK; end if; Entry_Configure(GameMenu, "Help", "-command {ShowHelp general}"); OptionsFrame.Name := New_String(OptionsCanvas & ".options.general"); Tcl.Tk.Ada.Grid.Grid(OptionsFrame, "-sticky nwes -padx 10"); for CheckBox of Checkbox_Array loop Tcl_SetVar (Interp, To_String(CheckBox.Name), To_String(CheckBox.Value)); end loop; for SpinBox of SpinBox_Array loop SpinBox_Widget := Get_Widget(To_String(SpinBox.Name), Interp); Set(SpinBox_Widget, To_String(SpinBox.Value)); end loop; for ComboBox of ComboBox_Array loop ComboBox_Widget := Get_Widget(To_String(ComboBox.Name), Interp); Current(ComboBox_Widget, To_String(ComboBox.Value)); end loop; OptionsFrame.Name := New_String(Widget_Image(OptionsCanvas) & ".options.interface"); ComboBox_Widget.Name := New_String(Widget_Image(OptionsFrame) & ".theme"); Set (ComboBox_Widget, "{" & To_String (Themes_List(To_String(Game_Settings.Interface_Theme)).Name) & "}"); KeyEntry.Interp := Interp; OptionsFrame.Name := New_String(Widget_Image(OptionsCanvas) & ".options"); Load_Menu_Accelerators_Loop : for I in MenuAccelerators'Range loop Accels(I).ShortCut := MenuAccelerators(I); end loop Load_Menu_Accelerators_Loop; Load_Map_Accelerators_Loop : for I in MapAccelerators'Range loop Accels(I + MenuAccelerators'Last).ShortCut := MapAccelerators(I); end loop Load_Map_Accelerators_Loop; Accels(Accels'Last).ShortCut := FullScreenAccel; Load_Accelerators_Loop : for Accel of Accels loop KeyEntry.Name := New_String(Widget_Image(OptionsFrame) & To_String(Accel.EntryName)); Delete(KeyEntry, "0", "end"); Insert(KeyEntry, "0", To_String(Accel.ShortCut)); end loop Load_Accelerators_Loop; if cget(Close_Button, "-command") = "ShowCombatUI" then configure(Close_Button, "-command {CloseOptions combat}"); else configure(Close_Button, "-command {CloseOptions map}"); end if; Tcl.Tk.Ada.Grid.Grid(Close_Button, "-row 0 -column 1"); configure (OptionsCanvas, "-height " & cget(Main_Paned, "-height") & " -width " & cget(Main_Paned, "-width")); Tcl_Eval(Get_Context, "update"); Canvas_Create (OptionsCanvas, "window", "0 0 -anchor nw -window " & Widget_Image(OptionsFrame)); Tcl_Eval(Get_Context, "update"); configure (OptionsCanvas, "-scrollregion [list " & BBox(OptionsCanvas, "all") & "]"); Show_Screen("optionsframe"); return Show_Options_Tab_Command(ClientData, Interp, Argc, Argv); end Show_Options_Command; -- ****o* GameOptions/GameOptions.Set_Fonts_Command -- FUNCTION -- Set the selected font -- PARAMETERS -- ClientData - Custom data send to the command. Unused -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. Unused -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- SetFonts -- SOURCE function Set_Fonts_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Set_Fonts_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(ClientData, Argc); FrameName: constant String := ".gameframe.paned.optionsframe.canvas.options.interface"; SpinBox: constant Ttk_SpinBox := Get_Widget(CArgv.Arg(Argv, 1), Interp); HelpFonts: constant array(1 .. 4) of Unbounded_String := (To_Unbounded_String("HelpFont"), To_Unbounded_String("BoldHelpFont"), To_Unbounded_String("UnderlineHelpFont"), To_Unbounded_String("ItalicHelpFont")); InterfaceFonts: constant array(1 .. 4) of Unbounded_String := (To_Unbounded_String("InterfaceFont"), To_Unbounded_String("InterfaceIcons"), To_Unbounded_String("OverstrikedFont"), To_Unbounded_String("UnderlineFont")); begin if CArgv.Arg(Argv, 1) = FrameName & ".mapfont" then Game_Settings.Map_Font_Size := Positive'Value(Get(SpinBox)); Font.Configure ("MapFont", "-size" & Positive'Image(Game_Settings.Map_Font_Size)); elsif CArgv.Arg(Argv, 1) = FrameName & ".helpfont" then Game_Settings.Help_Font_Size := Positive'Value(Get(SpinBox)); Set_Fonts_Loop : for FontName of HelpFonts loop Font.Configure (To_String(FontName), "-size" & Positive'Image(Game_Settings.Help_Font_Size)); end loop Set_Fonts_Loop; else Game_Settings.Interface_Font_Size := Positive'Value(Get(SpinBox)); for FontName of InterfaceFonts loop Font.Configure (To_String(FontName), "-size" & Positive'Image(Game_Settings.Interface_Font_Size)); end loop; end if; return TCL_OK; end Set_Fonts_Command; -- ****o* GameOptions/GameOptions.Set_Default_Fonts_Command -- FUNCTION -- Set the default values for fonts -- PARAMETERS -- ClientData - Custom data send to the command. Unused -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. Unused -- Argv - Values of arguments passed to the command. Unused -- RESULT -- This function always return TCL_OK -- COMMANDS -- SetDefaultFonts -- SOURCE function Set_Default_Fonts_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Set_Default_Fonts_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(ClientData, Argc, Argv); SpinBox: Ttk_SpinBox; SpinBoxNames: constant array(1 .. 3) of Unbounded_String := (To_Unbounded_String("map"), To_Unbounded_String("interface"), To_Unbounded_String("help")); FontNames: constant array(1 .. 3) of Unbounded_String := (To_Unbounded_String("MapFont"), To_Unbounded_String("InterfaceFont"), To_Unbounded_String("HelpFont")); begin SpinBox.Interp := Interp; Set_Default_Fonts_Loop : for I in SpinBoxNames'Range loop SpinBox.Name := New_String (".gameframe.paned.optionsframe.canvas.options.interface." & To_String(SpinBoxNames(I)) & "font"); Set(SpinBox, Positive'Image(DefaultFontsSizes(I))); Font.Configure (To_String(FontNames(I)), "-size" & Positive'Image(DefaultFontsSizes(I))); end loop Set_Default_Fonts_Loop; Font.Configure ("InterfaceIcons", "-size" & Positive'Image(DefaultFontsSizes(2))); return TCL_OK; end Set_Default_Fonts_Command; -- ****o* GameOptions/GameOptions.Close_Options_Command -- FUNCTION -- Save all options and back to the map -- PARAMETERS -- ClientData - Custom data send to the command. Unused -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. Unused -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- CloseOptions oldscreen -- Oldscreen is name of the screen to which the game should return. -- Can be 'map' or 'combat'. -- SOURCE function Close_Options_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Close_Options_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(ClientData, Argc); RootName: constant String := ".gameframe.paned.optionsframe.canvas.options"; KeyEntry: Ttk_Entry; KeysFile: File_Type; MapView: Tk_Text; ThemeComboBox: constant Ttk_ComboBox := Get_Widget(RootName & ".interface.theme", Interp); function Get_Spinbox_Value(SpinBox_Name: String) return Natural is SpinBox: constant Ttk_SpinBox := Get_Widget(RootName & SpinBox_Name, Interp); begin return Natural'Value(Get(SpinBox)); end Get_Spinbox_Value; function Get_Checkbox_Value(CheckBox_Name: String) return Boolean is begin if Tcl_GetVar(Interp, RootName & CheckBox_Name) = "1" then return True; end if; return False; end Get_Checkbox_Value; function Get_Combobox_Value(ComboBox_Name: String) return Natural is ComboBox: constant Ttk_ComboBox := Get_Widget(RootName & ComboBox_Name, Interp); begin return Natural'Value(Current(ComboBox)); end Get_Combobox_Value; begin configure(Close_Button, "-command ShowSkyMap"); Tcl.Tk.Ada.Grid.Grid_Remove(Close_Button); Game_Settings.Auto_Rest := Get_Checkbox_Value(".general.autorest"); Game_Settings.Undock_Speed := Ship_Speed'Val(Get_Combobox_Value(".general.speed") + 1); Game_Settings.Auto_Center := Get_Checkbox_Value(".general.autocenter"); Game_Settings.Auto_Return := Get_Checkbox_Value(".general.autoreturn"); Game_Settings.Auto_Finish := Get_Checkbox_Value(".general.autofinish"); Game_Settings.Auto_Ask_For_Bases := Get_Checkbox_Value(".general.autoaskforbases"); Game_Settings.Auto_Ask_For_Events := Get_Checkbox_Value(".general.autoaskforevents"); Game_Settings.Low_Fuel := Get_Spinbox_Value(".general.fuel"); Game_Settings.Low_Drinks := Get_Spinbox_Value(".general.drinks"); Game_Settings.Low_Food := Get_Spinbox_Value(".general.food"); Game_Settings.Auto_Move_Stop := Auto_Move_Break'Val(Get_Combobox_Value(".general.automovestop")); Game_Settings.Messages_Limit := Get_Spinbox_Value(".general.messageslimit"); Game_Settings.Saved_Messages := Get_Spinbox_Value(".general.savedmessages"); Game_Settings.Messages_Order := Messages_Order_Type'Val(Get_Combobox_Value(".general.messagesorder")); Game_Settings.Auto_Save := Auto_Save_Type'Val(Get_Combobox_Value(".general.autosave")); Set_Theme_Loop : for I in Themes_List.Iterate loop if Themes_List(I).Name = Get(ThemeComboBox) then Game_Settings.Interface_Theme := To_Unbounded_String(Themes_Container.Key(I)); exit Set_Theme_Loop; end if; end loop Set_Theme_Loop; Theme_Use(To_String(Game_Settings.Interface_Theme)); Set_Theme; MapView := Get_Widget(".gameframe.paned.mapframe.map"); if Tcl_GetVar(Interp, RootName & ".interface.rightbutton") = "1" then Game_Settings.Right_Button := True; Bind(MapView, "<Button-3>", "{ShowDestinationMenu %X %Y}"); Unbind(MapView, "<Button-1>"); else Game_Settings.Right_Button := False; Bind(MapView, "<Button-1>", "{ShowDestinationMenu %X %Y}"); Unbind(MapView, "<Button-3>"); end if; if Tcl_GetVar(Interp, RootName & ".interface.showtooltips") = "1" then Game_Settings.Show_Tooltips := True; Enable; else Game_Settings.Show_Tooltips := False; Disable; end if; Game_Settings.Show_Last_Messages := (if Tcl_GetVar(Interp, RootName & ".interface.showmessages") = "1" then True else False); if Tcl_GetVar(Interp, RootName & ".interface.fullscreen") = "1" then Game_Settings.Full_Screen := True; Wm_Set(Get_Main_Window(Interp), "attributes", "-fullscreen 1"); else Game_Settings.Full_Screen := False; Wm_Set(Get_Main_Window(Interp), "attributes", "-fullscreen 0"); end if; Game_Settings.Auto_Close_Messages_Time := Get_Spinbox_Value(".interface.closemessages"); Game_Settings.Show_Numbers := Get_Checkbox_Value(".interface.shownumbers"); Game_Settings.Map_Font_Size := Get_Spinbox_Value(".interface.mapfont"); Game_Settings.Help_Font_Size := Get_Spinbox_Value(".interface.helpfont"); Game_Settings.Interface_Font_Size := Get_Spinbox_Value(".interface.interfacefont"); Game_Settings.Lists_Limit := Get_Spinbox_Value(".interface.listslimit"); Save_Config; KeyEntry.Interp := Interp; Set_Accelerators_Loop : for I in 1 .. (Accels'Last - 1) loop Unbind_From_Main_Window (Interp, "<" & To_String (Insert (Accels(I).ShortCut, Index(Accels(I).ShortCut, "-", Backward) + 1, "KeyPress-")) & ">"); KeyEntry.Name := New_String(RootName & To_String(Accels(I).EntryName)); if I < 12 then MenuAccelerators(I) := To_Unbounded_String(Get(KeyEntry)); Bind_To_Main_Window (Get_Context, "<" & To_String (Insert (To_Unbounded_String(Get(KeyEntry)), Index(To_Unbounded_String(Get(KeyEntry)), "-", Backward) + 1, "KeyPress-")) & ">", "{InvokeMenu " & To_String(MenuAccelerators(I)) & "}"); Bind (GameMenu, "<" & To_String (Insert (To_Unbounded_String(Get(KeyEntry)), Index(To_Unbounded_String(Get(KeyEntry)), "-", Backward) + 1, "KeyPress-")) & ">", "{InvokeMenu " & To_String(MenuAccelerators(I)) & "}"); else MapAccelerators(I - 11) := To_Unbounded_String(Get(KeyEntry)); end if; end loop Set_Accelerators_Loop; Unbind_From_Main_Window (Interp, "<" & To_String (Insert (Accels(Accels'Last).ShortCut, Index(Accels(Accels'Last).ShortCut, "-", Backward) + 1, "KeyPress-")) & ">"); KeyEntry.Name := New_String(RootName & To_String(Accels(Accels'Last).EntryName)); FullScreenAccel := To_Unbounded_String(Get(KeyEntry)); Create(KeysFile, Append_File, To_String(Save_Directory) & "keys.cfg"); Save_Menu_Accelerators_Loop : for Key of MenuAccelerators loop Put_Line(KeysFile, To_String(Key)); end loop Save_Menu_Accelerators_Loop; Save_Map_Accelerators_Loop : for Key of MapAccelerators loop Put_Line(KeysFile, To_String(Key)); end loop Save_Map_Accelerators_Loop; Put_Line(KeysFile, To_String(FullScreenAccel)); Close(KeysFile); SetKeys; if CArgv.Arg(Argv, 1) = "map" then CreateGameMenu; ShowSkyMap(True); else ShowCombatUI(False); end if; return TCL_OK; end Close_Options_Command; -- ****o* GameOptions/GameOptions.Reset_Keys_Command -- FUNCTION -- Reset the selected group of keys to their default values -- PARAMETERS -- ClientData - Custom data send to the command. Unused -- Interp - Tcl interpreter in which command was executed. -- Argc - Number of arguments passed to the command. Unused -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- ResetKeys group -- Group is the group of keys which will be resetted. Possible values are -- movement, map, menu -- SOURCE function Reset_Keys_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Reset_Keys_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(ClientData, Argc); Default_Movement_Accels: constant array(1 .. 14) of Accel_Data := (1 => (To_Unbounded_String ((if Dir_Separator = '\' then "Home" else "KP_7")), To_Unbounded_String(".movement.upleft")), 2 => (To_Unbounded_String ((if Dir_Separator = '\' then "Up" else "KP_8")), To_Unbounded_String(".movement.up")), 3 => (To_Unbounded_String ((if Dir_Separator = '\' then "Prior" else "KP_9")), To_Unbounded_String(".movement.upright")), 4 => (To_Unbounded_String ((if Dir_Separator = '\' then "Left" else "KP_4")), To_Unbounded_String(".movement.left")), 5 => (To_Unbounded_String ((if Dir_Separator = '\' then "Clear" else "KP_5")), To_Unbounded_String(".movement.wait")), 6 => (To_Unbounded_String ((if Dir_Separator = '\' then "Right" else "KP_6")), To_Unbounded_String(".movement.right")), 7 => (To_Unbounded_String ((if Dir_Separator = '\' then "End" else "KP_1")), To_Unbounded_String(".movement.downleft")), 8 => (To_Unbounded_String ((if Dir_Separator = '\' then "Down" else "KP_2")), To_Unbounded_String(".movement.down")), 9 => (To_Unbounded_String ((if Dir_Separator = '\' then "Next" else "KP_3")), To_Unbounded_String(".movement.downright")), 10 => (To_Unbounded_String ((if Dir_Separator = '\' then "slash" else "KP_Divide")), To_Unbounded_String(".movement.moveto")), 11 => (To_Unbounded_String("Control-a"), To_Unbounded_String(".movement.fullstop")), 12 => (To_Unbounded_String("Control-b"), To_Unbounded_String(".movement.quarterspeed")), 13 => (To_Unbounded_String("Control-c"), To_Unbounded_String(".movement.halfspeed")), 14 => (To_Unbounded_String("Control-d"), To_Unbounded_String(".movement.fullspeed"))); Default_Menu_Accels: constant array(1 .. 12) of Accel_Data := (1 => (To_Unbounded_String("s"), To_Unbounded_String(".menu.shipinfo")), 2 => (To_Unbounded_String("o"), To_Unbounded_String(".menu.orders")), 3 => (To_Unbounded_String("r"), To_Unbounded_String(".menu.crafts")), 4 => (To_Unbounded_String("m"), To_Unbounded_String(".menu.messages")), 5 => (To_Unbounded_String("k"), To_Unbounded_String(".menu.knowledge")), 6 => (To_Unbounded_String("w"), To_Unbounded_String(".menu.waitorders")), 7 => (To_Unbounded_String("g"), To_Unbounded_String(".menu.gamestats")), 8 => (To_Unbounded_String("F1"), To_Unbounded_String(".menu.help")), 9 => (To_Unbounded_String("p"), To_Unbounded_String(".menu.gameoptions")), 10 => (To_Unbounded_String("q"), To_Unbounded_String(".menu.quit")), 11 => (To_Unbounded_String("x"), To_Unbounded_String(".menu.resign")), 12 => (To_Unbounded_String("e"), To_Unbounded_String(".menu.menu"))); Default_Map_Accels: constant array(1 .. 23) of Accel_Data := (1 => (To_Unbounded_String("Shift-Return"), To_Unbounded_String(".map.center")), 2 => (To_Unbounded_String("Shift-h"), To_Unbounded_String(".map.centerhomebase")), 3 => (To_Unbounded_String ("Shift-" & (if Dir_Separator = '\' then "Home" else "KP_7")), To_Unbounded_String(".map.mapupleft")), 4 => (To_Unbounded_String ("Shift-" & (if Dir_Separator = '\' then "Up" else "KP_8")), To_Unbounded_String(".map.mapup")), 5 => (To_Unbounded_String ("Shift-" & (if Dir_Separator = '\' then "Prior" else "KP_9")), To_Unbounded_String(".map.mapupright")), 6 => (To_Unbounded_String ("Shift-" & (if Dir_Separator = '\' then "Left" else "KP_4")), To_Unbounded_String(".map.mapleft")), 7 => (To_Unbounded_String ("Shift-" & (if Dir_Separator = '\' then "Right" else "KP_6")), To_Unbounded_String(".map.mapright")), 8 => (To_Unbounded_String ("Shift-" & (if Dir_Separator = '\' then "End" else "KP_1")), To_Unbounded_String(".map.mapdownleft")), 9 => (To_Unbounded_String ("Shift-" & (if Dir_Separator = '\' then "Down" else "KP_2")), To_Unbounded_String(".map.mapdown")), 10 => (To_Unbounded_String ("Shift-" & (if Dir_Separator = '\' then "Next" else "KP_3")), To_Unbounded_String(".map.mapdownright")), 11 => (To_Unbounded_String ("Control-" & (if Dir_Separator = '\' then "Home" else "KP_7")), To_Unbounded_String(".map.cursorupleft")), 12 => (To_Unbounded_String ("Control-" & (if Dir_Separator = '\' then "Up" else "KP_8")), To_Unbounded_String(".map.cursorup")), 13 => (To_Unbounded_String ("Control-" & (if Dir_Separator = '\' then "Prior" else "KP_9")), To_Unbounded_String(".map.cursorupright")), 14 => (To_Unbounded_String ("Control-" & (if Dir_Separator = '\' then "Left" else "KP_4")), To_Unbounded_String(".map.cursorleft")), 15 => (To_Unbounded_String ("Control-" & (if Dir_Separator = '\' then "Right" else "KP_6")), To_Unbounded_String(".map.cursorright")), 16 => (To_Unbounded_String ("Control-" & (if Dir_Separator = '\' then "End" else "KP_1")), To_Unbounded_String(".map.cursordownleft")), 17 => (To_Unbounded_String ("Control-" & (if Dir_Separator = '\' then "Down" else "KP_2")), To_Unbounded_String(".map.cursordown")), 18 => (To_Unbounded_String ("Control-" & (if Dir_Separator = '\' then "Next" else "KP_3")), To_Unbounded_String(".map.cursordownright")), 19 => (To_Unbounded_String ("Control-" & (if Dir_Separator = '\' then "Begin" else "KP_Begin")), To_Unbounded_String(".map.clickmouse")), 20 => (To_Unbounded_String("Control-a"), To_Unbounded_String(".movement.fullstop")), 21 => (To_Unbounded_String("Control-b"), To_Unbounded_String(".movement.quarterspeed")), 22 => (To_Unbounded_String("Control-c"), To_Unbounded_String(".movement.halfspeed")), 23 => (To_Unbounded_String("Control-d"), To_Unbounded_String(".movement.fullspeed"))); KeyEntry: Ttk_Entry; begin KeyEntry.Interp := Interp; if CArgv.Arg(Argv, 1) = "movement" then Reset_Movement_Keys_Loop : for Accel of Default_Movement_Accels loop KeyEntry.Name := New_String (".gameframe.paned.optionsframe.canvas.options" & To_String(Accel.EntryName)); Delete(KeyEntry, "0", "end"); Insert(KeyEntry, "0", To_String(Accel.ShortCut)); end loop Reset_Movement_Keys_Loop; elsif CArgv.Arg(Argv, 1) = "menu" then Reset_Menu_Keys_Loop : for Accel of Default_Menu_Accels loop KeyEntry.Name := New_String (".gameframe.paned.optionsframe.canvas.options" & To_String(Accel.EntryName)); Delete(KeyEntry, "0", "end"); Insert(KeyEntry, "0", To_String(Accel.ShortCut)); end loop Reset_Menu_Keys_Loop; elsif CArgv.Arg(Argv, 1) = "map" then Reset_Map_Keys_Loop : for Accel of Default_Map_Accels loop KeyEntry.Name := New_String (".gameframe.paned.optionsframe.canvas.options" & To_String(Accel.EntryName)); Delete(KeyEntry, "0", "end"); Insert(KeyEntry, "0", To_String(Accel.ShortCut)); end loop Reset_Map_Keys_Loop; end if; return TCL_OK; end Reset_Keys_Command; procedure AddCommands is begin Add_Command("ShowOptions", Show_Options_Command'Access); Add_Command("SetFonts", Set_Fonts_Command'Access); Add_Command("SetDefaultFonts", Set_Default_Fonts_Command'Access); Add_Command("CloseOptions", Close_Options_Command'Access); Add_Command("ShowOptionsTab", Show_Options_Tab_Command'Access); Add_Command("ResetKeys", Reset_Keys_Command'Access); end AddCommands; end GameOptions;
------------------------------------------------------------------------------ -- -- -- GNAT LIBRARY COMPONENTS -- -- -- -- ADA.CONTAINERS.FORMAL_DOUBLY_LINKED_LISTS -- -- -- -- B o d y -- -- -- -- Copyright (C) 2010-2016, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- ------------------------------------------------------------------------------ with System; use type System.Address; package body Ada.Containers.Formal_Doubly_Linked_Lists with SPARK_Mode => Off is ----------------------- -- Local Subprograms -- ----------------------- procedure Allocate (Container : in out List; New_Item : Element_Type; New_Node : out Count_Type); procedure Allocate (Container : in out List; New_Node : out Count_Type); procedure Free (Container : in out List; X : Count_Type); procedure Insert_Internal (Container : in out List; Before : Count_Type; New_Node : Count_Type); function Vet (L : List; Position : Cursor) return Boolean; --------- -- "=" -- --------- function "=" (Left, Right : List) return Boolean is LI, RI : Count_Type; begin if Left'Address = Right'Address then return True; end if; if Left.Length /= Right.Length then return False; end if; LI := Left.First; RI := Left.First; while LI /= 0 loop if Left.Nodes (LI).Element /= Right.Nodes (LI).Element then return False; end if; LI := Left.Nodes (LI).Next; RI := Right.Nodes (RI).Next; end loop; return True; end "="; -------------- -- Allocate -- -------------- procedure Allocate (Container : in out List; New_Item : Element_Type; New_Node : out Count_Type) is N : Node_Array renames Container.Nodes; begin if Container.Free >= 0 then New_Node := Container.Free; N (New_Node).Element := New_Item; Container.Free := N (New_Node).Next; else New_Node := abs Container.Free; N (New_Node).Element := New_Item; Container.Free := Container.Free - 1; end if; end Allocate; procedure Allocate (Container : in out List; New_Node : out Count_Type) is N : Node_Array renames Container.Nodes; begin if Container.Free >= 0 then New_Node := Container.Free; Container.Free := N (New_Node).Next; else New_Node := abs Container.Free; Container.Free := Container.Free - 1; end if; end Allocate; ------------ -- Append -- ------------ procedure Append (Container : in out List; New_Item : Element_Type; Count : Count_Type := 1) is begin Insert (Container, No_Element, New_Item, Count); end Append; ------------ -- Assign -- ------------ procedure Assign (Target : in out List; Source : List) is N : Node_Array renames Source.Nodes; J : Count_Type; begin if Target'Address = Source'Address then return; end if; if Target.Capacity < Source.Length then raise Constraint_Error with -- ??? "Source length exceeds Target capacity"; end if; Clear (Target); J := Source.First; while J /= 0 loop Append (Target, N (J).Element); J := N (J).Next; end loop; end Assign; ----------- -- Clear -- ----------- procedure Clear (Container : in out List) is N : Node_Array renames Container.Nodes; X : Count_Type; begin if Container.Length = 0 then pragma Assert (Container.First = 0); pragma Assert (Container.Last = 0); return; end if; pragma Assert (Container.First >= 1); pragma Assert (Container.Last >= 1); pragma Assert (N (Container.First).Prev = 0); pragma Assert (N (Container.Last).Next = 0); while Container.Length > 1 loop X := Container.First; Container.First := N (X).Next; N (Container.First).Prev := 0; Container.Length := Container.Length - 1; Free (Container, X); end loop; X := Container.First; Container.First := 0; Container.Last := 0; Container.Length := 0; Free (Container, X); end Clear; -------------- -- Contains -- -------------- function Contains (Container : List; Item : Element_Type) return Boolean is begin return Find (Container, Item) /= No_Element; end Contains; ---------- -- Copy -- ---------- function Copy (Source : List; Capacity : Count_Type := 0) return List is C : constant Count_Type := Count_Type'Max (Source.Capacity, Capacity); N : Count_Type; P : List (C); begin if 0 < Capacity and then Capacity < Source.Capacity then raise Capacity_Error; end if; N := 1; while N <= Source.Capacity loop P.Nodes (N).Prev := Source.Nodes (N).Prev; P.Nodes (N).Next := Source.Nodes (N).Next; P.Nodes (N).Element := Source.Nodes (N).Element; N := N + 1; end loop; P.Free := Source.Free; P.Length := Source.Length; P.First := Source.First; P.Last := Source.Last; if P.Free >= 0 then N := Source.Capacity + 1; while N <= C loop Free (P, N); N := N + 1; end loop; end if; return P; end Copy; --------------------- -- Current_To_Last -- --------------------- function Current_To_Last (Container : List; Current : Cursor) return List is Curs : Cursor := First (Container); C : List (Container.Capacity) := Copy (Container, Container.Capacity); Node : Count_Type; begin if Curs = No_Element then Clear (C); return C; end if; if Current /= No_Element and not Has_Element (Container, Current) then raise Constraint_Error; end if; while Curs.Node /= Current.Node loop Node := Curs.Node; Delete (C, Curs); Curs := Next (Container, (Node => Node)); end loop; return C; end Current_To_Last; ------------ -- Delete -- ------------ procedure Delete (Container : in out List; Position : in out Cursor; Count : Count_Type := 1) is N : Node_Array renames Container.Nodes; X : Count_Type; begin if not Has_Element (Container => Container, Position => Position) then raise Constraint_Error with "Position cursor has no element"; end if; pragma Assert (Vet (Container, Position), "bad cursor in Delete"); pragma Assert (Container.First >= 1); pragma Assert (Container.Last >= 1); pragma Assert (N (Container.First).Prev = 0); pragma Assert (N (Container.Last).Next = 0); if Position.Node = Container.First then Delete_First (Container, Count); Position := No_Element; return; end if; if Count = 0 then Position := No_Element; return; end if; for Index in 1 .. Count loop pragma Assert (Container.Length >= 2); X := Position.Node; Container.Length := Container.Length - 1; if X = Container.Last then Position := No_Element; Container.Last := N (X).Prev; N (Container.Last).Next := 0; Free (Container, X); return; end if; Position.Node := N (X).Next; pragma Assert (N (Position.Node).Prev >= 0); N (N (X).Next).Prev := N (X).Prev; N (N (X).Prev).Next := N (X).Next; Free (Container, X); end loop; Position := No_Element; end Delete; ------------------ -- Delete_First -- ------------------ procedure Delete_First (Container : in out List; Count : Count_Type := 1) is N : Node_Array renames Container.Nodes; X : Count_Type; begin if Count >= Container.Length then Clear (Container); return; end if; if Count = 0 then return; end if; for J in 1 .. Count loop X := Container.First; pragma Assert (N (N (X).Next).Prev = Container.First); Container.First := N (X).Next; N (Container.First).Prev := 0; Container.Length := Container.Length - 1; Free (Container, X); end loop; end Delete_First; ----------------- -- Delete_Last -- ----------------- procedure Delete_Last (Container : in out List; Count : Count_Type := 1) is N : Node_Array renames Container.Nodes; X : Count_Type; begin if Count >= Container.Length then Clear (Container); return; end if; if Count = 0 then return; end if; for J in 1 .. Count loop X := Container.Last; pragma Assert (N (N (X).Prev).Next = Container.Last); Container.Last := N (X).Prev; N (Container.Last).Next := 0; Container.Length := Container.Length - 1; Free (Container, X); end loop; end Delete_Last; ------------- -- Element -- ------------- function Element (Container : List; Position : Cursor) return Element_Type is begin if not Has_Element (Container => Container, Position => Position) then raise Constraint_Error with "Position cursor has no element"; end if; return Container.Nodes (Position.Node).Element; end Element; ---------- -- Find -- ---------- function Find (Container : List; Item : Element_Type; Position : Cursor := No_Element) return Cursor is From : Count_Type := Position.Node; begin if From = 0 and Container.Length = 0 then return No_Element; end if; if From = 0 then From := Container.First; end if; if Position.Node /= 0 and then not Has_Element (Container, Position) then raise Constraint_Error with "Position cursor has no element"; end if; while From /= 0 loop if Container.Nodes (From).Element = Item then return (Node => From); end if; From := Container.Nodes (From).Next; end loop; return No_Element; end Find; ----------- -- First -- ----------- function First (Container : List) return Cursor is begin if Container.First = 0 then return No_Element; end if; return (Node => Container.First); end First; ------------------- -- First_Element -- ------------------- function First_Element (Container : List) return Element_Type is F : constant Count_Type := Container.First; begin if F = 0 then raise Constraint_Error with "list is empty"; else return Container.Nodes (F).Element; end if; end First_Element; ----------------------- -- First_To_Previous -- ----------------------- function First_To_Previous (Container : List; Current : Cursor) return List is Curs : Cursor := Current; C : List (Container.Capacity) := Copy (Container, Container.Capacity); Node : Count_Type; begin if Curs = No_Element then return C; elsif not Has_Element (Container, Curs) then raise Constraint_Error; else while Curs.Node /= 0 loop Node := Curs.Node; Delete (C, Curs); Curs := Next (Container, (Node => Node)); end loop; return C; end if; end First_To_Previous; ---------- -- Free -- ---------- procedure Free (Container : in out List; X : Count_Type) is pragma Assert (X > 0); pragma Assert (X <= Container.Capacity); N : Node_Array renames Container.Nodes; begin N (X).Prev := -1; -- Node is deallocated (not on active list) if Container.Free >= 0 then N (X).Next := Container.Free; Container.Free := X; elsif X + 1 = abs Container.Free then N (X).Next := 0; -- Not strictly necessary, but marginally safer Container.Free := Container.Free + 1; else Container.Free := abs Container.Free; if Container.Free > Container.Capacity then Container.Free := 0; else for J in Container.Free .. Container.Capacity - 1 loop N (J).Next := J + 1; end loop; N (Container.Capacity).Next := 0; end if; N (X).Next := Container.Free; Container.Free := X; end if; end Free; --------------------- -- Generic_Sorting -- --------------------- package body Generic_Sorting with SPARK_Mode => Off is --------------- -- Is_Sorted -- --------------- function Is_Sorted (Container : List) return Boolean is Nodes : Node_Array renames Container.Nodes; Node : Count_Type := Container.First; begin for J in 2 .. Container.Length loop if Nodes (Nodes (Node).Next).Element < Nodes (Node).Element then return False; else Node := Nodes (Node).Next; end if; end loop; return True; end Is_Sorted; ----------- -- Merge -- ----------- procedure Merge (Target : in out List; Source : in out List) is LN : Node_Array renames Target.Nodes; RN : Node_Array renames Source.Nodes; LI : Cursor; RI : Cursor; begin if Target'Address = Source'Address then return; end if; LI := First (Target); RI := First (Source); while RI.Node /= 0 loop pragma Assert (RN (RI.Node).Next = 0 or else not (RN (RN (RI.Node).Next).Element < RN (RI.Node).Element)); if LI.Node = 0 then Splice (Target, No_Element, Source); return; end if; pragma Assert (LN (LI.Node).Next = 0 or else not (LN (LN (LI.Node).Next).Element < LN (LI.Node).Element)); if RN (RI.Node).Element < LN (LI.Node).Element then declare RJ : Cursor := RI; pragma Warnings (Off, RJ); begin RI.Node := RN (RI.Node).Next; Splice (Target, LI, Source, RJ); end; else LI.Node := LN (LI.Node).Next; end if; end loop; end Merge; ---------- -- Sort -- ---------- procedure Sort (Container : in out List) is N : Node_Array renames Container.Nodes; procedure Partition (Pivot, Back : Count_Type); procedure Sort (Front, Back : Count_Type); --------------- -- Partition -- --------------- procedure Partition (Pivot, Back : Count_Type) is Node : Count_Type; begin Node := N (Pivot).Next; while Node /= Back loop if N (Node).Element < N (Pivot).Element then declare Prev : constant Count_Type := N (Node).Prev; Next : constant Count_Type := N (Node).Next; begin N (Prev).Next := Next; if Next = 0 then Container.Last := Prev; else N (Next).Prev := Prev; end if; N (Node).Next := Pivot; N (Node).Prev := N (Pivot).Prev; N (Pivot).Prev := Node; if N (Node).Prev = 0 then Container.First := Node; else N (N (Node).Prev).Next := Node; end if; Node := Next; end; else Node := N (Node).Next; end if; end loop; end Partition; ---------- -- Sort -- ---------- procedure Sort (Front, Back : Count_Type) is Pivot : Count_Type; begin if Front = 0 then Pivot := Container.First; else Pivot := N (Front).Next; end if; if Pivot /= Back then Partition (Pivot, Back); Sort (Front, Pivot); Sort (Pivot, Back); end if; end Sort; -- Start of processing for Sort begin if Container.Length <= 1 then return; end if; pragma Assert (N (Container.First).Prev = 0); pragma Assert (N (Container.Last).Next = 0); Sort (Front => 0, Back => 0); pragma Assert (N (Container.First).Prev = 0); pragma Assert (N (Container.Last).Next = 0); end Sort; end Generic_Sorting; ----------------- -- Has_Element -- ----------------- function Has_Element (Container : List; Position : Cursor) return Boolean is begin if Position.Node = 0 then return False; end if; return Container.Nodes (Position.Node).Prev /= -1; end Has_Element; ------------ -- Insert -- ------------ procedure Insert (Container : in out List; Before : Cursor; New_Item : Element_Type; Position : out Cursor; Count : Count_Type := 1) is J : Count_Type; begin if Before.Node /= 0 then pragma Assert (Vet (Container, Before), "bad cursor in Insert"); end if; if Count = 0 then Position := Before; return; end if; if Container.Length > Container.Capacity - Count then raise Constraint_Error with "new length exceeds capacity"; end if; Allocate (Container, New_Item, New_Node => J); Insert_Internal (Container, Before.Node, New_Node => J); Position := (Node => J); for Index in 2 .. Count loop Allocate (Container, New_Item, New_Node => J); Insert_Internal (Container, Before.Node, New_Node => J); end loop; end Insert; procedure Insert (Container : in out List; Before : Cursor; New_Item : Element_Type; Count : Count_Type := 1) is Position : Cursor; begin Insert (Container, Before, New_Item, Position, Count); end Insert; procedure Insert (Container : in out List; Before : Cursor; Position : out Cursor; Count : Count_Type := 1) is J : Count_Type; begin if Before.Node /= 0 then pragma Assert (Vet (Container, Before), "bad cursor in Insert"); end if; if Count = 0 then Position := Before; return; end if; if Container.Length > Container.Capacity - Count then raise Constraint_Error with "new length exceeds capacity"; end if; Allocate (Container, New_Node => J); Insert_Internal (Container, Before.Node, New_Node => J); Position := (Node => J); for Index in 2 .. Count loop Allocate (Container, New_Node => J); Insert_Internal (Container, Before.Node, New_Node => J); end loop; end Insert; --------------------- -- Insert_Internal -- --------------------- procedure Insert_Internal (Container : in out List; Before : Count_Type; New_Node : Count_Type) is N : Node_Array renames Container.Nodes; begin if Container.Length = 0 then pragma Assert (Before = 0); pragma Assert (Container.First = 0); pragma Assert (Container.Last = 0); Container.First := New_Node; Container.Last := New_Node; N (Container.First).Prev := 0; N (Container.Last).Next := 0; elsif Before = 0 then pragma Assert (N (Container.Last).Next = 0); N (Container.Last).Next := New_Node; N (New_Node).Prev := Container.Last; Container.Last := New_Node; N (Container.Last).Next := 0; elsif Before = Container.First then pragma Assert (N (Container.First).Prev = 0); N (Container.First).Prev := New_Node; N (New_Node).Next := Container.First; Container.First := New_Node; N (Container.First).Prev := 0; else pragma Assert (N (Container.First).Prev = 0); pragma Assert (N (Container.Last).Next = 0); N (New_Node).Next := Before; N (New_Node).Prev := N (Before).Prev; N (N (Before).Prev).Next := New_Node; N (Before).Prev := New_Node; end if; Container.Length := Container.Length + 1; end Insert_Internal; -------------- -- Is_Empty -- -------------- function Is_Empty (Container : List) return Boolean is begin return Length (Container) = 0; end Is_Empty; ---------- -- Last -- ---------- function Last (Container : List) return Cursor is begin if Container.Last = 0 then return No_Element; end if; return (Node => Container.Last); end Last; ------------------ -- Last_Element -- ------------------ function Last_Element (Container : List) return Element_Type is L : constant Count_Type := Container.Last; begin if L = 0 then raise Constraint_Error with "list is empty"; else return Container.Nodes (L).Element; end if; end Last_Element; ------------ -- Length -- ------------ function Length (Container : List) return Count_Type is begin return Container.Length; end Length; ---------- -- Move -- ---------- procedure Move (Target : in out List; Source : in out List) is N : Node_Array renames Source.Nodes; X : Count_Type; begin if Target'Address = Source'Address then return; end if; if Target.Capacity < Source.Length then raise Constraint_Error with -- ??? "Source length exceeds Target capacity"; end if; Clear (Target); while Source.Length > 1 loop pragma Assert (Source.First in 1 .. Source.Capacity); pragma Assert (Source.Last /= Source.First); pragma Assert (N (Source.First).Prev = 0); pragma Assert (N (Source.Last).Next = 0); -- Copy first element from Source to Target X := Source.First; Append (Target, N (X).Element); -- optimize away??? -- Unlink first node of Source Source.First := N (X).Next; N (Source.First).Prev := 0; Source.Length := Source.Length - 1; -- The representation invariants for Source have been restored. It is -- now safe to free the unlinked node, without fear of corrupting the -- active links of Source. -- Note that the algorithm we use here models similar algorithms used -- in the unbounded form of the doubly-linked list container. In that -- case, Free is an instantation of Unchecked_Deallocation, which can -- fail (because PE will be raised if controlled Finalize fails), so -- we must defer the call until the last step. Here in the bounded -- form, Free merely links the node we have just "deallocated" onto a -- list of inactive nodes, so technically Free cannot fail. However, -- for consistency, we handle Free the same way here as we do for the -- unbounded form, with the pessimistic assumption that it can fail. Free (Source, X); end loop; if Source.Length = 1 then pragma Assert (Source.First in 1 .. Source.Capacity); pragma Assert (Source.Last = Source.First); pragma Assert (N (Source.First).Prev = 0); pragma Assert (N (Source.Last).Next = 0); -- Copy element from Source to Target X := Source.First; Append (Target, N (X).Element); -- Unlink node of Source Source.First := 0; Source.Last := 0; Source.Length := 0; -- Return the unlinked node to the free store Free (Source, X); end if; end Move; ---------- -- Next -- ---------- procedure Next (Container : List; Position : in out Cursor) is begin Position := Next (Container, Position); end Next; function Next (Container : List; Position : Cursor) return Cursor is begin if Position.Node = 0 then return No_Element; end if; if not Has_Element (Container, Position) then raise Program_Error with "Position cursor has no element"; end if; return (Node => Container.Nodes (Position.Node).Next); end Next; ------------- -- Prepend -- ------------- procedure Prepend (Container : in out List; New_Item : Element_Type; Count : Count_Type := 1) is begin Insert (Container, First (Container), New_Item, Count); end Prepend; -------------- -- Previous -- -------------- procedure Previous (Container : List; Position : in out Cursor) is begin Position := Previous (Container, Position); end Previous; function Previous (Container : List; Position : Cursor) return Cursor is begin if Position.Node = 0 then return No_Element; end if; if not Has_Element (Container, Position) then raise Program_Error with "Position cursor has no element"; end if; return (Node => Container.Nodes (Position.Node).Prev); end Previous; --------------------- -- Replace_Element -- --------------------- procedure Replace_Element (Container : in out List; Position : Cursor; New_Item : Element_Type) is begin if not Has_Element (Container, Position) then raise Constraint_Error with "Position cursor has no element"; end if; pragma Assert (Vet (Container, Position), "bad cursor in Replace_Element"); Container.Nodes (Position.Node).Element := New_Item; end Replace_Element; ---------------------- -- Reverse_Elements -- ---------------------- procedure Reverse_Elements (Container : in out List) is N : Node_Array renames Container.Nodes; I : Count_Type := Container.First; J : Count_Type := Container.Last; procedure Swap (L, R : Count_Type); ---------- -- Swap -- ---------- procedure Swap (L, R : Count_Type) is LN : constant Count_Type := N (L).Next; LP : constant Count_Type := N (L).Prev; RN : constant Count_Type := N (R).Next; RP : constant Count_Type := N (R).Prev; begin if LP /= 0 then N (LP).Next := R; end if; if RN /= 0 then N (RN).Prev := L; end if; N (L).Next := RN; N (R).Prev := LP; if LN = R then pragma Assert (RP = L); N (L).Prev := R; N (R).Next := L; else N (L).Prev := RP; N (RP).Next := L; N (R).Next := LN; N (LN).Prev := R; end if; end Swap; -- Start of processing for Reverse_Elements begin if Container.Length <= 1 then return; end if; pragma Assert (N (Container.First).Prev = 0); pragma Assert (N (Container.Last).Next = 0); Container.First := J; Container.Last := I; loop Swap (L => I, R => J); J := N (J).Next; exit when I = J; I := N (I).Prev; exit when I = J; Swap (L => J, R => I); I := N (I).Next; exit when I = J; J := N (J).Prev; exit when I = J; end loop; pragma Assert (N (Container.First).Prev = 0); pragma Assert (N (Container.Last).Next = 0); end Reverse_Elements; ------------------ -- Reverse_Find -- ------------------ function Reverse_Find (Container : List; Item : Element_Type; Position : Cursor := No_Element) return Cursor is CFirst : Count_Type := Position.Node; begin if CFirst = 0 then CFirst := Container.First; end if; if Container.Length = 0 then return No_Element; else while CFirst /= 0 loop if Container.Nodes (CFirst).Element = Item then return (Node => CFirst); else CFirst := Container.Nodes (CFirst).Prev; end if; end loop; return No_Element; end if; end Reverse_Find; ------------ -- Splice -- ------------ procedure Splice (Target : in out List; Before : Cursor; Source : in out List) is SN : Node_Array renames Source.Nodes; begin if Before.Node /= 0 then pragma Assert (Vet (Target, Before), "bad cursor in Splice"); end if; if Target'Address = Source'Address or else Source.Length = 0 then return; end if; pragma Assert (SN (Source.First).Prev = 0); pragma Assert (SN (Source.Last).Next = 0); if Target.Length > Count_Type'Base'Last - Source.Length then raise Constraint_Error with "new length exceeds maximum"; end if; if Target.Length + Source.Length > Target.Capacity then raise Constraint_Error; end if; loop Insert (Target, Before, SN (Source.Last).Element); Delete_Last (Source); exit when Is_Empty (Source); end loop; end Splice; procedure Splice (Target : in out List; Before : Cursor; Source : in out List; Position : in out Cursor) is Target_Position : Cursor; begin if Target'Address = Source'Address then Splice (Target, Before, Position); return; end if; if Position.Node = 0 then raise Constraint_Error with "Position cursor has no element"; end if; pragma Assert (Vet (Source, Position), "bad Position cursor in Splice"); if Target.Length >= Target.Capacity then raise Constraint_Error; end if; Insert (Container => Target, Before => Before, New_Item => Source.Nodes (Position.Node).Element, Position => Target_Position); Delete (Source, Position); Position := Target_Position; end Splice; procedure Splice (Container : in out List; Before : Cursor; Position : Cursor) is N : Node_Array renames Container.Nodes; begin if Before.Node /= 0 then pragma Assert (Vet (Container, Before), "bad Before cursor in Splice"); end if; if Position.Node = 0 then raise Constraint_Error with "Position cursor has no element"; end if; pragma Assert (Vet (Container, Position), "bad Position cursor in Splice"); if Position.Node = Before.Node or else N (Position.Node).Next = Before.Node then return; end if; pragma Assert (Container.Length >= 2); if Before.Node = 0 then pragma Assert (Position.Node /= Container.Last); if Position.Node = Container.First then Container.First := N (Position.Node).Next; N (Container.First).Prev := 0; else N (N (Position.Node).Prev).Next := N (Position.Node).Next; N (N (Position.Node).Next).Prev := N (Position.Node).Prev; end if; N (Container.Last).Next := Position.Node; N (Position.Node).Prev := Container.Last; Container.Last := Position.Node; N (Container.Last).Next := 0; return; end if; if Before.Node = Container.First then pragma Assert (Position.Node /= Container.First); if Position.Node = Container.Last then Container.Last := N (Position.Node).Prev; N (Container.Last).Next := 0; else N (N (Position.Node).Prev).Next := N (Position.Node).Next; N (N (Position.Node).Next).Prev := N (Position.Node).Prev; end if; N (Container.First).Prev := Position.Node; N (Position.Node).Next := Container.First; Container.First := Position.Node; N (Container.First).Prev := 0; return; end if; if Position.Node = Container.First then Container.First := N (Position.Node).Next; N (Container.First).Prev := 0; elsif Position.Node = Container.Last then Container.Last := N (Position.Node).Prev; N (Container.Last).Next := 0; else N (N (Position.Node).Prev).Next := N (Position.Node).Next; N (N (Position.Node).Next).Prev := N (Position.Node).Prev; end if; N (N (Before.Node).Prev).Next := Position.Node; N (Position.Node).Prev := N (Before.Node).Prev; N (Before.Node).Prev := Position.Node; N (Position.Node).Next := Before.Node; pragma Assert (N (Container.First).Prev = 0); pragma Assert (N (Container.Last).Next = 0); end Splice; ------------------ -- Strict_Equal -- ------------------ function Strict_Equal (Left, Right : List) return Boolean is CL : Count_Type := Left.First; CR : Count_Type := Right.First; begin while CL /= 0 or CR /= 0 loop if CL /= CR or else Left.Nodes (CL).Element /= Right.Nodes (CL).Element then return False; end if; CL := Left.Nodes (CL).Next; CR := Right.Nodes (CR).Next; end loop; return True; end Strict_Equal; ---------- -- Swap -- ---------- procedure Swap (Container : in out List; I, J : Cursor) is begin if I.Node = 0 then raise Constraint_Error with "I cursor has no element"; end if; if J.Node = 0 then raise Constraint_Error with "J cursor has no element"; end if; if I.Node = J.Node then return; end if; pragma Assert (Vet (Container, I), "bad I cursor in Swap"); pragma Assert (Vet (Container, J), "bad J cursor in Swap"); declare NN : Node_Array renames Container.Nodes; NI : Node_Type renames NN (I.Node); NJ : Node_Type renames NN (J.Node); EI_Copy : constant Element_Type := NI.Element; begin NI.Element := NJ.Element; NJ.Element := EI_Copy; end; end Swap; ---------------- -- Swap_Links -- ---------------- procedure Swap_Links (Container : in out List; I, J : Cursor) is I_Next, J_Next : Cursor; begin if I.Node = 0 then raise Constraint_Error with "I cursor has no element"; end if; if J.Node = 0 then raise Constraint_Error with "J cursor has no element"; end if; if I.Node = J.Node then return; end if; pragma Assert (Vet (Container, I), "bad I cursor in Swap_Links"); pragma Assert (Vet (Container, J), "bad J cursor in Swap_Links"); I_Next := Next (Container, I); if I_Next = J then Splice (Container, Before => I, Position => J); else J_Next := Next (Container, J); if J_Next = I then Splice (Container, Before => J, Position => I); else pragma Assert (Container.Length >= 3); Splice (Container, Before => I_Next, Position => J); Splice (Container, Before => J_Next, Position => I); end if; end if; end Swap_Links; --------- -- Vet -- --------- function Vet (L : List; Position : Cursor) return Boolean is N : Node_Array renames L.Nodes; begin if L.Length = 0 then return False; end if; if L.First = 0 then return False; end if; if L.Last = 0 then return False; end if; if Position.Node > L.Capacity then return False; end if; if N (Position.Node).Prev < 0 or else N (Position.Node).Prev > L.Capacity then return False; end if; if N (Position.Node).Next > L.Capacity then return False; end if; if N (L.First).Prev /= 0 then return False; end if; if N (L.Last).Next /= 0 then return False; end if; if N (Position.Node).Prev = 0 and then Position.Node /= L.First then return False; end if; if N (Position.Node).Next = 0 and then Position.Node /= L.Last then return False; end if; if L.Length = 1 then return L.First = L.Last; end if; if L.First = L.Last then return False; end if; if N (L.First).Next = 0 then return False; end if; if N (L.Last).Prev = 0 then return False; end if; if N (N (L.First).Next).Prev /= L.First then return False; end if; if N (N (L.Last).Prev).Next /= L.Last then return False; end if; if L.Length = 2 then if N (L.First).Next /= L.Last then return False; end if; if N (L.Last).Prev /= L.First then return False; end if; return True; end if; if N (L.First).Next = L.Last then return False; end if; if N (L.Last).Prev = L.First then return False; end if; if Position.Node = L.First then return True; end if; if Position.Node = L.Last then return True; end if; if N (Position.Node).Next = 0 then return False; end if; if N (Position.Node).Prev = 0 then return False; end if; if N (N (Position.Node).Next).Prev /= Position.Node then return False; end if; if N (N (Position.Node).Prev).Next /= Position.Node then return False; end if; if L.Length = 3 then if N (L.First).Next /= Position.Node then return False; end if; if N (L.Last).Prev /= Position.Node then return False; end if; end if; return True; end Vet; end Ada.Containers.Formal_Doubly_Linked_Lists;
package body GNAT.Directory_Operations is procedure Make_Dir (Dir_Name : Dir_Name_Str) is begin Ada.Directories.Create_Directory (Dir_Name); end Make_Dir; procedure Remove_Dir ( Dir_Name : Dir_Name_Str; Recursive : Boolean := False) is begin if Recursive then Ada.Directories.Delete_Tree (Dir_Name); else Ada.Directories.Delete_Directory (Dir_Name); end if; end Remove_Dir; function Base_Name (Path : Path_Name; Suffix : String := "") return String is E_First : Positive; E_Last : Natural; Last : Natural; begin Ada.Hierarchical_File_Names.Extension (Path, First => E_First, Last => E_Last); if E_First <= E_Last and then Path (E_First .. E_Last) = Suffix then Last := E_First - 1; else Last := Path'Last; end if; return Ada.Hierarchical_File_Names.Simple_Name ( Path (Path'First .. Last)); end Base_Name; function Format_Pathname ( Path : Path_Name; Style : Path_Style := System_Default) return Path_Name is pragma Unreferenced (Style); begin return Path; end Format_Pathname; procedure Open (Dir : in out Dir_Type; Dir_Name : Dir_Name_Str) is begin Ada.Directories.Start_Search (Dir, Dir_Name); end Open; procedure Read ( Dir : in out Dir_Type; Str : out String; Last : out Natural) is begin if Ada.Directories.More_Entries (Dir) then declare Directory_Entry : Ada.Directories.Directory_Entry_Type; begin Ada.Directories.Get_Next_Entry (Dir, Directory_Entry); declare Simple_Name : constant String := Ada.Directories.Simple_Name (Directory_Entry); begin Last := Str'First + (Simple_Name'Length - 1); Str (Str'First .. Last) := Simple_Name; end; end; else Last := 0; -- end of directory end if; end Read; end GNAT.Directory_Operations;
package Weak2 is Var : Integer; pragma Import (Ada, Var, "var_name"); pragma Weak_External (Var); function F return Integer; end Weak2;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2019, Fabien Chouteau -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ with ESF; package LibRISCV.CSR is type Id is mod 2 ** 12 with Size => 12; subtype User is Id with Dynamic_Predicate => (User and 2#00_11_00000000#) = 2#00_00_00000000#; subtype Supervisor is Id with Dynamic_Predicate => (Supervisor and 2#00_11_00000000#) = 2#00_01_00000000#; subtype Hypervisor is Id with Dynamic_Predicate => (Hypervisor and 2#00_11_00000000#) = 2#00_10_00000000#; subtype Machine is Id with Dynamic_Predicate => (Machine and 2#00_11_00000000#) = 2#00_11_00000000#; subtype Read_Only is Id with Dynamic_Predicate => (Read_Only and 2#11_0000000000#) = 2#11_0000000000#; function Hex is new ESF.Hex_Image (Id); type Name is ( ustatus, -- URW: User status register fflags, -- URW: Floating-Point Accrued Exceptions frm, -- URW: Floating-Point Dynamic Rounding Mode fcsr, -- URW: Floating-Point Control and St uie, -- URW: User interrupt-enable register utvec, -- URW: User trap handler base address uscratch, -- URW: Scratch register for user trap handlers uepc, -- URW: User exception program counter ucause, -- URW: User trap cause utval, -- URW: User bad address or instruction uip, -- URW: User interrupt pending sstatus, -- SRW: Supervisor status register sedeleg, -- SRW: Supervisor exception delegation register sideleg, -- SRW: Supervisor interrupt delegation register sie, -- SRW: Supervisor interrupt-enable register stvec, -- SRW: Supervisor trap handler base address scounteren, -- SRW: Supervisor counter enable sscratch, -- SRW: Scratch register for supervisor trap handlers sepc, -- SRW: Supervisor exception program counter scause, -- SRW: Supervisor trap cause stval, -- SRW: Supervisor bad address or instruction sip, -- SRW: Supervisor interrupt pending satp, -- SRW: Supervisor address translation and protection vsstatus, -- HRW: Virtual supervisor status register vsie, -- HRW: Virtual supervisor interrupt-enable register vstvec, -- HRW: Virtual supervisor trap handler base address vsscratch, -- HRW: Virtual supervisor scratch register vsepc, -- HRW: Virtual supervisor exception program counter vscause, -- HRW: Virtual supervisor trap cause vstval, -- HRW: Virtual supervisor bad address or instruction vsip, -- HRW: Virtual supervisor interrupt pending vsatp, -- HRW: Virtual supervisor address translation and protection mstatus, -- MRW: Machine status register misa, -- MRW: ISA and extension medeleg, -- MRW: Machine exception delegation register mideleg, -- MRW: Machine interrupt delegation register mie, -- MRW: Machine interrupt-enable register mtvec, -- MRW: Machine trap-handler base address mcounteren, -- MRW: Machine counter enable mstatush, -- MRW: Additional machine status register, RV32 only mcountinhibit, -- MRW: Machine counter-inhibit register mhpmevent3, -- MRW: Machine performance-monitoring event selector mhpmevent4, -- MRW: Machine performance-monitoring event selector mhpmevent31, -- MRW: Machine performance-monitoring event selector mscratch, -- MRW: Scratch register for machine trap handlers mepc, -- MRW: Machine exception program counter mcause, -- MRW: Machine trap cause mtval, -- MRW: Machine bad address or instruction mip, -- MRW: Machine interrupt pending mbase, -- MRW: Base register mbound, -- MRW: Bound register mibase, -- MRW: Instruction base register mibound, -- MRW: Instruction bound register mdbase, -- MRW: Data base register mdbound, -- MRW: Data bound register pmpcfg0, -- MRW: Physical memory protection configuration pmpcfg1, -- MRW: Physical memory protection configuration, RV32 only pmpcfg2, -- MRW: Physical memory protection configuration pmpcfg3, -- MRW: Physical memory protection configuration, RV32 only pmpaddr0, -- MRW: Physical memory protection address register pmpaddr1, -- MRW: Physical memory protection address register pmpaddr15, -- MRW: Physical memory protection address register hstatus, -- HRW: Hypervisor status register hedeleg, -- HRW: Hypervisor exception delegation register hideleg, -- HRW: Hypervisor interrupt delegation register hcounteren, -- SRW: Hypervisor counter enable hgatp, -- HRW: Hypervisor guest address translation and protection tselect, -- MRW: Debug/Trace trigger register select tdata1, -- MRW: First Debug/Trace trigger data register tdata2, -- MRW: Second Debug/Trace trigger data register tdata3, -- MRW: Third Debug/Trace trigger data register dcsr, -- DRW: Debug control and status register dpc, -- DRW: Debug PC dscratch0, -- DRW: Debug scratch register 0 dscratch1, -- DRW: Debug scratch register 1 mcycle, -- MRW: Machine cycle counter minstret, -- MRW: Machine instructions-retired counter mhpmcounter3, -- MRW: Machine performance-monitoring counter mhpmcounter4, -- MRW: Machine performance-monitoring counter mhpmcounter31, -- MRW: Machine performance-monitoring counter mcycleh, -- MRW: Upper 32 bits of mcycle, RV32I only minstreth, -- MRW: Upper 32 bits of minstret, RV32I only mhpmcounter3h, -- MRW: Upper 32 bits of mhpmcounter3, RV32I only mhpmcounter4h, -- MRW: Upper 32 bits of mhpmcounter4, RV32I only mhpmcounter31h, -- MRW: Upper 32 bits of mhpmcounter31, RV32I only cycle, -- URO: Cycle counter for RDCYCLE instruction time, -- URO: Timer for RDTIME instruction instret, -- URO: Instructions-retired counter for RDINSTRET instruction hpmcounter3, -- URO: Performance-monitoring counter hpmcounter4, -- URO: Performance-monitoring counter hpmcounter31, -- URO: Performance-monitoring counter cycleh, -- URO: Upper 32 bits of cycle, RV32I only timeh, -- URO: Upper 32 bits of time, RV32I only instreth, -- URO: Upper 32 bits of instret, RV32I only hpmcounter3h, -- URO: Upper 32 bits of hpmcounter3, RV32I only hpmcounter4h, -- URO: Upper 32 bits of hpmcounter4, RV32I only hpmcounter31h, -- URO: Upper 32 bits of hpmcounter31, RV32I only mvendorid, -- MRO: Vendor ID marchid, -- MRO: Architecture ID mimpid, -- MRO: Implementation ID mhartid, -- MRO: Hardware thread ID Not_Implemented -- Disgnate all CSR for which we do not have a name ); function To_Id (N : Name) return Id; function To_Name (I : Id) return Name; function Img (I : Id) return String; function Img (N : Name) return String; for Name use ( ustatus => 16#000#, fflags => 16#001#, frm => 16#002#, fcsr => 16#003#, uie => 16#004#, utvec => 16#005#, uscratch => 16#040#, uepc => 16#041#, ucause => 16#042#, utval => 16#043#, uip => 16#044#, sstatus => 16#100#, sedeleg => 16#102#, sideleg => 16#103#, sie => 16#104#, stvec => 16#105#, scounteren => 16#106#, sscratch => 16#140#, sepc => 16#141#, scause => 16#142#, stval => 16#143#, sip => 16#144#, satp => 16#180#, vsstatus => 16#200#, vsie => 16#204#, vstvec => 16#205#, vsscratch => 16#240#, vsepc => 16#241#, vscause => 16#242#, vstval => 16#243#, vsip => 16#244#, vsatp => 16#280#, mstatus => 16#300#, misa => 16#301#, medeleg => 16#302#, mideleg => 16#303#, mie => 16#304#, mtvec => 16#305#, mcounteren => 16#306#, mstatush => 16#310#, mcountinhibit => 16#320#, mhpmevent3 => 16#323#, mhpmevent4 => 16#324#, mhpmevent31 => 16#33F#, mscratch => 16#340#, mepc => 16#341#, mcause => 16#342#, mtval => 16#343#, mip => 16#344#, mbase => 16#380#, mbound => 16#381#, mibase => 16#382#, mibound => 16#383#, mdbase => 16#384#, mdbound => 16#385#, pmpcfg0 => 16#3A0#, pmpcfg1 => 16#3A1#, pmpcfg2 => 16#3A2#, pmpcfg3 => 16#3A3#, pmpaddr0 => 16#3B0#, pmpaddr1 => 16#3B1#, pmpaddr15 => 16#3BF#, hstatus => 16#600#, hedeleg => 16#602#, hideleg => 16#603#, hcounteren => 16#606#, hgatp => 16#680#, tselect => 16#7A0#, tdata1 => 16#7A1#, tdata2 => 16#7A2#, tdata3 => 16#7A3#, dcsr => 16#7B0#, dpc => 16#7B1#, dscratch0 => 16#7B2#, dscratch1 => 16#7B3#, mcycle => 16#B00#, minstret => 16#B02#, mhpmcounter3 => 16#B03#, mhpmcounter4 => 16#B04#, mhpmcounter31 => 16#B1F#, mcycleh => 16#B80#, minstreth => 16#B82#, mhpmcounter3h => 16#B83#, mhpmcounter4h => 16#B84#, mhpmcounter31h => 16#B9F#, cycle => 16#C00#, time => 16#C01#, instret => 16#C02#, hpmcounter3 => 16#C03#, hpmcounter4 => 16#C04#, hpmcounter31 => 16#C1F#, cycleh => 16#C80#, timeh => 16#C81#, instreth => 16#C82#, hpmcounter3h => 16#C83#, hpmcounter4h => 16#C84#, hpmcounter31h => 16#C9F#, mvendorid => 16#F11#, marchid => 16#F12#, mimpid => 16#F13#, mhartid => 16#F14#, Not_Implemented => 16#1000# ); end LibRISCV.CSR;
----------------------------------------------------------------------- -- servlet-servlets-rest -- REST servlet -- Copyright (C) 2016, 2017, 2018, 2019, 2020 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Servlet.Streams.JSON; package body Servlet.Core.Rest is -- ------------------------------ -- Called by the servlet container to indicate to a servlet that the servlet -- is being placed into service. -- ------------------------------ procedure Initialize (Server : in out Rest_Servlet; Context : in Servlet_Registry'Class) is pragma Unreferenced (Context); begin null; end Initialize; -- ------------------------------ -- Receives standard HTTP requests from the public service method and dispatches -- them to the Do_XXX methods defined in this class. This method is an HTTP-specific -- version of the Servlet.service(Request, Response) method. There's no need -- to override this method. -- ------------------------------ overriding procedure Service (Server : in Rest_Servlet; Request : in out Requests.Request'Class; Response : in out Responses.Response'Class) is Method : constant String := Request.Get_Method; begin if Method = "GET" then Rest_Servlet'Class (Server).Dispatch (GET, Request, Response); elsif Method = "POST" then Rest_Servlet'Class (Server).Dispatch (POST, Request, Response); elsif Method = "PUT" then Rest_Servlet'Class (Server).Dispatch (PUT, Request, Response); elsif Method = "DELETE" then Rest_Servlet'Class (Server).Dispatch (DELETE, Request, Response); elsif Method = "HEAD" then Rest_Servlet'Class (Server).Dispatch (HEAD, Request, Response); elsif Method = "OPTIONS" then Rest_Servlet'Class (Server).Dispatch (OPTIONS, Request, Response); elsif Method = "TRACE" then Rest_Servlet'Class (Server).Dispatch (TRACE, Request, Response); elsif Method = "PATCH" then Rest_Servlet'Class (Server).Dispatch (PATCH, Request, Response); elsif Method = "CONNECT" then Rest_Servlet'Class (Server).Dispatch (CONNECT, Request, Response); else Response.Send_Error (Responses.SC_NOT_IMPLEMENTED); end if; end Service; procedure Dispatch (Server : in Rest_Servlet; Method : in Method_Type; Request : in out Requests.Request'Class; Response : in out Responses.Response'Class) is pragma Unreferenced (Server); begin if not Request.Has_Route then Response.Set_Status (Responses.SC_NOT_FOUND); Response.Set_Committed; return; end if; declare Route : constant Routes.Route_Type_Accessor := Request.Get_Route; begin if not (Route in Routes.Servlets.Rest.API_Route_Type'Class) then Response.Set_Status (Responses.SC_NOT_FOUND); Response.Set_Committed; return; end if; declare Api : constant access Routes.Servlets.Rest.API_Route_Type'Class := Routes.Servlets.Rest.API_Route_Type'Class (Route.Element.all)'Access; Desc : constant Descriptor_Access := Api.Descriptors (Method); Output : constant Streams.Print_Stream := Response.Get_Output_Stream; Stream : Streams.JSON.Print_Stream; begin if Desc = null then Response.Set_Status (Responses.SC_NOT_FOUND); Response.Set_Committed; return; end if; -- if not App.Has_Permission (Desc.Permission) then -- Response.Set_Status (Responses.SC_FORBIDDEN); -- return; -- end if; Streams.JSON.Initialize (Stream, Output); Response.Set_Content_Type ("application/json; charset=utf-8"); Api.Descriptors (Method).Dispatch (Request, Response, Stream); end; end; end Dispatch; function Create_Route (Registry : in Core.Servlet_Registry; Name : in String) return Routes.Servlets.Rest.API_Route_Type_Access is Pos : constant Servlet_Maps.Cursor := Registry.Servlets.Find (Name); Result : Routes.Servlets.Rest.API_Route_Type_Access; begin if not Servlet_Maps.Has_Element (Pos) then -- Log.Error ("No servlet {0}", Name); raise Servlet_Error with "No servlet " & Name; end if; Result := new Routes.Servlets.Rest.API_Route_Type; Result.Servlet := Servlet_Maps.Element (Pos); return Result; end Create_Route; -- Create a route for the REST API. function Create_Route (Servlet : in Core.Servlet_Access) return Routes.Servlets.Rest.API_Route_Type_Access is Result : Routes.Servlets.Rest.API_Route_Type_Access; begin Result := new Routes.Servlets.Rest.API_Route_Type; Result.Servlet := Servlet; return Result; end Create_Route; end Servlet.Core.Rest;
package AOC.AOC_2019.Day01 is type Day_01 is new Day.Day with private; overriding procedure Init (D : in out Day_01; Root : String); overriding function Part_1 (D : Day_01) return String; overriding function Part_2 (D : Day_01) return String; private type Mass is new Natural; subtype Fuel is Mass; type Day_01 is new Day.Day with record Total_Fuel : Fuel := 0; Abhorrent_Total_Fuel : Fuel := 0; end record; function Calc_Fuel (M : Mass) return Fuel; function Calc_Abhorrent_Fuel (M : Mass) return Fuel; end AOC.AOC_2019.Day01;
with Helper; use Helper; package body Normalisation is -- Centre la figure sur l'axe X -- Raccorde les extremités de la figure à l'axe procedure Normaliser(Segments : in out Liste) is Coords_Min : constant Point2D := Trouver_Coords_Min (Segments); procedure Normaliser_Point(P : in out Point2D) is begin P := P - Coords_Min; end; procedure Normaliser_Liste is new Parcourir(Normaliser_Point); Debut : Point2D; Fin : Point2D; begin Debug("Offset appliqué:"); Debug(To_String(Coords_Min)); Normaliser_Liste(Segments); -- Instanciation maintenant car Segments a été décalé Debut := Tete(Segments); Fin := Queue(Segments); -- Points à rajouter en début et fin de courbe Debut := (Debut'First => Debut(Debut'First), Debut'Last => 0.0); Fin := (Fin'First => Fin(Fin'First), Fin'Last => 0.0); -- On vérifie leur utilité if Debut /= Tete(Segments) then Debug("Rajout d'un raccord en début de figure"); Insertion_Tete(Segments, Debut); end if; if Fin /= Queue(Segments) then Debug("Rajout d'un raccord en fin de figure"); Insertion_Queue(Segments, Fin); end if; Debug("Fin normalisation"); Debug; end; -- Trouve les coord min function Trouver_Coords_Min(Segments : in out Liste) return Point2D is -- Abscisses et ordonnées minimales nécessaires -- pour le pré-traitement X_Min : Float := Tete(Segments)(Point2D'First); Y_Min : Float := Tete(Segments)(Point2D'Last); -- Met à jour les minima X_Min et Y_Min procedure Comparer_Min(P : in out Point2D) is begin -- On compare X_Min et l'abscisse du point P X_Min := Float'Min(X_Min, P(P'First)); -- On compare Y_Min et l'ordonnée du point P Y_Min := Float'Min(Y_Min, P(P'Last)); end; procedure Chercher_Min is new Parcourir(Comparer_Min); begin Chercher_Min (Segments); return (Point2D'First => X_Min, Point2D'Last => Y_Min); end; end;
----------------------------------------------------------------------- -- keystore-gpg_tests -- Test AKT with GPG2 -- Copyright (C) 2020 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Text_IO; with Util.Test_Caller; with Util.Log.Loggers; with Util.Processes; with Util.Streams.Buffered; with Util.Streams.Pipes; package body Keystore.Fuse_Tests is Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Keystore.Fuse_Tests"); CHECK_MOUNT_PATH : constant String := "regtests/files/check-mount.sh"; package Caller is new Util.Test_Caller (Test, "AKT.Fuse"); procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is begin Caller.Add_Test (Suite, "Test AKT.Commands.Mount", Test_Mount'Access); Caller.Add_Test (Suite, "Test AKT.Commands.Mount (Fill)", Test_Mount_Fill'Access); Caller.Add_Test (Suite, "Test AKT.Commands.Mount (Clean)", Test_Mount_Clean'Access); Caller.Add_Test (Suite, "Test AKT.Commands.Mount (Check)", Test_Mount_Check'Access); Caller.Add_Test (Suite, "Test AKT.Commands.Mount (Stress)", Test_Mount_Stress'Access); end Add_Tests; -- ------------------------------ -- Execute the command and get the output in a string. -- ------------------------------ procedure Execute (T : in out Test; Command : in String; Input : in String; Output : in String; Result : out Ada.Strings.Unbounded.Unbounded_String; Status : in Natural := 0) is P : aliased Util.Streams.Pipes.Pipe_Stream; Buffer : Util.Streams.Buffered.Input_Buffer_Stream; begin if Input'Length > 0 then Log.Info ("Execute: {0} < {1}", Command, Input); elsif Output'Length > 0 then Log.Info ("Execute: {0} > {1}", Command, Output); else Log.Info ("Execute: {0}", Command); end if; P.Set_Input_Stream (Input); P.Set_Output_Stream (Output); P.Open (Command, Util.Processes.READ_ALL); -- Write on the process input stream. Result := Ada.Strings.Unbounded.Null_Unbounded_String; Buffer.Initialize (P'Unchecked_Access, 8192); Buffer.Read (Result); P.Close; Ada.Text_IO.Put_Line (Ada.Strings.Unbounded.To_String (Result)); Log.Info ("Command result: {0}", Result); Util.Tests.Assert_Equals (T, Status, P.Get_Exit_Status, "Command '" & Command & "' failed"); end Execute; procedure Execute (T : in out Test; Command : in String; Result : out Ada.Strings.Unbounded.Unbounded_String; Status : in Natural := 0) is begin T.Execute (Command, "", "", Result, Status); end Execute; procedure Execute (T : in out Test; Command : in String; Expect : in String; Status : in Natural := 0) is Path : constant String := Util.Tests.Get_Test_Path ("regtests/expect/" & Expect); Output : constant String := Util.Tests.Get_Test_Path ("regtests/result/" & Expect); Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute (Command, "", Output, Result, Status); Util.Tests.Assert_Equal_Files (T, Path, Output, "Command '" & Command & "' invalid output"); end Execute; -- ------------------------------ -- Test the akt keystore creation. -- ------------------------------ procedure Test_Mount (T : in out Test) is Tool : constant String := Util.Tests.Get_Test_Path (CHECK_MOUNT_PATH); Result : Ada.Strings.Unbounded.Unbounded_String; begin -- Create keystore T.Execute (Tool & " START", Result); Util.Tests.Assert_Matches (T, "PASS", Result, "akt keystore creation failed"); end Test_Mount; -- ------------------------------ -- Test the akt mount and filling the keystore. -- ------------------------------ procedure Test_Mount_Fill (T : in out Test) is Tool : constant String := Util.Tests.Get_Test_Path (CHECK_MOUNT_PATH); Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute (Tool & " FILL", Result); Util.Tests.Assert_Matches (T, "PASS", Result, "akt keystore mount+fill failed"); end Test_Mount_Fill; -- ------------------------------ -- Test the akt mount and cleaning the keystore. -- ------------------------------ procedure Test_Mount_Clean (T : in out Test) is Tool : constant String := Util.Tests.Get_Test_Path (CHECK_MOUNT_PATH); Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute (Tool & " CLEAN", Result); Util.Tests.Assert_Matches (T, "PASS", Result, "akt keystore mount+clean failed"); end Test_Mount_Clean; -- ------------------------------ -- Test the akt mount and checking its content. -- ------------------------------ procedure Test_Mount_Check (T : in out Test) is Tool : constant String := Util.Tests.Get_Test_Path (CHECK_MOUNT_PATH); Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute (Tool & " CHECK", Result); Util.Tests.Assert_Matches (T, "PASS", Result, "akt keystore mount+check after stress failed"); end Test_Mount_Check; -- ------------------------------ -- Test the akt mount and stressing the filesystem. -- ------------------------------ procedure Test_Mount_Stress (T : in out Test) is Tool : constant String := Util.Tests.Get_Test_Path (CHECK_MOUNT_PATH); Result : Ada.Strings.Unbounded.Unbounded_String; begin T.Execute (Tool & " BIG", Result); Util.Tests.Assert_Matches (T, "PASS", Result, "akt keystore mount+check after stress failed"); end Test_Mount_Stress; end Keystore.Fuse_Tests;
-- SPDX-FileCopyrightText: 2021 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- with Ada.Unchecked_Conversion; with Interfaces; with League.String_Vectors; with League.Regexps; with League.Text_Codecs; with League.Stream_Element_Vectors; package body Network.Addresses is function "+" (Text : Wide_Wide_String) return League.Strings.Universal_String renames League.Strings.To_Universal_String; type Protocol_Name is (ip4, tcp, dccp, ip6, ip6zone, -- rfc4007 IPv6 zone dns, -- domain name resolvable to both IPv6 and IPv4 addresses dns4, -- domain name resolvable only to IPv4 addresses dns6, -- domain name resolvable only to IPv6 addresses dnsaddr, sctp, udp, p2p_webrtc_star, p2p_webrtc_direct, p2p_stardust, p2p_circuit, udt, utp, unix, p2p, -- preferred over /ipfs https, onion, onion3, garlic64, garlic32, quic, ws, wss, p2p_websocket_star, http, memory -- in memory transport for self-dialing and testing; arbitrary ); for Protocol_Name'Size use 16; for Protocol_Name use (ip4 => 4, tcp => 6, dccp => 33, ip6 => 41, ip6zone => 42, dns => 53, dns4 => 54, dns6 => 55, dnsaddr => 56, sctp => 132, udp => 273, p2p_webrtc_star => 275, p2p_webrtc_direct => 276, p2p_stardust => 277, p2p_circuit => 290, udt => 301, utp => 302, unix => 400, -- ipfs => 421, p2p => 421, https => 443, onion => 444, onion3 => 445, garlic64 => 446, garlic32 => 447, quic => 460, ws => 477, wss => 478, p2p_websocket_star => 479, http => 480, memory => 777); procedure Read_Protocol_Name (Stream : access Ada.Streams.Root_Stream_Type'Class; Value : out Protocol_Name); procedure Write_Protocol_Name (Stream : access Ada.Streams.Root_Stream_Type'Class; Value : Protocol_Name); for Protocol_Name'Read use Read_Protocol_Name; for Protocol_Name'Write use Write_Protocol_Name; ipfs : constant Protocol_Name := p2p; -- backwards compatibility; equivalent to /p2p Offset : constant array (Protocol_Name) of Positive := (ip4 => 1, tcp => 4, dccp => 7, ip6 => 11, ip6zone => 14, dns => 21, dns4 => 24, dns6 => 28, dnsaddr => 32, sctp => 39, udp => 43, p2p_webrtc_star => 46, p2p_webrtc_direct => 61, p2p_stardust => 78, p2p_circuit => 90, udt => 101, utp => 104, unix => 107, p2p => 111, https => 114, onion => 119, onion3 => 124, garlic64 => 130, garlic32 => 138, quic => 146, ws => 150, wss => 152, p2p_websocket_star => 155, http => 173, memory => 177); Any_Image : constant Wide_Wide_String := "ip4" & "tcp" & "dccp" & "ip6" & "ip6zone" & "dns" & "dns4" & "dns6" & "dnsaddr" & "sctp" & "udp" & "p2p_webrtc_star" & "p2p_webrtc_direct" & "p2p_stardust" & "p2p_circuit" & "udt" & "utp" & "unix" & "p2p" & "https" & "onion" & "onion3" & "garlic64" & "garlic32" & "quic" & "ws" & "wss" & "p2p_websocket_star" & "http" & "memory"; subtype Byte is Interfaces.Unsigned_8; subtype Port is Interfaces.Unsigned_16; function Image (Value : Byte) return Wide_Wide_String with Inline; function Image (Value : Port) return Wide_Wide_String with Inline; function Image (Name : Protocol_Name) return Wide_Wide_String with Inline; procedure To_Value (Text : Wide_Wide_String; Name : out Protocol_Name; Ok : out Boolean) with Inline; IP4_Pattern_Text : constant Wide_Wide_String := "^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})" & "(\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})){3}$"; Port_Pattern_Text : constant Wide_Wide_String := "^[0-6]?[0-9]{1,4}$"; DNS_Pattern_Text : constant Wide_Wide_String := "^[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)+$"; type IP4_Raw is array (1 .. 4) of Byte; ----------- -- Image -- ----------- function Image (Value : Byte) return Wide_Wide_String is Text : constant Wide_Wide_String := Byte'Wide_Wide_Image (Value); begin return Text (2 .. Text'Last); end Image; ----------- -- Image -- ----------- function Image (Value : Port) return Wide_Wide_String is Text : constant Wide_Wide_String := Port'Wide_Wide_Image (Value); begin return Text (2 .. Text'Last); end Image; ----------- -- Image -- ----------- function Image (Name : Protocol_Name) return Wide_Wide_String is To : Positive := Any_Image'Last; begin if Name /= Protocol_Name'Last then To := Offset (Protocol_Name'Succ (Name)) - 1; end if; return Any_Image (Offset (Name) .. To); end Image; -------------- -- Is_Valid -- -------------- function Is_Valid (Value : League.Strings.Universal_String) return Boolean is IP4_Pattern : constant League.Regexps.Regexp_Pattern := League.Regexps.Compile (+IP4_Pattern_Text); Port_Pattern : constant League.Regexps.Regexp_Pattern := League.Regexps.Compile (+Port_Pattern_Text); DNS_Pattern : constant League.Regexps.Regexp_Pattern := League.Regexps.Compile (+DNS_Pattern_Text); Has_Proto : Boolean := False; Proto : Protocol_Name := Protocol_Name'First; List : constant League.String_Vectors.Universal_String_Vector := Value.Split ('/'); begin if List.Length < 2 or else not List (1).Is_Empty then return False; end if; for J in 2 .. List.Length loop declare Item : constant League.Strings.Universal_String := List (J); begin if Has_Proto then Has_Proto := False; case Proto is when ip4 => if not IP4_Pattern.Find_Match (Item).Is_Matched then return False; end if; when tcp | udp | dccp | sctp => if not Port_Pattern.Find_Match (Item).Is_Matched then return False; end if; when dns | dns4 | dns6 | dnsaddr => if not DNS_Pattern.Find_Match (Item).Is_Matched then return False; end if; when others => null; end case; else To_Value (Item.To_Wide_Wide_String, Proto, Has_Proto); if not Has_Proto then return False; end if; end if; end; end loop; return not Has_Proto; end Is_Valid; ---------- -- Read -- ---------- procedure Read (Self : access Ada.Streams.Root_Stream_Type'Class; Value : out Ada.Streams.Stream_Element_Count) is use type Interfaces.Unsigned_64; use type Byte; Shift : Natural := 0; Item : Byte; Result : Interfaces.Unsigned_64; begin Result := 0; loop Byte'Read (Self, Item); Result := Result + Interfaces.Shift_Left (Interfaces.Unsigned_64 (Item and 127), Shift); Shift := Shift + 7; exit when Item < 128; end loop; Value := Ada.Streams.Stream_Element_Count (Result); end Read; ---------- -- Read -- ---------- overriding procedure Read (Self : in out Simple_Stream; Item : out Ada.Streams.Stream_Element_Array; Last : out Ada.Streams.Stream_Element_Offset) is use type Ada.Streams.Stream_Element_Offset; To : constant Ada.Streams.Stream_Element_Offset := Ada.Streams.Stream_Element_Offset'Min (Self.Last + Item'Length, Self.Size); begin Last := Item'First + To - Self.Last - 1; Item (Item'First .. Last) := Self.Data (Self.Last + 1 .. To); Self.Last := To; end Read; ------------------------ -- Read_Protocol_Name -- ------------------------ procedure Read_Protocol_Name (Stream : access Ada.Streams.Root_Stream_Type'Class; Value : out Protocol_Name) is Size : constant := Protocol_Name'Size; type Raw_Protocol_Name is mod 2 ** Protocol_Name'Size with Size => Size; function Convert is new Ada.Unchecked_Conversion (Raw_Protocol_Name, Protocol_Name); Raw : Ada.Streams.Stream_Element_Count; begin Read (Stream, Raw); Value := Convert (Raw_Protocol_Name (Raw)); end Read_Protocol_Name; ---------------- -- To_Address -- ---------------- function To_Address (Value : League.Strings.Universal_String) return Address is begin return (Value => Value); end To_Address; ---------------- -- To_Address -- ---------------- function To_Address (Value : Ada.Streams.Stream_Element_Array) return Address is use type Ada.Streams.Stream_Element_Count; UTF : constant League.Text_Codecs.Text_Codec := League.Text_Codecs.Codec (+"utf-8"); S : aliased Simple_Stream := (Ada.Streams.Root_Stream_Type with Size => Value'Length, Last => 0, Data => Value); Result : League.Strings.Universal_String; Proto : Protocol_Name; Length : Ada.Streams.Stream_Element_Count; begin while S.Last < S.Size loop Protocol_Name'Read (S'Access, Proto); Result.Append ('/'); Result.Append (Image (Proto)); case Proto is when ip4 => declare Addr : IP4_Raw; begin Result.Append ('/'); IP4_Raw'Read (S'Access, Addr); Result.Append (Image (Addr (1))); for X in 2 .. 4 loop Result.Append ('.'); Result.Append (Image (Addr (X))); end loop; end; when tcp | udp | dccp | sctp => declare use type Port; High, Low : Byte; Value : Port; begin Result.Append ('/'); Byte'Read (S'Access, High); Byte'Read (S'Access, Low); Value := Port (High) * 256 + Port (Low); Result.Append (Image (Value)); end; when dns | dns4 | dns6 | dnsaddr => Read (S'Access, Length); declare Buffer : Ada.Streams.Stream_Element_Array (1 .. Length); Text : League.Strings.Universal_String; begin Ada.Streams.Stream_Element_Array'Read (S'Access, Buffer); Text := UTF.Decode (Buffer); Result.Append ('/'); Result.Append (Text); end; when others => null; end case; end loop; return (Value => Result); end To_Address; ----------------------------- -- To_Stream_Element_Array -- ----------------------------- function To_Stream_Element_Array (Self : Address) return Ada.Streams.Stream_Element_Array is Max : constant Natural := Self.Value.Length; S : aliased Simple_Stream (Ada.Streams.Stream_Element_Count (Max)); UTF : constant League.Text_Codecs.Text_Codec := League.Text_Codecs.Codec (+"utf-8"); Has_Proto : Boolean := False; Proto : Protocol_Name := Protocol_Name'First; List : constant League.String_Vectors.Universal_String_Vector := Self.Value.Split ('/'); begin for J in 2 .. List.Length loop declare Item : constant League.Strings.Universal_String := List (J); begin if Has_Proto then Has_Proto := False; case Proto is when ip4 => declare List : constant League.String_Vectors.Universal_String_Vector := Item.Split ('.'); Value : Byte; begin for J in 1 .. List.Length loop Value := Byte'Wide_Wide_Value (List (J).To_Wide_Wide_String); Byte'Write (S'Access, Value); end loop; end; when tcp | udp | dccp | sctp => declare use type Port; Value : constant Port := Port'Wide_Wide_Value (Item.To_Wide_Wide_String); High, Low : Byte; begin Low := Byte'Mod (Value); High := Byte (Value / 256); Byte'Write (S'Access, High); Byte'Write (S'Access, Low); end; when dns | dns4 | dns6 | dnsaddr | p2p => declare Image : constant League.Stream_Element_Vectors.Stream_Element_Vector := UTF.Encode (Item); begin Write (S'Access, Image.Length); S.Write (Image.To_Stream_Element_Array); end; when others => null; end case; else To_Value (Item.To_Wide_Wide_String, Proto, Has_Proto); Protocol_Name'Write (S'Access, Proto); end if; end; end loop; return S.Data (1 .. S.Last); end To_Stream_Element_Array; --------------- -- To_String -- --------------- function To_String (Self : Address) return League.Strings.Universal_String is begin return Self.Value; end To_String; -------------- -- To_Value -- -------------- procedure To_Value (Text : Wide_Wide_String; Name : out Protocol_Name; Ok : out Boolean) is begin Ok := False; if Text = "ipfs" then Name := ipfs; Ok := True; return; end if; for P in Protocol_Name loop if Image (P) = Text then Name := P; Ok := True; exit; end if; end loop; end To_Value; ----------- -- Write -- ----------- overriding procedure Write (Self : in out Simple_Stream; Item : Ada.Streams.Stream_Element_Array) is use type Ada.Streams.Stream_Element_Offset; begin Self.Data (Self.Last + 1 .. Self.Last + Item'Length) := Item; Self.Last := Self.Last + Item'Length; end Write; ----------- -- Write -- ----------- procedure Write (Self : access Ada.Streams.Root_Stream_Type'Class; Value : Ada.Streams.Stream_Element_Count) is use type Byte; use type Ada.Streams.Stream_Element_Count; Next : Ada.Streams.Stream_Element_Count := Value; Item : Byte; begin while Next > 127 loop Item := Byte'Mod (Next) or 128; Byte'Write (Self, Item); Next := Next / 128; end loop; Item := Byte'Mod (Next); Byte'Write (Self, Item); end Write; ------------------------- -- Write_Protocol_Name -- ------------------------- procedure Write_Protocol_Name (Stream : access Ada.Streams.Root_Stream_Type'Class; Value : Protocol_Name) is Size : constant := Protocol_Name'Size; type Raw_Protocol_Name is mod 2 ** Protocol_Name'Size with Size => Size; function Convert is new Ada.Unchecked_Conversion (Protocol_Name, Raw_Protocol_Name); Raw : constant Raw_Protocol_Name := Convert (Value); begin Write (Stream, Ada.Streams.Stream_Element_Count (Raw)); end Write_Protocol_Name; end Network.Addresses;
-- The Village of Vampire by YT, このソースコードはNYSLです procedure Tabula.Users.Load ( Name : in String; Info : in out User_Info);
package body Interface_utils with SPARK_Mode is function Convert_C_Bool(input : Extensions.bool) return Boolean is begin if (input > 0) then return True; else return False; end if; end Convert_C_Bool; begin null; end Interface_utils;
-- -- Provides Kafka functionality to manage messages -- package Kafka.Message is -- -- Frees resources for the specified Message and hands ownership back to -- rdkafka. -- -- librdkafka equivalent: rd_kafka_message_destroy -- procedure Destroy(Message : access Message_Type) with Import => True, Convention => C, External_Name => "rd_kafka_message_destroy"; -- -- Returns the error string for an errored Message or empty string if there -- was no error. -- -- This function MUST NOT be used with the producer. -- -- librdkafka equivalent: rd_kafka_message_errstr -- -- @param Message message to get the error of -- @returns string describing the error -- function Get_Error(Message : access constant Message_Type) return String; private function rd_kafka_message_errstr(Message : access constant Message_Type) return chars_ptr with Import => True, Convention => C, External_Name => "rd_kafka_message_errstr_wrapper"; end Kafka.Message;
with Giza.Colors; use Giza.Colors; with Giza.Window; use Giza.Window; with Giza.Widget.Button; use Giza.Widget.Button; with Giza.GUI; use Giza; package body Basic_Test_Window is ------------- -- On_Init -- ------------- overriding procedure On_Init (This : in out Test_Window) is -- Our real size Size : constant Size_T := Get_Size (Parent (This)); begin -- Add a back button at the bottom of the window This.Back := new Button.Instance; This.Back.Set_Text ("Back"); This.Back.Set_Size ((Size.W, Size.H / 10 - 1)); This.Back.Set_Foreground (Red); This.Add_Child (Widget.Reference (This.Back), (0, Size.H - Size.H / 10 + 1)); end On_Init; ----------------------- -- On_Position_Event -- ----------------------- overriding function On_Position_Event (This : in out Test_Window; Evt : Position_Event_Ref; Pos : Point_T) return Boolean is Res : Boolean; begin Res := On_Position_Event (Parent (This), Evt, Pos); if Res and then This.Back /= null and then This.Back.Active then This.Back.Set_Active (False); Giza.GUI.Pop; end if; return Res; end On_Position_Event; overriding function Get_Size (This : Test_Window) return Size_T is -- Our real size Size : constant Size_T := Get_Size (Parent (This)); begin -- Remove the size of "back" button return Size - (0, Size.H / 10); end Get_Size; end Basic_Test_Window;
with Ada.Integer_Text_IO; procedure Euler9 is function Pythagorean(A, B, C: Positive) return Boolean is (A * A + B * B = C * C); C: Positive; begin for A in Positive range 1 .. 998 loop for B in Positive range A .. 1000 - A - 1 loop C := 1000 - A - B; if Pythagorean(A, B, C) then Ada.Integer_Text_IO.Put(A * B * C); return; end if; end loop; end loop; end Euler9;
-- { dg-do compile } -- { dg-options "-O -gnatn -fdump-tree-optimized" } package body Array16 is function F1 (A : access My_T1) return My_T1 is begin return A.all; end; function F2 (A : access My_T2) return My_T2 is begin return A.all; end; procedure Proc (A : access My_T1; B : access My_T2) is L1 : My_T1 := F1(A); L2 : My_T2 := F2(B); begin if L1.D = 0 and then L2(1) = 0 then raise Program_Error; end if; end; end Array16; -- { dg-final { scan-tree-dump-not "secondary_stack" "optimized" } }
-- This spec has been automatically generated from STM32WL5x_CM0P.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package STM32_SVD.TZSC is pragma Preelaborate; --------------- -- Registers -- --------------- -- TZIC interrupt enable register 1 type IER1_Register is record -- TZICIE TZICIE : Boolean := True; -- TZSCIE TZSCIE : Boolean := True; -- AESIE AESIE : Boolean := True; -- RNGIE RNGIE : Boolean := True; -- SUBGHZSPIIE SUBGHZSPIIE : Boolean := True; -- PWRIE PWRIE : Boolean := True; -- FLASHIFIE FLASHIFIE : Boolean := True; -- DMA1IE DMA1IE : Boolean := True; -- DMA2IE DMA2IE : Boolean := True; -- DMAMUX1IE DMAMUX1IE : Boolean := True; -- FLASHIE FLASHIE : Boolean := True; -- SRAM1IE SRAM1IE : Boolean := True; -- SRAM2IE SRAM2IE : Boolean := True; -- PKAIE PKAIE : Boolean := True; -- unspecified Reserved_14_31 : HAL.UInt18 := 16#3FFFF#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for IER1_Register use record TZICIE at 0 range 0 .. 0; TZSCIE at 0 range 1 .. 1; AESIE at 0 range 2 .. 2; RNGIE at 0 range 3 .. 3; SUBGHZSPIIE at 0 range 4 .. 4; PWRIE at 0 range 5 .. 5; FLASHIFIE at 0 range 6 .. 6; DMA1IE at 0 range 7 .. 7; DMA2IE at 0 range 8 .. 8; DMAMUX1IE at 0 range 9 .. 9; FLASHIE at 0 range 10 .. 10; SRAM1IE at 0 range 11 .. 11; SRAM2IE at 0 range 12 .. 12; PKAIE at 0 range 13 .. 13; Reserved_14_31 at 0 range 14 .. 31; end record; -- TZIC status register 1 type MISR1_Register is record -- Read-only. TZICMF TZICMF : Boolean; -- Read-only. TZSCMF TZSCMF : Boolean; -- Read-only. AESMF AESMF : Boolean; -- Read-only. RNGMF RNGMF : Boolean; -- Read-only. SUBGHZSPIMF SUBGHZSPIMF : Boolean; -- Read-only. PWRMF PWRMF : Boolean; -- Read-only. FLASHIFMF FLASHIFMF : Boolean; -- Read-only. DMA1MF DMA1MF : Boolean; -- Read-only. DMA2MF DMA2MF : Boolean; -- Read-only. DMAMUX1MF DMAMUX1MF : Boolean; -- Read-only. FLASHMF FLASHMF : Boolean; -- Read-only. SRAM1MF SRAM1MF : Boolean; -- Read-only. SRAM2MF SRAM2MF : Boolean; -- Read-only. PKAMF PKAMF : Boolean; -- unspecified Reserved_14_31 : HAL.UInt18; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for MISR1_Register use record TZICMF at 0 range 0 .. 0; TZSCMF at 0 range 1 .. 1; AESMF at 0 range 2 .. 2; RNGMF at 0 range 3 .. 3; SUBGHZSPIMF at 0 range 4 .. 4; PWRMF at 0 range 5 .. 5; FLASHIFMF at 0 range 6 .. 6; DMA1MF at 0 range 7 .. 7; DMA2MF at 0 range 8 .. 8; DMAMUX1MF at 0 range 9 .. 9; FLASHMF at 0 range 10 .. 10; SRAM1MF at 0 range 11 .. 11; SRAM2MF at 0 range 12 .. 12; PKAMF at 0 range 13 .. 13; Reserved_14_31 at 0 range 14 .. 31; end record; -- TZIC interrupt status clear register 1 type ICR1_Register is record -- TZICCF TZICCF : Boolean := False; -- TZSCCF TZSCCF : Boolean := False; -- AESCF AESCF : Boolean := False; -- RNGCF RNGCF : Boolean := False; -- SUBGHZSPICF SUBGHZSPICF : Boolean := False; -- PWRCF PWRCF : Boolean := False; -- FLASHIFCF FLASHIFCF : Boolean := False; -- DMA1CF DMA1CF : Boolean := False; -- DMA2CF DMA2CF : Boolean := False; -- DMAMUX1CF DMAMUX1CF : Boolean := False; -- FLASHCF FLASHCF : Boolean := False; -- SRAM1CF SRAM1CF : Boolean := False; -- SRAM2CF SRAM2CF : Boolean := False; -- PKACF PKACF : Boolean := False; -- unspecified Reserved_14_31 : HAL.UInt18 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for ICR1_Register use record TZICCF at 0 range 0 .. 0; TZSCCF at 0 range 1 .. 1; AESCF at 0 range 2 .. 2; RNGCF at 0 range 3 .. 3; SUBGHZSPICF at 0 range 4 .. 4; PWRCF at 0 range 5 .. 5; FLASHIFCF at 0 range 6 .. 6; DMA1CF at 0 range 7 .. 7; DMA2CF at 0 range 8 .. 8; DMAMUX1CF at 0 range 9 .. 9; FLASHCF at 0 range 10 .. 10; SRAM1CF at 0 range 11 .. 11; SRAM2CF at 0 range 12 .. 12; PKACF at 0 range 13 .. 13; Reserved_14_31 at 0 range 14 .. 31; end record; -- TZSC control register type TZSC_CR_Register is record -- LCK LCK : Boolean := False; -- unspecified Reserved_1_31 : HAL.UInt31 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for TZSC_CR_Register use record LCK at 0 range 0 .. 0; Reserved_1_31 at 0 range 1 .. 31; end record; -- TZSC security configuration register type TZSC_SECCFGR1_Register is record -- unspecified Reserved_0_1 : HAL.UInt2 := 16#0#; -- AESSEC AESSEC : Boolean := False; -- RNGSEC RNGSEC : Boolean := False; -- unspecified Reserved_4_12 : HAL.UInt9 := 16#0#; -- PKASEC PKASEC : Boolean := False; -- unspecified Reserved_14_31 : HAL.UInt18 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for TZSC_SECCFGR1_Register use record Reserved_0_1 at 0 range 0 .. 1; AESSEC at 0 range 2 .. 2; RNGSEC at 0 range 3 .. 3; Reserved_4_12 at 0 range 4 .. 12; PKASEC at 0 range 13 .. 13; Reserved_14_31 at 0 range 14 .. 31; end record; -- TZSC privilege configuration register 1 type TZSC_PRIVCFGR1_Register is record -- unspecified Reserved_0_1 : HAL.UInt2 := 16#0#; -- AESPRIV AESPRIV : Boolean := False; -- RNGPRIV RNGPRIV : Boolean := False; -- SUBGHZSPIPRIV SUBGHZSPIPRIV : Boolean := False; -- unspecified Reserved_5_12 : HAL.UInt8 := 16#0#; -- PKAPRIV PKAPRIV : Boolean := False; -- unspecified Reserved_14_31 : HAL.UInt18 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for TZSC_PRIVCFGR1_Register use record Reserved_0_1 at 0 range 0 .. 1; AESPRIV at 0 range 2 .. 2; RNGPRIV at 0 range 3 .. 3; SUBGHZSPIPRIV at 0 range 4 .. 4; Reserved_5_12 at 0 range 5 .. 12; PKAPRIV at 0 range 13 .. 13; Reserved_14_31 at 0 range 14 .. 31; end record; subtype TZSC_MPCWM1_UPWMR_LGTH_Field is HAL.UInt12; -- Unprivileged Water Mark 1 register type TZSC_MPCWM1_UPWMR_Register is record -- unspecified Reserved_0_15 : HAL.UInt16 := 16#0#; -- LGTH LGTH : TZSC_MPCWM1_UPWMR_LGTH_Field := 16#FFF#; -- unspecified Reserved_28_31 : HAL.UInt4 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for TZSC_MPCWM1_UPWMR_Register use record Reserved_0_15 at 0 range 0 .. 15; LGTH at 0 range 16 .. 27; Reserved_28_31 at 0 range 28 .. 31; end record; subtype TZSC_MPCWM1_UPWWMR_LGTH_Field is HAL.UInt12; -- Unprivileged Writable Water Mark 1 register type TZSC_MPCWM1_UPWWMR_Register is record -- unspecified Reserved_0_15 : HAL.UInt16 := 16#0#; -- Define the length of Flash Unprivileged Writable area, in 2 LGTH : TZSC_MPCWM1_UPWWMR_LGTH_Field := 16#FFF#; -- unspecified Reserved_28_31 : HAL.UInt4 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for TZSC_MPCWM1_UPWWMR_Register use record Reserved_0_15 at 0 range 0 .. 15; LGTH at 0 range 16 .. 27; Reserved_28_31 at 0 range 28 .. 31; end record; subtype TZSC_MPCWM2_UPWMR_LGTH_Field is HAL.UInt12; -- Unprivileged Water Mark 2 register type TZSC_MPCWM2_UPWMR_Register is record -- unspecified Reserved_0_15 : HAL.UInt16 := 16#0#; -- LGTH LGTH : TZSC_MPCWM2_UPWMR_LGTH_Field := 16#FFF#; -- unspecified Reserved_28_31 : HAL.UInt4 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for TZSC_MPCWM2_UPWMR_Register use record Reserved_0_15 at 0 range 0 .. 15; LGTH at 0 range 16 .. 27; Reserved_28_31 at 0 range 28 .. 31; end record; subtype TZSC_MPCWM3_UPWMR_LGTH_Field is HAL.UInt12; -- Unprivileged Water Mark 3 register type TZSC_MPCWM3_UPWMR_Register is record -- unspecified Reserved_0_15 : HAL.UInt16 := 16#0#; -- LGTH LGTH : TZSC_MPCWM3_UPWMR_LGTH_Field := 16#FFF#; -- unspecified Reserved_28_31 : HAL.UInt4 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for TZSC_MPCWM3_UPWMR_Register use record Reserved_0_15 at 0 range 0 .. 15; LGTH at 0 range 16 .. 27; Reserved_28_31 at 0 range 28 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- TrustZone Interrupt Control type TZIC_Peripheral is record -- TZIC interrupt enable register 1 IER1 : aliased IER1_Register; -- TZIC status register 1 MISR1 : aliased MISR1_Register; -- TZIC interrupt status clear register 1 ICR1 : aliased ICR1_Register; end record with Volatile; for TZIC_Peripheral use record IER1 at 16#0# range 0 .. 31; MISR1 at 16#10# range 0 .. 31; ICR1 at 16#20# range 0 .. 31; end record; -- TrustZone Interrupt Control TZIC_Periph : aliased TZIC_Peripheral with Import, Address => TZIC_Base; -- Global TrustZone Controller type TZSC_Peripheral is record -- TZSC control register TZSC_CR : aliased TZSC_CR_Register; -- TZSC security configuration register TZSC_SECCFGR1 : aliased TZSC_SECCFGR1_Register; -- TZSC privilege configuration register 1 TZSC_PRIVCFGR1 : aliased TZSC_PRIVCFGR1_Register; -- Unprivileged Water Mark 1 register TZSC_MPCWM1_UPWMR : aliased TZSC_MPCWM1_UPWMR_Register; -- Unprivileged Writable Water Mark 1 register TZSC_MPCWM1_UPWWMR : aliased TZSC_MPCWM1_UPWWMR_Register; -- Unprivileged Water Mark 2 register TZSC_MPCWM2_UPWMR : aliased TZSC_MPCWM2_UPWMR_Register; -- Unprivileged Water Mark 3 register TZSC_MPCWM3_UPWMR : aliased TZSC_MPCWM3_UPWMR_Register; end record with Volatile; for TZSC_Peripheral use record TZSC_CR at 16#0# range 0 .. 31; TZSC_SECCFGR1 at 16#10# range 0 .. 31; TZSC_PRIVCFGR1 at 16#20# range 0 .. 31; TZSC_MPCWM1_UPWMR at 16#130# range 0 .. 31; TZSC_MPCWM1_UPWWMR at 16#134# range 0 .. 31; TZSC_MPCWM2_UPWMR at 16#138# range 0 .. 31; TZSC_MPCWM3_UPWMR at 16#140# range 0 .. 31; end record; -- Global TrustZone Controller TZSC_Periph : aliased TZSC_Peripheral with Import, Address => TZSC_Base; end STM32_SVD.TZSC;
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Program.Library_Items; with Program.Library_Unit_Bodies; with Program.Library_Unit_Declarations; with Program.Subunits; package body Program.Compilation_Units is ---------------- -- To_Subunit -- ---------------- function To_Subunit (Self : access Compilation_Unit'Class) return Program.Subunits.Subunit_Access is begin return Program.Subunits.Subunit_Access (Self); end To_Subunit; --------------------- -- To_Library_Item -- --------------------- function To_Library_Item (Self : access Compilation_Unit'Class) return Program.Library_Items.Library_Item_Access is begin return Program.Library_Items.Library_Item_Access (Self); end To_Library_Item; -------------------------- -- To_Library_Unit_Body -- -------------------------- function To_Library_Unit_Body (Self : access Compilation_Unit'Class) return Program.Library_Unit_Bodies.Library_Unit_Body_Access is begin return Program.Library_Unit_Bodies.Library_Unit_Body_Access (Self); end To_Library_Unit_Body; --------------------------------- -- To_Library_Unit_Declaration -- --------------------------------- function To_Library_Unit_Declaration (Self : access Compilation_Unit'Class) return Program.Library_Unit_Declarations.Library_Unit_Declaration_Access is begin return Program.Library_Unit_Declarations.Library_Unit_Declaration_Access (Self); end To_Library_Unit_Declaration; end Program.Compilation_Units;
-- { dg-do compile } package body Weak2 is function F return Integer is begin return Var; end; end Weak2;
------------------------------------------------------------------------------ -- -- -- Ada User Repository Annex (AURA) -- -- ANNEXI-STRAYLINE Reference Implementation -- -- -- -- Command Line Interface -- -- -- -- ------------------------------------------------------------------------ -- -- -- -- Copyright (C) 2019-2020, ANNEXI-STRAYLINE Trans-Human Ltd. -- -- All rights reserved. -- -- -- -- Original Contributors: -- -- * Richard Wai (ANNEXI-STRAYLINE) -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- -- -- * Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- This package implements the Subsystem type for use in tracking Subsystem -- dependencies for an AURA project when invoking the CLI. This type is -- intended to act as the Element_Type for the Hashed Set declared in the -- Subsystems.Subsystem_Sets child package. with Ada.Strings.Unbounded; with Ada.Strings.Wide_Wide_Unbounded; with Ada.Containers.Vectors; with Ada.Containers.Hashed_Sets; with Unit_Names; with Unit_Names.Hash; with Unit_Names.Sets; with Repositories; with Registrar.Source_Files; package Registrar.Subsystems is -- Subsystem_State -- --------------------- -- The Subsystem_State pertains to each Subsystem referenced by withed -- library units of a project. The Subsystem_State begings at Registered -- when entered into a Set, and will never regress. If a Subsystem can never -- reach Available, AURA fails type Subsystem_State is (Requested, -- Subsystem must be aquired and entered into the AURA project -- -- Once all Subsystems in a Set have reached Registered, each Subsystem -- is checked for existence in the current project. If the Subsystem -- has been aquired previously, the Status for the Subsystem advances -- to Aquired. Otherwise, the Subsystem needs to be aquired, and is -- advanced to Requested. Aquired, -- Requested Subsystems must be aquired. Failure to aquire any Requested -- Subsystem causes AURA to fail. -- -- Aquired means that the Subsystem's sources have been checked-out into -- the appropriate subdirectory, but that Configuration has not been -- completed. Units in the subsystem root directory have been entered, -- but special codepaths have not been, as this must happen after -- configuration Unavailable, -- Aquisition of the subsystem failed. The reason for this failure is -- assigned to the Aquisition_Note component (and thus only applies -- to AURA subsystems) Available); -- The subsystem has been Configured, and is now available for -- compilation -- Configuration_Pack -- ------------------------ -- The Configuration_Pack contains all of the important configuration -- parameters for configuration a subsystem for the local system. -- -- These values are loaded from a configuration unit, and are a collection -- of named strings, where the names are just for readability of the -- configuration unit, but have no other significant meaning package WWU renames Ada.Strings.Wide_Wide_Unbounded; package UBS renames Ada.Strings.Unbounded; type Configuration_Pair is record Name : WWU.Unbounded_Wide_Wide_String; Value: UBS.Unbounded_String; end record; package Configuration_Vectors is new Ada.Containers.Vectors (Index_Type => Positive, Element_Type => Configuration_Pair); subtype Configuration_Vector is Configuration_Vectors.Vector; type Configuration_Pack is record External_Libraries: Configuration_Vector; Ada_Compiler_Opts : Configuration_Vector; C_Compiler_Opts : Configuration_Vector; C_Definitions : Configuration_Vector; Codepaths : Configuration_Vector; Information : Configuration_Vector; end record; --------------- -- Subsystem -- --------------- use type Unit_Names.Unit_Name; type Subsystem (AURA: Boolean := False) is -- AURA = True => the Subsystem is an AURA subsystem -- False => the Subsystem is part of the root project record Name : Unit_Names.Unit_Name; State: Subsystem_State := Requested; Configuration: Configuration_Pack; -- Mostly for AURA subsystems, however the root project also -- contains configuration, which is registered with the -- "AURA" subsystem itself (which is a non AURA subsystem!) case AURA is when True => Source_Repository : Repositories.Repository_Index; -- Checkout repository information Aquisition_Failure: UBS.Unbounded_String; -- Reason for failure to aquire, set by the checkout process, -- and valid only if State = Unavailable when False => -- the Subsystem is part of the core project null; end case; end record; -- For implementation of Subsystems.Subsystem_Sets function Subsystem_Name_Hash (SS: Subsystem) return Ada.Containers.Hash_Type is (Unit_Names.Hash (SS.Name)); function Equivalent_Subsystems (Left, Right: Subsystem) return Boolean is (Left.Name = Right.Name); -------------------- -- Subsystem_Sets -- -------------------- package Subsystem_Sets is new Ada.Containers.Hashed_Sets (Element_Type => Subsystem, Hash => Subsystem_Name_Hash, Equivalent_Elements => Equivalent_Subsystems); end Registrar.Subsystems;
package Nested_Float_Packed is type Float_Type is record Value : Float; Valid : Boolean; end record; type Data_Type is record Data : Float_Type; end record; Default_Data : constant Data_Type := (Data => (Value => 1.0, Valid => False)); type Range_Type is (RV1, RV2, RV3); for Range_Type use (1, 2, 3); Data_Block : array (Range_Type) of Data_Type := (others => Default_Data); end;
with Ada.Text_IO; use Ada.Text_IO; procedure phrases is function Maju (c : Character) return Character is begin if c in 'a'..'z' then return Character'Val(Character'Pos(c) - 32); else return c; end if; end Maju; ch : Character; nb_a, nb_ne : Integer := 0; n : Boolean := False; begin loop Get(ch); exit when ch = '.'; if ch = 'a' then nb_a := nb_a + 1; end if; if n and ch = 'e' then nb_ne := nb_ne + 1; end if; n := ch = 'n'; Put(Maju(ch)); end loop; Put_Line("Nombre 'a' : " & Integer'Image(nb_a)); Put_Line("Nombre 'ne' : " & Integer'Image(nb_ne)); end phrases;
-- The MIT License (MIT) -- -- Copyright (c) 2016 artium@nihamkin.com -- -- Permission is hereby granted, free of charge, to any person obtaining a copy -- of this software and associated documentation files (the "Software"), to deal -- in the Software without restriction, including without limitation the rights -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -- copies of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in -- all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -- THE SOFTWARE. -- -- with System; generic type Button_Type is (<>); type Axis_Type is (<>); package Linux_Joystick is No_Joystick_Device_Found : Exception; type Milliseconds_Type is range 0..(2**32)-1; for Milliseconds_Type'Size use 32; type Value_Type is range -32767..32767; for Value_Type'Size use 16; type Event_Type_Type is (JS_EVENT_BUTTON, JS_EVENT_AXIS); for Event_Type_Type use (JS_EVENT_BUTTON => 1, JS_EVENT_AXIS => 2); for Event_Type_Type'Size use 7; type Button_Action_Type is (RELEASE, DEPRESS); for Button_Action_Type use (RELEASE => 0, DEPRESS => 1); type Js_Event_Type(Event_Type : Event_Type_Type) is record Time : Milliseconds_Type; Is_Init_Event : Boolean; case Event_Type is when JS_EVENT_BUTTON => Button : Button_Type; Button_Action : Button_Action_Type; when JS_EVENT_AXIS => Axis : Axis_Type; Value : Value_Type; end case; end record; function Open return String; procedure Open(Name : String); function Read return Js_Event_Type; procedure Close; end Linux_Joystick;