content
stringlengths
23
1.05M
with Ada.Text_IO; use Ada.Text_IO; procedure Day05 is function React (Unit1 : Character; Unit2 : Character) return Boolean is Result : Boolean := False; begin if abs (Character'Pos (Unit1) - Character'Pos (Unit2)) = 32 then Result := True; end if; return Result; end React; function Filter_Reactions (Polymer : String; Ignore : Character) return String is Result : String (Polymer'Range); Last : Natural := Result'First - 1; I : Natural := Result'First; begin while I <= Polymer'Last loop declare Keep : Boolean := True; begin if Polymer (I) = Ignore or abs (Character'Pos (Polymer (I)) - Character'Pos (Ignore)) = 32 then I := I + 1; else if I < Polymer'Last then if React (Polymer (I), Polymer (I + 1)) then Keep := False; end if; end if; if Keep then Last := Last + 1; Result (Last) := Polymer (I); I := I + 1; else I := I + 2; end if; end if; end; end loop; declare New_Polymer : constant String := Result (Result'First .. Last); begin if Last = Polymer'Last then return New_Polymer; else return Filter_Reactions (New_Polymer, Ignore); end if; end; end Filter_Reactions; Input_File : File_Type; begin Open (Input_File, In_File, "input.txt"); declare Input : constant String := Get_Line (Input_File); Minimum_Length : Natural; Current_Length : Natural; begin -- Part 1 Minimum_Length := Filter_Reactions (Input, '_')'Length; Put_Line ("Part 1 =" & Integer'Image (Minimum_Length)); -- Part 2 for C in Character'Pos ('a') .. Character'Pos ('z') loop Current_Length := Filter_Reactions (Input, Character'Val (C))'Length; if Current_Length < Minimum_Length then Minimum_Length := Current_Length; end if; end loop; Put_Line ("Part 2 =" & Integer'Image (Minimum_Length)); end; Close (Input_File); end Day05;
-- -- The author disclaims copyright to this source code. In place of -- a legal notice, here is a blessing: -- -- May you do good and not evil. -- May you find forgiveness for yourself and forgive others. -- May you share freely, not taking more than you give. -- --------------------------------------------------------------------------- -- -- This module implements routines use to construct the yy_action[] table. -- -- The state of the yy_action table under construction is an instance of -- the following structure. -- -- The yy_action table maps the pair (state_number, lookahead) into an -- action_number. The table is an array of integers pairs. The state_number -- determines an initial offset into the yy_action array. The lookahead -- value is then added to this initial offset to get an index X into the -- yy_action array. If the aAction[X].lookahead equals the value of the -- of the lookahead input, then the value of the action_number output is -- aAction[X].action. If the lookaheads do not match then the -- default action for the state_number is returned. -- -- All actions associated with a single state_number are first entered -- into aLookahead[] using multiple calls to acttab_action(). Then the -- actions for that single state_number are placed into the aAction[] -- array with a single call to acttab_insert(). The acttab_insert() call -- also resets the aLookahead[] array in preparation for the next -- state number. -- with Ada.Containers.Doubly_Linked_Lists; with Types; package body Actions is package Action_Lists is new Ada.Containers.Doubly_Linked_Lists (Element_Type => Action_Record); function Action_Cmp (Left, Right : in Action_Record) return Boolean is use type Rules.Index_Number; use type Types.Symbol_Index; RC1 : Types.Symbol_Index; RC : Rules.Index_Number; begin RC1 := Left.Symbol.Index - Right.Symbol.Index; if RC1 = 0 then RC := Action_Kind'Pos (Left.Kind) - Action_Kind'Pos (Right.Kind); end if; if RC = 0 and (Left.Kind = Reduce or Left.Kind = Shift_Reduce) then RC := Left.X.Rule.Index - Right.X.Rule.Index; end if; if RC = 0 then RC := 0; -- RC := (int) (ap2 - ap1); -- XXX Pointer raise Program_Error; end if; return RC /= 0; end Action_Cmp; -- Free_List : Action_Access := null; -- -- function Action_New return Action_Access is -- New_Action : Action_Access; -- begin -- if Free_List = null then -- declare -- I : Integer; -- amt : Integer := 100; -- begin -- freelist = (struct action *)calloc(amt, sizeof(struct action)); -- if( freelist==0 ){ -- fprintf(stderr,"Unable to allocate memory for a new parser action."); -- exit(1); -- } -- for(i=0; i<amt-1; i++) freelist[i].next = &freelist[i+1]; -- freelist[amt-1].next = 0; -- end; -- end if; -- New_Action := Free_List; -- Free_List := Free_List.Next; -- return New_Action; -- end Action_New; function Resolve_Conflict (Left : in out Action_Record; Right : in out Action_Record) return Integer is use Symbols; -- Apx : Action_Access renames Left; -- Apy : Action_Access renames Right; Apx : Action_Record renames Left; Apy : Action_Record renames Right; Spx : Symbol_Access; Spy : Symbol_Access; Error_Count : Natural := 0; begin pragma Assert (Apx.Symbol = Apy.Symbol); -- Otherwise there would be no conflict if Apx.Kind = Shift and Apy.Kind = Shift then Apy.Kind := SS_Conflict; Error_Count := Error_Count + 1; end if; if Apx.Kind = Shift and Apy.Kind = Reduce then Spx := Symbol_Access (Apx.Symbol); Spy := Symbol_Access (Apy.X.Rule.Prec_Symbol); if Spy = null or Spx.Precedence < 0 or Spy.Precedence < 0 then -- Not enough precedence information Apy.Kind := SR_Conflict; Error_Count := Error_Count + 1; elsif Spx.Precedence > Spy.Precedence then -- higher precedence wins Apy.Kind := RD_Resolved; elsif Spx.Precedence < Spy.Precedence then Apx.Kind := SH_Resolved; elsif Spx.Precedence = Spy.Precedence and Spx.Association = Right_Association then -- Use operator Apy.Kind := RD_Resolved; -- associativity elsif Spx.Precedence = Spy.Precedence and Spx.Association = Left_Association then -- to break tie Apx.Kind := SH_Resolved; else pragma Assert (Spx.Precedence = Spy.Precedence and Spx.Association = No_Association); Apx.Kind := Error; end if; elsif Apx.Kind = Reduce and Apy.Kind = Reduce then Spx := Symbol_Access (Apx.X.Rule.Prec_Symbol); Spy := Symbol_Access (Apy.X.Rule.Prec_Symbol); if Spx = null or Spy = null or Spx.Precedence < 0 or Spy.Precedence < 0 or Spx.Precedence = Spy.Precedence then Apy.Kind := RR_Conflict; Error_Count := Error_Count + 1; elsif Spx.Precedence > Spy.Precedence then Apy.Kind := RD_Resolved; elsif Spx.Precedence < Spy.Precedence then Apx.Kind := RD_Resolved; end if; else null; pragma Assert (Apx.Kind = SH_Resolved or Apx.Kind = RD_Resolved or Apx.Kind = SS_Conflict or Apx.Kind = SR_Conflict or Apx.Kind = RR_Conflict or Apy.Kind = SH_Resolved or Apy.Kind = RD_Resolved or Apy.Kind = SS_Conflict or Apy.Kind = SR_Conflict or Apy.Kind = RR_Conflict); -- The REDUCE/SHIFT case cannot happen because SHIFTs come before -- REDUCEs on the list. If we reach this point it must be because -- the parser conflict had already been resolved. end if; return Error_Count; end Resolve_Conflict; end Actions;
-- This spec has been automatically generated from STM32WB55x.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package STM32_SVD.GPIO is pragma Preelaborate; --------------- -- Registers -- --------------- -- MODER_MODE array element subtype MODER_MODE_Element is HAL.UInt2; -- MODER_MODE array type MODER_MODE_Field_Array is array (0 .. 15) of MODER_MODE_Element with Component_Size => 2, Size => 32; type MODER_Register (As_Array : Boolean := False) is record case As_Array is when False => -- MODE as a value Val : HAL.UInt32; when True => -- MODE as an array Arr : MODER_MODE_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for MODER_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- OTYPER_OT array type OTYPER_OT_Field_Array is array (0 .. 15) of Boolean with Component_Size => 1, Size => 16; -- Type definition for OTYPER_OT type OTYPER_OT_Field (As_Array : Boolean := False) is record case As_Array is when False => -- OT as a value Val : HAL.UInt16; when True => -- OT as an array Arr : OTYPER_OT_Field_Array; end case; end record with Unchecked_Union, Size => 16; for OTYPER_OT_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; type OTYPER_Register is record OT : OTYPER_OT_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for OTYPER_Register use record OT at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- OSPEEDR_OSPEED array element subtype OSPEEDR_OSPEED_Element is HAL.UInt2; -- OSPEEDR_OSPEED array type OSPEEDR_OSPEED_Field_Array is array (0 .. 15) of OSPEEDR_OSPEED_Element with Component_Size => 2, Size => 32; type OSPEEDR_Register (As_Array : Boolean := False) is record case As_Array is when False => -- OSPEED as a value Val : HAL.UInt32; when True => -- OSPEED as an array Arr : OSPEEDR_OSPEED_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for OSPEEDR_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- PUPDR_PUPD array element subtype PUPDR_PUPD_Element is HAL.UInt2; -- PUPDR_PUPD array type PUPDR_PUPD_Field_Array is array (0 .. 15) of PUPDR_PUPD_Element with Component_Size => 2, Size => 32; type PUPDR_Register (As_Array : Boolean := False) is record case As_Array is when False => -- PUPD as a value Val : HAL.UInt32; when True => -- PUPD as an array Arr : PUPDR_PUPD_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for PUPDR_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- IDR_ID array type IDR_ID_Field_Array is array (0 .. 15) of Boolean with Component_Size => 1, Size => 16; -- Type definition for IDR_ID type IDR_ID_Field (As_Array : Boolean := False) is record case As_Array is when False => -- ID as a value Val : HAL.UInt16; when True => -- ID as an array Arr : IDR_ID_Field_Array; end case; end record with Unchecked_Union, Size => 16; for IDR_ID_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; type IDR_Register is record ID : IDR_ID_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for IDR_Register use record ID at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- ODR_OD array type ODR_OD_Field_Array is array (0 .. 15) of Boolean with Component_Size => 1, Size => 16; -- Type definition for ODR_OD type ODR_OD_Field (As_Array : Boolean := False) is record case As_Array is when False => -- OD as a value Val : HAL.UInt16; when True => -- OD as an array Arr : ODR_OD_Field_Array; end case; end record with Unchecked_Union, Size => 16; for ODR_OD_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; type ODR_Register is record OD : ODR_OD_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for ODR_Register use record OD at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- BSRR_BS array type BSRR_BS_Field_Array is array (0 .. 15) of Boolean with Component_Size => 1, Size => 16; -- Type definition for BSRR_BS type BSRR_BS_Field (As_Array : Boolean := False) is record case As_Array is when False => -- BS as a value Val : HAL.UInt16; when True => -- BS as an array Arr : BSRR_BS_Field_Array; end case; end record with Unchecked_Union, Size => 16; for BSRR_BS_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; -- BSRR_BR array type BSRR_BR_Field_Array is array (0 .. 15) of Boolean with Component_Size => 1, Size => 16; -- Type definition for BSRR_BR type BSRR_BR_Field (As_Array : Boolean := False) is record case As_Array is when False => -- BR as a value Val : HAL.UInt16; when True => -- BR as an array Arr : BSRR_BR_Field_Array; end case; end record with Unchecked_Union, Size => 16; for BSRR_BR_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; type BSRR_Register is record BS : BSRR_BS_Field := (As_Array => False, Val => 16#0#); BR : BSRR_BR_Field := (As_Array => False, Val => 16#0#); end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for BSRR_Register use record BS at 0 range 0 .. 15; BR at 0 range 16 .. 31; end record; -- LCKR_LCK array type LCKR_LCK_Field_Array is array (0 .. 15) of Boolean with Component_Size => 1, Size => 16; -- Type definition for LCKR_LCK type LCKR_LCK_Field (As_Array : Boolean := False) is record case As_Array is when False => -- LCK as a value Val : HAL.UInt16; when True => -- LCK as an array Arr : LCKR_LCK_Field_Array; end case; end record with Unchecked_Union, Size => 16; for LCKR_LCK_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; type LCKR_Register is record LCK : LCKR_LCK_Field := (As_Array => False, Val => 16#0#); LCKK : Boolean := False; -- unspecified Reserved_17_31 : HAL.UInt15 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for LCKR_Register use record LCK at 0 range 0 .. 15; LCKK at 0 range 16 .. 16; Reserved_17_31 at 0 range 17 .. 31; end record; -- AFRL_AFSEL array element subtype AFRL_AFSEL_Element is HAL.UInt4; -- AFRL_AFSEL array type AFRL_AFSEL_Field_Array is array (0 .. 7) of AFRL_AFSEL_Element with Component_Size => 4, Size => 32; type AFRL_Register (As_Array : Boolean := False) is record case As_Array is when False => -- AFSEL as a value Val : HAL.UInt32; when True => -- AFSEL as an array Arr : AFRL_AFSEL_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for AFRL_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- AFRH_AFSEL array element subtype AFRH_AFSEL_Element is HAL.UInt4; -- AFRH_AFSEL array type AFRH_AFSEL_Field_Array is array (8 .. 15) of AFRH_AFSEL_Element with Component_Size => 4, Size => 32; type AFRH_Register (As_Array : Boolean := False) is record case As_Array is when False => -- AFSEL as a value Val : HAL.UInt32; when True => -- AFSEL as an array Arr : AFRH_AFSEL_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for AFRH_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; -- BRR_BR array type BRR_BR_Field_Array is array (0 .. 15) of Boolean with Component_Size => 1, Size => 16; -- Type definition for BRR_BR type BRR_BR_Field (As_Array : Boolean := False) is record case As_Array is when False => -- BR as a value Val : HAL.UInt16; when True => -- BR as an array Arr : BRR_BR_Field_Array; end case; end record with Unchecked_Union, Size => 16; for BRR_BR_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; type BRR_Register is record BR : BRR_BR_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for BRR_Register use record BR at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; ----------------- -- Peripherals -- ----------------- type GPIO_Peripheral is record MODER : aliased MODER_Register; OTYPER : aliased OTYPER_Register; OSPEEDR : aliased OSPEEDR_Register; PUPDR : aliased PUPDR_Register; IDR : aliased IDR_Register; ODR : aliased ODR_Register; BSRR : aliased BSRR_Register; LCKR : aliased LCKR_Register; AFRL : aliased AFRL_Register; AFRH : aliased AFRH_Register; BRR : aliased BRR_Register; end record with Volatile; for GPIO_Peripheral use record MODER at 16#0# range 0 .. 31; OTYPER at 16#4# range 0 .. 31; OSPEEDR at 16#8# range 0 .. 31; PUPDR at 16#C# range 0 .. 31; IDR at 16#10# range 0 .. 31; ODR at 16#14# range 0 .. 31; BSRR at 16#18# range 0 .. 31; LCKR at 16#1C# range 0 .. 31; AFRL at 16#20# range 0 .. 31; AFRH at 16#24# range 0 .. 31; BRR at 16#28# range 0 .. 31; end record; GPIOA_Periph : aliased GPIO_Peripheral with Import, Address => System'To_Address (16#48000000#); GPIOB_Periph : aliased GPIO_Peripheral with Import, Address => System'To_Address (16#48000400#); GPIOC_Periph : aliased GPIO_Peripheral with Import, Address => System'To_Address (16#48000800#); GPIOD_Periph : aliased GPIO_Peripheral with Import, Address => System'To_Address (16#48000C00#); GPIOE_Periph : aliased GPIO_Peripheral with Import, Address => System'To_Address (16#48001000#); GPIOH_Periph : aliased GPIO_Peripheral with Import, Address => System'To_Address (16#48001C00#); end STM32_SVD.GPIO;
-- part of AdaYaml, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "copying.txt" with AUnit; use AUnit; with AUnit.Test_Cases; use AUnit.Test_Cases; package Yaml.Dom.Dumping.Test is type TC is new Test_Cases.Test_Case with record Pool : Text.Pool.Reference; end record; overriding procedure Register_Tests (T : in out TC); overriding procedure Set_Up (T : in out TC); function Name (T : TC) return Message_String; procedure Plain_Scalar_Document (T : in out Test_Cases.Test_Case'Class); procedure Quoted_Scalar_Document (T : in out Test_Cases.Test_Case'Class); procedure Explicit_Document (T : in out Test_Cases.Test_Case'Class); end Yaml.Dom.Dumping.Test;
-- SPDX-FileCopyrightText: 2021 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- with WebIDL.Definitions; with WebIDL.Interface_Members; package WebIDL.Interfaces is pragma Preelaborate; type An_Interface is limited interface and WebIDL.Definitions.Definition; type Interface_Access is access all An_Interface'Class with Storage_Size => 0; not overriding function Members (Self : An_Interface) return WebIDL.Interface_Members.Interface_Member_Iterator_Access is abstract; end WebIDL.Interfaces;
-- Multithreaded relay with Ada.Command_Line; with Ada.Text_IO; with GNAT.Formatted_String; with ZMQ; procedure MTRelay is use type GNAT.Formatted_String.Formatted_String; type Context_Access is access all ZMQ.Context_Type'Class; task Step_1_Task is entry Start (Context_A : Context_Access); end Step_1_Task; task body Step_1_Task is Context : Context_Access := null; begin accept Start (Context_A : Context_Access) do Context := Context_A; end Start; declare -- Connect to step2 and tell it we're ready Xmitter : ZMQ.Socket_Type'Class := Context.New_Socket (ZMQ.ZMQ_PAIR); begin Xmitter.Connect ("inproc://step2"); Ada.Text_IO.Put_Line ("Step 1 ready, signaling step 2"); Xmitter.Send ("READY"); Xmitter.Close; end; end Step_1_Task; task Step_2_Task is entry Start (Context_A : Context_Access); end Step_2_Task; task body Step_2_Task is Context : Context_Access := null; begin accept Start (Context_A : Context_Access) do Context := Context_A; end Start; declare -- Bind inproc socket before starting step1 Receiver : ZMQ.Socket_Type'Class := Context.New_Socket (ZMQ.ZMQ_PAIR); begin Receiver.Bind ("inproc://step2"); Step_1_Task.Start (Context); -- Wait for signal and pass it on declare Unused_Msg : String := Receiver.Recv; begin null; end; Receiver.Close; end; -- Connect to step3 and tell it we're ready declare Xmitter : ZMQ.Socket_Type'Class := Context.New_Socket (ZMQ.ZMQ_PAIR); begin Xmitter.Connect ("inproc://step3"); Ada.Text_IO.Put_Line ("Step 2 ready, signaling step 3"); Xmitter.Send ("READY"); Xmitter.Close; end; end Step_2_Task; function Main return Ada.Command_Line.Exit_Status is Context : aliased ZMQ.Context_Type := ZMQ.New_Context; begin declare -- Bind inproc socket before starting step2 Receiver : ZMQ.Socket_Type'Class := Context.New_Socket (ZMQ.ZMQ_PAIR); begin Receiver.Bind ("inproc://step3"); Step_2_Task.Start (Context'Unrestricted_Access); -- Wait for signal declare Unused_Msg : String := Receiver.Recv; begin null; end; Receiver.Close; end; Ada.Text_IO.Put_Line ("Test successful!"); Context.Term; return 0; end Main; begin Ada.Command_Line.Set_Exit_Status (Main); end MTRelay;
--------------------------------------------------------------------------------- -- Copyright 2004-2005 © Luke A. Guest -- -- This code is to be used for tutorial purposes only. -- You may not redistribute this code in any form without my express permission. --------------------------------------------------------------------------------- package body Geometrical_Methods is function CollisionDetected(P : in Plane.Object; V : in Vector3.Object) return Boolean is begin -- Equation of a plane in vector notation: -- Pn . V = d -- Where: -- Pn = Plane normal -- V = Vector to test against -- d = Distance of the plane from the origin along the plane's normal. if Vector3.Dot(V, P.Normal) - P.Distance = 0.0 then return True; end if; return False; end CollisionDetected; function CollisionDetected(P : in Plane.Object; L : in Line_Segment.Object) return Boolean is -- Equation of a plane in vector notation: -- Pn . V = d -- Where: -- Pn = Plane normal -- V = Vector to test against -- d = Distance of the plane from the origin along the plane's normal. -- This seems to work no matter if PlaneD is added or subtracted from the dot products. EndPoint1 : Float := Vector3.Dot(L.StartPoint, P.Normal) - P.Distance; EndPoint2 : Float := Vector3.Dot(L.EndPoint, P.Normal) - P.Distance; begin --Put_Line("EndPoint1: " & Float'Image(EndPoint1) & " EndPoint2: " & Float'Image(EndPoint2)); if EndPoint1 * EndPoint2 < 0.0 then return True; end if; return False; end CollisionDetected; -- This is the same equation as the closest point on a line. -- q' = q + (distance - q.n)n function ClosestPoint(V : in Vector3.Object; P : in Plane.Object) return Vector3.Object is Temp : Float := P.Distance - Vector3.Dot(V, P.Normal); Prod : Vector3.Object := P.Normal * Temp; begin return V + Prod; end ClosestPoint; end Geometrical_Methods;
-- This file is covered by the Internet Software Consortium (ISC) License -- Reference: ../License.txt with Sodium.Thin_Binding; package Sodium.Functions is package Thin renames Sodium.Thin_Binding; ------------------ -- Data Types -- ------------------ subtype Standard_Hash is String (1 .. Positive (Thin.crypto_generichash_BYTES)); subtype Hash_Size_Range is Positive range Positive (Thin.crypto_generichash_BYTES_MIN) .. Positive (Thin.crypto_generichash_BYTES_MAX); subtype Any_Hash is String; subtype Standard_Key is String (1 .. Positive (Thin.crypto_generichash_KEYBYTES)); subtype Key_Size_Range is Positive range Positive (Thin.crypto_generichash_KEYBYTES_MIN) .. Positive (Thin.crypto_generichash_KEYBYTES_MAX); subtype Any_Key is String; subtype Short_Hash is String (1 .. Positive (Thin.crypto_shorthash_BYTES)); subtype Short_Key is String (1 .. Positive (Thin.crypto_shorthash_KEYBYTES)); subtype Password_Salt is String (1 .. Positive (Thin.crypto_pwhash_SALTBYTES)); subtype Passkey_Size_Range is Positive range 16 .. 64; subtype Any_Password_Key is String; subtype Public_Sign_Key is String (1 .. Positive (Thin.crypto_sign_PUBLICKEYBYTES)); subtype Secret_Sign_Key is String (1 .. Positive (Thin.crypto_sign_SECRETKEYBYTES)); subtype Sign_Key_Seed is String (1 .. Positive (Thin.crypto_sign_SEEDBYTES)); subtype Signature is String (1 .. Positive (Thin.crypto_sign_BYTES)); subtype Public_Box_Key is String (1 .. Positive (Thin.crypto_box_PUBLICKEYBYTES)); subtype Secret_Box_Key is String (1 .. Positive (Thin.crypto_box_SECRETKEYBYTES)); subtype Box_Key_Seed is String (1 .. Positive (Thin.crypto_box_SEEDBYTES)); subtype Box_Nonce is String (1 .. Positive (Thin.crypto_box_NONCEBYTES)); subtype Box_Shared_Key is String (1 .. Positive (Thin.crypto_box_BEFORENMBYTES)); subtype Symmetric_Key is String (1 .. Positive (Thin.crypto_secretbox_KEYBYTES)); subtype Symmetric_Nonce is String (1 .. Positive (Thin.crypto_secretbox_NONCEBYTES)); subtype Auth_Key is String (1 .. Positive (Thin.crypto_auth_KEYBYTES)); subtype Auth_Tag is String (1 .. Positive (Thin.crypto_auth_BYTES)); subtype Encrypted_Data is String; subtype Sealed_Data is String; subtype AEAD_Nonce is String; subtype AEAD_Key is String; type Natural32 is mod 2 ** 32; type Data_Criticality is (online_interactive, moderate, highly_sensitive); type AEAD_Construction is (ChaCha20_Poly1305, ChaCha20_Poly1305_IETF, AES256_GCM); type Hash_State is private; ---------------------- -- Initialization -- ---------------------- function initialize_sodium_library return Boolean; ---------------------- -- Hash Functions -- ---------------------- function Keyless_Hash (plain_text : String) return Standard_Hash; function Keyless_Hash (plain_text : String; output_size : Hash_Size_Range) return Any_Hash; function Keyed_Hash (plain_text : String; key : Standard_Key) return Standard_Hash; function Keyed_Hash (plain_text : String; key : Any_Key; output_size : Hash_Size_Range) return Any_Hash; function Multipart_Hash_Start (output_size : Hash_Size_Range) return Hash_State; function Multipart_Keyed_Hash_Start (key : Any_Key; output_size : Hash_Size_Range) return Hash_State; procedure Multipart_Append (plain_text : String; state : in out Hash_State); function Multipart_Hash_Complete (state : in out Hash_State) return Any_Hash; function Short_Input_Hash (short_data : String; key : Short_Key) return Short_Hash; --------------------- -- Random Things -- --------------------- function Random_Word return Natural32; function Random_Limited_Word (upper_bound : Natural32) return Natural32; function Random_Salt return Password_Salt; function Random_Nonce return Box_Nonce; function Random_Short_Key return Short_Key; function Random_Standard_Hash_Key return Standard_Key; function Random_Sign_Key_seed return Sign_Key_Seed; function Random_Box_Key_seed return Box_Key_Seed; function Random_Symmetric_Key return Symmetric_Key; function Random_Symmetric_Nonce return Symmetric_Nonce; function Random_Auth_Key return Auth_Key; function Random_Hash_Key (Key_Size : Key_Size_Range) return Any_Key; function Random_AEAD_Key (construction : AEAD_Construction := ChaCha20_Poly1305) return AEAD_Key; function Random_AEAD_Nonce (construction : AEAD_Construction := ChaCha20_Poly1305) return AEAD_Nonce; -------------------------- -- Password Functions -- -------------------------- function Derive_Password_Key (criticality : Data_Criticality := online_interactive; passkey_size : Passkey_Size_Range := Positive (Thin.crypto_box_SEEDBYTES); password : String; salt : Password_Salt) return Any_Password_Key; function Generate_Password_Hash (criticality : Data_Criticality := online_interactive; password : String) return Any_Hash; function Password_Hash_Matches (hash : Any_Hash; password : String) return Boolean; --------------- -- Helpers -- --------------- function As_Hexidecimal (binary : String) return String; function As_Binary (hexidecimal : String; ignore : String := "") return String; procedure increment_nonce (nonce : in out String); ----------------------------- -- Public Key Signatures -- ----------------------------- procedure Generate_Sign_Keys (sign_key_public : out Public_Sign_Key; sign_key_secret : out Secret_Sign_Key); procedure Generate_Sign_Keys (sign_key_public : out Public_Sign_Key; sign_key_secret : out Secret_Sign_Key; seed : Sign_Key_Seed); function Obtain_Signature (plain_text_message : String; sign_key_secret : Secret_Sign_Key) return Signature; function Signature_Matches (plain_text_message : String; sender_signature : Signature; sender_sign_key : Public_Sign_Key) return Boolean; ----------------------------- -- Public Key Encryption -- ----------------------------- procedure Generate_Box_Keys (box_key_public : out Public_Box_Key; box_key_secret : out Secret_Box_Key); procedure Generate_Box_Keys (box_key_public : out Public_Box_Key; box_key_secret : out Secret_Box_Key; seed : Box_Key_Seed); function Generate_Shared_Key (recipient_public_key : Public_Box_Key; sender_secret_key : Secret_Box_Key) return Box_Shared_Key; function Encrypt_Message (plain_text_message : String; recipient_public_key : Public_Box_Key; sender_secret_key : Secret_Box_Key; unique_nonce : Box_Nonce) return Encrypted_Data; function Encrypt_Message (plain_text_message : String; shared_key : Box_Shared_Key; unique_nonce : Box_Nonce) return Encrypted_Data; function Decrypt_Message (ciphertext : Encrypted_Data; sender_public_key : Public_Box_Key; recipient_secret_key : Secret_Box_Key; unique_nonce : Box_Nonce) return String; function Decrypt_Message (ciphertext : Encrypted_Data; shared_key : Box_Shared_Key; unique_nonce : Box_Nonce) return String; function Cipher_Length (plain_text_message : String) return Positive; function Clear_Text_Length (ciphertext : Encrypted_Data) return Positive; ---------------------------------- -- Anonymous Private Messages -- ---------------------------------- function Seal_Message (plain_text_message : String; recipient_public_key : Public_Box_Key) return Sealed_Data; function Unseal_Message (ciphertext : Sealed_Data; recipient_public_key : Public_Box_Key; recipient_secret_key : Secret_Box_Key) return String; function Sealed_Cipher_Length (plain_text : String) return Positive; function Sealed_Clear_Text_Length (ciphertext : Sealed_Data) return Positive; ---------------------------- -- Symmetric Encryption -- ---------------------------- function Symmetric_Encrypt (clear_text : String; secret_key : Symmetric_Key; unique_nonce : Symmetric_Nonce) return Encrypted_Data; function Symmetric_Decrypt (ciphertext : Encrypted_Data; secret_key : Symmetric_Key; unique_nonce : Symmetric_Nonce) return String; function Symmetric_Cipher_Length (plain_text : String) return Positive; function Symmetric_Clear_Text_Length (ciphertext : Encrypted_Data) return Positive; ------------------------------ -- Message Authentication -- ------------------------------ function Generate_Authentication_Tag (message : String; authentication_key : Auth_Key) return Auth_Tag; function Authentic_Message (message : String; authentication_tag : Auth_Tag; authentication_key : Auth_Key) return Boolean; ----------------------------------------------------- -- Authenticated Encryption with Additional Data -- ----------------------------------------------------- function AEAD_Encrypt (data_to_encrypt : String; additional_data : String; secret_key : AEAD_Key; unique_nonce : AEAD_Nonce; construction : AEAD_Construction := ChaCha20_Poly1305) return Encrypted_Data; function AEAD_Decrypt (ciphertext : Encrypted_Data; additional_data : String; secret_key : AEAD_Key; unique_nonce : AEAD_Nonce; construction : AEAD_Construction := ChaCha20_Poly1305) return String; function AEAD_Cipher_Length (plain_text : String; construction : AEAD_Construction := ChaCha20_Poly1305) return Positive; function AEAD_Clear_Text_Length (ciphertext : Encrypted_Data; construction : AEAD_Construction := ChaCha20_Poly1305) return Positive; function AES256_GCM_Available return Boolean; ------------------ -- Exceptions -- ------------------ Sodium_Out_Of_Memory : exception; Sodium_Already_Initialized : exception; Sodium_Invalid_Input : exception; Sodium_Wrong_Recipient : exception; Sodium_Symmetric_Failed : exception; Sodium_AEAD_Failed : exception; private type Hash_State is record hash_length : Thin.IC.size_t; state : aliased Thin.crypto_generichash_state; end record; function convert (data : Thin.IC.char_array) return String; function convert (data : String) return Thin.IC.char_array; end Sodium.Functions;
package body Count_Subprogram is procedure P2A (x, y : Integer) is null; procedure P2B (x : Integer; y : Integer) is null; procedure P4A (k, l, m, n : Integer) is null; procedure P4B (k : Integer; l : Integer; m : Integer; n : Integer) is null; procedure P3A (x, y, z : Integer) is null; procedure P3B (x, y : Integer; z : Integer) is null; procedure P3C (x : Integer; y, z : Integer) is null; procedure P3D (x : Integer; y : Integer; z : Integer) is null; procedure P3G (x : Integer := 0; y : Integer := 1; z : Integer := 2) is null; procedure P3H (x, y, z : Integer := 0) is null; -- STYLE_CHECK -- gnatyI: 'check mode IN keywords.' -- Mode in (the default mode) is not allowed to be given explicitly. -- in out is fine, but not in on its own. pragma Style_Checks (Off); procedure P3I (x, y, z : in Integer) is null; pragma Style_Checks (On); procedure P3J (x, y, z : in out Integer) is null; procedure P3K (x, y, z : out Integer) is null; -- Formal parameter is not referenced -- 1. pragma Unreferenced (x, y, z); can't be placed in the right scope -- 2. aspect is only associated with last parameter -- see https://gt3-prod-1.adacore.com/#/tickets/V401-014 pragma Extensions_Allowed (On); procedure P3N (x : Element_T with Unreferenced; y : Element_T with Unreferenced; z : Element_T with Unreferenced) is null; pragma Extensions_Allowed (Off); -- Formal parameter is not referenced -- pragma Unreferenced (x, y, z); can't be placed in the right scope pragma Extensions_Allowed (On); procedure P3O (x : Element_T with Unreferenced; y : Element_T with Unreferenced; z : Element_T with Unreferenced) is null; pragma Extensions_Allowed (Off); procedure S1 (Call_Back : access procedure (x, y, z : Integer)) is null; procedure S2 (Call_Back : access procedure (x : Integer; y : Integer; z : Integer)) is null; function F3C (x, y, z : Integer) return Integer is (x + y + z); function F3D (x : Integer; y : Integer; z : Integer) return Integer is (x + y + z); end Count_Subprogram;
with Ada.Assertions; use Ada.Assertions; package body Memory.Container is function Get_Memory(mem : Container_Type'Class) return Memory_Pointer is begin return Memory_Pointer(mem.mem); end Get_Memory; procedure Set_Memory(mem : in out Container_Type'Class; other : access Memory_Type'Class) is begin mem.mem := other; end Set_Memory; function Done(mem : Container_Type) return Boolean is begin if mem.mem /= null then return Done(mem.mem.all); else return True; end if; end Done; procedure Reset(mem : in out Container_Type; context : in Natural) is begin Reset(Memory_Type(mem), context); if mem.mem /= null then Reset(mem.mem.all, context); end if; mem.start_time := 0; end Reset; procedure Set_Port(mem : in out Container_Type; port : in Natural; ready : out Boolean) is begin if mem.mem /= null then Set_Port(mem.mem.all, port, ready); end if; end Set_Port; procedure Read(mem : in out Container_Type; address : in Address_Type; size : in Positive) is cycles : Time_Type; begin if mem.mem /= null then Start(mem); Read(mem.mem.all, address, size); Commit(mem, cycles); Advance(mem, cycles); end if; end Read; procedure Write(mem : in out Container_Type; address : in Address_Type; size : in Positive) is cycles : Time_Type; begin if mem.mem /= null then Start(mem); Write(mem.mem.all, address, size); Commit(mem, cycles); Advance(mem, cycles); end if; end Write; procedure Idle(mem : in out Container_Type; cycles : in Time_Type) is begin if mem.mem /= null then Idle(mem.mem.all, cycles); end if; Advance(mem, cycles); end Idle; procedure Start(mem : in out Container_Type'Class) is begin if mem.mem /= null then mem.start_time := Get_Time(mem.mem.all); else mem.start_time := mem.time; end if; end Start; procedure Commit(mem : in out Container_Type'Class; cycles : out Time_Type) is begin if mem.mem /= null then cycles := Get_Time(mem.mem.all) - mem.start_time; else cycles := mem.time - mem.start_time; end if; end Commit; procedure Do_Read(mem : in out Container_Type'Class; address : in Address_Type; size : in Positive) is begin if mem.mem /= null then Read(mem.mem.all, address, size); end if; end Do_Read; procedure Do_Write(mem : in out Container_Type'Class; address : in Address_Type; size : in Positive) is begin if mem.mem /= null then Write(mem.mem.all, address, size); end if; end Do_Write; procedure Do_Idle(mem : in out Container_Type'Class; cycles : in Time_Type) is begin if mem.mem /= null then Idle(mem.mem.all, cycles); else Advance(mem, cycles); end if; end Do_Idle; function Get_Path_Length(mem : Container_Type) return Natural is begin if mem.mem /= null then return Get_Path_Length(mem.mem.all); else return 0; end if; end Get_Path_Length; procedure Show_Access_Stats(mem : in out Container_Type) is begin if mem.mem /= null then Show_Access_Stats(mem.mem.all); end if; end Show_Access_Stats; function To_String(mem : Container_Type) return Unbounded_String is begin if mem.mem /= null then return To_String(mem.mem.all); else return Null_Unbounded_String; end if; end To_String; function Get_Cost(mem : Container_Type) return Cost_Type is begin if mem.mem /= null then return Get_Cost(mem.mem.all); else return 0; end if; end Get_Cost; function Get_Writes(mem : Container_Type) return Long_Integer is begin if mem.mem /= null then return Get_Writes(mem.mem.all); else return 0; end if; end Get_Writes; function Get_Word_Size(mem : Container_Type) return Positive is begin Assert(mem.mem /= null, "null memory in Memory.Container.Get_Word_Size"); return Get_Word_Size(mem.mem.all); end Get_Word_Size; function Get_Ports(mem : Container_Type) return Port_Vector_Type is begin return Get_Ports(mem.mem.all); end Get_Ports; procedure Adjust(mem : in out Container_Type) is begin if mem.mem /= null then mem.mem := Clone(mem.mem.all); end if; end Adjust; procedure Finalize(mem : in out Container_Type) is begin Destroy(Memory_Pointer(mem.mem)); Finalize(Memory_Type(mem)); end Finalize; end Memory.Container;
------------------------------------------------------------------------------ -- -- -- ASIS-for-GNAT IMPLEMENTATION COMPONENTS -- -- -- -- A 4 G . C U _ I N F O 2 -- -- -- -- B o d y -- -- -- -- Copyright (C) 1995-2012, Free Software Foundation, Inc. -- -- -- -- ASIS-for-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 -- -- Software Foundation; either version 2, or (at your option) any later -- -- version. ASIS-for-GNAT is distributed in the hope that it will be use- -- -- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- -- -- CHANTABILITY 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 ASIS-for-GNAT; see file -- -- COPYING. If not, write to the Free Software Foundation, 51 Franklin -- -- Street, Fifth Floor, Boston, MA 02110-1301, USA. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the -- -- Software Engineering Laboratory of the Swiss Federal Institute of -- -- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the -- -- Scientific Research Computer Center of Moscow State University (SRCC -- -- MSU), Russia, with funding partially provided by grants from the Swiss -- -- National Science Foundation and the Swiss Academy of Engineering -- -- Sciences. ASIS-for-GNAT is now maintained by AdaCore. -- -- (http://www.adacore.com). -- -- -- ------------------------------------------------------------------------------ with GNAT.OS_Lib; use GNAT.OS_Lib; with A4G.A_Opt; with A4G.A_Sinput; use A4G.A_Sinput; with A4G.Int_Knds; use A4G.Int_Knds; with A4G.Mapping; use A4G.Mapping; with A4G.Contt; use A4G.Contt; with A4G.Contt.Dp; use A4G.Contt.Dp; with A4G.Contt.UT; use A4G.Contt.UT; with Atree; use Atree; with Einfo; use Einfo; with Fname; use Fname; with Namet; use Namet; with Nlists; use Nlists; with Sinfo; use Sinfo; with Sinput; use Sinput; package body A4G.CU_Info2 is ----------------------- -- Local subprograms -- ----------------------- function Is_Mentioned_In_Annex_A return Boolean; -- This function assumes, that a normalized Ada name of a unit is set -- in the ASIS name buffer. It determines if this name is one of the -- names mentioned in the list of the names of predefined units given -- in RM 95 Annex A (2) function Is_Obsolescent_Renaming return Boolean; -- This function assumes, that a normalized Ada name of a unit is set -- in the ASIS name buffer. It determines if this name is one of the -- names mentioned in RM95 J.1 as Ada-83-style renaming of an Ada -- predefined unit ------------------ -- Get_Ada_Name -- ------------------ procedure Get_Ada_Name (Top : Node_Id) is Temp_Node : Node_Id; Unit_Name : Node_Id; Parent_Prefix : Node_Id; -- only for handling a subunit! Is_Subunit : Boolean := False; begin Temp_Node := Original_Node (Unit (Top)); if Nkind (Temp_Node) = N_Subunit then Is_Subunit := True; Parent_Prefix := Sinfo.Name (Temp_Node); Temp_Node := Proper_Body (Temp_Node); if Nkind (Temp_Node) = N_Subprogram_Body then Unit_Name := Defining_Unit_Name (Specification (Temp_Node)); elsif Nkind (Temp_Node) = N_Package_Body then Unit_Name := Defining_Unit_Name (Temp_Node); else -- N_Task_Body or N_Protected_Body Unit_Name := Defining_Identifier (Temp_Node); end if; -- in case of a subunit Unit_Name may be only of -- N_Defining_Identifier kind else case Nkind (Temp_Node) is when N_Subprogram_Declaration | N_Subprogram_Body | N_Package_Declaration | N_Generic_Package_Declaration | N_Generic_Subprogram_Declaration | N_Subprogram_Renaming_Declaration => Unit_Name := Defining_Unit_Name (Specification (Temp_Node)); when N_Package_Body | N_Package_Renaming_Declaration | N_Generic_Package_Renaming_Declaration | N_Generic_Procedure_Renaming_Declaration | N_Generic_Function_Renaming_Declaration | N_Package_Instantiation | N_Function_Instantiation | N_Procedure_Instantiation => Unit_Name := Defining_Unit_Name (Temp_Node); when others => pragma Assert (False); null; end case; end if; if Is_Subunit then Set_Name_String (Exp_Name_Image (Parent_Prefix) & '.' & Identifier_Image (Unit_Name)); else Set_Name_String (Exp_Name_Image (Unit_Name)); end if; end Get_Ada_Name; ------------- -- Is_Main -- ------------- function Is_Main (Top : Node_Id; Kind : Unit_Kinds) return Boolean is Unit_Node : Node_Id := Empty; Result : Boolean := False; begin case Kind is when A_Procedure | A_Procedure_Body | A_Function | A_Function_Body | A_Procedure_Renaming | A_Function_Renaming => Unit_Node := Specification (Unit (Top)); when A_Function_Instance | A_Procedure_Instance => Unit_Node := Unit (Top); if Nkind (Unit_Node) = N_Package_Body then Unit_Node := Corresponding_Spec (Unit_Node); while Nkind (Unit_Node) /= N_Package_Declaration loop Unit_Node := Parent (Unit_Node); end loop; end if; Unit_Node := Last_Non_Pragma (Visible_Declarations (Specification (Unit_Node))); Unit_Node := Specification (Unit_Node); when others => null; end case; if Present (Unit_Node) then Result := not Present (Parameter_Specifications (Unit_Node)); end if; if Result then case Kind is when A_Function | A_Function_Body | A_Function_Instance | A_Function_Renaming => Result := Is_Integer_Type (Entity (Sinfo.Result_Definition (Unit_Node))); when others => null; end case; end if; return Result; end Is_Main; ----------------------------- -- Is_Mentioned_In_Annex_A -- ----------------------------- function Is_Mentioned_In_Annex_A return Boolean is Result : Boolean := False; Ind : Positive := 1; Max_Child_Nlen : constant Integer := 36; subtype Child_Name is String (1 .. Max_Child_Nlen); type Child_List is array (Integer range <>) of Child_Name; Ada_Childs : constant Child_List := ( -- Contains names of child units of the Ada package that are predefined -- units in Ada 95 "asynchronous_task_control ", "calendar ", "characters ", "command_line ", "decimal ", "direct_io ", "dynamic_priorities ", "exceptions ", "finalization ", "interrupts ", "io_exceptions ", "numerics ", "real_time ", "sequential_io ", "storage_io ", "streams ", "strings ", "synchronous_task_control ", "tags ", "task_attributes ", "task_identification ", "text_io ", "unchecked_conversion ", "unchecked_deallocation ", "wide_text_io "); Ada_Childs_2005 : constant Child_List := ( -- Contains names of child units of the Ada package that are predefined -- units in Ada 2005 (but not in Ada 95) "assertions ", "complex_text_io ", "containers ", "directories ", "dispatching ", "environment_variables ", "execution_time ", "float_text_io ", "float_wide_text_io ", "float_wide_wide_text_io ", "integer_text_io ", "integer_wide_text_io ", "integer_wide_wide_text_io ", "task_termination ", "wide_characters ", "wide_wide_characters ", "wide_wide_text_io "); Ada_Execution_Time_Childs : constant Child_List := ( -- Contains names of child units of the Ada.Execution_Time package, -- these units are predefined in Ada 2005 only "group_budgets ", "timers "); Ada_Characters_Childs : constant Child_List := ( "handling ", "latin_1 "); Ada_Numerics_Childs : constant Child_List := ( -- Contains names of child units of Ada.Numerics, that are defined in -- Ada 95 "complex_elementary_functions ", "complex_types ", "discrete_random ", "elementary_functions ", "float_random ", "generic_complex_elementary_functions", "generic_complex_types ", "generic_elementary_functions "); Ada_Numerics_Childs_2005 : constant Child_List := ( -- Contains names of child units of Ada.Numerics, that are defined in -- Ada 2005 (but not in Ada 95) "complex_arrays ", "generic_complex_arrays ", "generic_real_arrays ", "real_arrays "); Ada_Strings_Childs : constant Child_List := ( -- Contains names of child units of Ada.Strings, that are defined in -- Ada 95 "bounded ", "fixed ", "maps ", "unbounded ", "wide_bounded ", "wide_fixed ", "wide_maps ", "wide_unbounded "); Ada_Strings_Childs_2005 : constant Child_List := ( -- Contains names of child units of Ada.Strings, that are defined in -- Ada 2005 (but not in Ada 95) "hash ", "wide_hash ", "wide_wide_bounded ", "wide_wide_fixed ", "wide_wide_hash ", "wide_wide_maps ", "wide_wide_unbounded "); Ada_Text_IO_Childs : constant Child_List := ( -- Contains names of child units of Ada.Text_IO, that are defined in -- Ada 95 "complex_io ", "editing ", "text_streams "); Ada_Text_IO_Childs_2005 : constant Child_List := ( -- Contains names of child units of Ada.Text_IO, that are defined in -- Ada 2005 (but not in Ada 95) "bounded_io ", "unbounded_io "); Ada_Wide_Text_IO_Childs : constant Child_List := ( -- Contains names of child units of Ada.Wide_Text_IO, that are defined -- in Ada 2005 and that are different from the defined in Ada 95 -- children of Ada.Text_IO "wide_bounded_io ", "wide_unbounded_io "); Ada_Wide_Wide_Text_IO_Childs : constant Child_List := ( -- Contains names of child units of Ada.Wide_Wide_Text_IO, that are -- defined in Ada 2005 and that are different from the defined in Ada 95 -- children of Ada.Text_IO "wide_wide_bounded_io ", "wide_wide_unbounded_io "); Interfaces_Childs : constant Child_List := ( "c ", "cobol ", "fortran "); Interfaces_C_Childs : constant Child_List := ( "pointers ", "strings "); System_Childs : constant Child_List := ( "address_to_access_conversions ", "machine_code ", "rpc ", "storage_elements ", "storage_pools "); function In_Child_List (Ind : Positive; L : Child_List) return Boolean; -- Checks if a part of a unit name which is stored in -- A_Name_Buffer (Ind .. A_Name_Len) belongs to a list of predefined -- child unit for a given predefined root unit function In_Child_List (Ind : Positive; L : Child_List) return Boolean is Padded_Unit_Name : String (1 .. Max_Child_Nlen); Last_Dot : Positive := 1; begin if A_Name_Len >= Ind + Max_Child_Nlen then return False; end if; -- checking if the argument name is not a name of grandchild: for I in reverse 1 .. A_Name_Len loop if A_Name_Buffer (I) = '.' then Last_Dot := I; exit; end if; end loop; if Last_Dot > Ind then return False; end if; Padded_Unit_Name (1 .. (A_Name_Len - Ind + 1)) := A_Name_Buffer (Ind .. A_Name_Len); Padded_Unit_Name ((A_Name_Len - Ind + 1) + 1 .. Max_Child_Nlen) := (others => ' '); for I in L'Range loop if Padded_Unit_Name = L (I) then return True; end if; end loop; return False; end In_Child_List; begin -- no need to analyze the suffix of a normalized name: A_Name_Len := A_Name_Len - 2; -- No need to check the Standard package - its origin is set when -- the corresponding unit entry is created in a special way if A_Name_Len >= 3 and then A_Name_Buffer (1 .. 3) = "ada" then if A_Name_Len = 3 then Result := True; else Ind := 5; Result := In_Child_List (Ind, Ada_Childs) or else (A4G.A_Opt.ASIS_2005_Mode_Internal and then In_Child_List (Ind, Ada_Childs_2005)); if Result = False then -- Checking grandchildren of Ada: if A_Name_Buffer (Ind .. Ind + 10) = "characters." then Ind := Ind + 11; Result := In_Child_List (Ind, Ada_Characters_Childs) or else (A4G.A_Opt.ASIS_2005_Mode_Internal and then A_Name_Buffer (Ind .. A_Name_Len) = "conversions"); elsif A_Name_Buffer (Ind .. Ind + 8) = "numerics." then Ind := Ind + 9; Result := In_Child_List (Ind, Ada_Numerics_Childs) or else (A4G.A_Opt.ASIS_2005_Mode_Internal and then In_Child_List (Ind, Ada_Numerics_Childs_2005)); elsif A_Name_Buffer (Ind .. A_Name_Len) = "streams.stream_io" or else A_Name_Buffer (Ind .. A_Name_Len) = "interrupts.names" or else (A4G.A_Opt.ASIS_2005_Mode_Internal and then (A_Name_Buffer (Ind .. A_Name_Len) = "real_time.timing_events" or else A_Name_Buffer (Ind .. A_Name_Len) = "tags.generic_dispatching_constructor")) then -- only one grandchild is possible, no need for searching Result := True; elsif A_Name_Buffer (Ind .. Ind + 7) = "strings." then Ind := Ind + 8; Result := In_Child_List (Ind, Ada_Strings_Childs) or else (A4G.A_Opt.ASIS_2005_Mode_Internal and then In_Child_List (Ind, Ada_Strings_Childs_2005)); if Result = False then if A_Name_Buffer (Ind .. A_Name_Len) = "maps.constants" or else A_Name_Buffer (Ind .. A_Name_Len) = "wide_maps.wide_constants" or else (A4G.A_Opt.ASIS_2005_Mode_Internal and then (A_Name_Buffer (Ind .. A_Name_Len) = "bounded.hash" or else A_Name_Buffer (Ind .. A_Name_Len) = "fixed.hash" or else A_Name_Buffer (Ind .. A_Name_Len) = "unbounded.hash" or else A_Name_Buffer (Ind .. A_Name_Len) = "wide_bounded.wide_hash" or else A_Name_Buffer (Ind .. A_Name_Len) = "wide_fixed.wide_hash" or else A_Name_Buffer (Ind .. A_Name_Len) = "wide_unbounded.wide_hash" or else A_Name_Buffer (Ind .. A_Name_Len) = "wide_wide_bounded.wide_wide_hash" or else A_Name_Buffer (Ind .. A_Name_Len) = "wide_wide_fixed.wide_wide_hash" or else A_Name_Buffer (Ind .. A_Name_Len) = "wide_wide_maps.wide_wide_constants" or else A_Name_Buffer (Ind .. A_Name_Len) = "wide_wide_unbounded.wide_wide_hash")) then Result := True; end if; end if; elsif A_Name_Buffer (Ind .. Ind + 7) = "text_io." then Ind := Ind + 8; Result := In_Child_List (Ind, Ada_Text_IO_Childs) or else (A4G.A_Opt.ASIS_2005_Mode_Internal and then In_Child_List (Ind, Ada_Text_IO_Childs_2005)); elsif A_Name_Buffer (Ind .. Ind + 12) = "wide_text_io." then Ind := Ind + 13; Result := In_Child_List (Ind, Ada_Text_IO_Childs) or else (A4G.A_Opt.ASIS_2005_Mode_Internal and then (In_Child_List (Ind, Ada_Text_IO_Childs_2005) or else In_Child_List (Ind, Ada_Wide_Text_IO_Childs))); -- Ada 2005 stuff elsif A4G.A_Opt.ASIS_2005_Mode_Internal and then A_Name_Buffer (Ind .. Ind + 14) = "execution_time." then Ind := Ind + 15; Result := In_Child_List (Ind, Ada_Execution_Time_Childs); elsif A4G.A_Opt.ASIS_2005_Mode_Internal and then A_Name_Buffer (Ind .. Ind + 17) = "wide_wide_text_io." then Result := In_Child_List (Ind, Ada_Text_IO_Childs) or else In_Child_List (Ind, Ada_Text_IO_Childs_2005) or else In_Child_List (Ind, Ada_Wide_Wide_Text_IO_Childs); end if; end if; end if; elsif A_Name_Len >= 10 and then A_Name_Buffer (1 .. 10) = "interfaces" then if A_Name_Len = 10 then Result := True; else Ind := 12; Result := In_Child_List (Ind, Interfaces_Childs); if Result = False then -- Checking grandchildren of Interfaces: if A_Name_Buffer (Ind .. Ind + 1) = "c." then Ind := Ind + 2; Result := In_Child_List (Ind, Interfaces_C_Childs); end if; end if; end if; elsif A_Name_Len >= 6 and then A_Name_Buffer (1 .. 6) = "system" then if A_Name_Len = 6 then Result := True; else Ind := 8; Result := In_Child_List (Ind, System_Childs); end if; end if; return Result; end Is_Mentioned_In_Annex_A; ----------------------------- -- Is_Obsolescent_Renaming -- ----------------------------- function Is_Obsolescent_Renaming return Boolean is Result : Boolean := False; begin -- This function is called after Is_Mentioned_In_Annex_A, so A_Name_Len -- is already moved two positions left to skip the suffix if A_Name_Buffer (A_Name_Len + 1 .. A_Name_Len + 2) = "%s" then case A_Name_Len is when 7 => Result := A_Name_Buffer (1 .. A_Name_Len) = "text_io"; when 8 => Result := A_Name_Buffer (1 .. A_Name_Len) = "calendar"; when 9 => Result := A_Name_Buffer (1 .. A_Name_Len) = "direct_io"; when 12 => Result := A_Name_Buffer (1 .. A_Name_Len) = "machine_code"; when 13 => Result := A_Name_Buffer (1 .. A_Name_Len) = "sequential_io" or else A_Name_Buffer (1 .. A_Name_Len) = "io_exceptions"; when 20 => Result := A_Name_Buffer (1 .. A_Name_Len) = "unchecked_conversion"; when 22 => Result := A_Name_Buffer (1 .. A_Name_Len) = "unchecked_deallocation"; when others => null; end case; end if; return Result; end Is_Obsolescent_Renaming; ---------------------- -- Set_Dependencies -- ---------------------- procedure Set_Dependencies (C : Context_Id; U : Unit_Id; Top : Node_Id) is Unit_Kind : constant Unit_Kinds := Kind (C, U); begin Set_Supporters (C, U, Top); if Unit_Kind = A_Procedure or else Unit_Kind = A_Function or else Unit_Kind = A_Package or else Unit_Kind = A_Generic_Procedure or else Unit_Kind = A_Generic_Function or else Unit_Kind = A_Generic_Package or else Unit_Kind = A_Procedure_Instance or else Unit_Kind = A_Function_Instance or else Unit_Kind = A_Package_Instance or else Unit_Kind = A_Procedure_Renaming or else Unit_Kind = A_Function_Renaming or else Unit_Kind = A_Package_Renaming or else Unit_Kind = A_Generic_Procedure_Renaming or else Unit_Kind = A_Generic_Function_Renaming or else Unit_Kind = A_Generic_Package_Renaming or else Unit_Kind = A_Procedure_Body or else Unit_Kind = A_Function_Body or else Unit_Kind = A_Package_Body or else Unit_Kind = A_Procedure_Body_Subunit or else Unit_Kind = A_Function_Body_Subunit or else Unit_Kind = A_Package_Body_Subunit or else Unit_Kind = A_Task_Body_Subunit or else Unit_Kind = A_Protected_Body_Subunit or else Unit_Kind = An_Unknown_Unit then Add_To_Parent (C, U); end if; end Set_Dependencies; ------------------------ -- Set_Kind_and_Class -- ------------------------- procedure Set_Kind_and_Class (C : Context_Id; U : Unit_Id; Top : Node_Id) is Is_Private : Boolean; Unit_Node : Node_Id; Unit_Node_Kind : Node_Kind; Kind_To_Set : Unit_Kinds := Not_A_Unit; Class_To_Set : Unit_Classes := Not_A_Class; begin Is_Private := Private_Present (Top); Unit_Node := Unit (Top); -- Original_Node??? if Is_Rewrite_Substitution (Unit_Node) then -- For Generic Unit_Node := Original_Node (Unit_Node); -- Instantiations end if; Unit_Node_Kind := Nkind (Unit_Node); case Unit_Node_Kind is when N_Subprogram_Declaration => if Asis_Internal_Element_Kind (Unit_Node) = A_Procedure_Declaration then Kind_To_Set := A_Procedure; else Kind_To_Set := A_Function; end if; if Is_Private then Class_To_Set := A_Private_Declaration; else Class_To_Set := A_Public_Declaration; end if; when N_Package_Declaration => Kind_To_Set := A_Package; if Is_Private then Class_To_Set := A_Private_Declaration; else Class_To_Set := A_Public_Declaration; end if; when N_Generic_Declaration => if Unit_Node_Kind = N_Generic_Package_Declaration then Kind_To_Set := A_Generic_Package; else -- two possibilities: generic procedure or generic function if Asis_Internal_Element_Kind (Unit_Node) = A_Generic_Procedure_Declaration then Kind_To_Set := A_Generic_Procedure; else Kind_To_Set := A_Generic_Function; end if; end if; if Is_Private then Class_To_Set := A_Private_Declaration; else Class_To_Set := A_Public_Declaration; end if; when N_Generic_Instantiation => if Unit_Node_Kind = N_Package_Instantiation then Kind_To_Set := A_Package_Instance; elsif Unit_Node_Kind = N_Procedure_Instantiation then Kind_To_Set := A_Procedure_Instance; else Kind_To_Set := A_Function_Instance; end if; if Is_Private then Class_To_Set := A_Private_Declaration; else Class_To_Set := A_Public_Declaration; end if; when N_Subprogram_Renaming_Declaration => if Asis_Internal_Element_Kind (Unit_Node) = A_Procedure_Renaming_Declaration then Kind_To_Set := A_Procedure_Renaming; else Kind_To_Set := A_Function_Renaming; end if; if Is_Private then Class_To_Set := A_Private_Declaration; else Class_To_Set := A_Public_Declaration; end if; when N_Package_Renaming_Declaration => Kind_To_Set := A_Package_Renaming; if Is_Private then Class_To_Set := A_Private_Declaration; else Class_To_Set := A_Public_Declaration; end if; when N_Generic_Renaming_Declaration => if Unit_Node_Kind = N_Generic_Procedure_Renaming_Declaration then Kind_To_Set := A_Generic_Procedure_Renaming; elsif Unit_Node_Kind = N_Generic_Function_Renaming_Declaration then Kind_To_Set := A_Generic_Function_Renaming; else Kind_To_Set := A_Generic_Package_Renaming; end if; if Is_Private then Class_To_Set := A_Private_Declaration; else Class_To_Set := A_Public_Declaration; end if; when N_Subprogram_Body => if Asis_Internal_Element_Kind (Unit_Node) = A_Procedure_Body_Declaration then Kind_To_Set := A_Procedure_Body; else Kind_To_Set := A_Function_Body; end if; if Acts_As_Spec (Top) or else not Comes_From_Source (Corresponding_Spec (Unit (Top))) -- This part of the condition covers an artificial spec created -- for a child subprogram then Class_To_Set := A_Public_Declaration_And_Body; else if Private_Present (Library_Unit (Top)) then Class_To_Set := A_Private_Body; else Class_To_Set := A_Public_Body; end if; end if; when N_Package_Body => Kind_To_Set := A_Package_Body; if Private_Present (Library_Unit (Top)) then Class_To_Set := A_Private_Body; else Class_To_Set := A_Public_Body; end if; when N_Subunit => Unit_Node := Proper_Body (Unit_Node); case Nkind (Unit_Node) is when N_Subprogram_Body => if Asis_Internal_Element_Kind (Unit_Node) = A_Procedure_Body_Declaration then Kind_To_Set := A_Procedure_Body_Subunit; else Kind_To_Set := A_Function_Body_Subunit; end if; when N_Package_Body => Kind_To_Set := A_Package_Body_Subunit; when N_Task_Body => Kind_To_Set := A_Task_Body_Subunit; when N_Protected_Body => Kind_To_Set := A_Protected_Body_Subunit; when others => null; end case; Class_To_Set := A_Separate_Body; when others => pragma Assert (False); null; end case; Set_Kind (C, U, Kind_To_Set); Set_Class (C, U, Class_To_Set); end Set_Kind_and_Class; ----------------------------- -- Set_S_F_Name_and_Origin -- ----------------------------- procedure Set_S_F_Name_and_Origin (Context : Context_Id; Unit : Unit_Id; Top : Node_Id) is Fname : File_Name_Type; Ref_Fname : File_Name_Type; Origin : Unit_Origins; begin -- Setting the (full) source file name in the Unit table. -- The source file is the file which has been compiled Fname := Full_File_Name (Get_Source_File_Index (Sloc (Top))); Namet.Get_Name_String (Fname); Set_Name_String (Normalize_Pathname (Namet.Name_Buffer (1 .. Namet.Name_Len), Resolve_Links => False)); Set_Source_File_Name (Unit); -- Setting the (full) reference file name Ref_Fname := Full_Ref_Name (Get_Source_File_Index (Sloc (Top))); if Ref_Fname = Fname then Set_Ref_File_As_Source_File (Unit); else Namet.Get_Name_String (Ref_Fname); Set_Ref_File_Name_String (Unit); Set_Source_File_Name (Unit, Ref => True); end if; -- to define the unit origin, we have to reset Fname to the short -- (that is, containing no directory information) file name Fname := File_Name (Get_Source_File_Index (Sloc (Top))); if Is_Predefined_File_Name (Fname) then Get_Name_String (Unit, Norm_Ada_Name); if Is_Mentioned_In_Annex_A then Origin := A_Predefined_Unit; elsif Is_Obsolescent_Renaming then -- We use a separate elsif path here to stress that this case may -- need more processing: we may want to check if such a unit is -- not redefined by a user, see RM95 J.1(10) and the discussion -- for B612-002 Origin := A_Predefined_Unit; else Origin := An_Implementation_Unit; end if; elsif Is_Internal_File_Name (Fname) then Origin := An_Implementation_Unit; else Origin := An_Application_Unit; end if; Set_Origin (Context, Unit, Origin); end Set_S_F_Name_and_Origin; end A4G.CU_Info2;
------------------------------------------------------------------------------ -- -- -- WAVEFILES -- -- -- -- Wavefile benchmarking -- -- -- -- The MIT License (MIT) -- -- -- -- Copyright (c) 2020 -- 2021 Gustavo A. Hoffmann -- -- -- -- 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.Text_IO; use Ada.Text_IO; with Ada.Real_Time; use Ada.Real_Time; with Ada.Execution_Time; use Ada.Execution_Time; with Audio.Wavefiles; use Audio.Wavefiles; with Audio.Wavefiles.Data_Types; use Audio.Wavefiles.Data_Types; with Audio.RIFF.Wav.Formats; use Audio.RIFF.Wav.Formats; with Audio.Wavefiles.Generic_Direct_Fixed_Wav_IO; with Time_Span_Conversions; with Write_Random_Noise_Wavefile; package body Wavefile_Benchmarking is Display_Debug_Info : constant Boolean := False; Verbose : constant Boolean := True; WF_In : Wavefile; WF_Out : Wavefile; procedure Open_Wavefile; procedure Close_Wavefile; function kHz_Per_Sample (Elapsed_Time : Time_Span; CPU_MHz : Float; Number_Ch : Positive; Number_Samples : Long_Long_Integer) return Float; procedure Display_Info (Elapsed_Time : Time_Span; CPU_MHz : Float; Number_Ch : Positive; Number_Samples : Long_Long_Integer; Sample_Rate : Positive); ------------------- -- Open_Wavefile -- ------------------- procedure Open_Wavefile is Wav_In_File_Name : constant String := "2ch_long_noise.wav"; Wav_Out_File_Name : constant String := "dummy.wav"; begin WF_In.Open (In_File, Wav_In_File_Name); WF_Out.Set_Format_Of_Wavefile (WF_In.Format_Of_Wavefile); WF_Out.Create (Out_File, Wav_Out_File_Name); end Open_Wavefile; -------------------- -- Close_Wavefile -- -------------------- procedure Close_Wavefile is begin WF_In.Close; WF_Out.Close; end Close_Wavefile; -------------------- -- kHz_Per_Sample -- -------------------- function kHz_Per_Sample (Elapsed_Time : Time_Span; CPU_MHz : Float; Number_Ch : Positive; Number_Samples : Long_Long_Integer) return Float is Factor : constant Long_Long_Float := (Long_Long_Float (Number_Samples) * Long_Long_Float (Number_Ch)); begin return Time_Span_Conversions.To_kHz (Elapsed_Time, CPU_MHz, Factor); end kHz_Per_Sample; ------------------ -- Display_Info -- ------------------ procedure Display_Info (Elapsed_Time : Time_Span; CPU_MHz : Float; Number_Ch : Positive; Number_Samples : Long_Long_Integer; Sample_Rate : Positive) is use Time_Span_Conversions; package F_IO is new Ada.Text_IO.Float_IO (Float); -- Duration_In_Seconds : Long_Long_Float := -- Long_Long_Float (Number_Samples) -- / Long_Long_Float (Sample_Rate); Factor : constant Long_Long_Float := (Long_Long_Float (Number_Samples) * Long_Long_Float (Number_Ch)); begin Put ("CPU time: "); F_IO.Put (Item => To_Miliseconds (Elapsed_Time), Fore => 5, Aft => 4, Exp => 0); Put (" miliseconds"); Put (" for " & Long_Long_Integer'Image (Number_Samples) & " samples"); Put (" on " & Integer'Image (Number_Ch) & " channels"); Put (" at " & Integer'Image (Sample_Rate) & " Hz"); New_Line; Put ("Overall Perf.: "); F_IO.Put (Item => (To_MHz (Elapsed_Time, CPU_MHz, Factor) * Float (Sample_Rate)), Fore => 5, Aft => 4, Exp => 0); Put (" MHz (per channel @ " & Positive'Image (Sample_Rate) & " kHz)"); New_Line; Put ("Overall Perf.: "); F_IO.Put (Item => To_kHz (Elapsed_Time, CPU_MHz, Factor), Fore => 5, Aft => 4, Exp => 0); Put (" kHz (per channel and per sample)"); New_Line; end Display_Info; --------------------- -- Benchm_CPU_Time -- --------------------- function Benchm_CPU_Time (CPU_MHz : Float) return Wavefile_Benchmark_kHz is Res : Wavefile_Benchmark_kHz; Start_Time, Stop_Time : CPU_Time; Elapsed_Time : Time_Span; Sample_Rate : Positive; package Wav_IO is new Audio.Wavefiles.Generic_Direct_Fixed_Wav_IO (Wav_Sample => Wav_Fixed_16, Channel_Range => Positive, Wav_MC_Sample => Wav_Buffer_Fixed_16); use Wav_IO; Cnt, Total_Cnt : Long_Long_Integer := 0; begin Write_Random_Noise_Wavefile; Open_Wavefile; Sample_Rate := To_Positive (WF_In.Format_Of_Wavefile.Samples_Per_Sec); pragma Assert (WF_In.Format_Of_Wavefile.Bits_Per_Sample = Bit_Depth_16 and then not WF_In.Format_Of_Wavefile.Is_Float_Format); if Display_Debug_Info then Put_Line ("========================================================"); Put_Line ("= Read"); Put_Line ("========================================================"); end if; Start_Time := Clock; loop Read_Wav_MC_Samples : declare Dummy_Wav_Buf : constant Wav_Buffer_Fixed_16 := Get (WF_In); begin Cnt := Cnt + 1; exit when End_Of_File (WF_In); end Read_Wav_MC_Samples; end loop; Stop_Time := Clock; Elapsed_Time := Stop_Time - Start_Time; -- Res (Wavefile_Read_Benchmark) := Elapsed_Time; Res (Wavefile_Read_Benchmark) := kHz_Per_Sample (Elapsed_Time, CPU_MHz, Number_Of_Channels (WF_In), Cnt); if Display_Debug_Info then Display_Info (Elapsed_Time, CPU_MHz, Number_Of_Channels (WF_In), Cnt, Sample_Rate); Put_Line ("========================================================"); Put_Line ("= Write"); Put_Line ("========================================================"); end if; Total_Cnt := Cnt; Cnt := 0; declare Wav_Buf : constant Wav_Buffer_Fixed_16 (1 .. Number_Of_Channels (WF_In)) := (others => 0.5); begin Start_Time := Clock; loop Write_Wav_MC_Samples : declare begin Cnt := Cnt + 1; Put (WF_Out, Wav_Buf); exit when Cnt = Total_Cnt; end Write_Wav_MC_Samples; end loop; Stop_Time := Clock; Elapsed_Time := Stop_Time - Start_Time; -- Res (Wavefile_Write_Benchmark) := Elapsed_Time; Res (Wavefile_Write_Benchmark) := kHz_Per_Sample (Elapsed_Time, CPU_MHz, Number_Of_Channels (WF_In), Cnt); end; if Display_Debug_Info then Display_Info (Elapsed_Time, CPU_MHz, Number_Of_Channels (WF_In), Cnt, Sample_Rate); end if; Close_Wavefile; return Res; end Benchm_CPU_Time; --------------------- -- Benchm_CPU_Time -- --------------------- procedure Benchm_CPU_Time (CPU_MHz : Float; Results : out Wavefile_Benchmark_Infos) is begin for I in Results'Range loop if Verbose and not Display_Debug_Info then Put ("."); end if; Results (I) := Benchm_CPU_Time (CPU_MHz); end loop; if Verbose and not Display_Debug_Info then New_Line; end if; end Benchm_CPU_Time; end Wavefile_Benchmarking;
with Inline7_Pkg2; package body Inline7_Pkg1 is procedure Test (I : Integer) is function F is new Inline7_Pkg2.Calc (I); begin if I /= F (I) then raise Program_Error; end if; end; end Inline7_Pkg1;
--------------------------------------------------------------------------- -- package Hessenberg -- Copyright (C) 2011-2018 Jonathan S. Parker -- -- Permission to use, copy, modify, and/or 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. --------------------------------------------------------------------------- generic type Real is digits <>; type Index is range <>; type A_Matrix is array(Index, Index) of Real; package Hessenberg is subtype C_Index is Index; subtype R_Index is Index; function Identity return A_Matrix; -- The input matrix A is transformed with similarity transformations: -- -- A_hessenberg = Q_transpose * A * Q. -- -- The Q's are orthogonal matrices constructed from the products of -- 2 x 2 Givens matrices. -- Q matrix has the same shape as A. procedure Lower_Hessenberg (A : in out A_Matrix; Q : out A_Matrix; Starting_Col : in C_Index := C_Index'First; Final_Col : in C_Index := C_Index'Last; Initial_Q : in A_Matrix := Identity); procedure Upper_Hessenberg (A : in out A_Matrix; Q : out A_Matrix; Starting_Col : in C_Index := C_Index'First; Final_Col : in C_Index := C_Index'Last; Initial_Q : in A_Matrix := Identity); end Hessenberg;
-- Abstract : -- -- See spec. -- -- Copyright (C) 2018 Free Software Foundation, Inc. -- -- 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 MERCHAN- -- TABILITY 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. pragma License (Modified_GPL); package body SAL.Gen_Unbounded_Definite_Vectors.Gen_Comparable is function Compare (Left, Right : in Vector) return Compare_Result is use all type Ada.Containers.Count_Type; begin if Left.Length = 0 then if Right.Length = 0 then return Equal; else -- null is less than non-null return Less; end if; elsif Right.Length = 0 then return Greater; else declare I : Base_Peek_Type := To_Peek_Type (Left.First); J : Base_Peek_Type := To_Peek_Type (Right.First); Left_Last : constant Base_Peek_Type := To_Peek_Type (Left.Last); Right_Last : constant Base_Peek_Type := To_Peek_Type (Right.Last); begin loop exit when I > Left_Last or J > Right_Last; case Element_Compare (Left.Elements (I), Right.Elements (J)) is when Less => return Less; when Equal => I := I + 1; J := J + 1; when Greater => return Greater; end case; end loop; if I > Left_Last then if J > Right_Last then return Equal; else -- right is longer return Less; end if; else -- left is longer return Greater; end if; end; end if; end Compare; end SAL.Gen_Unbounded_Definite_Vectors.Gen_Comparable;
with Resource4; with Ada.Command_Line; with Ada.Text_IO; procedure Test4 is use Resource4; C : Content_Access := Get_Content ("web/main.html"); begin if C = null then Ada.Text_IO.Put_Line ("FAIL: No content 'web/main.html'"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); return; end if; if C'Length /= 360 then Ada.Text_IO.Put_Line ("FAIL: Invalid length for 'web/main.html'"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); end if; C := Get_Content ("web/images/wiki-create.png"); if C = null then Ada.Text_IO.Put_Line ("FAIL: No content 'web/images/wiki-create.png'"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); return; end if; if C'Length /= 3534 then Ada.Text_IO.Put_Line ("FAIL: Invalid length for 'web/images/wiki-create.png'"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); end if; C := Get_Content ("not-included.xml"); if C /= null then Ada.Text_IO.Put_Line ("FAIL: Content was included 'not-included.xml'"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); return; end if; C := Get_Content ("web/preview/main-not-included.html"); if C /= null then Ada.Text_IO.Put_Line ("FAIL: Content was included 'web/preview/main-not-included.html'"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); return; end if; C := Get_Content ("web/js/main.js"); if C /= null then Ada.Text_IO.Put_Line ("FAIL: Content was included 'web/js/main.js'"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); return; end if; C := Get_Content ("web/css/main.css"); if C = null then Ada.Text_IO.Put_Line ("FAIL: No content 'web/css/main.css'"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); return; end if; if C'Length /= 94 then Ada.Text_IO.Put_Line ("FAIL: Invalid length for 'web/css/main.css'"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); end if; C := Get_Content ("not-included.txt"); if C /= null then Ada.Text_IO.Put_Line ("FAIL: Content was included 'not-included.txt'"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); return; end if; C := Get_Content ("config/test4.xml"); if C = null then Ada.Text_IO.Put_Line ("FAIL: No content 'config/test4.xml'"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); return; end if; if C'Length /= 23 then Ada.Text_IO.Put_Line ("FAIL: Invalid length for 'config/test4.xml'"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); end if; Ada.Text_IO.Put ("PASS: "); for Val of C.all loop if Character'Val (Val) /= ASCII.LF then Ada.Text_IO.Put (Character'Val (Val)); end if; end loop; Ada.Text_IO.New_Line; end Test4;
with DDS.DataReader; with DDS.DataWriter; with Interfaces.C.Extensions; with DDS.DomainParticipant; with DDS.Publisher; with DDS.Subscriber; with DDS.Request_Reply.Untypedcommon; with DDS.Request_Reply.Connext_C_Entity_Params; package DDS.Request_Reply.Connext_C_Requester is use Untypedcommon; use Connext_C_Entity_Params; DEFAULT_MAX_WAIT : constant DDS.Duration_T := DDS.To_Duration_T (1.0); type RTI_Connext_RequesterUntypedImpl is abstract new RTI_Connext_EntityUntypedImpl with null record; type RTI_Connext_RequesterUntypedImpl_Access is access all RTI_Connext_RequesterUntypedImpl; function RTI_Connext_RequesterUntypedImpl_Wait_For_Replies (Self : not null access RTI_Connext_RequesterUntypedImpl; Max_Wait : DDS.Duration_T := DEFAULT_MAX_WAIT; Min_Sample_Count : DDS.Natural := 1; Related_Request_Info : DDS.SampleIdentity_T) return DDS.ReturnCode_T; function RTI_Connext_RequesterUntypedImpl_get_request_datawriter (Self : not null access RTI_Connext_RequesterUntypedImpl) return DDS.DataWriter.Ref_Access is (DDS.DataWriter.Ref_Access (Self.Writer)); -- ========================================================================= -- ========================================================================= -- extern XMQCDllExport -- DDS_DataReader* RTI_Connext_RequesterUntypedImpl_get_request_datareader( -- RTI_Connext_RequesterUntypedImpl * self); function RTI_Connext_RequesterUntypedImpl_Get_Request_Datareader (Self : not null access RTI_Connext_RequesterUntypedImpl) return DDS.DataReader.Ref_Access is (DDS.DataReader.Ref_Access (Self.Reader)); type RTI_Connext_Requester is abstract new RTI_Connext_RequesterUntypedImpl with record null; end record; type RTI_Connext_RequesterParams is record Participant : DDS.DomainParticipant.Ref_Access; Service_Name : DDS.String; Request_Topic_Name : DDS.String; Reply_Topic_Name : DDS.String; Qos_Library_Name : DDS.String; Qos_Profile_Name : DDS.String; Datawriter_Qos : DDS.DataWriterQos; Datareader_Qos : DDS.DataReaderQos; Publisher : DDS.Publisher.Ref_Access; Subscriber : DDS.Subscriber.Ref_Access; end record; function RTI_Connext_Requester_Delete (Self : RTI_Connext_Requester)return DDS.ReturnCode_T; function RTI_Connext_Requester_Wait_For_Replies (Self : RTI_Connext_Requester; Min_Count : DDS.long; Max_Wait : DDS.Duration_T)return DDS.ReturnCode_T; function RTI_Connext_Requester_Wait_For_Replies_For_Related_Request (Self : RTI_Connext_Requester; Min_Count : DDS.long; Max_Wait : DDS.Duration_T; Related_Request_Id : DDS.SampleIdentity_T) return DDS.ReturnCode_T; function RTI_Connext_RequesterParams_To_RTI_Connext_EntityParams (Self : not null access RTI_Connext_RequesterParams; ToParams : out RTI_Connext_EntityParams) return DDS.ReturnCode_T; -- ========================================================================= -- ========================================================================= -- extern XMQCDllExport function RTI_Connext_RequesterUntypedImpl_Create (Params : RTI_Connext_RequesterParams; Request_Type_Name : DDS.String; Reply_Type_Name : DDS.String; reply_size : DDS.Integer) return RTI_Connext_RequesterUntypedImpl_Access; -- RTI_Connext_RequesterUntypedImpl_create( -- const RTI_Connext_RequesterParams * params, -- RegisterTypeFunc _request_type_fnc, -- const char * request_type_name, -- RegisterTypeFunc _reply_type_fnc, -- const char * reply_type_name, -- int reply_size); -- ========================================================================= -- ========================================================================= -- extern XMQCDllExport -- DDS_ReturnCode_t RTI_Connext_RequesterUntypedImpl_delete( -- RTI_Connext_RequesterUntypedImpl* self); -- ========================================================================= -- ========================================================================= -- extern XMQCDllExport -- DDS_ReturnCode_t RTI_Connext_RequesterUntypedImpl_wait_for_replies( -- RTI_Connext_RequesterUntypedImpl * self, -- const struct DDS_Duration_t * max_wait, -- int min_sample_count, -- const struct DDS_SampleIdentity_t* related_request_info); -- ========================================================================= -- ========================================================================= -- extern XMQCDllExport -- DDS_ReturnCode_t RTI_Connext_RequesterUntypedImpl_get_reply_loaned( -- RTI_Connext_RequesterUntypedImpl * self, -- void *** received_data, -- int * data_count, -- DDS_Boolean* is_loan, -- void* dataSeqContiguousBuffer, -- struct DDS_SampleInfoSeq* info_seq, -- DDS_Long data_seq_len, -- DDS_Long data_seq_max_len, -- DDS_Boolean ownership, -- DDS_Long max_samples, -- const struct DDS_SampleIdentity_t* related_request_id, -- RTIBool take); -- ========================================================================= -- ========================================================================= -- extern XMQCDllExport -- DDS_DataWriter* RTI_Connext_RequesterUntypedImpl_get_request_datawriter( -- RTI_Connext_RequesterUntypedImpl * self); end DDS.Request_Reply.Connext_C_Requester;
------------------------------------------------------------------------------ -- Copyright (c) 2011, Natacha Porté -- -- -- -- 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. -- ------------------------------------------------------------------------------ with Ada.Exceptions; with Ada.Strings.Maps.Constants; procedure Natools.Chunked_Strings.Tests.CXA4032 (Report : in out Natools.Tests.Reporter'Class) is package NT renames Natools.Tests; begin NT.Section (Report, "Port of ACATS CXA4032"); declare TC_Null_String : constant String := ""; TC_String_5 : constant String (1 .. 5) := "ABCDE"; TC_Chunked_String : Chunked_String := To_Chunked_String ("Test String"); begin NT.Section (Report, "Procedure Replace_Slice"); declare Name : constant String := "Index_Error raised when Low > Source'Last+1"; begin Replace_Slice (Source => TC_Chunked_String, Low => Length (TC_Chunked_String) + 2, High => Length (TC_Chunked_String), By => TC_String_5); NT.Item (Report, Name, NT.Fail); NT.Info (Report, "No exception has been raised."); NT.Info (Report, "Final value: """ & To_String (TC_Chunked_String) & '"'); exception when Ada.Strings.Index_Error => NT.Item (Report, Name, NT.Success); when Error : others => NT.Item (Report, Name, NT.Fail); NT.Info (Report, "Wrong exception " & Ada.Exceptions.Exception_Name (Error) & " raised instead"); end; declare Name : constant String := "1-character slice replacement"; begin TC_Chunked_String := To_Chunked_String ("Test String"); Replace_Slice (TC_Chunked_String, 5, 5, TC_String_5); Test (Report, Name, TC_Chunked_String, "TestABCDEString"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Prefix replacement"; begin Replace_Slice (TC_Chunked_String, 1, 4, TC_String_5); Test (Report, Name, TC_Chunked_String, "ABCDEABCDEString"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Suffix replacement by empty"; begin Replace_Slice (TC_Chunked_String, 11, Length (TC_Chunked_String), TC_Null_String); Test (Report, Name, TC_Chunked_String, "ABCDEABCDE"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Slice insertion in the middle"; begin Replace_Slice (TC_Chunked_String, Low => 4, High => 1, By => "xxx"); Test (Report, Name, TC_Chunked_String, "ABCxxxDEABCDE"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Slice insertion at the beginning"; begin Replace_Slice (TC_Chunked_String, Low => 1, High => 0, By => "yyy"); Test (Report, Name, TC_Chunked_String, "yyyABCxxxDEABCDE"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Slice insertion at the end"; begin Replace_Slice (TC_Chunked_String, Length (TC_Chunked_String) + 1, Length (TC_Chunked_String), By => "zzz"); Test (Report, Name, TC_Chunked_String, "yyyABCxxxDEABCDEzzz"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; NT.End_Section (Report); NT.Section (Report, "Procedure Insert"); TC_Chunked_String := To_Chunked_String ("Test String"); declare Name : constant String := "Index_Error raised on incorrect Before"; begin Insert (Source => TC_Chunked_String, Before => Length (TC_Chunked_String) + 2, New_Item => TC_String_5); NT.Item (Report, Name, NT.Fail); NT.Info (Report, "No exception has been raised."); NT.Info (Report, "Final value: """ & To_String (TC_Chunked_String) & '"'); exception when Ada.Strings.Index_Error => NT.Item (Report, Name, NT.Success); when Error : others => NT.Item (Report, Name, NT.Fail); NT.Info (Report, "Wrong exception " & Ada.Exceptions.Exception_Name (Error) & " raised instead"); end; declare Name : constant String := "Prefix insertion"; begin Insert (TC_Chunked_String, 1, "**"); Test (Report, Name, TC_Chunked_String, "**Test String"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Suffix insertion"; begin Insert (TC_Chunked_String, Length (TC_Chunked_String) + 1, "**"); Test (Report, Name, TC_Chunked_String, "**Test String**"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Insertion in the middle"; begin Insert (TC_Chunked_String, 8, "---"); Test (Report, Name, TC_Chunked_String, "**Test ---String**"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Empty insertion"; begin Insert (TC_Chunked_String, 3, TC_Null_String); Test (Report, Name, TC_Chunked_String, "**Test ---String**"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; NT.End_Section (Report); NT.Section (Report, "Procedure Overwrite"); declare Name : constant String := "Index_Error raised on incorrect Position"; begin Overwrite (Source => TC_Chunked_String, Position => Length (TC_Chunked_String) + 2, New_Item => TC_String_5); NT.Item (Report, Name, NT.Fail); NT.Info (Report, "No exception has been raised."); NT.Info (Report, "Final value: """ & To_String (TC_Chunked_String) & '"'); exception when Ada.Strings.Index_Error => NT.Item (Report, Name, NT.Success); when Error : others => NT.Item (Report, Name, NT.Fail); NT.Info (Report, "Wrong exception " & Ada.Exceptions.Exception_Name (Error) & " raised instead"); end; declare Name : constant String := "Normal overwrite"; begin TC_Chunked_String := To_Chunked_String ("Test String"); Overwrite (Source => TC_Chunked_String, Position => 1, New_Item => "XXXX"); Test (Report, Name, TC_Chunked_String, "XXXX String"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Overwrite after the end"; begin Overwrite (TC_Chunked_String, Length (TC_Chunked_String) + 1, "**"); Test (Report, Name, TC_Chunked_String, "XXXX String**"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Empty overwrite"; begin Overwrite (TC_Chunked_String, 3, TC_Null_String); Test (Report, Name, TC_Chunked_String, "XXXX String**"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Complete overwrite"; begin Overwrite (TC_Chunked_String, 1, "abcdefghijklmn"); Test (Report, Name, TC_Chunked_String, "abcdefghijklmn"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; NT.End_Section (Report); NT.Section (Report, "Procedure Delete"); declare Name : constant String := "Empty deletion at the end"; begin TC_Chunked_String := To_Chunked_String ("Test String"); Delete (Source => TC_Chunked_String, From => Length (TC_Chunked_String), Through => Length (TC_Chunked_String) - 1); Test (Report, Name, TC_Chunked_String, "Test String"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Empty deletion at the beginning"; begin Delete (TC_Chunked_String, 1, 0); Test (Report, Name, TC_Chunked_String, "Test String"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Prefix deletion"; begin Delete (TC_Chunked_String, 1, 5); Test (Report, Name, TC_Chunked_String, "String"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "1-character range deletion"; begin Delete (TC_Chunked_String, 3, 3); Test (Report, Name, TC_Chunked_String, "Sting"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; NT.End_Section (Report); NT.Section (Report, "Procedure Trim"); declare Name : constant String := "Nothing to trim"; begin TC_Chunked_String := To_Chunked_String ("No Spaces"); Trim (Source => TC_Chunked_String, Side => Ada.Strings.Both); Test (Report, Name, TC_Chunked_String, "No Spaces"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Trim left but not right"; begin TC_Chunked_String := To_Chunked_String (" Leading Spaces "); Trim (TC_Chunked_String, Ada.Strings.Left); Test (Report, Name, TC_Chunked_String, "Leading Spaces "); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Trim right but not left"; begin TC_Chunked_String := To_Chunked_String (" Ending Spaces "); Trim (TC_Chunked_String, Ada.Strings.Right); Test (Report, Name, TC_Chunked_String, " Ending Spaces"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Trim on both sides"; begin TC_Chunked_String := To_Chunked_String (" Spaces on both ends "); Trim (TC_Chunked_String, Ada.Strings.Both); Test (Report, Name, TC_Chunked_String, "Spaces on both ends"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; NT.End_Section (Report); NT.Section (Report, "Procedure Trim (with Character Set parameter)"); declare Name : constant String := "Normal trim"; begin TC_Chunked_String := To_Chunked_String ("lowerCASEletters"); Trim (Source => TC_Chunked_String, Left => Ada.Strings.Maps.Constants.Lower_Set, Right => Ada.Strings.Maps.Constants.Lower_Set); Test (Report, Name, TC_Chunked_String, "CASE"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Nothing to trim"; begin TC_Chunked_String := To_Chunked_String ("lowerCASEletters"); Trim (TC_Chunked_String, Ada.Strings.Maps.Constants.Upper_Set, Ada.Strings.Maps.Constants.Upper_Set); Test (Report, Name, TC_Chunked_String, "lowerCASEletters"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Normal trim"; begin TC_Chunked_String := To_Chunked_String ("012abcdefghGFEDCBA789ab"); Trim (TC_Chunked_String, Ada.Strings.Maps.Constants.Hexadecimal_Digit_Set, Ada.Strings.Maps.Constants.Hexadecimal_Digit_Set); Test (Report, Name, TC_Chunked_String, "ghG"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; NT.End_Section (Report); NT.Section (Report, "Procedure Head"); declare Name : constant String := "Empty head"; begin TC_Chunked_String := To_Chunked_String ("Test String"); Head (Source => TC_Chunked_String, Count => 0, Pad => '*'); Test (Report, Name, TC_Chunked_String, Null_Chunked_String); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Normal Head"; begin TC_Chunked_String := To_Chunked_String ("Test String"); Head (Source => TC_Chunked_String, Count => 4, Pad => '*'); Test (Report, Name, TC_Chunked_String, "Test"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "No-op Head"; begin TC_Chunked_String := To_Chunked_String ("Test String"); Head (Source => TC_Chunked_String, Count => Length (TC_Chunked_String), Pad => '*'); Test (Report, Name, TC_Chunked_String, "Test String"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Head with padding"; begin TC_Chunked_String := To_Chunked_String ("Test String"); Head (Source => TC_Chunked_String, Count => Length (TC_Chunked_String) + 4, Pad => '*'); Test (Report, Name, TC_Chunked_String, "Test String****"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Empty string with padding"; begin TC_Chunked_String := Null_Chunked_String; Head (Source => TC_Chunked_String, Count => Length (TC_Chunked_String) + 3, Pad => '*'); Test (Report, Name, TC_Chunked_String, "***"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; NT.End_Section (Report); NT.Section (Report, "Procedure Tail"); declare Name : constant String := "Empty tail"; begin TC_Chunked_String := To_Chunked_String ("Test String"); Tail (Source => TC_Chunked_String, Count => 0, Pad => '*'); Test (Report, Name, TC_Chunked_String, Null_Chunked_String); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Normal tail"; begin TC_Chunked_String := To_Chunked_String ("Test String"); Tail (Source => TC_Chunked_String, Count => 6, Pad => '*'); Test (Report, Name, TC_Chunked_String, "String"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "No-op tail"; begin TC_Chunked_String := To_Chunked_String ("Test String"); Tail (Source => TC_Chunked_String, Count => Length (TC_Chunked_String), Pad => '*'); Test (Report, Name, TC_Chunked_String, "Test String"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Tail with padding"; begin TC_Chunked_String := To_Chunked_String ("Test String"); Tail (Source => TC_Chunked_String, Count => Length (TC_Chunked_String) + 5, Pad => 'x'); Test (Report, Name, TC_Chunked_String, "xxxxxTest String"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; declare Name : constant String := "Empty string with padding"; begin TC_Chunked_String := Null_Chunked_String; Tail (Source => TC_Chunked_String, Count => Length (TC_Chunked_String) + 3, Pad => 'X'); Test (Report, Name, TC_Chunked_String, "XXX"); exception when Error : others => NT.Report_Exception (Report, Name, Error); end; NT.End_Section (Report); exception when Error : others => NT.Report_Exception (Report, "Preparation", Error); end; NT.End_Section (Report); end Natools.Chunked_Strings.Tests.CXA4032;
------------------------------------------------------------------------------ -- File : GL - IO.ads -- Description : I/O for (Open)GL graphics -- -- This package provides currently: -- -- ****************************************************** -- * INPUT * from a file or a data stream, to a texture * -- ****************************************************** -- -- - TGA image : RGA, RGBA, Grey -- - BMP image : B&W, 16 colours indexed (palette), -- 256 colours indexed -- -- *************************************************** -- * OUTPUT * from the GL active viewport, to a file * -- *************************************************** -- -- - BMP image : screenshot -- - AVI video : video capture -- ------------------------------------------------------------------------------ -- Change log: -- -- 19 - Jan - 2010 (GdM) : using workaround to the slow attribute I/O issue (GNAT, OA); -- buffered input; improvements on BMP -- -- 26 - May - 2008 (GdM) : added support for TGA images with RLE encoding -- -- 27 - Jan - 2008 (RK) : added 'Image' record and a function to get greyscale pixels from an Image. -- -- 10 - May - 2007 (GdM) : screenshot and video capture -- -- 13 - Oct - 2006 (GdM) : new blending_hint out parameter, indicates possible -- blending/transparency -- -- 30 - Apr - 2006 (GdM) : - added multi - format loaders -- - dimensions not power of two allowed, but -- discouraged in the docs. -- - > removed TGA_BAD_DIMENSION with Ada.Streams.Stream_IO; with Ada.Unchecked_Deallocation; package GL.IO is File_Not_Found : exception; type Supported_format is (BMP, TGA); type Byte_Array is array (Integer range <>) of aliased GL.Ubyte; type Byte_Array_Ptr is access all Byte_Array; procedure Free is new Ada.Unchecked_Deallocation (Byte_Array, Byte_Array_Ptr); type Byte_Grid is array (Integer range <>, Integer range <>) of aliased GL.Ubyte; type Image is record blending_hint : Boolean; -- has the image blending / transparency /alpha ? tex_Format : GL.TexFormatEnm; tex_pixel_Format : GL.TexPixelFormatEnm; size : Integer; Width, Height : Integer; Data : Byte_Array_Ptr; end record; function To_TGA_Image (Filename : String) return Image; function To_TGA_Image (S : Ada.Streams.Stream_IO.Stream_Access) return Image; function to_greyscale_Pixels (the_Image : Image) return Byte_Grid; -- Multi - format loader: procedure Load (name : String; -- file name format : Supported_format; -- expected file format ID : Integer; -- ID is the texture identifier to bind to blending_hint : out Boolean); -- has blending / transparency /alpha ? procedure Load (s : Ada.Streams.Stream_IO.Stream_Access; -- input data stream (e.g. UnZip.Streams) format : Supported_format; -- expected file format ID : Integer; -- ID is the texture identifier to bind to blending_hint : out Boolean); -- has blending / transparency /alpha ? -- Loaders specific to different formats: ---------------------- -- BMP format Input -- ---------------------- procedure Load_BMP (Name : String; -- File name Id : Integer; -- Id is the texture identifier to bind to blending_hint : out Boolean); -- has the image blending / transparency /alpha ? procedure Load_BMP (S : Ada.Streams.Stream_IO.Stream_Access; -- Input data stream Id : Integer; -- Id is the texture identifier to bind to blending_hint : out Boolean); -- has the image blending / transparency /alpha ? Unsupported_BMP_format, Not_BMP_format, BMP_Unsupported_Bits_per_Pixel, Unsupported_compression : exception; ---------------------- -- TGA format Input -- ---------------------- procedure Load_TGA (Name : String; -- File name Id : Integer; -- Id is the texture identifier to bind to blending_hint : out Boolean); -- has the image blending / transparency /alpha ? procedure Load_TGA (S : Ada.Streams.Stream_IO.Stream_Access; -- Input data stream Id : Integer; -- Id is the texture identifier to bind to blending_hint : out Boolean); -- has the image blending / transparency /alpha ? TGA_Unsupported_Image_Type : exception; -- color mapped or compressed image TGA_Unsupported_Bits_per_pixel : exception; -- image bits is not 8, 24 or 32 TGA_Bad_Data : exception; -- image data could not be loaded --------------------------------------------------------------------------- -- Image ("screenshot") of the current, active viewport (RGB BMP format) -- --------------------------------------------------------------------------- procedure Screenshot (Name : String); -------------------------------------------------- -- Video capture (RGB uncompressed, AVI format) -- -------------------------------------------------- procedure Start_Capture (AVI_Name : String; frame_rate : Positive); procedure Capture_Frame; -- captures the current, active viewport. procedure Stop_Capture; -------------------------------------------------------------------------- -- An object - oriented stream buffering, initially for reading images to -- -- the GL system, but that may be useful elsewhere, hence its presence -- -- in this package's specification -- -------------------------------------------------------------------------- -- type Input_buffer is private; procedure Attach_Stream (b : out Input_buffer; stm : Ada.Streams.Stream_IO.Stream_Access); procedure Get_Byte (b : in out Input_buffer; Return_Byte : out Ubyte); pragma Inline (Get_Byte); private type Input_buffer is record data : Byte_Array (1 .. 1024); stm : Ada.Streams.Stream_IO.Stream_Access; InBufIdx : Positive; -- Points to next char in buffer to be read MaxInBufIdx : Natural; -- Count of valid chars in input buffer InputEoF : Boolean; -- End of file indicator end record; end GL.IO;
package Giza.Bitmap_Fonts.FreeSerifBoldItalic24pt7b is Font : constant Giza.Font.Ref_Const; private FreeSerifBoldItalic24pt7bBitmaps : aliased constant Font_Bitmap := ( 16#00#, 16#3C#, 16#00#, 16#FC#, 16#01#, 16#F8#, 16#07#, 16#F0#, 16#0F#, 16#E0#, 16#1F#, 16#C0#, 16#3F#, 16#00#, 16#7E#, 16#00#, 16#F8#, 16#01#, 16#F0#, 16#07#, 16#C0#, 16#0F#, 16#80#, 16#1E#, 16#00#, 16#3C#, 16#00#, 16#70#, 16#00#, 16#E0#, 16#01#, 16#C0#, 16#03#, 16#00#, 16#0E#, 16#00#, 16#18#, 16#00#, 16#30#, 16#00#, 16#40#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F0#, 16#03#, 16#F0#, 16#0F#, 16#F0#, 16#1F#, 16#E0#, 16#3F#, 16#C0#, 16#3F#, 16#00#, 16#3C#, 16#00#, 16#1C#, 16#01#, 16#C7#, 16#C0#, 16#7D#, 16#F8#, 16#1F#, 16#BF#, 16#03#, 16#F7#, 16#C0#, 16#7C#, 16#F8#, 16#0F#, 16#9E#, 16#01#, 16#E3#, 16#C0#, 16#3C#, 16#70#, 16#07#, 16#0E#, 16#00#, 16#E3#, 16#80#, 16#38#, 16#70#, 16#07#, 16#0C#, 16#00#, 16#C0#, 16#00#, 16#03#, 16#C1#, 16#E0#, 16#00#, 16#70#, 16#38#, 16#00#, 16#1E#, 16#0F#, 16#00#, 16#03#, 16#C1#, 16#E0#, 16#00#, 16#70#, 16#38#, 16#00#, 16#1E#, 16#0F#, 16#00#, 16#03#, 16#81#, 16#C0#, 16#00#, 16#F0#, 16#78#, 16#00#, 16#1E#, 16#0F#, 16#00#, 16#07#, 16#83#, 16#C0#, 16#1F#, 16#FF#, 16#FF#, 16#83#, 16#FF#, 16#FF#, 16#F0#, 16#7F#, 16#FF#, 16#FC#, 16#00#, 16#E0#, 16#70#, 16#00#, 16#3C#, 16#1E#, 16#00#, 16#07#, 16#83#, 16#C0#, 16#00#, 16#E0#, 16#70#, 16#00#, 16#3C#, 16#1E#, 16#00#, 16#07#, 16#83#, 16#C0#, 16#00#, 16#E0#, 16#70#, 16#07#, 16#FF#, 16#FF#, 16#E0#, 16#FF#, 16#FF#, 16#FC#, 16#1F#, 16#FF#, 16#FF#, 16#00#, 16#38#, 16#1C#, 16#00#, 16#0F#, 16#07#, 16#80#, 16#01#, 16#E0#, 16#F0#, 16#00#, 16#38#, 16#1C#, 16#00#, 16#0F#, 16#07#, 16#80#, 16#01#, 16#C0#, 16#E0#, 16#00#, 16#78#, 16#3C#, 16#00#, 16#0F#, 16#07#, 16#80#, 16#01#, 16#C0#, 16#E0#, 16#00#, 16#78#, 16#3C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E0#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#1F#, 16#E0#, 16#00#, 16#7F#, 16#F8#, 16#01#, 16#F1#, 16#9E#, 16#01#, 16#C1#, 16#8F#, 16#03#, 16#83#, 16#8F#, 16#03#, 16#83#, 16#06#, 16#07#, 16#83#, 16#06#, 16#07#, 16#83#, 16#06#, 16#07#, 16#C7#, 16#04#, 16#07#, 16#E6#, 16#04#, 16#07#, 16#FE#, 16#00#, 16#03#, 16#FE#, 16#00#, 16#03#, 16#FF#, 16#00#, 16#01#, 16#FF#, 16#80#, 16#00#, 16#FF#, 16#C0#, 16#00#, 16#7F#, 16#E0#, 16#00#, 16#1F#, 16#E0#, 16#00#, 16#1F#, 16#F0#, 16#00#, 16#1F#, 16#F0#, 16#00#, 16#3B#, 16#F8#, 16#20#, 16#31#, 16#F8#, 16#20#, 16#30#, 16#F8#, 16#60#, 16#70#, 16#F8#, 16#60#, 16#60#, 16#F8#, 16#60#, 16#60#, 16#F8#, 16#F0#, 16#60#, 16#F0#, 16#F0#, 16#C1#, 16#E0#, 16#78#, 16#C3#, 16#E0#, 16#3C#, 16#C7#, 16#C0#, 16#0F#, 16#FF#, 16#00#, 16#03#, 16#FC#, 16#00#, 16#01#, 16#80#, 16#00#, 16#01#, 16#80#, 16#00#, 16#03#, 16#80#, 16#00#, 16#03#, 16#00#, 16#00#, 16#03#, 16#00#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#70#, 16#00#, 16#FF#, 16#80#, 16#1C#, 16#00#, 16#3F#, 16#38#, 16#1F#, 16#00#, 16#0F#, 16#C7#, 16#FF#, 16#E0#, 16#03#, 16#F0#, 16#3F#, 16#B8#, 16#00#, 16#7E#, 16#04#, 16#07#, 16#00#, 16#1F#, 16#80#, 16#81#, 16#C0#, 16#03#, 16#F0#, 16#10#, 16#30#, 16#00#, 16#FC#, 16#02#, 16#0E#, 16#00#, 16#1F#, 16#80#, 16#81#, 16#80#, 16#03#, 16#F0#, 16#10#, 16#70#, 16#00#, 16#7C#, 16#06#, 16#1C#, 16#00#, 16#0F#, 16#80#, 16#83#, 16#00#, 16#01#, 16#F0#, 16#30#, 16#E0#, 16#00#, 16#1E#, 16#0C#, 16#18#, 16#07#, 16#C3#, 16#E3#, 16#07#, 16#03#, 16#FC#, 16#3F#, 16#C0#, 16#C0#, 16#FC#, 16#43#, 16#E0#, 16#38#, 16#3E#, 16#0C#, 16#00#, 16#0E#, 16#0F#, 16#C0#, 16#80#, 16#01#, 16#83#, 16#F0#, 16#10#, 16#00#, 16#70#, 16#FC#, 16#02#, 16#00#, 16#0C#, 16#1F#, 16#80#, 16#40#, 16#03#, 16#83#, 16#E0#, 16#08#, 16#00#, 16#60#, 16#FC#, 16#02#, 16#00#, 16#18#, 16#1F#, 16#80#, 16#40#, 16#07#, 16#03#, 16#E0#, 16#10#, 16#00#, 16#C0#, 16#7C#, 16#02#, 16#00#, 16#38#, 16#0F#, 16#80#, 16#C0#, 16#06#, 16#01#, 16#F0#, 16#30#, 16#01#, 16#80#, 16#1F#, 16#0C#, 16#00#, 16#30#, 16#01#, 16#FF#, 16#00#, 16#0C#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#00#, 16#FF#, 16#80#, 16#00#, 16#01#, 16#F1#, 16#E0#, 16#00#, 16#00#, 16#F0#, 16#78#, 16#00#, 16#00#, 16#F0#, 16#3C#, 16#00#, 16#00#, 16#78#, 16#1E#, 16#00#, 16#00#, 16#7C#, 16#0F#, 16#00#, 16#00#, 16#3E#, 16#0F#, 16#80#, 16#00#, 16#1F#, 16#07#, 16#80#, 16#00#, 16#0F#, 16#87#, 16#80#, 16#00#, 16#07#, 16#C7#, 16#80#, 16#00#, 16#03#, 16#FF#, 16#00#, 16#00#, 16#01#, 16#FE#, 16#00#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#01#, 16#FF#, 16#07#, 16#FE#, 16#03#, 16#CF#, 16#C0#, 16#FE#, 16#03#, 16#C7#, 16#E0#, 16#3C#, 16#07#, 16#C3#, 16#F0#, 16#1C#, 16#07#, 16#C0#, 16#FC#, 16#0C#, 16#03#, 16#C0#, 16#7E#, 16#0E#, 16#03#, 16#E0#, 16#3F#, 16#0E#, 16#01#, 16#F0#, 16#1F#, 16#C6#, 16#01#, 16#F8#, 16#07#, 16#F6#, 16#00#, 16#FC#, 16#03#, 16#FF#, 16#00#, 16#7E#, 16#00#, 16#FF#, 16#00#, 16#3F#, 16#80#, 16#7F#, 16#80#, 16#1F#, 16#C0#, 16#1F#, 16#C0#, 16#07#, 16#F0#, 16#0F#, 16#F0#, 16#13#, 16#FE#, 16#0F#, 16#FE#, 16#18#, 16#FF#, 16#FE#, 16#FF#, 16#F8#, 16#3F#, 16#FE#, 16#3F#, 16#F8#, 16#07#, 16#F8#, 16#03#, 16#F0#, 16#00#, 16#1C#, 16#7D#, 16#FB#, 16#F7#, 16#CF#, 16#9E#, 16#3C#, 16#70#, 16#E3#, 16#87#, 16#0C#, 16#00#, 16#00#, 16#04#, 16#00#, 16#70#, 16#03#, 16#80#, 16#1C#, 16#00#, 16#E0#, 16#07#, 16#00#, 16#3C#, 16#01#, 16#E0#, 16#0F#, 16#00#, 16#3C#, 16#01#, 16#E0#, 16#0F#, 16#80#, 16#3C#, 16#00#, 16#F0#, 16#07#, 16#C0#, 16#1E#, 16#00#, 16#78#, 16#03#, 16#E0#, 16#0F#, 16#80#, 16#3E#, 16#00#, 16#F0#, 16#03#, 16#C0#, 16#0F#, 16#00#, 16#3C#, 16#00#, 16#F0#, 16#03#, 16#C0#, 16#0F#, 16#00#, 16#3C#, 16#00#, 16#70#, 16#01#, 16#C0#, 16#07#, 16#00#, 16#1C#, 16#00#, 16#30#, 16#00#, 16#E0#, 16#01#, 16#80#, 16#06#, 16#00#, 16#0C#, 16#00#, 16#30#, 16#00#, 16#60#, 16#01#, 16#80#, 16#00#, 16#00#, 16#01#, 16#00#, 16#06#, 16#00#, 16#08#, 16#00#, 16#30#, 16#00#, 16#40#, 16#01#, 16#80#, 16#06#, 16#00#, 16#1C#, 16#00#, 16#30#, 16#00#, 16#E0#, 16#03#, 16#80#, 16#0E#, 16#00#, 16#38#, 16#00#, 16#F0#, 16#03#, 16#C0#, 16#0F#, 16#00#, 16#3C#, 16#00#, 16#F0#, 16#03#, 16#C0#, 16#0F#, 16#00#, 16#7C#, 16#01#, 16#F0#, 16#07#, 16#C0#, 16#1E#, 16#00#, 16#78#, 16#03#, 16#E0#, 16#0F#, 16#80#, 16#3C#, 16#01#, 16#F0#, 16#07#, 16#80#, 16#1E#, 16#00#, 16#F0#, 16#03#, 16#80#, 16#1E#, 16#00#, 16#F0#, 16#03#, 16#80#, 16#1C#, 16#00#, 16#E0#, 16#06#, 16#00#, 16#30#, 16#00#, 16#80#, 16#00#, 16#00#, 16#E0#, 16#00#, 16#3E#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#F8#, 16#07#, 16#0E#, 16#1D#, 16#F1#, 16#C7#, 16#FF#, 16#11#, 16#FF#, 16#E2#, 16#3F#, 16#7E#, 16#4F#, 16#C0#, 16#3E#, 16#00#, 16#07#, 16#C0#, 16#3F#, 16#27#, 16#EF#, 16#C4#, 16#7F#, 16#F8#, 16#8F#, 16#FE#, 16#38#, 16#FB#, 16#87#, 16#0E#, 16#01#, 16#F0#, 16#00#, 16#3E#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#70#, 16#00#, 16#00#, 16#78#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#07#, 16#80#, 16#00#, 16#1E#, 16#00#, 16#00#, 16#78#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#07#, 16#80#, 16#00#, 16#1E#, 16#00#, 16#00#, 16#78#, 16#03#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FC#, 16#01#, 16#E0#, 16#00#, 16#07#, 16#80#, 16#00#, 16#1E#, 16#00#, 16#00#, 16#78#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#07#, 16#80#, 16#00#, 16#1E#, 16#00#, 16#00#, 16#78#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#07#, 16#80#, 16#00#, 16#0F#, 16#07#, 16#E1#, 16#FC#, 16#7F#, 16#1F#, 16#C3#, 16#F0#, 16#7C#, 16#0E#, 16#03#, 16#80#, 16#C0#, 16#60#, 16#30#, 16#18#, 16#1C#, 16#04#, 16#00#, 16#7F#, 16#F7#, 16#FF#, 16#7F#, 16#EF#, 16#FE#, 16#FF#, 16#E0#, 16#3C#, 16#7E#, 16#FF#, 16#FF#, 16#FF#, 16#7E#, 16#3C#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#78#, 16#00#, 16#0F#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#78#, 16#00#, 16#1E#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#F0#, 16#00#, 16#1E#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#F0#, 16#00#, 16#1E#, 16#00#, 16#07#, 16#80#, 16#00#, 16#F0#, 16#00#, 16#3C#, 16#00#, 16#07#, 16#80#, 16#01#, 16#E0#, 16#00#, 16#3C#, 16#00#, 16#0F#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#7C#, 16#00#, 16#0F#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#78#, 16#00#, 16#0F#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#78#, 16#00#, 16#1E#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#F8#, 16#00#, 16#1E#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#F0#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#80#, 16#00#, 16#E3#, 16#80#, 16#0F#, 16#07#, 16#00#, 16#7C#, 16#1C#, 16#03#, 16#E0#, 16#78#, 16#0F#, 16#81#, 16#E0#, 16#7C#, 16#07#, 16#83#, 16#F0#, 16#1F#, 16#0F#, 16#C0#, 16#FC#, 16#7E#, 16#03#, 16#F1#, 16#F8#, 16#0F#, 16#CF#, 16#E0#, 16#3F#, 16#3F#, 16#00#, 16#FD#, 16#FC#, 16#07#, 16#F7#, 16#F0#, 16#1F#, 16#DF#, 16#C0#, 16#7F#, 16#7E#, 16#01#, 16#FB#, 16#F8#, 16#0F#, 16#EF#, 16#E0#, 16#3F#, 16#BF#, 16#80#, 16#FE#, 16#FC#, 16#03#, 16#F3#, 16#F0#, 16#1F#, 16#CF#, 16#C0#, 16#7F#, 16#3F#, 16#01#, 16#F8#, 16#FC#, 16#07#, 16#E3#, 16#E0#, 16#3F#, 16#0F#, 16#80#, 16#FC#, 16#1E#, 16#07#, 16#E0#, 16#78#, 16#1F#, 16#00#, 16#E0#, 16#78#, 16#03#, 16#83#, 16#C0#, 16#07#, 16#1E#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#70#, 16#01#, 16#FE#, 16#01#, 16#FF#, 16#E0#, 16#00#, 16#FE#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#FC#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#FC#, 16#00#, 16#1F#, 16#80#, 16#01#, 16#F8#, 16#00#, 16#1F#, 16#80#, 16#03#, 16#F0#, 16#00#, 16#3F#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#3E#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#7E#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#FC#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#FC#, 16#00#, 16#0F#, 16#80#, 16#01#, 16#F8#, 16#00#, 16#1F#, 16#80#, 16#01#, 16#F8#, 16#00#, 16#3F#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#3F#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#7F#, 16#00#, 16#1F#, 16#F8#, 16#0F#, 16#FF#, 16#F0#, 16#00#, 16#0F#, 16#80#, 16#01#, 16#FF#, 16#80#, 16#0F#, 16#FF#, 16#00#, 16#7F#, 16#FE#, 16#03#, 16#83#, 16#F8#, 16#0C#, 16#07#, 16#F0#, 16#60#, 16#1F#, 16#C3#, 16#00#, 16#3F#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#3E#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#3F#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#1E#, 16#00#, 16#00#, 16#F0#, 16#00#, 16#07#, 16#80#, 16#00#, 16#3C#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#0E#, 16#00#, 16#00#, 16#70#, 16#06#, 16#03#, 16#80#, 16#10#, 16#1C#, 16#00#, 16#C0#, 16#E0#, 16#06#, 16#03#, 16#FF#, 16#F8#, 16#3F#, 16#FF#, 16#E1#, 16#FF#, 16#FF#, 16#0F#, 16#FF#, 16#FC#, 16#3F#, 16#FF#, 16#E0#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#FF#, 16#C0#, 16#0F#, 16#FF#, 16#80#, 16#60#, 16#FE#, 16#03#, 16#01#, 16#FC#, 16#08#, 16#03#, 16#F0#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#3F#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#FC#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#3E#, 16#00#, 16#07#, 16#F8#, 16#00#, 16#7F#, 16#F0#, 16#00#, 16#7F#, 16#E0#, 16#00#, 16#3F#, 16#C0#, 16#00#, 16#7F#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#3F#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#0F#, 16#80#, 16#00#, 16#3C#, 16#1C#, 16#01#, 16#F0#, 16#F8#, 16#07#, 16#83#, 16#F0#, 16#3C#, 16#0F#, 16#E1#, 16#E0#, 16#1F#, 16#FE#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#07#, 16#00#, 16#00#, 16#07#, 16#80#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#07#, 16#F8#, 16#00#, 16#07#, 16#FC#, 16#00#, 16#06#, 16#FC#, 16#00#, 16#06#, 16#7E#, 16#00#, 16#06#, 16#3F#, 16#00#, 16#06#, 16#3F#, 16#00#, 16#06#, 16#1F#, 16#80#, 16#06#, 16#0F#, 16#C0#, 16#06#, 16#07#, 16#E0#, 16#03#, 16#07#, 16#E0#, 16#03#, 16#03#, 16#F0#, 16#03#, 16#01#, 16#F8#, 16#03#, 16#01#, 16#FC#, 16#03#, 16#00#, 16#FC#, 16#03#, 16#00#, 16#7E#, 16#03#, 16#FF#, 16#FF#, 16#E1#, 16#FF#, 16#FF#, 16#F0#, 16#FF#, 16#FF#, 16#F0#, 16#FF#, 16#FF#, 16#F8#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#3F#, 16#FE#, 16#00#, 16#3F#, 16#FE#, 16#00#, 16#7F#, 16#FE#, 16#00#, 16#7F#, 16#FC#, 16#00#, 16#FF#, 16#FC#, 16#00#, 16#C0#, 16#00#, 16#01#, 16#80#, 16#00#, 16#01#, 16#80#, 16#00#, 16#03#, 16#00#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#03#, 16#FE#, 16#00#, 16#07#, 16#FF#, 16#00#, 16#07#, 16#FF#, 16#80#, 16#0F#, 16#FF#, 16#C0#, 16#00#, 16#FF#, 16#E0#, 16#00#, 16#1F#, 16#E0#, 16#00#, 16#0F#, 16#F0#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#03#, 16#C0#, 16#78#, 16#03#, 16#C0#, 16#FC#, 16#07#, 16#80#, 16#FC#, 16#0F#, 16#00#, 16#FE#, 16#1E#, 16#00#, 16#7F#, 16#F8#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#0E#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#0F#, 16#80#, 16#00#, 16#7E#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#3F#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#FE#, 16#00#, 16#01#, 16#FF#, 16#F0#, 16#07#, 16#FF#, 16#F0#, 16#0F#, 16#E1#, 16#F0#, 16#3F#, 16#81#, 16#F0#, 16#7F#, 16#03#, 16#F0#, 16#FC#, 16#07#, 16#E3#, 16#F8#, 16#0F#, 16#C7#, 16#F0#, 16#1F#, 16#8F#, 16#C0#, 16#7F#, 16#1F#, 16#80#, 16#FE#, 16#3F#, 16#01#, 16#FC#, 16#7C#, 16#03#, 16#F0#, 16#F8#, 16#0F#, 16#E1#, 16#F0#, 16#1F#, 16#C1#, 16#E0#, 16#3F#, 16#03#, 16#C0#, 16#FC#, 16#07#, 16#81#, 16#F0#, 16#07#, 16#87#, 16#C0#, 16#07#, 16#FF#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#0F#, 16#FF#, 16#FC#, 16#1F#, 16#FF#, 16#F8#, 16#3F#, 16#FF#, 16#E0#, 16#FF#, 16#FF#, 16#C1#, 16#FF#, 16#FF#, 16#07#, 16#00#, 16#1C#, 16#08#, 16#00#, 16#78#, 16#30#, 16#01#, 16#E0#, 16#40#, 16#03#, 16#C0#, 16#00#, 16#0F#, 16#00#, 16#00#, 16#1C#, 16#00#, 16#00#, 16#78#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#0F#, 16#00#, 16#00#, 16#1C#, 16#00#, 16#00#, 16#78#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#0F#, 16#00#, 16#00#, 16#1C#, 16#00#, 16#00#, 16#78#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#0F#, 16#00#, 16#00#, 16#1E#, 16#00#, 16#00#, 16#78#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#0F#, 16#00#, 16#00#, 16#1E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1F#, 16#00#, 16#03#, 16#FE#, 16#00#, 16#3C#, 16#78#, 16#03#, 16#C1#, 16#E0#, 16#3C#, 16#07#, 16#81#, 16#E0#, 16#3C#, 16#1F#, 16#01#, 16#E0#, 16#F8#, 16#0F#, 16#07#, 16#C0#, 16#78#, 16#3F#, 16#03#, 16#C1#, 16#F8#, 16#3C#, 16#0F#, 16#E1#, 16#E0#, 16#3F#, 16#9E#, 16#01#, 16#FF#, 16#C0#, 16#07#, 16#FC#, 16#00#, 16#3F#, 16#C0#, 16#00#, 16#FF#, 16#00#, 16#1F#, 16#FC#, 16#03#, 16#CF#, 16#F0#, 16#3C#, 16#3F#, 16#83#, 16#C0#, 16#FC#, 16#3C#, 16#03#, 16#F1#, 16#E0#, 16#1F#, 16#9E#, 16#00#, 16#7C#, 16#F0#, 16#03#, 16#E7#, 16#80#, 16#1F#, 16#3C#, 16#00#, 16#F9#, 16#E0#, 16#07#, 16#87#, 16#00#, 16#3C#, 16#3C#, 16#03#, 16#C0#, 16#F0#, 16#3C#, 16#03#, 16#C3#, 16#C0#, 16#07#, 16#F0#, 16#00#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#FF#, 16#E0#, 16#03#, 16#F1#, 16#E0#, 16#0F#, 16#C1#, 16#C0#, 16#3F#, 16#03#, 16#C0#, 16#FE#, 16#07#, 16#81#, 16#F8#, 16#0F#, 16#87#, 16#F0#, 16#1F#, 16#0F#, 16#C0#, 16#3E#, 16#3F#, 16#80#, 16#FC#, 16#7F#, 16#01#, 16#F8#, 16#FC#, 16#03#, 16#F1#, 16#F8#, 16#07#, 16#E3#, 16#F0#, 16#1F#, 16#C7#, 16#E0#, 16#3F#, 16#8F#, 16#C0#, 16#7E#, 16#0F#, 16#81#, 16#FC#, 16#1F#, 16#03#, 16#F8#, 16#1F#, 16#0F#, 16#E0#, 16#1F#, 16#FF#, 16#C0#, 16#1F#, 16#FF#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#7E#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#7C#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#1F#, 16#00#, 16#00#, 16#E0#, 16#00#, 16#00#, 16#01#, 16#E0#, 16#1F#, 16#81#, 16#FE#, 16#0F#, 16#F0#, 16#7F#, 16#81#, 16#F8#, 16#07#, 16#80#, 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#07#, 16#80#, 16#7E#, 16#07#, 16#F8#, 16#3F#, 16#C1#, 16#FE#, 16#07#, 16#E0#, 16#1E#, 16#00#, 16#00#, 16#78#, 16#01#, 16#F8#, 16#07#, 16#F8#, 16#0F#, 16#F0#, 16#1F#, 16#E0#, 16#1F#, 16#80#, 16#1E#, 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#07#, 16#80#, 16#1F#, 16#80#, 16#3F#, 16#80#, 16#7F#, 16#00#, 16#FE#, 16#00#, 16#FC#, 16#00#, 16#F8#, 16#00#, 16#E0#, 16#01#, 16#C0#, 16#07#, 16#00#, 16#0C#, 16#00#, 16#30#, 16#01#, 16#C0#, 16#0E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#00#, 16#00#, 16#1F#, 16#00#, 16#00#, 16#7F#, 16#00#, 16#03#, 16#FF#, 16#00#, 16#0F#, 16#FC#, 16#00#, 16#3F#, 16#F0#, 16#01#, 16#FF#, 16#C0#, 16#07#, 16#FE#, 16#00#, 16#1F#, 16#F8#, 16#00#, 16#7F#, 16#E0#, 16#00#, 16#FF#, 16#80#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#FF#, 16#00#, 16#00#, 16#FF#, 16#E0#, 16#00#, 16#1F#, 16#F8#, 16#00#, 16#07#, 16#FE#, 16#00#, 16#01#, 16#FF#, 16#C0#, 16#00#, 16#7F#, 16#F0#, 16#00#, 16#0F#, 16#FC#, 16#00#, 16#03#, 16#FF#, 16#00#, 16#00#, 16#FF#, 16#00#, 16#00#, 16#1F#, 16#00#, 16#00#, 16#07#, 16#00#, 16#00#, 16#01#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 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#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#80#, 16#00#, 16#00#, 16#E0#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#00#, 16#FF#, 16#00#, 16#00#, 16#FF#, 16#C0#, 16#00#, 16#3F#, 16#F0#, 16#00#, 16#0F#, 16#FE#, 16#00#, 16#03#, 16#FF#, 16#80#, 16#00#, 16#7F#, 16#E0#, 16#00#, 16#1F#, 16#F8#, 16#00#, 16#07#, 16#FF#, 16#00#, 16#00#, 16#FF#, 16#00#, 16#00#, 16#3F#, 16#00#, 16#00#, 16#FF#, 16#00#, 16#03#, 16#FF#, 16#00#, 16#1F#, 16#FC#, 16#00#, 16#7F#, 16#E0#, 16#01#, 16#FF#, 16#80#, 16#0F#, 16#FE#, 16#00#, 16#3F#, 16#F0#, 16#00#, 16#FF#, 16#C0#, 16#00#, 16#FF#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#00#, 16#E0#, 16#00#, 16#00#, 16#80#, 16#00#, 16#00#, 16#01#, 16#F8#, 16#01#, 16#FF#, 16#80#, 16#F1#, 16#F0#, 16#38#, 16#3E#, 16#1E#, 16#0F#, 16#C7#, 16#C3#, 16#F1#, 16#F0#, 16#FC#, 16#7C#, 16#3F#, 16#0E#, 16#0F#, 16#C0#, 16#07#, 16#F0#, 16#01#, 16#F8#, 16#00#, 16#FC#, 16#00#, 16#3F#, 16#00#, 16#1F#, 16#00#, 16#07#, 16#80#, 16#03#, 16#C0#, 16#01#, 16#E0#, 16#00#, 16#60#, 16#00#, 16#30#, 16#00#, 16#0C#, 16#00#, 16#06#, 16#00#, 16#01#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#C0#, 16#01#, 16#F8#, 16#00#, 16#FF#, 16#00#, 16#3F#, 16#C0#, 16#0F#, 16#F0#, 16#01#, 16#F8#, 16#00#, 16#3C#, 16#00#, 16#00#, 16#00#, 16#07#, 16#FC#, 16#00#, 16#00#, 16#1F#, 16#FF#, 16#C0#, 16#00#, 16#3F#, 16#01#, 16#F0#, 16#00#, 16#3C#, 16#00#, 16#1E#, 16#00#, 16#7C#, 16#00#, 16#03#, 16#80#, 16#7C#, 16#00#, 16#00#, 16#E0#, 16#7C#, 16#00#, 16#00#, 16#38#, 16#3C#, 16#00#, 16#F0#, 16#4C#, 16#3E#, 16#00#, 16#FD#, 16#E7#, 16#1E#, 16#00#, 16#F3#, 16#F1#, 16#9F#, 16#00#, 16#F1#, 16#F0#, 16#EF#, 16#80#, 16#F0#, 16#78#, 16#3F#, 16#80#, 16#F0#, 16#3C#, 16#1F#, 16#C0#, 16#78#, 16#1E#, 16#0F#, 16#E0#, 16#78#, 16#1E#, 16#07#, 16#F0#, 16#3C#, 16#0F#, 16#03#, 16#F8#, 16#3E#, 16#07#, 16#81#, 16#FC#, 16#1E#, 16#07#, 16#81#, 16#FE#, 16#0F#, 16#03#, 16#C0#, 16#DF#, 16#07#, 16#83#, 16#C0#, 16#6F#, 16#83#, 16#C3#, 16#E0#, 16#63#, 16#E1#, 16#F3#, 16#F0#, 16#71#, 16#F0#, 16#7E#, 16#78#, 16#70#, 16#F8#, 16#1E#, 16#3F#, 16#F0#, 16#3E#, 16#00#, 16#07#, 16#E0#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#00#, 16#00#, 16#7C#, 16#00#, 16#00#, 16#00#, 16#1F#, 16#00#, 16#03#, 16#80#, 16#03#, 16#F0#, 16#07#, 16#C0#, 16#00#, 16#7F#, 16#FF#, 16#80#, 16#00#, 16#07#, 16#FC#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#00#, 16#00#, 16#00#, 16#1C#, 16#00#, 16#00#, 16#00#, 16#38#, 16#00#, 16#00#, 16#00#, 16#F0#, 16#00#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#00#, 16#FF#, 16#00#, 16#00#, 16#03#, 16#7E#, 16#00#, 16#00#, 16#06#, 16#FC#, 16#00#, 16#00#, 16#19#, 16#FC#, 16#00#, 16#00#, 16#63#, 16#F8#, 16#00#, 16#00#, 16#C7#, 16#F0#, 16#00#, 16#03#, 16#0F#, 16#E0#, 16#00#, 16#04#, 16#0F#, 16#C0#, 16#00#, 16#18#, 16#1F#, 16#C0#, 16#00#, 16#60#, 16#3F#, 16#80#, 16#00#, 16#C0#, 16#7F#, 16#00#, 16#03#, 16#00#, 16#FE#, 16#00#, 16#0F#, 16#FF#, 16#FC#, 16#00#, 16#1F#, 16#FF#, 16#F8#, 16#00#, 16#60#, 16#03#, 16#F8#, 16#00#, 16#C0#, 16#07#, 16#F0#, 16#03#, 16#00#, 16#0F#, 16#E0#, 16#0E#, 16#00#, 16#1F#, 16#C0#, 16#18#, 16#00#, 16#3F#, 16#80#, 16#70#, 16#00#, 16#7F#, 16#01#, 16#C0#, 16#00#, 16#FE#, 16#03#, 16#80#, 16#01#, 16#FE#, 16#1F#, 16#80#, 16#07#, 16#FE#, 16#7F#, 16#C0#, 16#3F#, 16#FF#, 16#01#, 16#FF#, 16#FF#, 16#80#, 16#00#, 16#FF#, 16#FF#, 16#E0#, 16#00#, 16#FE#, 16#1F#, 16#E0#, 16#01#, 16#FC#, 16#1F#, 16#E0#, 16#03#, 16#F8#, 16#1F#, 16#E0#, 16#0F#, 16#E0#, 16#3F#, 16#C0#, 16#1F#, 16#C0#, 16#7F#, 16#80#, 16#3F#, 16#80#, 16#FF#, 16#00#, 16#7F#, 16#01#, 16#FE#, 16#01#, 16#FC#, 16#03#, 16#F8#, 16#03#, 16#F8#, 16#0F#, 16#F0#, 16#07#, 16#F0#, 16#1F#, 16#C0#, 16#0F#, 16#C0#, 16#7F#, 16#00#, 16#3F#, 16#87#, 16#F0#, 16#00#, 16#7F#, 16#FF#, 16#00#, 16#00#, 16#FE#, 16#1F#, 16#C0#, 16#03#, 16#F8#, 16#0F#, 16#E0#, 16#07#, 16#F0#, 16#0F#, 16#E0#, 16#0F#, 16#E0#, 16#1F#, 16#C0#, 16#1F#, 16#C0#, 16#3F#, 16#C0#, 16#7F#, 16#00#, 16#7F#, 16#80#, 16#FE#, 16#00#, 16#FF#, 16#01#, 16#FC#, 16#01#, 16#FE#, 16#03#, 16#F0#, 16#07#, 16#FC#, 16#0F#, 16#E0#, 16#0F#, 16#F0#, 16#1F#, 16#C0#, 16#3F#, 16#E0#, 16#3F#, 16#80#, 16#7F#, 16#80#, 16#FE#, 16#01#, 16#FE#, 16#01#, 16#FE#, 16#0F#, 16#F8#, 16#07#, 16#FF#, 16#FF#, 16#C0#, 16#3F#, 16#FF#, 16#FC#, 16#00#, 16#00#, 16#00#, 16#01#, 16#FE#, 16#08#, 16#00#, 16#7F#, 16#FE#, 16#C0#, 16#0F#, 16#F0#, 16#7E#, 16#00#, 16#FE#, 16#01#, 16#F0#, 16#1F#, 16#E0#, 16#07#, 16#01#, 16#FE#, 16#00#, 16#38#, 16#1F#, 16#E0#, 16#00#, 16#C0#, 16#FE#, 16#00#, 16#06#, 16#0F#, 16#F0#, 16#00#, 16#20#, 16#FF#, 16#00#, 16#01#, 16#07#, 16#F8#, 16#00#, 16#08#, 16#7F#, 16#80#, 16#00#, 16#03#, 16#FC#, 16#00#, 16#00#, 16#3F#, 16#E0#, 16#00#, 16#01#, 16#FE#, 16#00#, 16#00#, 16#0F#, 16#F0#, 16#00#, 16#00#, 16#FF#, 16#80#, 16#00#, 16#07#, 16#FC#, 16#00#, 16#00#, 16#3F#, 16#C0#, 16#00#, 16#01#, 16#FE#, 16#00#, 16#00#, 16#0F#, 16#F0#, 16#00#, 16#00#, 16#7F#, 16#80#, 16#00#, 16#03#, 16#FC#, 16#00#, 16#00#, 16#1F#, 16#E0#, 16#00#, 16#00#, 16#FF#, 16#00#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#00#, 16#1F#, 16#E0#, 16#00#, 16#60#, 16#7F#, 16#00#, 16#06#, 16#03#, 16#FC#, 16#00#, 16#70#, 16#0F#, 16#E0#, 16#07#, 16#00#, 16#1F#, 16#C0#, 16#E0#, 16#00#, 16#7F#, 16#FE#, 16#00#, 16#00#, 16#7F#, 16#80#, 16#00#, 16#01#, 16#FF#, 16#FF#, 16#80#, 16#00#, 16#3F#, 16#FF#, 16#FE#, 16#00#, 16#00#, 16#FE#, 16#07#, 16#F0#, 16#00#, 16#1F#, 16#C0#, 16#3F#, 16#00#, 16#03#, 16#F8#, 16#07#, 16#F0#, 16#00#, 16#FE#, 16#00#, 16#7F#, 16#00#, 16#1F#, 16#C0#, 16#07#, 16#F0#, 16#03#, 16#F8#, 16#00#, 16#FE#, 16#00#, 16#7F#, 16#00#, 16#1F#, 16#C0#, 16#1F#, 16#C0#, 16#03#, 16#FC#, 16#03#, 16#F8#, 16#00#, 16#7F#, 16#80#, 16#7F#, 16#00#, 16#0F#, 16#F0#, 16#0F#, 16#C0#, 16#01#, 16#FE#, 16#03#, 16#F8#, 16#00#, 16#3F#, 16#C0#, 16#7F#, 16#00#, 16#07#, 16#F8#, 16#0F#, 16#E0#, 16#01#, 16#FF#, 16#03#, 16#F8#, 16#00#, 16#3F#, 16#E0#, 16#7F#, 16#00#, 16#07#, 16#F8#, 16#0F#, 16#E0#, 16#00#, 16#FF#, 16#01#, 16#FC#, 16#00#, 16#3F#, 16#E0#, 16#7F#, 16#00#, 16#07#, 16#F8#, 16#0F#, 16#E0#, 16#01#, 16#FF#, 16#01#, 16#FC#, 16#00#, 16#3F#, 16#C0#, 16#3F#, 16#00#, 16#0F#, 16#F0#, 16#0F#, 16#E0#, 16#01#, 16#FC#, 16#01#, 16#FC#, 16#00#, 16#7F#, 16#00#, 16#3F#, 16#80#, 16#1F#, 16#C0#, 16#0F#, 16#E0#, 16#0F#, 16#F0#, 16#01#, 16#FE#, 16#07#, 16#F8#, 16#00#, 16#7F#, 16#FF#, 16#FC#, 16#00#, 16#3F#, 16#FF#, 16#F8#, 16#00#, 16#00#, 16#01#, 16#FF#, 16#FF#, 16#FF#, 16#00#, 16#7F#, 16#FF#, 16#FF#, 16#00#, 16#3F#, 16#C0#, 16#7E#, 16#00#, 16#3F#, 16#80#, 16#1E#, 16#00#, 16#3F#, 16#80#, 16#0E#, 16#00#, 16#3F#, 16#00#, 16#06#, 16#00#, 16#3F#, 16#00#, 16#04#, 16#00#, 16#7F#, 16#00#, 16#04#, 16#00#, 16#7F#, 16#00#, 16#00#, 16#00#, 16#7E#, 16#01#, 16#80#, 16#00#, 16#FE#, 16#01#, 16#00#, 16#00#, 16#FE#, 16#03#, 16#00#, 16#00#, 16#FC#, 16#0F#, 16#00#, 16#01#, 16#FF#, 16#FF#, 16#00#, 16#01#, 16#FF#, 16#FE#, 16#00#, 16#01#, 16#FC#, 16#3E#, 16#00#, 16#01#, 16#F8#, 16#1E#, 16#00#, 16#03#, 16#F8#, 16#0C#, 16#00#, 16#03#, 16#F8#, 16#0C#, 16#00#, 16#03#, 16#F8#, 16#0C#, 16#00#, 16#07#, 16#F0#, 16#08#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#08#, 16#07#, 16#F0#, 16#00#, 16#18#, 16#07#, 16#E0#, 16#00#, 16#30#, 16#0F#, 16#E0#, 16#00#, 16#30#, 16#0F#, 16#E0#, 16#00#, 16#70#, 16#0F#, 16#E0#, 16#01#, 16#E0#, 16#1F#, 16#C0#, 16#07#, 16#E0#, 16#1F#, 16#E0#, 16#3F#, 16#E0#, 16#3F#, 16#FF#, 16#FF#, 16#C0#, 16#FF#, 16#FF#, 16#FF#, 16#C0#, 16#01#, 16#FF#, 16#FF#, 16#FE#, 16#00#, 16#FF#, 16#FF#, 16#FC#, 16#00#, 16#FF#, 16#03#, 16#F0#, 16#01#, 16#FC#, 16#01#, 16#E0#, 16#03#, 16#F8#, 16#01#, 16#C0#, 16#0F#, 16#E0#, 16#01#, 16#80#, 16#1F#, 16#C0#, 16#02#, 16#00#, 16#3F#, 16#80#, 16#04#, 16#00#, 16#7F#, 16#00#, 16#00#, 16#01#, 16#FC#, 16#03#, 16#00#, 16#03#, 16#F8#, 16#04#, 16#00#, 16#07#, 16#F0#, 16#18#, 16#00#, 16#0F#, 16#C0#, 16#F0#, 16#00#, 16#3F#, 16#FF#, 16#C0#, 16#00#, 16#7F#, 16#FF#, 16#80#, 16#00#, 16#FE#, 16#1F#, 16#00#, 16#03#, 16#F8#, 16#1E#, 16#00#, 16#07#, 16#F0#, 16#18#, 16#00#, 16#0F#, 16#E0#, 16#30#, 16#00#, 16#1F#, 16#C0#, 16#60#, 16#00#, 16#7F#, 16#00#, 16#80#, 16#00#, 16#FE#, 16#01#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#00#, 16#FF#, 16#00#, 16#00#, 16#01#, 16#FE#, 16#00#, 16#00#, 16#07#, 16#FC#, 16#00#, 16#00#, 16#3F#, 16#FF#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FF#, 16#02#, 16#00#, 16#0F#, 16#FF#, 16#EE#, 16#00#, 16#3F#, 16#C0#, 16#FC#, 16#00#, 16#7F#, 16#00#, 16#7C#, 16#01#, 16#FE#, 16#00#, 16#3C#, 16#03#, 16#FC#, 16#00#, 16#38#, 16#07#, 16#F8#, 16#00#, 16#18#, 16#07#, 16#F0#, 16#00#, 16#18#, 16#0F#, 16#F0#, 16#00#, 16#10#, 16#1F#, 16#E0#, 16#00#, 16#10#, 16#1F#, 16#E0#, 16#00#, 16#00#, 16#3F#, 16#C0#, 16#00#, 16#00#, 16#3F#, 16#C0#, 16#00#, 16#00#, 16#7F#, 16#C0#, 16#00#, 16#00#, 16#7F#, 16#80#, 16#00#, 16#00#, 16#7F#, 16#80#, 16#00#, 16#00#, 16#FF#, 16#80#, 16#00#, 16#00#, 16#FF#, 16#80#, 16#1F#, 16#FF#, 16#FF#, 16#00#, 16#07#, 16#FC#, 16#FF#, 16#00#, 16#03#, 16#F8#, 16#FF#, 16#00#, 16#03#, 16#F8#, 16#FF#, 16#00#, 16#03#, 16#F0#, 16#FF#, 16#00#, 16#03#, 16#F0#, 16#FF#, 16#00#, 16#07#, 16#F0#, 16#7F#, 16#00#, 16#07#, 16#F0#, 16#7F#, 16#00#, 16#07#, 16#E0#, 16#7F#, 16#80#, 16#07#, 16#E0#, 16#3F#, 16#80#, 16#0F#, 16#E0#, 16#1F#, 16#C0#, 16#0F#, 16#C0#, 16#0F#, 16#E0#, 16#0F#, 16#C0#, 16#07#, 16#F0#, 16#3F#, 16#80#, 16#01#, 16#FF#, 16#FE#, 16#00#, 16#00#, 16#3F#, 16#E0#, 16#00#, 16#01#, 16#FF#, 16#FC#, 16#7F#, 16#FE#, 16#00#, 16#FF#, 16#C0#, 16#3F#, 16#F0#, 16#00#, 16#FE#, 16#00#, 16#3F#, 16#C0#, 16#01#, 16#FC#, 16#00#, 16#7F#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#FE#, 16#00#, 16#0F#, 16#E0#, 16#01#, 16#FC#, 16#00#, 16#1F#, 16#C0#, 16#07#, 16#F0#, 16#00#, 16#3F#, 16#80#, 16#0F#, 16#E0#, 16#00#, 16#7F#, 16#00#, 16#1F#, 16#C0#, 16#01#, 16#FC#, 16#00#, 16#7F#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#FE#, 16#00#, 16#07#, 16#F0#, 16#01#, 16#FC#, 16#00#, 16#0F#, 16#C0#, 16#03#, 16#F0#, 16#00#, 16#3F#, 16#80#, 16#0F#, 16#E0#, 16#00#, 16#7F#, 16#FF#, 16#FF#, 16#C0#, 16#00#, 16#FF#, 16#FF#, 16#FF#, 16#80#, 16#03#, 16#F8#, 16#00#, 16#7E#, 16#00#, 16#07#, 16#F0#, 16#01#, 16#FC#, 16#00#, 16#0F#, 16#E0#, 16#03#, 16#F8#, 16#00#, 16#1F#, 16#C0#, 16#07#, 16#E0#, 16#00#, 16#7F#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#FE#, 16#00#, 16#3F#, 16#80#, 16#01#, 16#FC#, 16#00#, 16#7F#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#FC#, 16#00#, 16#0F#, 16#E0#, 16#03#, 16#F8#, 16#00#, 16#1F#, 16#C0#, 16#07#, 16#F0#, 16#00#, 16#3F#, 16#80#, 16#0F#, 16#E0#, 16#00#, 16#FF#, 16#00#, 16#3F#, 16#C0#, 16#01#, 16#FE#, 16#00#, 16#7F#, 16#80#, 16#07#, 16#FC#, 16#01#, 16#FF#, 16#00#, 16#3F#, 16#FF#, 16#1F#, 16#FF#, 16#C0#, 16#00#, 16#01#, 16#FF#, 16#F8#, 16#03#, 16#FE#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#7F#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#FC#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#7E#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#3F#, 16#80#, 16#01#, 16#FC#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#FE#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#3F#, 16#80#, 16#01#, 16#F8#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#FE#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#7F#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#FC#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#7F#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#3F#, 16#C0#, 16#01#, 16#FC#, 16#00#, 16#1F#, 16#F0#, 16#03#, 16#FF#, 16#F0#, 16#00#, 16#00#, 16#07#, 16#FF#, 16#E0#, 16#00#, 16#3F#, 16#F0#, 16#00#, 16#03#, 16#FC#, 16#00#, 16#00#, 16#7F#, 16#00#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#00#, 16#3F#, 16#00#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#1F#, 16#C0#, 16#07#, 16#03#, 16#F0#, 16#01#, 16#F0#, 16#FE#, 16#00#, 16#3E#, 16#1F#, 16#C0#, 16#07#, 16#C3#, 16#F0#, 16#00#, 16#F8#, 16#FC#, 16#00#, 16#0F#, 16#3F#, 16#80#, 16#00#, 16#FF#, 16#C0#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#00#, 16#01#, 16#FF#, 16#F8#, 16#FF#, 16#C0#, 16#1F#, 16#F8#, 16#0F#, 16#C0#, 16#03#, 16#F8#, 16#01#, 16#C0#, 16#00#, 16#FE#, 16#00#, 16#E0#, 16#00#, 16#3F#, 16#80#, 16#70#, 16#00#, 16#1F#, 16#C0#, 16#38#, 16#00#, 16#07#, 16#F0#, 16#1C#, 16#00#, 16#01#, 16#FC#, 16#0E#, 16#00#, 16#00#, 16#7F#, 16#07#, 16#00#, 16#00#, 16#3F#, 16#83#, 16#80#, 16#00#, 16#0F#, 16#E1#, 16#C0#, 16#00#, 16#03#, 16#F8#, 16#E0#, 16#00#, 16#00#, 16#FC#, 16#60#, 16#00#, 16#00#, 16#7F#, 16#7C#, 16#00#, 16#00#, 16#1F#, 16#FF#, 16#00#, 16#00#, 16#07#, 16#FF#, 16#E0#, 16#00#, 16#03#, 16#FB#, 16#F8#, 16#00#, 16#00#, 16#FE#, 16#7F#, 16#00#, 16#00#, 16#3F#, 16#9F#, 16#C0#, 16#00#, 16#0F#, 16#E3#, 16#F8#, 16#00#, 16#07#, 16#F0#, 16#FE#, 16#00#, 16#01#, 16#FC#, 16#1F#, 16#C0#, 16#00#, 16#7F#, 16#07#, 16#F0#, 16#00#, 16#1F#, 16#80#, 16#FE#, 16#00#, 16#0F#, 16#E0#, 16#3F#, 16#80#, 16#03#, 16#F8#, 16#0F#, 16#F0#, 16#00#, 16#FE#, 16#01#, 16#FC#, 16#00#, 16#7F#, 16#00#, 16#7F#, 16#80#, 16#1F#, 16#E0#, 16#0F#, 16#E0#, 16#0F#, 16#F8#, 16#07#, 16#FC#, 16#0F#, 16#FF#, 16#C7#, 16#FF#, 16#C0#, 16#01#, 16#FF#, 16#F8#, 16#00#, 16#03#, 16#FF#, 16#00#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#00#, 16#7F#, 16#00#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#00#, 16#7F#, 16#00#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#04#, 16#1F#, 16#C0#, 16#00#, 16#60#, 16#FC#, 16#00#, 16#06#, 16#0F#, 16#E0#, 16#00#, 16#30#, 16#7F#, 16#00#, 16#03#, 16#83#, 16#F8#, 16#00#, 16#7C#, 16#3F#, 16#80#, 16#0F#, 16#C1#, 16#FE#, 16#03#, 16#FE#, 16#1F#, 16#FF#, 16#FF#, 16#F3#, 16#FF#, 16#FF#, 16#FF#, 16#00#, 16#01#, 16#FF#, 16#C0#, 16#00#, 16#3F#, 16#F0#, 16#03#, 16#FC#, 16#00#, 16#03#, 16#FC#, 16#00#, 16#3F#, 16#C0#, 16#00#, 16#7F#, 16#80#, 16#03#, 16#FC#, 16#00#, 16#0F#, 16#F8#, 16#00#, 16#3F#, 16#C0#, 16#00#, 16#FF#, 16#80#, 16#03#, 16#FC#, 16#00#, 16#1F#, 16#F0#, 16#00#, 16#3F#, 16#C0#, 16#03#, 16#FF#, 16#00#, 16#07#, 16#FC#, 16#00#, 16#37#, 16#F0#, 16#00#, 16#6F#, 16#E0#, 16#06#, 16#7E#, 16#00#, 16#04#, 16#FE#, 16#00#, 16#EF#, 16#E0#, 16#00#, 16#CF#, 16#E0#, 16#0C#, 16#FE#, 16#00#, 16#0C#, 16#FE#, 16#01#, 16#8F#, 16#E0#, 16#00#, 16#CF#, 16#E0#, 16#38#, 16#FC#, 16#00#, 16#08#, 16#FE#, 16#03#, 16#1F#, 16#C0#, 16#01#, 16#8F#, 16#E0#, 16#61#, 16#FC#, 16#00#, 16#18#, 16#7E#, 16#0E#, 16#1F#, 16#C0#, 16#01#, 16#07#, 16#E0#, 16#C3#, 16#F8#, 16#00#, 16#30#, 16#7F#, 16#18#, 16#3F#, 16#80#, 16#03#, 16#07#, 16#F3#, 16#83#, 16#F8#, 16#00#, 16#20#, 16#7F#, 16#30#, 16#3F#, 16#00#, 16#06#, 16#07#, 16#F7#, 16#07#, 16#F0#, 16#00#, 16#60#, 16#7F#, 16#E0#, 16#7F#, 16#00#, 16#06#, 16#07#, 16#FC#, 16#07#, 16#F0#, 16#00#, 16#E0#, 16#3F#, 16#C0#, 16#7E#, 16#00#, 16#0C#, 16#03#, 16#F8#, 16#0F#, 16#E0#, 16#00#, 16#C0#, 16#3F#, 16#00#, 16#FE#, 16#00#, 16#0C#, 16#03#, 16#F0#, 16#0F#, 16#E0#, 16#01#, 16#C0#, 16#3E#, 16#01#, 16#FC#, 16#00#, 16#1C#, 16#03#, 16#C0#, 16#1F#, 16#C0#, 16#07#, 16#E0#, 16#3C#, 16#03#, 16#FE#, 16#00#, 16#FF#, 16#C1#, 16#81#, 16#FF#, 16#FC#, 16#00#, 16#00#, 16#10#, 16#00#, 16#00#, 16#00#, 16#03#, 16#FF#, 16#00#, 16#1F#, 16#F8#, 16#03#, 16#F8#, 16#00#, 16#3F#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#F0#, 16#00#, 16#3F#, 16#00#, 16#07#, 16#00#, 16#03#, 16#FC#, 16#00#, 16#38#, 16#00#, 16#1F#, 16#E0#, 16#01#, 16#80#, 16#00#, 16#FF#, 16#80#, 16#0C#, 16#00#, 16#0D#, 16#FC#, 16#00#, 16#60#, 16#00#, 16#6F#, 16#F0#, 16#03#, 16#00#, 16#02#, 16#3F#, 16#80#, 16#30#, 16#00#, 16#31#, 16#FE#, 16#01#, 16#80#, 16#01#, 16#87#, 16#F0#, 16#0C#, 16#00#, 16#0C#, 16#3F#, 16#C0#, 16#C0#, 16#00#, 16#40#, 16#FE#, 16#06#, 16#00#, 16#06#, 16#07#, 16#F8#, 16#30#, 16#00#, 16#30#, 16#1F#, 16#C1#, 16#80#, 16#01#, 16#00#, 16#FF#, 16#18#, 16#00#, 16#18#, 16#03#, 16#F8#, 16#C0#, 16#00#, 16#C0#, 16#1F#, 16#C6#, 16#00#, 16#06#, 16#00#, 16#7F#, 16#60#, 16#00#, 16#60#, 16#03#, 16#FB#, 16#00#, 16#03#, 16#00#, 16#0F#, 16#F8#, 16#00#, 16#18#, 16#00#, 16#7F#, 16#C0#, 16#01#, 16#C0#, 16#01#, 16#FC#, 16#00#, 16#0C#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#60#, 16#00#, 16#7F#, 16#00#, 16#03#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#38#, 16#00#, 16#0F#, 16#80#, 16#01#, 16#C0#, 16#00#, 16#3C#, 16#00#, 16#3F#, 16#00#, 16#01#, 16#E0#, 16#03#, 16#FF#, 16#00#, 16#06#, 16#00#, 16#00#, 16#00#, 16#00#, 16#30#, 16#00#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#0F#, 16#FF#, 16#80#, 16#00#, 16#7E#, 16#1F#, 16#80#, 16#01#, 16#F0#, 16#0F#, 16#80#, 16#0F#, 16#C0#, 16#1F#, 16#80#, 16#3F#, 16#00#, 16#1F#, 16#80#, 16#FE#, 16#00#, 16#3F#, 16#03#, 16#F8#, 16#00#, 16#7E#, 16#07#, 16#F0#, 16#00#, 16#FE#, 16#1F#, 16#C0#, 16#01#, 16#FC#, 16#7F#, 16#80#, 16#03#, 16#F8#, 16#FE#, 16#00#, 16#07#, 16#F3#, 16#FC#, 16#00#, 16#1F#, 16#E7#, 16#F0#, 16#00#, 16#3F#, 16#DF#, 16#E0#, 16#00#, 16#7F#, 16#BF#, 16#C0#, 16#00#, 16#FE#, 16#7F#, 16#80#, 16#03#, 16#FC#, 16#FE#, 16#00#, 16#07#, 16#FB#, 16#FC#, 16#00#, 16#0F#, 16#F7#, 16#F8#, 16#00#, 16#3F#, 16#CF#, 16#F0#, 16#00#, 16#7F#, 16#9F#, 16#C0#, 16#00#, 16#FE#, 16#3F#, 16#80#, 16#03#, 16#FC#, 16#7F#, 16#00#, 16#07#, 16#F0#, 16#FE#, 16#00#, 16#1F#, 16#C0#, 16#FC#, 16#00#, 16#3F#, 16#81#, 16#F8#, 16#00#, 16#FE#, 16#03#, 16#F0#, 16#03#, 16#F8#, 16#03#, 16#F0#, 16#07#, 16#E0#, 16#03#, 16#E0#, 16#1F#, 16#00#, 16#03#, 16#E0#, 16#FC#, 16#00#, 16#03#, 16#FF#, 16#E0#, 16#00#, 16#01#, 16#FE#, 16#00#, 16#00#, 16#01#, 16#FF#, 16#FF#, 16#80#, 16#00#, 16#FF#, 16#FF#, 16#E0#, 16#00#, 16#FE#, 16#1F#, 16#E0#, 16#01#, 16#FC#, 16#1F#, 16#E0#, 16#03#, 16#F0#, 16#1F#, 16#C0#, 16#0F#, 16#E0#, 16#3F#, 16#C0#, 16#1F#, 16#C0#, 16#7F#, 16#80#, 16#3F#, 16#80#, 16#FF#, 16#00#, 16#7E#, 16#01#, 16#FE#, 16#01#, 16#FC#, 16#03#, 16#FC#, 16#03#, 16#F8#, 16#0F#, 16#F8#, 16#07#, 16#E0#, 16#1F#, 16#E0#, 16#0F#, 16#C0#, 16#7F#, 16#80#, 16#3F#, 16#81#, 16#FE#, 16#00#, 16#7F#, 16#07#, 16#F8#, 16#00#, 16#FF#, 16#FF#, 16#C0#, 16#03#, 16#FF#, 16#FC#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#00#, 16#7F#, 16#00#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#00#, 16#07#, 16#FC#, 16#00#, 16#00#, 16#3F#, 16#FF#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#0F#, 16#FF#, 16#00#, 16#00#, 16#7E#, 16#1F#, 16#80#, 16#01#, 16#F0#, 16#0F#, 16#80#, 16#0F#, 16#C0#, 16#1F#, 16#80#, 16#3F#, 16#80#, 16#1F#, 16#80#, 16#FE#, 16#00#, 16#3F#, 16#03#, 16#F8#, 16#00#, 16#7E#, 16#07#, 16#F0#, 16#00#, 16#FE#, 16#1F#, 16#C0#, 16#01#, 16#FC#, 16#7F#, 16#80#, 16#03#, 16#F8#, 16#FE#, 16#00#, 16#07#, 16#F3#, 16#FC#, 16#00#, 16#1F#, 16#E7#, 16#F8#, 16#00#, 16#3F#, 16#DF#, 16#E0#, 16#00#, 16#7F#, 16#BF#, 16#C0#, 16#00#, 16#FF#, 16#7F#, 16#80#, 16#01#, 16#FC#, 16#FE#, 16#00#, 16#07#, 16#FB#, 16#FC#, 16#00#, 16#0F#, 16#F7#, 16#F8#, 16#00#, 16#1F#, 16#CF#, 16#F0#, 16#00#, 16#7F#, 16#9F#, 16#C0#, 16#00#, 16#FE#, 16#3F#, 16#80#, 16#01#, 16#FC#, 16#7F#, 16#00#, 16#07#, 16#F0#, 16#FE#, 16#00#, 16#0F#, 16#E1#, 16#FC#, 16#00#, 16#3F#, 16#81#, 16#F8#, 16#00#, 16#7E#, 16#03#, 16#F0#, 16#01#, 16#F8#, 16#03#, 16#E0#, 16#07#, 16#E0#, 16#07#, 16#E0#, 16#1F#, 16#80#, 16#03#, 16#E0#, 16#7E#, 16#00#, 16#03#, 16#F3#, 16#F0#, 16#00#, 16#01#, 16#FF#, 16#00#, 16#00#, 16#01#, 16#80#, 16#00#, 16#00#, 16#06#, 16#00#, 16#00#, 16#00#, 16#1C#, 16#00#, 16#00#, 16#C0#, 16#7F#, 16#E0#, 16#03#, 16#03#, 16#FF#, 16#F8#, 16#1C#, 16#0F#, 16#FF#, 16#FF#, 16#F0#, 16#3F#, 16#FF#, 16#FF#, 16#C0#, 16#E0#, 16#3F#, 16#FF#, 16#00#, 16#00#, 16#0F#, 16#F0#, 16#00#, 16#01#, 16#FF#, 16#FF#, 16#C0#, 16#00#, 16#7F#, 16#FF#, 16#F8#, 16#00#, 16#3F#, 16#C3#, 16#FC#, 16#00#, 16#3F#, 16#81#, 16#FE#, 16#00#, 16#3F#, 16#80#, 16#FF#, 16#00#, 16#7F#, 16#80#, 16#FF#, 16#00#, 16#7F#, 16#00#, 16#FF#, 16#00#, 16#7F#, 16#00#, 16#FF#, 16#00#, 16#7F#, 16#00#, 16#FF#, 16#00#, 16#FF#, 16#01#, 16#FE#, 16#00#, 16#FE#, 16#01#, 16#FE#, 16#00#, 16#FE#, 16#03#, 16#FC#, 16#00#, 16#FE#, 16#07#, 16#F8#, 16#01#, 16#FC#, 16#1F#, 16#F0#, 16#01#, 16#FF#, 16#FF#, 16#C0#, 16#01#, 16#FF#, 16#FE#, 16#00#, 16#03#, 16#FD#, 16#FE#, 16#00#, 16#03#, 16#F8#, 16#FF#, 16#00#, 16#03#, 16#F8#, 16#FF#, 16#00#, 16#03#, 16#F8#, 16#FF#, 16#00#, 16#07#, 16#F8#, 16#7F#, 16#80#, 16#07#, 16#F0#, 16#7F#, 16#80#, 16#07#, 16#F0#, 16#3F#, 16#80#, 16#07#, 16#F0#, 16#3F#, 16#C0#, 16#0F#, 16#E0#, 16#3F#, 16#C0#, 16#0F#, 16#E0#, 16#1F#, 16#E0#, 16#0F#, 16#E0#, 16#1F#, 16#E0#, 16#1F#, 16#E0#, 16#1F#, 16#E0#, 16#1F#, 16#E0#, 16#0F#, 16#F0#, 16#3F#, 16#F0#, 16#0F#, 16#F8#, 16#FF#, 16#FC#, 16#0F#, 16#FE#, 16#00#, 16#1F#, 16#83#, 16#00#, 16#7F#, 16#F7#, 16#00#, 16#F8#, 16#7E#, 16#01#, 16#E0#, 16#1E#, 16#03#, 16#C0#, 16#0E#, 16#03#, 16#C0#, 16#0E#, 16#07#, 16#C0#, 16#0E#, 16#07#, 16#C0#, 16#04#, 16#07#, 16#C0#, 16#04#, 16#07#, 16#E0#, 16#04#, 16#07#, 16#F0#, 16#00#, 16#07#, 16#F8#, 16#00#, 16#03#, 16#FC#, 16#00#, 16#03#, 16#FF#, 16#00#, 16#01#, 16#FF#, 16#80#, 16#00#, 16#FF#, 16#C0#, 16#00#, 16#7F#, 16#E0#, 16#00#, 16#3F#, 16#E0#, 16#00#, 16#1F#, 16#F0#, 16#00#, 16#0F#, 16#F0#, 16#00#, 16#07#, 16#F8#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#01#, 16#F8#, 16#20#, 16#00#, 16#F8#, 16#20#, 16#00#, 16#F8#, 16#20#, 16#00#, 16#F8#, 16#70#, 16#00#, 16#F8#, 16#70#, 16#00#, 16#F0#, 16#78#, 16#01#, 16#F0#, 16#78#, 16#03#, 16#E0#, 16#7E#, 16#07#, 16#C0#, 16#47#, 16#FF#, 16#80#, 16#C0#, 16#FC#, 16#00#, 16#3F#, 16#FF#, 16#FF#, 16#E7#, 16#FF#, 16#FF#, 16#FC#, 16#FE#, 16#3F#, 16#8F#, 16#9E#, 16#07#, 16#E0#, 16#F3#, 16#80#, 16#FC#, 16#0C#, 16#60#, 16#3F#, 16#81#, 16#98#, 16#07#, 16#F0#, 16#13#, 16#00#, 16#FC#, 16#02#, 16#00#, 16#1F#, 16#80#, 16#40#, 16#07#, 16#F0#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#00#, 16#FF#, 16#00#, 16#00#, 16#3F#, 16#F0#, 16#00#, 16#3F#, 16#FF#, 16#C0#, 16#00#, 16#7F#, 16#FF#, 16#03#, 16#FF#, 16#0F#, 16#FC#, 16#00#, 16#FC#, 16#07#, 16#F0#, 16#00#, 16#38#, 16#07#, 16#F0#, 16#00#, 16#38#, 16#07#, 16#F0#, 16#00#, 16#30#, 16#0F#, 16#E0#, 16#00#, 16#30#, 16#0F#, 16#E0#, 16#00#, 16#70#, 16#0F#, 16#E0#, 16#00#, 16#60#, 16#0F#, 16#C0#, 16#00#, 16#60#, 16#1F#, 16#C0#, 16#00#, 16#60#, 16#1F#, 16#C0#, 16#00#, 16#C0#, 16#1F#, 16#C0#, 16#00#, 16#C0#, 16#1F#, 16#80#, 16#00#, 16#C0#, 16#3F#, 16#80#, 16#01#, 16#80#, 16#3F#, 16#80#, 16#01#, 16#80#, 16#3F#, 16#00#, 16#01#, 16#80#, 16#7F#, 16#00#, 16#01#, 16#00#, 16#7F#, 16#00#, 16#03#, 16#00#, 16#7F#, 16#00#, 16#03#, 16#00#, 16#7E#, 16#00#, 16#03#, 16#00#, 16#FE#, 16#00#, 16#06#, 16#00#, 16#FE#, 16#00#, 16#06#, 16#00#, 16#FC#, 16#00#, 16#06#, 16#00#, 16#FC#, 16#00#, 16#0E#, 16#00#, 16#FC#, 16#00#, 16#0C#, 16#00#, 16#FC#, 16#00#, 16#1C#, 16#00#, 16#FC#, 16#00#, 16#18#, 16#00#, 16#7E#, 16#00#, 16#38#, 16#00#, 16#7E#, 16#00#, 16#70#, 16#00#, 16#3F#, 16#81#, 16#E0#, 16#00#, 16#0F#, 16#FF#, 16#80#, 16#00#, 16#03#, 16#FE#, 16#00#, 16#00#, 16#FF#, 16#FC#, 16#03#, 16#FE#, 16#7F#, 16#E0#, 16#01#, 16#F8#, 16#7F#, 16#80#, 16#01#, 16#C0#, 16#FF#, 16#00#, 16#03#, 16#80#, 16#FE#, 16#00#, 16#0E#, 16#01#, 16#FC#, 16#00#, 16#18#, 16#03#, 16#F8#, 16#00#, 16#70#, 16#07#, 16#F0#, 16#00#, 16#C0#, 16#0F#, 16#F0#, 16#03#, 16#80#, 16#1F#, 16#E0#, 16#06#, 16#00#, 16#3F#, 16#C0#, 16#18#, 16#00#, 16#7F#, 16#80#, 16#70#, 16#00#, 16#7F#, 16#00#, 16#C0#, 16#00#, 16#FE#, 16#03#, 16#00#, 16#01#, 16#FC#, 16#0E#, 16#00#, 16#03#, 16#F8#, 16#18#, 16#00#, 16#07#, 16#F8#, 16#60#, 16#00#, 16#0F#, 16#F1#, 16#C0#, 16#00#, 16#0F#, 16#E3#, 16#00#, 16#00#, 16#1F#, 16#CC#, 16#00#, 16#00#, 16#3F#, 16#B8#, 16#00#, 16#00#, 16#7F#, 16#60#, 16#00#, 16#00#, 16#FF#, 16#C0#, 16#00#, 16#01#, 16#FF#, 16#00#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#00#, 16#0F#, 16#80#, 16#00#, 16#00#, 16#1F#, 16#00#, 16#00#, 16#00#, 16#3C#, 16#00#, 16#00#, 16#00#, 16#30#, 16#00#, 16#00#, 16#00#, 16#60#, 16#00#, 16#00#, 16#FF#, 16#F8#, 16#FF#, 16#F0#, 16#FF#, 16#9F#, 16#F8#, 16#1F#, 16#E0#, 16#0F#, 16#87#, 16#F8#, 16#07#, 16#E0#, 16#07#, 16#03#, 16#F8#, 16#03#, 16#F0#, 16#03#, 16#80#, 16#FE#, 16#01#, 16#F8#, 16#01#, 16#80#, 16#FF#, 16#00#, 16#FC#, 16#00#, 16#C0#, 16#7F#, 16#80#, 16#7F#, 16#00#, 16#C0#, 16#1F#, 16#C0#, 16#7F#, 16#80#, 16#60#, 16#0F#, 16#E0#, 16#3F#, 16#C0#, 16#60#, 16#07#, 16#F0#, 16#1F#, 16#E0#, 16#30#, 16#03#, 16#F8#, 16#1F#, 16#F0#, 16#30#, 16#01#, 16#FC#, 16#09#, 16#F8#, 16#18#, 16#00#, 16#FE#, 16#0C#, 16#FE#, 16#18#, 16#00#, 16#3F#, 16#84#, 16#7F#, 16#0C#, 16#00#, 16#1F#, 16#C6#, 16#3F#, 16#8C#, 16#00#, 16#0F#, 16#E2#, 16#1F#, 16#C6#, 16#00#, 16#07#, 16#F3#, 16#0F#, 16#E6#, 16#00#, 16#03#, 16#F9#, 16#87#, 16#F3#, 16#00#, 16#01#, 16#FD#, 16#81#, 16#FB#, 16#00#, 16#00#, 16#FE#, 16#C0#, 16#FD#, 16#80#, 16#00#, 16#3F#, 16#C0#, 16#7F#, 16#80#, 16#00#, 16#1F#, 16#E0#, 16#3F#, 16#C0#, 16#00#, 16#0F#, 16#E0#, 16#1F#, 16#C0#, 16#00#, 16#07#, 16#F0#, 16#0F#, 16#E0#, 16#00#, 16#03#, 16#F0#, 16#07#, 16#E0#, 16#00#, 16#01#, 16#F8#, 16#01#, 16#F0#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#F0#, 16#00#, 16#00#, 16#3C#, 16#00#, 16#78#, 16#00#, 16#00#, 16#1C#, 16#00#, 16#38#, 16#00#, 16#00#, 16#0E#, 16#00#, 16#1C#, 16#00#, 16#00#, 16#06#, 16#00#, 16#0C#, 16#00#, 16#00#, 16#03#, 16#00#, 16#06#, 16#00#, 16#00#, 16#03#, 16#FF#, 16#F0#, 16#FF#, 16#C0#, 16#3F#, 16#E0#, 16#0F#, 16#C0#, 16#03#, 16#F8#, 16#01#, 16#E0#, 16#00#, 16#FE#, 16#00#, 16#E0#, 16#00#, 16#3F#, 16#80#, 16#70#, 16#00#, 16#07#, 16#E0#, 16#18#, 16#00#, 16#01#, 16#FC#, 16#0C#, 16#00#, 16#00#, 16#7F#, 16#06#, 16#00#, 16#00#, 16#1F#, 16#C3#, 16#00#, 16#00#, 16#03#, 16#F9#, 16#80#, 16#00#, 16#00#, 16#FE#, 16#C0#, 16#00#, 16#00#, 16#3F#, 16#E0#, 16#00#, 16#00#, 16#07#, 16#F8#, 16#00#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#00#, 16#00#, 16#7F#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#00#, 16#01#, 16#FE#, 16#00#, 16#00#, 16#00#, 16#FF#, 16#80#, 16#00#, 16#00#, 16#77#, 16#F0#, 16#00#, 16#00#, 16#39#, 16#FC#, 16#00#, 16#00#, 16#1C#, 16#3F#, 16#00#, 16#00#, 16#06#, 16#0F#, 16#E0#, 16#00#, 16#03#, 16#03#, 16#F8#, 16#00#, 16#01#, 16#80#, 16#7E#, 16#00#, 16#00#, 16#C0#, 16#1F#, 16#C0#, 16#00#, 16#70#, 16#07#, 16#F0#, 16#00#, 16#38#, 16#01#, 16#FC#, 16#00#, 16#1E#, 16#00#, 16#7F#, 16#80#, 16#1F#, 16#C0#, 16#1F#, 16#F0#, 16#0F#, 16#FC#, 16#3F#, 16#FF#, 16#80#, 16#FF#, 16#F8#, 16#3F#, 16#F3#, 16#FC#, 16#00#, 16#FC#, 16#1F#, 16#C0#, 16#07#, 16#81#, 16#FC#, 16#00#, 16#70#, 16#0F#, 16#C0#, 16#0E#, 16#00#, 16#FE#, 16#00#, 16#C0#, 16#0F#, 16#E0#, 16#1C#, 16#00#, 16#7E#, 16#03#, 16#80#, 16#07#, 16#F0#, 16#30#, 16#00#, 16#7F#, 16#06#, 16#00#, 16#03#, 16#F0#, 16#E0#, 16#00#, 16#3F#, 16#8C#, 16#00#, 16#03#, 16#F9#, 16#80#, 16#00#, 16#1F#, 16#B0#, 16#00#, 16#01#, 16#FF#, 16#00#, 16#00#, 16#1F#, 16#E0#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#00#, 16#3F#, 16#00#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#00#, 16#7F#, 16#00#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#0F#, 16#F0#, 16#00#, 16#01#, 16#FF#, 16#00#, 16#00#, 16#FF#, 16#FE#, 16#00#, 16#00#, 16#03#, 16#FF#, 16#FF#, 16#F0#, 16#3F#, 16#FF#, 16#FF#, 16#03#, 16#F8#, 16#0F#, 16#F0#, 16#7C#, 16#01#, 16#FE#, 16#07#, 16#80#, 16#1F#, 16#C0#, 16#70#, 16#03#, 16#F8#, 16#06#, 16#00#, 16#7F#, 16#80#, 16#C0#, 16#0F#, 16#F0#, 16#08#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#03#, 16#FC#, 16#00#, 16#00#, 16#7F#, 16#80#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#1F#, 16#E0#, 16#00#, 16#03#, 16#FC#, 16#00#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#00#, 16#FF#, 16#00#, 16#00#, 16#1F#, 16#E0#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#C0#, 16#FF#, 16#00#, 16#0C#, 16#1F#, 16#E0#, 16#01#, 16#81#, 16#FC#, 16#00#, 16#38#, 16#3F#, 16#80#, 16#07#, 16#87#, 16#F8#, 16#01#, 16#F0#, 16#FF#, 16#00#, 16#FF#, 16#0F#, 16#FF#, 16#FF#, 16#F0#, 16#FF#, 16#FF#, 16#FF#, 16#00#, 16#00#, 16#3F#, 16#E0#, 16#07#, 16#FC#, 16#00#, 16#F0#, 16#00#, 16#3C#, 16#00#, 16#07#, 16#80#, 16#00#, 16#F0#, 16#00#, 16#3E#, 16#00#, 16#07#, 16#80#, 16#00#, 16#F0#, 16#00#, 16#1E#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#F0#, 16#00#, 16#1E#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#F0#, 16#00#, 16#1E#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#78#, 16#00#, 16#1E#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#78#, 16#00#, 16#0F#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#78#, 16#00#, 16#0F#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#78#, 16#00#, 16#0F#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#7C#, 16#00#, 16#0F#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#3C#, 16#00#, 16#0F#, 16#80#, 16#01#, 16#E0#, 16#00#, 16#3E#, 16#00#, 16#07#, 16#FE#, 16#01#, 16#FF#, 16#C0#, 16#00#, 16#F0#, 16#07#, 16#80#, 16#3E#, 16#00#, 16#F0#, 16#07#, 16#80#, 16#3E#, 16#01#, 16#F0#, 16#07#, 16#80#, 16#3C#, 16#01#, 16#F0#, 16#07#, 16#80#, 16#3C#, 16#01#, 16#F0#, 16#0F#, 16#80#, 16#3C#, 16#01#, 16#E0#, 16#0F#, 16#80#, 16#3C#, 16#01#, 16#E0#, 16#0F#, 16#80#, 16#7C#, 16#01#, 16#E0#, 16#0F#, 16#00#, 16#7C#, 16#01#, 16#E0#, 16#0F#, 16#00#, 16#7C#, 16#03#, 16#E0#, 16#0F#, 16#00#, 16#78#, 16#03#, 16#E0#, 16#0F#, 16#00#, 16#78#, 16#00#, 16#7F#, 16#E0#, 16#0F#, 16#FC#, 16#00#, 16#0F#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#3C#, 16#00#, 16#07#, 16#80#, 16#01#, 16#E0#, 16#00#, 16#3C#, 16#00#, 16#07#, 16#80#, 16#00#, 16#F0#, 16#00#, 16#3C#, 16#00#, 16#07#, 16#80#, 16#00#, 16#F0#, 16#00#, 16#3E#, 16#00#, 16#07#, 16#80#, 16#00#, 16#F0#, 16#00#, 16#1E#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#F0#, 16#00#, 16#1E#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#F0#, 16#00#, 16#1E#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#78#, 16#00#, 16#1E#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#78#, 16#00#, 16#0F#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#78#, 16#00#, 16#0F#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#78#, 16#00#, 16#0F#, 16#00#, 16#01#, 16#E0#, 16#07#, 16#FC#, 16#01#, 16#FF#, 16#00#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#7F#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#3F#, 16#C0#, 16#01#, 16#EF#, 16#00#, 16#1E#, 16#78#, 16#00#, 16#F1#, 16#E0#, 16#0F#, 16#0F#, 16#00#, 16#78#, 16#3C#, 16#07#, 16#C1#, 16#E0#, 16#3C#, 16#07#, 16#83#, 16#E0#, 16#3C#, 16#1E#, 16#00#, 16#F1#, 16#F0#, 16#07#, 16#8F#, 16#00#, 16#1E#, 16#F8#, 16#00#, 16#F0#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#70#, 16#3E#, 16#0F#, 16#83#, 16#F0#, 16#3E#, 16#07#, 16#C0#, 16#F0#, 16#0E#, 16#01#, 16#C0#, 16#00#, 16#3C#, 16#0C#, 16#03#, 16#F9#, 16#F0#, 16#1F#, 16#3F#, 16#80#, 16#F8#, 16#7E#, 16#07#, 16#C1#, 16#F8#, 16#3F#, 16#07#, 16#C0#, 16#F8#, 16#1F#, 16#07#, 16#E0#, 16#7C#, 16#3F#, 16#01#, 16#F0#, 16#FC#, 16#0F#, 16#87#, 16#E0#, 16#3E#, 16#1F#, 16#80#, 16#F8#, 16#7E#, 16#03#, 16#C3#, 16#F8#, 16#1F#, 16#0F#, 16#C0#, 16#7C#, 16#3F#, 16#03#, 16#F0#, 16#FC#, 16#0F#, 16#83#, 16#F0#, 16#7E#, 16#3F#, 16#C2#, 16#F8#, 16#BF#, 16#9B#, 16#E4#, 16#7F#, 16#CF#, 16#E0#, 16#FE#, 16#3F#, 16#01#, 16#E0#, 16#78#, 16#00#, 16#00#, 16#7C#, 16#00#, 16#3F#, 16#F0#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#7E#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#1F#, 16#00#, 16#00#, 16#7C#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#0F#, 16#80#, 16#00#, 16#3E#, 16#3E#, 16#01#, 16#F9#, 16#FC#, 16#07#, 16#CF#, 16#F8#, 16#1F#, 16#47#, 16#F0#, 16#7E#, 16#0F#, 16#C3#, 16#F8#, 16#3F#, 16#0F#, 16#C0#, 16#FC#, 16#3F#, 16#03#, 16#F1#, 16#F8#, 16#0F#, 16#C7#, 16#E0#, 16#3F#, 16#1F#, 16#01#, 16#F8#, 16#7C#, 16#07#, 16#E3#, 16#F0#, 16#1F#, 16#8F#, 16#C0#, 16#FC#, 16#3E#, 16#03#, 16#F1#, 16#F8#, 16#0F#, 16#87#, 16#E0#, 16#7C#, 16#1F#, 16#03#, 16#E0#, 16#FC#, 16#0F#, 16#03#, 16#F0#, 16#78#, 16#0F#, 16#C7#, 16#C0#, 16#1F#, 16#FE#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#00#, 16#3F#, 16#00#, 16#3F#, 16#E0#, 16#1E#, 16#3C#, 16#0F#, 16#0F#, 16#07#, 16#87#, 16#C3#, 16#E1#, 16#F1#, 16#F0#, 16#38#, 16#FC#, 16#00#, 16#3E#, 16#00#, 16#1F#, 16#80#, 16#07#, 16#E0#, 16#01#, 16#F8#, 16#00#, 16#FC#, 16#00#, 16#3F#, 16#00#, 16#0F#, 16#C0#, 16#03#, 16#F0#, 16#00#, 16#FC#, 16#03#, 16#3F#, 16#00#, 16#CF#, 16#E0#, 16#61#, 16#FC#, 16#70#, 16#3F#, 16#F8#, 16#07#, 16#FC#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#00#, 16#00#, 16#80#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#7F#, 16#E0#, 16#00#, 16#07#, 16#F0#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#7C#, 16#00#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#3F#, 16#00#, 16#00#, 16#1F#, 16#80#, 16#07#, 16#9F#, 16#80#, 16#0F#, 16#FF#, 16#C0#, 16#0F#, 16#9F#, 16#E0#, 16#0F#, 16#87#, 16#E0#, 16#0F#, 16#83#, 16#F0#, 16#0F#, 16#C1#, 16#F8#, 16#07#, 16#C0#, 16#F8#, 16#07#, 16#E0#, 16#7C#, 16#07#, 16#E0#, 16#7E#, 16#03#, 16#F0#, 16#3F#, 16#03#, 16#F0#, 16#1F#, 16#81#, 16#F8#, 16#0F#, 16#80#, 16#FC#, 16#0F#, 16#C0#, 16#FE#, 16#07#, 16#E0#, 16#7E#, 16#07#, 16#E0#, 16#3F#, 16#03#, 16#F0#, 16#1F#, 16#83#, 16#F8#, 16#0F#, 16#C1#, 16#F8#, 16#C7#, 16#E1#, 16#FC#, 16#C3#, 16#F9#, 16#BE#, 16#C0#, 16#FF#, 16#9F#, 16#C0#, 16#7F#, 16#8F#, 16#C0#, 16#0F#, 16#83#, 16#C0#, 16#00#, 16#00#, 16#3F#, 16#00#, 16#3F#, 16#E0#, 16#1E#, 16#3C#, 16#0F#, 16#0F#, 16#07#, 16#83#, 16#C3#, 16#E0#, 16#F1#, 16#F0#, 16#3C#, 16#FC#, 16#1E#, 16#3F#, 16#0F#, 16#9F#, 16#83#, 16#C7#, 16#E3#, 16#E1#, 16#FB#, 16#E0#, 16#FF#, 16#E0#, 16#3F#, 16#C0#, 16#0F#, 16#C0#, 16#03#, 16#F0#, 16#00#, 16#FC#, 16#03#, 16#3F#, 16#01#, 16#8F#, 16#C0#, 16#C1#, 16#F8#, 16#70#, 16#7F#, 16#F8#, 16#07#, 16#FC#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#03#, 16#CE#, 16#00#, 16#00#, 16#78#, 16#F0#, 16#00#, 16#0F#, 16#8F#, 16#00#, 16#00#, 16#F0#, 16#F0#, 16#00#, 16#1F#, 16#06#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#00#, 16#3E#, 16#00#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#00#, 16#3E#, 16#00#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#03#, 16#FF#, 16#C0#, 16#00#, 16#3F#, 16#FC#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#00#, 16#0F#, 16#80#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#00#, 16#1F#, 16#00#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#00#, 16#3F#, 16#00#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#00#, 16#3E#, 16#00#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#00#, 16#7C#, 16#00#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#0F#, 16#80#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#00#, 16#0F#, 16#80#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#06#, 16#1F#, 16#00#, 16#00#, 16#F1#, 16#E0#, 16#00#, 16#0F#, 16#3E#, 16#00#, 16#00#, 16#F3#, 16#C0#, 16#00#, 16#07#, 16#F8#, 16#00#, 16#00#, 16#3E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#7F#, 16#F0#, 16#00#, 16#7E#, 16#3F#, 16#E0#, 16#7C#, 16#0F#, 16#F0#, 16#7E#, 16#07#, 16#C0#, 16#7E#, 16#03#, 16#E0#, 16#3F#, 16#01#, 16#F0#, 16#1F#, 16#01#, 16#F8#, 16#0F#, 16#80#, 16#FC#, 16#07#, 16#C0#, 16#FC#, 16#01#, 16#E0#, 16#FC#, 16#00#, 16#78#, 16#FC#, 16#00#, 16#1F#, 16#FC#, 16#00#, 16#0F#, 16#F0#, 16#00#, 16#1C#, 16#00#, 16#00#, 16#1E#, 16#00#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#0F#, 16#F8#, 16#00#, 16#07#, 16#FF#, 16#80#, 16#01#, 16#FF#, 16#F8#, 16#00#, 16#7F#, 16#FE#, 16#00#, 16#77#, 16#FF#, 16#80#, 16#F0#, 16#7F#, 16#C0#, 16#F0#, 16#07#, 16#E0#, 16#F0#, 16#01#, 16#F0#, 16#78#, 16#00#, 16#F8#, 16#3C#, 16#00#, 16#78#, 16#1F#, 16#00#, 16#7C#, 16#07#, 16#C0#, 16#78#, 16#01#, 16#FF#, 16#F8#, 16#00#, 16#1F#, 16#E0#, 16#00#, 16#00#, 16#04#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#1F#, 16#F0#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#0F#, 16#80#, 16#00#, 16#1F#, 16#00#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#1F#, 16#87#, 16#C0#, 16#3E#, 16#1F#, 16#C0#, 16#FC#, 16#7F#, 16#81#, 16#F9#, 16#9F#, 16#03#, 16#E6#, 16#3E#, 16#07#, 16#D8#, 16#7C#, 16#1F#, 16#A0#, 16#F8#, 16#3F#, 16#83#, 16#F0#, 16#7F#, 16#07#, 16#E0#, 16#FC#, 16#0F#, 16#C3#, 16#F8#, 16#3F#, 16#07#, 16#E0#, 16#7E#, 16#0F#, 16#C0#, 16#FC#, 16#3F#, 16#03#, 16#F0#, 16#7E#, 16#07#, 16#E0#, 16#FC#, 16#0F#, 16#C1#, 16#F0#, 16#3F#, 16#17#, 16#E0#, 16#7E#, 16#6F#, 16#C0#, 16#F9#, 16#9F#, 16#01#, 16#F6#, 16#3E#, 16#03#, 16#F8#, 16#FC#, 16#07#, 16#F1#, 16#C0#, 16#07#, 16#80#, 16#01#, 16#E0#, 16#3F#, 16#03#, 16#F0#, 16#3F#, 16#03#, 16#F0#, 16#1E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#C7#, 16#FC#, 16#1F#, 16#C0#, 16#F8#, 16#0F#, 16#81#, 16#F8#, 16#1F#, 16#81#, 16#F0#, 16#1F#, 16#03#, 16#F0#, 16#3E#, 16#03#, 16#E0#, 16#3E#, 16#07#, 16#E0#, 16#7C#, 16#07#, 16#C0#, 16#FC#, 16#2F#, 16#84#, 16#F8#, 16#CF#, 16#98#, 16#FF#, 16#0F#, 16#E0#, 16#78#, 16#00#, 16#00#, 16#00#, 16#78#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#3F#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#01#, 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#01#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#1F#, 16#F0#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#3E#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#7C#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#3E#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#7C#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#3F#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#7E#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#3F#, 16#00#, 16#60#, 16#F8#, 16#03#, 16#C3#, 16#C0#, 16#0F#, 16#1F#, 16#00#, 16#3C#, 16#F8#, 16#00#, 16#7F#, 16#C0#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#00#, 16#06#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#07#, 16#FC#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#03#, 16#E3#, 16#FF#, 16#03#, 16#E0#, 16#FC#, 16#03#, 16#E0#, 16#F0#, 16#07#, 16#E0#, 16#E0#, 16#07#, 16#C1#, 16#C0#, 16#07#, 16#C3#, 16#80#, 16#0F#, 16#C7#, 16#00#, 16#0F#, 16#8E#, 16#00#, 16#0F#, 16#BE#, 16#00#, 16#0F#, 16#FE#, 16#00#, 16#1F#, 16#FE#, 16#00#, 16#1F#, 16#FE#, 16#00#, 16#1F#, 16#3E#, 16#00#, 16#3F#, 16#3F#, 16#00#, 16#3F#, 16#1F#, 16#00#, 16#3E#, 16#1F#, 16#00#, 16#3E#, 16#1F#, 16#04#, 16#7E#, 16#1F#, 16#8C#, 16#7E#, 16#0F#, 16#98#, 16#7C#, 16#0F#, 16#F0#, 16#FC#, 16#07#, 16#E0#, 16#E0#, 16#03#, 16#C0#, 16#00#, 16#08#, 16#0F#, 16#C7#, 16#FE#, 16#07#, 16#E0#, 16#3F#, 16#01#, 16#F8#, 16#0F#, 16#C0#, 16#7C#, 16#07#, 16#E0#, 16#3F#, 16#01#, 16#F0#, 16#0F#, 16#80#, 16#7C#, 16#07#, 16#E0#, 16#3E#, 16#01#, 16#F0#, 16#0F#, 16#80#, 16#F8#, 16#07#, 16#C0#, 16#3E#, 16#03#, 16#E0#, 16#1F#, 16#00#, 16#F8#, 16#0F#, 16#C0#, 16#7C#, 16#03#, 16#E0#, 16#1F#, 16#00#, 16#F8#, 16#8F#, 16#8C#, 16#7C#, 16#43#, 16#E4#, 16#1F#, 16#E0#, 16#FE#, 16#03#, 16#C0#, 16#00#, 16#00#, 16#70#, 16#78#, 16#0F#, 16#83#, 16#FE#, 16#3F#, 16#87#, 16#F8#, 16#1F#, 16#CF#, 16#F1#, 16#FF#, 16#03#, 16#F1#, 16#3E#, 16#73#, 16#E0#, 16#7E#, 16#47#, 16#D8#, 16#7C#, 16#0F#, 16#D0#, 16#FB#, 16#1F#, 16#81#, 16#F4#, 16#3E#, 16#C3#, 16#F0#, 16#3E#, 16#87#, 16#F0#, 16#7C#, 16#0F#, 16#E0#, 16#FE#, 16#1F#, 16#81#, 16#F4#, 16#1F#, 16#83#, 16#F0#, 16#3F#, 16#07#, 16#E0#, 16#7C#, 16#07#, 16#E0#, 16#FC#, 16#1F#, 16#81#, 16#F8#, 16#1F#, 16#83#, 16#F0#, 16#3F#, 16#07#, 16#E0#, 16#7C#, 16#07#, 16#E0#, 16#FC#, 16#0F#, 16#80#, 16#F8#, 16#1F#, 16#03#, 16#F0#, 16#3F#, 16#07#, 16#E0#, 16#7E#, 16#07#, 16#E0#, 16#FC#, 16#0F#, 16#88#, 16#F8#, 16#1F#, 16#81#, 16#F3#, 16#3F#, 16#03#, 16#E0#, 16#3E#, 16#47#, 16#E0#, 16#FC#, 16#07#, 16#F0#, 16#FC#, 16#1F#, 16#80#, 16#FE#, 16#18#, 16#00#, 16#00#, 16#0F#, 16#00#, 16#00#, 16#70#, 16#F8#, 16#7F#, 16#C3#, 16#F8#, 16#1F#, 16#8F#, 16#F0#, 16#3F#, 16#33#, 16#E0#, 16#7C#, 16#87#, 16#C1#, 16#F9#, 16#0F#, 16#83#, 16#F4#, 16#1F#, 16#07#, 16#D0#, 16#3E#, 16#0F#, 16#E0#, 16#FC#, 16#3F#, 16#81#, 16#F8#, 16#7F#, 16#03#, 16#E0#, 16#FC#, 16#0F#, 16#C1#, 16#F8#, 16#1F#, 16#87#, 16#E0#, 16#3E#, 16#0F#, 16#C0#, 16#FC#, 16#1F#, 16#81#, 16#F0#, 16#3E#, 16#03#, 16#E0#, 16#FC#, 16#0F#, 16#C9#, 16#F8#, 16#1F#, 16#33#, 16#E0#, 16#3E#, 16#47#, 16#C0#, 16#7F#, 16#1F#, 16#80#, 16#FE#, 16#38#, 16#00#, 16#F0#, 16#00#, 16#00#, 16#3F#, 16#00#, 16#0E#, 16#38#, 16#03#, 16#C1#, 16#C0#, 16#78#, 16#1E#, 16#0F#, 16#81#, 16#F0#, 16#F0#, 16#1F#, 16#1F#, 16#01#, 16#F3#, 16#E0#, 16#1F#, 16#3E#, 16#03#, 16#F7#, 16#C0#, 16#3F#, 16#7C#, 16#03#, 16#F7#, 16#C0#, 16#3E#, 16#FC#, 16#03#, 16#EF#, 16#C0#, 16#7E#, 16#F8#, 16#07#, 16#CF#, 16#80#, 16#7C#, 16#F8#, 16#0F#, 16#8F#, 16#80#, 16#F8#, 16#F8#, 16#1F#, 16#07#, 16#81#, 16#E0#, 16#78#, 16#3C#, 16#03#, 16#C7#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#00#, 16#0F#, 16#1F#, 16#00#, 16#3F#, 16#E7#, 16#F8#, 16#01#, 16#F9#, 16#FF#, 16#00#, 16#1F#, 16#47#, 16#F0#, 16#07#, 16#F0#, 16#7E#, 16#00#, 16#FE#, 16#0F#, 16#C0#, 16#1F#, 16#81#, 16#F8#, 16#03#, 16#F0#, 16#3F#, 16#00#, 16#FC#, 16#07#, 16#E0#, 16#1F#, 16#81#, 16#FC#, 16#03#, 16#E0#, 16#3F#, 16#00#, 16#7C#, 16#07#, 16#E0#, 16#1F#, 16#81#, 16#FC#, 16#03#, 16#F0#, 16#3F#, 16#00#, 16#7C#, 16#07#, 16#E0#, 16#0F#, 16#81#, 16#F8#, 16#03#, 16#F0#, 16#3E#, 16#00#, 16#7E#, 16#0F#, 16#C0#, 16#0F#, 16#81#, 16#F0#, 16#01#, 16#F0#, 16#7C#, 16#00#, 16#7F#, 16#1F#, 16#00#, 16#0F#, 16#FF#, 16#C0#, 16#01#, 16#F3#, 16#E0#, 16#00#, 16#3E#, 16#00#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#00#, 16#3E#, 16#00#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#01#, 16#F8#, 16#00#, 16#00#, 16#7F#, 16#00#, 16#00#, 16#3F#, 16#FC#, 16#00#, 16#00#, 16#00#, 16#3E#, 16#00#, 16#03#, 16#F9#, 16#F0#, 16#1F#, 16#1F#, 16#C0#, 16#F8#, 16#7E#, 16#07#, 16#C1#, 16#F8#, 16#3F#, 16#07#, 16#E0#, 16#F8#, 16#1F#, 16#87#, 16#E0#, 16#7C#, 16#3F#, 16#01#, 16#F0#, 16#FC#, 16#0F#, 16#C7#, 16#E0#, 16#3E#, 16#1F#, 16#80#, 16#F8#, 16#7E#, 16#07#, 16#E3#, 16#F0#, 16#1F#, 16#8F#, 16#C0#, 16#7C#, 16#3F#, 16#03#, 16#F0#, 16#FC#, 16#0F#, 16#C3#, 16#F0#, 16#7E#, 16#0F#, 16#C3#, 16#F8#, 16#3F#, 16#9B#, 16#E0#, 16#7F#, 16#DF#, 16#01#, 16#FE#, 16#7C#, 16#01#, 16#F1#, 16#F0#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#3E#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#1F#, 16#80#, 16#00#, 16#7C#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#7F#, 16#F8#, 16#00#, 16#00#, 16#71#, 16#E1#, 16#FF#, 16#3E#, 16#07#, 16#E7#, 16#F0#, 16#7E#, 16#FF#, 16#07#, 16#E9#, 16#E0#, 16#7D#, 16#0E#, 16#07#, 16#D0#, 16#00#, 16#FE#, 16#00#, 16#0F#, 16#E0#, 16#00#, 16#FC#, 16#00#, 16#0F#, 16#C0#, 16#01#, 16#FC#, 16#00#, 16#1F#, 16#80#, 16#01#, 16#F8#, 16#00#, 16#1F#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#3F#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#7E#, 16#00#, 16#07#, 16#E0#, 16#00#, 16#7E#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#01#, 16#F1#, 16#07#, 16#FF#, 16#0F#, 16#0F#, 16#0E#, 16#07#, 16#1E#, 16#06#, 16#1E#, 16#06#, 16#1F#, 16#02#, 16#1F#, 16#02#, 16#1F#, 16#80#, 16#0F#, 16#C0#, 16#0F#, 16#E0#, 16#0F#, 16#F0#, 16#07#, 16#F8#, 16#03#, 16#F8#, 16#01#, 16#FC#, 16#00#, 16#FC#, 16#40#, 16#7C#, 16#40#, 16#7C#, 16#60#, 16#3C#, 16#E0#, 16#38#, 16#F0#, 16#38#, 16#F8#, 16#F0#, 16#DF#, 16#C0#, 16#00#, 16#20#, 16#03#, 16#00#, 16#38#, 16#03#, 16#80#, 16#3C#, 16#03#, 16#E0#, 16#7F#, 16#07#, 16#FF#, 16#3F#, 16#F8#, 16#7C#, 16#07#, 16#E0#, 16#3F#, 16#01#, 16#F0#, 16#0F#, 16#80#, 16#FC#, 16#07#, 16#C0#, 16#3E#, 16#03#, 16#F0#, 16#1F#, 16#80#, 16#F8#, 16#07#, 16#C0#, 16#7E#, 16#03#, 16#F1#, 16#1F#, 16#08#, 16#F8#, 16#87#, 16#C8#, 16#3F#, 16#C1#, 16#FC#, 16#07#, 16#80#, 16#00#, 16#00#, 16#40#, 16#00#, 16#1F#, 16#03#, 16#F7#, 16#F8#, 16#0F#, 16#87#, 16#E0#, 16#3E#, 16#1F#, 16#81#, 16#F8#, 16#7E#, 16#07#, 16#C1#, 16#F0#, 16#1F#, 16#07#, 16#C0#, 16#FC#, 16#3F#, 16#03#, 16#E0#, 16#F8#, 16#0F#, 16#83#, 16#E0#, 16#7E#, 16#0F#, 16#81#, 16#F0#, 16#7E#, 16#0F#, 16#C1#, 16#F0#, 16#3F#, 16#07#, 16#C1#, 16#FC#, 16#1F#, 16#07#, 16#E0#, 16#F8#, 16#2F#, 16#83#, 16#E1#, 16#3C#, 16#6F#, 16#8D#, 16#F1#, 16#3E#, 16#67#, 16#C8#, 16#FF#, 16#1F#, 16#E3#, 16#F8#, 16#7F#, 16#07#, 16#C0#, 16#F0#, 16#00#, 16#06#, 16#07#, 16#1F#, 16#07#, 16#BF#, 16#83#, 16#E7#, 16#C1#, 16#F3#, 16#E0#, 16#F9#, 16#F8#, 16#3C#, 16#7C#, 16#0C#, 16#3E#, 16#06#, 16#1F#, 16#03#, 16#0F#, 16#83#, 16#07#, 16#C1#, 16#83#, 16#E1#, 16#81#, 16#F1#, 16#80#, 16#F9#, 16#80#, 16#7C#, 16#C0#, 16#3E#, 16#C0#, 16#1F#, 16#C0#, 16#0F#, 16#C0#, 16#07#, 16#C0#, 16#03#, 16#C0#, 16#01#, 16#C0#, 16#00#, 16#C0#, 16#00#, 16#40#, 16#00#, 16#06#, 16#01#, 16#81#, 16#C7#, 16#C0#, 16#30#, 16#7F#, 16#F8#, 16#0E#, 16#0F#, 16#9F#, 16#01#, 16#C1#, 16#F3#, 16#E0#, 16#78#, 16#3E#, 16#7C#, 16#1F#, 16#03#, 16#CF#, 16#C3#, 16#E0#, 16#30#, 16#F8#, 16#FC#, 16#06#, 16#1F#, 16#1F#, 16#C0#, 16#83#, 16#E7#, 16#F8#, 16#30#, 16#7C#, 16#FF#, 16#04#, 16#0F#, 16#B7#, 16#E1#, 16#81#, 16#F6#, 16#FC#, 16#60#, 16#3F#, 16#8F#, 16#98#, 16#07#, 16#E1#, 16#F3#, 16#00#, 16#FC#, 16#3E#, 16#C0#, 16#1F#, 16#07#, 16#F0#, 16#03#, 16#E0#, 16#FC#, 16#00#, 16#78#, 16#1F#, 16#80#, 16#0F#, 16#03#, 16#E0#, 16#01#, 16#C0#, 16#78#, 16#00#, 16#30#, 16#0E#, 16#00#, 16#06#, 16#01#, 16#80#, 16#00#, 16#00#, 16#F0#, 16#1E#, 16#0F#, 16#F0#, 16#3E#, 16#01#, 16#F8#, 16#7F#, 16#01#, 16#F8#, 16#FF#, 16#00#, 16#F9#, 16#8E#, 16#00#, 16#FB#, 16#00#, 16#00#, 16#FF#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#00#, 16#7C#, 16#00#, 16#00#, 16#7C#, 16#00#, 16#00#, 16#7C#, 16#00#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#FE#, 16#00#, 16#01#, 16#BF#, 16#00#, 16#01#, 16#BF#, 16#08#, 16#73#, 16#1F#, 16#18#, 16#FF#, 16#1F#, 16#30#, 16#FE#, 16#1F#, 16#E0#, 16#FC#, 16#0F#, 16#C0#, 16#78#, 16#07#, 16#80#, 16#00#, 16#30#, 16#1C#, 16#0F#, 16#F0#, 16#7C#, 16#07#, 16#E0#, 16#F8#, 16#0F#, 16#C1#, 16#F0#, 16#0F#, 16#C1#, 16#E0#, 16#1F#, 16#81#, 16#C0#, 16#3F#, 16#03#, 16#00#, 16#3E#, 16#06#, 16#00#, 16#7E#, 16#08#, 16#00#, 16#FC#, 16#30#, 16#01#, 16#F8#, 16#60#, 16#01#, 16#F1#, 16#80#, 16#03#, 16#E3#, 16#00#, 16#07#, 16#CC#, 16#00#, 16#0F#, 16#D8#, 16#00#, 16#1F#, 16#E0#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#3F#, 16#00#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#07#, 16#00#, 16#00#, 16#0C#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#60#, 16#01#, 16#C1#, 16#80#, 16#07#, 16#E6#, 16#00#, 16#0F#, 16#F8#, 16#00#, 16#1F#, 16#C0#, 16#00#, 16#1E#, 16#00#, 16#00#, 16#00#, 16#07#, 16#FF#, 16#E1#, 16#FF#, 16#F8#, 16#3F#, 16#FF#, 16#07#, 16#FF#, 16#C0#, 16#80#, 16#70#, 16#30#, 16#1C#, 16#04#, 16#07#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#30#, 16#00#, 16#0E#, 16#00#, 16#03#, 16#80#, 16#00#, 16#60#, 16#00#, 16#18#, 16#00#, 16#06#, 16#00#, 16#01#, 16#80#, 16#00#, 16#30#, 16#00#, 16#0C#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#FE#, 16#00#, 16#1F#, 16#E0#, 16#C7#, 16#FC#, 16#3D#, 16#CF#, 16#C7#, 16#90#, 16#F8#, 16#F0#, 16#07#, 16#9C#, 16#00#, 16#3E#, 16#00#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#FC#, 16#00#, 16#1F#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#7C#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#78#, 16#00#, 16#0F#, 16#80#, 16#00#, 16#F8#, 16#00#, 16#0F#, 16#80#, 16#01#, 16#F0#, 16#00#, 16#1F#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#1F#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#3E#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#78#, 16#00#, 16#1E#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#1F#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#0F#, 16#80#, 16#00#, 16#F8#, 16#00#, 16#0F#, 16#80#, 16#01#, 16#F0#, 16#00#, 16#1F#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#1F#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#3E#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#3E#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#7C#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#7C#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#7E#, 16#00#, 16#03#, 16#F0#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#F0#, 16#00#, 16#3E#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#3E#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#3E#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#7C#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#7C#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#F8#, 16#00#, 16#0F#, 16#80#, 16#00#, 16#F8#, 16#00#, 16#0F#, 16#80#, 16#01#, 16#F0#, 16#00#, 16#1F#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#1F#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#78#, 16#00#, 16#1E#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#7C#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#F8#, 16#00#, 16#0F#, 16#80#, 16#00#, 16#F8#, 16#00#, 16#0F#, 16#80#, 16#01#, 16#F0#, 16#00#, 16#1F#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#1E#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#3E#, 16#00#, 16#07#, 16#C0#, 16#00#, 16#7C#, 16#00#, 16#0F#, 16#80#, 16#03#, 16#F0#, 16#00#, 16#F8#, 16#00#, 16#00#, 16#1F#, 16#00#, 16#03#, 16#FF#, 16#01#, 16#3F#, 16#FE#, 16#1D#, 16#FF#, 16#FF#, 16#FE#, 16#0F#, 16#FF#, 16#00#, 16#1F#, 16#F0#, 16#00#, 16#1F#, 16#00#); FreeSerifBoldItalic24pt7bGlyphs : aliased constant Glyph_Array := ( (0, 0, 0, 12, 0, 1), -- 0x20 ' ' (0, 15, 33, 18, 3, -31), -- 0x21 '!' (62, 19, 13, 26, 6, -31), -- 0x22 '"' (93, 27, 33, 23, -2, -32), -- 0x23 '#' (205, 24, 39, 24, -1, -33), -- 0x24 '$' (322, 35, 32, 39, 2, -30), -- 0x25 '%' (462, 33, 33, 37, 0, -31), -- 0x26 '&' (599, 7, 13, 13, 6, -31), -- 0x27 ''' (611, 14, 41, 16, 1, -31), -- 0x28 '(' (683, 14, 41, 16, -2, -31), -- 0x29 ')' (755, 19, 20, 23, 3, -31), -- 0x2A '*' (803, 22, 23, 27, 2, -22), -- 0x2B '+' (867, 10, 15, 12, -3, -5), -- 0x2C ',' (886, 12, 5, 16, 0, -12), -- 0x2D '-' (894, 8, 7, 12, 0, -5), -- 0x2E '.' (901, 19, 33, 16, 0, -31), -- 0x2F '/' (980, 22, 33, 23, 1, -31), -- 0x30 '0' (1071, 20, 32, 23, 0, -31), -- 0x31 '1' (1151, 22, 32, 23, 1, -31), -- 0x32 '2' (1239, 22, 33, 24, 0, -31), -- 0x33 '3' (1330, 25, 32, 23, 0, -31), -- 0x34 '4' (1430, 24, 32, 24, 0, -30), -- 0x35 '5' (1526, 23, 32, 24, 1, -30), -- 0x36 '6' (1618, 23, 31, 23, 3, -30), -- 0x37 '7' (1708, 21, 33, 23, 1, -31), -- 0x38 '8' (1795, 23, 33, 23, 0, -31), -- 0x39 '9' (1890, 13, 22, 12, 0, -20), -- 0x3A ':' (1926, 15, 30, 12, -2, -20), -- 0x3B ';' (1983, 24, 25, 27, 1, -23), -- 0x3C '<' (2058, 24, 14, 27, 3, -18), -- 0x3D '=' (2100, 24, 25, 27, 3, -23), -- 0x3E '>' (2175, 18, 33, 24, 4, -31), -- 0x3F '?' (2250, 33, 33, 39, 3, -31), -- 0x40 '@' (2387, 31, 32, 33, 0, -31), -- 0x41 'A' (2511, 31, 31, 30, 0, -30), -- 0x42 'B' (2632, 29, 33, 29, 2, -31), -- 0x43 'C' (2752, 35, 31, 34, 0, -30), -- 0x44 'D' (2888, 32, 31, 30, 0, -30), -- 0x45 'E' (3012, 31, 31, 29, 0, -30), -- 0x46 'F' (3133, 32, 33, 33, 2, -31), -- 0x47 'G' (3265, 39, 31, 35, 0, -30), -- 0x48 'H' (3417, 21, 31, 18, 0, -30), -- 0x49 'I' (3499, 27, 36, 23, 0, -30), -- 0x4A 'J' (3621, 34, 31, 31, 0, -30), -- 0x4B 'K' (3753, 29, 31, 29, 0, -30), -- 0x4C 'L' (3866, 44, 32, 41, 0, -30), -- 0x4D 'M' (4042, 37, 32, 33, 0, -30), -- 0x4E 'N' (4190, 31, 33, 32, 2, -31), -- 0x4F 'O' (4318, 31, 31, 28, 0, -30), -- 0x50 'P' (4439, 31, 42, 32, 2, -31), -- 0x51 'Q' (4602, 32, 31, 31, 0, -30), -- 0x52 'R' (4726, 24, 33, 24, 0, -31), -- 0x53 'S' (4825, 27, 31, 28, 4, -30), -- 0x54 'T' (4930, 32, 32, 34, 5, -30), -- 0x55 'U' (5058, 31, 32, 33, 6, -30), -- 0x56 'V' (5182, 41, 32, 44, 6, -30), -- 0x57 'W' (5346, 34, 31, 33, 0, -30), -- 0x58 'X' (5478, 28, 31, 30, 6, -30), -- 0x59 'Y' (5587, 28, 31, 26, 0, -30), -- 0x5A 'Z' (5696, 19, 38, 16, -2, -30), -- 0x5B '[' (5787, 13, 33, 19, 6, -31), -- 0x5C '\' (5841, 19, 38, 16, -3, -30), -- 0x5D ']' (5932, 21, 17, 27, 3, -30), -- 0x5E '^' (5977, 24, 3, 23, 0, 5), -- 0x5F '_' (5986, 10, 9, 16, 4, -32), -- 0x60 '`' (5998, 22, 23, 24, 1, -21), -- 0x61 'a' (6062, 22, 33, 23, 1, -31), -- 0x62 'b' (6153, 18, 23, 20, 1, -21), -- 0x63 'c' (6205, 25, 34, 24, 1, -32), -- 0x64 'd' (6312, 18, 23, 20, 1, -21), -- 0x65 'e' (6364, 28, 41, 23, -4, -31), -- 0x66 'f' (6508, 25, 31, 23, -1, -21), -- 0x67 'g' (6605, 23, 34, 26, 1, -32), -- 0x68 'h' (6703, 12, 33, 14, 2, -31), -- 0x69 'i' (6753, 22, 42, 16, -4, -31), -- 0x6A 'j' (6869, 24, 34, 24, 1, -32), -- 0x6B 'k' (6971, 13, 34, 14, 2, -32), -- 0x6C 'l' (7027, 35, 23, 36, 0, -21), -- 0x6D 'm' (7128, 23, 23, 25, 0, -21), -- 0x6E 'n' (7195, 20, 23, 22, 1, -21), -- 0x6F 'o' (7253, 27, 31, 23, -4, -21), -- 0x70 'p' (7358, 22, 31, 23, 1, -21), -- 0x71 'q' (7444, 20, 22, 19, 0, -21), -- 0x72 'r' (7499, 16, 23, 17, 0, -21), -- 0x73 's' (7545, 13, 29, 13, 2, -27), -- 0x74 't' (7593, 22, 23, 25, 2, -21), -- 0x75 'u' (7657, 17, 23, 21, 3, -21), -- 0x76 'v' (7706, 27, 23, 31, 3, -21), -- 0x77 'w' (7784, 24, 23, 22, -1, -21), -- 0x78 'x' (7853, 23, 31, 20, -3, -21), -- 0x79 'y' (7943, 19, 25, 19, 0, -20), -- 0x7A 'z' (8003, 20, 41, 16, 0, -31), -- 0x7B '{' (8106, 4, 33, 13, 5, -31), -- 0x7C '|' (8123, 20, 41, 16, -6, -31), -- 0x7D '}' (8226, 21, 7, 27, 3, -14)); -- 0x7E '~' Font_D : aliased constant Bitmap_Font := (FreeSerifBoldItalic24pt7bBitmaps'Access, FreeSerifBoldItalic24pt7bGlyphs'Access, 56); Font : constant Giza.Font.Ref_Const := Font_D'Access; end Giza.Bitmap_Fonts.FreeSerifBoldItalic24pt7b;
----------------------------------------------------------------------- -- openapi-clients -- Rest client support -- Copyright (C) 2017, 2018, 2020, 2022 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.Http.Clients; private with Util.Streams.Texts; with OpenAPI.Streams; with OpenAPI.Credentials; with Util.Serialize.IO; -- == REST Client == -- The <tt>OpenAPI.Clients</tt> package implements the support used by the code generator -- to make REST client operations. package OpenAPI.Clients is -- Exception raised when an API was not found. Not_Found : exception; -- Exception raised when a parameter is invalid. Parameter_Error : exception; -- Exception raised when the caller is not authorized. Authorization_Error : exception; -- Exception raised when the caller does not have the permission. Permission_Error : exception; type Request_Type is tagged limited private; type Stream_Accessor (Stream : access OpenAPI.Streams.Output_Stream'Class) is private with Implicit_Dereference => Stream; function Stream (Req : in Request_Type) return Stream_Accessor; type Operation_Type is (HEAD, GET, POST, PUT, DELETE, OPTIONS, PATCH); -- The possible content types that are supported by the OpenAPI Ada client library. type Content_Type is (APPLICATION_JSON, APPLICATION_XML, APPLICATION_FORM, TEXT_PLAIN); -- A list of content types for the Set_Accept and Initialize operations. type Content_Type_Array is array (Positive range <>) of Content_Type; type URI_Type is tagged private; -- Set the path to use for the URI. procedure Set_Path (URI : in out URI_Type; Path : in String); -- Set the path parameter. procedure Set_Path_Param (URI : in out URI_Type; Name : in String; Value : in String); -- Set the path parameter. procedure Set_Path_Param (URI : in out URI_Type; Name : in String; Value : in UString); -- Add a query parameter. procedure Add_Param (URI : in out URI_Type; Name : in String; Value : in String); -- Add a query parameter. procedure Add_Param (URI : in out URI_Type; Name : in String; Value : in UString); procedure Add_Param (URI : in out URI_Type; Name : in String; Value : in Nullable_UString); -- Add a query parameter. procedure Add_Param (URI : in out URI_Type; Name : in String; Value : in Boolean); procedure Add_Param (URI : in out URI_Type; Name : in String; Value : in Nullable_Boolean); -- Add a query parameter. procedure Add_Param (URI : in out URI_Type; Name : in String; Value : in UString_Vectors.Vector); procedure Add_Param (URI : in out URI_Type; Name : in String; Value : in Nullable_UString_Vectors.Vector); -- Convert the URI into a string. function To_String (URI : in URI_Type) return String; type Client_Type is new Util.Http.Clients.Client with private; -- Set the server base URI to connect to. procedure Set_Server (Client : in out Client_Type; Server : in String); procedure Set_Server (Client : in out Client_Type; Server : in UString); -- Set the credential instance that is responsible for populating the HTTP request -- before sending the request. procedure Set_Credentials (Client : in out Client_Type; Credential : access OpenAPI.Credentials.Credential_Type'Class); procedure Call (Client : in out Client_Type; Operation : in Operation_Type; URI : in URI_Type'Class; Request : in Request_Type'Class); procedure Call (Client : in out Client_Type; Operation : in Operation_Type; URI : in URI_Type'Class); procedure Call (Client : in out Client_Type; Operation : in Operation_Type; URI : in URI_Type'Class; Reply : out Value_Type); procedure Call (Client : in out Client_Type; Operation : in Operation_Type; URI : in URI_Type'Class; Request : in Request_Type'Class; Reply : out Value_Type); -- Set the Accept header according to what the operation supports and what is -- selected by the client. procedure Set_Accept (Client : in out Client_Type; List : in Content_Type_Array); -- Handle an error after an API call. The default implementation raises an exception -- if the HTTP status code is 400, 401 or 403. procedure Error (Client : in out Client_Type; Status : in Natural; Response : in Util.Http.Clients.Response'Class); -- Get the HTTP response code status. function Get_Status (Client : in Client_Type) return Natural; -- Initialize the request body to prepare for the serialization of data using -- a supported and configured content type. procedure Initialize (Client : in out Client_Type; Request : in out Request_Type'Class; Types : in Content_Type_Array); private type Request_Type is tagged limited record Buffer : aliased Util.Streams.Texts.Print_Stream; Data : access Util.Serialize.IO.Output_Stream'Class; end record; type Client_Type is new Util.Http.Clients.Client with record Server : UString; Credential : access OpenAPI.Credentials.Credential_Type'Class; Response : Util.Http.Clients.Response; end record; type Stream_Accessor (Stream : access OpenAPI.Streams.Output_Stream'Class) is record N : Natural := 0; end record; type URI_Type is tagged record URI : UString; Query : UString; end record; end OpenAPI.Clients;
with Ada.Text_IO; with c_code_h; procedure Ada_C_Ada_Main is package ATI renames Ada.Text_Io; begin ATI.Put_Line ("Ada_C_Ada_Main: Calling c_ada_caller"); c_code_h.c_ada_caller; ATI.Put_Line ("Ada_C_Ada_Main: Returned from c_ada_caller"); end Ada_C_Ada_Main;
------------------------------------------------------------------------------- -- Copyright (c) 2019, Daniel King -- 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. -- * The name of the copyright holder may not 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 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 Keccak.Types; -- @summary -- Generic parallel sponge construction. -- -- @description -- This parallel sponge is built on top of a parallel permutation, which -- can perform multiple separate permutations in parallel by taking -- advantage of SIMD instructions sets (e.g. SSE2, AVX2). -- -- @group Sponge generic State_Size : Positive; -- Size in bits of the underlying permutation state. -- E.g. for Keccak-f[1600] this should be set to 1600. type State_Type is private; -- Type of the parallel permutation state. Parallelism : Positive; -- Number of parallel instances provided by State_Type. with procedure Init (S : out State_Type); -- Initializes the parallel permutation states. with procedure Permute_All (S : in out State_Type); -- Applies the permutation function to each state in parallel. with procedure XOR_Bits_Into_State_Separate (S : in out State_Type; Data : in Types.Byte_Array; Data_Offset : in Natural; Bit_Len : in Natural); -- XOR bits into a specific instance of the permutation state. with procedure XOR_Bits_Into_State_All (S : in out State_Type; Data : in Types.Byte_Array; Bit_Len : in Natural); with procedure Extract_Bytes (S : in State_Type; Data : in out Keccak.Types.Byte_Array; Data_Offset : in Natural; Byte_Len : in Natural); -- Extracts a bytes of output from the state with procedure Pad (Block : in out Keccak.Types.Byte_Array; Num_Used_Bits : in Natural; Max_Bit_Length : in Natural); -- Apply the padding rule to a block of data. Min_Padding_Bits : Natural; -- Minimum number of padding bits appended to the message. -- -- E.g. for pad10*1 there are a minimum of 2 padding bits (two '1' bits). package Keccak.Generic_Parallel_Sponge is Num_Parallel_Instances : constant Positive := Parallelism; Block_Size_Bits : constant Positive := State_Size; subtype Rate_Bits_Number is Positive range 1 .. State_Size - 1 with Dynamic_Predicate => Rate_Bits_Number mod 8 = 0; -- Number representing the Rate (in bits). -- -- The Rate must be a positive integer, and less than the size of the -- state (i.e. there must be at least 1 bit of "capacity"). Furthermore, -- this implementation restricts the Rate to a multiple of 8 bits. type Context (Capacity : Positive) is private; type States is (Absorbing, Squeezing, Finished); procedure Init (Ctx : out Context) with Global => null, Pre => (Ctx.Capacity < State_Size and then (State_Size - Ctx.Capacity) mod 8 = 0), Post => State_Of (Ctx) = Absorbing; -- Initialise the sponge. procedure Absorb_Bytes_Separate (Ctx : in out Context; Data : in Types.Byte_Array) with Global => null, Pre => (Data'Length mod Num_Parallel_Instances = 0 and Data'Length / Num_Parallel_Instances <= Natural'Last / 8 and State_Of (Ctx) = Absorbing), Contract_Cases => ((Data'Length / Num_Parallel_Instances) mod (Rate_Of (Ctx) / 8) = 0 => State_Of (Ctx) = Absorbing, others => State_Of (Ctx) = Squeezing); -- Split a buffer and asborb each chunk into separate parallel instances. -- -- The Data buffer is split into N equal-sized chunks, where N is the -- number of parallel instances. For example, with Keccak-f[1600]x4, the -- Data will be split into four chunks of equal length: -- -- +-----------+-----------+-----------+-----------+ -- | 0 | 1 | 2 | 3 | Data (split into N chunks) -- +-----------+-----------+-----------+-----------+ -- | | | | Absorb -- V V V V -- +-----------+-----------+-----------+-----------+ -- | 0 | 1 | 2 | 3 | Context (N parallel instances) -- +-----------+-----------+-----------+-----------+ -- -- Chunk 0 will be absorbed into the first parallel instance; chunk 1 will -- be absorbed into the second parallel instance, and so on... -- -- This procedure can be called multiple times to absorb an arbitrary -- amount of data, provided that the length of each chunk is a multiple -- of the rate. If the chunk length is not a multiple of the rate then -- the data will be absorbed, but the Context will advance to the -- Squeezing state and no more data can be absorbed. procedure Absorb_Bytes_All (Ctx : in out Context; Data : in Types.Byte_Array) with Global => null, Pre => State_Of (Ctx) = Absorbing, Contract_Cases => (Data'Length mod (Rate_Of (Ctx) / 8) = 0 => State_Of (Ctx) = Absorbing, others => State_Of (Ctx) = Squeezing); -- Absorb the same data into all parallel instances. -- -- . +--------------+ -- . | | Data -- . +--------------+ -- . .---------' / \ '--------. -- . / / \ \ Absorb -- . V V V V -- +-----------+-----------+-----------+-----------+ -- | 0 | 1 | 2 | 3 | Context (N parallel instances) -- +-----------+-----------+-----------+-----------+ -- -- This procedure can be called multiple times to absorb an arbitrary -- amount of data, provided that the length of each chunk is a multiple -- of the rate. If the chunk length is not a multiple of the rate then -- the data will be absorbed, but the Context will advance to the -- Squeezing state and no more data can be absorbed. procedure Absorb_Bytes_Separate_With_Suffix (Ctx : in out Context; Data : in Types.Byte_Array; Suffix : in Types.Byte; Suffix_Len : in Natural) with Global => null, Pre => (Data'Length mod Num_Parallel_Instances = 0 and Data'Length / Num_Parallel_Instances <= Natural'Last / 8 and Suffix_Len in 0 .. 8 - Min_Padding_Bits and State_Of (Ctx) = Absorbing), Post => State_Of (Ctx) = Squeezing; -- Same as Absorb_Bytes_Separate, but suffix bits are also appended to -- each chunk during absorption. procedure Absorb_Bytes_All_With_Suffix (Ctx : in out Context; Data : in Types.Byte_Array; Suffix : in Types.Byte; Suffix_Len : in Natural) with Global => null, Pre => (State_Of (Ctx) = Absorbing and Suffix_Len in 0 .. 8 - Min_Padding_Bits), Post => State_Of (Ctx) = Squeezing; -- Same as Absorb_Bytes_All, but suffix bits are also appended to the data -- during absorption. procedure Squeeze_Bytes_Separate (Ctx : in out Context; Data : out Types.Byte_Array) with Global => null, Pre => (Data'Length mod Num_Parallel_Instances = 0 and State_Of (Ctx) in Absorbing | Squeezing), Post => Rate_Of (Ctx) = Rate_Of (Ctx'Old), Contract_Cases => ((Data'Length / Num_Parallel_Instances) mod (Rate_Of (Ctx) / 8) = 0 => State_Of (Ctx) = Squeezing, others => State_Of (Ctx) = Finished); -- Get output bytes from all parallel instances. -- -- +-----------+-----------+-----------+-----------+ -- | 0 | 1 | 2 | 3 | Context (N parallel instances) -- +-----------+-----------+-----------+-----------+ -- | | | | Extract -- V V V V -- +-----------+-----------+-----------+-----------+ -- | 0 | 1 | 2 | 3 | Data (split into N chunks) -- +-----------+-----------+-----------+-----------+ -- -- This function may be called multiple times to generate a large amount of -- output data, as long as the length of the Data buffer is a multiple of -- N * Rate, where N is Num_Parallel_Instances and Rate is the Rate parameter -- in bytes. If the Data buffer length does not meet this criterea, then -- the context enters the Finished state and no more output bytes can be -- produced. pragma Annotate (GNATprove, False_Positive, """Data"" might not be initialized", "GNATprove issues a false positive due to the use of loops to initialize Data"); function State_Of (Ctx : in Context) return States; -- Get the current state of the context. function Rate_Of (Ctx : in Context) return Rate_Bits_Number; -- Get the configured rate parameter (in bits). private subtype Rate_Bytes_Number is Positive range 1 .. ((State_Size + 7) / 8) - 1; -- The rate number here represents bytes, not bits. -- This makes it easier to handle in proof, since bytes are -- always a multiple of 8 bits. type Context (Capacity : Positive) is record Permutation_State : State_Type; Rate : Rate_Bytes_Number; State : States; end record with Predicate => (Context.Rate = (State_Size - Context.Capacity) / 8 and then (State_Size - Context.Capacity) mod 8 = 0 and then Context.Rate * 8 = State_Size - Context.Capacity); function State_Of (Ctx : in Context) return States is (Ctx.State); function Rate_Of (Ctx : in Context) return Rate_Bits_Number is (Ctx.Rate * 8); end Keccak.Generic_Parallel_Sponge;
with Ada.Numerics.Elementary_Functions; Package body CompStats_Statistics is function Get_Count (Values: Values_Array) return Integer is Count: Integer; -- Stores final count begin Count := Values'Length; return Count; end Get_Count; -------------------------------------------------------------- function Get_Minimum (Values: Values_Array) return Float is Count: Integer; -- Length of array Minimum: Float; -- Stores minimum begin Count := Get_Count(Values); Minimum := Values(1); for index in Integer range 2 .. Count loop if Values(index) < Minimum then Minimum := Values(index); end if; end loop; return Minimum; end Get_Minimum; -------------------------------------------------------------- function Get_Maximum (Values: Values_Array) return Float is Count: Integer; -- Length of array Maximum: Float; -- Stores maximum begin Count := Get_Count(Values); Maximum := Values(1); for index in Integer range 2 .. Count loop if Values(index) > Maximum then Maximum := Values(index); end if; end loop; return Maximum; end Get_Maximum; -------------------------------------------------------------- function Get_Range (Values: Values_Array) return Float is CS_Range: Float; -- Stores range Minimum: Float; Maximum: Float; begin Minimum := Get_Minimum(Values); Maximum := Get_Maximum(Values); CS_Range := Maximum - Minimum; return CS_Range; end Get_Range; -------------------------------------------------------------- function Get_Sum (Values: Values_Array) return Float is Sum: Float; Count: Integer; begin Count := Get_Count(values); if count = 0 then return 0.0; -- should throw an error end if; Sum := 0.0; for index in Integer range 1 .. Count loop Sum := Sum + Values(index); end loop; return Sum; end Get_Sum; -------------------------------------------------------------- function Get_Mean (Values: Values_Array) return Float is Mean: Float; Sum: Float; Count: Integer; begin Count := Get_Count(values); if count = 0 then return 0.0; -- should throw an error end if; Sum := Get_Sum(Values); Mean := Sum / Float(count); return Mean; end Get_Mean; -------------------------------------------------------------- function Get_Sum_Of_Squares (Values: Values_Array) return Float is SS: Float; Mean:Float; Difference: Float; Count : Integer; begin SS := 0.0; Count := Get_Count(values); if count = 0 then return 0.0; -- should throw an error end if; Mean := Get_Mean(Values); for index in Integer range 1 .. Count loop Difference := Values(index) - Mean; SS := SS + (Difference * Difference); end loop; return SS; end Get_Sum_Of_Squares; -------------------------------------------------------------- function Get_Population_Variance (Values: Values_Array) return Float is Population_Variance : Float; Count : Integer; begin Count := Get_Count (values); if count = 0 then return 0.0; -- should throw an error end if; Population_Variance := Get_Sum_Of_Squares(Values) / Float(Count); return Population_Variance; end Get_Population_Variance; -------------------------------------------------------------- function Get_Sample_Variance (Values: Values_Array) return Float is Sample_Variance : Float; Count : Integer; begin Count := Get_Count (values); if count = 0 then return 0.0; -- should throw an error end if; Sample_Variance := Get_Sum_Of_Squares(Values) / Float(Count - 1); return Sample_Variance; end Get_Sample_Variance; -------------------------------------------------------------- function Get_Population_Standard_Deviation (Values: Values_Array) return Float is Population_Standard_Deviation : Float; Population_Variance : Float; Count : Integer; begin Count := Get_Count (values); if count = 0 then return 0.0; -- should throw an error end if; Population_Variance := Get_Population_Variance(Values); Population_Standard_Deviation := Ada.Numerics.Elementary_Functions.Sqrt(Population_Variance); return Population_Variance; end Get_Population_Standard_Deviation; -------------------------------------------------------------- function Get_Sample_Standard_Deviation (Values: Values_Array) return Float is Sample_Standard_Deviation : Float; Sample_Variance : Float; Count : Integer; begin Count := Get_Count (values); if count = 0 then return 0.0; -- should throw an error end if; Sample_Variance := Get_Sample_Variance(Values); Sample_Standard_Deviation := Ada.Numerics.Elementary_Functions.Sqrt(Sample_Variance); return Sample_Standard_Deviation; end Get_Sample_Standard_Deviation; -------------------------------------------------------------- function Get_Standard_Error_of_Mean (Values : Values_Array) return Float is Standard_Error : Float; Count : Integer; begin Count := Get_Count(Values); if count = 0 then return 0.0; -- should throw an error end if; Standard_Error := Get_Sample_Standard_Deviation(Values) / Ada.Numerics.Elementary_Functions.Sqrt(Float(Count)); return Standard_Error; end Get_Standard_Error_of_Mean; -------------------------------------------------------------- function Get_Coefficient_Of_Variation (Values : Values_Array) return Float is Sample_Standard_Deviation : Float; Mean : Float; Count : Integer; begin Count := Get_Count(Values); if Count = 0 then return 0.0; -- should throw an error end if; Sample_Standard_Deviation := Get_Sample_Standard_Deviation (Values); Mean := Get_Mean (Values); if Mean /= 0.0 then return Sample_Standard_Deviation / Mean; else return 0.0; end if; end Get_Coefficient_Of_Variation; -------------------------------------------------------------- function Is_Value_In_Array (Values : Values_Array; Value : Float) return Boolean is Count : Integer; begin Count := Get_Count(Values); if Count = 0 then return FALSE; -- should throw an error end if; for index in Integer range 1..Count loop if Values(index) = Value then return True; end if; end loop; return false; end Is_Value_In_Array; -------------------------------------------------------------- function Get_Unique_Values (Values : Values_Array) return Values_Array is Count : INTEGER; Index : INTEGER; Value : FLOAT; Matched : BOOLEAN; Initial_Array : Values_Array (Integer range 1..Values'Length); begin Count := Get_Count(Values); Index := 2; Initial_Array(1) := Values(1); for idx in Integer range 2..Count loop Value := Values(idx); Matched := False; for idy in Integer range 1..Index loop if Value = Initial_Array(idy) then Matched := True; exit; end if; end loop; if Matched = False then Initial_Array(Index) := Value; Index := Index + 1; end if; end loop; Index := Index - 1; -- Return array up to Index return Initial_Array(1..Index); end Get_Unique_Values; -------------------------------------------------------------- -------------------------------------------------------------- end CompStats_Statistics;
package body Primes is function Next(Ps: List) return Positive is begin case Ps'Length is when 0 => return 2; when 1 => return 3; when others => declare N: Positive := Ps(Ps'Last) + 2; begin while (for some P of Ps => N mod P = 0) loop N := N + 2; end loop; return N; end; end case; end Next; function First(N: Positive) return List is Result: List(1 .. N) := (others => 1); begin for I in Result'Range loop Result(I) := Next(Result(Result'First .. I - 1)); end loop; return Result; end First; end Primes;
with Ada.Numerics.Discrete_Random; package body RandInt is gen: RA.Generator; function Next(n: in Natural) return Natural is begin return RA.Random(gen) mod n+1; end Next; begin RA.Reset(gen); end RandInt;
-------------------------------------------------------------------------------- -- Copyright (c) 2013, Felix Krause <contact@flyx.org> -- -- Permission to use, copy, modify, and/or 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. -------------------------------------------------------------------------------- with Interfaces.C; with Interfaces.C.Strings; with CL.Enumerations; with CL.Contexts; with CL.Memory; with CL.Memory.Images; with CL.Samplers; with CL.Programs; with CL.Queueing; private package CL.API is type Image_Format_Ptr is access all CL.Memory.Images.Image_Format; pragma Convention (C, Image_Format_Ptr); ----------------------------------------------------------------------------- -- Platform APIs ----------------------------------------------------------------------------- function Get_Platform_IDs (Num_Entries : CL.UInt; Value : System.Address; Num_Platforms : CL.UInt_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Platform_IDs, External_Name => "clGetPlatformIDs"); function Get_Platform_Info (Source : System.Address; Info : Enumerations.Platform_Info; Value_Size : Size; Value : access Interfaces.C.char_array; Return_Size : Size_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Platform_Info, External_Name => "clGetPlatformInfo"); ----------------------------------------------------------------------------- -- Device APIs ----------------------------------------------------------------------------- function Get_Device_IDs (Source : System.Address; Types : Bitfield; Num_Entries : UInt; Value : System.Address; Num_Devices : UInt_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Device_IDs, External_Name => "clGetDeviceIDs"); function Get_Device_Info (Source : System.Address; Param : Enumerations.Device_Info; Num_Entries : Size; Value : access Interfaces.C.char_array; Return_Size : Size_Ptr) return Enumerations.Error_Code; function Get_Device_Info (Source : System.Address; Param : Enumerations.Device_Info; Num_Entries : Size; Value : System.Address; Return_Size : Size_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Device_Info, External_Name => "clGetDeviceInfo"); ----------------------------------------------------------------------------- -- Context APIs ----------------------------------------------------------------------------- type Error_Callback is access procedure (Error_Info : IFC.Strings.chars_ptr; Private_Info : C_Chars.Pointer; CB : IFC.ptrdiff_t; User_Data : CL.Contexts.Error_Callback); pragma Convention (C, Error_Callback); function Create_Context (Properties : Address_Ptr; Num_Devices : UInt; Devices : System.Address; Callback : Error_Callback; User_Data : System.Address; Error : Enumerations.Error_Ptr) return System.Address; pragma Import (Convention => StdCall, Entity => Create_Context, External_Name => "clCreateContext"); function Create_Context_From_Type (Properties : Address_Ptr; Dev_Type : Bitfield; Callback : Error_Callback; User_Data : System.Address; Error : Enumerations.Error_Ptr) return System.Address; pragma Import (Convention => StdCall, Entity => Create_Context_From_Type, External_Name => "clCreateContextFromType"); function Retain_Context (Target : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Retain_Context, External_Name => "clRetainContext"); function Release_Context (Target : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Release_Context, External_Name => "clReleaseContext"); function Get_Context_Info (Source : System.Address; Param : Enumerations.Context_Info; Value_Size : Size; Value : System.Address; Return_Size : Size_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Context_Info, External_Name => "clGetContextInfo"); ----------------------------------------------------------------------------- -- Command Queue APIs ----------------------------------------------------------------------------- function Create_Command_Queue (Attach_To : System.Address; Device : System.Address; Properties : Bitfield; Error : Enumerations.Error_Ptr) return System.Address; pragma Import (Convention => StdCall, Entity => Create_Command_Queue, External_Name => "clCreateCommandQueue"); function Retain_Command_Queue (Queue : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Retain_Command_Queue, External_Name => "clRetainCommandQueue"); function Release_Command_Queue (Queue : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Release_Command_Queue, External_Name => "clReleaseCommandQueue"); function Get_Command_Queue_Info (Queue : System.Address; Param : Enumerations.Command_Queue_Info; Value_Size : Size; Value : System.Address; Return_Size : Size_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Command_Queue_Info, External_Name => "clGetCommandQueueInfo"); ----------------------------------------------------------------------------- -- Memory APIs ----------------------------------------------------------------------------- function Create_Buffer (Context : System.Address; Flags : Bitfield; Size : CL.Size; Host_Ptr : System.Address; Error : Enumerations.Error_Ptr) return System.Address; pragma Import (Convention => StdCall, Entity => Create_Buffer, External_Name => "clCreateBuffer"); function Create_Image2D (Context : System.Address; Flags : Bitfield; Format : Image_Format_Ptr; Width : Size; Height : Size; Row_Pitch : Size; Host_Ptr : System.Address; Error : Enumerations.Error_Ptr) return System.Address; pragma Import (Convention => StdCall, Entity => Create_Image2D, External_Name => "clCreateImage2D"); function Create_Image3D (Context : System.Address; Flags : Bitfield; Format : Image_Format_Ptr; Width : Size; Height : Size; Depth : Size; Row_Pitch : Size; Slice_Pitch : Size; Host_Ptr : System.Address; Error : Enumerations.Error_Ptr) return System.Address; pragma Import (Convention => StdCall, Entity => Create_Image3D, External_Name => "clCreateImage3D"); function Get_Mem_Object_Info (Object : System.Address; Info : Enumerations.Memory_Info; Size : CL.Size; Value : System.Address; Return_Size : Size_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Mem_Object_Info, External_Name => "clGetMemObjectInfo"); --type Destructor_Callback_Raw is -- access procedure (Object : System.Address; -- Callback : Destructor_Callback); --pragma Convention (C, Destructor_Callback_Raw); --function CL_Create_Sub_Buffer (Source : System.Address; -- Flags : Memory_Flags; -- Create_Type : Buffer_Create_Type; -- Info : Buffer_Create_Info; -- Error : CL.Error_Ptr) -- return System.Address; --pragma Import (Convention => StdCall, Entity => CL_Create_Sub_Buffer, -- External_Name => "clCreateSubBuffer"); function Retain_Mem_Object (Mem_Object : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Retain_Mem_Object, External_Name => "clRetainMemObject"); function Release_Mem_Object (Mem_Object : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Release_Mem_Object, External_Name => "clReleaseMemObject"); function Get_Supported_Image_Formats (Context : System.Address; Flags : Bitfield; Object_Type : CL.Memory.Images.Image_Type; Num_Entries : UInt; Value : System.Address; Return_Size : UInt_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Supported_Image_Formats, External_Name => "clGetSupportedImageFormats"); function Get_Image_Info (Object : System.Address; Info : Enumerations.Image_Info; Size : CL.Size; Value : System.Address; Return_Size : Size_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Image_Info, External_Name => "clGetImageInfo"); --function CL_Set_Mem_Object_Destructor_Callback -- (Object : System.Address; -- Callback : Destructor_Callback_Raw; -- User_Data : Destructor_Callback) return Error_Code; --pragma Import (Convention => StdCall, -- Entity => CL_Set_Mem_Object_Destructor_Callback, -- External_Name => "clSetMemObjectDestructorCallback"); ----------------------------------------------------------------------------- -- Sampler APIs ----------------------------------------------------------------------------- function Create_Sampler (Context : System.Address; Normalized_Coords : Bool; Addressing : Samplers.Addressing_Mode; Filter : Samplers.Filter_Mode; Error : Enumerations.Error_Ptr) return System.Address; pragma Import (Convention => StdCall, Entity => Create_Sampler, External_Name => "clCreateSampler"); function Retain_Sampler (Target : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Retain_Sampler, External_Name => "clRetainSampler"); function Release_Sampler (Target : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Release_Sampler, External_Name => "clReleaseSampler"); function Get_Sampler_Info (Source : System.Address; Info : Enumerations.Sampler_Info; Value_Size : Size; Value : System.Address; Return_Size : Size_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Sampler_Info, External_Name => "clGetSamplerInfo"); ----------------------------------------------------------------------------- -- Program APIs ----------------------------------------------------------------------------- function Create_Program_With_Source (Context : System.Address; Count : UInt; Sources : access IFC.Strings.chars_ptr; Lengths : access Size; Error : Enumerations.Error_Ptr) return System.Address; pragma Import (Convention => StdCall, Entity => Create_Program_With_Source, External_Name => "clCreateProgramWithSource"); function Create_Program_With_Binary (Context : System.Address; Num_Devices : UInt; Device_List : System.Address; Lengths : Size_Ptr; Binaries : access System.Address; Status : access Int; Error : Enumerations.Error_Ptr) return System.Address; pragma Import (Convention => StdCall, Entity => Create_Program_With_Binary, External_Name => "clCreateProgramWithBinary"); function Retain_Program (Target : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Retain_Program, External_Name => "clRetainProgram"); function Release_Program (Target : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Release_Program, External_Name => "clReleaseProgram"); type Build_Callback_Raw is access procedure (Subject : System.Address; Callback : Programs.Build_Callback); pragma Convention (C, Build_Callback_Raw); function Build_Program (Target : System.Address; Num_Devices : UInt; Device_List : System.Address; Options : IFC.Strings.chars_ptr; Callback : Build_Callback_Raw; User_Data : Programs.Build_Callback) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Build_Program, External_Name => "clBuildProgram"); function Unload_Compiler return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Unload_Compiler, External_Name => "clUnloadCompiler"); function Get_Program_Info (Source : System.Address; Param : Enumerations.Program_Info; Value_Size : Size; Value : System.Address; Return_Size : Size_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Program_Info, External_Name => "clGetProgramInfo"); function Get_Program_Build_Info (Source : System.Address; Device : System.Address; Param : Enumerations.Program_Build_Info; Value_Size : Size; Value : System.Address; Return_Size : Size_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Program_Build_Info, External_Name => "clGetProgramBuildInfo"); ----------------------------------------------------------------------------- -- Kernel APIs ----------------------------------------------------------------------------- function Create_Kernel (Source : System.Address; Name : IFC.Strings.chars_ptr; Error : Enumerations.Error_Ptr) return System.Address; pragma Import (Convention => StdCall, Entity => Create_Kernel, External_Name => "clCreateKernel"); function Create_Kernels_In_Program (Source : System.Address; Num_Kernels : UInt; Kernels : System.Address; Return_Size : UInt_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Create_Kernels_In_Program, External_Name => "clCreateKernelsInProgram"); function Retain_Kernel (Target : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Retain_Kernel, External_Name => "clRetainKernel"); function Release_Kernel (Target : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Release_Kernel, External_Name => "clReleaseKernel"); function Set_Kernel_Arg (Target : System.Address; Arg_Index : UInt; Value_Size : Size; Value : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Set_Kernel_Arg, External_Name => "clSetKernelArg"); function Get_Kernel_Info (Source : System.Address; Param : Enumerations.Kernel_Info; Value_Size : Size; Value : System.Address; Return_Size : Size_Ptr) return Enumerations.Error_Code; function Get_Kernel_Info (Source : System.Address; Param : Enumerations.Kernel_Info; Value_Size : Size; Value : access Interfaces.C.char_array; Return_Size : Size_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Kernel_Info, External_Name => "clGetKernelInfo"); function Get_Kernel_Work_Group_Info (Source : System.Address; Device : System.Address; Param : Enumerations.Kernel_Work_Group_Info; Value_Size : Size; Value : System.Address; Return_Size : Size_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Kernel_Work_Group_Info, External_Name => "clGetKernelWorkGroupInfo"); ----------------------------------------------------------------------------- -- Event APIs ----------------------------------------------------------------------------- function Wait_For_Events (Num_Events : CL.UInt; Event_List : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Wait_For_Events, External_Name => "clWaitForEvents"); function Get_Event_Info (Source : System.Address; Param : Enumerations.Event_Info; Value_Size : Size; Value : System.Address; Return_Size : Size_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Event_Info, External_Name => "clGetEventInfo"); function Retain_Event (Target : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Retain_Event, External_Name => "clRetainEvent"); function Release_Event (Target : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Release_Event, External_Name => "clReleaseEvent"); function Get_Event_Profiling_Info (Source : System.Address; Param : Enumerations.Profiling_Info; Value_Size : Size; Value : System.Address; Return_Size : Size_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Get_Event_Profiling_Info, External_Name => "clGetEventProfilingInfo"); ----------------------------------------------------------------------------- -- Flush & Finish APIs ----------------------------------------------------------------------------- function Flush (Queue : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Flush, External_Name => "clFlush"); function Finish (Queue : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Finish, External_Name => "clFinish"); ----------------------------------------------------------------------------- -- Enqueued Commands APIs ----------------------------------------------------------------------------- function Enqueue_Read_Buffer (Queue : System.Address; Buffer : System.Address; Blocking : Bool; Offset : Size; CB : Size; Ptr : System.Address; Num_Events : UInt; Event_List : Address_Ptr; Event : Address_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_Read_Buffer, External_Name => "clEnqueueReadBuffer"); function Enqueue_Write_Buffer (Queue : System.Address; Buffer : System.Address; Blocking : Bool; Offset : Size; CB : Size; Ptr : System.Address; Num_Events : UInt; Event_List : Address_Ptr; Event : Address_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_Write_Buffer, External_Name => "clEnqueueWriteBuffer"); function Enqueue_Copy_Buffer (Queue : System.Address; Source : System.Address; Dest : System.Address; Src_Offset : Size; Dest_Offset : Size; CB : Size; Num_Events : UInt; Event_List : Address_Ptr; Event : Address_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_Copy_Buffer, External_Name => "clEnqueueCopyBuffer"); function Enqueue_Read_Image (Queue : System.Address; Image : System.Address; Blocking : Bool; Origin : access constant Size; Region : access constant Size; Row_Pitch : Size; Slice_Pitch : Size; Ptr : System.Address; Num_Events : UInt; Event_List : Address_Ptr; Event : Address_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_Read_Image, External_Name => "clEnqueueReadImage"); function Enqueue_Write_Image (Queue : System.Address; Image : System.Address; Blocking : Bool; Origin : access constant Size; Region : access constant Size; Row_Pitch : Size; Slice_Pitch : Size; Ptr : System.Address; Num_Events : UInt; Event_List : Address_Ptr; Event : Address_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_Write_Image, External_Name => "clEnqueueWriteImage"); function Enqueue_Copy_Image (Queue : System.Address; Source : System.Address; Dest : System.Address; Src_Origin : access constant Size; Dest_Origin : access constant Size; Region : access constant Size; Num_Events : UInt; Event_List : Address_Ptr; Event : Address_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_Copy_Image, External_Name => "clEnqueueCopyImage"); function Enqueue_Copy_Image_To_Buffer (Queue : System.Address; Image : System.Address; Buffer : System.Address; Origin : Size_Ptr; Region : Size_Ptr; Dest_Offset : Size; Num_Events : UInt; Event_List : Address_Ptr; Event : Address_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_Copy_Image_To_Buffer, External_Name => "clEnqueueCopyImageToBuffer"); function Enqueue_Copy_Buffer_To_Image (Queue : System.Address; Buffer : System.Address; Image : System.Address; Src_Offset : Size; Origin : Size_Ptr; Region : Size_Ptr; Num_Events : UInt; Event_List : Address_Ptr; Event : Address_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_Copy_Buffer_To_Image, External_Name => "clEnqueueCopyBufferToImage"); function Enqueue_Map_Buffer (Queue : System.Address; Buffer : System.Address; Blocking : System.Address; Map_Flags : Queueing.Map_Flags; Offset : Size; CB : Size; Num_Events : UInt; Event_List : Address_Ptr; Event : Address_Ptr; Error : Enumerations.Error_Ptr) return System.Address; pragma Import (Convention => StdCall, Entity => Enqueue_Map_Buffer, External_Name => "clEnqueueMapBuffer"); function Enqueue_Map_Image (Queue : System.Address; Image : System.Address; Blocking : Bool; Map_Flags : Queueing.Map_Flags; Origin : Size_Ptr; Region : Size_Ptr; Row_Pitch : Size_Ptr; Slice_Pitch : Size_Ptr; Num_Events : UInt; Event_List : Address_Ptr; Event : Address_Ptr; Error : Enumerations.Error_Ptr) return System.Address; pragma Import (Convention => StdCall, Entity => Enqueue_Map_Image, External_Name => "clEnqueueMapImage"); function Enqueue_Unmap_Mem_Object (Queue : System.Address; Memobj : System.Address; Ptr : System.Address; Num_Events : UInt; Event_List : Address_Ptr; Event : Address_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_Unmap_Mem_Object, External_Name => "clEnqueueUnmapMemObject"); function Enqueue_NDRange_Kernel (Queue : System.Address; Kernel : System.Address; Work_Dim : UInt; Global_Work_Offset : access constant Size; Global_Work_Size : access constant Size; Local_Work_Size : access constant Size; Num_Events : UInt; Event_List : Address_Ptr; Event : Address_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_NDRange_Kernel, External_Name => "clEnqueueNDRangeKernel"); function Enqueue_Task (Queue : System.Address; Kernel : System.Address; Num_Events : UInt; Event_List : Address_Ptr; Event : Address_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_Task, External_Name => "clEnqueueTask"); -- Enqueue_Native_Kernel ommited function Enqueue_Marker (Queue : System.Address; Event : Address_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_Marker, External_Name => "clEnqueueMarker"); function Enqueue_Wait_For_Events (Queue : System.Address; Num_Events : UInt; Event_List : Address_Ptr) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_Wait_For_Events, External_Name => "clEnqueueWaitForEvents"); function Enqueue_Barrier (Queue : System.Address) return Enumerations.Error_Code; pragma Import (Convention => StdCall, Entity => Enqueue_Barrier, External_Name => "clEnqueueBarrier"); -- clGetExtensionFunctionAddress ommited end CL.API;
-- { dg-do run } procedure Fixedpnt is A : Duration := 1.0; B : Duration := Duration ((-1.0) * A); begin if B > 0.0 then raise Constraint_Error; end if; end;
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS -- -- -- -- SYSTEM.TASK_PRIMITIVES.OPERATIONS.MONOTONIC -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2020, 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 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/>. -- -- -- -- GNARL was developed by the GNARL team at Florida State University. -- -- Extensive contributions were provided by Ada Core Technologies, Inc. -- -- -- ------------------------------------------------------------------------------ -- This is the Monotonic version of this package for Posix and Linux targets. separate (System.Task_Primitives.Operations) package body Monotonic is ----------------------- -- Local Subprograms -- ----------------------- procedure Compute_Deadline (Time : Duration; Mode : ST.Delay_Modes; Check_Time : out Duration; Abs_Time : out Duration); -- Helper for Timed_Sleep and Timed_Delay: given a deadline specified by -- Time and Mode, compute the current clock reading (Check_Time), and the -- target absolute and relative clock readings (Abs_Time). The -- epoch for Time depends on Mode; the epoch for Check_Time and Abs_Time -- is always that of CLOCK_RT_Ada. --------------------- -- Monotonic_Clock -- --------------------- function Monotonic_Clock return Duration is TS : aliased timespec; Result : Interfaces.C.int; begin Result := clock_gettime (clock_id => OSC.CLOCK_RT_Ada, tp => TS'Unchecked_Access); pragma Assert (Result = 0); return To_Duration (TS); end Monotonic_Clock; ------------------- -- RT_Resolution -- ------------------- function RT_Resolution return Duration is TS : aliased timespec; Result : Interfaces.C.int; begin Result := clock_getres (OSC.CLOCK_REALTIME, TS'Unchecked_Access); pragma Assert (Result = 0); return To_Duration (TS); end RT_Resolution; ---------------------- -- Compute_Deadline -- ---------------------- procedure Compute_Deadline (Time : Duration; Mode : ST.Delay_Modes; Check_Time : out Duration; Abs_Time : out Duration) is begin Check_Time := Monotonic_Clock; -- Relative deadline if Mode = Relative then Abs_Time := Duration'Min (Time, Max_Sensible_Delay) + Check_Time; pragma Warnings (Off); -- Comparison "OSC.CLOCK_RT_Ada = OSC.CLOCK_REALTIME" is compile -- time known. -- Absolute deadline specified using the tasking clock (CLOCK_RT_Ada) elsif Mode = Absolute_RT or else OSC.CLOCK_RT_Ada = OSC.CLOCK_REALTIME then pragma Warnings (On); Abs_Time := Duration'Min (Check_Time + Max_Sensible_Delay, Time); -- Absolute deadline specified using the calendar clock, in the -- case where it is not the same as the tasking clock: compensate for -- difference between clock epochs (Base_Time - Base_Cal_Time). else declare Cal_Check_Time : constant Duration := OS_Primitives.Clock; RT_Time : constant Duration := Time + Check_Time - Cal_Check_Time; begin Abs_Time := Duration'Min (Check_Time + Max_Sensible_Delay, RT_Time); end; end if; end Compute_Deadline; ----------------- -- Timed_Sleep -- ----------------- -- This is for use within the run-time system, so abort is -- assumed to be already deferred, and the caller should be -- holding its own ATCB lock. procedure Timed_Sleep (Self_ID : ST.Task_Id; Time : Duration; Mode : ST.Delay_Modes; Reason : System.Tasking.Task_States; Timedout : out Boolean; Yielded : out Boolean) is pragma Unreferenced (Reason); Base_Time : Duration; Check_Time : Duration; Abs_Time : Duration; P_Abs_Time : Duration; Request : aliased timespec; Result : Interfaces.C.int; Exit_Outer : Boolean := False; begin Timedout := True; Yielded := False; Compute_Deadline (Time => Time, Mode => Mode, Check_Time => Check_Time, Abs_Time => Abs_Time); Base_Time := Check_Time; -- To keep a sensible Max_Sensible_Delay on a target whose system -- maximum is less than sensible, we split the delay into manageable -- chunks of time less than or equal to the Max_System_Delay. if Abs_Time > Check_Time then Outer : loop pragma Warnings (Off, "condition is always *"); if Max_System_Delay < Max_Sensible_Delay and then Abs_Time > Check_Time + Max_System_Delay then P_Abs_Time := Check_Time + Max_System_Delay; else P_Abs_Time := Abs_Time; Exit_Outer := True; end if; pragma Warnings (On); Request := To_Timespec (P_Abs_Time); Inner : loop exit Outer when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level; Result := pthread_cond_timedwait (cond => Self_ID.Common.LL.CV'Access, mutex => Self_ID.Common.LL.L'Access, abstime => Request'Access); case Result is when 0 | EINTR => -- Somebody may have called Wakeup for us Timedout := False; exit Outer; when ETIMEDOUT => exit Outer when Exit_Outer; Check_Time := Monotonic_Clock; exit Inner; when others => pragma Assert (False); end case; exit Outer when Abs_Time <= Check_Time or else Check_Time < Base_Time; end loop Inner; end loop Outer; end if; end Timed_Sleep; ----------------- -- Timed_Delay -- ----------------- -- This is for use in implementing delay statements, so we assume the -- caller is abort-deferred but is holding no locks. procedure Timed_Delay (Self_ID : ST.Task_Id; Time : Duration; Mode : ST.Delay_Modes) is Base_Time : Duration; Check_Time : Duration; Abs_Time : Duration; P_Abs_Time : Duration; Request : aliased timespec; Result : Interfaces.C.int; Exit_Outer : Boolean := False; begin Write_Lock (Self_ID); Compute_Deadline (Time => Time, Mode => Mode, Check_Time => Check_Time, Abs_Time => Abs_Time); Base_Time := Check_Time; -- To keep a sensible Max_Sensible_Delay on a target whose system -- maximum is less than sensible, we split the delay into manageable -- chunks of time less than or equal to the Max_System_Delay. if Abs_Time > Check_Time then Self_ID.Common.State := Delay_Sleep; Outer : loop pragma Warnings (Off, "condition is always *"); if Max_System_Delay < Max_Sensible_Delay and then Abs_Time > Check_Time + Max_System_Delay then P_Abs_Time := Check_Time + Max_System_Delay; else P_Abs_Time := Abs_Time; Exit_Outer := True; end if; pragma Warnings (On); Request := To_Timespec (P_Abs_Time); Inner : loop exit Outer when Self_ID.Pending_ATC_Level < Self_ID.ATC_Nesting_Level; Result := pthread_cond_timedwait (cond => Self_ID.Common.LL.CV'Access, mutex => Self_ID.Common.LL.L'Access, abstime => Request'Access); case Result is when ETIMEDOUT => exit Outer when Exit_Outer; Check_Time := Monotonic_Clock; exit Inner; when 0 | EINTR => null; when others => pragma Assert (False); end case; exit Outer when Abs_Time <= Check_Time or else Check_Time < Base_Time; end loop Inner; end loop Outer; Self_ID.Common.State := Runnable; end if; Unlock (Self_ID); pragma Unreferenced (Result); Result := sched_yield; end Timed_Delay; end Monotonic;
Positional := H(A, F'Access); Named := H(Int => A, Fun => F'Access); Mixed := H(A, Fun=>F'Access);
with Ada.Text_IO; use Ada.Text_IO; with Simple_Math; procedure Main is package Io is new Ada.Text_IO.Float_IO (Simple_Math.Float_T); function Get (Prompt : String) return Simple_Math.Float_T is begin Put (" " & Prompt & " => "); return Simple_Math.Float_T'value (Get_Line); end Get; procedure Test_Square_Root (Number : Simple_Math.Float_T) is begin null; end Test_Square_Root; procedure Test_Square (Number : Simple_Math.Float_T) is begin null; end Test_Square; procedure Test_Multiply (Left : Simple_Math.Float_T; Right : Simple_Math.Float_T) is begin null; end Test_Multiply; procedure Test_Divide (Numerator : Simple_Math.Float_T; Denominator : Simple_Math.Float_T) is begin null; end Test_Divide; begin Put_Line ("Test_Square_Root"); Test_Square_Root (Get ("Number")); Put_Line ("Test_Square"); Test_Square (Get ("Number")); Put_Line ("Test_Multiply"); Test_Multiply (Get ("Left"), Get ("right")); Put_Line ("Test_Divide"); Test_Divide (Get ("Numerator"), Get ("Denominator")); end Main;
Foo := 1; loop exit when Foo = 10; Foo := Foo + 1; end loop;
-- -- Test unit for this demo. -- -- 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.Text_IO; use Ada.Text_IO; with data_storage; use data_storage; with algorithmic; use algorithmic; procedure test_separation is begin Put_Line("Test of the algorithmic separation; base case"); Put("Invoking Naive algorithm: "); declare ND : Naive_Data; result : Integer; begin ND.Set_Data(3); result := ND.Do_Naive_Calculation(3); Put_Line(" 3 + 3^3 = " & result'Img); end; Put("Invoking Optimized algorithm: "); declare OD : Optimized_Data; result : Integer; begin OD.Set_Data(3); OD.Set_Extra_Data(3**3); result := OD.Do_Optimized_Calculation(3); Put_Line(" 3 + 3^3 = " & result'Img); end; New_Line; Put_Line("Testing invocation by 3rd parties"); Put("Naive algorithm, "); declare ND : Naive_Data; UT : Unrelated_Type; result : Integer; begin ND.Set_Data(3); result := do_some_calc_messy(UT, 3, ND); Put("messy: 3 + 3^3 = " & result'Img & ", "); result := do_some_calc_oop(UT, 3, ND); Put_Line("oop: 3 + 3^3 = " & result'Img); end; Put("Optimized algorithm, "); declare OD : Optimized_Data; UT : Unrelated_Type; result : Integer; begin OD.Set_Data(3); result := do_some_calc_messy(UT, 3, OD); -- NOTE how our invocation is exactly the same as in naive case!! Put("messy: 3 + 3^3 = " & result'Img & ", "); result := do_some_calc_oop(UT, 3, OD); Put_Line("oop: 3 + 3^3 = " & result'Img); -- ditto here end; end test_separation;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- P R E P C O M P -- -- -- -- S p e c -- -- -- -- Copyright (C) 2002-2005, 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. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This package stores all preprocessing data for the compiler with Types; use Types; package Prepcomp is procedure Add_Dependencies; -- Add dependencies on the preprocessing data file and the -- preprocessing definition files, if any. procedure Add_Symbol_Definition (Def : String); -- Add a symbol definition from the command line. -- Fail if definition is illegal. procedure Check_Symbols; -- Check if there are preprocessing symbols on the command line and -- set preprocessing if there are some: all files are preprocessed with -- these symbols. This procedure should not be called if there is a -- preprocessing data file specified on the command line. Procedure -- Parse_Preprocessing_Data_File should be called instead. procedure Parse_Preprocessing_Data_File (N : File_Name_Type); -- Parse a preprocessing data file, specified with a -gnatep= switch procedure Prepare_To_Preprocess (Source : File_Name_Type; Preprocessing_Needed : out Boolean); -- Prepare, if necessary, the preprocessor for a source file. -- If the source file needs to be preprocessed, Preprocessing_Needed -- is set to True. Otherwise, Preprocessing_Needed is set to False -- and no preprocessing needs to be done. procedure Process_Command_Line_Symbol_Definitions; -- Check symbol definitions that have been added by calls to procedure -- Add_Symbol_Definition and stored as pointers to string, and put them in -- a table. The reason the definitions were stored as pointer to strings is -- that the name table is not yest initialized when we process the command -- line switches. These symbol definitions will be later used in -- the call to Prepare_To_Preprocess. end Prepcomp;
with System; -- ============================================================================= -- Package body AVR.INTERRUPTS -- -- Maps the interrupts for the MCU micro-controller. -- To attach an interrupt, proceed like -- procedure Receive_Handler; -- pragma Machine_Attribute -- (Entity => Receive_Handler, -- Attribute_Name => "signal"); -- pragma Export -- (Convention => C, -- Entity => Receive_Handler, -- External_Name => <interrupt_vector_name>); -- ============================================================================= package AVR.INTERRUPTS is type External_Interrupt_Control_Type is array (0 .. 7) of Bit_Array_Type (0 .. 1); pragma Pack (External_Interrupt_Control_Type); for External_Interrupt_Control_Type'Size use 2 * BYTE_SIZE; Reg_EICR : External_Interrupt_Control_Type; for Reg_EICR'Address use System'To_Address (16#69#); type External_Interrupt_Mask_Register is new Bit_Array_Type (0 .. 7); Reg_EIMSK : External_Interrupt_Mask_Register; for Reg_EIMSK'Address use System'To_Address (16#3D#); type External_Interrupt_Flag_Type is new Bit_Array_Type (0 .. 7); Reg_EIFR : External_Interrupt_Flag_Type; for Reg_EIFR'Address use System'To_Address (16#3C#); type Pin_Change_Interrupt_Control_Register_Type is new Bit_Array_Type (0 .. 7); Reg_PCICR : Pin_Change_Interrupt_Control_Register_Type; for Reg_PCICR'Address use System'To_Address (16#68#); type Pin_Change_Interrupt_Flag_Type is new Bit_Array_Type (0 .. 7); Reg_PCIFR : Pin_Change_Interrupt_Flag_Type; for Reg_PCIFR'Address use System'To_Address (16#3B#); type Pin_Change_Mask_Type is new Bit_Array_Type (0 .. 23); Reg_PCMSK : Pin_Change_Mask_Type; for Reg_PCMSK'Address use System'To_Address (16#6B#); #if MCU="ATMEGA2560" then RESET : constant String := "__vector_0"; -- External Pin, Power-on, Brown-out, Watchdog and JTAG AVR Reset INT0 : constant String := "__vector_1"; -- External Interrupt Request 0 INT1 : constant String := "__vector_2"; -- External Interrupt Request 1 INT2 : constant String := "__vector_3"; -- External Interrupt Request 2 INT3 : constant String := "__vector_4"; -- External Interrupt Request 3 INT4 : constant String := "__vector_5"; -- External Interrupt Request 4 INT5 : constant String := "__vector_6"; -- External Interrupt Request 5 INT6 : constant String := "__vector_7"; -- External Interrupt Request 6 INT7 : constant String := "__vector_8"; -- External Interrupt Request 7 PCINT0 : constant String := "__vector_9"; -- Pin Change Interrupt Request 0 PCINT1 : constant String := "__vector_10"; -- Pin Change Interrupt Request 1 PCINT2 : constant String := "__vector_11"; -- Pin Change Interrupt Request 2 WDT : constant String := "__vector_12"; -- Watchdog Time-out Interrupt TIMER2_COMPA : constant String := "__vector_13"; -- Timer/Counter2 Compare Match A TIMER2_COMPB : constant String := "__vector_14"; -- Timer/Counter2 Compare Match B TIMER2_OVF : constant String := "__vector_15"; -- Timer/Counter2 Overflow TIMER1_CAPT : constant String := "__vector_16"; -- Timer/Counter1 Capture Event TIMER1_COMPA : constant String := "__vector_17"; -- Timer/Counter1 Compare Match A TIMER1_COMPB : constant String := "__vector_18"; -- Timer/Counter1 Compare Match B TIMER1_COMPC : constant String := "__vector_19"; -- Timer/Counter1 Compare Match C TIMER1_OVF : constant String := "__vector_20"; -- Timer/Counter1 Overflow TIMER0_COMPA : constant String := "__vector_21"; -- Timer/Counter0 Compare Match A TIMER0_COMPB : constant String := "__vector_22"; -- Timer/Counter0 Compare match B TIMER0_OVF : constant String := "__vector_23"; -- Timer/Counter0 Overflow SPI_STC : constant String := "__vector_24"; -- SPI Serial Transfer Complete USART0_RX : constant String := "__vector_25"; -- USART0 Rx Complete USART0_UDRE : constant String := "__vector_26"; -- USART0 Data Register Empty USART0_TX : constant String := "__vector_27"; -- USART0 Tx Complete ANALOG_COMP : constant String := "__vector_28"; -- Analog Comparator ADC : constant String := "__vector_29"; -- ADC Conversion Complete EE_READY : constant String := "__vector_30"; -- EEPROM Ready TIMER3_CAPT : constant String := "__vector_31"; -- Timer/Counter3 Capture Event TIMER3_COMPA : constant String := "__vector_32"; -- Timer/Counter3 Compare Match A TIMER3_COMPB : constant String := "__vector_33"; -- Timer/Counter3 Compare Match B TIMER3_COMPC : constant String := "__vector_34"; -- Timer/Counter3 Compare Match C TIMER3_OVF : constant String := "__vector_35"; -- Timer/Counter3 Overflow USART1_RX : constant String := "__vector_36"; -- USART1 Rx Complete USART1_UDRE : constant String := "__vector_37"; -- USART1 Data Register Empty USART1_TX : constant String := "__vector_38"; -- USART1 Tx Complete TWI : constant String := "__vector_39"; -- 2-wire Serial Interface SPM_READY : constant String := "__vector_40"; -- Store Program Memory Ready TIMER4_CAPT : constant String := "__vector_41"; -- Timer/Counter4 Capture Event TIMER4_COMPA : constant String := "__vector_42"; -- Timer/Counter4 Compare Match A TIMER4_COMPB : constant String := "__vector_43"; -- Timer/Counter4 Compare Match B TIMER4_COMPC : constant String := "__vector_44"; -- Timer/Counter4 Compare Match C TIMER4_OVF : constant String := "__vector_45"; -- Timer/Counter4 Overflow TIMER5_CAPT : constant String := "__vector_46"; -- Timer/Counter5 Capture Event TIMER5_COMPA : constant String := "__vector_47"; -- Timer/Counter5 Compare Match A TIMER5_COMPB : constant String := "__vector_48"; -- Timer/Counter5 Compare Match B TIMER5_COMPC : constant String := "__vector_49"; -- Timer/Counter5 Compare Match C TIMER5_OVF : constant String := "__vector_50"; -- Timer/Counter5 Overflow USART2_RX : constant String := "__vector_51"; -- USART2 Rx Complete USART2_UDRE : constant String := "__vector_52"; -- USART2 Data Register Empty USART2_TX : constant String := "__vector_53"; -- USART2 Tx Complete USART3_RX : constant String := "__vector_54"; -- USART3 Rx Complete USART3_UDRE : constant String := "__vector_55"; -- USART3 Data Register Empty USART3_TX : constant String := "__vector_56"; -- USART3 Tx Complete #end if; #if MCU="ATMEGA328P" then RESET : constant String := "__vector_0"; -- External Pin, Power-on, Brown-out, Watchdog and System Reset INT0 : constant String := "__vector_1"; -- External Interrupt Request 0 INT1 : constant String := "__vector_2"; -- External Interrupt Request 1 PCINT0 : constant String := "__vector_3"; -- Pin Change Interrupt Request 0 PCINT1 : constant String := "__vector_4"; -- Pin Change Interrupt Request 1 PCINT2 : constant String := "__vector_5"; -- Pin Change Interrupt Request 2 WDT : constant String := "__vector_6"; -- Watchdog Time-out Interrupt TIMER2_COMPA : constant String := "__vector_7"; -- Timer/Counter2 Compare Match A TIMER2_COMPB : constant String := "__vector_8"; -- Timer/Counter2 Compare Match B TIMER2_OVF : constant String := "__vector_9"; -- Timer/Counter2 Overflow TIMER1_CAPT : constant String := "__vector_10"; -- Timer/Counter1 Capture Event TIMER1_COMPA : constant String := "__vector_11"; -- Timer/Counter1 Compare Match A TIMER1_COMPB : constant String := "__vector_12"; -- Timer/Counter1 Compare Match B TIMER1_OVF : constant String := "__vector_13"; -- Timer/Counter1 Overflow TIMER0_COMPA : constant String := "__vector_14"; -- Timer/Counter0 Compare Match A TIMER0_COMPB : constant String := "__vector_15"; -- Timer/Counter0 Compare match B TIMER0_OVF : constant String := "__vector_16"; -- Timer/Counter0 Overflow SPI_STC : constant String := "__vector_17"; -- SPI Serial Transfer Complete USART0_RX : constant String := "__vector_18"; -- USART0 Rx Complete USART0_UDRE : constant String := "__vector_19"; -- USART0 Data Register Empty USART0_TX : constant String := "__vector_20"; -- USART0 Tx Complete ADC : constant String := "__vector_21"; -- ADC Conversion Complete EE_READY : constant String := "__vector_22"; -- EEPROM Ready ANALOG_COMP : constant String := "__vector_23"; -- Analog Comparator TWI : constant String := "__vector_24"; -- 2-wire Serial Interface SPM_READY : constant String := "__vector_25"; -- Store Program Memory Ready #end if; procedure Enable; procedure Disable; procedure Handle_Interrupt_RESET is null; pragma Machine_Attribute (Entity => Handle_Interrupt_RESET, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_RESET, External_Name => RESET); procedure Handle_Interrupt_INT0 is null; pragma Machine_Attribute (Entity => Handle_Interrupt_INT0, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_INT0, External_Name => INT0); procedure Handle_Interrupt_INT1 is null; pragma Machine_Attribute (Entity => Handle_Interrupt_INT1, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_INT1, External_Name => INT1); #if MCU="ATMEGA2560" then procedure Handle_Interrupt_INT2 is null; pragma Machine_Attribute (Entity => Handle_Interrupt_INT2, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_INT2, External_Name => INT2); procedure Handle_Interrupt_INT3 is null; pragma Machine_Attribute (Entity => Handle_Interrupt_INT3, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_INT3, External_Name => INT3); procedure Handle_Interrupt_INT4 is null; pragma Machine_Attribute (Entity => Handle_Interrupt_INT4, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_INT4, External_Name => INT4); procedure Handle_Interrupt_INT5 is null; pragma Machine_Attribute (Entity => Handle_Interrupt_INT5, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_INT5, External_Name => INT5); procedure Handle_Interrupt_INT6 is null; pragma Machine_Attribute (Entity => Handle_Interrupt_INT6, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_INT6, External_Name => INT6); procedure Handle_Interrupt_INT7 is null; pragma Machine_Attribute (Entity => Handle_Interrupt_INT7, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_INT7, External_Name => INT7); #end if; procedure Handle_Interrupt_PCINT0 is null; pragma Machine_Attribute (Entity => Handle_Interrupt_PCINT0, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_PCINT0, External_Name => PCINT0); procedure Handle_Interrupt_PCINT1 is null; pragma Machine_Attribute (Entity => Handle_Interrupt_PCINT1, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_PCINT1, External_Name => PCINT1); procedure Handle_Interrupt_PCINT2 is null; pragma Machine_Attribute (Entity => Handle_Interrupt_PCINT2, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_PCINT2, External_Name => PCINT2); procedure Handle_Interrupt_WDT is null; pragma Machine_Attribute (Entity => Handle_Interrupt_WDT, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_WDT, External_Name => WDT); procedure Handle_Interrupt_TIMER2_COMPA is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER2_COMPA, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER2_COMPA, External_Name => TIMER2_COMPA); procedure Handle_Interrupt_TIMER2_COMPB is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER2_COMPB, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER2_COMPB, External_Name => TIMER2_COMPB); procedure Handle_Interrupt_TIMER2_OVF is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER2_OVF, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER2_OVF, External_Name => TIMER2_OVF); procedure Handle_Interrupt_TIMER1_CAPT is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER1_CAPT, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER1_CAPT, External_Name => TIMER1_CAPT); procedure Handle_Interrupt_TIMER1_COMPA is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER1_COMPA, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER1_COMPA, External_Name => TIMER1_COMPA); procedure Handle_Interrupt_TIMER1_COMPB is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER1_COMPB, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER1_COMPB, External_Name => TIMER1_COMPB); #if MCU="ATMEGA2560" then procedure Handle_Interrupt_TIMER1_COMPC is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER1_COMPC, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER1_COMPC, External_Name => TIMER1_COMPC); #end if; procedure Handle_Interrupt_TIMER1_OVF is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER1_OVF, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER1_OVF, External_Name => TIMER1_OVF); procedure Handle_Interrupt_TIMER0_COMPA is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER0_COMPA, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER0_COMPA, External_Name => TIMER0_COMPA); procedure Handle_Interrupt_TIMER0_COMPB is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER0_COMPB, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER0_COMPB, External_Name => TIMER0_COMPB); procedure Handle_Interrupt_TIMER0_OVF is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER0_OVF, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER0_OVF, External_Name => TIMER0_OVF); procedure Handle_Interrupt_SPI_STC is null; pragma Machine_Attribute (Entity => Handle_Interrupt_SPI_STC, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_SPI_STC, External_Name => SPI_STC); procedure Handle_Interrupt_USART0_RX; pragma Machine_Attribute (Entity => Handle_Interrupt_USART0_RX, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_USART0_RX, External_Name => USART0_RX); procedure Handle_Interrupt_USART0_UDRE is null; pragma Machine_Attribute (Entity => Handle_Interrupt_USART0_UDRE, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_USART0_UDRE, External_Name => USART0_UDRE); procedure Handle_Interrupt_USART0_TX is null; pragma Machine_Attribute (Entity => Handle_Interrupt_USART0_TX, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_USART0_TX, External_Name => USART0_TX); procedure Handle_Interrupt_ANALOG_COMP is null; pragma Machine_Attribute (Entity => Handle_Interrupt_ANALOG_COMP, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_ANALOG_COMP, External_Name => ANALOG_COMP); procedure Handle_Interrupt_ADC is null; pragma Machine_Attribute (Entity => Handle_Interrupt_ADC, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_ADC, External_Name => ADC); procedure Handle_Interrupt_EE_READY is null; pragma Machine_Attribute (Entity => Handle_Interrupt_EE_READY, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_EE_READY, External_Name => EE_READY); #if MCU="ATMEGA2560" then procedure Handle_Interrupt_TIMER3_CAPT is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER3_CAPT, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER3_CAPT, External_Name => TIMER3_CAPT); procedure Handle_Interrupt_TIMER3_COMPA is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER3_COMPA, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER3_COMPA, External_Name => TIMER3_COMPA); procedure Handle_Interrupt_TIMER3_COMPB is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER3_COMPB, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER3_COMPB, External_Name => TIMER3_COMPB); procedure Handle_Interrupt_TIMER3_COMPC is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER3_COMPC, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER3_COMPC, External_Name => TIMER3_COMPC); procedure Handle_Interrupt_TIMER3_OVF is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER3_OVF, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER3_OVF, External_Name => TIMER3_OVF); procedure Handle_Interrupt_USART1_UDRE is null; pragma Machine_Attribute (Entity => Handle_Interrupt_USART1_UDRE, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_USART1_UDRE, External_Name => USART1_UDRE); procedure Handle_Interrupt_USART1_TX is null; pragma Machine_Attribute (Entity => Handle_Interrupt_USART1_TX, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_USART1_TX, External_Name => USART1_TX); #end if; procedure Handle_Interrupt_TWI; pragma Machine_Attribute (Entity => Handle_Interrupt_TWI, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TWI, External_Name => TWI); procedure Handle_Interrupt_SPM_READY is null; pragma Machine_Attribute (Entity => Handle_Interrupt_SPM_READY, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_SPM_READY, External_Name => SPM_READY); #if MCU="ATMEGA2560" then procedure Handle_Interrupt_TIMER4_CAPT is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER4_CAPT, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER4_CAPT, External_Name => TIMER4_CAPT); procedure Handle_Interrupt_TIMER4_COMPA is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER4_COMPA, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER4_COMPA, External_Name => TIMER4_COMPA); procedure Handle_Interrupt_TIMER4_COMPB is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER4_COMPB, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER4_COMPB, External_Name => TIMER4_COMPB); procedure Handle_Interrupt_TIMER4_COMPC is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER4_COMPC, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER4_COMPC, External_Name => TIMER4_COMPC); procedure Handle_Interrupt_TIMER4_OVF is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER4_OVF, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER4_OVF, External_Name => TIMER4_OVF); procedure Handle_Interrupt_TIMER5_CAPT is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER5_CAPT, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER5_CAPT, External_Name => TIMER5_CAPT); procedure Handle_Interrupt_TIMER5_COMPA is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER5_COMPA, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER5_COMPA, External_Name => TIMER5_COMPA); procedure Handle_Interrupt_TIMER5_COMPB is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER5_COMPB, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER5_COMPB, External_Name => TIMER5_COMPB); procedure Handle_Interrupt_TIMER5_COMPC is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER5_COMPC, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER5_COMPC, External_Name => TIMER5_COMPC); procedure Handle_Interrupt_TIMER5_OVF is null; pragma Machine_Attribute (Entity => Handle_Interrupt_TIMER5_OVF, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_TIMER5_OVF, External_Name => TIMER5_OVF); procedure Handle_Interrupt_USART2_RX; pragma Machine_Attribute (Entity => Handle_Interrupt_USART2_RX, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_USART2_RX, External_Name => USART2_RX); procedure Handle_Interrupt_USART2_UDRE is null; pragma Machine_Attribute (Entity => Handle_Interrupt_USART2_UDRE, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_USART2_UDRE, External_Name => USART2_UDRE); procedure Handle_Interrupt_USART2_TX is null; pragma Machine_Attribute (Entity => Handle_Interrupt_USART2_TX, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_USART2_TX, External_Name => USART2_TX); procedure Handle_Interrupt_USART3_RX; pragma Machine_Attribute (Entity => Handle_Interrupt_USART3_RX, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_USART3_RX, External_Name => USART3_RX); procedure Handle_Interrupt_USART3_UDRE is null; pragma Machine_Attribute (Entity => Handle_Interrupt_USART3_UDRE, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_USART3_UDRE, External_Name => USART3_UDRE); procedure Handle_Interrupt_USART3_TX is null; pragma Machine_Attribute (Entity => Handle_Interrupt_USART3_TX, Attribute_Name => "signal"); pragma Export (Convention => C, Entity => Handle_Interrupt_USART3_TX, External_Name => USART3_TX); #end if; end AVR.INTERRUPTS;
private with ada.Strings.unbounded, ada.Containers.vectors; package XML -- -- Provides simple XML reader/writer support. -- -- Heavily based on Chip Richards Ada XML packages. -- is --- Attribute type -- type Attribute_t is tagged private; type Attributes_t is array (Positive range <>) of aliased Attribute_t; type Attributes_view is access all Attributes_t; function Name (Self : in Attribute_t) return String; function Value (Self : in Attribute_t) return String; --- Element type -- type Element is tagged private; type Elements is array (Positive range <>) of access Element; -- Construction -- function to_XML (Filename : in String) return Element; -- -- Parses 'Filename' and returns the root node Element of the parsed XML tree. -- Attributes -- function Name (Self : in Element) return String; function Attributes (Self : in Element) return Attributes_t; function Data (Self : in Element) return String; function Attribute (Self : in Element; Named : in String) return access Attribute_t'Class; -- -- Returns null if the named attribute does not exist. -- Hierachy -- function Parent (Self : in Element) return access Element; function Children (Self : in Element) return Elements; function Child (Self : in Element; Named : in String) return access Element; -- -- Returns null if the named child does not exist. function Children (Self : in Element; Named : in String) return Elements; procedure add_Child (Self : in out Element; the_Child : access Element); private use ada.Strings.unbounded; type Attribute_t is tagged record Name : unbounded_String; Value : unbounded_String; end record; type Element_view is access all Element; package element_Vectors is new ada.containers.Vectors (Positive, Element_view); subtype element_Vector is element_vectors.Vector; type Element is tagged record Name : unbounded_String; Attributes : Attributes_view; Data : unbounded_String; Parent : Element_view; Children : element_Vector; end record; end XML;
package Discr20 is Size : Integer; type Name is new String (1..Size); type Rec is record It : Name; end record; type Danger is (This, That); type def (X : Danger := This) is record case X is when This => It : Rec; when That => null; end case; end record; type Switch is (On, Off); type Wrapper (Disc : Switch := On) is private; function Get (X : Wrapper) return Def; private type Wrapper (Disc : Switch := On) is record Case Disc is when On => It : Def; when Off => null; end case; end record; end Discr20;
------------------------------------------------------------------------------ -- -- -- GNAT LIBRARY COMPONENTS -- -- -- -- G N A T . T T Y -- -- -- -- B o d y -- -- -- -- Copyright (C) 2002-2020, AdaCore -- -- -- -- 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. -- -- -- ------------------------------------------------------------------------------ with Interfaces.C.Strings; use Interfaces.C.Strings; package body GNAT.TTY is use System; procedure Check_TTY (Handle : TTY_Handle); -- Check the validity of Handle. Raise Program_Error if ttys are not -- supported. Raise Constraint_Error if Handle is an invalid handle. ------------------ -- Allocate_TTY -- ------------------ procedure Allocate_TTY (Handle : out TTY_Handle) is function Internal return System.Address; pragma Import (C, Internal, "__gnat_new_tty"); begin if not TTY_Supported then raise Program_Error; end if; Handle.Handle := Internal; end Allocate_TTY; --------------- -- Check_TTY -- --------------- procedure Check_TTY (Handle : TTY_Handle) is begin if not TTY_Supported then raise Program_Error; elsif Handle.Handle = System.Null_Address then raise Constraint_Error; end if; end Check_TTY; --------------- -- Close_TTY -- --------------- procedure Close_TTY (Handle : in out TTY_Handle) is procedure Internal (Handle : System.Address); pragma Import (C, Internal, "__gnat_close_tty"); begin Check_TTY (Handle); Internal (Handle.Handle); Handle.Handle := System.Null_Address; end Close_TTY; --------------- -- Reset_TTY -- --------------- procedure Reset_TTY (Handle : TTY_Handle) is procedure Internal (Handle : System.Address); pragma Import (C, Internal, "__gnat_reset_tty"); begin Check_TTY (Handle); Internal (Handle.Handle); end Reset_TTY; -------------------- -- TTY_Descriptor -- -------------------- function TTY_Descriptor (Handle : TTY_Handle) return GNAT.OS_Lib.File_Descriptor is function Internal (Handle : System.Address) return GNAT.OS_Lib.File_Descriptor; pragma Import (C, Internal, "__gnat_tty_fd"); begin Check_TTY (Handle); return Internal (Handle.Handle); end TTY_Descriptor; -------------- -- TTY_Name -- -------------- function TTY_Name (Handle : TTY_Handle) return String is function Internal (Handle : System.Address) return chars_ptr; pragma Import (C, Internal, "__gnat_tty_name"); begin Check_TTY (Handle); return Value (Internal (Handle.Handle)); end TTY_Name; ------------------- -- TTY_Supported -- ------------------- function TTY_Supported return Boolean is function Internal return Integer; pragma Import (C, Internal, "__gnat_tty_supported"); begin return Internal /= 0; end TTY_Supported; end GNAT.TTY;
-- Copyright 2021 Jeff Foley. All rights reserved. -- Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. local json = require("json") name = "BGPView" type = "api" function start() setratelimit(1) end function asn(ctx, addr, asn) if asn == 0 then if addr == "" then return end local ip, cidr = getcidr(addr) if ip == "" then return end asn = getasn(ip, cidr) if asn == 0 then return end end local a = asinfo(asn) if a == nil then return end newasn(ctx, { ['addr']=addr, ['asn']=asn, ['prefix']=a.prefix, ['cc']=a.cc, ['registry']=a.registry, ['desc']=a.desc, ['netblocks']=netblocks(asn), }) end function getcidr(addr) local resp = cacherequest("https://api.bgpview.io/ip/" .. addr) if resp == "" then return "", 0 end local j = json.decode(resp) if (j == nil or j.status ~= "ok" or j.status_message ~= "Query was successful") then return "", 0 end local ip = j.data.rir_allocation.ip local cidr = j.data.rir_allocation.cidr return ip, cidr end function getasn(ip, cidr) local resp = cacherequest("https://api.bgpview.io/prefix/" .. ip .. "/" .. tostring(cidr)) if resp == "" then return 0 end local j = json.decode(resp) if (j == nil or j.status ~= "ok" or j.status_message ~= "Query was successful") then return 0 end local last = #(j.data.asns) if last == 0 then return 0 end return j.data.asns[last].asn end function asinfo(asn) resp = cacherequest("https://api.bgpview.io/asn/" .. tostring(asn)) if resp == "" then return nil end j = json.decode(resp) if (j == nil or j.status ~= "ok" or j.status_message ~= "Query was successful") then return nil end local registry = "" if #(j.data.rir_allocation) > 0 then registry = j.data.rir_allocation.rir_name end return { ['asn']=asn, prefix=ip .. "/" .. tostring(cidr), desc=j.data.name .. " - " .. j.data.description_full, cc=j.data.country_code, ['registry']=registry, } end function netblocks(asn) local resp = cacherequest("https://api.bgpview.io/asn/" .. tostring(asn) .. "/prefixes") if resp == "" then return nil end local j = json.decode(resp) if (j == nil or j.status ~= "ok" or j.status_message ~= "Query was successful") then return nil end local netblocks = {} for i, p in pairs(j.data.ipv4_prefixes) do table.insert(netblocks, p.ip .. "/" .. tostring(p.cidr)) end for i, p in pairs(j.data.ipv6_prefixes) do table.insert(netblocks, p.ip .. "/" .. tostring(p.cidr)) end return netblocks end function cacherequest(url) local resp local cfg = datasrc_config() -- Check if the response data is in the graph database if (cfg and cfg.ttl ~= nil and cfg.ttl > 0) then resp = obtain_response(url, cfg.ttl) end if (resp == nil or resp == "") then local err checkratelimit() resp, err = request(ctx, { ['url']=url, headers={['Content-Type']="application/json"}, }) if (err ~= nil and err ~= "") then return "" end if (cfg and cfg.ttl ~= nil and cfg.ttl > 0) then cache_response(url, resp) end end return resp end
private package SPARKNaCl.PDebug with SPARK_Mode => On is procedure DH16 (S : in String; D : in Normal_GF); procedure DH32 (S : in String; D : in GF32); procedure DH64 (S : in String; D : in GF64); end SPARKNaCl.PDebug;
with HW.GFX; with HW.GFX.Framebuffer_Filler; with HW.GFX.GMA; with HW.GFX.GMA.Display_Probing; use HW.GFX; use HW.GFX.GMA; use HW.GFX.GMA.Display_Probing; with HW.Debug; with HW.Debug_Sink; with GMA.Mainboard; package body GMA is fb_valid : boolean := false; linear_fb_addr : word64; fb : Framebuffer_Type; function fill_lb_framebuffer (framebuffer : in out lb_framebuffer) return Interfaces.C.int is use type word64; use type Interfaces.C.int; begin if fb_valid then framebuffer := ( physical_address => linear_fb_addr, x_resolution => Word64(fb.Width), y_resolution => Word64(fb.Height), bpp => 32 ); Debug.Put ("fill_lb_framebuffer at "); Debug.Put_Word64(linear_fb_addr); Debug.Put (" and is "); Debug.Put_Int32(fb.Width); Debug.Put (" x "); Debug.Put_Int32(fb.Height); Debug.Put_Line (""); return 0; else return -1; end if; end fill_lb_framebuffer; ---------------------------------------------------------------------------- procedure gfxinit (lightup_ok : out Interfaces.C.int) is use type pos32; use type word64; ports : Port_List; configs : Pipe_Configs; success : boolean; min_h : pos16 := pos16'last; min_v : pos16 := pos16'last; begin lightup_ok := 0; HW.GFX.GMA.Initialize (Success => success); if success then ports := Mainboard.ports; HW.GFX.GMA.Display_Probing.Scan_Ports (configs, ports); if configs (Primary).Port /= Disabled then for i in Pipe_Index loop exit when configs (i).Port = Disabled; min_h := pos16'min (min_h, configs (i).Mode.H_Visible); min_v := pos16'min (min_v, configs (i).Mode.V_Visible); end loop; fb := configs (Primary).Framebuffer; fb.Width := Width_Type (min_h); fb.Height := Height_Type (min_v); fb.Stride := Div_Round_Up (fb.Width, 16) * 16; fb.V_Stride := fb.Height; for i in Pipe_Index loop exit when configs (i).Port = Disabled; configs (i).Framebuffer := fb; end loop; HW.GFX.GMA.Dump_Configs (configs); HW.GFX.GMA.Setup_Default_FB (FB => fb, Clear => true, Success => success); if success then HW.GFX.GMA.Update_Outputs (configs); HW.GFX.GMA.Map_Linear_FB (linear_fb_addr, fb); fb_valid := linear_fb_addr /= 0; lightup_ok := (if fb_valid then 1 else 0); end if; end if; end if; end gfxinit; procedure test_debugprint is begin HW.Debug_Sink.Put("\ngma test debug printt ok\n"); end test_debugprint; end GMA;
-- REST API Validation -- API to validate -- -- The version of the OpenAPI document: 1.0.0 -- Contact: Stephane.Carrez@gmail.com -- -- NOTE: This package is auto generated by OpenAPI-Generator 5.2.1-SNAPSHOT. -- https://openapi-generator.tech -- Do not edit the class manually. pragma Warnings (Off, "*is not referenced"); pragma Warnings (Off, "*no entities of*are referenced"); with Swagger.Servers; with TestAPI.Models; with Security.Permissions; package TestAPI.Skeletons is pragma Style_Checks ("-mr"); pragma Warnings (Off, "*use clause for package*"); use TestAPI.Models; type Server_Type is limited interface; -- Update a ticket package ACL_Write_Ticket is new Security.Permissions.Definition ("write:ticket"); -- Read a ticket package ACL_Read_Ticket is new Security.Permissions.Definition ("read:ticket"); -- -- Query an orchestrated service instance procedure Orch_Store (Server : in out Server_Type; Inline_Object_3Type : in InlineObject3_Type; Context : in out Swagger.Servers.Context_Type) is abstract; -- Create a ticket procedure Do_Create_Ticket (Server : in out Server_Type; Title : in Swagger.UString; Owner : in Swagger.Nullable_UString; Status : in Swagger.Nullable_UString; Description : in Swagger.Nullable_UString; Context : in out Swagger.Servers.Context_Type) is abstract; -- Delete a ticket procedure Do_Delete_Ticket (Server : in out Server_Type; Tid : in Swagger.Long; Context : in out Swagger.Servers.Context_Type) is abstract; -- List the tickets procedure Do_Head_Ticket (Server : in out Server_Type ; Context : in out Swagger.Servers.Context_Type) is abstract; -- Patch a ticket procedure Do_Patch_Ticket (Server : in out Server_Type; Tid : in Swagger.Long; Owner : in Swagger.Nullable_UString; Status : in Swagger.Nullable_UString; Title : in Swagger.Nullable_UString; Description : in Swagger.Nullable_UString; Result : out TestAPI.Models.Ticket_Type; Context : in out Swagger.Servers.Context_Type) is abstract; -- Update a ticket procedure Do_Update_Ticket (Server : in out Server_Type; Tid : in Swagger.Long; Owner : in Swagger.Nullable_UString; Status : in Swagger.Nullable_UString; Title : in Swagger.Nullable_UString; Description : in Swagger.Nullable_UString; Result : out TestAPI.Models.Ticket_Type; Context : in out Swagger.Servers.Context_Type) is abstract; -- Get a ticket -- Get a ticket procedure Do_Get_Ticket (Server : in out Server_Type; Tid : in Swagger.Long; Result : out TestAPI.Models.Ticket_Type; Context : in out Swagger.Servers.Context_Type) is abstract; -- List the tickets -- List the tickets created for the project. procedure Do_List_Tickets (Server : in out Server_Type; Status : in Swagger.Nullable_UString; Owner : in Swagger.Nullable_UString; Result : out TestAPI.Models.Ticket_Type_Vectors.Vector; Context : in out Swagger.Servers.Context_Type) is abstract; -- Get a ticket -- Get a ticket procedure Do_Options_Ticket (Server : in out Server_Type; Tid : in Swagger.Long; Result : out TestAPI.Models.Ticket_Type; Context : in out Swagger.Servers.Context_Type) is abstract; generic type Implementation_Type is limited new Server_Type with private; URI_Prefix : String := ""; package Skeleton is procedure Register (Server : in out Swagger.Servers.Application_Type'Class); -- procedure Orch_Store (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- Create a ticket procedure Do_Create_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- Delete a ticket procedure Do_Delete_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- List the tickets procedure Do_Head_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- Patch a ticket procedure Do_Patch_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- Update a ticket procedure Do_Update_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- Get a ticket procedure Do_Get_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- List the tickets procedure Do_List_Tickets (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- Get a ticket procedure Do_Options_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); end Skeleton; generic type Implementation_Type is limited new Server_Type with private; URI_Prefix : String := ""; package Shared_Instance is procedure Register (Server : in out Swagger.Servers.Application_Type'Class); -- procedure Orch_Store (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- Create a ticket procedure Do_Create_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- Delete a ticket procedure Do_Delete_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- List the tickets procedure Do_Head_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- Patch a ticket procedure Do_Patch_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- Update a ticket procedure Do_Update_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- Get a ticket procedure Do_Get_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- List the tickets procedure Do_List_Tickets (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); -- Get a ticket procedure Do_Options_Ticket (Req : in out Swagger.Servers.Request'Class; Reply : in out Swagger.Servers.Response'Class; Stream : in out Swagger.Servers.Output_Stream'Class; Context : in out Swagger.Servers.Context_Type); private protected Server is -- procedure Orch_Store (Inline_Object_3Type : in InlineObject3_Type; Context : in out Swagger.Servers.Context_Type); -- Create a ticket procedure Do_Create_Ticket (Title : in Swagger.UString; Owner : in Swagger.Nullable_UString; Status : in Swagger.Nullable_UString; Description : in Swagger.Nullable_UString; Context : in out Swagger.Servers.Context_Type); -- Delete a ticket procedure Do_Delete_Ticket (Tid : in Swagger.Long; Context : in out Swagger.Servers.Context_Type); -- List the tickets procedure Do_Head_Ticket (Context : in out Swagger.Servers.Context_Type); -- Patch a ticket procedure Do_Patch_Ticket (Tid : in Swagger.Long; Owner : in Swagger.Nullable_UString; Status : in Swagger.Nullable_UString; Title : in Swagger.Nullable_UString; Description : in Swagger.Nullable_UString; Result : out TestAPI.Models.Ticket_Type; Context : in out Swagger.Servers.Context_Type); -- Update a ticket procedure Do_Update_Ticket (Tid : in Swagger.Long; Owner : in Swagger.Nullable_UString; Status : in Swagger.Nullable_UString; Title : in Swagger.Nullable_UString; Description : in Swagger.Nullable_UString; Result : out TestAPI.Models.Ticket_Type; Context : in out Swagger.Servers.Context_Type); -- Get a ticket procedure Do_Get_Ticket (Tid : in Swagger.Long; Result : out TestAPI.Models.Ticket_Type; Context : in out Swagger.Servers.Context_Type); -- List the tickets procedure Do_List_Tickets (Status : in Swagger.Nullable_UString; Owner : in Swagger.Nullable_UString; Result : out TestAPI.Models.Ticket_Type_Vectors.Vector; Context : in out Swagger.Servers.Context_Type); -- Get a ticket procedure Do_Options_Ticket (Tid : in Swagger.Long; Result : out TestAPI.Models.Ticket_Type; Context : in out Swagger.Servers.Context_Type); private Impl : Implementation_Type; end Server; end Shared_Instance; end TestAPI.Skeletons;
-- C37209B.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. --* -- OBJECTIVE: -- CHECK THAT CONSTRAINT_ERROR IS RAISED WHEN THE SUBTYPE -- INDICATION IN A CONSTANT OBJECT DECLARATION SPECIFIES A -- CONSTRAINED SUBTYPE WITH DISCRIMINANTS AND THE INITIALIZATION -- VALUE DOES NOT BELONG TO THE SUBTYPE (I. E., THE DISCRIMINANT -- VALUE DOES NOT MATCH THOSE SPECIFIED BY THE CONSTRAINT). -- HISTORY: -- RJW 08/25/86 CREATED ORIGINAL TEST -- VCL 08/19/87 CHANGED THE RETURN TYPE OF FUNTION 'INIT' IN -- PACKAGE 'PRIV2' SO THAT 'INIT' IS UNCONSTRAINED, -- THUS NOT RAISING A CONSTRAINT ERROR ON RETURN FROM -- 'INIT'. WITH REPORT; USE REPORT; PROCEDURE C37209B IS BEGIN TEST ( "C37209B", "CHECK THAT CONSTRAINT_ERROR IS RAISED WHEN " & "THE SUBTYPE INDICATION IN A CONSTANT " & "OBJECT DECLARATION SPECIFIES A CONSTRAINED " & "SUBTYPE WITH DISCRIMINANTS AND THE " & "INITIALIZATION VALUE DOES NOT BELONG TO " & "THE SUBTYPE (I. E., THE DISCRIMINANT VALUE " & "DOES NOT MATCH THOSE SPECIFIED BY THE " & "CONSTRAINT)" ); DECLARE TYPE REC (D : INTEGER) IS RECORD NULL; END RECORD; SUBTYPE REC1 IS REC (IDENT_INT (5)); BEGIN DECLARE R1 : CONSTANT REC1 := (D => IDENT_INT (10)); I : INTEGER := IDENT_INT (R1.D); BEGIN FAILED ( "NO EXCEPTION RAISED FOR DECLARATION OF " & "R1" ); EXCEPTION WHEN OTHERS => FAILED ( "EXCEPTION FOR R1 RAISED INSIDE BLOCK" ); END; EXCEPTION WHEN CONSTRAINT_ERROR => NULL; WHEN OTHERS => FAILED ( "OTHER EXCEPTION RAISED AT DECLARATION OF " & "R1" ); END; BEGIN DECLARE PACKAGE PRIV1 IS TYPE REC (D : INTEGER) IS PRIVATE; SUBTYPE REC2 IS REC (IDENT_INT (5)); R2 : CONSTANT REC2; PRIVATE TYPE REC (D : INTEGER) IS RECORD NULL; END RECORD; R2 : CONSTANT REC2 := (D => IDENT_INT (10)); END PRIV1; USE PRIV1; BEGIN DECLARE I : INTEGER := IDENT_INT (R2.D); BEGIN FAILED ( "NO EXCEPTION RAISED AT DECLARATION " & "OF R2" ); END; END; EXCEPTION WHEN CONSTRAINT_ERROR => NULL; WHEN OTHERS => FAILED ( "OTHER EXCEPTION RAISED AT DECLARATION " & "OF R2" ); END; BEGIN DECLARE PACKAGE PRIV2 IS TYPE REC (D : INTEGER) IS PRIVATE; SUBTYPE REC3 IS REC (IDENT_INT (5)); FUNCTION INIT (D : INTEGER) RETURN REC; PRIVATE TYPE REC (D : INTEGER) IS RECORD NULL; END RECORD; END PRIV2; PACKAGE BODY PRIV2 IS FUNCTION INIT (D : INTEGER) RETURN REC IS BEGIN RETURN (D => IDENT_INT (D)); END INIT; END PRIV2; USE PRIV2; BEGIN DECLARE R3 : CONSTANT REC3 := INIT (10); I : INTEGER := IDENT_INT (R3.D); BEGIN FAILED ( "NO EXCEPTION RAISED AT DECLARATION " & "OF R3" ); END; END; EXCEPTION WHEN CONSTRAINT_ERROR => NULL; WHEN OTHERS => FAILED ( "OTHER EXCEPTION RAISED AT DECLARATION " & "OF R3" ); END; BEGIN DECLARE PACKAGE LPRIV IS TYPE REC (D : INTEGER) IS LIMITED PRIVATE; SUBTYPE REC4 IS REC (IDENT_INT (5)); R4 : CONSTANT REC4; PRIVATE TYPE REC (D : INTEGER) IS RECORD NULL; END RECORD; R4 : CONSTANT REC4 := (D => IDENT_INT (10)); END LPRIV; USE LPRIV; BEGIN DECLARE I : INTEGER := IDENT_INT (R4.D); BEGIN FAILED ( "NO EXCEPTION RAISED AT DECLARATION " & "OF R4" ); END; END; EXCEPTION WHEN CONSTRAINT_ERROR => NULL; WHEN OTHERS => FAILED ( "OTHER EXCEPTION RAISED AT DECLARATION " & "OF R4" ); END; RESULT; END C37209B;
-- 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.Characters.Handling; use Ada.Characters.Handling; with Ada.Characters.Latin_1; use Ada.Characters.Latin_1; with Ada.Containers.Vectors; use Ada.Containers; with Ada.Exceptions; use Ada.Exceptions; with Ada.Strings; use Ada.Strings; with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Interfaces.C; use Interfaces.C; with Interfaces.C.Strings; use Interfaces.C.Strings; with GNAT.Directory_Operations; use GNAT.Directory_Operations; with CArgv; use CArgv; with Tcl; use Tcl; with Tcl.Ada; use Tcl.Ada; with Tcl.Tk.Ada; use Tcl.Tk.Ada; with Tcl.Tk.Ada.Grid; 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.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.Widgets.TtkPanedWindow; use Tcl.Tk.Ada.Widgets.TtkPanedWindow; with Tcl.Tk.Ada.Widgets.TtkScrollbar; use Tcl.Tk.Ada.Widgets.TtkScrollbar; with Tcl.Tk.Ada.Winfo; use Tcl.Tk.Ada.Winfo; with Bases.Cargo; use Bases.Cargo; with BasesTypes; use BasesTypes; with Config; use Config; with CoreUI; use CoreUI; with Crew; use Crew; with Dialogs; use Dialogs; with Events; use Events; with Factions; use Factions; with Game; use Game; with Maps; use Maps; with Maps.UI; use Maps.UI; with Missions; use Missions; with Ships.Cargo; use Ships.Cargo; with Ships.Crew; use Ships.Crew; with Table; use Table; with Utils.UI; use Utils.UI; package body Trades.UI is -- ****iv* TUI/TUI.TradeTable -- FUNCTION -- Table with info about the available items to trade -- SOURCE TradeTable: Table_Widget (8); -- **** -- ****iv* TUI/TUI.Items_Indexes -- FUNCTION -- Indexes of the items for trade -- SOURCE Items_Indexes: Natural_Container.Vector; -- **** -- ****it* TUI/TUI.Items_Sort_Orders -- FUNCTION -- Sorting orders for the trading list -- OPTIONS -- NAMEASC - Sort items by name ascending -- NAMEDESC - Sort items by name descending -- TYPEASC - Sort items by type ascending -- TYPEDESC - Sort items by type descending -- DURABILITYASC - Sort items by durability ascending -- DURABILITYDESC - Sort items by durability descending -- PRICEASC - Sort items by price ascending -- PRICEDESC - Sort items by price descending -- PROFITASC - Sort items by profit ascending -- PROFITDESC - Sort items by profit descending -- WEIGHTASC - Sort items by weight ascending -- WEIGHTDESC - Sort items by weight descending -- OWNEDASC - Sort items by owned amount ascending -- OWNEDDESC - Sort items by owned amount descending -- AVAILABLEASC - Sort items by available amount ascending -- AVAILABLEDESC - Sort items by available amount descending -- NONE - No sorting modules (default) -- HISTORY -- 6.4 - Added -- SOURCE type Items_Sort_Orders is (NAMEASC, NAMEDESC, TYPEASC, TYPEDESC, DURABILITYASC, DURABILITYDESC, PRICEASC, PRICEDESC, PROFITASC, PROFITDESC, WEIGHTASC, WEIGHTDESC, OWNEDASC, OWNEDDESC, AVAILABLEASC, AVAILABLEDESC, NONE) with Default_Value => NONE; -- **** -- ****id* TUI/TUI.Default_Items_Sort_Order -- FUNCTION -- Default sorting order for the trading list -- HISTORY -- 6.4 - Added -- SOURCE Default_Items_Sort_Order: constant Items_Sort_Orders := NONE; -- **** -- ****iv* TUI/TUI.Items_Sort_Order -- FUNCTION -- The current sorting order for the trading list -- HISTORY -- 6.4 - Added -- SOURCE Items_Sort_Order: Items_Sort_Orders := Default_Items_Sort_Order; -- **** -- ****o* TUI/TUI.Show_Trade_Command -- FUNCTION -- Show information about trading -- 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. -- Argv - Values of arguments passed to the command. -- RESULT -- This function always return TCL_OK -- COMMANDS -- ShowTrade ?itemtype? ?searchstring? -- Itemtype is type of items to show, searchstring is string which is -- looking for in items names -- SOURCE function Show_Trade_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_Trade_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(ClientData); TradeFrame: Ttk_Frame := Get_Widget(Main_Paned & ".tradeframe", Interp); TradeCanvas: constant Tk_Canvas := Get_Widget(TradeFrame & ".canvas", Interp); Label: Ttk_Label := Get_Widget(TradeCanvas & ".trade.options.typelabel", Interp); ItemType, ProtoIndex, BaseType, ItemName, TradeInfo, ItemDurability: Unbounded_String; ItemsTypes: Unbounded_String := To_Unbounded_String("All"); Price: Positive; ComboBox: Ttk_ComboBox; BaseIndex: constant Natural := SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).BaseIndex; BaseCargo: BaseCargo_Container.Vector; BaseCargoIndex, BaseAmount: Natural; IndexesList: Positive_Container.Vector; EventIndex: constant Natural := SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).EventIndex; Profit: Integer; MoneyIndex2: constant Natural := FindItem(Player_Ship.Cargo, Money_Index); SearchEntry: constant Ttk_Entry := Get_Widget(TradeCanvas & ".trade.options.search", Interp); Page: constant Positive := (if Argc = 4 then Positive'Value(CArgv.Arg(Argv, 3)) else 1); Start_Row: constant Positive := ((Page - 1) * Game_Settings.Lists_Limit) + 1; Current_Row: Positive := 1; Arguments: constant String := (if Argc > 2 then "{" & CArgv.Arg(Argv, 1) & "} {" & CArgv.Arg(Argv, 2) & "}" elsif Argc = 2 then CArgv.Arg(Argv, 1) & " {}" else "All {}"); Current_Item_Index: Positive := 1; begin if Winfo_Get(Label, "exists") = "0" then Tcl_EvalFile (Get_Context, To_String(Data_Directory) & "ui" & Dir_Separator & "trade.tcl"); Bind(TradeFrame, "<Configure>", "{ResizeCanvas %W.canvas %w %h}"); TradeFrame := Get_Widget(TradeCanvas & ".trade"); TradeTable := CreateTable (Widget_Image(TradeFrame), (To_Unbounded_String("Name"), To_Unbounded_String("Type"), To_Unbounded_String("Durability"), To_Unbounded_String("Price"), To_Unbounded_String("Profit"), To_Unbounded_String("Weight"), To_Unbounded_String("Owned"), To_Unbounded_String("Available")), Get_Widget(Main_Paned & ".tradeframe.scrolly"), "SortTradeItems", "Press mouse button to sort the items."); elsif Winfo_Get(Label, "ismapped") = "1" and Argc = 1 then Items_Sort_Order := Default_Items_Sort_Order; Tcl.Tk.Ada.Grid.Grid_Remove(Close_Button); configure(Close_Button, "-command ShowSkyMap"); Entry_Configure(GameMenu, "Help", "-command {ShowHelp general}"); if BaseIndex = 0 and EventIndex > 0 then DeleteEvent(EventIndex); end if; ShowSkyMap(True); return TCL_OK; end if; if Argc < 3 then Delete(SearchEntry, "0", "end"); end if; configure(Close_Button, "-command {ShowSkyMap ShowTrade}"); Entry_Configure(GameMenu, "Help", "-command {ShowHelp trade}"); TradeFrame.Name := New_String(TradeCanvas & ".trade"); ComboBox := Get_Widget(TradeFrame & ".options.type", Interp); ClearTable(TradeTable); if BaseIndex > 0 then BaseType := Sky_Bases(BaseIndex).Base_Type; BaseCargo := Sky_Bases(BaseIndex).Cargo; else BaseType := To_Unbounded_String("0"); BaseCargo := TraderCargo; end if; if Items_Sort_Order = Default_Items_Sort_Order then Items_Indexes.Clear; for I in Player_Ship.Cargo.Iterate loop Items_Indexes.Append(Inventory_Container.To_Index(I)); end loop; Items_Indexes.Append(0); for I in BaseCargo.Iterate loop Items_Indexes.Append(BaseCargo_Container.To_Index(I)); end loop; end if; Show_Cargo_Items_Loop : for I of Items_Indexes loop Current_Item_Index := Current_Item_Index + 1; exit Show_Cargo_Items_Loop when I = 0; if Get_Price(BaseType, Player_Ship.Cargo(I).ProtoIndex) = 0 then goto End_Of_Cargo_Loop; end if; ProtoIndex := Player_Ship.Cargo(I).ProtoIndex; BaseCargoIndex := Find_Base_Cargo(ProtoIndex, Player_Ship.Cargo(I).Durability); if BaseCargoIndex > 0 then IndexesList.Append(New_Item => BaseCargoIndex); end if; ItemType := (if Items_List(ProtoIndex).ShowType = Null_Unbounded_String then Items_List(ProtoIndex).IType else Items_List(ProtoIndex).ShowType); if Index(ItemsTypes, To_String("{" & ItemType & "}")) = 0 then Append(ItemsTypes, " {" & ItemType & "}"); end if; if Argc > 1 and then CArgv.Arg(Argv, 1) /= "All" and then To_String(ItemType) /= CArgv.Arg(Argv, 1) then goto End_Of_Cargo_Loop; end if; ItemName := To_Unbounded_String (GetItemName(Player_Ship.Cargo(I), False, False)); if Argc = 3 and then Index (To_Lower(To_String(ItemName)), To_Lower(CArgv.Arg(Argv, 2))) = 0 then goto End_Of_Cargo_Loop; end if; if Current_Row < Start_Row then Current_Row := Current_Row + 1; goto End_Of_Cargo_Loop; end if; if BaseCargoIndex = 0 then Price := Get_Price(BaseType, ProtoIndex); else Price := (if BaseIndex > 0 then Sky_Bases(BaseIndex).Cargo(BaseCargoIndex).Price else TraderCargo(BaseCargoIndex).Price); end if; if EventIndex > 0 then if Events_List(EventIndex).EType = DoublePrice and then Events_List(EventIndex).ItemIndex = ProtoIndex then Price := Price * 2; end if; end if; Profit := Price - Player_Ship.Cargo(I).Price; BaseAmount := 0; if BaseCargoIndex > 0 and Is_Buyable(BaseType, ProtoIndex) then BaseAmount := BaseCargo(BaseCargoIndex).Amount; end if; AddButton (TradeTable, To_String(ItemName), "Show available options for item", "ShowTradeMenu" & Positive'Image(I), 1); AddButton (TradeTable, To_String(ItemType), "Show available options for item", "ShowTradeMenu" & Positive'Image(I), 2); ItemDurability := (if Player_Ship.Cargo(I).Durability < 100 then To_Unbounded_String (GetItemDamage(Player_Ship.Cargo(I).Durability)) else To_Unbounded_String("Unused")); AddProgressBar (TradeTable, Player_Ship.Cargo(I).Durability, Default_Item_Durability, To_String(ItemDurability), "ShowTradeMenu" & Positive'Image(I), 3); AddButton (TradeTable, Positive'Image(Price), "Show available options for item", "ShowTradeMenu" & Positive'Image(I), 4); AddButton (Table => TradeTable, Text => Positive'Image(Profit), Tooltip => "Show available options for item", Command => "ShowTradeMenu" & Positive'Image(I), Column => 5, Color => (if Profit > 0 then "green" elsif Profit < 0 then "red" else "")); AddButton (TradeTable, Positive'Image(Items_List(ProtoIndex).Weight) & " kg", "Show available options for item", "ShowTradeMenu" & Positive'Image(I), 6); AddButton (TradeTable, Positive'Image(Player_Ship.Cargo(I).Amount), "Show available options for item", "ShowTradeMenu" & Positive'Image(I), 7); AddButton (TradeTable, Positive'Image(BaseAmount), "Show available options for item", "ShowTradeMenu" & Positive'Image(I), 8, True); exit Show_Cargo_Items_Loop when TradeTable.Row = Game_Settings.Lists_Limit + 1; <<End_Of_Cargo_Loop>> end loop Show_Cargo_Items_Loop; Show_Trader_Items_Loop : for I in Current_Item_Index .. Items_Indexes.Last_Index loop exit Show_Trader_Items_Loop when TradeTable.Row = Game_Settings.Lists_Limit + 1; if IndexesList.Find_Index(Item => Items_Indexes(I)) > 0 or not Is_Buyable (Base_Type => BaseType, Item_Index => BaseCargo(Items_Indexes(I)).Proto_Index, Base_Index => BaseIndex) or BaseCargo(Items_Indexes(I)).Amount = 0 then goto End_Of_Trader_Loop; end if; ProtoIndex := BaseCargo(Items_Indexes(I)).Proto_Index; ItemType := (if Items_List(ProtoIndex).ShowType = Null_Unbounded_String then Items_List(ProtoIndex).IType else Items_List(ProtoIndex).ShowType); if Index(ItemsTypes, To_String("{" & ItemType & "}")) = 0 then Append(ItemsTypes, " {" & ItemType & "}"); end if; if Argc > 1 and then CArgv.Arg(Argv, 1) /= "All" and then To_String(ItemType) /= CArgv.Arg(Argv, 1) then goto End_Of_Trader_Loop; end if; ItemName := Items_List(ProtoIndex).Name; if Argc = 3 and then Index (To_Lower(To_String(ItemName)), To_Lower(CArgv.Arg(Argv, 2))) = 0 then goto End_Of_Trader_Loop; end if; if Current_Row < Start_Row then Current_Row := Current_Row + 1; goto End_Of_Trader_Loop; end if; Price := (if BaseIndex > 0 then Sky_Bases(BaseIndex).Cargo(Items_Indexes(I)).Price else TraderCargo(Items_Indexes(I)).Price); if EventIndex > 0 then if Events_List(EventIndex).EType = DoublePrice and then Events_List(EventIndex).ItemIndex = ProtoIndex then Price := Price * 2; end if; end if; BaseAmount := (if BaseIndex = 0 then TraderCargo(Items_Indexes(I)).Amount else Sky_Bases(BaseIndex).Cargo(Items_Indexes(I)).Amount); AddButton (TradeTable, To_String(ItemName), "Show available options for item", "ShowTradeMenu -" & Trim(Positive'Image(Items_Indexes(I)), Left), 1); AddButton (TradeTable, To_String(ItemType), "Show available options for item", "ShowTradeMenu -" & Trim(Positive'Image(Items_Indexes(I)), Left), 2); ItemDurability := (if BaseCargo(Items_Indexes(I)).Durability < 100 then To_Unbounded_String (GetItemDamage(BaseCargo(Items_Indexes(I)).Durability)) else To_Unbounded_String("Unused")); AddProgressBar (TradeTable, BaseCargo(Items_Indexes(I)).Durability, Default_Item_Durability, To_String(ItemDurability), "ShowTradeMenu -" & Trim(Positive'Image(Items_Indexes(I)), Left), 3); AddButton (TradeTable, Positive'Image(Price), "Show available options for item", "ShowTradeMenu -" & Trim(Positive'Image(Items_Indexes(I)), Left), 4); AddButton (TradeTable, Integer'Image(-(Price)), "Show available options for item", "ShowTradeMenu -" & Trim(Positive'Image(Items_Indexes(I)), Left), 5, False, "red"); AddButton (TradeTable, Positive'Image(Items_List(ProtoIndex).Weight) & " kg", "Show available options for item", "ShowTradeMenu -" & Trim(Positive'Image(Items_Indexes(I)), Left), 6); AddButton (TradeTable, " 0", "Show available options for item", "ShowTradeMenu -" & Trim(Positive'Image(Items_Indexes(I)), Left), 7); AddButton (TradeTable, Natural'Image(BaseAmount), "Show available options for item", "ShowTradeMenu -" & Trim(Positive'Image(Items_Indexes(I)), Left), 8, True); <<End_Of_Trader_Loop>> end loop Show_Trader_Items_Loop; if Page > 1 then if TradeTable.Row < Game_Settings.Lists_Limit + 1 then AddPagination (TradeTable, "ShowTrade " & Arguments & Positive'Image(Page - 1), ""); else AddPagination (TradeTable, "ShowTrade " & Arguments & Positive'Image(Page - 1), "ShowTrade " & Arguments & Positive'Image(Page + 1)); end if; elsif TradeTable.Row = Game_Settings.Lists_Limit + 1 then AddPagination (TradeTable, "", "ShowTrade " & Arguments & Positive'Image(Page + 1)); end if; UpdateTable (TradeTable, (if Focus = Widget_Image(SearchEntry) then False)); Tcl_Eval(Get_Context, "update"); configure(ComboBox, "-values [list " & To_String(ItemsTypes) & "]"); if Argc = 1 then Current(ComboBox, "0"); end if; if MoneyIndex2 > 0 then TradeInfo := To_Unbounded_String ("You have" & Natural'Image(Player_Ship.Cargo(MoneyIndex2).Amount) & " " & To_String(Money_Name) & "."); else TradeInfo := To_Unbounded_String ("You don't have any " & To_String(Money_Name) & " to buy anything."); end if; declare FreeSpace: Integer := FreeCargo(0); begin if FreeSpace < 0 then FreeSpace := 0; end if; Append (TradeInfo, LF & "Free cargo space:" & Integer'Image(FreeSpace) & " kg."); end; Label.Name := New_String(TradeFrame & ".options.playerinfo"); configure(Label, "-text {" & To_String(TradeInfo) & "}"); TradeInfo := Null_Unbounded_String; if BaseIndex > 0 then if Sky_Bases(BaseIndex).Cargo(1).Amount = 0 then Append (TradeInfo, "Base doesn't have any " & To_String(Money_Name) & "to buy anything."); else Append (TradeInfo, "Base has" & Positive'Image(Sky_Bases(BaseIndex).Cargo(1).Amount) & " " & To_String(Money_Name) & "."); end if; else if TraderCargo(1).Amount = 0 then Append (TradeInfo, "Ship doesn't have any " & To_String(Money_Name) & "to buy anything."); else Append (TradeInfo, "Ship has" & Positive'Image(TraderCargo(1).Amount) & " " & To_String(Money_Name) & "."); end if; end if; Label.Name := New_String(TradeFrame & ".options.baseinfo"); configure(Label, "-text {" & To_String(TradeInfo) & "}"); Tcl.Tk.Ada.Grid.Grid(Close_Button, "-row 0 -column 1"); configure (TradeCanvas, "-height [expr " & SashPos(Main_Paned, "0") & " - 20] -width " & cget(Main_Paned, "-width")); Tcl_Eval(Get_Context, "update"); Canvas_Create (TradeCanvas, "window", "0 0 -anchor nw -window " & TradeFrame); Tcl_Eval(Get_Context, "update"); configure (TradeCanvas, "-scrollregion [list " & BBox(TradeCanvas, "all") & "]"); Xview_Move_To(TradeCanvas, "0.0"); Yview_Move_To(TradeCanvas, "0.0"); Show_Screen("tradeframe"); Tcl_SetResult(Interp, "1"); return TCL_OK; end Show_Trade_Command; -- ****if* TUI/TUI.ItemIndex -- FUNCTION -- Index of the currently selected item -- SOURCE ItemIndex: Integer; -- **** -- ****o* TUI/TUI.Show_Trade_Item_Info_Command -- FUNCTION -- Show information about the selected item -- PARAMETERS -- ClientData - Custom data send to the command. Unused -- Interp - Tcl interpreter in which command was executed. Unused -- 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 -- ShowTradeItemInfo -- SOURCE function Show_Trade_Item_Info_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_Trade_Item_Info_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(ClientData, Interp, Argc, Argv); use Tiny_String; ItemInfo, ProtoIndex: Unbounded_String; CargoIndex, BaseCargoIndex: Natural := 0; BaseIndex: constant Natural := SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).BaseIndex; ItemTypes: constant array(1 .. 6) of Unbounded_String := (Weapon_Type, Chest_Armor, Head_Armor, Arms_Armor, Legs_Armor, Shield_Type); begin if ItemIndex < 0 then BaseCargoIndex := abs (ItemIndex); else CargoIndex := ItemIndex; end if; if CargoIndex > Natural(Player_Ship.Cargo.Length) then return TCL_OK; end if; if BaseIndex = 0 and BaseCargoIndex > Natural(TraderCargo.Length) then return TCL_OK; elsif BaseIndex > 0 and then BaseCargoIndex > Natural(Sky_Bases(BaseIndex).Cargo.Length) then return TCL_OK; end if; if CargoIndex > 0 then ProtoIndex := Player_Ship.Cargo(CargoIndex).ProtoIndex; else ProtoIndex := (if BaseIndex = 0 then TraderCargo(BaseCargoIndex).Proto_Index else Sky_Bases(BaseIndex).Cargo(BaseCargoIndex).Proto_Index); end if; if Items_List(ProtoIndex).IType = Weapon_Type then Append (ItemInfo, "Skill: " & To_String (SkillsData_Container.Element (Skills_List, Items_List(ProtoIndex).Value(3)) .Name) & "/" & To_String (AttributesData_Container.Element (Attributes_List, SkillsData_Container.Element (Skills_List, Items_List(ProtoIndex).Value(3)) .Attribute) .Name) & (if Items_List(ProtoIndex).Value(4) = 1 then LF & "Can be used with shield." else LF & "Can't be used with shield (two-handed weapon).") & LF & "Damage type: "); case Items_List(ProtoIndex).Value(5) is when 1 => Append(ItemInfo, "cutting"); when 2 => Append(ItemInfo, "impaling"); when 3 => Append(ItemInfo, "blunt"); when others => null; end case; end if; Show_More_Info_Loop : for ItemType of ItemTypes loop if Items_List(ProtoIndex).IType = ItemType then if ItemInfo /= Null_Unbounded_String then Append(ItemInfo, LF); end if; Append (ItemInfo, "Damage chance: " & GetItemChanceToDamage(Items_List(ProtoIndex).Value(1)) & LF & "Strength:" & Integer'Image(Items_List(ProtoIndex).Value(2))); exit Show_More_Info_Loop; end if; end loop Show_More_Info_Loop; if Tools_List.Contains(Items_List(ProtoIndex).IType) then if ItemInfo /= Null_Unbounded_String then Append(ItemInfo, LF); end if; Append (ItemInfo, "Damage chance: " & GetItemChanceToDamage(Items_List(ProtoIndex).Value(1))); end if; if Length(Items_List(ProtoIndex).IType) > 4 and then (Slice(Items_List(ProtoIndex).IType, 1, 4) = "Ammo" or Items_List(ProtoIndex).IType = To_Unbounded_String("Harpoon")) then if ItemInfo /= Null_Unbounded_String then Append(ItemInfo, LF); end if; Append (ItemInfo, "Strength:" & Integer'Image(Items_List(ProtoIndex).Value(1))); end if; if Items_List(ProtoIndex).Description /= Null_Unbounded_String then if ItemInfo /= Null_Unbounded_String then Append(ItemInfo, LF & LF); end if; Append(ItemInfo, Items_List(ProtoIndex).Description); end if; ShowInfo (Text => To_String(ItemInfo), Title => To_String(Items_List(ProtoIndex).Name)); return TCL_OK; end Show_Trade_Item_Info_Command; -- ****o* TUI/TUI.Trade_Item_Command -- FUNCTION -- Buy or sell the selected item -- PARAMETERS -- ClientData - Custom data send to the command. -- 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 -- TradeItem tradetype -- Tradetype is type of trade action. Can be buy, buymax, sell, sellmax -- SOURCE function Trade_Item_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Trade_Item_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is BaseIndex: constant Natural := SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).BaseIndex; BaseCargoIndex, CargoIndex: Natural := 0; Trader: String(1 .. 4); ProtoIndex: Unbounded_String; TypeBox: constant Ttk_ComboBox := Get_Widget (Main_Paned & ".tradeframe.canvas.trade.options.type", Interp); AmountBox: constant Ttk_SpinBox := Get_Widget(".itemdialog.amount", Interp); begin if ItemIndex < 0 then BaseCargoIndex := abs (ItemIndex); else CargoIndex := ItemIndex; end if; if CargoIndex > 0 then ProtoIndex := Player_Ship.Cargo(CargoIndex).ProtoIndex; if BaseCargoIndex = 0 then BaseCargoIndex := Find_Base_Cargo(ProtoIndex); end if; else ProtoIndex := (if BaseIndex = 0 then TraderCargo(BaseCargoIndex).Proto_Index else Sky_Bases(BaseIndex).Cargo(BaseCargoIndex).Proto_Index); end if; Trader := (if BaseIndex > 0 then "base" else "ship"); if Argc > 2 then if CArgv.Arg(Argv, 1) in "buy" then BuyItems(BaseCargoIndex, CArgv.Arg(Argv, 2)); else SellItems(CargoIndex, CArgv.Arg(Argv, 2)); end if; else if CArgv.Arg(Argv, 1) in "buy" then BuyItems(BaseCargoIndex, Get(AmountBox)); else SellItems(CargoIndex, Get(AmountBox)); end if; if Close_Dialog_Command (ClientData, Interp, 2, CArgv.Empty & "CloseDialog" & ".itemdialog") = TCL_ERROR then return TCL_ERROR; end if; end if; UpdateHeader; Update_Messages; return Show_Trade_Command (ClientData, Interp, 2, CArgv.Empty & "ShowTrade" & Get(TypeBox)); exception when An_Exception : Trade_Cant_Buy => ShowMessage (Text => "You can't buy " & Exception_Message(An_Exception) & " in this " & Trader & ".", Title => "Can't buy items"); return TCL_OK; when An_Exception : Trade_Not_For_Sale_Now => ShowMessage (Text => "You can't buy " & Exception_Message(An_Exception) & " in this base at this moment.", Title => "Can't buy items"); return TCL_OK; when An_Exception : Trade_Buying_Too_Much => ShowMessage (Text => Trader & " don't have that much " & Exception_Message(An_Exception) & " for sale.", Title => "Not enough items"); return TCL_OK; when Trade_No_Free_Cargo => ShowMessage (Text => "You don't have that much free space in your ship cargo.", Title => "No free cargo space"); return TCL_OK; when An_Exception : Trade_No_Money => ShowMessage (Text => "You don't have any " & To_String(Money_Name) & " to buy " & Exception_Message(An_Exception) & ".", Title => "No money to buy items"); return TCL_OK; when An_Exception : Trade_Not_Enough_Money => ShowMessage (Text => "You don't have enough " & To_String(Money_Name) & " to buy so much " & Exception_Message(An_Exception) & ".", Title => "Not enough money to buy items"); return TCL_OK; when Trade_Invalid_Amount => if CArgv.Arg(Argv, 1) = "buy" then ShowMessage (Text => "You entered invalid amount to buy.", Title => "Invalid amount of items"); else ShowMessage (Text => "You entered invalid amount to sell.", Title => "Invalid amount of items"); end if; return TCL_OK; when An_Exception : Trade_Too_Much_For_Sale => ShowMessage (Text => "You dont have that much " & Exception_Message(An_Exception) & " in ship cargo.", Title => "Not enough items for sale"); return TCL_OK; when An_Exception : Trade_No_Money_In_Base => ShowMessage (Text => "You can't sell so much " & Exception_Message(An_Exception) & " because " & Trader & " don't have that much " & To_String(Money_Name) & " to buy it.", Title => "Too much items for sale"); return TCL_OK; when Trade_No_Trader => ShowMessage (Text => "You don't have assigned anyone in crew to talk in bases duty.", Title => "No trader assigned"); return TCL_OK; end Trade_Item_Command; -- ****o* TUI/TUI.Search_Trade_Command -- FUNCTION -- Show only this items which contains the selected sequence -- PARAMETERS -- ClientData - Custom data send to the command. -- 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 -- SearchTrade -- SOURCE function Search_Trade_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Search_Trade_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(Argc); TypeBox: constant Ttk_ComboBox := Get_Widget (Main_Paned & ".tradeframe.canvas.trade.options.type", Interp); SearchText: constant String := CArgv.Arg(Argv, 1); begin if SearchText'Length = 0 then return Show_Trade_Command (ClientData, Interp, 2, CArgv.Empty & "ShowTrade" & Get(TypeBox)); end if; return Show_Trade_Command (ClientData, Interp, 3, CArgv.Empty & "ShowTrade" & Get(TypeBox) & SearchText); end Search_Trade_Command; -- ****o* TUI/TUI.Show_Trade_Menu_Command -- FUNCTION -- Show trade menu with buy/sell options for the selected item -- PARAMETERS -- ClientData - Custom data send to the command. -- 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 -- ShowTradeMenu itemindex -- ItemIndex is the index of the item which menu will be show. If index -- starts with minus means item in base/trader cargo only. Otherwise it is -- index in the player ship cargo. -- SOURCE function Show_Trade_Menu_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_Trade_Menu_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); TradeMenu: Tk_Menu := Get_Widget(".trademenu", Interp); MoneyIndex2: constant Natural := FindItem(Player_Ship.Cargo, Money_Index); BaseIndex: constant Natural := SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).BaseIndex; BaseCargoIndex2, Price: Natural; ProtoIndex, BaseType: Unbounded_String; begin ItemIndex := Integer'Value(CArgv.Arg(Argv, 1)); if Winfo_Get(TradeMenu, "exists") = "0" then TradeMenu := Create(".trademenu", "-tearoff false"); end if; Delete(TradeMenu, "0", "end"); BaseType := (if BaseIndex > 0 then Sky_Bases(BaseIndex).Base_Type else To_Unbounded_String("0")); if ItemIndex > 0 then ProtoIndex := Player_Ship.Cargo(ItemIndex).ProtoIndex; BaseCargoIndex2 := Find_Base_Cargo(ProtoIndex); else BaseCargoIndex2 := abs (ItemIndex); ProtoIndex := (if BaseIndex = 0 then TraderCargo(BaseCargoIndex2).Proto_Index else Sky_Bases(BaseIndex).Cargo(BaseCargoIndex2).Proto_Index); end if; if ItemIndex > 0 then if BaseCargoIndex2 > 0 then Price := (if BaseIndex > 0 then Sky_Bases(BaseIndex).Cargo(BaseCargoIndex2).Price else TraderCargo(BaseCargoIndex2).Price); else Price := Get_Price(BaseType, ProtoIndex); end if; else Price := (if BaseIndex > 0 then Sky_Bases(BaseIndex).Cargo(BaseCargoIndex2).Price else TraderCargo(BaseCargoIndex2).Price); end if; declare EventIndex: constant Natural := SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).EventIndex; begin if EventIndex > 0 then if Events_List(EventIndex).EType = DoublePrice and then Events_List(EventIndex).ItemIndex = ProtoIndex then Price := Price * 2; end if; end if; end; if ItemIndex > 0 then declare MaxSellAmount: Integer := Player_Ship.Cargo(ItemIndex).Amount; MaxPrice: Natural := MaxSellAmount * Price; Weight: Integer; begin Count_Price(MaxPrice, FindMember(Talk), False); if BaseIndex > 0 and then MaxPrice > Sky_Bases(BaseIndex).Cargo(1).Amount then MaxSellAmount := Natural (Float'Floor (Float(MaxSellAmount) * (Float(Sky_Bases(BaseIndex).Cargo(1).Amount) / Float(MaxPrice)))); elsif BaseIndex = 0 and then MaxPrice > TraderCargo(1).Amount then MaxSellAmount := Natural (Float'Floor (Float(MaxSellAmount) * (Float(TraderCargo(1).Amount) / Float(MaxPrice)))); end if; MaxPrice := MaxSellAmount * Price; if MaxPrice > 0 then Count_Price(MaxPrice, FindMember(Talk), False); end if; Weight := FreeCargo ((Items_List(ProtoIndex).Weight * MaxSellAmount) - MaxPrice); Count_Sell_Amount_loop : while Weight < 0 loop MaxSellAmount := Integer (Float'Floor (Float(MaxSellAmount) * (Float(MaxPrice + Weight) / Float(MaxPrice)))); exit Count_Sell_Amount_loop when MaxSellAmount < 1; MaxPrice := MaxSellAmount * Price; Count_Price(MaxPrice, FindMember(Talk), False); Weight := FreeCargo ((Items_List(ProtoIndex).Weight * MaxSellAmount) - MaxPrice); end loop Count_Sell_Amount_loop; if MaxSellAmount > 0 then Menu.Add (TradeMenu, "command", "-label {Sell selected amount} -command {TradeAmount sell " & Natural'Image(MaxSellAmount) & Natural'Image(Price) & "}"); Menu.Add (TradeMenu, "command", "-label {Sell" & Natural'Image(MaxSellAmount) & " of them} -command {TradeItem sell" & Natural'Image(MaxSellAmount) & "}"); end if; end; end if; if BaseCargoIndex2 > 0 and MoneyIndex2 > 0 and Is_Buyable(BaseType, ProtoIndex) then declare MaxBuyAmount: Integer := Player_Ship.Cargo(MoneyIndex2).Amount / Price; MaxPrice: Natural := MaxBuyAmount * Price; Weight: Integer; begin if MaxBuyAmount > 0 then Count_Price(MaxPrice, FindMember(Talk)); if MaxPrice < (MaxBuyAmount * Price) then MaxBuyAmount := Natural (Float'Floor (Float(MaxBuyAmount) * ((Float(MaxBuyAmount) * Float(Price)) / Float(MaxPrice)))); end if; if BaseIndex > 0 and then MaxBuyAmount > Sky_Bases(BaseIndex).Cargo(BaseCargoIndex2).Amount then MaxBuyAmount := Sky_Bases(BaseIndex).Cargo(BaseCargoIndex2).Amount; elsif BaseIndex = 0 and then MaxBuyAmount > TraderCargo(BaseCargoIndex2).Amount then MaxBuyAmount := TraderCargo(BaseCargoIndex2).Amount; end if; MaxPrice := MaxBuyAmount * Price; Count_Price(MaxPrice, FindMember(Talk)); Weight := FreeCargo (MaxPrice - (Items_List(ProtoIndex).Weight * MaxBuyAmount)); Count_Buy_Amount_Loop : while Weight < 0 loop MaxBuyAmount := MaxBuyAmount + (Weight / Items_List(ProtoIndex).Weight) - 1; if MaxBuyAmount < 0 then MaxBuyAmount := 0; end if; exit Count_Buy_Amount_Loop when MaxBuyAmount = 0; MaxPrice := MaxBuyAmount * Price; Count_Price(MaxPrice, FindMember(Talk)); Weight := FreeCargo (MaxPrice - (Items_List(ProtoIndex).Weight * MaxBuyAmount)); end loop Count_Buy_Amount_Loop; if MaxBuyAmount > 0 then Menu.Add (TradeMenu, "command", "-label {Buy selected amount} -command {TradeAmount buy" & Natural'Image(MaxBuyAmount) & Natural'Image(Price) & "}"); Menu.Add (TradeMenu, "command", "-label {Buy" & Natural'Image(MaxBuyAmount) & " of them} -command {TradeItem buy" & Natural'Image(MaxBuyAmount) & "}"); end if; end if; end; end if; Menu.Add (TradeMenu, "command", "-label {Show more info about the item} -command ShowTradeItemInfo"); Tk_Popup (TradeMenu, Winfo_Get(Get_Main_Window(Interp), "pointerx"), Winfo_Get(Get_Main_Window(Interp), "pointery")); return TCL_OK; end Show_Trade_Menu_Command; -- ****o* TUI/TUI.Trade_Amount_Command -- FUNCTION -- Show dialog to enter amount of items to sell or buy -- PARAMETERS -- ClientData - Custom data send to the command. Unused -- Interp - Tcl interpreter in which command was executed. Unused -- 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 -- TradeAmount action baseindex -- Action which will be taken. Can be buy or sell. BaseIndex is the index -- of the base from which item will be bought. If zero it mean buying from -- trader ship. -- SOURCE function Trade_Amount_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Trade_Amount_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(ClientData, Interp, Argc); BaseIndex: constant Natural := SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).BaseIndex; begin if CArgv.Arg(Argv, 1) = "sell" then ShowManipulateItem ("Sell " & GetItemName(Player_Ship.Cargo(ItemIndex)), "TradeItem sell", "sell", ItemIndex, Natural'Value(CArgv.Arg(Argv, 2)), Natural'Value(CArgv.Arg(Argv, 3))); else if ItemIndex > 0 then ShowManipulateItem ("Buy " & GetItemName(Player_Ship.Cargo(ItemIndex)), "TradeItem buy", "buy", ItemIndex, Natural'Value(CArgv.Arg(Argv, 2)), Natural'Value(CArgv.Arg(Argv, 3))); else if BaseIndex > 0 then ShowManipulateItem ("Buy " & To_String (Items_List (Sky_Bases(BaseIndex).Cargo(abs (ItemIndex)) .Proto_Index) .Name), "TradeItem buy", "buy", abs (ItemIndex), Natural'Value(CArgv.Arg(Argv, 2)), Natural'Value(CArgv.Arg(Argv, 3))); else ShowManipulateItem ("Buy " & To_String (Items_List(TraderCargo(abs (ItemIndex)).Proto_Index) .Name), "TradeItem buy", "buy", abs (ItemIndex), Natural'Value(CArgv.Arg(Argv, 2)), Natural'Value(CArgv.Arg(Argv, 3))); end if; end if; end if; return TCL_OK; end Trade_Amount_Command; -- ****o* TUI/TUI.Sort_Items_Command -- FUNCTION -- Sort the trading list -- PARAMETERS -- ClientData - Custom data send to the command. -- 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 -- SortTradeItems x -- X is X axis coordinate where the player clicked the mouse button -- SOURCE function Sort_Items_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int with Convention => C; -- **** function Sort_Items_Command (ClientData: Integer; Interp: Tcl.Tcl_Interp; Argc: Interfaces.C.int; Argv: CArgv.Chars_Ptr_Ptr) return Interfaces.C.int is pragma Unreferenced(Argc); Column: constant Positive := Get_Column_Number(TradeTable, Natural'Value(CArgv.Arg(Argv, 1))); type Local_Item_Data is record Name: Unbounded_String; IType: Unbounded_String; Damage: Float; Price: Natural; Profit: Integer; Weight: Positive; Owned: Natural; Available: Natural; Id: Positive; end record; BaseIndex: constant Natural := SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).BaseIndex; Indexes_List: Positive_Container.Vector; BaseCargo: BaseCargo_Container.Vector; BaseCargoIndex, Price: Natural; ProtoIndex, BaseType: Unbounded_String; EventIndex: constant Natural := SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).EventIndex; package Items_Container is new Vectors (Index_Type => Positive, Element_Type => Local_Item_Data); Local_Items: Items_Container.Vector; function "<"(Left, Right: Local_Item_Data) return Boolean is begin if Items_Sort_Order = NAMEASC and then Left.Name < Right.Name then return True; end if; if Items_Sort_Order = NAMEDESC and then Left.Name > Right.Name then return True; end if; if Items_Sort_Order = TYPEASC and then Left.IType < Right.IType then return True; end if; if Items_Sort_Order = TYPEDESC and then Left.IType > Right.IType then return True; end if; if Items_Sort_Order = DURABILITYASC and then Left.Damage < Right.Damage then return True; end if; if Items_Sort_Order = DURABILITYDESC and then Left.Damage > Right.Damage then return True; end if; if Items_Sort_Order = PRICEASC and then Left.Price < Right.Price then return True; end if; if Items_Sort_Order = PRICEDESC and then Left.Price > Right.Price then return True; end if; if Items_Sort_Order = PROFITASC and then Left.Profit < Right.Profit then return True; end if; if Items_Sort_Order = PROFITDESC and then Left.Profit > Right.Profit then return True; end if; if Items_Sort_Order = WEIGHTASC and then Left.Weight < Right.Weight then return True; end if; if Items_Sort_Order = WEIGHTDESC and then Left.Weight > Right.Weight then return True; end if; if Items_Sort_Order = OWNEDASC and then Left.Owned < Right.Owned then return True; end if; if Items_Sort_Order = OWNEDDESC and then Left.Owned > Right.Owned then return True; end if; if Items_Sort_Order = AVAILABLEASC and then Left.Available < Right.Available then return True; end if; if Items_Sort_Order = AVAILABLEDESC and then Left.Available > Right.Available then return True; end if; return False; end "<"; package Sort_Items is new Items_Container.Generic_Sorting; begin case Column is when 1 => if Items_Sort_Order = NAMEASC then Items_Sort_Order := NAMEDESC; else Items_Sort_Order := NAMEASC; end if; when 2 => if Items_Sort_Order = TYPEASC then Items_Sort_Order := TYPEDESC; else Items_Sort_Order := TYPEASC; end if; when 3 => if Items_Sort_Order = DURABILITYASC then Items_Sort_Order := DURABILITYDESC; else Items_Sort_Order := DURABILITYASC; end if; when 4 => if Items_Sort_Order = PRICEASC then Items_Sort_Order := PRICEDESC; else Items_Sort_Order := PRICEASC; end if; when 5 => if Items_Sort_Order = PROFITASC then Items_Sort_Order := PROFITDESC; else Items_Sort_Order := PROFITASC; end if; when 6 => if Items_Sort_Order = WEIGHTASC then Items_Sort_Order := WEIGHTDESC; else Items_Sort_Order := WEIGHTASC; end if; when 7 => if Items_Sort_Order = OWNEDASC then Items_Sort_Order := OWNEDDESC; else Items_Sort_Order := OWNEDASC; end if; when 8 => if Items_Sort_Order = AVAILABLEASC then Items_Sort_Order := AVAILABLEDESC; else Items_Sort_Order := AVAILABLEASC; end if; when others => null; end case; if Items_Sort_Order = Default_Items_Sort_Order then return TCL_OK; end if; if BaseIndex > 0 then BaseCargo := Sky_Bases(BaseIndex).Cargo; BaseType := Sky_Bases(BaseIndex).Base_Type; else BaseCargo := TraderCargo; BaseType := To_Unbounded_String("0"); end if; for I in Player_Ship.Cargo.Iterate loop ProtoIndex := Player_Ship.Cargo(I).ProtoIndex; BaseCargoIndex := Find_Base_Cargo(ProtoIndex, Player_Ship.Cargo(I).Durability); if BaseCargoIndex > 0 then Indexes_List.Append(New_Item => BaseCargoIndex); Price := BaseCargo(BaseCargoIndex).Price; else Price := Get_Price(BaseType, ProtoIndex); end if; if EventIndex > 0 then if Events_List(EventIndex).EType = DoublePrice and then Events_List(EventIndex).ItemIndex = ProtoIndex then Price := Price * 2; end if; end if; Local_Items.Append (New_Item => (Name => To_Unbounded_String(GetItemName(Player_Ship.Cargo(I))), IType => (if Items_List(ProtoIndex).ShowType = Null_Unbounded_String then Items_List(ProtoIndex).IType else Items_List(ProtoIndex).ShowType), Damage => Float(Player_Ship.Cargo(I).Durability) / Float(Default_Item_Durability), Price => Price, Profit => Price - Player_Ship.Cargo(I).Price, Weight => Items_List(ProtoIndex).Weight, Owned => Player_Ship.Cargo(I).Amount, Available => (if BaseCargoIndex > 0 then BaseCargo(BaseCargoIndex).Amount else 0), Id => Inventory_Container.To_Index(I))); end loop; Sort_Items.Sort(Local_Items); Items_Indexes.Clear; for Item of Local_Items loop Items_Indexes.Append(Item.Id); end loop; Items_Indexes.Append(0); Local_Items.Clear; for I in BaseCargo.First_Index .. BaseCargo.Last_Index loop if Indexes_List.Find_Index(Item => I) = 0 then ProtoIndex := BaseCargo(I).Proto_Index; Price := BaseCargo(I).Price; if EventIndex > 0 then if Events_List(EventIndex).EType = DoublePrice and then Events_List(EventIndex).ItemIndex = ProtoIndex then Price := Price * 2; end if; end if; Local_Items.Append (New_Item => (Name => Items_List(ProtoIndex).Name, IType => (if Items_List(ProtoIndex).ShowType = Null_Unbounded_String then Items_List(ProtoIndex).IType else Items_List(ProtoIndex).ShowType), Damage => Float(BaseCargo(I).Durability) / Float(Default_Item_Durability), Price => Price, Profit => -(Price), Weight => Items_List(ProtoIndex).Weight, Owned => 0, Available => BaseCargo(I).Amount, Id => I)); end if; end loop; Sort_Items.Sort(Local_Items); for Item of Local_Items loop Items_Indexes.Append(Item.Id); end loop; return Show_Trade_Command (ClientData, Interp, 2, CArgv.Empty & "ShowTrade" & "All"); end Sort_Items_Command; procedure AddCommands is begin Add_Command("ShowTrade", Show_Trade_Command'Access); Add_Command("ShowTradeItemInfo", Show_Trade_Item_Info_Command'Access); Add_Command("TradeItem", Trade_Item_Command'Access); Add_Command("SearchTrade", Search_Trade_Command'Access); Add_Command("ShowTradeMenu", Show_Trade_Menu_Command'Access); Add_Command("TradeAmount", Trade_Amount_Command'Access); Add_Command("SortTradeItems", Sort_Items_Command'Access); end AddCommands; end Trades.UI;
Pragma Ada_2012; Pragma Assertion_Policy( Check ); With Ada.Finalization, Ada.Streams; Generic Type Character is (<>); Type String is array(Positive Range <>) of Character; Empty_String : String := (2..1 => <>); Type File_Type is limited private; Type File_Mode is (<>); Type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class; with function Stream (File : File_Type) return Stream_Access is <>; with procedure Create (File : in out File_Type; Mode : File_Mode; Name : String := Empty_String; Form : String := Empty_String) is <>; with procedure Open (File : in out File_Type; Mode : File_Mode; Name : String; Form : String := Empty_String) is <>; with procedure Close (File : In Out File_Type) is <>; with procedure Delete (File : In Out File_Type) is <>; with procedure Reset (File : In Out File_Type; Mode : File_Mode) is <>; with procedure Reset (File : In Out File_Type) is <>; with function Mode (File : In File_Type) return File_Mode is <>; with function Name (File : In File_Type) return String is <>; with function Form (File : In File_Type) return String is <>; with function Is_Open (File : In File_Type) return Boolean is <>; Package EVIL.Util.Files with Pure, SPARK_Mode => On is Type File is tagged limited private; Function Create (Name : In String; Mode : In File_Mode) Return File with Global => Null, Depends => (Create'Result => (Name, Mode)); Function Open (Name : In String; Mode : In File_Mode) Return File with Global => Null, Depends => (Open'Result => (Name, Mode)); Function Mode (Object : In File) Return File_Mode with Global => Null, Depends => (Mode'Result => Object); Function Name (Object : In File) Return String with Global => Null, Depends => (Name'Result => Object); Function Form (Object : In File) Return String with Global => Null, Depends => (Form'Result => Object); Function Open (Object : In File) Return Boolean with Global => Null, Depends => (Open'Result => Object); Function Stream (Object : In File) Return Stream_Access with Global => Null, Depends => (Stream'Result => Object); Procedure Close (Object : In Out File) with Global => Null, Depends => (Object =>+ Null); Procedure Delete (Object : In Out File) with Global => Null, Depends => (Object =>+ Null); Procedure Reset (Object : In Out File) with Global => Null, Depends => (Object =>+ Null); Procedure Reset (Object : In Out File; Mode : In File_Mode) with Global => Null, Depends => (Object =>+ Mode); Private Type File is new Ada.Finalization.Limited_Controlled with Record Data : Aliased File_Type; FSA : Stream_Access; end record; Overriding Procedure Finalize (Object : In Out File) with Global => Null, Depends => (Object => Null); Function Stream (Object : File) return Stream_Access is (Object.FSA); End EVIL.Util.Files;
with Ada.Real_Time; package Support.Clock is beg_clock : Ada.Real_Time.Time; end_clock : Ada.Real_Time.Time; function get_date return String; function get_elapsed (beg_clock : Ada.Real_Time.Time; end_clock : Ada.Real_Time.Time) return Real; procedure reset_elapsed_cpu; procedure report_elapsed_cpu (num_points, num_loop : Integer); end Support.Clock;
with System.Address_To_Named_Access_Conversions; with System.Storage_Map; with System.System_Allocators; package body System.Unbounded_Stack_Allocators is pragma Suppress (All_Checks); use type Storage_Elements.Integer_Address; use type Storage_Elements.Storage_Offset; Down : Boolean renames Storage_Map.Growing_Down_Is_Preferred; Expanding : constant := 1; -- connecting next page pragma Warnings (Off, Expanding); function Ceiling_Page_Size (Required : Storage_Elements.Storage_Count) return Storage_Elements.Storage_Count; function Ceiling_Page_Size (Required : Storage_Elements.Storage_Count) return Storage_Elements.Storage_Count is Alignment : constant Storage_Elements.Integer_Address := Storage_Elements.Integer_Address (System_Allocators.Page_Size); begin return Storage_Elements.Storage_Offset ( Storage_Elements.Integer_Address'Mod (Required) + Storage_Elements.Integer_Address'Mod (-Required) mod Alignment); end Ceiling_Page_Size; package BA_Conv is new Address_To_Named_Access_Conversions (Block, Block_Access); function Cast (X : Address) return Block_Access renames BA_Conv.To_Pointer; function Align_Header_Size (Mask : Storage_Elements.Integer_Address) return Storage_Elements.Storage_Count; function Align_Header_Size (Mask : Storage_Elements.Integer_Address) return Storage_Elements.Storage_Count is Header_Size : constant Storage_Elements.Storage_Count := Block'Size / Standard'Storage_Unit; begin return Storage_Elements.Storage_Count ( (Storage_Elements.Integer_Address (Header_Size) + Mask) and not Mask); end Align_Header_Size; -- direction-depended operations procedure Commit ( Used : in out Address; Storage_Address : out Address; Size_In_Storage_Elements : Storage_Elements.Storage_Count; Mask : Storage_Elements.Integer_Address); procedure Commit ( Used : in out Address; Storage_Address : out Address; Size_In_Storage_Elements : Storage_Elements.Storage_Count; Mask : Storage_Elements.Integer_Address) is begin if Down then Storage_Address := Address ( (Storage_Elements.Integer_Address ( Used - Size_In_Storage_Elements) - Mask) and not Mask); Used := Storage_Address; else Storage_Address := Address ( (Storage_Elements.Integer_Address (Used) + Mask) and not Mask); Used := Storage_Address + Size_In_Storage_Elements; end if; end Commit; function Is_In (New_Used, B : Address) return Boolean; function Is_In (New_Used, B : Address) return Boolean is Header_Size : constant Storage_Elements.Storage_Count := Block'Size / Standard'Storage_Unit; begin if Down then return New_Used >= B + Header_Size; else return New_Used <= Cast (B).Limit; end if; end Is_In; function Bottom (B : Address) return Address; function Bottom (B : Address) return Address is Header_Size : constant Storage_Elements.Storage_Count := Block'Size / Standard'Storage_Unit; begin if Down then return Cast (B).Limit; else return B + Header_Size; end if; end Bottom; function Growing_Address ( Current_Block : Address; Additional_Block_Size : Storage_Elements.Storage_Count) return Address; function Growing_Address ( Current_Block : Address; Additional_Block_Size : Storage_Elements.Storage_Count) return Address is begin if Down then return Current_Block - Additional_Block_Size; else return Cast (Current_Block).Limit; end if; end Growing_Address; function Is_Growable ( Current_Block : Address; Additional_Block : Address; Additional_Block_Size : Storage_Elements.Storage_Count; Reverse_Growing : Boolean) return Boolean; function Is_Growable ( Current_Block : Address; Additional_Block : Address; Additional_Block_Size : Storage_Elements.Storage_Count; Reverse_Growing : Boolean) return Boolean is begin if Down /= Reverse_Growing then return (Additional_Block + Additional_Block_Size) = Current_Block; else return Cast (Current_Block).Limit = Additional_Block; end if; end Is_Growable; procedure Grow ( Current_Block : in out Address; Additional_Block : Address; Additional_Block_Size : Storage_Elements.Storage_Count; Reverse_Growing : Boolean; Top_Is_Unused : Boolean); procedure Grow ( Current_Block : in out Address; Additional_Block : Address; Additional_Block_Size : Storage_Elements.Storage_Count; Reverse_Growing : Boolean; Top_Is_Unused : Boolean) is begin if Down /= Reverse_Growing then Cast (Additional_Block).all := Cast (Current_Block).all; if Top_Is_Unused then Cast (Additional_Block).Used := Bottom (Additional_Block); end if; Current_Block := Additional_Block; else Cast (Current_Block).Limit := Cast (Current_Block).Limit + Additional_Block_Size; end if; end Grow; -- implementation procedure Allocate ( Allocator : aliased in out Allocator_Type; Storage_Address : out Address; Size_In_Storage_Elements : Storage_Elements.Storage_Count; Alignment : Storage_Elements.Storage_Count) is Mask : constant Storage_Elements.Integer_Address := Storage_Elements.Integer_Address (Alignment - 1); Top : Address := Allocator; Top_Is_Unused : Boolean; -- new block: New_Block : Address := Null_Address; New_Block_Size : Storage_Elements.Storage_Count; Aligned_Header_Size : Storage_Elements.Storage_Count; begin if Top /= Null_Address then -- when top block is empty and previous block has enough space Top_Is_Unused := Cast (Top).Used = Bottom (Top); if Top_Is_Unused and then Cast (Top).Previous /= Null_Address then declare Previous : constant Address := Cast (Top).Previous; New_Previous_Used : Address := Cast (Previous).Used; New_Storage_Address : Address; begin Commit ( Used => New_Previous_Used, Storage_Address => New_Storage_Address, Size_In_Storage_Elements => Size_In_Storage_Elements, Mask => Mask); if Is_In (New_Previous_Used, Previous) then Allocator := Previous; System_Allocators.Unmap (Top, Cast (Top).Limit - Top); Storage_Address := New_Storage_Address; Cast (Previous).Used := New_Previous_Used; return; end if; end; end if; -- when top block has enough space declare New_Top_Used : Address := Cast (Top).Used; New_Storage_Address : Address; begin Commit ( Used => New_Top_Used, Storage_Address => New_Storage_Address, Size_In_Storage_Elements => Size_In_Storage_Elements, Mask => Mask); if Is_In (New_Top_Used, Top) then Storage_Address := New_Storage_Address; Cast (Top).Used := New_Top_Used; return; end if; end; -- try expanding top block if Expanding /= 0 then Aligned_Header_Size := Align_Header_Size (Mask); declare Additional_Block_Size : constant Storage_Elements.Storage_Count := Ceiling_Page_Size ( Size_In_Storage_Elements + Aligned_Header_Size); Additional_Block : constant Address := System_Allocators.Map ( Growing_Address (Top, Additional_Block_Size), Additional_Block_Size); begin if Is_Growable ( Current_Block => Top, Additional_Block => Additional_Block, Additional_Block_Size => Additional_Block_Size, Reverse_Growing => False) then Grow ( Current_Block => Top, Additional_Block => Additional_Block, Additional_Block_Size => Additional_Block_Size, Reverse_Growing => False, Top_Is_Unused => Top_Is_Unused); Allocator := Top; Commit ( Used => Cast (Top).Used, Storage_Address => Storage_Address, Size_In_Storage_Elements => Size_In_Storage_Elements, Mask => Mask); return; elsif Is_Growable ( Current_Block => Top, Additional_Block => Additional_Block, Additional_Block_Size => Additional_Block_Size, Reverse_Growing => True) -- reverse and then Top_Is_Unused then -- The new block is allocated brefore the top block, -- concatenate them. Grow ( Current_Block => Top, Additional_Block => Additional_Block, Additional_Block_Size => Additional_Block_Size, Reverse_Growing => True, Top_Is_Unused => True); -- already checked in above Allocator := Top; Commit ( Used => Cast (Top).Used, Storage_Address => Storage_Address, Size_In_Storage_Elements => Size_In_Storage_Elements, Mask => Mask); return; end if; New_Block := Additional_Block; New_Block_Size := Additional_Block_Size; end; end if; -- top block is not enough, then free it if unused if Top_Is_Unused then declare New_Top : constant Address := Cast (Top).Previous; begin System_Allocators.Unmap (Top, Cast (Top).Limit - Top); Allocator := New_Top; Top := New_Top; end; end if; end if; -- new block declare Default_Block_Size : constant := 10 * 1024; begin if New_Block = Null_Address then Aligned_Header_Size := Align_Header_Size (Mask); New_Block_Size := Size_In_Storage_Elements + Aligned_Header_Size; if Top = Null_Address then New_Block_Size := Storage_Elements.Storage_Offset'Max ( Default_Block_Size, New_Block_Size); end if; New_Block_Size := Ceiling_Page_Size (New_Block_Size); New_Block := System_Allocators.Map (Null_Address, New_Block_Size); if New_Block = Null_Address then raise Storage_Error; end if; end if; Cast (New_Block).Previous := Top; Allocator := New_Block; Cast (New_Block).Limit := New_Block + New_Block_Size; Cast (New_Block).Used := Bottom (New_Block); Commit ( Used => Cast (New_Block).Used, Storage_Address => Storage_Address, Size_In_Storage_Elements => Size_In_Storage_Elements, Mask => Mask); end; end Allocate; function Mark (Allocator : aliased in out Allocator_Type) return Marker is Top : constant Address := Allocator; begin if Top = Null_Address then return Marker (Null_Address); elsif Cast (Top).Used = Bottom (Top) then declare Previous : constant Address := Cast (Top).Previous; begin if Previous = Null_Address then return Marker (Null_Address); else return Marker (Cast (Previous).Used); end if; end; else return Marker (Cast (Top).Used); end if; end Mark; procedure Release ( Allocator : aliased in out Allocator_Type; Mark : Marker) is begin if Allocator /= Null_Address then loop declare Top : constant Address := Allocator; begin if Address (Mark) in Top .. Cast (Top).Limit then Cast (Top).Used := Address (Mark); exit; elsif Cast (Top).Previous = Null_Address or else Address (Mark) = Cast (Cast (Top).Previous).Used then -- leave one unused block Cast (Top).Used := Bottom (Top); exit; end if; Allocator := Cast (Top).Previous; System_Allocators.Unmap (Top, Cast (Top).Limit - Top); end; end loop; end if; end Release; procedure Clear (Allocator : aliased in out Allocator_Type) is begin while Allocator /= Null_Address loop declare Top : constant Address := Allocator; begin Allocator := Cast (Top).Previous; System_Allocators.Unmap (Top, Cast (Top).Limit - Top); end; end loop; end Clear; function Size (B : Address) return Storage_Elements.Storage_Count is Header_Size : constant Storage_Elements.Storage_Count := Block'Size / Standard'Storage_Unit; begin return Cast (B).Limit - (B + Header_Size); end Size; function Used_Size (B : Address) return Storage_Elements.Storage_Count is begin if Down then return Bottom (B) - Cast (B).Used; else return Cast (B).Used - Bottom (B); end if; end Used_Size; end System.Unbounded_Stack_Allocators;
package SPDX.Exceptions is pragma Style_Checks (Off); -- Genrated code Version : constant String :="3.10-14-g0fb8a59"; type Id is ( GCC_exception_2_0, openvpn_openssl_exception, GPL_3_0_linking_exception, Fawkes_Runtime_exception, u_boot_exception_2_0, PS_or_PDF_font_exception_20170817, gnu_javamail_exception, LGPL_3_0_linking_exception, DigiRule_FOSS_exception, LLVM_exception, Linux_syscall_note, GPL_3_0_linking_source_exception, Qwt_exception_1_0, Id_389_exception, mif_exception, eCos_exception_2_0, CLISP_exception_2_0, Bison_exception_2_2, Libtool_exception, LZMA_exception, OpenJDK_assembly_exception_1_0, Font_exception_2_0, OCaml_LGPL_linking_exception, GCC_exception_3_1, Bootloader_exception, SHL_2_0, Classpath_exception_2_0, Swift_exception, Autoconf_exception_2_0, FLTK_exception, freertos_exception_2_0, Universal_FOSS_exception_1_0, WxWindows_exception_3_1, OCCT_exception_1_0, Autoconf_exception_3_0, i2p_gpl_java_exception, GPL_CC_1_0, Qt_LGPL_exception_1_1, SHL_2_1, Qt_GPL_exception_1_0); type String_Access is not null access constant String; Img_Ptr : constant array (Id) of String_Access := ( GCC_exception_2_0 => new String'("GCC-exception-2.0"), openvpn_openssl_exception => new String'("openvpn-openssl-exception"), GPL_3_0_linking_exception => new String'("GPL-3.0-linking-exception"), Fawkes_Runtime_exception => new String'("Fawkes-Runtime-exception"), u_boot_exception_2_0 => new String'("u-boot-exception-2.0"), PS_or_PDF_font_exception_20170817 => new String'("PS-or-PDF-font-exception-20170817"), gnu_javamail_exception => new String'("gnu-javamail-exception"), LGPL_3_0_linking_exception => new String'("LGPL-3.0-linking-exception"), DigiRule_FOSS_exception => new String'("DigiRule-FOSS-exception"), LLVM_exception => new String'("LLVM-exception"), Linux_syscall_note => new String'("Linux-syscall-note"), GPL_3_0_linking_source_exception => new String'("GPL-3.0-linking-source-exception"), Qwt_exception_1_0 => new String'("Qwt-exception-1.0"), Id_389_exception => new String'("389-exception"), mif_exception => new String'("mif-exception"), eCos_exception_2_0 => new String'("eCos-exception-2.0"), CLISP_exception_2_0 => new String'("CLISP-exception-2.0"), Bison_exception_2_2 => new String'("Bison-exception-2.2"), Libtool_exception => new String'("Libtool-exception"), LZMA_exception => new String'("LZMA-exception"), OpenJDK_assembly_exception_1_0 => new String'("OpenJDK-assembly-exception-1.0"), Font_exception_2_0 => new String'("Font-exception-2.0"), OCaml_LGPL_linking_exception => new String'("OCaml-LGPL-linking-exception"), GCC_exception_3_1 => new String'("GCC-exception-3.1"), Bootloader_exception => new String'("Bootloader-exception"), SHL_2_0 => new String'("SHL-2.0"), Classpath_exception_2_0 => new String'("Classpath-exception-2.0"), Swift_exception => new String'("Swift-exception"), Autoconf_exception_2_0 => new String'("Autoconf-exception-2.0"), FLTK_exception => new String'("FLTK-exception"), freertos_exception_2_0 => new String'("freertos-exception-2.0"), Universal_FOSS_exception_1_0 => new String'("Universal-FOSS-exception-1.0"), WxWindows_exception_3_1 => new String'("WxWindows-exception-3.1"), OCCT_exception_1_0 => new String'("OCCT-exception-1.0"), Autoconf_exception_3_0 => new String'("Autoconf-exception-3.0"), i2p_gpl_java_exception => new String'("i2p-gpl-java-exception"), GPL_CC_1_0 => new String'("GPL-CC-1.0"), Qt_LGPL_exception_1_1 => new String'("Qt-LGPL-exception-1.1"), SHL_2_1 => new String'("SHL-2.1"), Qt_GPL_exception_1_0 => new String'("Qt-GPL-exception-1.0")); function Img (I : Id) return String is (Img_Ptr (I).all); Name_Ptr : constant array (Id) of String_Access := ( GCC_exception_2_0 => new String'("GCC Runtime Library exception 2.0"), openvpn_openssl_exception => new String'("OpenVPN OpenSSL Exception"), GPL_3_0_linking_exception => new String'("GPL-3.0 Linking Exception"), Fawkes_Runtime_exception => new String'("Fawkes Runtime Exception"), u_boot_exception_2_0 => new String'("U-Boot exception 2.0"), PS_or_PDF_font_exception_20170817 => new String'("PS/PDF font exception (2017-08-17)"), gnu_javamail_exception => new String'("GNU JavaMail exception"), LGPL_3_0_linking_exception => new String'("LGPL-3.0 Linking Exception"), DigiRule_FOSS_exception => new String'("DigiRule FOSS License Exception"), LLVM_exception => new String'("LLVM Exception"), Linux_syscall_note => new String'("Linux Syscall Note"), GPL_3_0_linking_source_exception => new String'("GPL-3.0 Linking Exception (with Corresponding Source)"), Qwt_exception_1_0 => new String'("Qwt exception 1.0"), Id_389_exception => new String'("389 Directory Server Exception"), mif_exception => new String'("Macros and Inline Functions Exception"), eCos_exception_2_0 => new String'("eCos exception 2.0"), CLISP_exception_2_0 => new String'("CLISP exception 2.0"), Bison_exception_2_2 => new String'("Bison exception 2.2"), Libtool_exception => new String'("Libtool Exception"), LZMA_exception => new String'("LZMA exception"), OpenJDK_assembly_exception_1_0 => new String'("OpenJDK Assembly exception 1.0"), Font_exception_2_0 => new String'("Font exception 2.0"), OCaml_LGPL_linking_exception => new String'("OCaml LGPL Linking Exception"), GCC_exception_3_1 => new String'("GCC Runtime Library exception 3.1"), Bootloader_exception => new String'("Bootloader Distribution Exception"), SHL_2_0 => new String'("Solderpad Hardware License v2.0"), Classpath_exception_2_0 => new String'("Classpath exception 2.0"), Swift_exception => new String'("Swift Exception"), Autoconf_exception_2_0 => new String'("Autoconf exception 2.0"), FLTK_exception => new String'("FLTK exception"), freertos_exception_2_0 => new String'("FreeRTOS Exception 2.0"), Universal_FOSS_exception_1_0 => new String'("Universal FOSS Exception, Version 1.0"), WxWindows_exception_3_1 => new String'("WxWindows Library Exception 3.1"), OCCT_exception_1_0 => new String'("Open CASCADE Exception 1.0"), Autoconf_exception_3_0 => new String'("Autoconf exception 3.0"), i2p_gpl_java_exception => new String'("i2p GPL+Java Exception"), GPL_CC_1_0 => new String'("GPL Cooperation Commitment 1.0"), Qt_LGPL_exception_1_1 => new String'("Qt LGPL exception 1.1"), SHL_2_1 => new String'("Solderpad Hardware License v2.1"), Qt_GPL_exception_1_0 => new String'("Qt GPL exception 1.0")); function Name (I : Id) return String is (Name_Ptr (I).all); function Valid_Id (Str : String) return Boolean; function From_Id (Str : String) return Id; end SPDX.Exceptions;
-- Copyright (c) 2017 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with LSP.Types; with LSP.Messages; package LSP_Documents is type Document is tagged private; not overriding procedure Initalize (Self : out Document; Uri : LSP.Types.LSP_String; Text : LSP.Types.LSP_String; Version : LSP.Types.Version_Id); not overriding function Get_Line (Self : Document; Line : LSP.Types.Line_Number) return LSP.Types.LSP_String; not overriding function Version (Self : Document) return LSP.Types.Version_Id; type Lookup_Result_Kinds is (None, Attribute_Designator, Pragma_Name, Identifier); type Lookup_Result (Kind : Lookup_Result_Kinds := None) is record case Kind is when Attribute_Designator | Identifier => Value : LSP.Types.LSP_String; when Pragma_Name => Name : LSP.Types.LSP_String; Parameter : Natural := 0; -- Active parameter when None => null; end case; end record; not overriding function Lookup (Self : Document; Where : LSP.Messages.Position) return Lookup_Result; not overriding function All_Symbols (Self : Document; Query : LSP.Types.LSP_String) return LSP.Messages.SymbolInformation_Vector; private type Document is tagged record Uri : LSP.Types.LSP_String; Lines : LSP.Types.LSP_String_Vector; Version : LSP.Types.Version_Id; end record; end LSP_Documents;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E T _ T A R G -- -- -- -- S p e c -- -- -- -- Copyright (C) 2013-2014, 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. 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 COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This package handles setting target dependent parameters. If the -gnatet -- switch is not set, then these values are taken from the back end (via the -- routines in Get_Targ, and the enumerate_modes routine in misc.c). If the -- switch is set, then the values are read from the target.atp file in the -- current directory (usually written with the Write_Target_Dependent_Values -- procedure defined in this package). -- Note that all these values return sizes of C types with corresponding -- names. This allows GNAT to define the corresponding Ada types to have -- the same representation. There is one exception: the representation -- of Wide_Character_Type uses twice the size of a C char, instead of the -- size of wchar_t, since this corresponds to expected Ada usage. with Einfo; use Einfo; with Stand; use Stand; with Types; use Types; package Set_Targ is ----------------------------- -- Target-Dependent Values -- ----------------------------- -- The following is a table of target dependent values. In normal operation -- these values are set by calling the appropriate C backend routines that -- interface to back end routines that determine target characteristics. -- If the -gnateT switch is used, then any values that are read from the -- file target.atp in the current directory overwrite values set from the -- back end. This is used by tools other than the compiler, e.g. to do -- semantic analysis of programs that will run on some other target than -- the machine on which the tool is run. -- Note: fields marked with a question mark are boolean fields, where a -- value of 0 is False, and a value of 1 is True. Bits_BE : Nat; -- Bits stored big-endian? Bits_Per_Unit : Pos; -- Bits in a storage unit Bits_Per_Word : Pos; -- Bits in a word Bytes_BE : Nat; -- Bytes stored big-endian? Char_Size : Pos; -- Standard.Character'Size Double_Float_Alignment : Nat; -- Alignment of double float Double_Scalar_Alignment : Nat; -- Alignment of double length scalar Double_Size : Pos; -- Standard.Long_Float'Size Float_Size : Pos; -- Standard.Float'Size Float_Words_BE : Nat; -- Float words stored big-endian? Int_Size : Pos; -- Standard.Integer'Size Long_Double_Size : Pos; -- Standard.Long_Long_Float'Size Long_Long_Size : Pos; -- Standard.Long_Long_Integer'Size Long_Size : Pos; -- Standard.Long_Integer'Size Maximum_Alignment : Pos; -- Maximum permitted alignment Max_Unaligned_Field : Pos; -- Maximum size for unaligned bit field Pointer_Size : Pos; -- System.Address'Size Short_Enums : Nat; -- Foreign enums use short size? Short_Size : Pos; -- Standard.Short_Integer'Size Strict_Alignment : Nat; -- Strict alignment? System_Allocator_Alignment : Nat; -- Alignment for malloc calls Wchar_T_Size : Pos; -- Interfaces.C.wchar_t'Size Words_BE : Nat; -- Words stored big-endian? ------------------------------------- -- Registered Floating-Point Types -- ------------------------------------- -- This table contains the list of modes supported by the back-end as -- provided by the back end routine enumerate_modes in misc.c. Note that -- we only store floating-point modes (see Register_Float_Type). type FPT_Mode_Entry is record NAME : String_Ptr; -- Name of mode (no null character at end) DIGS : Natural; -- Digits for floating-point type FLOAT_REP : Float_Rep_Kind; -- Float representation PRECISION : Natural; -- Precision in bits SIZE : Natural; -- Size in bits ALIGNMENT : Natural; -- Alignment in bits end record; FPT_Mode_Table : array (1 .. 1000) of FPT_Mode_Entry; Num_FPT_Modes : Natural := 0; -- Table containing the supported modes and number of entries ----------------- -- Subprograms -- ----------------- subtype S_Float_Types is Standard_Entity_Type range S_Short_Float .. S_Long_Long_Float; function C_Type_For (T : S_Float_Types) return String; -- Return the name of a C type supported by the back-end and suitable as -- a basis to construct the standard Ada floating point type identified by -- T. This is used as a common ground to feed both ttypes values and the -- GNAT tree nodes for the standard floating point types. procedure Write_Target_Dependent_Values; -- This routine writes the file target.atp in the current directory with -- the values of the global target parameters as listed above, and as set -- by prior calls to Initialize/Read_Target_Dependent_Values. The format -- of the target.atp file is as follows -- -- First come the values of the variables defined in this spec: -- -- One line per value -- -- name value -- -- where name is the name of the parameter, spelled out in full, -- and cased as in the above list, and value is an unsigned decimal -- integer. Two or more blanks separates the name from the value. -- -- All the variables must be present, in alphabetical order (i.e. the -- same order as the declarations in this spec). -- -- Then there is a blank line to separate the two parts of the file. Then -- come the lines showing the floating-point types to be registered. -- -- One line per registered mode -- -- name digs float_rep precision alignment -- -- where name is the string name of the type (which can have single -- spaces embedded in the name (e.g. long double). The name is followed -- by at least two blanks. The following fields are as described above -- for a Mode_Entry (where float_rep is I/V/A for IEEE-754-Binary, -- Vax_Native, AAMP), fields are separated by at least one blank, and -- a LF character immediately follows the alignment field. -- -- ??? We do not write the size for backward compatibility reasons, -- which means that target.atp will not be a complete description for -- the very peculiar cases where the size cannot be computed from the -- precision and the alignment by the formula: -- -- size := (precision + alignment - 1) / alignment * alignment end Set_Targ;
------------------------------------------------------------------------------ -- Copyright (c) 2016, Natacha Porté -- -- -- -- 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. -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Natools.Smaz_Tools provides dictionary-independant tools to deal with -- -- word lists and prepare dictionary creation. -- -- Note that the dictionary is intended to be generated and hard-coded, -- -- so the final client shouldn't need this package. -- ------------------------------------------------------------------------------ with Ada.Containers.Indefinite_Doubly_Linked_Lists; with Natools.S_Expressions; private with Ada.Containers.Indefinite_Ordered_Maps; private with Ada.Containers.Indefinite_Ordered_Sets; private with Ada.Finalization; package Natools.Smaz_Tools is pragma Preelaborate; package String_Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists (String); procedure Read_List (List : out String_Lists.List; Descriptor : in out S_Expressions.Descriptor'Class); -- Read atoms from Descriptor to fill List List_For_Linear_Search : String_Lists.List; function Linear_Search (Value : String) return Natural; -- Function and data source for inefficient but dynamic function -- that can be used with Dictionary.Hash. procedure Set_Dictionary_For_Map_Search (List : in String_Lists.List); function Map_Search (Value : String) return Natural; -- Function and data source for logarithmic search using standard -- ordered map, that can be used with Dictionary.Hash. type Search_Trie is private; procedure Initialize (Trie : out Search_Trie; List : in String_Lists.List); function Search (Trie : in Search_Trie; Value : in String) return Natural; -- Trie-based search in a dynamic dictionary, for lookup whose -- speed-vs-memory is even more skewed towards speed. procedure Set_Dictionary_For_Trie_Search (List : in String_Lists.List); function Trie_Search (Value : String) return Natural; -- Function and data source for trie-based search that can be -- used with Dictionary.Hash. function Dummy_Hash (Value : String) return Natural; -- Placeholder for Hash dictionary member, always raises Program_Error type String_Count is range 0 .. 2 ** 31 - 1; -- Type for a number of substring occurrences package Methods is type Enum is (Encoded, Frequency, Gain); end Methods; -- Evaluation methods to select words to remove or include type Word_Counter is private; -- Accumulate frequency/occurrence counts for a set of strings procedure Add_Word (Counter : in out Word_Counter; Word : in String; Count : in String_Count := 1); -- Include Count number of occurrences of Word in Counter procedure Add_Substrings (Counter : in out Word_Counter; Phrase : in String; Min_Size : in Positive; Max_Size : in Positive); -- Include all the substrings of Phrase whose lengths are -- between Min_Size and Max_Size. procedure Add_Words (Counter : in out Word_Counter; Phrase : in String; Min_Size : in Positive; Max_Size : in Positive); -- Add the "words" from Phrase into Counter, with a word being currently -- defined as anything between ASCII blanks or punctuation, -- or in other words [0-9A-Za-z\x80-\xFF]+ procedure Filter_By_Count (Counter : in out Word_Counter; Threshold_Count : in String_Count); -- Remove from Counter all entries whose count is below the threshold function Simple_Dictionary (Counter : in Word_Counter; Word_Count : in Natural; Method : in Methods.Enum := Methods.Encoded) return String_Lists.List; -- Return the Word_Count words in Counter that have the highest score, -- the score being count * length. procedure Simple_Dictionary_And_Pending (Counter : in Word_Counter; Word_Count : in Natural; Selected : out String_Lists.List; Pending : out String_Lists.List; Method : in Methods.Enum := Methods.Encoded; Max_Pending_Count : in Ada.Containers.Count_Type := Ada.Containers.Count_Type'Last); -- Return in Selected the Word_Count words in Counter that have the -- highest score, and in Pending the remaining words, -- the score being count * length. type Score_Value is range 0 .. 2 ** 31 - 1; function Score_Encoded (Count : in String_Count; Length : in Positive) return Score_Value is (Score_Value (Count) * Score_Value (Length)); -- Score value using the amount of encoded data by the element function Score_Frequency (Count : in String_Count; Length : in Positive) return Score_Value is (Score_Value (Count)); -- Score value using the number of times the element was used function Score_Gain (Count : in String_Count; Length : in Positive) return Score_Value is (Score_Value (Count) * (Score_Value (Length) - 1)); -- Score value using the number of bytes saved using the element function Score (Count : in String_Count; Length : in Positive; Method : in Methods.Enum) return Score_Value is (case Method is when Methods.Encoded => Score_Encoded (Count, Length), when Methods.Frequency => Score_Frequency (Count, Length), when Methods.Gain => Score_Gain (Count, Length)); -- Scare value with dynamically chosen method private package Word_Maps is new Ada.Containers.Indefinite_Ordered_Maps (String, String_Count); type Word_Counter is record Map : Word_Maps.Map; end record; type Scored_Word (Size : Natural) is record Word : String (1 .. Size); Score : Score_Value; end record; function "<" (Left, Right : Scored_Word) return Boolean is (Left.Score > Right.Score or else (Left.Score = Right.Score and then Left.Word < Right.Word)); function To_Scored_Word (Cursor : in Word_Maps.Cursor; Method : in Methods.Enum) return Scored_Word; package Scored_Word_Sets is new Ada.Containers.Indefinite_Ordered_Sets (Scored_Word); package Dictionary_Maps is new Ada.Containers.Indefinite_Ordered_Maps (String, Natural); Search_Map : Dictionary_Maps.Map; type Trie_Node; type Trie_Node_Access is access Trie_Node; type Trie_Node_Array is array (Character) of Trie_Node_Access; type Trie_Node (Is_Leaf : Boolean) is new Ada.Finalization.Controlled with record Index : Natural; case Is_Leaf is when True => null; when False => Children : Trie_Node_Array; end case; end record; overriding procedure Adjust (Node : in out Trie_Node); overriding procedure Finalize (Node : in out Trie_Node); type Search_Trie is record Not_Found : Natural; Root : Trie_Node (False); end record; Trie_For_Search : Search_Trie; end Natools.Smaz_Tools;
----------------------------------------------------------------------- -- properties-bundles -- Generic name/value property management -- Copyright (C) 2001, 2002, 2003, 2006, 2008, 2009, 2010, 2011, 2012 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.Containers; with Ada.Finalization; with Ada.Containers.Hashed_Maps; with Util.Strings; with Util.Concurrent.Locks; package Util.Properties.Bundles is NO_BUNDLE : exception; NOT_WRITEABLE : exception; type Manager is new Util.Properties.Manager with private; -- ------------------------------ -- Bundle loader -- ------------------------------ -- The <b>Loader</b> provides facilities for loading property bundles -- and maintains a cache of bundles. The cache is thread-safe but the returned -- bundles are not thread-safe. type Loader is limited private; type Loader_Access is access all Loader; -- Initialize the bundle factory and specify where the property files are stored. procedure Initialize (Factory : in out Loader; Path : in String); -- Load the bundle with the given name and for the given locale name. procedure Load_Bundle (Factory : in out Loader; Name : in String; Locale : in String; Bundle : out Manager'Class); private procedure Add_Bundle (Self : in out Manager; Props : in Manager_Access); -- Add a bundle type Bundle_Manager_Access is access all Manager'Class; type Manager is new Util.Properties.Manager with null record; overriding procedure Initialize (Object : in out Manager); overriding procedure Adjust (Object : in out Manager); package Bundle_Map is new Ada.Containers.Hashed_Maps (Element_Type => Bundle_Manager_Access, Key_Type => Util.Strings.Name_Access, Hash => Util.Strings.Hash, Equivalent_Keys => Util.Strings.Equivalent_Keys); type Loader is new Ada.Finalization.Limited_Controlled with record Lock : Util.Concurrent.Locks.RW_Lock; Bundles : Bundle_Map.Map; Path : Unbounded_String; end record; -- Finalize the bundle loader and clear the cache overriding procedure Finalize (Factory : in out Loader); -- Clear the cache bundle procedure Clear_Cache (Factory : in out Loader); -- Find the bundle with the given name and for the given locale name. procedure Find_Bundle (Factory : in out Loader; Name : in String; Locale : in String; Bundle : out Manager'Class; Found : out Boolean); -- Load the bundle with the given name and for the given locale name. procedure Load_Bundle (Factory : in out Loader; Name : in String; Found : out Boolean); end Util.Properties.Bundles;
with openGL.Texture, ada.Strings.unbounded, ada.Streams.Stream_IO, ada.unchecked_Deallocation; package openGL.IO -- -- Provides I/O functions for openGL. -- is subtype Text is ada.Strings.unbounded.unbounded_String; ------------------ -- General Vertex -- null_Id : constant long_Index_t; type Vertex is record site_Id, coord_Id, normal_Id, weights_Id : long_Index_t; end record; type Vertices is array (long_Index_t range <>) of aliased Vertex; type Vertices_view is access all Vertices; -------- -- Face -- type facet_Kind is (Triangle, Quad, Polygon); type Face (Kind : facet_Kind := Triangle) is record case Kind is when Triangle => Tri : Vertices (1 .. 3); when Quad => Quad : Vertices (1 .. 4); when Polygon => Poly : Vertices_view; end case; end record; type Faces is array (long_Index_t range <>) of Face; procedure destroy (Self : in out Face); function Vertices_of (Self : in Face) return Vertices; procedure set_Vertex_in (Self : in out Face; Which : in long_Index_t; To : in Vertex); -------------------- -- Rigging/Skinning -- type bone_Id is range 0 .. 200; type bone_Weight is record Bone : bone_Id; Weight : Real; end record; type bone_Weights is array (long_Index_t range <>) of bone_Weight; type bone_Weights_view is access bone_Weights; type bone_Weights_array is array (long_Index_t range <>) of bone_Weights_view; --------- -- Views -- type Sites_view is access all openGL.many_Sites; type Coords_view is access all openGL.many_Coordinates_2D; type Normals_view is access all openGL.many_Normals; type bone_Weights_array_view is access all bone_Weights_array; type Faces_view is access all IO.Faces; procedure free is new ada.unchecked_Deallocation (many_Sites, IO.Sites_view); procedure free is new ada.unchecked_Deallocation (many_Coordinates_2D, IO.Coords_view); procedure free is new ada.unchecked_Deallocation (many_Normals, IO.Normals_view); procedure free is new ada.unchecked_Deallocation (IO.Faces, IO.Faces_view); ----------------- --- General Model -- type Model is record Sites : Sites_view; Coords : Coords_view; Normals : Normals_view; Weights : bone_Weights_array_view; Faces : Faces_view; end record; procedure destroy (Self : in out Model); -------------- -- Heightmaps -- type height_Map_view is access all height_Map; function to_height_Map (image_Filename : in asset_Name; Scale : in Real := 1.0) return height_Map_view; ---------- -- Images -- function fetch_Image (Stream : in ada.Streams.Stream_IO.Stream_access; try_TGA : in Boolean) return openGL.Image; pragma Obsolescent (fetch_Image, "use 'openGL.Images.fetch_Image' instead"); function to_Image (image_Filename : in asset_Name) return Image; function to_lucid_Image (image_Filename : in asset_Name) return lucid_Image; function to_lucid_Image (image_Filename : in asset_Name; is_Lucid : access Boolean) return lucid_Image; ------------ -- Textures -- function to_Texture (image_Filename : in asset_Name) return Texture.Object; --------------- -- Screenshots -- function current_Frame return Image; procedure Screenshot (Filename : in String; with_Alpha : in Boolean := False); -- -- Stores the image of the current, active viewport (in RGB or RGBA Bitmap format). ----------------- -- Video Capture -- procedure start_capture (AVI_Name : in String; frame_Rate : in Positive); -- -- Prepare for video capture (RGB uncompressed, AVI format). procedure capture_Frame; -- -- Captures the current active viewport. procedure stop_capture; private null_Id : constant long_Index_t := 0; end openGL.IO;
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure Ecrire_Entier is -- Écrire un entier. -- Paramètres : -- Nombre : l'entier à écrire -- Nécessite : Nombre >= 0 -- Nombre positif -- Assure : -- Nombre est écrit procedure Ecrire_Recursif (Nombre: in Integer) is Chiffre: Integer; Char: Character; begin if Nombre < 10 then Put(Character'Val (Character'Pos('0') + Nombre)); return; end if; Chiffre := Nombre mod 10; Char := Character'Val (Character'Pos('0') + Chiffre); Ecrire_Recursif(Nombre / 10); Put(Char); end Ecrire_Recursif; -- Écrire un entier. -- Paramètres : -- Nombre : l'entier à écrire -- Nécessite : Nombre >= 0 -- Nombre positif -- Assure : -- Nombre est écrit procedure Ecrire_Iteratif (Nombre: in Integer) is Iteration: Integer; Nbr: Integer; begin Iteration := 0; Nbr := Nombre; while (Nombre / 10**Iteration) > 9 loop Iteration := Iteration + 1; end loop; for I in reverse 0 .. Iteration loop Put(Character'Val (Character'Pos('0') + (Nbr / 10 ** I))); Nbr := Nbr mod (10 ** I); end loop; end Ecrire_Iteratif; -- Écrire un entier. -- Paramètres : -- Nombre : l'entier à écrire -- Nécessite : --- -- Assure : -- Nombre est écrit procedure Ecrire (Nombre: in Integer) is begin -- Cas special: Integer'FIRST if Nombre = Integer'First then Put("-2"); Ecrire_Recursif((-1*Nombre) mod 1000000000); elsif Nombre < 0 then Put('-'); Ecrire_Recursif(-1*Nombre); else Ecrire_Recursif(Nombre); end if; end Ecrire; Un_Entier: Integer; -- un entier lu au clavier Message: constant String := "L'entier lu est "; begin -- Demander un entier Put ("Un entier : "); Get (Un_Entier); -- Afficher l'entier lu avec les différents sous-programmes if Un_Entier >= 0 then -- L'afficher avec Ecrire_Recursif Put (Message & "(Ecrire_Recursif) : "); Ecrire_Recursif (Un_Entier); New_Line; -- L'afficher avec Ecrire_Iteratif Put (Message & "(Ecrire_Iteratif) : "); Ecrire_Iteratif (Un_Entier); New_Line; else Put_Line ("Le nombre est négatif. " & "On ne peut utiliser ni Ecrire_Recursif ni Ecrire_Iteratif."); end if; -- L'afficher avec Ecrire Put (Message & "(Ecrire) : "); Ecrire (Un_Entier); New_Line; end Ecrire_Entier;
------------------------------------------------------------------------------ -- Copyright (C) 2017-2020 by Heisenbug Ltd. (gh+saatana@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); ------------------------------------------------------------------------------ -- SPARK implementation of PHELIX. -- -- A. Cover sheet for Phelix Submission to ECRYPT -- -- 1. Name of submitted algorithm: Phelix -- -- -- 2. Type of submitted algorithm: Synchronous stream cipher with authentication -- Proposed security level: 128-bit. Key length: up to 256 bits. -- Proposed environment: Any. -- -- 3. Principle Submitter: Douglas Whiting -- Telephone: +1-760-827-4502 -- Fax: +1-760-930-9115 -- Organization: Hifn, Inc. -- Postal Address: 5973 Avenida Encinas, Suite 110, -- Carlsbad, California 92009 USA -- E-mail Address: dwhiting@hifn.com -- -- 4. Name of auxiliary submitter: Bruce Schneier -- -- 5. Name of algorithm inventors: Douglas Whiting, Bruce Schneier, -- John Kelsey, Stefan Lucks, Tadayoshi Kohno -- -- 6. Name of owner of the algorithm: Public domain -- -- 7. Signature of submitter: _________________________________________ -- -- 8. Backup point of contact: Bruce Schneier, -- Telephone: +1-650-404-2400 -- Fax: +1-650-903-0461 -- Organization: Counterpane Internet Security -- Postal Address: 1090A La Avenida -- Mountain View, CA 94043 USA -- E-mail Address: schneier@counterpane.com ------------------------------------------------------------------------------ package Saatana.Crypto.Phelix with SPARK_Mode => On, Pure => True is Max_Nonce_Size : constant := 128; Max_MAC_Size : constant := 128; Max_Key_Size : constant := 256; subtype MAC_Size_32 is Word_32 range 0 .. Max_MAC_Size with Dynamic_Predicate => MAC_Size_32 mod 8 = 0; subtype Key_Size_32 is Word_32 range 0 .. Max_Key_Size with Dynamic_Predicate => Key_Size_32 mod 8 = 0; type Context is private; -- Proof functions. function Ctx_AAD_Len (Ctx : in Context) return Stream_Count with Ghost => True, Global => null; function Ctx_I (Ctx : in Context) return Word_32 with Ghost => True, Global => null; function Ctx_Key_Size (Ctx : in Context) return Key_Size_32 with Ghost => True, Global => null; function Ctx_Mac_Size (Ctx : in Context) return MAC_Size_32 with Ghost => True, Global => null; function Ctx_Msg_Len (Ctx : in Context) return Word_32 with Ghost => True, Global => null; -- As the order in which calls are made is important, we define some proof -- functions to be used as precondition. function Setup_Key_Called (Ctx : in Context) return Boolean with Ghost => True, Global => null; function Setup_Nonce_Called (Ctx : in Context) return Boolean with Ghost => True, Global => null; -- -- Encrypt_Packet -- -- Using the cipher context This, this subprogram encrypts Payload and -- stores the Header followed by the encrypted Payload into Packet, and -- the message authentication code into MAC. -- procedure Encrypt_Packet (This : in out Context; Nonce : in Nonce_Stream; Header : in Plaintext_Stream; Payload : in Plaintext_Stream; Packet : out Ciphertext_Stream; Mac : out MAC_Stream) with Global => null, Depends => (This => (This, Nonce, Header, Payload), Packet => (Packet, This, Nonce, Header, Payload), Mac => (Mac, -- Not really, but SPARK insists. This, Nonce, Header, Payload)), Pre => (Setup_Key_Called (This) and then Header'Initialized and then Payload'Initialized and then Header'Length + Payload'Length = Packet'Length and then Nonce'Length = Max_Nonce_Size / 8 and then Mac'Length = Stream_Count (Ctx_Mac_Size (This) / 8)), Post => (Setup_Key_Called (This) = Setup_Key_Called (This'Old) and then not Setup_Nonce_Called (This) and then Packet'Initialized); -- -- Decrypt_Packet -- -- Using the cipher context This, this subprogram decrypts Payload and -- stores the Header followed by the decrypted Payload into Packet, and -- the message authentication code into MAC. -- -- The resulting Packet must only be processed if the returned MAC matches -- the expected one. -- procedure Decrypt_Packet (This : in out Context; Nonce : in Nonce_Stream; Header : in Plaintext_Stream; Payload : in Ciphertext_Stream; Packet : out Plaintext_Stream; Mac : out MAC_Stream) with Global => null, Depends => (This => (This, Nonce, Header, Payload), Packet => (Packet, -- not really This, Nonce, Header, Payload), Mac => (Mac, This, Nonce, Header, Payload)), Pre => (Setup_Key_Called (This) and then Header'Initialized and then Payload'Initialized and then Header'Length + Payload'Length = Packet'Length and then Nonce'Length = Max_Nonce_Size / 8 and then Mac'Length = Stream_Count (Ctx_Mac_Size (This) / 8)), Post => (Setup_Key_Called (This) = Setup_Key_Called (This'Old) and then not Setup_Nonce_Called (This) and then Packet'Initialized); -- -- Setup_Key -- -- Initializes the key schedule of the cipher context This. -- procedure Setup_Key (This : out Context; Key : in Key_Stream; Mac_Size : in MAC_Size_32) with Global => null, Depends => (This => (Key, Mac_Size)), Pre => (Key'Length <= Max_Key_Size / 8), -- Support key sizes between 0 and 256 bits Post => (Setup_Key_Called (This) and then not Setup_Nonce_Called (This) and then Ctx_Key_Size (This) = Key'Length * 8 and then Ctx_Mac_Size (This) = Mac_Size); -- -- Setup_Nonce -- -- Updates the internal cipher state with the given Nonce. -- -- Setup_Nonce can be called several times to setup a new cipher context. -- procedure Setup_Nonce (This : in out Context; Nonce : in Nonce_Stream) with Global => null, Depends => (This => (This, Nonce)), Pre => (Setup_Key_Called (This) and then Nonce'Length = Max_Nonce_Size / 8), Post => (Setup_Key_Called (This) = Setup_Key_Called (This'Old) and then Setup_Nonce_Called (This) and then Ctx_I (This) = 8 and then Ctx_Key_Size (This) = Ctx_Key_Size (This'Old) and then Ctx_Mac_Size (This) = Ctx_Mac_Size (This'Old) and then Ctx_AAD_Len (This) = 0 and then Ctx_Msg_Len (This) = 0); -- -- Process_AAD -- -- Updates the internal cipher state for a proper calculation of the -- message authentication code for a subsequent decryption or encryption. -- -- Process_AAD can be called several times in succession for different -- parts of the plain text stream. -- procedure Process_AAD (This : in out Context; Aad : in Plaintext_Stream) with Global => null, Depends => (This => (This, Aad)), Pre => (Aad'Initialized and then Setup_Nonce_Called (This) and then Ctx_Msg_Len (This) = 0 and then -- AAD processing must be done first Ctx_AAD_Len (This) mod 4 = 0 and then -- can only make ONE sub-word call! Ctx_AAD_Len (This) < Stream_Count'Last - Aad'Length), Post => (Setup_Key_Called (This) = Setup_Key_Called (This'Old) and then Setup_Nonce_Called (This) = Setup_Nonce_Called (This'Old) and then Ctx_AAD_Len (This) = Ctx_AAD_Len (This'Old) + Aad'Length and then Ctx_Msg_Len (This) = 0 and then Ctx_Key_Size (This) = Ctx_Key_Size (This'Old) and then Ctx_Mac_Size (This) = Ctx_Mac_Size (This'Old)); -- -- Encrypt_Bytes -- -- Using the cipher context This, this subprogram encrypts the Source into -- Destination. -- -- Encrypt_Bytes can be called several times in succession for different -- parts of the plaintext. -- procedure Encrypt_Bytes (This : in out Context; Source : in Plaintext_Stream; Destination : out Ciphertext_Stream) with Global => null, Depends => (This => (This, Source), Destination => (This, Destination, Source)), Pre => (Source'Initialized and then Source'Length = Destination'Length and then Setup_Nonce_Called (This) and then Ctx_Msg_Len (This) mod 4 = 0), -- Can only make ONE sub-word call! Post => (Setup_Key_Called (This) = Setup_Key_Called (This'Old) and then Setup_Nonce_Called (This) = Setup_Nonce_Called (This'Old) and then Ctx_AAD_Len (This) = Ctx_AAD_Len (This'Old) and then Ctx_Msg_Len (This) = Ctx_Msg_Len (This'Old) + Word_32 (Source'Length mod 2 ** 32) and then Ctx_Key_Size (This) = Ctx_Key_Size (This'Old) and then Ctx_Mac_Size (This) = Ctx_Mac_Size (This'Old) and then Destination'Initialized); -- -- Decrypt_Bytes -- -- Using the cipher context This, this subprogram decrypts the Source into -- Destination. -- -- Decrypt_Bytes can be called several times in succession for different -- parts of the cipher text. -- procedure Decrypt_Bytes (This : in out Context; Source : in Ciphertext_Stream; Destination : out Plaintext_Stream) with Global => null, Depends => (This => (This, Source), Destination => (Destination, This, Source)), Pre => (Source'Initialized and then Source'Length = Destination'Length and then Setup_Nonce_Called (This) and then Ctx_Msg_Len (This) mod 4 = 0), Post => (Setup_Key_Called (This) = Setup_Key_Called (This'Old) and then Setup_Nonce_Called (This) = Setup_Nonce_Called (This'Old) and then Ctx_AAD_Len (This) = Ctx_AAD_Len (This'Old) and then Ctx_Msg_Len (This) = Ctx_Msg_Len (This'Old) + Word_32 (Source'Length mod 2 ** 32) and then Ctx_Key_Size (This) = Ctx_Key_Size (This'Old) and then Ctx_Mac_Size (This) = Ctx_Mac_Size (This'Old) and then Destination'Initialized); -- -- Finalize -- -- Calculates the message authentication code after a decryption or -- encryption and stores it in Mac. -- procedure Finalize (This : in out Context; Mac : out MAC_Stream) with Global => null, Depends => (This => This, Mac => (Mac, -- This isn't exactly True, but SPARK insists, probably because we rely on Mac'Length This)), Pre => (Setup_Nonce_Called (This) and then Mac'Length = Stream_Count (Ctx_Mac_Size (This) / 8)), Post => (Setup_Key_Called (This) = Setup_Key_Called (This'Old) and then not Setup_Nonce_Called (This)); private type Mod_8 is mod 8; subtype Full_State_Words is Mod_8 range 0 .. 4; -- 5 state words subtype Old_State_Words is Mod_8 range 0 .. 3; -- 4 old state words type Unsigned_32_Array is array (Mod_8 range <>) of Word_32; -- Several state arrays (old Z, state words, expanded key. subtype Old_Z_4 is Unsigned_32_Array (Old_State_Words); subtype State_Words is Unsigned_32_Array (Full_State_Words); subtype Key_Processing is Unsigned_32_Array (Mod_8); type Key_Schedule is tagged record Key_Size : Key_Size_32; -- initial key size, in bits MAC_Size : MAC_Size_32; -- MAC tag size, in bits X_1_Bump : Word_32; -- 4 * (keySize / 8) + 256 * (MAC_Size mod 128) X_0 : Key_Processing; X_1 : Key_Processing; -- processed working key material end record; type Cipher_State is tagged record Old_Z : Old_Z_4; -- Previous four Z_4 values for output Z : State_Words; -- 5 internal state words (160 bits) AAD_Len : Stream_Count; -- AAD length I : Word_32; -- block number (modulo 2 ** 32) Msg_Len : Word_32; -- message length (modulo 2 ** 32) AAD_Xor : Word_32; -- aadXor constant end record; type Phase is (Uninitialized, Key_Has_Been_Setup, Nonce_Has_Been_Setup); -- Ensure proper call sequence. State changes are: -- -- (Uninitialized) -- | -- v -- (Key_Has_Been_Setup) <-. -- | | -- v | -- (Nonce_Has_Been_Setup) | -- | | -- `--------------' type Context is record KS : Key_Schedule; CS : Cipher_State; -- This state variable is merely here to ensure proper call sequences -- as precondition. -- Also, we need it to be automatically initialized. Setup_Phase : Phase := Uninitialized; end record; -- Proof functions function Ctx_AAD_Len (Ctx : in Context) return Stream_Count is (Ctx.CS.AAD_Len); function Ctx_I (Ctx : in Context) return Word_32 is (Ctx.CS.I); function Ctx_Key_Size (Ctx : in Context) return Key_Size_32 is (Ctx.KS.Key_Size); function Ctx_Mac_Size (Ctx : in Context) return MAC_Size_32 is (Ctx.KS.MAC_Size); function Ctx_Msg_Len (Ctx : in Context) return Word_32 is (Ctx.CS.Msg_Len); function Setup_Key_Called (Ctx : in Context) return Boolean is (Ctx.Setup_Phase in Key_Has_Been_Setup .. Nonce_Has_Been_Setup); function Setup_Nonce_Called (Ctx : in Context) return Boolean is (Ctx.Setup_Phase in Nonce_Has_Been_Setup); end Saatana.Crypto.Phelix;
-- { dg-do compile } with Limited_With2_Pkg2; package body Limited_With2 is function Func (Val : Rec1) return Limited_With2_Pkg1.Rec2 is begin return Val.F; end; end Limited_With2;
with Ada.Assertions; use Ada.Assertions; package TestSLModes is procedure run_test; end TestSLModes;
pragma License (Unrestricted); with Ada.Text_IO; package Ada.Long_Float_Text_IO is new Text_IO.Float_IO (Long_Float);
pragma License (Unrestricted); with Ada.Characters.Conversions; with Ada.Strings.Generic_Hash; function Ada.Strings.Hash is new Generic_Hash (Character, String, Characters.Conversions.Get); pragma Pure (Ada.Strings.Hash);
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- E X P _ C H 9 -- -- -- -- 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. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Atree; use Atree; with Checks; use Checks; with Einfo; use Einfo; with Elists; use Elists; with Errout; use Errout; with Exp_Ch3; use Exp_Ch3; with Exp_Ch11; use Exp_Ch11; with Exp_Ch6; use Exp_Ch6; with Exp_Dbug; use Exp_Dbug; with Exp_Sel; use Exp_Sel; with Exp_Smem; use Exp_Smem; with Exp_Tss; use Exp_Tss; with Exp_Util; use Exp_Util; with Freeze; use Freeze; with Hostparm; with Namet; use Namet; with Nlists; use Nlists; with Nmake; use Nmake; with Opt; use Opt; with Restrict; use Restrict; with Rident; use Rident; with Rtsfind; use Rtsfind; with Sem; use Sem; with Sem_Ch6; use Sem_Ch6; with Sem_Ch8; use Sem_Ch8; with Sem_Ch11; use Sem_Ch11; with Sem_Elab; use Sem_Elab; with Sem_Res; use Sem_Res; with Sem_Util; use Sem_Util; with Sinfo; use Sinfo; with Snames; use Snames; with Stand; use Stand; with Targparm; use Targparm; with Tbuild; use Tbuild; with Uintp; use Uintp; package body Exp_Ch9 is -- The following constant establishes the upper bound for the index of -- an entry family. It is used to limit the allocated size of protected -- types with defaulted discriminant of an integer type, when the bound -- of some entry family depends on a discriminant. The limitation to -- entry families of 128K should be reasonable in all cases, and is a -- documented implementation restriction. It will be lifted when protected -- entry families are re-implemented as a single ordered queue. Entry_Family_Bound : constant Int := 2**16; ----------------------- -- Local Subprograms -- ----------------------- function Actual_Index_Expression (Sloc : Source_Ptr; Ent : Entity_Id; Index : Node_Id; Tsk : Entity_Id) return Node_Id; -- Compute the index position for an entry call. Tsk is the target -- task. If the bounds of some entry family depend on discriminants, -- the expression computed by this function uses the discriminants -- of the target task. procedure Add_Object_Pointer (Decls : List_Id; Pid : Entity_Id; Loc : Source_Ptr); -- Prepend an object pointer declaration to the declaration list -- Decls. This object pointer is initialized to a type conversion -- of the System.Address pointer passed to entry barrier functions -- and entry body procedures. procedure Add_Formal_Renamings (Spec : Node_Id; Decls : List_Id; Ent : Entity_Id; Loc : Source_Ptr); -- Create renaming declarations for the formals, inside the procedure -- that implements an entry body. The renamings make the original names -- of the formals accessible to gdb, and serve no other purpose. -- Spec is the specification of the procedure being built. -- Decls is the list of declarations to be enhanced. -- Ent is the entity for the original entry body. function Build_Accept_Body (Astat : Node_Id) return Node_Id; -- Transform accept statement into a block with added exception handler. -- Used both for simple accept statements and for accept alternatives in -- select statements. Astat is the accept statement. function Build_Barrier_Function (N : Node_Id; Ent : Entity_Id; Pid : Node_Id) return Node_Id; -- Build the function body returning the value of the barrier expression -- for the specified entry body. function Build_Barrier_Function_Specification (Def_Id : Entity_Id; Loc : Source_Ptr) return Node_Id; -- Build a specification for a function implementing -- the protected entry barrier of the specified entry body. function Build_Corresponding_Record (N : Node_Id; Ctyp : Node_Id; Loc : Source_Ptr) return Node_Id; -- Common to tasks and protected types. Copy discriminant specifications, -- build record declaration. N is the type declaration, Ctyp is the -- concurrent entity (task type or protected type). function Build_Entry_Count_Expression (Concurrent_Type : Node_Id; Component_List : List_Id; Loc : Source_Ptr) return Node_Id; -- Compute number of entries for concurrent object. This is a count of -- simple entries, followed by an expression that computes the length -- of the range of each entry family. A single array with that size is -- allocated for each concurrent object of the type. function Build_Parameter_Block (Loc : Source_Ptr; Actuals : List_Id; Formals : List_Id; Decls : List_Id) return Entity_Id; -- Generate an access type for each actual parameter in the list Actuals. -- Cleate an encapsulating record that contains all the actuals and return -- its type. Generate: -- type Ann1 is access all <actual1-type> -- ... -- type AnnN is access all <actualN-type> -- type Pnn is record -- <formal1> : Ann1; -- ... -- <formalN> : AnnN; -- end record; function Build_Wrapper_Body (Loc : Source_Ptr; Proc_Nam : Entity_Id; Obj_Typ : Entity_Id; Formals : List_Id) return Node_Id; -- Ada 2005 (AI-345): Build the body that wraps a primitive operation -- associated with a protected or task type. This is required to implement -- dispatching calls through interfaces. Proc_Nam is the entry name to be -- wrapped, Obj_Typ is the type of the newly added formal parameter to -- handle object notation, Formals are the original entry formals that will -- be explicitly replicated. function Build_Wrapper_Spec (Loc : Source_Ptr; Proc_Nam : Entity_Id; Obj_Typ : Entity_Id; Formals : List_Id) return Node_Id; -- Ada 2005 (AI-345): Build the specification of a primitive operation -- associated with a protected or task type. This is required implement -- dispatching calls through interfaces. Proc_Nam is the entry name to be -- wrapped, Obj_Typ is the type of the newly added formal parameter to -- handle object notation, Formals are the original entry formals that will -- be explicitly replicated. function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id; -- Build the function that translates the entry index in the call -- (which depends on the size of entry families) into an index into the -- Entry_Bodies_Array, to determine the body and barrier function used -- in a protected entry call. A pointer to this function appears in every -- protected object. function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id; -- Build subprogram declaration for previous one function Build_Protected_Entry (N : Node_Id; Ent : Entity_Id; Pid : Node_Id) return Node_Id; -- Build the procedure implementing the statement sequence of -- the specified entry body. function Build_Protected_Entry_Specification (Def_Id : Entity_Id; Ent_Id : Entity_Id; Loc : Source_Ptr) return Node_Id; -- Build a specification for a procedure implementing -- the statement sequence of the specified entry body. -- Add attributes associating it with the entry defining identifier -- Ent_Id. function Build_Protected_Subprogram_Body (N : Node_Id; Pid : Node_Id; N_Op_Spec : Node_Id) return Node_Id; -- This function is used to construct the protected version of a protected -- subprogram. Its statement sequence first defers abort, then locks -- the associated protected object, and then enters a block that contains -- a call to the unprotected version of the subprogram (for details, see -- Build_Unprotected_Subprogram_Body). This block statement requires -- a cleanup handler that unlocks the object in all cases. -- (see Exp_Ch7.Expand_Cleanup_Actions). function Build_Protected_Spec (N : Node_Id; Obj_Type : Entity_Id; Unprotected : Boolean := False; Ident : Entity_Id) return List_Id; -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_ -- Subprogram_Type. Builds signature of protected subprogram, adding the -- formal that corresponds to the object itself. For an access to protected -- subprogram, there is no object type to specify, so the additional -- parameter has type Address and mode In. An indirect call through such -- a pointer converts the address to a reference to the actual object. -- The object is a limited record and therefore a by_reference type. function Build_Selected_Name (Prefix : Entity_Id; Selector : Entity_Id; Append_Char : Character := ' ') return Name_Id; -- Build a name in the form of Prefix__Selector, with an optional -- character appended. This is used for internal subprograms generated -- for operations of protected types, including barrier functions. -- For the subprograms generated for entry bodies and entry barriers, -- the generated name includes a sequence number that makes names -- unique in the presence of entry overloading. This is necessary -- because entry body procedures and barrier functions all have the -- same signature. procedure Build_Simple_Entry_Call (N : Node_Id; Concval : Node_Id; Ename : Node_Id; Index : Node_Id); -- Some comments here would be useful ??? function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id; -- This routine constructs a specification for the procedure that we will -- build for the task body for task type T. The spec has the form: -- -- procedure tnameB (_Task : access tnameV); -- -- where name is the character name taken from the task type entity that -- is passed as the argument to the procedure, and tnameV is the task -- value type that is associated with the task type. function Build_Unprotected_Subprogram_Body (N : Node_Id; Pid : Node_Id) return Node_Id; -- This routine constructs the unprotected version of a protected -- subprogram body, which is contains all of the code in the -- original, unexpanded body. This is the version of the protected -- subprogram that is called from all protected operations on the same -- object, including the protected version of the same subprogram. procedure Collect_Entry_Families (Loc : Source_Ptr; Cdecls : List_Id; Current_Node : in out Node_Id; Conctyp : Entity_Id); -- For each entry family in a concurrent type, create an anonymous array -- type of the right size, and add a component to the corresponding_record. function Family_Offset (Loc : Source_Ptr; Hi : Node_Id; Lo : Node_Id; Ttyp : Entity_Id) return Node_Id; -- Compute (Hi - Lo) for two entry family indices. Hi is the index in -- an accept statement, or the upper bound in the discrete subtype of -- an entry declaration. Lo is the corresponding lower bound. Ttyp is -- the concurrent type of the entry. function Family_Size (Loc : Source_Ptr; Hi : Node_Id; Lo : Node_Id; Ttyp : Entity_Id) return Node_Id; -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in -- a family, and handle properly the superflat case. This is equivalent -- to the use of 'Length on the index type, but must use Family_Offset -- to handle properly the case of bounds that depend on discriminants. procedure Extract_Dispatching_Call (N : Node_Id; Call_Ent : out Entity_Id; Object : out Entity_Id; Actuals : out List_Id; Formals : out List_Id); -- Given a dispatching call, extract the entity of the name of the call, -- its object parameter, its actual parameters and the formal parameters -- of the overriden interface-level version. procedure Extract_Entry (N : Node_Id; Concval : out Node_Id; Ename : out Node_Id; Index : out Node_Id); -- Given an entry call, returns the associated concurrent object, -- the entry name, and the entry family index. function Find_Task_Or_Protected_Pragma (T : Node_Id; P : Name_Id) return Node_Id; -- Searches the task or protected definition T for the first occurrence -- of the pragma whose name is given by P. The caller has ensured that -- the pragma is present in the task definition. A special case is that -- when P is Name_uPriority, the call will also find Interrupt_Priority. -- ??? Should be implemented with the rep item chain mechanism. function Index_Constant_Declaration (N : Node_Id; Index_Id : Entity_Id; Prot : Entity_Id) return List_Id; -- For an entry family and its barrier function, we define a local entity -- that maps the index in the call into the entry index into the object: -- -- I : constant Index_Type := Index_Type'Val ( -- E - <<index of first family member>> + -- Protected_Entry_Index (Index_Type'Pos (Index_Type'First))); function Parameter_Block_Pack (Loc : Source_Ptr; Blk_Typ : Entity_Id; Actuals : List_Id; Formals : List_Id; Decls : List_Id; Stmts : List_Id) return Entity_Id; -- Set the components of the generated parameter block with the values of -- the actual parameters. Generate aliased temporaries to capture the -- values for types that are passed by copy. Otherwise generate a reference -- to the actual's value. Return the address of the aggregate block. -- Generate: -- Jnn1 : alias <formal-type1>; -- Jnn1 := <actual1>; -- ... -- P : Blk_Typ := ( -- Jnn1'unchecked_access; -- <actual2>'reference; -- ...); function Parameter_Block_Unpack (Loc : Source_Ptr; P : Entity_Id; Actuals : List_Id; Formals : List_Id) return List_Id; -- Retrieve the values of the components from the parameter block and -- assign then to the original actual parameters. Generate: -- <actual1> := P.<formal1>; -- ... -- <actualN> := P.<formalN>; procedure Update_Prival_Subtypes (N : Node_Id); -- The actual subtypes of the privals will differ from the type of the -- private declaration in the original protected type, if the protected -- type has discriminants or if the prival has constrained components. -- This is because the privals are generated out of sequence w.r.t. the -- analysis of a protected body. After generating the bodies for protected -- operations, we set correctly the type of all references to privals, by -- means of a recursive tree traversal, which is heavy-handed but -- correct. ----------------------------- -- Actual_Index_Expression -- ----------------------------- function Actual_Index_Expression (Sloc : Source_Ptr; Ent : Entity_Id; Index : Node_Id; Tsk : Entity_Id) return Node_Id is Ttyp : constant Entity_Id := Etype (Tsk); Expr : Node_Id; Num : Node_Id; Lo : Node_Id; Hi : Node_Id; Prev : Entity_Id; S : Node_Id; function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id; -- Compute difference between bounds of entry family -------------------------- -- Actual_Family_Offset -- -------------------------- function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id; -- Replace a reference to a discriminant with a selected component -- denoting the discriminant of the target task. ----------------------------- -- Actual_Discriminant_Ref -- ----------------------------- function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is Typ : constant Entity_Id := Etype (Bound); B : Node_Id; begin if not Is_Entity_Name (Bound) or else Ekind (Entity (Bound)) /= E_Discriminant then if Nkind (Bound) = N_Attribute_Reference then return Bound; else B := New_Copy_Tree (Bound); end if; else B := Make_Selected_Component (Sloc, Prefix => New_Copy_Tree (Tsk), Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc)); Analyze_And_Resolve (B, Typ); end if; return Make_Attribute_Reference (Sloc, Attribute_Name => Name_Pos, Prefix => New_Occurrence_Of (Etype (Bound), Sloc), Expressions => New_List (B)); end Actual_Discriminant_Ref; -- Start of processing for Actual_Family_Offset begin return Make_Op_Subtract (Sloc, Left_Opnd => Actual_Discriminant_Ref (Hi), Right_Opnd => Actual_Discriminant_Ref (Lo)); end Actual_Family_Offset; -- Start of processing for Actual_Index_Expression begin -- The queues of entries and entry families appear in textual -- order in the associated record. The entry index is computed as -- the sum of the number of queues for all entries that precede the -- designated one, to which is added the index expression, if this -- expression denotes a member of a family. -- The following is a place holder for the count of simple entries Num := Make_Integer_Literal (Sloc, 1); -- We construct an expression which is a series of addition -- operations. See comments in Entry_Index_Expression, which is -- identical in structure. if Present (Index) then S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent))); Expr := Make_Op_Add (Sloc, Left_Opnd => Num, Right_Opnd => Actual_Family_Offset ( Make_Attribute_Reference (Sloc, Attribute_Name => Name_Pos, Prefix => New_Reference_To (Base_Type (S), Sloc), Expressions => New_List (Relocate_Node (Index))), Type_Low_Bound (S))); else Expr := Num; end if; -- Now add lengths of preceding entries and entry families Prev := First_Entity (Ttyp); while Chars (Prev) /= Chars (Ent) or else (Ekind (Prev) /= Ekind (Ent)) or else not Sem_Ch6.Type_Conformant (Ent, Prev) loop if Ekind (Prev) = E_Entry then Set_Intval (Num, Intval (Num) + 1); elsif Ekind (Prev) = E_Entry_Family then S := Etype (Discrete_Subtype_Definition (Declaration_Node (Prev))); Lo := Type_Low_Bound (S); Hi := Type_High_Bound (S); Expr := Make_Op_Add (Sloc, Left_Opnd => Expr, Right_Opnd => Make_Op_Add (Sloc, Left_Opnd => Actual_Family_Offset (Hi, Lo), Right_Opnd => Make_Integer_Literal (Sloc, 1))); -- Other components are anonymous types to be ignored else null; end if; Next_Entity (Prev); end loop; return Expr; end Actual_Index_Expression; ---------------------------------- -- Add_Discriminal_Declarations -- ---------------------------------- procedure Add_Discriminal_Declarations (Decls : List_Id; Typ : Entity_Id; Name : Name_Id; Loc : Source_Ptr) is D : Entity_Id; begin if Has_Discriminants (Typ) then D := First_Discriminant (Typ); while Present (D) loop Prepend_To (Decls, Make_Object_Renaming_Declaration (Loc, Defining_Identifier => Discriminal (D), Subtype_Mark => New_Reference_To (Etype (D), Loc), Name => Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name), Selector_Name => Make_Identifier (Loc, Chars (D))))); Next_Discriminant (D); end loop; end if; end Add_Discriminal_Declarations; ------------------------ -- Add_Object_Pointer -- ------------------------ procedure Add_Object_Pointer (Decls : List_Id; Pid : Entity_Id; Loc : Source_Ptr) is Decl : Node_Id; Obj_Ptr : Node_Id; begin -- Prepend the declaration of _object. This must be first in the -- declaration list, since it is used by the discriminal and -- prival declarations. -- ??? An attempt to make this a renaming was unsuccessful. -- -- type poVP is access poV; -- _object : poVP := poVP!O; Obj_Ptr := Make_Defining_Identifier (Loc, Chars => New_External_Name (Chars (Corresponding_Record_Type (Pid)), 'P')); Decl := Make_Object_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uObject), Object_Definition => New_Reference_To (Obj_Ptr, Loc), Expression => Unchecked_Convert_To (Obj_Ptr, Make_Identifier (Loc, Name_uO))); Set_Needs_Debug_Info (Defining_Identifier (Decl)); Prepend_To (Decls, Decl); Prepend_To (Decls, Make_Full_Type_Declaration (Loc, Defining_Identifier => Obj_Ptr, Type_Definition => Make_Access_To_Object_Definition (Loc, Subtype_Indication => New_Reference_To (Corresponding_Record_Type (Pid), Loc)))); end Add_Object_Pointer; -------------------------- -- Add_Formal_Renamings -- -------------------------- procedure Add_Formal_Renamings (Spec : Node_Id; Decls : List_Id; Ent : Entity_Id; Loc : Source_Ptr) is Ptr : constant Entity_Id := Defining_Identifier (Next (First (Parameter_Specifications (Spec)))); -- The name of the formal that holds the address of the parameter block -- for the call. Comp : Entity_Id; Decl : Node_Id; Formal : Entity_Id; New_F : Entity_Id; begin Formal := First_Formal (Ent); while Present (Formal) loop Comp := Entry_Component (Formal); New_F := Make_Defining_Identifier (Sloc (Formal), Chars (Formal)); Set_Etype (New_F, Etype (Formal)); Set_Scope (New_F, Ent); Set_Needs_Debug_Info (New_F); -- That's the whole point. if Ekind (Formal) = E_In_Parameter then Set_Ekind (New_F, E_Constant); else Set_Ekind (New_F, E_Variable); Set_Extra_Constrained (New_F, Extra_Constrained (Formal)); end if; Set_Actual_Subtype (New_F, Actual_Subtype (Formal)); Decl := Make_Object_Renaming_Declaration (Loc, Defining_Identifier => New_F, Subtype_Mark => New_Reference_To (Etype (Formal), Loc), Name => Make_Explicit_Dereference (Loc, Make_Selected_Component (Loc, Prefix => Unchecked_Convert_To (Entry_Parameters_Type (Ent), Make_Identifier (Loc, Chars (Ptr))), Selector_Name => New_Reference_To (Comp, Loc)))); Append (Decl, Decls); Set_Renamed_Object (Formal, New_F); Next_Formal (Formal); end loop; end Add_Formal_Renamings; ------------------------------ -- Add_Private_Declarations -- ------------------------------ procedure Add_Private_Declarations (Decls : List_Id; Typ : Entity_Id; Name : Name_Id; Loc : Source_Ptr) is Def : constant Node_Id := Protected_Definition (Parent (Typ)); Decl : Node_Id; Body_Ent : constant Entity_Id := Corresponding_Body (Parent (Typ)); P : Node_Id; Pdef : Entity_Id; begin pragma Assert (Nkind (Def) = N_Protected_Definition); if Present (Private_Declarations (Def)) then P := First (Private_Declarations (Def)); while Present (P) loop if Nkind (P) = N_Component_Declaration then Pdef := Defining_Identifier (P); Decl := Make_Object_Renaming_Declaration (Loc, Defining_Identifier => Prival (Pdef), Subtype_Mark => New_Reference_To (Etype (Pdef), Loc), Name => Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name), Selector_Name => Make_Identifier (Loc, Chars (Pdef)))); Set_Needs_Debug_Info (Defining_Identifier (Decl)); Prepend_To (Decls, Decl); end if; Next (P); end loop; end if; -- One more "prival" for object itself, with the right protection type declare Protection_Type : RE_Id; begin if Has_Attach_Handler (Typ) then if Restricted_Profile then if Has_Entries (Typ) then Protection_Type := RE_Protection_Entry; else Protection_Type := RE_Protection; end if; else Protection_Type := RE_Static_Interrupt_Protection; end if; elsif Has_Interrupt_Handler (Typ) then Protection_Type := RE_Dynamic_Interrupt_Protection; -- The type has explicit entries or generated primitive entry -- wrappers. elsif Has_Entries (Typ) or else (Ada_Version >= Ada_05 and then Present (Interface_List (Parent (Typ)))) then if Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False or else Number_Entries (Typ) > 1 then Protection_Type := RE_Protection_Entries; else Protection_Type := RE_Protection_Entry; end if; else Protection_Type := RE_Protection; end if; Decl := Make_Object_Renaming_Declaration (Loc, Defining_Identifier => Object_Ref (Body_Ent), Subtype_Mark => New_Reference_To (RTE (Protection_Type), Loc), Name => Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name), Selector_Name => Make_Identifier (Loc, Name_uObject))); Set_Needs_Debug_Info (Defining_Identifier (Decl)); Prepend_To (Decls, Decl); end; end Add_Private_Declarations; ----------------------- -- Build_Accept_Body -- ----------------------- function Build_Accept_Body (Astat : Node_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (Astat); Stats : constant Node_Id := Handled_Statement_Sequence (Astat); New_S : Node_Id; Hand : Node_Id; Call : Node_Id; Ohandle : Node_Id; begin -- At the end of the statement sequence, Complete_Rendezvous is called. -- A label skipping the Complete_Rendezvous, and all other accept -- processing, has already been added for the expansion of requeue -- statements. Call := Build_Runtime_Call (Loc, RE_Complete_Rendezvous); Insert_Before (Last (Statements (Stats)), Call); Analyze (Call); -- If exception handlers are present, then append Complete_Rendezvous -- calls to the handlers, and construct the required outer block. if Present (Exception_Handlers (Stats)) then Hand := First (Exception_Handlers (Stats)); while Present (Hand) loop Call := Build_Runtime_Call (Loc, RE_Complete_Rendezvous); Append (Call, Statements (Hand)); Analyze (Call); Next (Hand); end loop; New_S := Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List ( Make_Block_Statement (Loc, Handled_Statement_Sequence => Stats))); else New_S := Stats; end if; -- At this stage we know that the new statement sequence does not -- have an exception handler part, so we supply one to call -- Exceptional_Complete_Rendezvous. This handler is -- when all others => -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception); -- We handle Abort_Signal to make sure that we properly catch the abort -- case and wake up the caller. Ohandle := Make_Others_Choice (Loc); Set_All_Others (Ohandle); Set_Exception_Handlers (New_S, New_List ( Make_Exception_Handler (Loc, Exception_Choices => New_List (Ohandle), Statements => New_List ( Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( RTE (RE_Exceptional_Complete_Rendezvous), Loc), Parameter_Associations => New_List ( Make_Function_Call (Loc, Name => New_Reference_To ( RTE (RE_Get_GNAT_Exception), Loc)))))))); Set_Parent (New_S, Astat); -- temp parent for Analyze call Analyze_Exception_Handlers (Exception_Handlers (New_S)); Expand_Exception_Handlers (New_S); -- Exceptional_Complete_Rendezvous must be called with abort -- still deferred, which is the case for a "when all others" handler. return New_S; end Build_Accept_Body; ----------------------------------- -- Build_Activation_Chain_Entity -- ----------------------------------- procedure Build_Activation_Chain_Entity (N : Node_Id) is P : Node_Id; B : Node_Id; Decls : List_Id; begin -- Loop to find enclosing construct containing activation chain variable P := Parent (N); while Nkind (P) /= N_Subprogram_Body and then Nkind (P) /= N_Package_Declaration and then Nkind (P) /= N_Package_Body and then Nkind (P) /= N_Block_Statement and then Nkind (P) /= N_Task_Body loop P := Parent (P); end loop; -- If we are in a package body, the activation chain variable is -- allocated in the corresponding spec. First, we save the package -- body node because we enter the new entity in its Declarations list. B := P; if Nkind (P) = N_Package_Body then P := Unit_Declaration_Node (Corresponding_Spec (P)); Decls := Declarations (B); elsif Nkind (P) = N_Package_Declaration then Decls := Visible_Declarations (Specification (B)); else Decls := Declarations (B); end if; -- If activation chain entity not already declared, declare it if No (Activation_Chain_Entity (P)) then Set_Activation_Chain_Entity (P, Make_Defining_Identifier (Sloc (N), Name_uChain)); Prepend_To (Decls, Make_Object_Declaration (Sloc (P), Defining_Identifier => Activation_Chain_Entity (P), Aliased_Present => True, Object_Definition => New_Reference_To (RTE (RE_Activation_Chain), Sloc (P)))); Analyze (First (Decls)); end if; end Build_Activation_Chain_Entity; ---------------------------- -- Build_Barrier_Function -- ---------------------------- function Build_Barrier_Function (N : Node_Id; Ent : Entity_Id; Pid : Node_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (N); Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N); Index_Spec : constant Node_Id := Entry_Index_Specification (Ent_Formals); Op_Decls : constant List_Id := New_List; Bdef : Entity_Id; Bspec : Node_Id; begin Bdef := Make_Defining_Identifier (Loc, Chars (Barrier_Function (Ent))); Bspec := Build_Barrier_Function_Specification (Bdef, Loc); -- <object pointer declaration> -- <discriminant renamings> -- <private object renamings> -- Add discriminal and private renamings. These names have -- already been used to expand references to discriminants -- and private data. Add_Discriminal_Declarations (Op_Decls, Pid, Name_uObject, Loc); Add_Private_Declarations (Op_Decls, Pid, Name_uObject, Loc); Add_Object_Pointer (Op_Decls, Pid, Loc); -- If this is the barrier for an entry family, the entry index is -- visible in the body of the barrier. Create a local variable that -- converts the entry index (which is the last formal of the barrier -- function) into the appropriate offset into the entry array. The -- entry index constant must be set, as for the entry body, so that -- local references to the entry index are correctly replaced with -- the local variable. This parallels what is done for entry bodies. if Present (Index_Spec) then declare Index_Id : constant Entity_Id := Defining_Identifier (Index_Spec); Index_Con : constant Entity_Id := Make_Defining_Identifier (Loc, Chars => New_Internal_Name ('J')); begin Set_Entry_Index_Constant (Index_Id, Index_Con); Append_List_To (Op_Decls, Index_Constant_Declaration (N, Index_Id, Pid)); end; end if; -- Note: the condition in the barrier function needs to be properly -- processed for the C/Fortran boolean possibility, but this happens -- automatically since the return statement does this normalization. return Make_Subprogram_Body (Loc, Specification => Bspec, Declarations => Op_Decls, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List ( Make_Return_Statement (Loc, Expression => Condition (Ent_Formals))))); end Build_Barrier_Function; ------------------------------------------ -- Build_Barrier_Function_Specification -- ------------------------------------------ function Build_Barrier_Function_Specification (Def_Id : Entity_Id; Loc : Source_Ptr) return Node_Id is begin Set_Needs_Debug_Info (Def_Id); return Make_Function_Specification (Loc, Defining_Unit_Name => Def_Id, Parameter_Specifications => New_List ( Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO), Parameter_Type => New_Reference_To (RTE (RE_Address), Loc)), Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uE), Parameter_Type => New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))), Result_Definition => New_Reference_To (Standard_Boolean, Loc)); end Build_Barrier_Function_Specification; -------------------------- -- Build_Call_With_Task -- -------------------------- function Build_Call_With_Task (N : Node_Id; E : Entity_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (N); begin return Make_Function_Call (Loc, Name => New_Reference_To (E, Loc), Parameter_Associations => New_List (Concurrent_Ref (N))); end Build_Call_With_Task; -------------------------------- -- Build_Corresponding_Record -- -------------------------------- function Build_Corresponding_Record (N : Node_Id; Ctyp : Entity_Id; Loc : Source_Ptr) return Node_Id is Rec_Ent : constant Entity_Id := Make_Defining_Identifier (Loc, New_External_Name (Chars (Ctyp), 'V')); Disc : Entity_Id; Dlist : List_Id; New_Disc : Entity_Id; Cdecls : List_Id; begin Set_Corresponding_Record_Type (Ctyp, Rec_Ent); Set_Ekind (Rec_Ent, E_Record_Type); Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp)); Set_Is_Concurrent_Record_Type (Rec_Ent, True); Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp); Set_Stored_Constraint (Rec_Ent, No_Elist); Cdecls := New_List; -- Use discriminals to create list of discriminants for record, and -- create new discriminals for use in default expressions, etc. It is -- worth noting that a task discriminant gives rise to 5 entities; -- a) The original discriminant. -- b) The discriminal for use in the task. -- c) The discriminant of the corresponding record. -- d) The discriminal for the init proc of the corresponding record. -- e) The local variable that renames the discriminant in the procedure -- for the task body. -- In fact the discriminals b) are used in the renaming declarations -- for e). See details in einfo (Handling of Discriminants). if Present (Discriminant_Specifications (N)) then Dlist := New_List; Disc := First_Discriminant (Ctyp); while Present (Disc) loop New_Disc := CR_Discriminant (Disc); Append_To (Dlist, Make_Discriminant_Specification (Loc, Defining_Identifier => New_Disc, Discriminant_Type => New_Occurrence_Of (Etype (Disc), Loc), Expression => New_Copy (Discriminant_Default_Value (Disc)))); Next_Discriminant (Disc); end loop; else Dlist := No_List; end if; -- Now we can construct the record type declaration. Note that this -- record is "limited tagged". It is "limited" to reflect the underlying -- limitedness of the task or protected object that it represents, and -- ensuring for example that it is properly passed by reference. It is -- "tagged" to give support to dispatching calls through interfaces (Ada -- 2005: AI-345) return Make_Full_Type_Declaration (Loc, Defining_Identifier => Rec_Ent, Discriminant_Specifications => Dlist, Type_Definition => Make_Record_Definition (Loc, Component_List => Make_Component_List (Loc, Component_Items => Cdecls), Tagged_Present => Ada_Version >= Ada_05 and then Is_Tagged_Type (Ctyp), Limited_Present => True)); end Build_Corresponding_Record; ---------------------------------- -- Build_Entry_Count_Expression -- ---------------------------------- function Build_Entry_Count_Expression (Concurrent_Type : Node_Id; Component_List : List_Id; Loc : Source_Ptr) return Node_Id is Eindx : Nat; Ent : Entity_Id; Ecount : Node_Id; Comp : Node_Id; Lo : Node_Id; Hi : Node_Id; Typ : Entity_Id; begin -- Count number of non-family entries Eindx := 0; Ent := First_Entity (Concurrent_Type); while Present (Ent) loop if Ekind (Ent) = E_Entry then Eindx := Eindx + 1; end if; Next_Entity (Ent); end loop; Ecount := Make_Integer_Literal (Loc, Eindx); -- Loop through entry families building the addition nodes Ent := First_Entity (Concurrent_Type); Comp := First (Component_List); while Present (Ent) loop if Ekind (Ent) = E_Entry_Family then while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop Next (Comp); end loop; Typ := Etype (Discrete_Subtype_Definition (Parent (Ent))); Hi := Type_High_Bound (Typ); Lo := Type_Low_Bound (Typ); Ecount := Make_Op_Add (Loc, Left_Opnd => Ecount, Right_Opnd => Family_Size (Loc, Hi, Lo, Concurrent_Type)); end if; Next_Entity (Ent); end loop; return Ecount; end Build_Entry_Count_Expression; --------------------------- -- Build_Parameter_Block -- --------------------------- function Build_Parameter_Block (Loc : Source_Ptr; Actuals : List_Id; Formals : List_Id; Decls : List_Id) return Entity_Id is Actual : Entity_Id; Comp_Nam : Node_Id; Comps : List_Id; Formal : Entity_Id; Has_Comp : Boolean := False; Rec_Nam : Node_Id; begin Actual := First (Actuals); Comps := New_List; Formal := Defining_Identifier (First (Formals)); while Present (Actual) loop if not Is_Controlling_Actual (Actual) then -- Generate: -- type Ann is access all <actual-type> Comp_Nam := Make_Defining_Identifier (Loc, New_Internal_Name ('A')); Append_To (Decls, Make_Full_Type_Declaration (Loc, Defining_Identifier => Comp_Nam, Type_Definition => Make_Access_To_Object_Definition (Loc, All_Present => True, Constant_Present => Ekind (Formal) = E_In_Parameter, Subtype_Indication => New_Reference_To (Etype (Actual), Loc)))); -- Generate: -- Param : Ann; Append_To (Comps, Make_Component_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Chars (Formal)), Component_Definition => Make_Component_Definition (Loc, Aliased_Present => False, Subtype_Indication => New_Reference_To (Comp_Nam, Loc)))); Has_Comp := True; end if; Next_Actual (Actual); Next_Formal_With_Extras (Formal); end loop; Rec_Nam := Make_Defining_Identifier (Loc, New_Internal_Name ('P')); if Has_Comp then -- Generate: -- type Pnn is record -- Param1 : Ann1; -- ... -- ParamN : AnnN; -- where Pnn is a parameter wrapping record, Param1 .. ParamN are -- the original parameter names and Ann1 .. AnnN are the access to -- actual types. Append_To (Decls, Make_Full_Type_Declaration (Loc, Defining_Identifier => Rec_Nam, Type_Definition => Make_Record_Definition (Loc, Component_List => Make_Component_List (Loc, Comps)))); else -- Generate: -- type Pnn is null record; Append_To (Decls, Make_Full_Type_Declaration (Loc, Defining_Identifier => Rec_Nam, Type_Definition => Make_Record_Definition (Loc, Null_Present => True, Component_List => Empty))); end if; return Rec_Nam; end Build_Parameter_Block; ------------------------ -- Build_Wrapper_Body -- ------------------------ function Build_Wrapper_Body (Loc : Source_Ptr; Proc_Nam : Entity_Id; Obj_Typ : Entity_Id; Formals : List_Id) return Node_Id is Actuals : List_Id := No_List; Body_Spec : Node_Id; Conv_Id : Node_Id; First_Formal : Node_Id; Formal : Node_Id; begin Body_Spec := Build_Wrapper_Spec (Loc, Proc_Nam, Obj_Typ, Formals); -- If we did not generate the specification do have nothing else to do if Body_Spec = Empty then return Empty; end if; -- Map formals to actuals. Use the list built for the wrapper spec, -- skipping the object notation parameter. First_Formal := First (Parameter_Specifications (Body_Spec)); Formal := First_Formal; Next (Formal); if Present (Formal) then Actuals := New_List; while Present (Formal) loop Append_To (Actuals, Make_Identifier (Loc, Chars => Chars (Defining_Identifier (Formal)))); Next (Formal); end loop; end if; -- An access-to-variable first parameter will require an explicit -- dereference in the unchecked conversion. This case occurs when -- a protected entry wrapper must override an interface-level -- procedure with interface access as first parameter. -- SubprgName (O.all).Proc_Nam (Formal_1 .. Formal_N) if Nkind (Parameter_Type (First_Formal)) = N_Access_Definition then Conv_Id := Make_Explicit_Dereference (Loc, Prefix => Make_Identifier (Loc, Chars => Name_uO)); else Conv_Id := Make_Identifier (Loc, Chars => Name_uO); end if; if Ekind (Proc_Nam) = E_Function then return Make_Subprogram_Body (Loc, Specification => Body_Spec, Declarations => Empty_List, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List ( Make_Return_Statement (Loc, Make_Function_Call (Loc, Name => Make_Selected_Component (Loc, Prefix => Unchecked_Convert_To ( Corresponding_Concurrent_Type (Obj_Typ), Conv_Id), Selector_Name => New_Reference_To (Proc_Nam, Loc)), Parameter_Associations => Actuals))))); else return Make_Subprogram_Body (Loc, Specification => Body_Spec, Declarations => Empty_List, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List ( Make_Procedure_Call_Statement (Loc, Name => Make_Selected_Component (Loc, Prefix => Unchecked_Convert_To ( Corresponding_Concurrent_Type (Obj_Typ), Conv_Id), Selector_Name => New_Reference_To (Proc_Nam, Loc)), Parameter_Associations => Actuals)))); end if; end Build_Wrapper_Body; ------------------------ -- Build_Wrapper_Spec -- ------------------------ function Build_Wrapper_Spec (Loc : Source_Ptr; Proc_Nam : Entity_Id; Obj_Typ : Entity_Id; Formals : List_Id) return Node_Id is New_Name_Id : constant Entity_Id := Make_Defining_Identifier (Loc, Chars (Proc_Nam)); First_Param : Node_Id := Empty; Iface : Entity_Id; Iface_Elmt : Elmt_Id := No_Elmt; New_Formals : List_Id; Obj_Param : Node_Id; Obj_Param_Typ : Node_Id; Iface_Prim_Op : Entity_Id; Iface_Prim_Op_Elmt : Elmt_Id; function Overriding_Possible (Iface_Prim_Op : Entity_Id; Proc_Nam : Entity_Id) return Boolean; -- Determine whether a primitive operation can be overriden by the -- wrapper. Iface_Prim_Op is the candidate primitive operation of an -- abstract interface type, Proc_Nam is the generated entry wrapper. function Replicate_Entry_Formals (Loc : Source_Ptr; Formals : List_Id) return List_Id; -- An explicit parameter replication is required due to the -- Is_Entry_Formal flag being set for all the formals. The explicit -- replication removes the flag that would otherwise cause a different -- path of analysis. ------------------------- -- Overriding_Possible -- ------------------------- function Overriding_Possible (Iface_Prim_Op : Entity_Id; Proc_Nam : Entity_Id) return Boolean is Prim_Op_Spec : constant Node_Id := Parent (Iface_Prim_Op); Proc_Spec : constant Node_Id := Parent (Proc_Nam); Is_Access_To_Variable : Boolean; Is_Out_Present : Boolean; function Type_Conformant_Parameters (Prim_Op_Param_Specs : List_Id; Proc_Param_Specs : List_Id) return Boolean; -- Determine whether the parameters of the generated entry wrapper -- and those of a primitive operation are type conformant. During -- this check, the first parameter of the primitive operation is -- always skipped. -------------------------------- -- Type_Conformant_Parameters -- -------------------------------- function Type_Conformant_Parameters (Prim_Op_Param_Specs : List_Id; Proc_Param_Specs : List_Id) return Boolean is Prim_Op_Param : Node_Id; Proc_Param : Node_Id; begin -- Skip the first parameter of the primitive operation Prim_Op_Param := Next (First (Prim_Op_Param_Specs)); Proc_Param := First (Proc_Param_Specs); while Present (Prim_Op_Param) and then Present (Proc_Param) loop -- The two parameters must be mode conformant and have -- the exact same types. if Ekind (Defining_Identifier (Prim_Op_Param)) /= Ekind (Defining_Identifier (Proc_Param)) or else Etype (Parameter_Type (Prim_Op_Param)) /= Etype (Parameter_Type (Proc_Param)) then return False; end if; Next (Prim_Op_Param); Next (Proc_Param); end loop; -- One of the lists is longer than the other if Present (Prim_Op_Param) or else Present (Proc_Param) then return False; end if; return True; end Type_Conformant_Parameters; -- Start of processing for Overriding_Possible begin if Chars (Iface_Prim_Op) /= Chars (Proc_Nam) then return False; end if; -- Special check for protected procedures: If an inherited subprogram -- is implemented by a protected procedure or an entry, then the -- first parameter of the inherited subprogram shall be of mode OUT -- or IN OUT, or an access-to-variable parameter. if Ekind (Iface_Prim_Op) = E_Procedure then Is_Out_Present := Present (Parameter_Specifications (Prim_Op_Spec)) and then Out_Present (First (Parameter_Specifications (Prim_Op_Spec))); Is_Access_To_Variable := Present (Parameter_Specifications (Prim_Op_Spec)) and then Nkind (Parameter_Type (First (Parameter_Specifications (Prim_Op_Spec)))) = N_Access_Definition; if not Is_Out_Present and then not Is_Access_To_Variable then return False; end if; end if; return Type_Conformant_Parameters ( Parameter_Specifications (Prim_Op_Spec), Parameter_Specifications (Proc_Spec)); end Overriding_Possible; ----------------------------- -- Replicate_Entry_Formals -- ----------------------------- function Replicate_Entry_Formals (Loc : Source_Ptr; Formals : List_Id) return List_Id is New_Formals : constant List_Id := New_List; Formal : Node_Id; begin Formal := First (Formals); while Present (Formal) loop -- Create an explicit copy of the entry parameter Append_To (New_Formals, Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Chars => Chars (Defining_Identifier (Formal))), In_Present => In_Present (Formal), Out_Present => Out_Present (Formal), Parameter_Type => New_Reference_To (Etype ( Parameter_Type (Formal)), Loc))); Next (Formal); end loop; return New_Formals; end Replicate_Entry_Formals; -- Start of processing for Build_Wrapper_Spec begin -- The mode is determined by the first parameter of the interface-level -- procedure that the current entry is trying to override. pragma Assert (Present (Abstract_Interfaces (Corresponding_Record_Type (Scope (Proc_Nam))))); Iface_Elmt := First_Elmt (Abstract_Interfaces (Corresponding_Record_Type (Scope (Proc_Nam)))); -- We must examine all the protected operations of the implemented -- interfaces in order to discover a possible overriding candidate. Examine_Interfaces : while Present (Iface_Elmt) loop Iface := Node (Iface_Elmt); if Present (Primitive_Operations (Iface)) then Iface_Prim_Op_Elmt := First_Elmt (Primitive_Operations (Iface)); while Present (Iface_Prim_Op_Elmt) loop Iface_Prim_Op := Node (Iface_Prim_Op_Elmt); while Present (Alias (Iface_Prim_Op)) loop Iface_Prim_Op := Alias (Iface_Prim_Op); end loop; -- The current primitive operation can be overriden by the -- generated entry wrapper. if Overriding_Possible (Iface_Prim_Op, Proc_Nam) then First_Param := First (Parameter_Specifications (Parent (Iface_Prim_Op))); exit Examine_Interfaces; end if; Next_Elmt (Iface_Prim_Op_Elmt); end loop; end if; Next_Elmt (Iface_Elmt); end loop Examine_Interfaces; -- Return if no interface primitive can be overriden if No (First_Param) then return Empty; end if; New_Formals := Replicate_Entry_Formals (Loc, Formals); -- ??? Certain source packages contain protected or task types that do -- not implement any interfaces and are compiled with the -gnat05 -- switch. In this case, a default first parameter is created. if Present (First_Param) then if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then Obj_Param_Typ := Make_Access_Definition (Loc, Subtype_Mark => New_Reference_To (Obj_Typ, Loc)); else Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc); end if; Obj_Param := Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO), In_Present => In_Present (First_Param), Out_Present => Out_Present (First_Param), Parameter_Type => Obj_Param_Typ); else Obj_Param := Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO), In_Present => True, Out_Present => True, Parameter_Type => New_Reference_To (Obj_Typ, Loc)); end if; Prepend_To (New_Formals, Obj_Param); -- Minimum decoration needed to catch the entity in -- Sem_Ch6.Override_Dispatching_Operation if Ekind (Proc_Nam) = E_Procedure or else Ekind (Proc_Nam) = E_Entry then Set_Ekind (New_Name_Id, E_Procedure); Set_Is_Primitive_Wrapper (New_Name_Id); Set_Wrapped_Entity (New_Name_Id, Proc_Nam); return Make_Procedure_Specification (Loc, Defining_Unit_Name => New_Name_Id, Parameter_Specifications => New_Formals); else pragma Assert (Ekind (Proc_Nam) = E_Function); Set_Ekind (New_Name_Id, E_Function); return Make_Function_Specification (Loc, Defining_Unit_Name => New_Name_Id, Parameter_Specifications => New_Formals, Result_Definition => New_Copy (Result_Definition (Parent (Proc_Nam)))); end if; end Build_Wrapper_Spec; --------------------------- -- Build_Find_Body_Index -- --------------------------- function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (Typ); Ent : Entity_Id; E_Typ : Entity_Id; Has_F : Boolean := False; Index : Nat; If_St : Node_Id := Empty; Lo : Node_Id; Hi : Node_Id; Decls : List_Id := New_List; Ret : Node_Id; Spec : Node_Id; Siz : Node_Id := Empty; procedure Add_If_Clause (Expr : Node_Id); -- Add test for range of current entry function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id; -- If a bound of an entry is given by a discriminant, retrieve the -- actual value of the discriminant from the enclosing object. ------------------- -- Add_If_Clause -- ------------------- procedure Add_If_Clause (Expr : Node_Id) is Cond : Node_Id; Stats : constant List_Id := New_List ( Make_Return_Statement (Loc, Expression => Make_Integer_Literal (Loc, Index + 1))); begin -- Index for current entry body Index := Index + 1; -- Compute total length of entry queues so far if No (Siz) then Siz := Expr; else Siz := Make_Op_Add (Loc, Left_Opnd => Siz, Right_Opnd => Expr); end if; Cond := Make_Op_Le (Loc, Left_Opnd => Make_Identifier (Loc, Name_uE), Right_Opnd => Siz); -- Map entry queue indices in the range of the current family -- into the current index, that designates the entry body. if No (If_St) then If_St := Make_Implicit_If_Statement (Typ, Condition => Cond, Then_Statements => Stats, Elsif_Parts => New_List); Ret := If_St; else Append ( Make_Elsif_Part (Loc, Condition => Cond, Then_Statements => Stats), Elsif_Parts (If_St)); end if; end Add_If_Clause; ------------------------------ -- Convert_Discriminant_Ref -- ------------------------------ function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is B : Node_Id; begin if Is_Entity_Name (Bound) and then Ekind (Entity (Bound)) = E_Discriminant then B := Make_Selected_Component (Loc, Prefix => Unchecked_Convert_To (Corresponding_Record_Type (Typ), Make_Explicit_Dereference (Loc, Make_Identifier (Loc, Name_uObject))), Selector_Name => Make_Identifier (Loc, Chars (Bound))); Set_Etype (B, Etype (Entity (Bound))); else B := New_Copy_Tree (Bound); end if; return B; end Convert_Discriminant_Ref; -- Start of processing for Build_Find_Body_Index begin Spec := Build_Find_Body_Index_Spec (Typ); Ent := First_Entity (Typ); while Present (Ent) loop if Ekind (Ent) = E_Entry_Family then Has_F := True; exit; end if; Next_Entity (Ent); end loop; if not Has_F then -- If the protected type has no entry families, there is a one-one -- correspondence between entry queue and entry body. Ret := Make_Return_Statement (Loc, Expression => Make_Identifier (Loc, Name_uE)); else -- Suppose entries e1, e2, ... have size l1, l2, ... we generate -- the following: -- -- if E <= l1 then return 1; -- elsif E <= l1 + l2 then return 2; -- ... Index := 0; Siz := Empty; Ent := First_Entity (Typ); Add_Object_Pointer (Decls, Typ, Loc); while Present (Ent) loop if Ekind (Ent) = E_Entry then Add_If_Clause (Make_Integer_Literal (Loc, 1)); elsif Ekind (Ent) = E_Entry_Family then E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent))); Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ)); Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ)); Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ)); end if; Next_Entity (Ent); end loop; if Index = 1 then Decls := New_List; Ret := Make_Return_Statement (Loc, Expression => Make_Integer_Literal (Loc, 1)); elsif Nkind (Ret) = N_If_Statement then -- Ranges are in increasing order, so last one doesn't need guard declare Nod : constant Node_Id := Last (Elsif_Parts (Ret)); begin Remove (Nod); Set_Else_Statements (Ret, Then_Statements (Nod)); end; end if; end if; return Make_Subprogram_Body (Loc, Specification => Spec, Declarations => Decls, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List (Ret))); end Build_Find_Body_Index; -------------------------------- -- Build_Find_Body_Index_Spec -- -------------------------------- function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (Typ); Id : constant Entity_Id := Make_Defining_Identifier (Loc, Chars => New_External_Name (Chars (Typ), 'F')); Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO); Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE); begin return Make_Function_Specification (Loc, Defining_Unit_Name => Id, Parameter_Specifications => New_List ( Make_Parameter_Specification (Loc, Defining_Identifier => Parm1, Parameter_Type => New_Reference_To (RTE (RE_Address), Loc)), Make_Parameter_Specification (Loc, Defining_Identifier => Parm2, Parameter_Type => New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))), Result_Definition => New_Occurrence_Of ( RTE (RE_Protected_Entry_Index), Loc)); end Build_Find_Body_Index_Spec; ------------------------- -- Build_Master_Entity -- ------------------------- procedure Build_Master_Entity (E : Entity_Id) is Loc : constant Source_Ptr := Sloc (E); P : Node_Id; Decl : Node_Id; S : Entity_Id; begin S := Scope (E); -- Ada 2005 (AI-287): Do not set/get the has_master_entity reminder -- in internal scopes, unless present already.. Required for nested -- limited aggregates. This could use some more explanation ???? if Ada_Version >= Ada_05 then while Is_Internal (S) loop S := Scope (S); end loop; end if; -- Nothing to do if we already built a master entity for this scope -- or if there is no task hierarchy. if Has_Master_Entity (S) or else Restriction_Active (No_Task_Hierarchy) then return; end if; -- Otherwise first build the master entity -- _Master : constant Master_Id := Current_Master.all; -- and insert it just before the current declaration Decl := Make_Object_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uMaster), Constant_Present => True, Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc), Expression => Make_Explicit_Dereference (Loc, New_Reference_To (RTE (RE_Current_Master), Loc))); P := Parent (E); Insert_Before (P, Decl); Analyze (Decl); -- Ada 2005 (AI-287): Set the has_master_entity reminder in the -- non-internal scope selected above. if Ada_Version >= Ada_05 then Set_Has_Master_Entity (S); else Set_Has_Master_Entity (Scope (E)); end if; -- Now mark the containing scope as a task master while Nkind (P) /= N_Compilation_Unit loop P := Parent (P); -- If we fall off the top, we are at the outer level, and the -- environment task is our effective master, so nothing to mark. if Nkind (P) = N_Task_Body or else Nkind (P) = N_Block_Statement or else Nkind (P) = N_Subprogram_Body then Set_Is_Task_Master (P, True); return; elsif Nkind (Parent (P)) = N_Subunit then P := Corresponding_Stub (Parent (P)); end if; end loop; end Build_Master_Entity; --------------------------- -- Build_Protected_Entry -- --------------------------- function Build_Protected_Entry (N : Node_Id; Ent : Entity_Id; Pid : Node_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (N); Op_Decls : constant List_Id := New_List; Edef : Entity_Id; Espec : Node_Id; Op_Stats : List_Id; Ohandle : Node_Id; Complete : Node_Id; begin Edef := Make_Defining_Identifier (Loc, Chars => Chars (Protected_Body_Subprogram (Ent))); Espec := Build_Protected_Entry_Specification (Edef, Empty, Loc); -- <object pointer declaration> -- Add object pointer declaration. This is needed by the discriminal and -- prival renamings, which should already have been inserted into the -- declaration list. Add_Object_Pointer (Op_Decls, Pid, Loc); -- Add renamings for formals for use by debugger Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc); if Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False or else Number_Entries (Pid) > 1 or else (Has_Attach_Handler (Pid) and then not Restricted_Profile) then Complete := New_Reference_To (RTE (RE_Complete_Entry_Body), Loc); else Complete := New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc); end if; Op_Stats := New_List ( Make_Block_Statement (Loc, Declarations => Declarations (N), Handled_Statement_Sequence => Handled_Statement_Sequence (N)), Make_Procedure_Call_Statement (Loc, Name => Complete, Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Prefix => Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name_uObject), Selector_Name => Make_Identifier (Loc, Name_uObject)), Attribute_Name => Name_Unchecked_Access)))); if Restriction_Active (No_Exception_Handlers) then return Make_Subprogram_Body (Loc, Specification => Espec, Declarations => Op_Decls, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Op_Stats)); else Ohandle := Make_Others_Choice (Loc); Set_All_Others (Ohandle); if Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False or else Number_Entries (Pid) > 1 or else (Has_Attach_Handler (Pid) and then not Restricted_Profile) then Complete := New_Reference_To (RTE (RE_Exceptional_Complete_Entry_Body), Loc); else Complete := New_Reference_To ( RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc); end if; -- Create body of entry procedure. The renaming declarations are -- placed ahead of the block that contains the actual entry body. return Make_Subprogram_Body (Loc, Specification => Espec, Declarations => Op_Decls, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => Op_Stats, Exception_Handlers => New_List ( Make_Exception_Handler (Loc, Exception_Choices => New_List (Ohandle), Statements => New_List ( Make_Procedure_Call_Statement (Loc, Name => Complete, Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Prefix => Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name_uObject), Selector_Name => Make_Identifier (Loc, Name_uObject)), Attribute_Name => Name_Unchecked_Access), Make_Function_Call (Loc, Name => New_Reference_To ( RTE (RE_Get_GNAT_Exception), Loc))))))))); end if; end Build_Protected_Entry; ----------------------------------------- -- Build_Protected_Entry_Specification -- ----------------------------------------- function Build_Protected_Entry_Specification (Def_Id : Entity_Id; Ent_Id : Entity_Id; Loc : Source_Ptr) return Node_Id is P : Entity_Id; begin Set_Needs_Debug_Info (Def_Id); P := Make_Defining_Identifier (Loc, Name_uP); if Present (Ent_Id) then Append_Elmt (P, Accept_Address (Ent_Id)); end if; return Make_Procedure_Specification (Loc, Defining_Unit_Name => Def_Id, Parameter_Specifications => New_List ( Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO), Parameter_Type => New_Reference_To (RTE (RE_Address), Loc)), Make_Parameter_Specification (Loc, Defining_Identifier => P, Parameter_Type => New_Reference_To (RTE (RE_Address), Loc)), Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uE), Parameter_Type => New_Reference_To (RTE (RE_Protected_Entry_Index), Loc)))); end Build_Protected_Entry_Specification; -------------------------- -- Build_Protected_Spec -- -------------------------- function Build_Protected_Spec (N : Node_Id; Obj_Type : Entity_Id; Unprotected : Boolean := False; Ident : Entity_Id) return List_Id is Loc : constant Source_Ptr := Sloc (N); Decl : Node_Id; Formal : Entity_Id; New_Plist : List_Id; New_Param : Node_Id; begin New_Plist := New_List; Formal := First_Formal (Ident); while Present (Formal) loop New_Param := Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Sloc (Formal), Chars (Formal)), In_Present => In_Present (Parent (Formal)), Out_Present => Out_Present (Parent (Formal)), Parameter_Type => New_Reference_To (Etype (Formal), Loc)); if Unprotected then Set_Protected_Formal (Formal, Defining_Identifier (New_Param)); end if; Append (New_Param, New_Plist); Next_Formal (Formal); end loop; -- If the subprogram is a procedure and the context is not an access -- to protected subprogram, the parameter is in-out. Otherwise it is -- an in parameter. Decl := Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uObject), In_Present => True, Out_Present => (Etype (Ident) = Standard_Void_Type and then not Is_RTE (Obj_Type, RE_Address)), Parameter_Type => New_Reference_To (Obj_Type, Loc)); Set_Needs_Debug_Info (Defining_Identifier (Decl)); Prepend_To (New_Plist, Decl); return New_Plist; end Build_Protected_Spec; --------------------------------------- -- Build_Protected_Sub_Specification -- --------------------------------------- function Build_Protected_Sub_Specification (N : Node_Id; Prottyp : Entity_Id; Mode : Subprogram_Protection_Mode) return Node_Id is Loc : constant Source_Ptr := Sloc (N); Decl : Node_Id; Ident : Entity_Id; New_Id : Entity_Id; New_Plist : List_Id; New_Spec : Node_Id; Append_Chr : constant array (Subprogram_Protection_Mode) of Character := (Dispatching_Mode => ' ', Protected_Mode => 'P', Unprotected_Mode => 'N'); begin if Ekind (Defining_Unit_Name (Specification (N))) = E_Subprogram_Body then Decl := Unit_Declaration_Node (Corresponding_Spec (N)); else Decl := N; end if; Ident := Defining_Unit_Name (Specification (Decl)); New_Plist := Build_Protected_Spec (Decl, Corresponding_Record_Type (Prottyp), Mode = Unprotected_Mode, Ident); New_Id := Make_Defining_Identifier (Loc, Chars => Build_Selected_Name (Prottyp, Ident, Append_Chr (Mode))); -- The unprotected operation carries the user code, and debugging -- information must be generated for it, even though this spec does -- not come from source. It is also convenient to allow gdb to step -- into the protected operation, even though it only contains lock/ -- unlock calls. Set_Needs_Debug_Info (New_Id); if Nkind (Specification (Decl)) = N_Procedure_Specification then return Make_Procedure_Specification (Loc, Defining_Unit_Name => New_Id, Parameter_Specifications => New_Plist); else New_Spec := Make_Function_Specification (Loc, Defining_Unit_Name => New_Id, Parameter_Specifications => New_Plist, Result_Definition => New_Copy (Result_Definition (Specification (Decl)))); Set_Return_Present (Defining_Unit_Name (New_Spec)); return New_Spec; end if; end Build_Protected_Sub_Specification; ------------------------------------- -- Build_Protected_Subprogram_Body -- ------------------------------------- function Build_Protected_Subprogram_Body (N : Node_Id; Pid : Node_Id; N_Op_Spec : Node_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (N); Op_Spec : Node_Id; P_Op_Spec : Node_Id; Uactuals : List_Id; Pformal : Node_Id; Unprot_Call : Node_Id; Sub_Body : Node_Id; Lock_Name : Node_Id; Lock_Stmt : Node_Id; Service_Name : Node_Id; R : Node_Id; Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning Stmts : List_Id; Object_Parm : Node_Id; Exc_Safe : Boolean; function Is_Exception_Safe (Subprogram : Node_Id) return Boolean; -- Tell whether a given subprogram cannot raise an exception ----------------------- -- Is_Exception_Safe -- ----------------------- function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is function Has_Side_Effect (N : Node_Id) return Boolean; -- Return True whenever encountering a subprogram call or raise -- statement of any kind in the sequence of statements --------------------- -- Has_Side_Effect -- --------------------- -- What is this doing buried two levels down in exp_ch9. It seems -- like a generally useful function, and indeed there may be code -- duplication going on here ??? function Has_Side_Effect (N : Node_Id) return Boolean is Stmt : Node_Id; Expr : Node_Id; function Is_Call_Or_Raise (N : Node_Id) return Boolean; -- Indicate whether N is a subprogram call or a raise statement ---------------------- -- Is_Call_Or_Raise -- ---------------------- function Is_Call_Or_Raise (N : Node_Id) return Boolean is begin return Nkind (N) = N_Procedure_Call_Statement or else Nkind (N) = N_Function_Call or else Nkind (N) = N_Raise_Statement or else Nkind (N) = N_Raise_Constraint_Error or else Nkind (N) = N_Raise_Program_Error or else Nkind (N) = N_Raise_Storage_Error; end Is_Call_Or_Raise; -- Start of processing for Has_Side_Effect begin Stmt := N; while Present (Stmt) loop if Is_Call_Or_Raise (Stmt) then return True; end if; -- An object declaration can also contain a function call -- or a raise statement if Nkind (Stmt) = N_Object_Declaration then Expr := Expression (Stmt); if Present (Expr) and then Is_Call_Or_Raise (Expr) then return True; end if; end if; Next (Stmt); end loop; return False; end Has_Side_Effect; -- Start of processing for Is_Exception_Safe begin -- If the checks handled by the back end are not disabled, we cannot -- ensure that no exception will be raised. if not Access_Checks_Suppressed (Empty) or else not Discriminant_Checks_Suppressed (Empty) or else not Range_Checks_Suppressed (Empty) or else not Index_Checks_Suppressed (Empty) or else Opt.Stack_Checking_Enabled then return False; end if; if Has_Side_Effect (First (Declarations (Subprogram))) or else Has_Side_Effect ( First (Statements (Handled_Statement_Sequence (Subprogram)))) then return False; else return True; end if; end Is_Exception_Safe; -- Start of processing for Build_Protected_Subprogram_Body begin Op_Spec := Specification (N); Exc_Safe := Is_Exception_Safe (N); P_Op_Spec := Build_Protected_Sub_Specification (N, Pid, Protected_Mode); -- Build a list of the formal parameters of the protected version of -- the subprogram to use as the actual parameters of the unprotected -- version. Uactuals := New_List; Pformal := First (Parameter_Specifications (P_Op_Spec)); while Present (Pformal) loop Append ( Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))), Uactuals); Next (Pformal); end loop; -- Make a call to the unprotected version of the subprogram built above -- for use by the protected version built below. if Nkind (Op_Spec) = N_Function_Specification then if Exc_Safe then R := Make_Defining_Identifier (Loc, New_Internal_Name ('R')); Unprot_Call := Make_Object_Declaration (Loc, Defining_Identifier => R, Constant_Present => True, Object_Definition => New_Copy (Result_Definition (N_Op_Spec)), Expression => Make_Function_Call (Loc, Name => Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))), Parameter_Associations => Uactuals)); Return_Stmt := Make_Return_Statement (Loc, Expression => New_Reference_To (R, Loc)); else Unprot_Call := Make_Return_Statement (Loc, Expression => Make_Function_Call (Loc, Name => Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))), Parameter_Associations => Uactuals)); end if; else Unprot_Call := Make_Procedure_Call_Statement (Loc, Name => Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))), Parameter_Associations => Uactuals); end if; -- Wrap call in block that will be covered by an at_end handler if not Exc_Safe then Unprot_Call := Make_Block_Statement (Loc, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List (Unprot_Call))); end if; -- Make the protected subprogram body. This locks the protected -- object and calls the unprotected version of the subprogram. -- If the protected object is controlled (i.e it has entries or -- needs finalization for interrupt handling), call Lock_Entries, -- except if the protected object follows the Ravenscar profile, in -- which case call Lock_Entry, otherwise call the simplified version, -- Lock. if Has_Entries (Pid) or else Has_Interrupt_Handler (Pid) or else (Has_Attach_Handler (Pid) and then not Restricted_Profile) or else (Ada_Version >= Ada_05 and then Present (Interface_List (Parent (Pid)))) then if Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False or else Number_Entries (Pid) > 1 or else (Has_Attach_Handler (Pid) and then not Restricted_Profile) then Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc); Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc); else Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc); Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc); end if; else Lock_Name := New_Reference_To (RTE (RE_Lock), Loc); Service_Name := New_Reference_To (RTE (RE_Unlock), Loc); end if; Object_Parm := Make_Attribute_Reference (Loc, Prefix => Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name_uObject), Selector_Name => Make_Identifier (Loc, Name_uObject)), Attribute_Name => Name_Unchecked_Access); Lock_Stmt := Make_Procedure_Call_Statement (Loc, Name => Lock_Name, Parameter_Associations => New_List (Object_Parm)); if Abort_Allowed then Stmts := New_List ( Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Abort_Defer), Loc), Parameter_Associations => Empty_List), Lock_Stmt); else Stmts := New_List (Lock_Stmt); end if; if not Exc_Safe then Append (Unprot_Call, Stmts); else if Nkind (Op_Spec) = N_Function_Specification then Pre_Stmts := Stmts; Stmts := Empty_List; else Append (Unprot_Call, Stmts); end if; Append ( Make_Procedure_Call_Statement (Loc, Name => Service_Name, Parameter_Associations => New_List (New_Copy_Tree (Object_Parm))), Stmts); if Abort_Allowed then Append ( Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc), Parameter_Associations => Empty_List), Stmts); end if; if Nkind (Op_Spec) = N_Function_Specification then Append (Return_Stmt, Stmts); Append (Make_Block_Statement (Loc, Declarations => New_List (Unprot_Call), Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts)), Pre_Stmts); Stmts := Pre_Stmts; end if; end if; Sub_Body := Make_Subprogram_Body (Loc, Declarations => Empty_List, Specification => P_Op_Spec, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts)); if not Exc_Safe then Set_Is_Protected_Subprogram_Body (Sub_Body); end if; return Sub_Body; end Build_Protected_Subprogram_Body; ------------------------------------- -- Build_Protected_Subprogram_Call -- ------------------------------------- procedure Build_Protected_Subprogram_Call (N : Node_Id; Name : Node_Id; Rec : Node_Id; External : Boolean := True) is Loc : constant Source_Ptr := Sloc (N); Sub : constant Entity_Id := Entity (Name); New_Sub : Node_Id; Params : List_Id; begin if External then New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc); else New_Sub := New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc); end if; if Present (Parameter_Associations (N)) then Params := New_Copy_List_Tree (Parameter_Associations (N)); else Params := New_List; end if; Prepend (Rec, Params); if Ekind (Sub) = E_Procedure then Rewrite (N, Make_Procedure_Call_Statement (Loc, Name => New_Sub, Parameter_Associations => Params)); else pragma Assert (Ekind (Sub) = E_Function); Rewrite (N, Make_Function_Call (Loc, Name => New_Sub, Parameter_Associations => Params)); end if; if External and then Nkind (Rec) = N_Unchecked_Type_Conversion and then Is_Entity_Name (Expression (Rec)) and then Is_Shared_Passive (Entity (Expression (Rec))) then Add_Shared_Var_Lock_Procs (N); end if; end Build_Protected_Subprogram_Call; ------------------------- -- Build_Selected_Name -- ------------------------- function Build_Selected_Name (Prefix : Entity_Id; Selector : Entity_Id; Append_Char : Character := ' ') return Name_Id is Select_Buffer : String (1 .. Hostparm.Max_Name_Length); Select_Len : Natural; begin Get_Name_String (Chars (Selector)); Select_Len := Name_Len; Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len); Get_Name_String (Chars (Prefix)); -- If scope is anonymous type, discard suffix to recover name of -- single protected object. Otherwise use protected type name. if Name_Buffer (Name_Len) = 'T' then Name_Len := Name_Len - 1; end if; Name_Buffer (Name_Len + 1) := '_'; Name_Buffer (Name_Len + 2) := '_'; Name_Len := Name_Len + 2; for J in 1 .. Select_Len loop Name_Len := Name_Len + 1; Name_Buffer (Name_Len) := Select_Buffer (J); end loop; -- Now add the Append_Char if specified. The encoding to follow -- depends on the type of entity. If Append_Char is either 'N' or 'P', -- then the entity is associated to a protected type subprogram. -- Otherwise, it is a protected type entry. For each case, the -- encoding to follow for the suffix is documented in exp_dbug.ads. -- It would be better to encapsulate this as a routine in Exp_Dbug ??? if Append_Char /= ' ' then if Append_Char = 'P' or Append_Char = 'N' then Name_Len := Name_Len + 1; Name_Buffer (Name_Len) := Append_Char; return Name_Find; else Name_Buffer (Name_Len + 1) := '_'; Name_Buffer (Name_Len + 2) := Append_Char; Name_Len := Name_Len + 2; return New_External_Name (Name_Find, ' ', -1); end if; else return Name_Find; end if; end Build_Selected_Name; ----------------------------- -- Build_Simple_Entry_Call -- ----------------------------- -- A task entry call is converted to a call to Call_Simple -- declare -- P : parms := (parm, parm, parm); -- begin -- Call_Simple (acceptor-task, entry-index, P'Address); -- parm := P.param; -- parm := P.param; -- ... -- end; -- Here Pnn is an aggregate of the type constructed for the entry to hold -- the parameters, and the constructed aggregate value contains either the -- parameters or, in the case of non-elementary types, references to these -- parameters. Then the address of this aggregate is passed to the runtime -- routine, along with the task id value and the task entry index value. -- Pnn is only required if parameters are present. -- The assignments after the call are present only in the case of in-out -- or out parameters for elementary types, and are used to assign back the -- resulting values of such parameters. -- Note: the reason that we insert a block here is that in the context -- of selects, conditional entry calls etc. the entry call statement -- appears on its own, not as an element of a list. -- A protected entry call is converted to a Protected_Entry_Call: -- declare -- P : E1_Params := (param, param, param); -- Pnn : Boolean; -- Bnn : Communications_Block; -- declare -- P : E1_Params := (param, param, param); -- Bnn : Communications_Block; -- begin -- Protected_Entry_Call ( -- Object => po._object'Access, -- E => <entry index>; -- Uninterpreted_Data => P'Address; -- Mode => Simple_Call; -- Block => Bnn); -- parm := P.param; -- parm := P.param; -- ... -- end; procedure Build_Simple_Entry_Call (N : Node_Id; Concval : Node_Id; Ename : Node_Id; Index : Node_Id) is begin Expand_Call (N); -- Convert entry call to Call_Simple call declare Loc : constant Source_Ptr := Sloc (N); Parms : constant List_Id := Parameter_Associations (N); Stats : constant List_Id := New_List; Actual : Node_Id; Call : Node_Id; Comm_Name : Entity_Id; Conctyp : Node_Id; Decls : List_Id; Ent : Entity_Id; Ent_Acc : Entity_Id; Formal : Node_Id; Iface_Tag : Entity_Id; Iface_Typ : Entity_Id; N_Node : Node_Id; N_Var : Node_Id; P : Entity_Id; Parm1 : Node_Id; Parm2 : Node_Id; Parm3 : Node_Id; Pdecl : Node_Id; Plist : List_Id; X : Entity_Id; Xdecl : Node_Id; begin -- Simple entry and entry family cases merge here Ent := Entity (Ename); Ent_Acc := Entry_Parameters_Type (Ent); Conctyp := Etype (Concval); -- If prefix is an access type, dereference to obtain the task type if Is_Access_Type (Conctyp) then Conctyp := Designated_Type (Conctyp); end if; -- Special case for protected subprogram calls if Is_Protected_Type (Conctyp) and then Is_Subprogram (Entity (Ename)) then if not Is_Eliminated (Entity (Ename)) then Build_Protected_Subprogram_Call (N, Ename, Convert_Concurrent (Concval, Conctyp)); Analyze (N); end if; return; end if; -- First parameter is the Task_Id value from the task value or the -- Object from the protected object value, obtained by selecting -- the _Task_Id or _Object from the result of doing an unchecked -- conversion to convert the value to the corresponding record type. Parm1 := Concurrent_Ref (Concval); -- Second parameter is the entry index, computed by the routine -- provided for this purpose. The value of this expression is -- assigned to an intermediate variable to assure that any entry -- family index expressions are evaluated before the entry -- parameters. if Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False or else not Is_Protected_Type (Conctyp) or else Number_Entries (Conctyp) > 1 or else (Has_Attach_Handler (Conctyp) and then not Restricted_Profile) then X := Make_Defining_Identifier (Loc, Name_uX); Xdecl := Make_Object_Declaration (Loc, Defining_Identifier => X, Object_Definition => New_Reference_To (RTE (RE_Task_Entry_Index), Loc), Expression => Actual_Index_Expression ( Loc, Entity (Ename), Index, Concval)); Decls := New_List (Xdecl); Parm2 := New_Reference_To (X, Loc); else Xdecl := Empty; Decls := New_List; Parm2 := Empty; end if; -- The third parameter is the packaged parameters. If there are -- none, then it is just the null address, since nothing is passed. if No (Parms) then Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc); P := Empty; -- Case of parameters present, where third argument is the address -- of a packaged record containing the required parameter values. else -- First build a list of parameter values, which are references to -- objects of the parameter types. Plist := New_List; Actual := First_Actual (N); Formal := First_Formal (Ent); while Present (Actual) loop -- If it is a by_copy_type, copy it to a new variable. The -- packaged record has a field that points to this variable. if Is_By_Copy_Type (Etype (Actual)) then N_Node := Make_Object_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Chars => New_Internal_Name ('J')), Aliased_Present => True, Object_Definition => New_Reference_To (Etype (Formal), Loc)); -- We have to make an assignment statement separate for the -- case of limited type. We cannot assign it unless the -- Assignment_OK flag is set first. if Ekind (Formal) /= E_Out_Parameter then N_Var := New_Reference_To (Defining_Identifier (N_Node), Loc); Set_Assignment_OK (N_Var); Append_To (Stats, Make_Assignment_Statement (Loc, Name => N_Var, Expression => Relocate_Node (Actual))); end if; Append (N_Node, Decls); Append_To (Plist, Make_Attribute_Reference (Loc, Attribute_Name => Name_Unchecked_Access, Prefix => New_Reference_To (Defining_Identifier (N_Node), Loc))); else -- Interface class-wide formal if Ada_Version >= Ada_05 and then Ekind (Etype (Formal)) = E_Class_Wide_Type and then Is_Interface (Etype (Formal)) then Iface_Typ := Etype (Etype (Formal)); -- Generate: -- formal_iface_type! (actual.iface_tag)'reference Iface_Tag := Find_Interface_Tag (Etype (Actual), Iface_Typ); pragma Assert (Present (Iface_Tag)); Append_To (Plist, Make_Reference (Loc, Unchecked_Convert_To (Iface_Typ, Make_Selected_Component (Loc, Prefix => Relocate_Node (Actual), Selector_Name => New_Reference_To (Iface_Tag, Loc))))); else -- Generate: -- actual'reference Append_To (Plist, Make_Reference (Loc, Relocate_Node (Actual))); end if; end if; Next_Actual (Actual); Next_Formal_With_Extras (Formal); end loop; -- Now build the declaration of parameters initialized with the -- aggregate containing this constructed parameter list. P := Make_Defining_Identifier (Loc, Name_uP); Pdecl := Make_Object_Declaration (Loc, Defining_Identifier => P, Object_Definition => New_Reference_To (Designated_Type (Ent_Acc), Loc), Expression => Make_Aggregate (Loc, Expressions => Plist)); Parm3 := Make_Attribute_Reference (Loc, Attribute_Name => Name_Address, Prefix => New_Reference_To (P, Loc)); Append (Pdecl, Decls); end if; -- Now we can create the call, case of protected type if Is_Protected_Type (Conctyp) then if Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False or else Number_Entries (Conctyp) > 1 or else (Has_Attach_Handler (Conctyp) and then not Restricted_Profile) then -- Change the type of the index declaration Set_Object_Definition (Xdecl, New_Reference_To (RTE (RE_Protected_Entry_Index), Loc)); -- Some additional declarations for protected entry calls if No (Decls) then Decls := New_List; end if; -- Bnn : Communications_Block; Comm_Name := Make_Defining_Identifier (Loc, New_Internal_Name ('B')); Append_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => Comm_Name, Object_Definition => New_Reference_To (RTE (RE_Communication_Block), Loc))); -- Some additional statements for protected entry calls -- Protected_Entry_Call ( -- Object => po._object'Access, -- E => <entry index>; -- Uninterpreted_Data => P'Address; -- Mode => Simple_Call; -- Block => Bnn); Call := Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Protected_Entry_Call), Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Attribute_Name => Name_Unchecked_Access, Prefix => Parm1), Parm2, Parm3, New_Reference_To (RTE (RE_Simple_Call), Loc), New_Occurrence_Of (Comm_Name, Loc))); else -- Protected_Single_Entry_Call ( -- Object => po._object'Access, -- Uninterpreted_Data => P'Address; -- Mode => Simple_Call); Call := Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( RTE (RE_Protected_Single_Entry_Call), Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Attribute_Name => Name_Unchecked_Access, Prefix => Parm1), Parm3, New_Reference_To (RTE (RE_Simple_Call), Loc))); end if; -- Case of task type else Call := Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Call_Simple), Loc), Parameter_Associations => New_List (Parm1, Parm2, Parm3)); end if; Append_To (Stats, Call); -- If there are out or in/out parameters by copy add assignment -- statements for the result values. if Present (Parms) then Actual := First_Actual (N); Formal := First_Formal (Ent); Set_Assignment_OK (Actual); while Present (Actual) loop if Is_By_Copy_Type (Etype (Actual)) and then Ekind (Formal) /= E_In_Parameter then N_Node := Make_Assignment_Statement (Loc, Name => New_Copy (Actual), Expression => Make_Explicit_Dereference (Loc, Make_Selected_Component (Loc, Prefix => New_Reference_To (P, Loc), Selector_Name => Make_Identifier (Loc, Chars (Formal))))); -- In all cases (including limited private types) we want -- the assignment to be valid. Set_Assignment_OK (Name (N_Node)); -- If the call is the triggering alternative in an -- asynchronous select, or the entry_call alternative of a -- conditional entry call, the assignments for in-out -- parameters are incorporated into the statement list that -- follows, so that there are executed only if the entry -- call succeeds. if (Nkind (Parent (N)) = N_Triggering_Alternative and then N = Triggering_Statement (Parent (N))) or else (Nkind (Parent (N)) = N_Entry_Call_Alternative and then N = Entry_Call_Statement (Parent (N))) then if No (Statements (Parent (N))) then Set_Statements (Parent (N), New_List); end if; Prepend (N_Node, Statements (Parent (N))); else Insert_After (Call, N_Node); end if; end if; Next_Actual (Actual); Next_Formal_With_Extras (Formal); end loop; end if; -- Finally, create block and analyze it Rewrite (N, Make_Block_Statement (Loc, Declarations => Decls, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats))); Analyze (N); end; end Build_Simple_Entry_Call; -------------------------------- -- Build_Task_Activation_Call -- -------------------------------- procedure Build_Task_Activation_Call (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Chain : Entity_Id; Call : Node_Id; Name : Node_Id; P : Node_Id; begin -- Get the activation chain entity. Except in the case of a package -- body, this is in the node that w as passed. For a package body, we -- have to find the corresponding package declaration node. if Nkind (N) = N_Package_Body then P := Corresponding_Spec (N); loop P := Parent (P); exit when Nkind (P) = N_Package_Declaration; end loop; Chain := Activation_Chain_Entity (P); else Chain := Activation_Chain_Entity (N); end if; if Present (Chain) then if Restricted_Profile then Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc); else Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc); end if; Call := Make_Procedure_Call_Statement (Loc, Name => Name, Parameter_Associations => New_List (Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Chain, Loc), Attribute_Name => Name_Unchecked_Access))); if Nkind (N) = N_Package_Declaration then if Present (Corresponding_Body (N)) then null; elsif Present (Private_Declarations (Specification (N))) then Append (Call, Private_Declarations (Specification (N))); else Append (Call, Visible_Declarations (Specification (N))); end if; else if Present (Handled_Statement_Sequence (N)) then -- The call goes at the start of the statement sequence, but -- after the start of exception range label if one is present. declare Stm : Node_Id; begin Stm := First (Statements (Handled_Statement_Sequence (N))); if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then Next (Stm); end if; Insert_Before (Stm, Call); end; else Set_Handled_Statement_Sequence (N, Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List (Call))); end if; end if; Analyze (Call); Check_Task_Activation (N); end if; end Build_Task_Activation_Call; ------------------------------- -- Build_Task_Allocate_Block -- ------------------------------- procedure Build_Task_Allocate_Block (Actions : List_Id; N : Node_Id; Args : List_Id) is T : constant Entity_Id := Entity (Expression (N)); Init : constant Entity_Id := Base_Init_Proc (T); Loc : constant Source_Ptr := Sloc (N); Chain : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uChain); Blkent : Entity_Id; Block : Node_Id; begin Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A')); Block := Make_Block_Statement (Loc, Identifier => New_Reference_To (Blkent, Loc), Declarations => New_List ( -- _Chain : Activation_Chain; Make_Object_Declaration (Loc, Defining_Identifier => Chain, Aliased_Present => True, Object_Definition => New_Reference_To (RTE (RE_Activation_Chain), Loc))), Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List ( -- Init (Args); Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (Init, Loc), Parameter_Associations => Args), -- Activate_Tasks (_Chain); Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Chain, Loc), Attribute_Name => Name_Unchecked_Access))))), Has_Created_Identifier => True, Is_Task_Allocation_Block => True); Append_To (Actions, Make_Implicit_Label_Declaration (Loc, Defining_Identifier => Blkent, Label_Construct => Block)); Append_To (Actions, Block); Set_Activation_Chain_Entity (Block, Chain); end Build_Task_Allocate_Block; ----------------------------------------------- -- Build_Task_Allocate_Block_With_Init_Stmts -- ----------------------------------------------- procedure Build_Task_Allocate_Block_With_Init_Stmts (Actions : List_Id; N : Node_Id; Init_Stmts : List_Id) is Loc : constant Source_Ptr := Sloc (N); Chain : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uChain); Blkent : Entity_Id; Block : Node_Id; begin Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A')); Append_To (Init_Stmts, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Chain, Loc), Attribute_Name => Name_Unchecked_Access)))); Block := Make_Block_Statement (Loc, Identifier => New_Reference_To (Blkent, Loc), Declarations => New_List ( -- _Chain : Activation_Chain; Make_Object_Declaration (Loc, Defining_Identifier => Chain, Aliased_Present => True, Object_Definition => New_Reference_To (RTE (RE_Activation_Chain), Loc))), Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts), Has_Created_Identifier => True, Is_Task_Allocation_Block => True); Append_To (Actions, Make_Implicit_Label_Declaration (Loc, Defining_Identifier => Blkent, Label_Construct => Block)); Append_To (Actions, Block); Set_Activation_Chain_Entity (Block, Chain); end Build_Task_Allocate_Block_With_Init_Stmts; ----------------------------------- -- Build_Task_Proc_Specification -- ----------------------------------- function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (T); Nam : constant Name_Id := Chars (T); Ent : Entity_Id; begin Ent := Make_Defining_Identifier (Loc, Chars => New_External_Name (Nam, 'B')); Set_Is_Internal (Ent); -- Associate the procedure with the task, if this is the declaration -- (and not the body) of the procedure. if No (Task_Body_Procedure (T)) then Set_Task_Body_Procedure (T, Ent); end if; return Make_Procedure_Specification (Loc, Defining_Unit_Name => Ent, Parameter_Specifications => New_List ( Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uTask), Parameter_Type => Make_Access_Definition (Loc, Subtype_Mark => New_Reference_To (Corresponding_Record_Type (T), Loc))))); end Build_Task_Proc_Specification; --------------------------------------- -- Build_Unprotected_Subprogram_Body -- --------------------------------------- function Build_Unprotected_Subprogram_Body (N : Node_Id; Pid : Node_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (N); N_Op_Spec : Node_Id; Op_Decls : List_Id; begin -- Make an unprotected version of the subprogram for use within the same -- object, with a new name and an additional parameter representing the -- object. Op_Decls := Declarations (N); N_Op_Spec := Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode); return Make_Subprogram_Body (Loc, Specification => N_Op_Spec, Declarations => Op_Decls, Handled_Statement_Sequence => Handled_Statement_Sequence (N)); end Build_Unprotected_Subprogram_Body; ---------------------------- -- Collect_Entry_Families -- ---------------------------- procedure Collect_Entry_Families (Loc : Source_Ptr; Cdecls : List_Id; Current_Node : in out Node_Id; Conctyp : Entity_Id) is Efam : Entity_Id; Efam_Decl : Node_Id; Efam_Type : Entity_Id; begin Efam := First_Entity (Conctyp); while Present (Efam) loop if Ekind (Efam) = E_Entry_Family then Efam_Type := Make_Defining_Identifier (Loc, Chars => New_Internal_Name ('F')); declare Bas : Entity_Id := Base_Type (Etype (Discrete_Subtype_Definition (Parent (Efam)))); Bas_Decl : Node_Id := Empty; Lo, Hi : Node_Id; begin Get_Index_Bounds (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi); if Scope (Bas) = Standard_Standard and then Bas = Base_Type (Standard_Integer) and then Has_Discriminants (Conctyp) and then Present (Discriminant_Default_Value (First_Discriminant (Conctyp))) and then (Denotes_Discriminant (Lo, True) or else Denotes_Discriminant (Hi, True)) then Bas := Make_Defining_Identifier (Loc, New_Internal_Name ('B')); Bas_Decl := Make_Subtype_Declaration (Loc, Defining_Identifier => Bas, Subtype_Indication => Make_Subtype_Indication (Loc, Subtype_Mark => New_Occurrence_Of (Standard_Integer, Loc), Constraint => Make_Range_Constraint (Loc, Range_Expression => Make_Range (Loc, Make_Integer_Literal (Loc, -Entry_Family_Bound), Make_Integer_Literal (Loc, Entry_Family_Bound - 1))))); Insert_After (Current_Node, Bas_Decl); Current_Node := Bas_Decl; Analyze (Bas_Decl); end if; Efam_Decl := Make_Full_Type_Declaration (Loc, Defining_Identifier => Efam_Type, Type_Definition => Make_Unconstrained_Array_Definition (Loc, Subtype_Marks => (New_List (New_Occurrence_Of (Bas, Loc))), Component_Definition => Make_Component_Definition (Loc, Aliased_Present => False, Subtype_Indication => New_Reference_To (Standard_Character, Loc)))); end; Insert_After (Current_Node, Efam_Decl); Current_Node := Efam_Decl; Analyze (Efam_Decl); Append_To (Cdecls, Make_Component_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Chars (Efam)), Component_Definition => Make_Component_Definition (Loc, Aliased_Present => False, Subtype_Indication => Make_Subtype_Indication (Loc, Subtype_Mark => New_Occurrence_Of (Efam_Type, Loc), Constraint => Make_Index_Or_Discriminant_Constraint (Loc, Constraints => New_List ( New_Occurrence_Of (Etype (Discrete_Subtype_Definition (Parent (Efam))), Loc))))))); end if; Next_Entity (Efam); end loop; end Collect_Entry_Families; -------------------- -- Concurrent_Ref -- -------------------- -- The expression returned for a reference to a concurrent object has the -- form: -- taskV!(name)._Task_Id -- for a task, and -- objectV!(name)._Object -- for a protected object. For the case of an access to a concurrent -- object, there is an extra explicit dereference: -- taskV!(name.all)._Task_Id -- objectV!(name.all)._Object -- here taskV and objectV are the types for the associated records, which -- contain the required _Task_Id and _Object fields for tasks and protected -- objects, respectively. -- For the case of a task type name, the expression is -- Self; -- i.e. a call to the Self function which returns precisely this Task_Id -- For the case of a protected type name, the expression is -- objectR -- which is a renaming of the _object field of the current object object -- record, passed into protected operations as a parameter. function Concurrent_Ref (N : Node_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (N); Ntyp : constant Entity_Id := Etype (N); Dtyp : Entity_Id; Sel : Name_Id; function Is_Current_Task (T : Entity_Id) return Boolean; -- Check whether the reference is to the immediately enclosing task -- type, or to an outer one (rare but legal). --------------------- -- Is_Current_Task -- --------------------- function Is_Current_Task (T : Entity_Id) return Boolean is Scop : Entity_Id; begin Scop := Current_Scope; while Present (Scop) and then Scop /= Standard_Standard loop if Scop = T then return True; elsif Is_Task_Type (Scop) then return False; -- If this is a procedure nested within the task type, we must -- assume that it can be called from an inner task, and therefore -- cannot treat it as a local reference. elsif Is_Overloadable (Scop) and then In_Open_Scopes (T) then return False; else Scop := Scope (Scop); end if; end loop; -- We know that we are within the task body, so should have found it -- in scope. raise Program_Error; end Is_Current_Task; -- Start of processing for Concurrent_Ref begin if Is_Access_Type (Ntyp) then Dtyp := Designated_Type (Ntyp); if Is_Protected_Type (Dtyp) then Sel := Name_uObject; else Sel := Name_uTask_Id; end if; return Make_Selected_Component (Loc, Prefix => Unchecked_Convert_To (Corresponding_Record_Type (Dtyp), Make_Explicit_Dereference (Loc, N)), Selector_Name => Make_Identifier (Loc, Sel)); elsif Is_Entity_Name (N) and then Is_Concurrent_Type (Entity (N)) then if Is_Task_Type (Entity (N)) then if Is_Current_Task (Entity (N)) then return Make_Function_Call (Loc, Name => New_Reference_To (RTE (RE_Self), Loc)); else declare Decl : Node_Id; T_Self : constant Entity_Id := Make_Defining_Identifier (Loc, Chars => New_Internal_Name ('T')); T_Body : constant Node_Id := Parent (Corresponding_Body (Parent (Entity (N)))); begin Decl := Make_Object_Declaration (Loc, Defining_Identifier => T_Self, Object_Definition => New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc), Expression => Make_Function_Call (Loc, Name => New_Reference_To (RTE (RE_Self), Loc))); Prepend (Decl, Declarations (T_Body)); Analyze (Decl); Set_Scope (T_Self, Entity (N)); return New_Occurrence_Of (T_Self, Loc); end; end if; else pragma Assert (Is_Protected_Type (Entity (N))); return New_Reference_To ( Object_Ref (Corresponding_Body (Parent (Base_Type (Ntyp)))), Loc); end if; else pragma Assert (Is_Concurrent_Type (Ntyp)); if Is_Protected_Type (Ntyp) then Sel := Name_uObject; else Sel := Name_uTask_Id; end if; return Make_Selected_Component (Loc, Prefix => Unchecked_Convert_To (Corresponding_Record_Type (Ntyp), New_Copy_Tree (N)), Selector_Name => Make_Identifier (Loc, Sel)); end if; end Concurrent_Ref; ------------------------ -- Convert_Concurrent -- ------------------------ function Convert_Concurrent (N : Node_Id; Typ : Entity_Id) return Node_Id is begin if not Is_Concurrent_Type (Typ) then return N; else return Unchecked_Convert_To (Corresponding_Record_Type (Typ), New_Copy_Tree (N)); end if; end Convert_Concurrent; ---------------------------- -- Entry_Index_Expression -- ---------------------------- function Entry_Index_Expression (Sloc : Source_Ptr; Ent : Entity_Id; Index : Node_Id; Ttyp : Entity_Id) return Node_Id is Expr : Node_Id; Num : Node_Id; Lo : Node_Id; Hi : Node_Id; Prev : Entity_Id; S : Node_Id; begin -- The queues of entries and entry families appear in textual order in -- the associated record. The entry index is computed as the sum of the -- number of queues for all entries that precede the designated one, to -- which is added the index expression, if this expression denotes a -- member of a family. -- The following is a place holder for the count of simple entries Num := Make_Integer_Literal (Sloc, 1); -- We construct an expression which is a series of addition operations. -- The first operand is the number of single entries that precede this -- one, the second operand is the index value relative to the start of -- the referenced family, and the remaining operands are the lengths of -- the entry families that precede this entry, i.e. the constructed -- expression is: -- number_simple_entries + -- (s'pos (index-value) - s'pos (family'first)) + 1 + -- family'length + ... -- where index-value is the given index value, and s is the index -- subtype (we have to use pos because the subtype might be an -- enumeration type preventing direct subtraction). Note that the task -- entry array is one-indexed. -- The upper bound of the entry family may be a discriminant, so we -- retrieve the lower bound explicitly to compute offset, rather than -- using the index subtype which may mention a discriminant. if Present (Index) then S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent))); Expr := Make_Op_Add (Sloc, Left_Opnd => Num, Right_Opnd => Family_Offset ( Sloc, Make_Attribute_Reference (Sloc, Attribute_Name => Name_Pos, Prefix => New_Reference_To (Base_Type (S), Sloc), Expressions => New_List (Relocate_Node (Index))), Type_Low_Bound (S), Ttyp)); else Expr := Num; end if; -- Now add lengths of preceding entries and entry families Prev := First_Entity (Ttyp); while Chars (Prev) /= Chars (Ent) or else (Ekind (Prev) /= Ekind (Ent)) or else not Sem_Ch6.Type_Conformant (Ent, Prev) loop if Ekind (Prev) = E_Entry then Set_Intval (Num, Intval (Num) + 1); elsif Ekind (Prev) = E_Entry_Family then S := Etype (Discrete_Subtype_Definition (Declaration_Node (Prev))); Lo := Type_Low_Bound (S); Hi := Type_High_Bound (S); Expr := Make_Op_Add (Sloc, Left_Opnd => Expr, Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp)); -- Other components are anonymous types to be ignored else null; end if; Next_Entity (Prev); end loop; return Expr; end Entry_Index_Expression; --------------------------- -- Establish_Task_Master -- --------------------------- procedure Establish_Task_Master (N : Node_Id) is Call : Node_Id; begin if Restriction_Active (No_Task_Hierarchy) = False then Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master); Prepend_To (Declarations (N), Call); Analyze (Call); end if; end Establish_Task_Master; -------------------------------- -- Expand_Accept_Declarations -- -------------------------------- -- Part of the expansion of an accept statement involves the creation of -- a declaration that can be referenced from the statement sequence of -- the accept: -- Ann : Address; -- This declaration is inserted immediately before the accept statement -- and it is important that it be inserted before the statements of the -- statement sequence are analyzed. Thus it would be too late to create -- this declaration in the Expand_N_Accept_Statement routine, which is -- why there is a separate procedure to be called directly from Sem_Ch9. -- Ann is used to hold the address of the record containing the parameters -- (see Expand_N_Entry_Call for more details on how this record is built). -- References to the parameters do an unchecked conversion of this address -- to a pointer to the required record type, and then access the field that -- holds the value of the required parameter. The entity for the address -- variable is held as the top stack element (i.e. the last element) of the -- Accept_Address stack in the corresponding entry entity, and this element -- must be set in place before the statements are processed. -- The above description applies to the case of a stand alone accept -- statement, i.e. one not appearing as part of a select alternative. -- For the case of an accept that appears as part of a select alternative -- of a selective accept, we must still create the declaration right away, -- since Ann is needed immediately, but there is an important difference: -- The declaration is inserted before the selective accept, not before -- the accept statement (which is not part of a list anyway, and so would -- not accommodate inserted declarations) -- We only need one address variable for the entire selective accept. So -- the Ann declaration is created only for the first accept alternative, -- and subsequent accept alternatives reference the same Ann variable. -- We can distinguish the two cases by seeing whether the accept statement -- is part of a list. If not, then it must be in an accept alternative. -- To expand the requeue statement, a label is provided at the end of the -- accept statement or alternative of which it is a part, so that the -- statement can be skipped after the requeue is complete. This label is -- created here rather than during the expansion of the accept statement, -- because it will be needed by any requeue statements within the accept, -- which are expanded before the accept. procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is Loc : constant Source_Ptr := Sloc (N); Ann : Entity_Id := Empty; Adecl : Node_Id; Lab_Id : Node_Id; Lab : Node_Id; Ldecl : Node_Id; Ldecl2 : Node_Id; begin if Expander_Active then -- If we have no handled statement sequence, then build a dummy -- sequence consisting of a null statement. This is only done if -- pragma FIFO_Within_Priorities is specified. The issue here is -- that even a null accept body has an effect on the called task -- in terms of its position in the queue, so we cannot optimize -- the context switch away. However, if FIFO_Within_Priorities -- is not active, the optimization is legitimate, since we can -- say that our dispatching policy (i.e. the default dispatching -- policy) reorders the queue to be the same as just before the -- call. In the absence of a specified dispatching policy, we are -- allowed to modify queue orders for a given priority at will! if Opt.Task_Dispatching_Policy = 'F' and then No (Handled_Statement_Sequence (N)) then Set_Handled_Statement_Sequence (N, Make_Handled_Sequence_Of_Statements (Loc, New_List (Make_Null_Statement (Loc)))); end if; -- Create and declare two labels to be placed at the end of the -- accept statement. The first label is used to allow requeues to -- skip the remainder of entry processing. The second label is used -- to skip the remainder of entry processing if the rendezvous -- completes in the middle of the accept body. if Present (Handled_Statement_Sequence (N)) then Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L')); Set_Entity (Lab_Id, Make_Defining_Identifier (Loc, Chars (Lab_Id))); Lab := Make_Label (Loc, Lab_Id); Ldecl := Make_Implicit_Label_Declaration (Loc, Defining_Identifier => Entity (Lab_Id), Label_Construct => Lab); Append (Lab, Statements (Handled_Statement_Sequence (N))); Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L')); Set_Entity (Lab_Id, Make_Defining_Identifier (Loc, Chars (Lab_Id))); Lab := Make_Label (Loc, Lab_Id); Ldecl2 := Make_Implicit_Label_Declaration (Loc, Defining_Identifier => Entity (Lab_Id), Label_Construct => Lab); Append (Lab, Statements (Handled_Statement_Sequence (N))); else Ldecl := Empty; Ldecl2 := Empty; end if; -- Case of stand alone accept statement if Is_List_Member (N) then if Present (Handled_Statement_Sequence (N)) then Ann := Make_Defining_Identifier (Loc, Chars => New_Internal_Name ('A')); Adecl := Make_Object_Declaration (Loc, Defining_Identifier => Ann, Object_Definition => New_Reference_To (RTE (RE_Address), Loc)); Insert_Before (N, Adecl); Analyze (Adecl); Insert_Before (N, Ldecl); Analyze (Ldecl); Insert_Before (N, Ldecl2); Analyze (Ldecl2); end if; -- Case of accept statement which is in an accept alternative else declare Acc_Alt : constant Node_Id := Parent (N); Sel_Acc : constant Node_Id := Parent (Acc_Alt); Alt : Node_Id; begin pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative); pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept); -- ??? Consider a single label for select statements if Present (Handled_Statement_Sequence (N)) then Prepend (Ldecl2, Statements (Handled_Statement_Sequence (N))); Analyze (Ldecl2); Prepend (Ldecl, Statements (Handled_Statement_Sequence (N))); Analyze (Ldecl); end if; -- Find first accept alternative of the selective accept. A -- valid selective accept must have at least one accept in it. Alt := First (Select_Alternatives (Sel_Acc)); while Nkind (Alt) /= N_Accept_Alternative loop Next (Alt); end loop; -- If we are the first accept statement, then we have to create -- the Ann variable, as for the stand alone case, except that -- it is inserted before the selective accept. Similarly, a -- label for requeue expansion must be declared. if N = Accept_Statement (Alt) then Ann := Make_Defining_Identifier (Loc, New_Internal_Name ('A')); Adecl := Make_Object_Declaration (Loc, Defining_Identifier => Ann, Object_Definition => New_Reference_To (RTE (RE_Address), Loc)); Insert_Before (Sel_Acc, Adecl); Analyze (Adecl); -- If we are not the first accept statement, then find the Ann -- variable allocated by the first accept and use it. else Ann := Node (Last_Elmt (Accept_Address (Entity (Entry_Direct_Name (Accept_Statement (Alt)))))); end if; end; end if; -- Merge here with Ann either created or referenced, and Adecl -- pointing to the corresponding declaration. Remaining processing -- is the same for the two cases. if Present (Ann) then Append_Elmt (Ann, Accept_Address (Ent)); Set_Needs_Debug_Info (Ann); end if; -- Create renaming declarations for the entry formals. Each reference -- to a formal becomes a dereference of a component of the parameter -- block, whose address is held in Ann. These declarations are -- eventually inserted into the accept block, and analyzed there so -- that they have the proper scope for gdb and do not conflict with -- other declarations. if Present (Parameter_Specifications (N)) and then Present (Handled_Statement_Sequence (N)) then declare Comp : Entity_Id; Decl : Node_Id; Formal : Entity_Id; New_F : Entity_Id; begin New_Scope (Ent); Formal := First_Formal (Ent); while Present (Formal) loop Comp := Entry_Component (Formal); New_F := Make_Defining_Identifier (Sloc (Formal), Chars (Formal)); Set_Etype (New_F, Etype (Formal)); Set_Scope (New_F, Ent); Set_Needs_Debug_Info (New_F); -- That's the whole point. if Ekind (Formal) = E_In_Parameter then Set_Ekind (New_F, E_Constant); else Set_Ekind (New_F, E_Variable); Set_Extra_Constrained (New_F, Extra_Constrained (Formal)); end if; Set_Actual_Subtype (New_F, Actual_Subtype (Formal)); Decl := Make_Object_Renaming_Declaration (Loc, Defining_Identifier => New_F, Subtype_Mark => New_Reference_To (Etype (Formal), Loc), Name => Make_Explicit_Dereference (Loc, Make_Selected_Component (Loc, Prefix => Unchecked_Convert_To ( Entry_Parameters_Type (Ent), New_Reference_To (Ann, Loc)), Selector_Name => New_Reference_To (Comp, Loc)))); if No (Declarations (N)) then Set_Declarations (N, New_List); end if; Append (Decl, Declarations (N)); Set_Renamed_Object (Formal, New_F); Next_Formal (Formal); end loop; End_Scope; end; end if; end if; end Expand_Accept_Declarations; --------------------------------------------- -- Expand_Access_Protected_Subprogram_Type -- --------------------------------------------- procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Comps : List_Id; T : constant Entity_Id := Defining_Identifier (N); D_T : constant Entity_Id := Designated_Type (T); D_T2 : constant Entity_Id := Make_Defining_Identifier (Loc, Chars => New_Internal_Name ('D')); E_T : constant Entity_Id := Make_Defining_Identifier (Loc, Chars => New_Internal_Name ('E')); P_List : constant List_Id := Build_Protected_Spec (N, RTE (RE_Address), False, D_T); Decl1 : Node_Id; Decl2 : Node_Id; Def1 : Node_Id; begin -- Create access to protected subprogram with full signature if Nkind (Type_Definition (N)) = N_Access_Function_Definition then Def1 := Make_Access_Function_Definition (Loc, Parameter_Specifications => P_List, Result_Definition => New_Copy (Result_Definition (Type_Definition (N)))); else Def1 := Make_Access_Procedure_Definition (Loc, Parameter_Specifications => P_List); end if; Decl1 := Make_Full_Type_Declaration (Loc, Defining_Identifier => D_T2, Type_Definition => Def1); Analyze (Decl1); Insert_After (N, Decl1); -- Create Equivalent_Type, a record with two components for an access to -- object and an access to subprogram. Comps := New_List ( Make_Component_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, New_Internal_Name ('P')), Component_Definition => Make_Component_Definition (Loc, Aliased_Present => False, Subtype_Indication => New_Occurrence_Of (RTE (RE_Address), Loc))), Make_Component_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, New_Internal_Name ('S')), Component_Definition => Make_Component_Definition (Loc, Aliased_Present => False, Subtype_Indication => New_Occurrence_Of (D_T2, Loc)))); Decl2 := Make_Full_Type_Declaration (Loc, Defining_Identifier => E_T, Type_Definition => Make_Record_Definition (Loc, Component_List => Make_Component_List (Loc, Component_Items => Comps))); Analyze (Decl2); Insert_After (Decl1, Decl2); Set_Equivalent_Type (T, E_T); end Expand_Access_Protected_Subprogram_Type; -------------------------- -- Expand_Entry_Barrier -- -------------------------- procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is Loc : constant Source_Ptr := Sloc (N); Prot : constant Entity_Id := Scope (Ent); Spec_Decl : constant Node_Id := Parent (Prot); Cond : constant Node_Id := Condition (Entry_Body_Formal_Part (N)); Func : Node_Id; B_F : Node_Id; Body_Decl : Node_Id; begin if No_Run_Time_Mode then Error_Msg_CRT ("entry barrier", N); return; end if; -- The body of the entry barrier must be analyzed in the context of the -- protected object, but its scope is external to it, just as any other -- unprotected version of a protected operation. The specification has -- been produced when the protected type declaration was elaborated. We -- build the body, insert it in the enclosing scope, but analyze it in -- the current context. A more uniform approach would be to treat -- barrier just as a protected function, and discard the protected -- version of it because it is never called. if Expander_Active then B_F := Build_Barrier_Function (N, Ent, Prot); Func := Barrier_Function (Ent); Set_Corresponding_Spec (B_F, Func); Body_Decl := Parent (Corresponding_Body (Spec_Decl)); if Nkind (Parent (Body_Decl)) = N_Subunit then Body_Decl := Corresponding_Stub (Parent (Body_Decl)); end if; Insert_Before_And_Analyze (Body_Decl, B_F); Update_Prival_Subtypes (B_F); Set_Privals (Spec_Decl, N, Loc, After_Barrier => True); Set_Discriminals (Spec_Decl); Set_Scope (Func, Scope (Prot)); else Analyze_And_Resolve (Cond, Any_Boolean); end if; -- The Ravenscar profile restricts barriers to simple variables declared -- within the protected object. We also allow Boolean constants, since -- these appear in several published examples and are also allowed by -- the Aonix compiler. -- Note that after analysis variables in this context will be replaced -- by the corresponding prival, that is to say a renaming of a selected -- component of the form _Object.Var. If expansion is disabled, as -- within a generic, we check that the entity appears in the current -- scope. if Is_Entity_Name (Cond) then if Entity (Cond) = Standard_False or else Entity (Cond) = Standard_True then return; elsif not Expander_Active and then Scope (Entity (Cond)) = Current_Scope then return; -- Check for case of _object.all.field (note that the explicit -- dereference gets inserted by analyze/expand of _object.field) elsif Present (Renamed_Object (Entity (Cond))) and then Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component and then Chars (Prefix (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject then return; end if; end if; -- It is not a boolean variable or literal, so check the restriction Check_Restriction (Simple_Barriers, Cond); end Expand_Entry_Barrier; ------------------------------------ -- Expand_Entry_Body_Declarations -- ------------------------------------ procedure Expand_Entry_Body_Declarations (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Index_Spec : Node_Id; begin if Expander_Active then -- Expand entry bodies corresponding to entry families -- by assigning a placeholder for the constant that will -- be used to expand references to the entry index parameter. Index_Spec := Entry_Index_Specification (Entry_Body_Formal_Part (N)); if Present (Index_Spec) then Set_Entry_Index_Constant ( Defining_Identifier (Index_Spec), Make_Defining_Identifier (Loc, New_Internal_Name ('J'))); end if; end if; end Expand_Entry_Body_Declarations; ------------------------------ -- Expand_N_Abort_Statement -- ------------------------------ -- Expand abort T1, T2, .. Tn; into: -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...)) procedure Expand_N_Abort_Statement (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Tlist : constant List_Id := Names (N); Count : Nat; Aggr : Node_Id; Tasknm : Node_Id; begin Aggr := Make_Aggregate (Loc, Component_Associations => New_List); Count := 0; Tasknm := First (Tlist); while Present (Tasknm) loop Count := Count + 1; -- A task interface class-wide type object is being aborted. -- Retrieve its _task_id by calling a dispatching routine. if Ada_Version >= Ada_05 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type and then Is_Interface (Etype (Tasknm)) and then Is_Task_Interface (Etype (Tasknm)) then Append_To (Component_Associations (Aggr), Make_Component_Association (Loc, Choices => New_List ( Make_Integer_Literal (Loc, Count)), Expression => -- Tasknm._disp_get_task_id Make_Selected_Component (Loc, Prefix => New_Copy_Tree (Tasknm), Selector_Name => Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))); else Append_To (Component_Associations (Aggr), Make_Component_Association (Loc, Choices => New_List ( Make_Integer_Literal (Loc, Count)), Expression => Concurrent_Ref (Tasknm))); end if; Next (Tasknm); end loop; Rewrite (N, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc), Parameter_Associations => New_List ( Make_Qualified_Expression (Loc, Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc), Expression => Aggr)))); Analyze (N); end Expand_N_Abort_Statement; ------------------------------- -- Expand_N_Accept_Statement -- ------------------------------- -- This procedure handles expansion of accept statements that stand -- alone, i.e. they are not part of an accept alternative. The expansion -- of accept statement in accept alternatives is handled by the routines -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The -- following description applies only to stand alone accept statements. -- If there is no handled statement sequence, or only null statements, -- then this is called a trivial accept, and the expansion is: -- Accept_Trivial (entry-index) -- If there is a handled statement sequence, then the expansion is: -- Ann : Address; -- {Lnn : Label} -- begin -- begin -- Accept_Call (entry-index, Ann); -- Renaming_Declarations for formals -- <statement sequence from N_Accept_Statement node> -- Complete_Rendezvous; -- <<Lnn>> -- -- exception -- when ... => -- <exception handler from N_Accept_Statement node> -- Complete_Rendezvous; -- when ... => -- <exception handler from N_Accept_Statement node> -- Complete_Rendezvous; -- ... -- end; -- exception -- when all others => -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception); -- end; -- The first three declarations were already inserted ahead of the accept -- statement by the Expand_Accept_Declarations procedure, which was called -- directly from the semantics during analysis of the accept. statement, -- before analyzing its contained statements. -- The declarations from the N_Accept_Statement, as noted in Sinfo, come -- from possible expansion activity (the original source of course does -- not have any declarations associated with the accept statement, since -- an accept statement has no declarative part). In particular, if the -- expander is active, the first such declaration is the declaration of -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement). -- -- The two blocks are merged into a single block if the inner block has -- no exception handlers, but otherwise two blocks are required, since -- exceptions might be raised in the exception handlers of the inner -- block, and Exceptional_Complete_Rendezvous must be called. procedure Expand_N_Accept_Statement (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Stats : constant Node_Id := Handled_Statement_Sequence (N); Ename : constant Node_Id := Entry_Direct_Name (N); Eindx : constant Node_Id := Entry_Index (N); Eent : constant Entity_Id := Entity (Ename); Acstack : constant Elist_Id := Accept_Address (Eent); Ann : constant Entity_Id := Node (Last_Elmt (Acstack)); Ttyp : constant Entity_Id := Etype (Scope (Eent)); Blkent : Entity_Id; Call : Node_Id; Block : Node_Id; function Null_Statements (Stats : List_Id) return Boolean; -- Check for null statement sequence (i.e a list of labels and -- null statements). --------------------- -- Null_Statements -- --------------------- function Null_Statements (Stats : List_Id) return Boolean is Stmt : Node_Id; begin Stmt := First (Stats); while Nkind (Stmt) /= N_Empty and then (Nkind (Stmt) = N_Null_Statement or else Nkind (Stmt) = N_Label) loop Next (Stmt); end loop; return Nkind (Stmt) = N_Empty; end Null_Statements; -- Start of processing for Expand_N_Accept_Statement begin -- If accept statement is not part of a list, then its parent must be -- an accept alternative, and, as described above, we do not do any -- expansion for such accept statements at this level. if not Is_List_Member (N) then pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative); return; -- Trivial accept case (no statement sequence, or null statements). -- If the accept statement has declarations, then just insert them -- before the procedure call. -- We avoid this optimization when FIFO_Within_Priorities is active, -- since it is not correct according to annex D semantics. The problem -- is that the call is required to reorder the acceptors position on -- its ready queue, even though there is nothing to be done. However, -- if no policy is specified, then we decide that our dispatching -- policy always reorders the queue right after the RV to look the -- way they were just before the RV. Since we are allowed to freely -- reorder same-priority queues (this is part of what dispatching -- policies are all about), the optimization is legitimate. elsif Opt.Task_Dispatching_Policy /= 'F' and then (No (Stats) or else Null_Statements (Statements (Stats))) then -- Remove declarations for renamings, because the parameter block -- will not be assigned. declare D : Node_Id; Next_D : Node_Id; begin D := First (Declarations (N)); while Present (D) loop Next_D := Next (D); if Nkind (D) = N_Object_Renaming_Declaration then Remove (D); end if; D := Next_D; end loop; end; if Present (Declarations (N)) then Insert_Actions (N, Declarations (N)); end if; Rewrite (N, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc), Parameter_Associations => New_List ( Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp)))); Analyze (N); -- Discard Entry_Address that was created for it, so it will not be -- emitted if this accept statement is in the statement part of a -- delay alternative. if Present (Stats) then Remove_Last_Elmt (Acstack); end if; -- Case of statement sequence present else -- Construct the block, using the declarations from the accept -- statement if any to initialize the declarations of the block. Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A')); Set_Ekind (Blkent, E_Block); Set_Etype (Blkent, Standard_Void_Type); Set_Scope (Blkent, Current_Scope); Block := Make_Block_Statement (Loc, Identifier => New_Reference_To (Blkent, Loc), Declarations => Declarations (N), Handled_Statement_Sequence => Build_Accept_Body (N)); -- Prepend call to Accept_Call to main statement sequence If the -- accept has exception handlers, the statement sequence is wrapped -- in a block. Insert call and renaming declarations in the -- declarations of the block, so they are elaborated before the -- handlers. Call := Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Accept_Call), Loc), Parameter_Associations => New_List ( Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp), New_Reference_To (Ann, Loc))); if Parent (Stats) = N then Prepend (Call, Statements (Stats)); else Set_Declarations (Parent (Stats), New_List (Call)); end if; Analyze (Call); New_Scope (Blkent); declare D : Node_Id; Next_D : Node_Id; Typ : Entity_Id; begin D := First (Declarations (N)); while Present (D) loop Next_D := Next (D); if Nkind (D) = N_Object_Renaming_Declaration then -- The renaming declarations for the formals were created -- during analysis of the accept statement, and attached to -- the list of declarations. Place them now in the context -- of the accept block or subprogram. Remove (D); Typ := Entity (Subtype_Mark (D)); Insert_After (Call, D); Analyze (D); -- If the formal is class_wide, it does not have an actual -- subtype. The analysis of the renaming declaration creates -- one, but we need to retain the class-wide nature of the -- entity. if Is_Class_Wide_Type (Typ) then Set_Etype (Defining_Identifier (D), Typ); end if; end if; D := Next_D; end loop; end; End_Scope; -- Replace the accept statement by the new block Rewrite (N, Block); Analyze (N); -- Last step is to unstack the Accept_Address value Remove_Last_Elmt (Acstack); end if; end Expand_N_Accept_Statement; ---------------------------------- -- Expand_N_Asynchronous_Select -- ---------------------------------- -- This procedure assumes that the trigger statement is an entry call or -- a dispatching procedure call. A delay alternative should already have -- been expanded into an entry call to the appropriate delay object Wait -- entry. -- If the trigger is a task entry call, the select is implemented with -- a Task_Entry_Call: -- declare -- B : Boolean; -- C : Boolean; -- P : parms := (parm, parm, parm); -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions -- procedure _clean is -- begin -- ... -- Cancel_Task_Entry_Call (C); -- ... -- end _clean; -- begin -- Abort_Defer; -- Task_Entry_Call -- (acceptor-task, -- entry-index, -- P'Address, -- Asynchronous_Call, -- B); -- begin -- begin -- Abort_Undefer; -- <abortable-part> -- at end -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions. -- end; -- exception -- when Abort_Signal => Abort_Undefer; -- end; -- parm := P.param; -- parm := P.param; -- ... -- if not C then -- <triggered-statements> -- end if; -- end; -- Note that Build_Simple_Entry_Call is used to expand the entry -- of the asynchronous entry call (by the -- Expand_N_Entry_Call_Statement procedure) as follows: -- declare -- P : parms := (parm, parm, parm); -- begin -- Call_Simple (acceptor-task, entry-index, P'Address); -- parm := P.param; -- parm := P.param; -- ... -- end; -- so the task at hand is to convert the latter expansion into the former -- If the trigger is a protected entry call, the select is -- implemented with Protected_Entry_Call: -- declare -- P : E1_Params := (param, param, param); -- Bnn : Communications_Block; -- begin -- declare -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions. -- procedure _clean is -- begin -- ... -- if Enqueued (Bnn) then -- Cancel_Protected_Entry_Call (Bnn); -- end if; -- ... -- end _clean; -- begin -- begin -- Protected_Entry_Call ( -- Object => po._object'Access, -- E => <entry index>; -- Uninterpreted_Data => P'Address; -- Mode => Asynchronous_Call; -- Block => Bnn); -- if Enqueued (Bnn) then -- <abortable-part> -- end if; -- at end -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions. -- end; -- exception -- when Abort_Signal => Abort_Undefer; -- end; -- if not Cancelled (Bnn) then -- <triggered-statements> -- end if; -- end; -- Build_Simple_Entry_Call is used to expand the all to a simple -- protected entry call: -- declare -- P : E1_Params := (param, param, param); -- Bnn : Communications_Block; -- begin -- Protected_Entry_Call ( -- Object => po._object'Access, -- E => <entry index>; -- Uninterpreted_Data => P'Address; -- Mode => Simple_Call; -- Block => Bnn); -- parm := P.param; -- parm := P.param; -- ... -- end; -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is -- expanded into: -- declare -- B : Boolean := False; -- Bnn : Communication_Block; -- C : Ada.Tags.Prim_Op_Kind; -- K : Ada.Tags.Tagged_Kind := -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>)); -- P : Parameters := (Param1 .. ParamN); -- S : Integer; -- U : Boolean; -- begin -- if K = Ada.Tags.TK_Limited_Tagged then -- <dispatching-call>; -- <triggering-statements>; -- else -- S := Ada.Tags.Get_Offset_Index (Ada.Tags.Tag (<object>), -- DT_Position (<dispatching-call>)); -- _Disp_Get_Prim_Op_Kind (<object>, S, C); -- if C = POK_Protected_Entry then -- declare -- procedure _clean is -- begin -- if Enqueued (Bnn) then -- Cancel_Protected_Entry_Call (Bnn); -- end if; -- end _clean; -- begin -- begin -- _Disp_Asynchronous_Select -- (<object>, S, P'address, Bnn, B); -- Param1 := P.Param1; -- ... -- ParamN := P.ParamN; -- if Enqueued (Bnn) then -- <abortable-statements> -- end if; -- at end -- _clean; -- end; -- exception -- when Abort_Signal => Abort_Undefer; -- end; -- if not Cancelled (Bnn) then -- <triggering-statements> -- end if; -- elsif C = POK_Task_Entry then -- declare -- procedure _clean is -- begin -- Cancel_Task_Entry_Call (U); -- end _clean; -- begin -- Abort_Defer; -- _Disp_Asynchronous_Select -- (<object>, S, P'address, Bnn, B); -- Param1 := P.Param1; -- ... -- ParamN := P.ParamN; -- begin -- begin -- Abort_Undefer; -- <abortable-statements> -- at end -- _clean; -- end; -- exception -- when Abort_Signal => Abort_Undefer; -- end; -- if not U then -- <triggering-statements> -- end if; -- end; -- else -- <dispatching-call>; -- <triggering-statements> -- end if; -- end if; -- end; -- The job is to convert this to the asynchronous form -- If the trigger is a delay statement, it will have been expanded into a -- call to one of the GNARL delay procedures. This routine will convert -- this into a protected entry call on a delay object and then continue -- processing as for a protected entry call trigger. This requires -- declaring a Delay_Block object and adding a pointer to this object to -- the parameter list of the delay procedure to form the parameter list of -- the entry call. This object is used by the runtime to queue the delay -- request. -- For a description of the use of P and the assignments after the -- call, see Expand_N_Entry_Call_Statement. procedure Expand_N_Asynchronous_Select (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Abrt : constant Node_Id := Abortable_Part (N); Astats : constant List_Id := Statements (Abrt); Trig : constant Node_Id := Triggering_Alternative (N); Tstats : constant List_Id := Statements (Trig); Abort_Block_Ent : Entity_Id; Abortable_Block : Node_Id; Actuals : List_Id; Blk_Ent : Entity_Id; Blk_Typ : Entity_Id; Call : Node_Id; Call_Ent : Entity_Id; Cancel_Param : Entity_Id; Cleanup_Block : Node_Id; Cleanup_Block_Ent : Entity_Id; Cleanup_Stmts : List_Id; Conc_Typ_Stmts : List_Id; Concval : Node_Id; Dblock_Ent : Entity_Id; Decl : Node_Id; Decls : List_Id; Ecall : Node_Id; Ename : Node_Id; Enqueue_Call : Node_Id; Formals : List_Id; Hdle : List_Id; Index : Node_Id; Lim_Typ_Stmts : List_Id; N_Orig : Node_Id; Obj : Entity_Id; Param : Node_Id; Params : List_Id; Pdef : Entity_Id; ProtE_Stmts : List_Id; ProtP_Stmts : List_Id; Stmt : Node_Id; Stmts : List_Id; Target_Undefer : RE_Id; TaskE_Stmts : List_Id; Undefer_Args : List_Id := No_List; B : Entity_Id; -- Call status flag Bnn : Entity_Id; -- Communication block C : Entity_Id; -- Call kind K : Entity_Id; -- Tagged kind P : Entity_Id; -- Parameter block S : Entity_Id; -- Primitive operation slot T : Entity_Id; -- Additional status flag begin Blk_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('A')); Ecall := Triggering_Statement (Trig); -- The arguments in the call may require dynamic allocation, and the -- call statement may have been transformed into a block. The block -- may contain additional declarations for internal entities, and the -- original call is found by sequential search. if Nkind (Ecall) = N_Block_Statement then Ecall := First (Statements (Handled_Statement_Sequence (Ecall))); while Nkind (Ecall) /= N_Procedure_Call_Statement and then Nkind (Ecall) /= N_Entry_Call_Statement loop Next (Ecall); end loop; end if; -- This is either a dispatching call or a delay statement used as a -- trigger which was expanded into a procedure call. if Nkind (Ecall) = N_Procedure_Call_Statement then if Ada_Version >= Ada_05 and then (No (Original_Node (Ecall)) or else (Nkind (Original_Node (Ecall)) /= N_Delay_Relative_Statement and then Nkind (Original_Node (Ecall)) /= N_Delay_Until_Statement)) then Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals); Decls := New_List; Stmts := New_List; -- Call status flag processing, generate: -- B : Boolean := False; B := Build_B (Loc, Decls); -- Communication block processing, generate: -- Bnn : Communication_Block; Bnn := Make_Defining_Identifier (Loc, New_Internal_Name ('B')); Append_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => Bnn, Object_Definition => New_Reference_To (RTE (RE_Communication_Block), Loc))); -- Call kind processing, generate: -- C : Ada.Tags.Prim_Op_Kind; C := Build_C (Loc, Decls); -- Tagged kind processing, generate: -- K : Ada.Tags.Tagged_Kind := -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>)); K := Build_K (Loc, Decls, Obj); -- Parameter block processing Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls); P := Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts); -- Dispatch table slot processing, generate: -- S : Integer; S := Build_S (Loc, Decls); -- Additional status flag processing, generate: T := Make_Defining_Identifier (Loc, New_Internal_Name ('T')); Append_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => T, Object_Definition => New_Reference_To (Standard_Boolean, Loc))); -- --------------------------------------------------------------- -- Protected entry handling -- Generate: -- Param1 := P.Param1; -- ... -- ParamN := P.ParamN; Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals); -- Generate: -- _Disp_Asynchronous_Select (<object>, S, P'address, Bnn, B); Prepend_To (Cleanup_Stmts, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( Find_Prim_Op (Etype (Etype (Obj)), Name_uDisp_Asynchronous_Select), Loc), Parameter_Associations => New_List ( New_Copy_Tree (Obj), New_Reference_To (S, Loc), Make_Attribute_Reference (Loc, Prefix => New_Reference_To (P, Loc), Attribute_Name => Name_Address), New_Reference_To (Bnn, Loc), New_Reference_To (B, Loc)))); -- Generate: -- if Enqueued (Bnn) then -- <abortable-statements> -- end if; Append_To (Cleanup_Stmts, Make_If_Statement (Loc, Condition => Make_Function_Call (Loc, Name => New_Reference_To (RTE (RE_Enqueued), Loc), Parameter_Associations => New_List ( New_Reference_To (Bnn, Loc))), Then_Statements => New_Copy_List_Tree (Astats))); -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions -- will then generate a _clean for the communication block Bnn. -- Generate: -- declare -- procedure _clean is -- begin -- if Enqueued (Bnn) then -- Cancel_Protected_Entry_Call (Bnn); -- end if; -- end _clean; -- begin -- Cleanup_Stmts -- at end -- _clean; -- end; Cleanup_Block_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('C')); Cleanup_Block := Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn); -- Wrap the cleanup block in an exception handling block -- Generate: -- begin -- Cleanup_Block -- exception -- when Abort_Signal => Abort_Undefer; -- end; Abort_Block_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('A')); ProtE_Stmts := New_List ( Make_Implicit_Label_Declaration (Loc, Defining_Identifier => Abort_Block_Ent), Build_Abort_Block (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block)); -- Generate: -- if not Cancelled (Bnn) then -- <triggering-statements> -- end if; Append_To (ProtE_Stmts, Make_If_Statement (Loc, Condition => Make_Op_Not (Loc, Right_Opnd => Make_Function_Call (Loc, Name => New_Reference_To (RTE (RE_Cancelled), Loc), Parameter_Associations => New_List ( New_Reference_To (Bnn, Loc)))), Then_Statements => New_Copy_List_Tree (Tstats))); -- --------------------------------------------------------------- -- Task entry handling -- Generate: -- Param1 := P.Param1; -- ... -- ParamN := P.ParamN; TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals); -- Generate: -- _Disp_Asynchronous_Select (<object>, S, P'address, Bnn, B); Prepend_To (TaskE_Stmts, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( Find_Prim_Op (Etype (Etype (Obj)), Name_uDisp_Asynchronous_Select), Loc), Parameter_Associations => New_List ( New_Copy_Tree (Obj), New_Reference_To (S, Loc), Make_Attribute_Reference (Loc, Prefix => New_Reference_To (P, Loc), Attribute_Name => Name_Address), New_Reference_To (Bnn, Loc), New_Reference_To (B, Loc)))); -- Generate: -- Abort_Defer; Prepend_To (TaskE_Stmts, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Abort_Defer), Loc), Parameter_Associations => No_List)); -- Generate: -- Abort_Undefer; -- <abortable-statements> Cleanup_Stmts := New_Copy_List_Tree (Astats); Prepend_To (Cleanup_Stmts, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc), Parameter_Associations => No_List)); -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions -- will generate a _clean for the additional status flag. -- Generate: -- declare -- procedure _clean is -- begin -- Cancel_Task_Entry_Call (U); -- end _clean; -- begin -- Cleanup_Stmts -- at end -- _clean; -- end; Cleanup_Block_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('C')); Cleanup_Block := Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T); -- Wrap the cleanup block in an exception handling block -- Generate: -- begin -- Cleanup_Block -- exception -- when Abort_Signal => Abort_Undefer; -- end; Abort_Block_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('A')); Append_To (TaskE_Stmts, Make_Implicit_Label_Declaration (Loc, Defining_Identifier => Abort_Block_Ent)); Append_To (TaskE_Stmts, Build_Abort_Block (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block)); -- Generate: -- if not T then -- <triggering-statements> -- end if; Append_To (TaskE_Stmts, Make_If_Statement (Loc, Condition => Make_Op_Not (Loc, Right_Opnd => New_Reference_To (T, Loc)), Then_Statements => New_Copy_List_Tree (Tstats))); ------------------------------------------------------------------- -- Protected procedure handling -- Generate: -- <dispatching-call>; -- <triggering-statements> ProtP_Stmts := New_Copy_List_Tree (Tstats); Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall)); -- Generate: -- S := Ada.Tags.Get_Offset_Index ( -- Ada.Tags.Tag (<object>), DT_Position (Call_Ent)); Conc_Typ_Stmts := New_List ( Build_S_Assignment (Loc, S, Obj, Call_Ent)); -- Generate: -- _Disp_Get_Prim_Op_Kind (<object>, S, C); Append_To (Conc_Typ_Stmts, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( Find_Prim_Op (Etype (Etype (Obj)), Name_uDisp_Get_Prim_Op_Kind), Loc), Parameter_Associations => New_List ( New_Copy_Tree (Obj), New_Reference_To (S, Loc), New_Reference_To (C, Loc)))); -- Generate: -- if C = POK_Procedure_Entry then -- ProtE_Stmts -- elsif C = POK_Task_Entry then -- TaskE_Stmts -- else -- ProtP_Stmts -- end if; Append_To (Conc_Typ_Stmts, Make_If_Statement (Loc, Condition => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (C, Loc), Right_Opnd => New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)), Then_Statements => ProtE_Stmts, Elsif_Parts => New_List ( Make_Elsif_Part (Loc, Condition => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (C, Loc), Right_Opnd => New_Reference_To (RTE (RE_POK_Task_Entry), Loc)), Then_Statements => TaskE_Stmts)), Else_Statements => ProtP_Stmts)); -- Generate: -- <dispatching-call>; -- <triggering-statements> Lim_Typ_Stmts := New_Copy_List_Tree (Tstats); Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall)); -- Generate: -- if K = Ada.Tags.TK_Limited_Tagged then -- Lim_Typ_Stmts -- else -- Conc_Typ_Stmts -- end if; Append_To (Stmts, Make_If_Statement (Loc, Condition => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (K, Loc), Right_Opnd => New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)), Then_Statements => Lim_Typ_Stmts, Else_Statements => Conc_Typ_Stmts)); Rewrite (N, Make_Block_Statement (Loc, Declarations => Decls, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Stmts))); Analyze (N); return; -- Delay triggering statement processing else -- Add a Delay_Block object to the parameter list of the delay -- procedure to form the parameter list of the Wait entry call. Dblock_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('D')); Pdef := Entity (Name (Ecall)); if Is_RTE (Pdef, RO_CA_Delay_For) then Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_Duration), Loc); elsif Is_RTE (Pdef, RO_CA_Delay_Until) then Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_Calendar), Loc); else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until)); Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc); end if; Append_To (Parameter_Associations (Ecall), Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Dblock_Ent, Loc), Attribute_Name => Name_Unchecked_Access)); -- Create the inner block to protect the abortable part Hdle := New_List ( Make_Exception_Handler (Loc, Exception_Choices => New_List (New_Reference_To (Stand.Abort_Signal, Loc)), Statements => New_List ( Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc))))); Prepend_To (Astats, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc))); Abortable_Block := Make_Block_Statement (Loc, Identifier => New_Reference_To (Blk_Ent, Loc), Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => Astats), Has_Created_Identifier => True, Is_Asynchronous_Call_Block => True); -- Append call to if Enqueue (When, DB'Unchecked_Access) then Rewrite (Ecall, Make_Implicit_If_Statement (N, Condition => Make_Function_Call (Loc, Name => Enqueue_Call, Parameter_Associations => Parameter_Associations (Ecall)), Then_Statements => New_List (Make_Block_Statement (Loc, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List ( Make_Implicit_Label_Declaration (Loc, Defining_Identifier => Blk_Ent, Label_Construct => Abortable_Block), Abortable_Block), Exception_Handlers => Hdle))))); Stmts := New_List (Ecall); -- Construct statement sequence for new block Append_To (Stmts, Make_Implicit_If_Statement (N, Condition => Make_Function_Call (Loc, Name => New_Reference_To ( RTE (RE_Timed_Out), Loc), Parameter_Associations => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Dblock_Ent, Loc), Attribute_Name => Name_Unchecked_Access))), Then_Statements => Tstats)); -- The result is the new block Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent); Rewrite (N, Make_Block_Statement (Loc, Declarations => New_List ( Make_Object_Declaration (Loc, Defining_Identifier => Dblock_Ent, Aliased_Present => True, Object_Definition => New_Reference_To ( RTE (RE_Delay_Block), Loc))), Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Stmts))); Analyze (N); return; end if; else N_Orig := N; end if; Extract_Entry (Ecall, Concval, Ename, Index); Build_Simple_Entry_Call (Ecall, Concval, Ename, Index); Stmts := Statements (Handled_Statement_Sequence (Ecall)); Decls := Declarations (Ecall); if Is_Protected_Type (Etype (Concval)) then -- Get the declarations of the block expanded from the entry call Decl := First (Decls); while Present (Decl) and then (Nkind (Decl) /= N_Object_Declaration or else not Is_RTE (Etype (Object_Definition (Decl)), RE_Communication_Block)) loop Next (Decl); end loop; pragma Assert (Present (Decl)); Cancel_Param := Defining_Identifier (Decl); -- Change the mode of the Protected_Entry_Call call -- Protected_Entry_Call ( -- Object => po._object'Access, -- E => <entry index>; -- Uninterpreted_Data => P'Address; -- Mode => Asynchronous_Call; -- Block => Bnn); Stmt := First (Stmts); -- Skip assignments to temporaries created for in-out parameters -- This makes unwarranted assumptions about the shape of the expanded -- tree for the call, and should be cleaned up ??? while Nkind (Stmt) /= N_Procedure_Call_Statement loop Next (Stmt); end loop; Call := Stmt; Param := First (Parameter_Associations (Call)); while Present (Param) and then not Is_RTE (Etype (Param), RE_Call_Modes) loop Next (Param); end loop; pragma Assert (Present (Param)); Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc)); Analyze (Param); -- Append an if statement to execute the abortable part -- Generate: -- if Enqueued (Bnn) then Append_To (Stmts, Make_Implicit_If_Statement (N, Condition => Make_Function_Call (Loc, Name => New_Reference_To ( RTE (RE_Enqueued), Loc), Parameter_Associations => New_List ( New_Reference_To (Cancel_Param, Loc))), Then_Statements => Astats)); Abortable_Block := Make_Block_Statement (Loc, Identifier => New_Reference_To (Blk_Ent, Loc), Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts), Has_Created_Identifier => True, Is_Asynchronous_Call_Block => True); -- For the JVM call Update_Exception instead of Abort_Undefer. -- See 4jexcept.ads for an explanation. if Hostparm.Java_VM then Target_Undefer := RE_Update_Exception; Undefer_Args := New_List (Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Current_Target_Exception), Loc))); else Target_Undefer := RE_Abort_Undefer; end if; Stmts := New_List ( Make_Block_Statement (Loc, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List ( Make_Implicit_Label_Declaration (Loc, Defining_Identifier => Blk_Ent, Label_Construct => Abortable_Block), Abortable_Block), -- exception Exception_Handlers => New_List ( Make_Exception_Handler (Loc, -- when Abort_Signal => -- Abort_Undefer.all; Exception_Choices => New_List (New_Reference_To (Stand.Abort_Signal, Loc)), Statements => New_List ( Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( RTE (Target_Undefer), Loc), Parameter_Associations => Undefer_Args)))))), -- if not Cancelled (Bnn) then -- triggered statements -- end if; Make_Implicit_If_Statement (N, Condition => Make_Op_Not (Loc, Right_Opnd => Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc), Parameter_Associations => New_List ( New_Occurrence_Of (Cancel_Param, Loc)))), Then_Statements => Tstats)); -- Asynchronous task entry call else if No (Decls) then Decls := New_List; end if; B := Make_Defining_Identifier (Loc, Name_uB); -- Insert declaration of B in declarations of existing block Prepend_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => B, Object_Definition => New_Reference_To (Standard_Boolean, Loc))); Cancel_Param := Make_Defining_Identifier (Loc, Name_uC); -- Insert declaration of C in declarations of existing block Prepend_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => Cancel_Param, Object_Definition => New_Reference_To (Standard_Boolean, Loc))); -- Remove and save the call to Call_Simple Stmt := First (Stmts); -- Skip assignments to temporaries created for in-out parameters. -- This makes unwarranted assumptions about the shape of the expanded -- tree for the call, and should be cleaned up ??? while Nkind (Stmt) /= N_Procedure_Call_Statement loop Next (Stmt); end loop; Call := Stmt; -- Create the inner block to protect the abortable part Hdle := New_List ( Make_Exception_Handler (Loc, Exception_Choices => New_List (New_Reference_To (Stand.Abort_Signal, Loc)), Statements => New_List ( Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc))))); Prepend_To (Astats, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc))); Abortable_Block := Make_Block_Statement (Loc, Identifier => New_Reference_To (Blk_Ent, Loc), Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => Astats), Has_Created_Identifier => True, Is_Asynchronous_Call_Block => True); Insert_After (Call, Make_Block_Statement (Loc, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List ( Make_Implicit_Label_Declaration (Loc, Defining_Identifier => Blk_Ent, Label_Construct => Abortable_Block), Abortable_Block), Exception_Handlers => Hdle))); -- Create new call statement Params := Parameter_Associations (Call); Append_To (Params, New_Reference_To (RTE (RE_Asynchronous_Call), Loc)); Append_To (Params, New_Reference_To (B, Loc)); Rewrite (Call, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc), Parameter_Associations => Params)); -- Construct statement sequence for new block Append_To (Stmts, Make_Implicit_If_Statement (N, Condition => Make_Op_Not (Loc, New_Reference_To (Cancel_Param, Loc)), Then_Statements => Tstats)); -- Protected the call against abort Prepend_To (Stmts, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Abort_Defer), Loc), Parameter_Associations => Empty_List)); end if; Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param); -- The result is the new block Rewrite (N_Orig, Make_Block_Statement (Loc, Declarations => Decls, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Stmts))); Analyze (N_Orig); end Expand_N_Asynchronous_Select; ------------------------------------- -- Expand_N_Conditional_Entry_Call -- ------------------------------------- -- The conditional task entry call is converted to a call to -- Task_Entry_Call: -- declare -- B : Boolean; -- P : parms := (parm, parm, parm); -- begin -- Task_Entry_Call -- (acceptor-task, -- entry-index, -- P'Address, -- Conditional_Call, -- B); -- parm := P.param; -- parm := P.param; -- ... -- if B then -- normal-statements -- else -- else-statements -- end if; -- end; -- For a description of the use of P and the assignments after the -- call, see Expand_N_Entry_Call_Statement. Note that the entry call -- of the conditional entry call has already been expanded (by the -- Expand_N_Entry_Call_Statement procedure) as follows: -- declare -- P : parms := (parm, parm, parm); -- begin -- ... info for in-out parameters -- Call_Simple (acceptor-task, entry-index, P'Address); -- parm := P.param; -- parm := P.param; -- ... -- end; -- so the task at hand is to convert the latter expansion into the former -- The conditional protected entry call is converted to a call to -- Protected_Entry_Call: -- declare -- P : parms := (parm, parm, parm); -- Bnn : Communications_Block; -- begin -- Protected_Entry_Call ( -- Object => po._object'Access, -- E => <entry index>; -- Uninterpreted_Data => P'Address; -- Mode => Conditional_Call; -- Block => Bnn); -- parm := P.param; -- parm := P.param; -- ... -- if Cancelled (Bnn) then -- else-statements -- else -- normal-statements -- end if; -- end; -- As for tasks, the entry call of the conditional entry call has -- already been expanded (by the Expand_N_Entry_Call_Statement procedure) -- as follows: -- declare -- P : E1_Params := (param, param, param); -- Bnn : Communications_Block; -- begin -- Protected_Entry_Call ( -- Object => po._object'Access, -- E => <entry index>; -- Uninterpreted_Data => P'Address; -- Mode => Simple_Call; -- Block => Bnn); -- parm := P.param; -- parm := P.param; -- ... -- end; -- Ada 2005 (AI-345): A dispatching conditional entry call is converted -- into: -- declare -- B : Boolean := False; -- C : Ada.Tags.Prim_Op_Kind; -- K : Ada.Tags.Tagged_Kind := -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>)); -- P : Parameters := (Param1 .. ParamN); -- S : Integer; -- begin -- if K = Ada.Tags.TK_Limited_Tagged then -- <dispatching-call>; -- <triggering-statements> -- else -- S := Ada.Tags.Get_Offset_Index (Ada.Tags.Tag (<object>), -- DT_Position (<dispatching-call>)); -- _Disp_Conditional_Select (<object>, S, P'address, C, B); -- if C = POK_Protected_Entry -- or else C = POK_Task_Entry -- then -- Param1 := P.Param1; -- ... -- ParamN := P.ParamN; -- end if; -- if B then -- if C = POK_Procedure -- or else C = POK_Protected_Procedure -- or else C = POK_Task_Procedure -- then -- <dispatching-call>; -- end if; -- <triggering-statements> -- else -- <else-statements> -- end if; -- end if; -- end; procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Alt : constant Node_Id := Entry_Call_Alternative (N); Blk : Node_Id := Entry_Call_Statement (Alt); Transient_Blk : Node_Id; Actuals : List_Id; Blk_Typ : Entity_Id; Call : Node_Id; Call_Ent : Entity_Id; Conc_Typ_Stmts : List_Id; Decl : Node_Id; Decls : List_Id; Formals : List_Id; Lim_Typ_Stmts : List_Id; N_Stats : List_Id; Obj : Entity_Id; Param : Node_Id; Params : List_Id; Stmt : Node_Id; Stmts : List_Id; Unpack : List_Id; B : Entity_Id; -- Call status flag C : Entity_Id; -- Call kind K : Entity_Id; -- Tagged kind P : Entity_Id; -- Parameter block S : Entity_Id; -- Primitive operation slot begin if Ada_Version >= Ada_05 and then Nkind (Blk) = N_Procedure_Call_Statement then Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals); Decls := New_List; Stmts := New_List; -- Call status flag processing, generate: -- B : Boolean := False; B := Build_B (Loc, Decls); -- Call kind processing, generate: -- C : Ada.Tags.Prim_Op_Kind; C := Build_C (Loc, Decls); -- Tagged kind processing, generate: -- K : Ada.Tags.Tagged_Kind := -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>)); K := Build_K (Loc, Decls, Obj); -- Parameter block processing Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls); P := Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts); -- Dispatch table slot processing, generate: -- S : Integer; S := Build_S (Loc, Decls); -- Generate: -- S := Ada.Tags.Get_Offset_Index ( -- Ada.Tags.Tag (<object>), DT_Position (Call_Ent)); Conc_Typ_Stmts := New_List ( Build_S_Assignment (Loc, S, Obj, Call_Ent)); -- Generate: -- _Disp_Conditional_Select (<object>, S, P'address, C, B); Append_To (Conc_Typ_Stmts, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( Find_Prim_Op (Etype (Etype (Obj)), Name_uDisp_Conditional_Select), Loc), Parameter_Associations => New_List ( New_Copy_Tree (Obj), New_Reference_To (S, Loc), Make_Attribute_Reference (Loc, Prefix => New_Reference_To (P, Loc), Attribute_Name => Name_Address), New_Reference_To (C, Loc), New_Reference_To (B, Loc)))); -- Generate: -- if C = POK_Protected_Entry -- or else C = POK_Task_Entry -- then -- Param1 := P.Param1; -- ... -- ParamN := P.ParamN; -- end if; Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals); -- Generate the if statement only when the packed parameters need -- explicit assignments to their corresponding actuals. if Present (Unpack) then Append_To (Conc_Typ_Stmts, Make_If_Statement (Loc, Condition => Make_Or_Else (Loc, Left_Opnd => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (C, Loc), Right_Opnd => New_Reference_To (RTE ( RE_POK_Protected_Entry), Loc)), Right_Opnd => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (C, Loc), Right_Opnd => New_Reference_To (RTE (RE_POK_Task_Entry), Loc))), Then_Statements => Unpack)); end if; -- Generate: -- if B then -- if C = POK_Procedure -- or else C = POK_Protected_Procedure -- or else C = POK_Task_Procedure -- then -- <dispatching-call> -- end if; -- <normal-statements> -- else -- <else-statements> -- end if; N_Stats := New_Copy_List_Tree (Statements (Alt)); Prepend_To (N_Stats, Make_If_Statement (Loc, Condition => Make_Or_Else (Loc, Left_Opnd => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (C, Loc), Right_Opnd => New_Reference_To (RTE (RE_POK_Procedure), Loc)), Right_Opnd => Make_Or_Else (Loc, Left_Opnd => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (C, Loc), Right_Opnd => New_Reference_To (RTE ( RE_POK_Protected_Procedure), Loc)), Right_Opnd => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (C, Loc), Right_Opnd => New_Reference_To (RTE ( RE_POK_Task_Procedure), Loc)))), Then_Statements => New_List (Blk))); Append_To (Conc_Typ_Stmts, Make_If_Statement (Loc, Condition => New_Reference_To (B, Loc), Then_Statements => N_Stats, Else_Statements => Else_Statements (N))); -- Generate: -- <dispatching-call>; -- <triggering-statements> Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt)); Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk)); -- Generate: -- if K = Ada.Tags.TK_Limited_Tagged then -- Lim_Typ_Stmts -- else -- Conc_Typ_Stmts -- end if; Append_To (Stmts, Make_If_Statement (Loc, Condition => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (K, Loc), Right_Opnd => New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)), Then_Statements => Lim_Typ_Stmts, Else_Statements => Conc_Typ_Stmts)); Rewrite (N, Make_Block_Statement (Loc, Declarations => Decls, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Stmts))); -- As described above, The entry alternative is transformed into a -- block that contains the gnulli call, and possibly assignment -- statements for in-out parameters. The gnulli call may itself be -- rewritten into a transient block if some unconstrained parameters -- require it. We need to retrieve the call to complete its parameter -- list. else Transient_Blk := First_Real_Statement (Handled_Statement_Sequence (Blk)); if Present (Transient_Blk) and then Nkind (Transient_Blk) = N_Block_Statement then Blk := Transient_Blk; end if; Stmts := Statements (Handled_Statement_Sequence (Blk)); Stmt := First (Stmts); while Nkind (Stmt) /= N_Procedure_Call_Statement loop Next (Stmt); end loop; Call := Stmt; Params := Parameter_Associations (Call); if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then -- Substitute Conditional_Entry_Call for Simple_Call parameter Param := First (Params); while Present (Param) and then not Is_RTE (Etype (Param), RE_Call_Modes) loop Next (Param); end loop; pragma Assert (Present (Param)); Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc)); Analyze (Param); -- Find the Communication_Block parameter for the call to the -- Cancelled function. Decl := First (Declarations (Blk)); while Present (Decl) and then not Is_RTE (Etype (Object_Definition (Decl)), RE_Communication_Block) loop Next (Decl); end loop; -- Add an if statement to execute the else part if the call -- does not succeed (as indicated by the Cancelled predicate). Append_To (Stmts, Make_Implicit_If_Statement (N, Condition => Make_Function_Call (Loc, Name => New_Reference_To (RTE (RE_Cancelled), Loc), Parameter_Associations => New_List ( New_Reference_To (Defining_Identifier (Decl), Loc))), Then_Statements => Else_Statements (N), Else_Statements => Statements (Alt))); else B := Make_Defining_Identifier (Loc, Name_uB); -- Insert declaration of B in declarations of existing block if No (Declarations (Blk)) then Set_Declarations (Blk, New_List); end if; Prepend_To (Declarations (Blk), Make_Object_Declaration (Loc, Defining_Identifier => B, Object_Definition => New_Reference_To (Standard_Boolean, Loc))); -- Create new call statement Append_To (Params, New_Reference_To (RTE (RE_Conditional_Call), Loc)); Append_To (Params, New_Reference_To (B, Loc)); Rewrite (Call, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc), Parameter_Associations => Params)); -- Construct statement sequence for new block Append_To (Stmts, Make_Implicit_If_Statement (N, Condition => New_Reference_To (B, Loc), Then_Statements => Statements (Alt), Else_Statements => Else_Statements (N))); end if; -- The result is the new block Rewrite (N, Make_Block_Statement (Loc, Declarations => Declarations (Blk), Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Stmts))); end if; Analyze (N); end Expand_N_Conditional_Entry_Call; --------------------------------------- -- Expand_N_Delay_Relative_Statement -- --------------------------------------- -- Delay statement is implemented as a procedure call to Delay_For -- defined in Ada.Calendar.Delays in order to reduce the overhead of -- simple delays imposed by the use of Protected Objects. procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); begin Rewrite (N, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc), Parameter_Associations => New_List (Expression (N)))); Analyze (N); end Expand_N_Delay_Relative_Statement; ------------------------------------ -- Expand_N_Delay_Until_Statement -- ------------------------------------ -- Delay Until statement is implemented as a procedure call to -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays. procedure Expand_N_Delay_Until_Statement (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Typ : Entity_Id; begin if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then Typ := RTE (RO_CA_Delay_Until); else Typ := RTE (RO_RT_Delay_Until); end if; Rewrite (N, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (Typ, Loc), Parameter_Associations => New_List (Expression (N)))); Analyze (N); end Expand_N_Delay_Until_Statement; ------------------------- -- Expand_N_Entry_Body -- ------------------------- procedure Expand_N_Entry_Body (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Dec : constant Node_Id := Parent (Current_Scope); Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N); Index_Spec : constant Node_Id := Entry_Index_Specification (Ent_Formals); Next_Op : Node_Id; First_Decl : constant Node_Id := First (Declarations (N)); Index_Decl : List_Id; begin -- Add the renamings for private declarations and discriminants Add_Discriminal_Declarations (Declarations (N), Defining_Identifier (Dec), Name_uObject, Loc); Add_Private_Declarations (Declarations (N), Defining_Identifier (Dec), Name_uObject, Loc); if Present (Index_Spec) then Index_Decl := Index_Constant_Declaration (N, Defining_Identifier (Index_Spec), Defining_Identifier (Dec)); -- If the entry has local declarations, insert index declaration -- before them, because the index may be used therein. if Present (First_Decl) then Insert_List_Before (First_Decl, Index_Decl); else Append_List_To (Declarations (N), Index_Decl); end if; end if; -- Associate privals and discriminals with the next protected operation -- body to be expanded. These are used to expand references to private -- data objects and discriminants, respectively. Next_Op := Next_Protected_Operation (N); if Present (Next_Op) then Set_Privals (Dec, Next_Op, Loc); Set_Discriminals (Dec); end if; end Expand_N_Entry_Body; ----------------------------------- -- Expand_N_Entry_Call_Statement -- ----------------------------------- -- An entry call is expanded into GNARLI calls to implement -- a simple entry call (see Build_Simple_Entry_Call). procedure Expand_N_Entry_Call_Statement (N : Node_Id) is Concval : Node_Id; Ename : Node_Id; Index : Node_Id; begin if No_Run_Time_Mode then Error_Msg_CRT ("entry call", N); return; end if; -- If this entry call is part of an asynchronous select, don't expand it -- here; it will be expanded with the select statement. Don't expand -- timed entry calls either, as they are translated into asynchronous -- entry calls. -- ??? This whole approach is questionable; it may be better to go back -- to allowing the expansion to take place and then attempting to fix it -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out -- whether the expanded call is on a task or protected entry. if (Nkind (Parent (N)) /= N_Triggering_Alternative or else N /= Triggering_Statement (Parent (N))) and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative or else N /= Entry_Call_Statement (Parent (N)) or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call) then Extract_Entry (N, Concval, Ename, Index); Build_Simple_Entry_Call (N, Concval, Ename, Index); end if; end Expand_N_Entry_Call_Statement; -------------------------------- -- Expand_N_Entry_Declaration -- -------------------------------- -- If there are parameters, then first, each of the formals is marked by -- setting Is_Entry_Formal. Next a record type is built which is used to -- hold the parameter values. The name of this record type is entryP where -- entry is the name of the entry, with an additional corresponding access -- type called entryPA. The record type has matching components for each -- formal (the component names are the same as the formal names). For -- elementary types, the component type matches the formal type. For -- composite types, an access type is declared (with the name formalA) -- which designates the formal type, and the type of the component is this -- access type. Finally the Entry_Component of each formal is set to -- reference the corresponding record component. procedure Expand_N_Entry_Declaration (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Entry_Ent : constant Entity_Id := Defining_Identifier (N); Components : List_Id; Formal : Node_Id; Ftype : Entity_Id; Last_Decl : Node_Id; Component : Entity_Id; Ctype : Entity_Id; Decl : Node_Id; Rec_Ent : Entity_Id; Acc_Ent : Entity_Id; begin Formal := First_Formal (Entry_Ent); Last_Decl := N; -- Most processing is done only if parameters are present if Present (Formal) then Components := New_List; -- Loop through formals while Present (Formal) loop Set_Is_Entry_Formal (Formal); Component := Make_Defining_Identifier (Sloc (Formal), Chars (Formal)); Set_Entry_Component (Formal, Component); Set_Entry_Formal (Component, Formal); Ftype := Etype (Formal); -- Declare new access type and then append Ctype := Make_Defining_Identifier (Loc, New_Internal_Name ('A')); Decl := Make_Full_Type_Declaration (Loc, Defining_Identifier => Ctype, Type_Definition => Make_Access_To_Object_Definition (Loc, All_Present => True, Constant_Present => Ekind (Formal) = E_In_Parameter, Subtype_Indication => New_Reference_To (Ftype, Loc))); Insert_After (Last_Decl, Decl); Last_Decl := Decl; Append_To (Components, Make_Component_Declaration (Loc, Defining_Identifier => Component, Component_Definition => Make_Component_Definition (Loc, Aliased_Present => False, Subtype_Indication => New_Reference_To (Ctype, Loc)))); Next_Formal_With_Extras (Formal); end loop; -- Create the Entry_Parameter_Record declaration Rec_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('P')); Decl := Make_Full_Type_Declaration (Loc, Defining_Identifier => Rec_Ent, Type_Definition => Make_Record_Definition (Loc, Component_List => Make_Component_List (Loc, Component_Items => Components))); Insert_After (Last_Decl, Decl); Last_Decl := Decl; -- Construct and link in the corresponding access type Acc_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('A')); Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent); Decl := Make_Full_Type_Declaration (Loc, Defining_Identifier => Acc_Ent, Type_Definition => Make_Access_To_Object_Definition (Loc, All_Present => True, Subtype_Indication => New_Reference_To (Rec_Ent, Loc))); Insert_After (Last_Decl, Decl); Last_Decl := Decl; end if; end Expand_N_Entry_Declaration; ----------------------------- -- Expand_N_Protected_Body -- ----------------------------- -- Protected bodies are expanded to the completion of the subprograms -- created for the corresponding protected type. These are a protected and -- unprotected version of each protected subprogram in the object, a -- function to calculate each entry barrier, and a procedure to execute the -- sequence of statements of each protected entry body. For example, for -- protected type ptype: -- function entB -- (O : System.Address; -- E : Protected_Entry_Index) -- return Boolean -- is -- <discriminant renamings> -- <private object renamings> -- begin -- return <barrier expression>; -- end entB; -- procedure pprocN (_object : in out poV;...) is -- <discriminant renamings> -- <private object renamings> -- begin -- <sequence of statements> -- end pprocN; -- procedure pprocP (_object : in out poV;...) is -- procedure _clean is -- Pn : Boolean; -- begin -- ptypeS (_object, Pn); -- Unlock (_object._object'Access); -- Abort_Undefer.all; -- end _clean; -- begin -- Abort_Defer.all; -- Lock (_object._object'Access); -- pprocN (_object;...); -- at end -- _clean; -- end pproc; -- function pfuncN (_object : poV;...) return Return_Type is -- <discriminant renamings> -- <private object renamings> -- begin -- <sequence of statements> -- end pfuncN; -- function pfuncP (_object : poV) return Return_Type is -- procedure _clean is -- begin -- Unlock (_object._object'Access); -- Abort_Undefer.all; -- end _clean; -- begin -- Abort_Defer.all; -- Lock (_object._object'Access); -- return pfuncN (_object); -- at end -- _clean; -- end pfunc; -- procedure entE -- (O : System.Address; -- P : System.Address; -- E : Protected_Entry_Index) -- is -- <discriminant renamings> -- <private object renamings> -- type poVP is access poV; -- _Object : ptVP := ptVP!(O); -- begin -- begin -- <statement sequence> -- Complete_Entry_Body (_Object._Object); -- exception -- when all others => -- Exceptional_Complete_Entry_Body ( -- _Object._Object, Get_GNAT_Exception); -- end; -- end entE; -- The type poV is the record created for the protected type to hold -- the state of the protected object. procedure Expand_N_Protected_Body (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Pid : constant Entity_Id := Corresponding_Spec (N); Has_Entries : Boolean := False; Op_Decl : Node_Id; Op_Body : Node_Id; Op_Id : Entity_Id; Disp_Op_Body : Node_Id; New_Op_Body : Node_Id; Current_Node : Node_Id; Num_Entries : Natural := 0; function Build_Dispatching_Subprogram_Body (N : Node_Id; Pid : Node_Id; Prot_Bod : Node_Id) return Node_Id; -- Build a dispatching version of the protected subprogram body. The -- newly generated subprogram contains a call to the original protected -- body. The following code is generated: -- -- function <protected-function-name> (Param1 .. ParamN) return -- <return-type> is -- begin -- return <protected-function-name>P (Param1 .. ParamN); -- end <protected-function-name>; -- -- or -- -- procedure <protected-procedure-name> (Param1 .. ParamN) is -- begin -- <protected-procedure-name>P (Param1 .. ParamN); -- end <protected-procedure-name> --------------------------------------- -- Build_Dispatching_Subprogram_Body -- --------------------------------------- function Build_Dispatching_Subprogram_Body (N : Node_Id; Pid : Node_Id; Prot_Bod : Node_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (N); Actuals : List_Id; Formal : Node_Id; Spec : Node_Id; Stmts : List_Id; begin -- Generate a specification without a letter suffix in order to -- override an interface function or procedure. Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode); -- The formal parameters become the actuals of the protected -- function or procedure call. Actuals := New_List; Formal := First (Parameter_Specifications (Spec)); while Present (Formal) loop Append_To (Actuals, Make_Identifier (Loc, Chars (Defining_Identifier (Formal)))); Next (Formal); end loop; if Nkind (Spec) = N_Procedure_Specification then Stmts := New_List ( Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (Corresponding_Spec (Prot_Bod), Loc), Parameter_Associations => Actuals)); else pragma Assert (Nkind (Spec) = N_Function_Specification); Stmts := New_List ( Make_Return_Statement (Loc, Expression => Make_Function_Call (Loc, Name => New_Reference_To (Corresponding_Spec (Prot_Bod), Loc), Parameter_Associations => Actuals))); end if; return Make_Subprogram_Body (Loc, Declarations => Empty_List, Specification => Spec, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Stmts)); end Build_Dispatching_Subprogram_Body; -- Start of processing for Expand_N_Protected_Body begin if No_Run_Time_Mode then Error_Msg_CRT ("protected body", N); return; end if; if Nkind (Parent (N)) = N_Subunit then -- This is the proper body corresponding to a stub. The declarations -- must be inserted at the point of the stub, which is in the decla- -- rative part of the parent unit. Current_Node := Corresponding_Stub (Parent (N)); else Current_Node := N; end if; Op_Body := First (Declarations (N)); -- The protected body is replaced with the bodies of its -- protected operations, and the declarations for internal objects -- that may have been created for entry family bounds. Rewrite (N, Make_Null_Statement (Sloc (N))); Analyze (N); while Present (Op_Body) loop case Nkind (Op_Body) is when N_Subprogram_Declaration => null; when N_Subprogram_Body => -- Exclude functions created to analyze defaults if not Is_Eliminated (Defining_Entity (Op_Body)) and then not Is_Eliminated (Corresponding_Spec (Op_Body)) then New_Op_Body := Build_Unprotected_Subprogram_Body (Op_Body, Pid); Insert_After (Current_Node, New_Op_Body); Current_Node := New_Op_Body; Analyze (New_Op_Body); Update_Prival_Subtypes (New_Op_Body); -- Build the corresponding protected operation only if -- this is a visible operation of the type, or if it is -- an interrupt handler. Otherwise it is only callable -- from within the object, and the unprotected version -- is sufficient. if Present (Corresponding_Spec (Op_Body)) then Op_Decl := Unit_Declaration_Node (Corresponding_Spec (Op_Body)); if Nkind (Parent (Op_Decl)) = N_Protected_Definition and then (List_Containing (Op_Decl) = Visible_Declarations (Parent (Op_Decl)) or else Is_Interrupt_Handler (Corresponding_Spec (Op_Body))) then New_Op_Body := Build_Protected_Subprogram_Body ( Op_Body, Pid, Specification (New_Op_Body)); Insert_After (Current_Node, New_Op_Body); Analyze (New_Op_Body); Current_Node := New_Op_Body; -- Generate an overriding primitive operation body for -- this subprogram if the protected type implements -- an inerface. if Ada_Version >= Ada_05 and then Present (Abstract_Interfaces ( Corresponding_Record_Type (Pid))) then Disp_Op_Body := Build_Dispatching_Subprogram_Body ( Op_Body, Pid, New_Op_Body); Insert_After (Current_Node, Disp_Op_Body); Analyze (Disp_Op_Body); Current_Node := Disp_Op_Body; end if; end if; end if; end if; when N_Entry_Body => Op_Id := Defining_Identifier (Op_Body); Has_Entries := True; Num_Entries := Num_Entries + 1; New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid); Insert_After (Current_Node, New_Op_Body); Current_Node := New_Op_Body; Analyze (New_Op_Body); Update_Prival_Subtypes (New_Op_Body); when N_Implicit_Label_Declaration => null; when N_Itype_Reference => Insert_After (Current_Node, New_Copy (Op_Body)); when N_Freeze_Entity => New_Op_Body := New_Copy (Op_Body); if Present (Entity (Op_Body)) and then Freeze_Node (Entity (Op_Body)) = Op_Body then Set_Freeze_Node (Entity (Op_Body), New_Op_Body); end if; Insert_After (Current_Node, New_Op_Body); Current_Node := New_Op_Body; Analyze (New_Op_Body); when N_Pragma => New_Op_Body := New_Copy (Op_Body); Insert_After (Current_Node, New_Op_Body); Current_Node := New_Op_Body; Analyze (New_Op_Body); when N_Object_Declaration => pragma Assert (not Comes_From_Source (Op_Body)); New_Op_Body := New_Copy (Op_Body); Insert_After (Current_Node, New_Op_Body); Current_Node := New_Op_Body; Analyze (New_Op_Body); when others => raise Program_Error; end case; Next (Op_Body); end loop; -- Finally, create the body of the function that maps an entry index -- into the corresponding body index, except when there is no entry, -- or in a ravenscar-like profile (no abort, no entry queue, 1 entry) if Has_Entries and then (Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False or else Num_Entries > 1 or else (Has_Attach_Handler (Pid) and then not Restricted_Profile)) then New_Op_Body := Build_Find_Body_Index (Pid); Insert_After (Current_Node, New_Op_Body); Current_Node := New_Op_Body; Analyze (New_Op_Body); end if; -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after -- the protected body. At this point the entry specs have been created, -- frozen and included in the dispatch table for the protected type. pragma Assert (Present (Corresponding_Record_Type (Pid))); if Ada_Version >= Ada_05 and then Present (Protected_Definition (Parent (Pid))) and then Present (Abstract_Interfaces (Corresponding_Record_Type (Pid))) then declare Vis_Decl : Node_Id := First (Visible_Declarations (Protected_Definition (Parent (Pid)))); Wrap_Body : Node_Id; begin -- Examine the visible declarations of the protected type, looking -- for an entry declaration. We do not consider entry families -- since they cannot have dispatching operations, thus they do not -- need entry wrappers. while Present (Vis_Decl) loop if Nkind (Vis_Decl) = N_Entry_Declaration then Wrap_Body := Build_Wrapper_Body (Loc, Proc_Nam => Defining_Identifier (Vis_Decl), Obj_Typ => Corresponding_Record_Type (Pid), Formals => Parameter_Specifications (Vis_Decl)); if Wrap_Body /= Empty then Insert_After (Current_Node, Wrap_Body); Current_Node := Wrap_Body; Analyze (Wrap_Body); end if; elsif Nkind (Vis_Decl) = N_Subprogram_Declaration then Wrap_Body := Build_Wrapper_Body (Loc, Proc_Nam => Defining_Unit_Name (Specification (Vis_Decl)), Obj_Typ => Corresponding_Record_Type (Pid), Formals => Parameter_Specifications (Specification (Vis_Decl))); if Wrap_Body /= Empty then Insert_After (Current_Node, Wrap_Body); Current_Node := Wrap_Body; Analyze (Wrap_Body); end if; end if; Next (Vis_Decl); end loop; end; end if; end Expand_N_Protected_Body; ----------------------------------------- -- Expand_N_Protected_Type_Declaration -- ----------------------------------------- -- First we create a corresponding record type declaration used to -- represent values of this protected type. -- The general form of this type declaration is -- type poV (discriminants) is record -- _Object : aliased <kind>Protection -- [(<entry count> [, <handler count>])]; -- [entry_family : array (bounds) of Void;] -- <private data fields> -- end record; -- The discriminants are present only if the corresponding protected type -- has discriminants, and they exactly mirror the protected type -- discriminants. The private data fields similarly mirror the private -- declarations of the protected type. -- The Object field is always present. It contains RTS specific data used -- to control the protected object. It is declared as Aliased so that it -- can be passed as a pointer to the RTS. This allows the protected record -- to be referenced within RTS data structures. An appropriate Protection -- type and discriminant are generated. -- The Service field is present for protected objects with entries. It -- contains sufficient information to allow the entry service procedure for -- this object to be called when the object is not known till runtime. -- One entry_family component is present for each entry family in the -- task definition (see Expand_N_Task_Type_Declaration). -- When a protected object is declared, an instance of the protected type -- value record is created. The elaboration of this declaration creates the -- correct bounds for the entry families, and also evaluates the priority -- expression if needed. The initialization routine for the protected type -- itself then calls Initialize_Protection with appropriate parameters to -- initialize the value of the Task_Id field. Install_Handlers may be also -- called if a pragma Attach_Handler applies. -- Note: this record is passed to the subprograms created by the expansion -- of protected subprograms and entries. It is an in parameter to protected -- functions and an in out parameter to procedures and entry bodies. The -- Entity_Id for this created record type is placed in the -- Corresponding_Record_Type field of the associated protected type entity. -- Next we create a procedure specifications for protected subprograms and -- entry bodies. For each protected subprograms two subprograms are -- created, an unprotected and a protected version. The unprotected version -- is called from within other operations of the same protected object. -- We also build the call to register the procedure if a pragma -- Interrupt_Handler applies. -- A single subprogram is created to service all entry bodies; it has an -- additional boolean out parameter indicating that the previous entry call -- made by the current task was serviced immediately, i.e. not by proxy. -- The O parameter contains a pointer to a record object of the type -- described above. An untyped interface is used here to allow this -- procedure to be called in places where the type of the object to be -- serviced is not known. This must be done, for example, when a call that -- may have been requeued is cancelled; the corresponding object must be -- serviced, but which object that is not known till runtime. -- procedure ptypeS -- (O : System.Address; P : out Boolean); -- procedure pprocN (_object : in out poV); -- procedure pproc (_object : in out poV); -- function pfuncN (_object : poV); -- function pfunc (_object : poV); -- ... -- Note that this must come after the record type declaration, since -- the specs refer to this type. procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Prottyp : constant Entity_Id := Defining_Identifier (N); Pdef : constant Node_Id := Protected_Definition (N); -- This contains two lists; one for visible and one for private decls Rec_Decl : Node_Id; Cdecls : List_Id; Discr_Map : constant Elist_Id := New_Elmt_List; Priv : Node_Id; New_Priv : Node_Id; Comp : Node_Id; Comp_Id : Entity_Id; Sub : Node_Id; Current_Node : Node_Id := N; Bdef : Entity_Id := Empty; -- avoid uninit warning Edef : Entity_Id := Empty; -- avoid uninit warning Entries_Aggr : Node_Id; Body_Id : Entity_Id; Body_Arr : Node_Id; E_Count : Int; Object_Comp : Node_Id; procedure Register_Handler; -- For a protected operation that is an interrupt handler, add the -- freeze action that will register it as such. ---------------------- -- Register_Handler -- ---------------------- procedure Register_Handler is -- All semantic checks already done in Sem_Prag Prot_Proc : constant Entity_Id := Defining_Unit_Name (Specification (Current_Node)); Proc_Address : constant Node_Id := Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Prot_Proc, Loc), Attribute_Name => Name_Address); RTS_Call : constant Entity_Id := Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( RTE (RE_Register_Interrupt_Handler), Loc), Parameter_Associations => New_List (Proc_Address)); begin Append_Freeze_Action (Prot_Proc, RTS_Call); end Register_Handler; -- Start of processing for Expand_N_Protected_Type_Declaration begin if Present (Corresponding_Record_Type (Prottyp)) then return; else Rec_Decl := Build_Corresponding_Record (N, Prottyp, Loc); Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl))); end if; -- Ada 2005 (AI-345): Propagate the attribute that contains the list -- of implemented interfaces. Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N)); Qualify_Entity_Names (N); -- If the type has discriminants, their occurrences in the declaration -- have been replaced by the corresponding discriminals. For components -- that are constrained by discriminants, their homologues in the -- corresponding record type must refer to the discriminants of that -- record, so we must apply a new renaming to subtypes_indications: -- protected discriminant => discriminal => record discriminant -- This replacement is not applied to default expressions, for which -- the discriminal is correct. if Has_Discriminants (Prottyp) then declare Disc : Entity_Id; Decl : Node_Id; begin Disc := First_Discriminant (Prottyp); Decl := First (Discriminant_Specifications (Rec_Decl)); while Present (Disc) loop Append_Elmt (Discriminal (Disc), Discr_Map); Append_Elmt (Defining_Identifier (Decl), Discr_Map); Next_Discriminant (Disc); Next (Decl); end loop; end; end if; -- Fill in the component declarations -- Add components for entry families. For each entry family, create an -- anonymous type declaration with the same size, and analyze the type. Collect_Entry_Families (Loc, Cdecls, Current_Node, Prottyp); -- Prepend the _Object field with the right type to the component list. -- We need to compute the number of entries, and in some cases the -- number of Attach_Handler pragmas. declare Ritem : Node_Id; Num_Attach_Handler : Int := 0; Protection_Subtype : Node_Id; Entry_Count_Expr : constant Node_Id := Build_Entry_Count_Expression (Prottyp, Cdecls, Loc); begin if Has_Attach_Handler (Prottyp) then Ritem := First_Rep_Item (Prottyp); while Present (Ritem) loop if Nkind (Ritem) = N_Pragma and then Chars (Ritem) = Name_Attach_Handler then Num_Attach_Handler := Num_Attach_Handler + 1; end if; Next_Rep_Item (Ritem); end loop; if Restricted_Profile then if Has_Entries (Prottyp) then Protection_Subtype := New_Reference_To (RTE (RE_Protection_Entry), Loc); else Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc); end if; else Protection_Subtype := Make_Subtype_Indication (Sloc => Loc, Subtype_Mark => New_Reference_To (RTE (RE_Static_Interrupt_Protection), Loc), Constraint => Make_Index_Or_Discriminant_Constraint ( Sloc => Loc, Constraints => New_List ( Entry_Count_Expr, Make_Integer_Literal (Loc, Num_Attach_Handler)))); end if; elsif Has_Interrupt_Handler (Prottyp) then Protection_Subtype := Make_Subtype_Indication ( Sloc => Loc, Subtype_Mark => New_Reference_To (RTE (RE_Dynamic_Interrupt_Protection), Loc), Constraint => Make_Index_Or_Discriminant_Constraint ( Sloc => Loc, Constraints => New_List (Entry_Count_Expr))); -- Type has explicit entries or generated primitive entry wrappers elsif Has_Entries (Prottyp) or else (Ada_Version >= Ada_05 and then Present (Interface_List (N))) then if Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False or else Number_Entries (Prottyp) > 1 then Protection_Subtype := Make_Subtype_Indication ( Sloc => Loc, Subtype_Mark => New_Reference_To (RTE (RE_Protection_Entries), Loc), Constraint => Make_Index_Or_Discriminant_Constraint ( Sloc => Loc, Constraints => New_List (Entry_Count_Expr))); else Protection_Subtype := New_Reference_To (RTE (RE_Protection_Entry), Loc); end if; else Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc); end if; Object_Comp := Make_Component_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uObject), Component_Definition => Make_Component_Definition (Loc, Aliased_Present => True, Subtype_Indication => Protection_Subtype)); end; pragma Assert (Present (Pdef)); -- Add private field components if Present (Private_Declarations (Pdef)) then Priv := First (Private_Declarations (Pdef)); while Present (Priv) loop if Nkind (Priv) = N_Component_Declaration then -- The component definition consists of a subtype indication, -- or (in Ada 2005) an access definition. Make a copy of the -- proper definition. declare Old_Comp : constant Node_Id := Component_Definition (Priv); Pent : constant Entity_Id := Defining_Identifier (Priv); New_Comp : Node_Id; begin if Present (Subtype_Indication (Old_Comp)) then New_Comp := Make_Component_Definition (Sloc (Pent), Aliased_Present => False, Subtype_Indication => New_Copy_Tree (Subtype_Indication (Old_Comp), Discr_Map)); else New_Comp := Make_Component_Definition (Sloc (Pent), Aliased_Present => False, Access_Definition => New_Copy_Tree (Access_Definition (Old_Comp), Discr_Map)); end if; New_Priv := Make_Component_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Sloc (Pent), Chars (Pent)), Component_Definition => New_Comp, Expression => Expression (Priv)); Append_To (Cdecls, New_Priv); end; elsif Nkind (Priv) = N_Subprogram_Declaration then -- Make the unprotected version of the subprogram available -- for expansion of intra object calls. There is need for -- a protected version only if the subprogram is an interrupt -- handler, otherwise this operation can only be called from -- within the body. Sub := Make_Subprogram_Declaration (Loc, Specification => Build_Protected_Sub_Specification (Priv, Prottyp, Unprotected_Mode)); Insert_After (Current_Node, Sub); Analyze (Sub); Set_Protected_Body_Subprogram (Defining_Unit_Name (Specification (Priv)), Defining_Unit_Name (Specification (Sub))); Current_Node := Sub; if Is_Interrupt_Handler (Defining_Unit_Name (Specification (Priv))) then Sub := Make_Subprogram_Declaration (Loc, Specification => Build_Protected_Sub_Specification (Priv, Prottyp, Protected_Mode)); Insert_After (Current_Node, Sub); Analyze (Sub); Current_Node := Sub; if not Restricted_Profile then Register_Handler; end if; end if; end if; Next (Priv); end loop; end if; -- Put the _Object component after the private component so that it -- be finalized early as required by 9.4 (20) Append_To (Cdecls, Object_Comp); Insert_After (Current_Node, Rec_Decl); Current_Node := Rec_Decl; -- Analyze the record declaration immediately after construction, -- because the initialization procedure is needed for single object -- declarations before the next entity is analyzed (the freeze call -- that generates this initialization procedure is found below). Analyze (Rec_Decl, Suppress => All_Checks); -- Ada 2005 (AI-345): Construct the primitive entry wrappers before -- the corresponding record is frozen if Ada_Version >= Ada_05 and then Present (Visible_Declarations (Pdef)) and then Present (Corresponding_Record_Type (Defining_Identifier (Parent (Pdef)))) and then Present (Abstract_Interfaces (Corresponding_Record_Type (Defining_Identifier (Parent (Pdef))))) then declare Current_Node : Node_Id := Rec_Decl; Vis_Decl : Node_Id; Wrap_Spec : Node_Id; New_N : Node_Id; begin -- Examine the visible declarations of the protected type, looking -- for declarations of entries, and subprograms. We do not -- consider entry families since they cannot have dispatching -- operations, thus they do not need entry wrappers. Vis_Decl := First (Visible_Declarations (Pdef)); while Present (Vis_Decl) loop Wrap_Spec := Empty; if Nkind (Vis_Decl) = N_Entry_Declaration and then No (Discrete_Subtype_Definition (Vis_Decl)) then Wrap_Spec := Build_Wrapper_Spec (Loc, Proc_Nam => Defining_Identifier (Vis_Decl), Obj_Typ => Defining_Identifier (Rec_Decl), Formals => Parameter_Specifications (Vis_Decl)); elsif Nkind (Vis_Decl) = N_Subprogram_Declaration then Wrap_Spec := Build_Wrapper_Spec (Loc, Proc_Nam => Defining_Unit_Name (Specification (Vis_Decl)), Obj_Typ => Defining_Identifier (Rec_Decl), Formals => Parameter_Specifications (Specification (Vis_Decl))); end if; if Wrap_Spec /= Empty then New_N := Make_Subprogram_Declaration (Loc, Specification => Wrap_Spec); Insert_After (Current_Node, New_N); Current_Node := New_N; Analyze (New_N); end if; Next (Vis_Decl); end loop; end; end if; -- Collect pointers to entry bodies and their barriers, to be placed -- in the Entry_Bodies_Array for the type. For each entry/family we -- add an expression to the aggregate which is the initial value of -- this array. The array is declared after all protected subprograms. if Has_Entries (Prottyp) then Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List); else Entries_Aggr := Empty; end if; -- Build two new procedure specifications for each protected subprogram; -- one to call from outside the object and one to call from inside. -- Build a barrier function and an entry body action procedure -- specification for each protected entry. Initialize the entry body -- array. If subprogram is flagged as eliminated, do not generate any -- internal operations. E_Count := 0; Comp := First (Visible_Declarations (Pdef)); while Present (Comp) loop if Nkind (Comp) = N_Subprogram_Declaration and then not Is_Eliminated (Defining_Entity (Comp)) then Sub := Make_Subprogram_Declaration (Loc, Specification => Build_Protected_Sub_Specification (Comp, Prottyp, Unprotected_Mode)); Insert_After (Current_Node, Sub); Analyze (Sub); Set_Protected_Body_Subprogram (Defining_Unit_Name (Specification (Comp)), Defining_Unit_Name (Specification (Sub))); -- Make the protected version of the subprogram available for -- expansion of external calls. Current_Node := Sub; Sub := Make_Subprogram_Declaration (Loc, Specification => Build_Protected_Sub_Specification (Comp, Prottyp, Protected_Mode)); Insert_After (Current_Node, Sub); Analyze (Sub); Current_Node := Sub; -- Generate an overriding primitive operation specification for -- this subprogram if the protected type implements an inerface. if Ada_Version >= Ada_05 and then Present (Abstract_Interfaces (Corresponding_Record_Type (Prottyp))) then Sub := Make_Subprogram_Declaration (Loc, Specification => Build_Protected_Sub_Specification (Comp, Prottyp, Dispatching_Mode)); Insert_After (Current_Node, Sub); Analyze (Sub); Current_Node := Sub; end if; -- If a pragma Interrupt_Handler applies, build and add a call to -- Register_Interrupt_Handler to the freezing actions of the -- protected version (Current_Node) of the subprogram: -- system.interrupts.register_interrupt_handler -- (prot_procP'address); if not Restricted_Profile and then Is_Interrupt_Handler (Defining_Unit_Name (Specification (Comp))) then Register_Handler; end if; elsif Nkind (Comp) = N_Entry_Declaration then E_Count := E_Count + 1; Comp_Id := Defining_Identifier (Comp); Set_Privals_Chain (Comp_Id, New_Elmt_List); Edef := Make_Defining_Identifier (Loc, Build_Selected_Name (Prottyp, Comp_Id, 'E')); Sub := Make_Subprogram_Declaration (Loc, Specification => Build_Protected_Entry_Specification (Edef, Comp_Id, Loc)); Insert_After (Current_Node, Sub); Analyze (Sub); Set_Protected_Body_Subprogram ( Defining_Identifier (Comp), Defining_Unit_Name (Specification (Sub))); Current_Node := Sub; Bdef := Make_Defining_Identifier (Loc, Build_Selected_Name (Prottyp, Comp_Id, 'B')); Sub := Make_Subprogram_Declaration (Loc, Specification => Build_Barrier_Function_Specification (Bdef, Loc)); Insert_After (Current_Node, Sub); Analyze (Sub); Set_Protected_Body_Subprogram (Bdef, Bdef); Set_Barrier_Function (Comp_Id, Bdef); Set_Scope (Bdef, Scope (Comp_Id)); Current_Node := Sub; -- Collect pointers to the protected subprogram and the barrier -- of the current entry, for insertion into Entry_Bodies_Array. Append ( Make_Aggregate (Loc, Expressions => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Bdef, Loc), Attribute_Name => Name_Unrestricted_Access), Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Edef, Loc), Attribute_Name => Name_Unrestricted_Access))), Expressions (Entries_Aggr)); end if; Next (Comp); end loop; -- If there are some private entry declarations, expand it as if they -- were visible entries. if Present (Private_Declarations (Pdef)) then Comp := First (Private_Declarations (Pdef)); while Present (Comp) loop if Nkind (Comp) = N_Entry_Declaration then E_Count := E_Count + 1; Comp_Id := Defining_Identifier (Comp); Set_Privals_Chain (Comp_Id, New_Elmt_List); Edef := Make_Defining_Identifier (Loc, Build_Selected_Name (Prottyp, Comp_Id, 'E')); Sub := Make_Subprogram_Declaration (Loc, Specification => Build_Protected_Entry_Specification (Edef, Comp_Id, Loc)); Insert_After (Current_Node, Sub); Analyze (Sub); Set_Protected_Body_Subprogram ( Defining_Identifier (Comp), Defining_Unit_Name (Specification (Sub))); Current_Node := Sub; Bdef := Make_Defining_Identifier (Loc, Build_Selected_Name (Prottyp, Comp_Id, 'E')); Sub := Make_Subprogram_Declaration (Loc, Specification => Build_Barrier_Function_Specification (Bdef, Loc)); Insert_After (Current_Node, Sub); Analyze (Sub); Set_Protected_Body_Subprogram (Bdef, Bdef); Set_Barrier_Function (Comp_Id, Bdef); Set_Scope (Bdef, Scope (Comp_Id)); Current_Node := Sub; -- Collect pointers to the protected subprogram and the barrier -- of the current entry, for insertion into Entry_Bodies_Array. Append ( Make_Aggregate (Loc, Expressions => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Bdef, Loc), Attribute_Name => Name_Unrestricted_Access), Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Edef, Loc), Attribute_Name => Name_Unrestricted_Access))), Expressions (Entries_Aggr)); end if; Next (Comp); end loop; end if; -- Emit declaration for Entry_Bodies_Array, now that the addresses of -- all protected subprograms have been collected. if Has_Entries (Prottyp) then Body_Id := Make_Defining_Identifier (Sloc (Prottyp), New_External_Name (Chars (Prottyp), 'A')); if Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False or else E_Count > 1 or else (Has_Attach_Handler (Prottyp) and then not Restricted_Profile) then Body_Arr := Make_Object_Declaration (Loc, Defining_Identifier => Body_Id, Aliased_Present => True, Object_Definition => Make_Subtype_Indication (Loc, Subtype_Mark => New_Reference_To ( RTE (RE_Protected_Entry_Body_Array), Loc), Constraint => Make_Index_Or_Discriminant_Constraint (Loc, Constraints => New_List ( Make_Range (Loc, Make_Integer_Literal (Loc, 1), Make_Integer_Literal (Loc, E_Count))))), Expression => Entries_Aggr); else Body_Arr := Make_Object_Declaration (Loc, Defining_Identifier => Body_Id, Aliased_Present => True, Object_Definition => New_Reference_To (RTE (RE_Entry_Body), Loc), Expression => Make_Aggregate (Loc, Expressions => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Bdef, Loc), Attribute_Name => Name_Unrestricted_Access), Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Edef, Loc), Attribute_Name => Name_Unrestricted_Access)))); end if; -- A pointer to this array will be placed in the corresponding record -- by its initialization procedure so this needs to be analyzed here. Insert_After (Current_Node, Body_Arr); Current_Node := Body_Arr; Analyze (Body_Arr); Set_Entry_Bodies_Array (Prottyp, Body_Id); -- Finally, build the function that maps an entry index into the -- corresponding body. A pointer to this function is placed in each -- object of the type. Except for a ravenscar-like profile (no abort, -- no entry queue, 1 entry) if Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False or else E_Count > 1 or else (Has_Attach_Handler (Prottyp) and then not Restricted_Profile) then Sub := Make_Subprogram_Declaration (Loc, Specification => Build_Find_Body_Index_Spec (Prottyp)); Insert_After (Current_Node, Sub); Analyze (Sub); end if; end if; end Expand_N_Protected_Type_Declaration; -------------------------------- -- Expand_N_Requeue_Statement -- -------------------------------- -- A requeue statement is expanded into one of four GNARLI operations, -- depending on the source and destination (task or protected object). In -- addition, code must be generated to jump around the remainder of -- processing for the original entry and, if the destination is (different) -- protected object, to attempt to service it. The following illustrates -- the various cases: -- procedure entE -- (O : System.Address; -- P : System.Address; -- E : Protected_Entry_Index) -- is -- <discriminant renamings> -- <private object renamings> -- type poVP is access poV; -- _Object : ptVP := ptVP!(O); -- begin -- begin -- <start of statement sequence for entry> -- -- Requeue from one protected entry body to another protected -- -- entry. -- Requeue_Protected_Entry ( -- _object._object'Access, -- new._object'Access, -- E, -- Abort_Present); -- return; -- <some more of the statement sequence for entry> -- -- Requeue from an entry body to a task entry -- Requeue_Protected_To_Task_Entry ( -- New._task_id, -- E, -- Abort_Present); -- return; -- <rest of statement sequence for entry> -- Complete_Entry_Body (_Object._Object); -- exception -- when all others => -- Exceptional_Complete_Entry_Body ( -- _Object._Object, Get_GNAT_Exception); -- end; -- end entE; -- Requeue of a task entry call to a task entry -- Accept_Call (E, Ann); -- <start of statement sequence for accept statement> -- Requeue_Task_Entry (New._task_id, E, Abort_Present); -- goto Lnn; -- <rest of statement sequence for accept statement> -- <<Lnn>> -- Complete_Rendezvous; -- exception -- when all others => -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception); -- Requeue of a task entry call to a protected entry -- Accept_Call (E, Ann); -- <start of statement sequence for accept statement> -- Requeue_Task_To_Protected_Entry ( -- new._object'Access, -- E, -- Abort_Present); -- newS (new, Pnn); -- goto Lnn; -- <rest of statement sequence for accept statement> -- <<Lnn>> -- Complete_Rendezvous; -- exception -- when all others => -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception); -- Further details on these expansions can be found in -- Expand_N_Protected_Body and Expand_N_Accept_Statement. procedure Expand_N_Requeue_Statement (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Acc_Stat : Node_Id; Concval : Node_Id; Ename : Node_Id; Index : Node_Id; Conctyp : Entity_Id; Oldtyp : Entity_Id; Lab_Node : Node_Id; Rcall : Node_Id; Abortable : Node_Id; Skip_Stat : Node_Id; Self_Param : Node_Id; New_Param : Node_Id; Params : List_Id; RTS_Call : Entity_Id; begin Abortable := New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc); -- Set up the target object Extract_Entry (N, Concval, Ename, Index); Conctyp := Etype (Concval); New_Param := Concurrent_Ref (Concval); -- The target entry index and abortable flag are the same for all cases Params := New_List ( Entry_Index_Expression (Loc, Entity (Ename), Index, Conctyp), Abortable); -- Determine proper GNARLI call and required additional parameters -- Loop to find nearest enclosing task type or protected type Oldtyp := Current_Scope; loop if Is_Task_Type (Oldtyp) then if Is_Task_Type (Conctyp) then RTS_Call := RTE (RE_Requeue_Task_Entry); else pragma Assert (Is_Protected_Type (Conctyp)); RTS_Call := RTE (RE_Requeue_Task_To_Protected_Entry); New_Param := Make_Attribute_Reference (Loc, Prefix => New_Param, Attribute_Name => Name_Unchecked_Access); end if; Prepend (New_Param, Params); exit; elsif Is_Protected_Type (Oldtyp) then Self_Param := Make_Attribute_Reference (Loc, Prefix => Concurrent_Ref (New_Occurrence_Of (Oldtyp, Loc)), Attribute_Name => Name_Unchecked_Access); if Is_Task_Type (Conctyp) then RTS_Call := RTE (RE_Requeue_Protected_To_Task_Entry); else pragma Assert (Is_Protected_Type (Conctyp)); RTS_Call := RTE (RE_Requeue_Protected_Entry); New_Param := Make_Attribute_Reference (Loc, Prefix => New_Param, Attribute_Name => Name_Unchecked_Access); end if; Prepend (New_Param, Params); Prepend (Self_Param, Params); exit; -- If neither task type or protected type, must be in some inner -- enclosing block, so move on out else Oldtyp := Scope (Oldtyp); end if; end loop; -- Create the GNARLI call Rcall := Make_Procedure_Call_Statement (Loc, Name => New_Occurrence_Of (RTS_Call, Loc), Parameter_Associations => Params); Rewrite (N, Rcall); Analyze (N); if Is_Protected_Type (Oldtyp) then -- Build the return statement to skip the rest of the entry body Skip_Stat := Make_Return_Statement (Loc); else -- If the requeue is within a task, find the end label of the -- enclosing accept statement. Acc_Stat := Parent (N); while Nkind (Acc_Stat) /= N_Accept_Statement loop Acc_Stat := Parent (Acc_Stat); end loop; -- The last statement is the second label, used for completing the -- rendezvous the usual way. The label we are looking for is right -- before it. Lab_Node := Prev (Last (Statements (Handled_Statement_Sequence (Acc_Stat)))); pragma Assert (Nkind (Lab_Node) = N_Label); -- Build the goto statement to skip the rest of the accept -- statement. Skip_Stat := Make_Goto_Statement (Loc, Name => New_Occurrence_Of (Entity (Identifier (Lab_Node)), Loc)); end if; Set_Analyzed (Skip_Stat); Insert_After (N, Skip_Stat); end Expand_N_Requeue_Statement; ------------------------------- -- Expand_N_Selective_Accept -- ------------------------------- procedure Expand_N_Selective_Accept (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Alts : constant List_Id := Select_Alternatives (N); -- Note: in the below declarations a lot of new lists are allocated -- unconditionally which may well not end up being used. That's -- not a good idea since it wastes space gratuitously ??? Accept_Case : List_Id; Accept_List : constant List_Id := New_List; Alt : Node_Id; Alt_List : constant List_Id := New_List; Alt_Stats : List_Id; Ann : Entity_Id := Empty; Block : Node_Id; Check_Guard : Boolean := True; Decls : constant List_Id := New_List; Stats : constant List_Id := New_List; Body_List : constant List_Id := New_List; Trailing_List : constant List_Id := New_List; Choices : List_Id; Else_Present : Boolean := False; Terminate_Alt : Node_Id := Empty; Select_Mode : Node_Id; Delay_Case : List_Id; Delay_Count : Integer := 0; Delay_Val : Entity_Id; Delay_Index : Entity_Id; Delay_Min : Entity_Id; Delay_Num : Int := 1; Delay_Alt_List : List_Id := New_List; Delay_List : constant List_Id := New_List; D : Entity_Id; M : Entity_Id; First_Delay : Boolean := True; Guard_Open : Entity_Id; End_Lab : Node_Id; Index : Int := 1; Lab : Node_Id; Num_Alts : Int; Num_Accept : Nat := 0; Proc : Node_Id; Q : Node_Id; Time_Type : Entity_Id; X : Node_Id; Select_Call : Node_Id; Qnam : constant Entity_Id := Make_Defining_Identifier (Loc, New_External_Name ('S', 0)); Xnam : constant Entity_Id := Make_Defining_Identifier (Loc, New_External_Name ('J', 1)); ----------------------- -- Local subprograms -- ----------------------- function Accept_Or_Raise return List_Id; -- For the rare case where delay alternatives all have guards, and -- all of them are closed, it is still possible that there were open -- accept alternatives with no callers. We must reexamine the -- Accept_List, and execute a selective wait with no else if some -- accept is open. If none, we raise program_error. procedure Add_Accept (Alt : Node_Id); -- Process a single accept statement in a select alternative. Build -- procedure for body of accept, and add entry to dispatch table with -- expression for guard, in preparation for call to run time select. function Make_And_Declare_Label (Num : Int) return Node_Id; -- Manufacture a label using Num as a serial number and declare it. -- The declaration is appended to Decls. The label marks the trailing -- statements of an accept or delay alternative. function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id; -- Build call to Selective_Wait runtime routine procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int); -- Add code to compare value of delay with previous values, and -- generate case entry for trailing statements. procedure Process_Accept_Alternative (Alt : Node_Id; Index : Int; Proc : Node_Id); -- Add code to call corresponding procedure, and branch to -- trailing statements, if any. --------------------- -- Accept_Or_Raise -- --------------------- function Accept_Or_Raise return List_Id is Cond : Node_Id; Stats : List_Id; J : constant Entity_Id := Make_Defining_Identifier (Loc, New_Internal_Name ('J')); begin -- We generate the following: -- for J in q'range loop -- if q(J).S /=null_task_entry then -- selective_wait (simple_mode,...); -- done := True; -- exit; -- end if; -- end loop; -- -- if no rendez_vous then -- raise program_error; -- end if; -- Note that the code needs to know that the selector name -- in an Accept_Alternative is named S. Cond := Make_Op_Ne (Loc, Left_Opnd => Make_Selected_Component (Loc, Prefix => Make_Indexed_Component (Loc, Prefix => New_Reference_To (Qnam, Loc), Expressions => New_List (New_Reference_To (J, Loc))), Selector_Name => Make_Identifier (Loc, Name_S)), Right_Opnd => New_Reference_To (RTE (RE_Null_Task_Entry), Loc)); Stats := New_List ( Make_Implicit_Loop_Statement (N, Identifier => Empty, Iteration_Scheme => Make_Iteration_Scheme (Loc, Loop_Parameter_Specification => Make_Loop_Parameter_Specification (Loc, Defining_Identifier => J, Discrete_Subtype_Definition => Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Qnam, Loc), Attribute_Name => Name_Range, Expressions => New_List ( Make_Integer_Literal (Loc, 1))))), Statements => New_List ( Make_Implicit_If_Statement (N, Condition => Cond, Then_Statements => New_List ( Make_Select_Call ( New_Reference_To (RTE (RE_Simple_Mode), Loc)), Make_Exit_Statement (Loc)))))); Append_To (Stats, Make_Raise_Program_Error (Loc, Condition => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (Xnam, Loc), Right_Opnd => New_Reference_To (RTE (RE_No_Rendezvous), Loc)), Reason => PE_All_Guards_Closed)); return Stats; end Accept_Or_Raise; ---------------- -- Add_Accept -- ---------------- procedure Add_Accept (Alt : Node_Id) is Acc_Stm : constant Node_Id := Accept_Statement (Alt); Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm); Eent : constant Entity_Id := Entity (Ename); Index : constant Node_Id := Entry_Index (Acc_Stm); Null_Body : Node_Id; Proc_Body : Node_Id; PB_Ent : Entity_Id; Expr : Node_Id; Call : Node_Id; begin if No (Ann) then Ann := Node (Last_Elmt (Accept_Address (Eent))); end if; if Present (Condition (Alt)) then Expr := Make_Conditional_Expression (Loc, New_List ( Condition (Alt), Entry_Index_Expression (Loc, Eent, Index, Scope (Eent)), New_Reference_To (RTE (RE_Null_Task_Entry), Loc))); else Expr := Entry_Index_Expression (Loc, Eent, Index, Scope (Eent)); end if; if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then Null_Body := New_Reference_To (Standard_False, Loc); if Abort_Allowed then Call := Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)); Insert_Before (First (Statements (Handled_Statement_Sequence ( Accept_Statement (Alt)))), Call); Analyze (Call); end if; PB_Ent := Make_Defining_Identifier (Sloc (Ename), New_External_Name (Chars (Ename), 'A', Num_Accept)); Set_Needs_Debug_Info (PB_Ent, Comes_From_Source (Alt)); Proc_Body := Make_Subprogram_Body (Loc, Specification => Make_Procedure_Specification (Loc, Defining_Unit_Name => PB_Ent), Declarations => Declarations (Acc_Stm), Handled_Statement_Sequence => Build_Accept_Body (Accept_Statement (Alt))); -- During the analysis of the body of the accept statement, any -- zero cost exception handler records were collected in the -- Accept_Handler_Records field of the N_Accept_Alternative node. -- This is where we move them to where they belong, namely the -- newly created procedure. Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt)); Append (Proc_Body, Body_List); else Null_Body := New_Reference_To (Standard_True, Loc); -- if accept statement has declarations, insert above, given that -- we are not creating a body for the accept. if Present (Declarations (Acc_Stm)) then Insert_Actions (N, Declarations (Acc_Stm)); end if; end if; Append_To (Accept_List, Make_Aggregate (Loc, Expressions => New_List (Null_Body, Expr))); Num_Accept := Num_Accept + 1; end Add_Accept; ---------------------------- -- Make_And_Declare_Label -- ---------------------------- function Make_And_Declare_Label (Num : Int) return Node_Id is Lab_Id : Node_Id; begin Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num)); Lab := Make_Label (Loc, Lab_Id); Append_To (Decls, Make_Implicit_Label_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Chars (Lab_Id)), Label_Construct => Lab)); return Lab; end Make_And_Declare_Label; ---------------------- -- Make_Select_Call -- ---------------------- function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is Params : constant List_Id := New_List; begin Append ( Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Qnam, Loc), Attribute_Name => Name_Unchecked_Access), Params); Append (Select_Mode, Params); Append (New_Reference_To (Ann, Loc), Params); Append (New_Reference_To (Xnam, Loc), Params); return Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Selective_Wait), Loc), Parameter_Associations => Params); end Make_Select_Call; -------------------------------- -- Process_Accept_Alternative -- -------------------------------- procedure Process_Accept_Alternative (Alt : Node_Id; Index : Int; Proc : Node_Id) is Choices : List_Id := No_List; Alt_Stats : List_Id; begin Adjust_Condition (Condition (Alt)); Alt_Stats := No_List; if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then Choices := New_List ( Make_Integer_Literal (Loc, Index)); Alt_Stats := New_List ( Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( Defining_Unit_Name (Specification (Proc)), Loc))); end if; if Statements (Alt) /= Empty_List then if No (Alt_Stats) then -- Accept with no body, followed by trailing statements Choices := New_List ( Make_Integer_Literal (Loc, Index)); Alt_Stats := New_List; end if; -- After the call, if any, branch to to trailing statements. We -- create a label for each, as well as the corresponding label -- declaration. Lab := Make_And_Declare_Label (Index); Append_To (Alt_Stats, Make_Goto_Statement (Loc, Name => New_Copy (Identifier (Lab)))); Append (Lab, Trailing_List); Append_List (Statements (Alt), Trailing_List); Append_To (Trailing_List, Make_Goto_Statement (Loc, Name => New_Copy (Identifier (End_Lab)))); end if; if Present (Alt_Stats) then -- Procedure call. and/or trailing statements Append_To (Alt_List, Make_Case_Statement_Alternative (Loc, Discrete_Choices => Choices, Statements => Alt_Stats)); end if; end Process_Accept_Alternative; ------------------------------- -- Process_Delay_Alternative -- ------------------------------- procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is Choices : List_Id; Cond : Node_Id; Delay_Alt : List_Id; begin -- Deal with C/Fortran boolean as delay condition Adjust_Condition (Condition (Alt)); -- Determine the smallest specified delay -- for each delay alternative generate: -- if guard-expression then -- Delay_Val := delay-expression; -- Guard_Open := True; -- if Delay_Val < Delay_Min then -- Delay_Min := Delay_Val; -- Delay_Index := Index; -- end if; -- end if; -- The enclosing if-statement is omitted if there is no guard if Delay_Count = 1 or else First_Delay then First_Delay := False; Delay_Alt := New_List ( Make_Assignment_Statement (Loc, Name => New_Reference_To (Delay_Min, Loc), Expression => Expression (Delay_Statement (Alt)))); if Delay_Count > 1 then Append_To (Delay_Alt, Make_Assignment_Statement (Loc, Name => New_Reference_To (Delay_Index, Loc), Expression => Make_Integer_Literal (Loc, Index))); end if; else Delay_Alt := New_List ( Make_Assignment_Statement (Loc, Name => New_Reference_To (Delay_Val, Loc), Expression => Expression (Delay_Statement (Alt)))); if Time_Type = Standard_Duration then Cond := Make_Op_Lt (Loc, Left_Opnd => New_Reference_To (Delay_Val, Loc), Right_Opnd => New_Reference_To (Delay_Min, Loc)); else -- The scope of the time type must define a comparison -- operator. The scope itself may not be visible, so we -- construct a node with entity information to insure that -- semantic analysis can find the proper operator. Cond := Make_Function_Call (Loc, Name => Make_Selected_Component (Loc, Prefix => New_Reference_To (Scope (Time_Type), Loc), Selector_Name => Make_Operator_Symbol (Loc, Chars => Name_Op_Lt, Strval => No_String)), Parameter_Associations => New_List ( New_Reference_To (Delay_Val, Loc), New_Reference_To (Delay_Min, Loc))); Set_Entity (Prefix (Name (Cond)), Scope (Time_Type)); end if; Append_To (Delay_Alt, Make_Implicit_If_Statement (N, Condition => Cond, Then_Statements => New_List ( Make_Assignment_Statement (Loc, Name => New_Reference_To (Delay_Min, Loc), Expression => New_Reference_To (Delay_Val, Loc)), Make_Assignment_Statement (Loc, Name => New_Reference_To (Delay_Index, Loc), Expression => Make_Integer_Literal (Loc, Index))))); end if; if Check_Guard then Append_To (Delay_Alt, Make_Assignment_Statement (Loc, Name => New_Reference_To (Guard_Open, Loc), Expression => New_Reference_To (Standard_True, Loc))); end if; if Present (Condition (Alt)) then Delay_Alt := New_List ( Make_Implicit_If_Statement (N, Condition => Condition (Alt), Then_Statements => Delay_Alt)); end if; Append_List (Delay_Alt, Delay_List); -- If the delay alternative has a statement part, add choice to the -- case statements for delays. if Present (Statements (Alt)) then if Delay_Count = 1 then Append_List (Statements (Alt), Delay_Alt_List); else Choices := New_List ( Make_Integer_Literal (Loc, Index)); Append_To (Delay_Alt_List, Make_Case_Statement_Alternative (Loc, Discrete_Choices => Choices, Statements => Statements (Alt))); end if; elsif Delay_Count = 1 then -- If the single delay has no trailing statements, add a branch -- to the exit label to the selective wait. Delay_Alt_List := New_List ( Make_Goto_Statement (Loc, Name => New_Copy (Identifier (End_Lab)))); end if; end Process_Delay_Alternative; -- Start of processing for Expand_N_Selective_Accept begin -- First insert some declarations before the select. The first is: -- Ann : Address -- This variable holds the parameters passed to the accept body. This -- declaration has already been inserted by the time we get here by -- a call to Expand_Accept_Declarations made from the semantics when -- processing the first accept statement contained in the select. We -- can find this entity as Accept_Address (E), where E is any of the -- entries references by contained accept statements. -- The first step is to scan the list of Selective_Accept_Statements -- to find this entity, and also count the number of accepts, and -- determine if terminated, delay or else is present: Num_Alts := 0; Alt := First (Alts); while Present (Alt) loop if Nkind (Alt) = N_Accept_Alternative then Add_Accept (Alt); elsif Nkind (Alt) = N_Delay_Alternative then Delay_Count := Delay_Count + 1; -- If the delays are relative delays, the delay expressions have -- type Standard_Duration. Otherwise they must have some time type -- recognized by GNAT. if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then Time_Type := Standard_Duration; else Time_Type := Etype (Expression (Delay_Statement (Alt))); if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time) then null; else Error_Msg_NE ( "& is not a time type ('R'M 9.6(6))", Expression (Delay_Statement (Alt)), Time_Type); Time_Type := Standard_Duration; Set_Etype (Expression (Delay_Statement (Alt)), Any_Type); end if; end if; if No (Condition (Alt)) then -- This guard will always be open Check_Guard := False; end if; elsif Nkind (Alt) = N_Terminate_Alternative then Adjust_Condition (Condition (Alt)); Terminate_Alt := Alt; end if; Num_Alts := Num_Alts + 1; Next (Alt); end loop; Else_Present := Present (Else_Statements (N)); -- At the same time (see procedure Add_Accept) we build the accept list: -- Qnn : Accept_List (1 .. num-select) := ( -- (null-body, entry-index), -- (null-body, entry-index), -- .. -- (null_body, entry-index)); -- In the above declaration, null-body is True if the corresponding -- accept has no body, and false otherwise. The entry is either the -- entry index expression if there is no guard, or if a guard is -- present, then a conditional expression of the form: -- (if guard then entry-index else Null_Task_Entry) -- If a guard is statically known to be false, the entry can simply -- be omitted from the accept list. Q := Make_Object_Declaration (Loc, Defining_Identifier => Qnam, Object_Definition => New_Reference_To (RTE (RE_Accept_List), Loc), Aliased_Present => True, Expression => Make_Qualified_Expression (Loc, Subtype_Mark => New_Reference_To (RTE (RE_Accept_List), Loc), Expression => Make_Aggregate (Loc, Expressions => Accept_List))); Append (Q, Decls); -- Then we declare the variable that holds the index for the accept -- that will be selected for service: -- Xnn : Select_Index; X := Make_Object_Declaration (Loc, Defining_Identifier => Xnam, Object_Definition => New_Reference_To (RTE (RE_Select_Index), Loc), Expression => New_Reference_To (RTE (RE_No_Rendezvous), Loc)); Append (X, Decls); -- After this follow procedure declarations for each accept body -- procedure Pnn is -- begin -- ... -- end; -- where the ... are statements from the corresponding procedure body. -- No parameters are involved, since the parameters are passed via Ann -- and the parameter references have already been expanded to be direct -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore, -- any embedded tasking statements (which would normally be illegal in -- procedures, have been converted to calls to the tasking runtime so -- there is no problem in putting them into procedures. -- The original accept statement has been expanded into a block in -- the same fashion as for simple accepts (see Build_Accept_Body). -- Note: we don't really need to build these procedures for the case -- where no delay statement is present, but it is just as easy to -- build them unconditionally, and not significantly inefficient, -- since if they are short they will be inlined anyway. -- The procedure declarations have been assembled in Body_List -- If delays are present, we must compute the required delay. -- We first generate the declarations: -- Delay_Index : Boolean := 0; -- Delay_Min : Some_Time_Type.Time; -- Delay_Val : Some_Time_Type.Time; -- Delay_Index will be set to the index of the minimum delay, i.e. the -- active delay that is actually chosen as the basis for the possible -- delay if an immediate rendez-vous is not possible. -- In the most common case there is a single delay statement, and this -- is handled specially. if Delay_Count > 0 then -- Generate the required declarations Delay_Val := Make_Defining_Identifier (Loc, New_External_Name ('D', 1)); Delay_Index := Make_Defining_Identifier (Loc, New_External_Name ('D', 2)); Delay_Min := Make_Defining_Identifier (Loc, New_External_Name ('D', 3)); Append_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => Delay_Val, Object_Definition => New_Reference_To (Time_Type, Loc))); Append_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => Delay_Index, Object_Definition => New_Reference_To (Standard_Integer, Loc), Expression => Make_Integer_Literal (Loc, 0))); Append_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => Delay_Min, Object_Definition => New_Reference_To (Time_Type, Loc), Expression => Unchecked_Convert_To (Time_Type, Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Underlying_Type (Time_Type), Loc), Attribute_Name => Name_Last)))); -- Create Duration and Delay_Mode objects used for passing a delay -- value to RTS D := Make_Defining_Identifier (Loc, New_Internal_Name ('D')); M := Make_Defining_Identifier (Loc, New_Internal_Name ('M')); declare Discr : Entity_Id; begin -- Note that these values are defined in s-osprim.ads and must -- be kept in sync: -- -- Relative : constant := 0; -- Absolute_Calendar : constant := 1; -- Absolute_RT : constant := 2; if Time_Type = Standard_Duration then Discr := Make_Integer_Literal (Loc, 0); elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then Discr := Make_Integer_Literal (Loc, 1); else pragma Assert (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)); Discr := Make_Integer_Literal (Loc, 2); end if; Append_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => D, Object_Definition => New_Reference_To (Standard_Duration, Loc))); Append_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => M, Object_Definition => New_Reference_To (Standard_Integer, Loc), Expression => Discr)); end; if Check_Guard then Guard_Open := Make_Defining_Identifier (Loc, New_External_Name ('G', 1)); Append_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => Guard_Open, Object_Definition => New_Reference_To (Standard_Boolean, Loc), Expression => New_Reference_To (Standard_False, Loc))); end if; -- Delay_Count is zero, don't need M and D set (suppress warning) else M := Empty; D := Empty; end if; if Present (Terminate_Alt) then -- If the terminate alternative guard is False, use -- Simple_Mode; otherwise use Terminate_Mode. if Present (Condition (Terminate_Alt)) then Select_Mode := Make_Conditional_Expression (Loc, New_List (Condition (Terminate_Alt), New_Reference_To (RTE (RE_Terminate_Mode), Loc), New_Reference_To (RTE (RE_Simple_Mode), Loc))); else Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc); end if; elsif Else_Present or Delay_Count > 0 then Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc); else Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc); end if; Select_Call := Make_Select_Call (Select_Mode); Append (Select_Call, Stats); -- Now generate code to act on the result. There is an entry -- in this case for each accept statement with a non-null body, -- followed by a branch to the statements that follow the Accept. -- In the absence of delay alternatives, we generate: -- case X is -- when No_Rendezvous => -- omitted if simple mode -- goto Lab0; -- when 1 => -- P1n; -- goto Lab1; -- when 2 => -- P2n; -- goto Lab2; -- when others => -- goto Exit; -- end case; -- -- Lab0: Else_Statements; -- goto exit; -- Lab1: Trailing_Statements1; -- goto Exit; -- -- Lab2: Trailing_Statements2; -- goto Exit; -- ... -- Exit: -- Generate label for common exit End_Lab := Make_And_Declare_Label (Num_Alts + 1); -- First entry is the default case, when no rendezvous is possible Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc)); if Else_Present then -- If no rendezvous is possible, the else part is executed Lab := Make_And_Declare_Label (0); Alt_Stats := New_List ( Make_Goto_Statement (Loc, Name => New_Copy (Identifier (Lab)))); Append (Lab, Trailing_List); Append_List (Else_Statements (N), Trailing_List); Append_To (Trailing_List, Make_Goto_Statement (Loc, Name => New_Copy (Identifier (End_Lab)))); else Alt_Stats := New_List ( Make_Goto_Statement (Loc, Name => New_Copy (Identifier (End_Lab)))); end if; Append_To (Alt_List, Make_Case_Statement_Alternative (Loc, Discrete_Choices => Choices, Statements => Alt_Stats)); -- We make use of the fact that Accept_Index is an integer type, and -- generate successive literals for entries for each accept. Only those -- for which there is a body or trailing statements get a case entry. Alt := First (Select_Alternatives (N)); Proc := First (Body_List); while Present (Alt) loop if Nkind (Alt) = N_Accept_Alternative then Process_Accept_Alternative (Alt, Index, Proc); Index := Index + 1; if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then Next (Proc); end if; elsif Nkind (Alt) = N_Delay_Alternative then Process_Delay_Alternative (Alt, Delay_Num); Delay_Num := Delay_Num + 1; end if; Next (Alt); end loop; -- An others choice is always added to the main case, as well -- as the delay case (to satisfy the compiler). Append_To (Alt_List, Make_Case_Statement_Alternative (Loc, Discrete_Choices => New_List (Make_Others_Choice (Loc)), Statements => New_List (Make_Goto_Statement (Loc, Name => New_Copy (Identifier (End_Lab)))))); Accept_Case := New_List ( Make_Case_Statement (Loc, Expression => New_Reference_To (Xnam, Loc), Alternatives => Alt_List)); Append_List (Trailing_List, Accept_Case); Append (End_Lab, Accept_Case); Append_List (Body_List, Decls); -- Construct case statement for trailing statements of delay -- alternatives, if there are several of them. if Delay_Count > 1 then Append_To (Delay_Alt_List, Make_Case_Statement_Alternative (Loc, Discrete_Choices => New_List (Make_Others_Choice (Loc)), Statements => New_List (Make_Null_Statement (Loc)))); Delay_Case := New_List ( Make_Case_Statement (Loc, Expression => New_Reference_To (Delay_Index, Loc), Alternatives => Delay_Alt_List)); else Delay_Case := Delay_Alt_List; end if; -- If there are no delay alternatives, we append the case statement -- to the statement list. if Delay_Count = 0 then Append_List (Accept_Case, Stats); -- Delay alternatives present else -- If delay alternatives are present we generate: -- find minimum delay. -- DX := minimum delay; -- M := <delay mode>; -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P, -- DX, MX, X); -- -- if X = No_Rendezvous then -- case statement for delay statements. -- else -- case statement for accept alternatives. -- end if; declare Cases : Node_Id; Stmt : Node_Id; Parms : List_Id; Parm : Node_Id; Conv : Node_Id; begin -- The type of the delay expression is known to be legal if Time_Type = Standard_Duration then Conv := New_Reference_To (Delay_Min, Loc); elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then Conv := Make_Function_Call (Loc, New_Reference_To (RTE (RO_CA_To_Duration), Loc), New_List (New_Reference_To (Delay_Min, Loc))); else pragma Assert (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)); Conv := Make_Function_Call (Loc, New_Reference_To (RTE (RO_RT_To_Duration), Loc), New_List (New_Reference_To (Delay_Min, Loc))); end if; Stmt := Make_Assignment_Statement (Loc, Name => New_Reference_To (D, Loc), Expression => Conv); -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode) Parms := Parameter_Associations (Select_Call); Parm := First (Parms); while Present (Parm) and then Parm /= Select_Mode loop Next (Parm); end loop; pragma Assert (Present (Parm)); Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc)); Analyze (Parm); -- Prepare two new parameters of Duration and Delay_Mode type -- which represent the value and the mode of the minimum delay. Next (Parm); Insert_After (Parm, New_Reference_To (M, Loc)); Insert_After (Parm, New_Reference_To (D, Loc)); -- Create a call to RTS Rewrite (Select_Call, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc), Parameter_Associations => Parms)); -- This new call should follow the calculation of the minimum -- delay. Insert_List_Before (Select_Call, Delay_List); if Check_Guard then Stmt := Make_Implicit_If_Statement (N, Condition => New_Reference_To (Guard_Open, Loc), Then_Statements => New_List (New_Copy_Tree (Stmt), New_Copy_Tree (Select_Call)), Else_Statements => Accept_Or_Raise); Rewrite (Select_Call, Stmt); else Insert_Before (Select_Call, Stmt); end if; Cases := Make_Implicit_If_Statement (N, Condition => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (Xnam, Loc), Right_Opnd => New_Reference_To (RTE (RE_No_Rendezvous), Loc)), Then_Statements => Delay_Case, Else_Statements => Accept_Case); Append (Cases, Stats); end; end if; -- Replace accept statement with appropriate block Block := Make_Block_Statement (Loc, Declarations => Decls, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats)); Rewrite (N, Block); Analyze (N); -- Note: have to worry more about abort deferral in above code ??? -- Final step is to unstack the Accept_Address entries for all accept -- statements appearing in accept alternatives in the select statement Alt := First (Alts); while Present (Alt) loop if Nkind (Alt) = N_Accept_Alternative then Remove_Last_Elmt (Accept_Address (Entity (Entry_Direct_Name (Accept_Statement (Alt))))); end if; Next (Alt); end loop; end Expand_N_Selective_Accept; -------------------------------------- -- Expand_N_Single_Task_Declaration -- -------------------------------------- -- Single task declarations should never be present after semantic -- analysis, since we expect them to be replaced by a declaration of an -- anonymous task type, followed by a declaration of the task object. We -- include this routine to make sure that is happening! procedure Expand_N_Single_Task_Declaration (N : Node_Id) is begin raise Program_Error; end Expand_N_Single_Task_Declaration; ------------------------ -- Expand_N_Task_Body -- ------------------------ -- Given a task body -- task body tname is -- <declarations> -- begin -- <statements> -- end x; -- This expansion routine converts it into a procedure and sets the -- elaboration flag for the procedure to true, to represent the fact -- that the task body is now elaborated: -- procedure tnameB (_Task : access tnameV) is -- discriminal : dtype renames _Task.discriminant; -- procedure _clean is -- begin -- Abort_Defer.all; -- Complete_Task; -- Abort_Undefer.all; -- return; -- end _clean; -- begin -- Abort_Undefer.all; -- <declarations> -- System.Task_Stages.Complete_Activation; -- <statements> -- at end -- _clean; -- end tnameB; -- tnameE := True; -- In addition, if the task body is an activator, then a call to activate -- tasks is added at the start of the statements, before the call to -- Complete_Activation, and if in addition the task is a master then it -- must be established as a master. These calls are inserted and analyzed -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is -- expanded. -- There is one discriminal declaration line generated for each -- discriminant that is present to provide an easy reference point for -- discriminant references inside the body (see Exp_Ch2.Expand_Name). -- Note on relationship to GNARLI definition. In the GNARLI definition, -- task body procedures have a profile (Arg : System.Address). That is -- needed because GNARLI has to use the same access-to-subprogram type -- for all task types. We depend here on knowing that in GNAT, passing -- an address argument by value is identical to passing a record value -- by access (in either case a single pointer is passed), so even though -- this procedure has the wrong profile. In fact it's all OK, since the -- callings sequence is identical. procedure Expand_N_Task_Body (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Ttyp : constant Entity_Id := Corresponding_Spec (N); Call : Node_Id; New_N : Node_Id; begin -- Here we start the expansion by generating discriminal declarations Add_Discriminal_Declarations (Declarations (N), Ttyp, Name_uTask, Loc); -- Add a call to Abort_Undefer at the very beginning of the task -- body since this body is called with abort still deferred. if Abort_Allowed then Call := Build_Runtime_Call (Loc, RE_Abort_Undefer); Insert_Before (First (Statements (Handled_Statement_Sequence (N))), Call); Analyze (Call); end if; -- The statement part has already been protected with an at_end and -- cleanup actions. The call to Complete_Activation must be placed -- at the head of the sequence of statements of that block. The -- declarations have been merged in this sequence of statements but -- the first real statement is accessible from the First_Real_Statement -- field (which was set for exactly this purpose). if Restricted_Profile then Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation); else Call := Build_Runtime_Call (Loc, RE_Complete_Activation); end if; Insert_Before (First_Real_Statement (Handled_Statement_Sequence (N)), Call); Analyze (Call); New_N := Make_Subprogram_Body (Loc, Specification => Build_Task_Proc_Specification (Ttyp), Declarations => Declarations (N), Handled_Statement_Sequence => Handled_Statement_Sequence (N)); -- If the task contains generic instantiations, cleanup actions -- are delayed until after instantiation. Transfer the activation -- chain to the subprogram, to insure that the activation call is -- properly generated. It the task body contains inner tasks, indicate -- that the subprogram is a task master. if Delay_Cleanups (Ttyp) then Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N)); Set_Is_Task_Master (New_N, Is_Task_Master (N)); end if; Rewrite (N, New_N); Analyze (N); -- Set elaboration flag immediately after task body. If the body is a -- subunit, the flag is set in the declarative part containing the stub. if Nkind (Parent (N)) /= N_Subunit then Insert_After (N, Make_Assignment_Statement (Loc, Name => Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')), Expression => New_Reference_To (Standard_True, Loc))); end if; -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after -- the task body. At this point the entry specs have been created, -- frozen and included in the dispatch table for the task type. pragma Assert (Present (Corresponding_Record_Type (Ttyp))); if Ada_Version >= Ada_05 and then Present (Task_Definition (Parent (Ttyp))) and then Present (Abstract_Interfaces (Corresponding_Record_Type (Ttyp))) then declare Current_Node : Node_Id; Vis_Decl : Node_Id := First (Visible_Declarations (Task_Definition (Parent (Ttyp)))); Wrap_Body : Node_Id; begin if Nkind (Parent (N)) = N_Subunit then Current_Node := Corresponding_Stub (Parent (N)); else Current_Node := N; end if; -- Examine the visible declarations of the task type, looking for -- an entry declaration. We do not consider entry families since -- they cannot have dispatching operations, thus they do not need -- entry wrappers. while Present (Vis_Decl) loop if Nkind (Vis_Decl) = N_Entry_Declaration and then Ekind (Defining_Identifier (Vis_Decl)) = E_Entry then -- Create the specification of the wrapper Wrap_Body := Build_Wrapper_Body (Loc, Proc_Nam => Defining_Identifier (Vis_Decl), Obj_Typ => Corresponding_Record_Type (Ttyp), Formals => Parameter_Specifications (Vis_Decl)); if Wrap_Body /= Empty then Insert_After (Current_Node, Wrap_Body); Current_Node := Wrap_Body; Analyze (Wrap_Body); end if; end if; Next (Vis_Decl); end loop; end; end if; end Expand_N_Task_Body; ------------------------------------ -- Expand_N_Task_Type_Declaration -- ------------------------------------ -- We have several things to do. First we must create a Boolean flag used -- to mark if the body is elaborated yet. This variable gets set to True -- when the body of the task is elaborated (we can't rely on the normal -- ABE mechanism for the task body, since we need to pass an access to -- this elaboration boolean to the runtime routines). -- taskE : aliased Boolean := False; -- Next a variable is declared to hold the task stack size (either the -- default : Unspecified_Size, or a value that is set by a pragma -- Storage_Size). If the value of the pragma Storage_Size is static, then -- the variable is initialized with this value: -- taskZ : Size_Type := Unspecified_Size; -- or -- taskZ : Size_Type := Size_Type (size_expression); -- Next we create a corresponding record type declaration used to represent -- values of this task. The general form of this type declaration is -- type taskV (discriminants) is record -- _Task_Id : Task_Id; -- entry_family : array (bounds) of Void; -- _Priority : Integer := priority_expression; -- _Size : Size_Type := Size_Type (size_expression); -- _Task_Info : Task_Info_Type := task_info_expression; -- end record; -- The discriminants are present only if the corresponding task type has -- discriminants, and they exactly mirror the task type discriminants. -- The Id field is always present. It contains the Task_Id value, as set by -- the call to Create_Task. Note that although the task is limited, the -- task value record type is not limited, so there is no problem in passing -- this field as an out parameter to Create_Task. -- One entry_family component is present for each entry family in the task -- definition. The bounds correspond to the bounds of the entry family -- (which may depend on discriminants). The element type is void, since we -- only need the bounds information for determining the entry index. Note -- that the use of an anonymous array would normally be illegal in this -- context, but this is a parser check, and the semantics is quite prepared -- to handle such a case. -- The _Size field is present only if a Storage_Size pragma appears in the -- task definition. The expression captures the argument that was present -- in the pragma, and is used to override the task stack size otherwise -- associated with the task type. -- The _Priority field is present only if a Priority or Interrupt_Priority -- pragma appears in the task definition. The expression captures the -- argument that was present in the pragma, and is used to provide the Size -- parameter to the call to Create_Task. -- The _Task_Info field is present only if a Task_Info pragma appears in -- the task definition. The expression captures the argument that was -- present in the pragma, and is used to provide the Task_Image parameter -- to the call to Create_Task. -- When a task is declared, an instance of the task value record is -- created. The elaboration of this declaration creates the correct bounds -- for the entry families, and also evaluates the size, priority, and -- task_Info expressions if needed. The initialization routine for the task -- type itself then calls Create_Task with appropriate parameters to -- initialize the value of the Task_Id field. -- Note: the address of this record is passed as the "Discriminants" -- parameter for Create_Task. Since Create_Task merely passes this onto the -- body procedure, it does not matter that it does not quite match the -- GNARLI model of what is being passed (the record contains more than just -- the discriminants, but the discriminants can be found from the record -- value). -- The Entity_Id for this created record type is placed in the -- Corresponding_Record_Type field of the associated task type entity. -- Next we create a procedure specification for the task body procedure: -- procedure taskB (_Task : access taskV); -- Note that this must come after the record type declaration, since -- the spec refers to this type. It turns out that the initialization -- procedure for the value type references the task body spec, but that's -- fine, since it won't be generated till the freeze point for the type, -- which is certainly after the task body spec declaration. -- Finally, we set the task index value field of the entry attribute in -- the case of a simple entry. procedure Expand_N_Task_Type_Declaration (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N)); Tasknm : constant Name_Id := Chars (Tasktyp); Taskdef : constant Node_Id := Task_Definition (N); Proc_Spec : Node_Id; Rec_Decl : Node_Id; Rec_Ent : Entity_Id; Cdecls : List_Id; Elab_Decl : Node_Id; Size_Decl : Node_Id; Body_Decl : Node_Id; Task_Size : Node_Id; Ent_Stack : Entity_Id; Decl_Stack : Node_Id; begin -- If already expanded, nothing to do if Present (Corresponding_Record_Type (Tasktyp)) then return; end if; -- Here we will do the expansion Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc); -- Ada 2005 (AI-345): Propagate the attribute that contains the list -- of implemented interfaces. Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N)); Rec_Ent := Defining_Identifier (Rec_Decl); Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl))); Qualify_Entity_Names (N); -- First create the elaboration variable Elab_Decl := Make_Object_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Sloc (Tasktyp), Chars => New_External_Name (Tasknm, 'E')), Aliased_Present => True, Object_Definition => New_Reference_To (Standard_Boolean, Loc), Expression => New_Reference_To (Standard_False, Loc)); Insert_After (N, Elab_Decl); -- Next create the declaration of the size variable (tasknmZ) Set_Storage_Size_Variable (Tasktyp, Make_Defining_Identifier (Sloc (Tasktyp), Chars => New_External_Name (Tasknm, 'Z'))); if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then Is_Static_Expression (Expression (First ( Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma ( Taskdef, Name_Storage_Size))))) then Size_Decl := Make_Object_Declaration (Loc, Defining_Identifier => Storage_Size_Variable (Tasktyp), Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc), Expression => Convert_To (RTE (RE_Size_Type), Relocate_Node ( Expression (First ( Pragma_Argument_Associations ( Find_Task_Or_Protected_Pragma (Taskdef, Name_Storage_Size))))))); else Size_Decl := Make_Object_Declaration (Loc, Defining_Identifier => Storage_Size_Variable (Tasktyp), Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc), Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc)); end if; Insert_After (Elab_Decl, Size_Decl); -- Next build the rest of the corresponding record declaration. This is -- done last, since the corresponding record initialization procedure -- will reference the previously created entities. -- Fill in the component declarations -- first the _Task_Id field Append_To (Cdecls, Make_Component_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uTask_Id), Component_Definition => Make_Component_Definition (Loc, Aliased_Present => False, Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id), Loc)))); -- Declare static ATCB (that is, created by the expander) if we are -- using the Restricted run time. if Restricted_Profile then Append_To (Cdecls, Make_Component_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uATCB), Component_Definition => Make_Component_Definition (Loc, Aliased_Present => True, Subtype_Indication => Make_Subtype_Indication (Loc, Subtype_Mark => New_Occurrence_Of (RTE (RE_Ada_Task_Control_Block), Loc), Constraint => Make_Index_Or_Discriminant_Constraint (Loc, Constraints => New_List (Make_Integer_Literal (Loc, 0))))))); end if; -- Declare static stack (that is, created by the expander) if we are -- using the Restricted run time on a bare board configuration. if Restricted_Profile and then Preallocated_Stacks_On_Target then -- First we need to extract the appropriate stack size Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack); if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then Task_Size := Relocate_Node ( Expression (First ( Pragma_Argument_Associations ( Find_Task_Or_Protected_Pragma (Taskdef, Name_Storage_Size))))); else Task_Size := New_Reference_To (RTE (RE_Default_Stack_Size), Loc); end if; Decl_Stack := Make_Component_Declaration (Loc, Defining_Identifier => Ent_Stack, Component_Definition => Make_Component_Definition (Loc, Aliased_Present => True, Subtype_Indication => Make_Subtype_Indication (Loc, Subtype_Mark => New_Occurrence_Of (RTE (RE_Storage_Array), Loc), Constraint => Make_Index_Or_Discriminant_Constraint (Loc, Constraints => New_List (Make_Range (Loc, Low_Bound => Make_Integer_Literal (Loc, 1), High_Bound => Convert_To (RTE (RE_Storage_Offset), Task_Size))))))); Append_To (Cdecls, Decl_Stack); -- The appropriate alignment for the stack is ensured by the run-time -- code in charge of task creation. end if; -- Add components for entry families Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp); -- Add the _Priority component if a Priority pragma is present if Present (Taskdef) and then Has_Priority_Pragma (Taskdef) then declare Prag : constant Node_Id := Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority); Expr : Node_Id; begin Expr := First (Pragma_Argument_Associations (Prag)); if Nkind (Expr) = N_Pragma_Argument_Association then Expr := Expression (Expr); end if; Expr := New_Copy_Tree (Expr); -- Add conversion to proper type to do range check if required -- Note that for runtime units, we allow out of range interrupt -- priority values to be used in a priority pragma. This is for -- the benefit of some versions of System.Interrupts which use -- a special server task with maximum interrupt priority. if Chars (Prag) = Name_Priority and then not GNAT_Mode then Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr)); else Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr)); end if; Append_To (Cdecls, Make_Component_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uPriority), Component_Definition => Make_Component_Definition (Loc, Aliased_Present => False, Subtype_Indication => New_Reference_To (Standard_Integer, Loc)), Expression => Expr)); end; end if; -- Add the _Task_Size component if a Storage_Size pragma is present if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then Append_To (Cdecls, Make_Component_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uSize), Component_Definition => Make_Component_Definition (Loc, Aliased_Present => False, Subtype_Indication => New_Reference_To (RTE (RE_Size_Type), Loc)), Expression => Convert_To (RTE (RE_Size_Type), Relocate_Node ( Expression (First ( Pragma_Argument_Associations ( Find_Task_Or_Protected_Pragma (Taskdef, Name_Storage_Size)))))))); end if; -- Add the _Task_Info component if a Task_Info pragma is present if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then Append_To (Cdecls, Make_Component_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uTask_Info), Component_Definition => Make_Component_Definition (Loc, Aliased_Present => False, Subtype_Indication => New_Reference_To (RTE (RE_Task_Info_Type), Loc)), Expression => New_Copy ( Expression (First ( Pragma_Argument_Associations ( Find_Task_Or_Protected_Pragma (Taskdef, Name_Task_Info))))))); end if; Insert_After (Size_Decl, Rec_Decl); -- Analyze the record declaration immediately after construction, -- because the initialization procedure is needed for single task -- declarations before the next entity is analyzed. Analyze (Rec_Decl); -- Create the declaration of the task body procedure Proc_Spec := Build_Task_Proc_Specification (Tasktyp); Body_Decl := Make_Subprogram_Declaration (Loc, Specification => Proc_Spec); Insert_After (Rec_Decl, Body_Decl); -- The subprogram does not comes from source, so we have to indicate the -- need for debugging information explicitly. Set_Needs_Debug_Info (Defining_Entity (Proc_Spec), Comes_From_Source (Original_Node (N))); -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before -- the corresponding record has been frozen. if Ada_Version >= Ada_05 and then Present (Taskdef) and then Present (Corresponding_Record_Type (Defining_Identifier (Parent (Taskdef)))) and then Present (Abstract_Interfaces (Corresponding_Record_Type (Defining_Identifier (Parent (Taskdef))))) then declare Current_Node : Node_Id := Rec_Decl; Vis_Decl : Node_Id := First (Visible_Declarations (Taskdef)); Wrap_Spec : Node_Id; New_N : Node_Id; begin -- Examine the visible declarations of the task type, looking for -- an entry declaration. We do not consider entry families since -- they cannot have dispatching operations, thus they do not need -- entry wrappers. while Present (Vis_Decl) loop if Nkind (Vis_Decl) = N_Entry_Declaration and then Ekind (Defining_Identifier (Vis_Decl)) = E_Entry then Wrap_Spec := Build_Wrapper_Spec (Loc, Proc_Nam => Defining_Identifier (Vis_Decl), Obj_Typ => Etype (Rec_Ent), Formals => Parameter_Specifications (Vis_Decl)); if Wrap_Spec /= Empty then New_N := Make_Subprogram_Declaration (Loc, Specification => Wrap_Spec); Insert_After (Current_Node, New_N); Current_Node := New_N; Analyze (New_N); end if; end if; Next (Vis_Decl); end loop; end; end if; -- Ada 2005 (AI-345): We must defer freezing to allow further -- declaration of primitive subprograms covering task interfaces if Ada_Version <= Ada_95 then -- Now we can freeze the corresponding record. This needs manually -- freezing, since it is really part of the task type, and the task -- type is frozen at this stage. We of course need the initialization -- procedure for this corresponding record type and we won't get it -- in time if we don't freeze now. declare L : constant List_Id := Freeze_Entity (Rec_Ent, Loc); begin if Is_Non_Empty_List (L) then Insert_List_After (Body_Decl, L); end if; end; end if; -- Complete the expansion of access types to the current task type, if -- any were declared. Expand_Previous_Access_Type (Tasktyp); end Expand_N_Task_Type_Declaration; ------------------------------- -- Expand_N_Timed_Entry_Call -- ------------------------------- -- A timed entry call in normal case is not implemented using ATC mechanism -- anymore for efficiency reason. -- select -- T.E; -- S1; -- or -- Delay D; -- S2; -- end select; -- is expanded as follow: -- 1) When T.E is a task entry_call; -- declare -- B : Boolean; -- X : Task_Entry_Index := <entry index>; -- DX : Duration := To_Duration (D); -- M : Delay_Mode := <discriminant>; -- P : parms := (parm, parm, parm); -- begin -- Timed_Protected_Entry_Call (<acceptor-task>, X, P'Address, -- DX, M, B); -- if B then -- S1; -- else -- S2; -- end if; -- end; -- 2) When T.E is a protected entry_call; -- declare -- B : Boolean; -- X : Protected_Entry_Index := <entry index>; -- DX : Duration := To_Duration (D); -- M : Delay_Mode := <discriminant>; -- P : parms := (parm, parm, parm); -- begin -- Timed_Protected_Entry_Call (<object>'unchecked_access, X, -- P'Address, DX, M, B); -- if B then -- S1; -- else -- S2; -- end if; -- end; -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call; -- declare -- B : Boolean := False; -- C : Ada.Tags.Prim_Op_Kind; -- DX : Duration := To_Duration (D) -- K : Ada.Tags.Tagged_Kind := -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>)); -- M : Integer :=...; -- P : Parameters := (Param1 .. ParamN); -- S : Iteger; -- begin -- if K = Ada.Tags.TK_Limited_Tagged then -- <dispatching-call>; -- <triggering-statements> -- else -- S := Ada.Tags.Get_Offset_Index (Ada.Tags.Tag (<object>), -- DT_Position (<dispatching-call>)); -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B); -- if C = POK_Protected_Entry -- or else C = POK_Task_Entry -- then -- Param1 := P.Param1; -- ... -- ParamN := P.ParamN; -- end if; -- if B then -- if C = POK_Procedure -- or else C = POK_Protected_Procedure -- or else C = POK_Task_Procedure -- then -- <dispatching-call>; -- end if; -- <triggering-statements> -- else -- <timed-statements> -- end if; -- end if; -- end; procedure Expand_N_Timed_Entry_Call (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); E_Call : Node_Id := Entry_Call_Statement (Entry_Call_Alternative (N)); E_Stats : constant List_Id := Statements (Entry_Call_Alternative (N)); D_Stat : constant Node_Id := Delay_Statement (Delay_Alternative (N)); D_Stats : constant List_Id := Statements (Delay_Alternative (N)); Actuals : List_Id; Blk_Typ : Entity_Id; Call : Node_Id; Call_Ent : Entity_Id; Conc_Typ_Stmts : List_Id; Concval : Node_Id; D_Conv : Node_Id; D_Disc : Node_Id; D_Type : Entity_Id; Decls : List_Id; Dummy : Node_Id; Ename : Node_Id; Formals : List_Id; Index : Node_Id; Lim_Typ_Stmts : List_Id; N_Stats : List_Id; Obj : Entity_Id; Param : Node_Id; Params : List_Id; Stmt : Node_Id; Stmts : List_Id; Unpack : List_Id; B : Entity_Id; -- Call status flag C : Entity_Id; -- Call kind D : Entity_Id; -- Delay K : Entity_Id; -- Tagged kind M : Entity_Id; -- Delay mode P : Entity_Id; -- Parameter block S : Entity_Id; -- Primitive operation slot begin -- The arguments in the call may require dynamic allocation, and the -- call statement may have been transformed into a block. The block -- may contain additional declarations for internal entities, and the -- original call is found by sequential search. if Nkind (E_Call) = N_Block_Statement then E_Call := First (Statements (Handled_Statement_Sequence (E_Call))); while Nkind (E_Call) /= N_Procedure_Call_Statement and then Nkind (E_Call) /= N_Entry_Call_Statement loop Next (E_Call); end loop; end if; if Ada_Version >= Ada_05 and then Nkind (E_Call) = N_Procedure_Call_Statement then Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals); Decls := New_List; Stmts := New_List; else -- Build an entry call using Simple_Entry_Call Extract_Entry (E_Call, Concval, Ename, Index); Build_Simple_Entry_Call (E_Call, Concval, Ename, Index); Decls := Declarations (E_Call); Stmts := Statements (Handled_Statement_Sequence (E_Call)); if No (Decls) then Decls := New_List; end if; end if; -- Call status flag processing if Ada_Version >= Ada_05 and then Nkind (E_Call) = N_Procedure_Call_Statement then -- Generate: -- B : Boolean := False; B := Build_B (Loc, Decls); else -- Generate: -- B : Boolean; B := Make_Defining_Identifier (Loc, Name_uB); Prepend_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => B, Object_Definition => New_Reference_To (Standard_Boolean, Loc))); end if; -- Call kind processing if Ada_Version >= Ada_05 and then Nkind (E_Call) = N_Procedure_Call_Statement then -- Generate: -- C : Ada.Tags.Prim_Op_Kind; C := Build_C (Loc, Decls); end if; -- Duration and mode processing D_Type := Base_Type (Etype (Expression (D_Stat))); -- Use the type of the delay expression (Calendar or Real_Time) -- to generate the appropriate conversion. if Nkind (D_Stat) = N_Delay_Relative_Statement then D_Disc := Make_Integer_Literal (Loc, 0); D_Conv := Relocate_Node (Expression (D_Stat)); elsif Is_RTE (D_Type, RO_CA_Time) then D_Disc := Make_Integer_Literal (Loc, 1); D_Conv := Make_Function_Call (Loc, New_Reference_To (RTE (RO_CA_To_Duration), Loc), New_List (New_Copy (Expression (D_Stat)))); else pragma Assert (Is_RTE (D_Type, RO_RT_Time)); D_Disc := Make_Integer_Literal (Loc, 2); D_Conv := Make_Function_Call (Loc, New_Reference_To (RTE (RO_RT_To_Duration), Loc), New_List (New_Copy (Expression (D_Stat)))); end if; D := Make_Defining_Identifier (Loc, New_Internal_Name ('D')); -- Generate: -- D : Duration; Append_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => D, Object_Definition => New_Reference_To (Standard_Duration, Loc))); M := Make_Defining_Identifier (Loc, New_Internal_Name ('M')); -- Generate: -- M : Integer := (0 | 1 | 2); Append_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => M, Object_Definition => New_Reference_To (Standard_Integer, Loc), Expression => D_Disc)); -- Do the assignement at this stage only because the evaluation of the -- expression must not occur before (see ACVC C97302A). Append_To (Stmts, Make_Assignment_Statement (Loc, Name => New_Reference_To (D, Loc), Expression => D_Conv)); -- Parameter block processing -- Manually create the parameter block for dispatching calls. In the -- case of entries, the block has already been created during the call -- to Build_Simple_Entry_Call. if Ada_Version >= Ada_05 and then Nkind (E_Call) = N_Procedure_Call_Statement then -- Tagged kind processing, generate: -- K : Ada.Tags.Tagged_Kind := -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>)); K := Build_K (Loc, Decls, Obj); Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls); P := Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts); -- Dispatch table slot processing, generate: -- S : Integer; S := Build_S (Loc, Decls); -- Generate: -- S := Ada.Tags.Get_Offset_Index ( -- Ada.Tags.Tag (<object>), DT_Position (Call_Ent)); Conc_Typ_Stmts := New_List ( Build_S_Assignment (Loc, S, Obj, Call_Ent)); -- Generate: -- _Disp_Timed_Select (<object>, S, P'address, D, M, C, B); -- where Obj is the controlling formal parameter, S is the dispatch -- table slot number of the dispatching operation, P is the wrapped -- parameter block, D is the duration, M is the duration mode, C is -- the call kind and B is the call status. Params := New_List; Append_To (Params, New_Copy_Tree (Obj)); Append_To (Params, New_Reference_To (S, Loc)); Append_To (Params, Make_Attribute_Reference (Loc, Prefix => New_Reference_To (P, Loc), Attribute_Name => Name_Address)); Append_To (Params, New_Reference_To (D, Loc)); Append_To (Params, New_Reference_To (M, Loc)); Append_To (Params, New_Reference_To (C, Loc)); Append_To (Params, New_Reference_To (B, Loc)); Append_To (Conc_Typ_Stmts, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( Find_Prim_Op (Etype (Etype (Obj)), Name_uDisp_Timed_Select), Loc), Parameter_Associations => Params)); -- Generate: -- if C = POK_Protected_Entry -- or else C = POK_Task_Entry -- then -- Param1 := P.Param1; -- ... -- ParamN := P.ParamN; -- end if; Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals); -- Generate the if statement only when the packed parameters need -- explicit assignments to their corresponding actuals. if Present (Unpack) then Append_To (Conc_Typ_Stmts, Make_If_Statement (Loc, Condition => Make_Or_Else (Loc, Left_Opnd => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (C, Loc), Right_Opnd => New_Reference_To (RTE ( RE_POK_Protected_Entry), Loc)), Right_Opnd => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (C, Loc), Right_Opnd => New_Reference_To (RTE (RE_POK_Task_Entry), Loc))), Then_Statements => Unpack)); end if; -- Generate: -- if B then -- if C = POK_Procedure -- or else C = POK_Protected_Procedure -- or else C = POK_Task_Procedure -- then -- <dispatching-call> -- end if; -- <triggering-statements> -- else -- <timed-statements> -- end if; N_Stats := New_Copy_List_Tree (E_Stats); Prepend_To (N_Stats, Make_If_Statement (Loc, Condition => Make_Or_Else (Loc, Left_Opnd => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (C, Loc), Right_Opnd => New_Reference_To (RTE (RE_POK_Procedure), Loc)), Right_Opnd => Make_Or_Else (Loc, Left_Opnd => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (C, Loc), Right_Opnd => New_Reference_To (RTE ( RE_POK_Protected_Procedure), Loc)), Right_Opnd => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (C, Loc), Right_Opnd => New_Reference_To (RTE ( RE_POK_Task_Procedure), Loc)))), Then_Statements => New_List (E_Call))); Append_To (Conc_Typ_Stmts, Make_If_Statement (Loc, Condition => New_Reference_To (B, Loc), Then_Statements => N_Stats, Else_Statements => D_Stats)); -- Generate: -- <dispatching-call>; -- <triggering-statements> Lim_Typ_Stmts := New_Copy_List_Tree (E_Stats); Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call)); -- Generate: -- if K = Ada.Tags.TK_Limited_Tagged then -- Lim_Typ_Stmts -- else -- Conc_Typ_Stmts -- end if; Append_To (Stmts, Make_If_Statement (Loc, Condition => Make_Op_Eq (Loc, Left_Opnd => New_Reference_To (K, Loc), Right_Opnd => New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)), Then_Statements => Lim_Typ_Stmts, Else_Statements => Conc_Typ_Stmts)); else -- Skip assignments to temporaries created for in-out parameters. -- This makes unwarranted assumptions about the shape of the expanded -- tree for the call, and should be cleaned up ??? Stmt := First (Stmts); while Nkind (Stmt) /= N_Procedure_Call_Statement loop Next (Stmt); end loop; -- Do the assignement at this stage only because the evaluation -- of the expression must not occur before (see ACVC C97302A). Insert_Before (Stmt, Make_Assignment_Statement (Loc, Name => New_Reference_To (D, Loc), Expression => D_Conv)); Call := Stmt; Params := Parameter_Associations (Call); -- For a protected type, we build a Timed_Protected_Entry_Call if Is_Protected_Type (Etype (Concval)) then -- Create a new call statement Param := First (Params); while Present (Param) and then not Is_RTE (Etype (Param), RE_Call_Modes) loop Next (Param); end loop; Dummy := Remove_Next (Next (Param)); -- Remove garbage is following the Cancel_Param if present Dummy := Next (Param); -- Remove the mode of the Protected_Entry_Call call, then remove -- the Communication_Block of the Protected_Entry_Call call, and -- finally add Duration and a Delay_Mode parameter pragma Assert (Present (Param)); Rewrite (Param, New_Reference_To (D, Loc)); Rewrite (Dummy, New_Reference_To (M, Loc)); -- Add a Boolean flag for successful entry call Append_To (Params, New_Reference_To (B, Loc)); if Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False or else Number_Entries (Etype (Concval)) > 1 then Rewrite (Call, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE ( RE_Timed_Protected_Entry_Call), Loc), Parameter_Associations => Params)); else Param := First (Params); while Present (Param) and then not Is_RTE (Etype (Param), RE_Protected_Entry_Index) loop Next (Param); end loop; Remove (Param); Rewrite (Call, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( RTE (RE_Timed_Protected_Single_Entry_Call), Loc), Parameter_Associations => Params)); end if; -- For the task case, build a Timed_Task_Entry_Call else -- Create a new call statement Append_To (Params, New_Reference_To (D, Loc)); Append_To (Params, New_Reference_To (M, Loc)); Append_To (Params, New_Reference_To (B, Loc)); Rewrite (Call, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc), Parameter_Associations => Params)); end if; Append_To (Stmts, Make_Implicit_If_Statement (N, Condition => New_Reference_To (B, Loc), Then_Statements => E_Stats, Else_Statements => D_Stats)); end if; Rewrite (N, Make_Block_Statement (Loc, Declarations => Decls, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Stmts))); Analyze (N); end Expand_N_Timed_Entry_Call; ---------------------------------------- -- Expand_Protected_Body_Declarations -- ---------------------------------------- -- Part of the expansion of a protected body involves the creation of a -- declaration that can be referenced from the statement sequences of the -- entry bodies: -- A : Address; -- This declaration is inserted in the declarations of the service entries -- procedure for the protected body, and it is important that it be -- inserted before the statements of the entry body statement sequences are -- analyzed. Thus it would be too late to create this declaration in the -- Expand_N_Protected_Body routine, which is why there is a separate -- procedure to be called directly from Sem_Ch9. -- Ann is used to hold the address of the record containing the parameters -- (see Expand_N_Entry_Call for more details on how this record is built). -- References to the parameters do an unchecked conversion of this address -- to a pointer to the required record type, and then access the field that -- holds the value of the required parameter. The entity for the address -- variable is held as the top stack element (i.e. the last element) of the -- Accept_Address stack in the corresponding entry entity, and this element -- must be set in place before the statements are processed. -- No stack is needed for entry bodies, since they cannot be nested, but it -- is kept for consistency between protected and task entries. The stack -- will never contain more than one element. There is also only one such -- variable for a given protected body, but this is placed on the -- Accept_Address stack of all of the entries, again for consistency. -- To expand the requeue statement, a label is provided at the end of the -- loop in the entry service routine created by the expander (see -- Expand_N_Protected_Body for details), so that the statement can be -- skipped after the requeue is complete. This label is created during the -- expansion of the entry body, which will take place after the expansion -- of the requeue statements that it contains, so a placeholder defining -- identifier is associated with the task type here. -- Another label is provided following case statement created by the -- expander. This label is need for implementing return statement from -- entry body so that a return can be expanded as a goto to this label. -- This label is created during the expansion of the entry body, which -- will take place after the expansion of the return statements that it -- contains. Therefore, just like the label for expanding requeues, we -- need another placeholder for the label. procedure Expand_Protected_Body_Declarations (N : Node_Id; Spec_Id : Entity_Id) is Op : Node_Id; begin if No_Run_Time_Mode then Error_Msg_CRT ("protected body", N); return; elsif Expander_Active then -- Associate privals with the first subprogram or entry body to be -- expanded. These are used to expand references to private data -- objects. Op := First_Protected_Operation (Declarations (N)); if Present (Op) then Set_Discriminals (Parent (Spec_Id)); Set_Privals (Parent (Spec_Id), Op, Sloc (N)); end if; end if; end Expand_Protected_Body_Declarations; ------------------------- -- External_Subprogram -- ------------------------- function External_Subprogram (E : Entity_Id) return Entity_Id is Subp : constant Entity_Id := Protected_Body_Subprogram (E); Decl : constant Node_Id := Unit_Declaration_Node (E); begin -- If the protected operation is defined in the visible part of the -- protected type, or if it is an interrupt handler, the internal and -- external subprograms follow each other on the entity chain. If the -- operation is defined in the private part of the type, there is no -- need for a separate locking version of the operation, and internal -- calls use the protected_body_subprogram directly. if List_Containing (Decl) = Visible_Declarations (Parent (Decl)) or else Is_Interrupt_Handler (E) then return Next_Entity (Subp); else return (Subp); end if; end External_Subprogram; ------------------------------ -- Extract_Dispatching_Call -- ------------------------------ procedure Extract_Dispatching_Call (N : Node_Id; Call_Ent : out Entity_Id; Object : out Entity_Id; Actuals : out List_Id; Formals : out List_Id) is Call_Nam : Node_Id; begin pragma Assert (Nkind (N) = N_Procedure_Call_Statement); if Present (Original_Node (N)) then Call_Nam := Name (Original_Node (N)); else Call_Nam := Name (N); end if; -- Retrieve the name of the dispatching procedure. It contains the -- dispatch table slot number. loop case Nkind (Call_Nam) is when N_Identifier => exit; when N_Selected_Component => Call_Nam := Selector_Name (Call_Nam); when others => raise Program_Error; end case; end loop; Actuals := Parameter_Associations (N); Call_Ent := Entity (Call_Nam); Formals := Parameter_Specifications (Parent (Call_Ent)); Object := First (Actuals); if Present (Original_Node (Object)) then Object := Original_Node (Object); end if; end Extract_Dispatching_Call; ------------------- -- Extract_Entry -- ------------------- procedure Extract_Entry (N : Node_Id; Concval : out Node_Id; Ename : out Node_Id; Index : out Node_Id) is Nam : constant Node_Id := Name (N); begin -- For a simple entry, the name is a selected component, with the -- prefix being the task value, and the selector being the entry. if Nkind (Nam) = N_Selected_Component then Concval := Prefix (Nam); Ename := Selector_Name (Nam); Index := Empty; -- For a member of an entry family, the name is an indexed component -- where the prefix is a selected component, whose prefix in turn is -- the task value, and whose selector is the entry family. The single -- expression in the expressions list of the indexed component is the -- subscript for the family. else pragma Assert (Nkind (Nam) = N_Indexed_Component); Concval := Prefix (Prefix (Nam)); Ename := Selector_Name (Prefix (Nam)); Index := First (Expressions (Nam)); end if; end Extract_Entry; ------------------- -- Family_Offset -- ------------------- function Family_Offset (Loc : Source_Ptr; Hi : Node_Id; Lo : Node_Id; Ttyp : Entity_Id) return Node_Id is function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id; -- If one of the bounds is a reference to a discriminant, replace with -- corresponding discriminal of type. Within the body of a task retrieve -- the renamed discriminant by simple visibility, using its generated -- name. Within a protected object, find the original dis- criminant and -- replace it with the discriminal of the current prot- ected operation. ------------------------------ -- Convert_Discriminant_Ref -- ------------------------------ function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (Bound); B : Node_Id; D : Entity_Id; begin if Is_Entity_Name (Bound) and then Ekind (Entity (Bound)) = E_Discriminant then if Is_Task_Type (Ttyp) and then Has_Completion (Ttyp) then B := Make_Identifier (Loc, Chars (Entity (Bound))); Find_Direct_Name (B); elsif Is_Protected_Type (Ttyp) then D := First_Discriminant (Ttyp); while Chars (D) /= Chars (Entity (Bound)) loop Next_Discriminant (D); end loop; B := New_Reference_To (Discriminal (D), Loc); else B := New_Reference_To (Discriminal (Entity (Bound)), Loc); end if; elsif Nkind (Bound) = N_Attribute_Reference then return Bound; else B := New_Copy_Tree (Bound); end if; return Make_Attribute_Reference (Loc, Attribute_Name => Name_Pos, Prefix => New_Occurrence_Of (Etype (Bound), Loc), Expressions => New_List (B)); end Convert_Discriminant_Ref; -- Start of processing for Family_Offset begin return Make_Op_Subtract (Loc, Left_Opnd => Convert_Discriminant_Ref (Hi), Right_Opnd => Convert_Discriminant_Ref (Lo)); end Family_Offset; ----------------- -- Family_Size -- ----------------- function Family_Size (Loc : Source_Ptr; Hi : Node_Id; Lo : Node_Id; Ttyp : Entity_Id) return Node_Id is Ityp : Entity_Id; begin if Is_Task_Type (Ttyp) then Ityp := RTE (RE_Task_Entry_Index); else Ityp := RTE (RE_Protected_Entry_Index); end if; return Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Ityp, Loc), Attribute_Name => Name_Max, Expressions => New_List ( Make_Op_Add (Loc, Left_Opnd => Family_Offset (Loc, Hi, Lo, Ttyp), Right_Opnd => Make_Integer_Literal (Loc, 1)), Make_Integer_Literal (Loc, 0))); end Family_Size; ----------------------------------- -- Find_Task_Or_Protected_Pragma -- ----------------------------------- function Find_Task_Or_Protected_Pragma (T : Node_Id; P : Name_Id) return Node_Id is N : Node_Id; begin N := First (Visible_Declarations (T)); while Present (N) loop if Nkind (N) = N_Pragma then if Chars (N) = P then return N; elsif P = Name_Priority and then Chars (N) = Name_Interrupt_Priority then return N; else Next (N); end if; else Next (N); end if; end loop; N := First (Private_Declarations (T)); while Present (N) loop if Nkind (N) = N_Pragma then if Chars (N) = P then return N; elsif P = Name_Priority and then Chars (N) = Name_Interrupt_Priority then return N; else Next (N); end if; else Next (N); end if; end loop; raise Program_Error; end Find_Task_Or_Protected_Pragma; ------------------------------- -- First_Protected_Operation -- ------------------------------- function First_Protected_Operation (D : List_Id) return Node_Id is First_Op : Node_Id; begin First_Op := First (D); while Present (First_Op) and then Nkind (First_Op) /= N_Subprogram_Body and then Nkind (First_Op) /= N_Entry_Body loop Next (First_Op); end loop; return First_Op; end First_Protected_Operation; -------------------------------- -- Index_Constant_Declaration -- -------------------------------- function Index_Constant_Declaration (N : Node_Id; Index_Id : Entity_Id; Prot : Entity_Id) return List_Id is Loc : constant Source_Ptr := Sloc (N); Decls : constant List_Id := New_List; Index_Con : constant Entity_Id := Entry_Index_Constant (Index_Id); Index_Typ : Entity_Id; Hi : Node_Id := Type_High_Bound (Etype (Index_Id)); Lo : Node_Id := Type_Low_Bound (Etype (Index_Id)); function Replace_Discriminant (Bound : Node_Id) return Node_Id; -- The bounds of the entry index may depend on discriminants, so each -- declaration of an entry_index_constant must have its own subtype -- declaration, using the local renaming of the object discriminant. -------------------------- -- Replace_Discriminant -- -------------------------- function Replace_Discriminant (Bound : Node_Id) return Node_Id is begin if Nkind (Bound) = N_Identifier and then Ekind (Entity (Bound)) = E_Constant and then Present (Discriminal_Link (Entity (Bound))) then return Make_Identifier (Loc, Chars (Entity (Bound))); else return Duplicate_Subexpr (Bound); end if; end Replace_Discriminant; -- Start of processing for Index_Constant_Declaration begin Set_Discriminal_Link (Index_Con, Index_Id); if Is_Entity_Name ( Original_Node (Discrete_Subtype_Definition (Parent (Index_Id)))) then -- Simple case: entry family is given by a subtype mark, and index -- constant has the same type, no replacement needed. Index_Typ := Etype (Index_Id); else Hi := Replace_Discriminant (Hi); Lo := Replace_Discriminant (Lo); Index_Typ := Make_Defining_Identifier (Loc, New_Internal_Name ('J')); Append ( Make_Subtype_Declaration (Loc, Defining_Identifier => Index_Typ, Subtype_Indication => Make_Subtype_Indication (Loc, Subtype_Mark => New_Occurrence_Of (Base_Type (Etype (Index_Id)), Loc), Constraint => Make_Range_Constraint (Loc, Range_Expression => Make_Range (Loc, Lo, Hi)))), Decls); end if; Append ( Make_Object_Declaration (Loc, Defining_Identifier => Index_Con, Constant_Present => True, Object_Definition => New_Occurrence_Of (Index_Typ, Loc), Expression => Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Index_Typ, Loc), Attribute_Name => Name_Val, Expressions => New_List ( Make_Op_Add (Loc, Left_Opnd => Make_Op_Subtract (Loc, Left_Opnd => Make_Identifier (Loc, Name_uE), Right_Opnd => Entry_Index_Expression (Loc, Defining_Identifier (N), Empty, Prot)), Right_Opnd => Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Index_Typ, Loc), Attribute_Name => Name_Pos, Expressions => New_List ( Make_Attribute_Reference (Loc, Prefix => New_Reference_To (Index_Typ, Loc), Attribute_Name => Name_First))))))), Decls); return Decls; end Index_Constant_Declaration; -------------------------------- -- Make_Initialize_Protection -- -------------------------------- function Make_Initialize_Protection (Protect_Rec : Entity_Id) return List_Id is Loc : constant Source_Ptr := Sloc (Protect_Rec); P_Arr : Entity_Id; Pdef : Node_Id; Pdec : Node_Id; Ptyp : constant Node_Id := Corresponding_Concurrent_Type (Protect_Rec); Args : List_Id; L : constant List_Id := New_List; Has_Entry : constant Boolean := Has_Entries (Ptyp); Restricted : constant Boolean := Restricted_Profile; begin -- We may need two calls to properly initialize the object, one to -- Initialize_Protection, and possibly one to Install_Handlers if we -- have a pragma Attach_Handler. -- Get protected declaration. In the case of a task type declaration, -- this is simply the parent of the protected type entity. In the single -- protected object declaration, this parent will be the implicit type, -- and we can find the corresponding single protected object declaration -- by searching forward in the declaration list in the tree. -- Is the test for N_Single_Protected_Declaration needed here??? Nodes -- of this type should have been removed during semantic analysis. Pdec := Parent (Ptyp); while Nkind (Pdec) /= N_Protected_Type_Declaration and then Nkind (Pdec) /= N_Single_Protected_Declaration loop Next (Pdec); end loop; -- Now we can find the object definition from this declaration Pdef := Protected_Definition (Pdec); -- Build the parameter list for the call. Note that _Init is the name -- of the formal for the object to be initialized, which is the task -- value record itself. Args := New_List; -- Object parameter. This is a pointer to the object of type -- Protection used by the GNARL to control the protected object. Append_To (Args, Make_Attribute_Reference (Loc, Prefix => Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name_uInit), Selector_Name => Make_Identifier (Loc, Name_uObject)), Attribute_Name => Name_Unchecked_Access)); -- Priority parameter. Set to Unspecified_Priority unless there is a -- priority pragma, in which case we take the value from the pragma, -- or there is an interrupt pragma and no priority pragma, and we -- set the ceiling to Interrupt_Priority'Last, an implementation- -- defined value, see D.3(10). if Present (Pdef) and then Has_Priority_Pragma (Pdef) then Append_To (Args, Duplicate_Subexpr_No_Checks (Expression (First (Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (Pdef, Name_Priority)))))); elsif Has_Interrupt_Handler (Ptyp) or else Has_Attach_Handler (Ptyp) then -- When no priority is specified but an xx_Handler pragma is, -- we default to System.Interrupts.Default_Interrupt_Priority, -- see D.3(10). Append_To (Args, New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc)); else Append_To (Args, New_Reference_To (RTE (RE_Unspecified_Priority), Loc)); end if; if Has_Entry or else Has_Interrupt_Handler (Ptyp) or else Has_Attach_Handler (Ptyp) or else (Ada_Version >= Ada_05 and then Present (Interface_List (Parent (Ptyp)))) then -- Compiler_Info parameter. This parameter allows entry body -- procedures and barrier functions to be called from the runtime. -- It is a pointer to the record generated by the compiler to -- represent the protected object. if Has_Entry or else not Restricted then Append_To (Args, Make_Attribute_Reference (Loc, Prefix => Make_Identifier (Loc, Name_uInit), Attribute_Name => Name_Address)); end if; if Has_Entry then -- Entry_Bodies parameter. This is a pointer to an array of -- pointers to the entry body procedures and barrier functions of -- the object. If the protected type has no entries this object -- will not exist; in this case, pass a null. P_Arr := Entry_Bodies_Array (Ptyp); Append_To (Args, Make_Attribute_Reference (Loc, Prefix => New_Reference_To (P_Arr, Loc), Attribute_Name => Name_Unrestricted_Access)); if Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False or else Number_Entries (Ptyp) > 1 or else (Has_Attach_Handler (Ptyp) and then not Restricted) then -- Find index mapping function (clumsy but ok for now) while Ekind (P_Arr) /= E_Function loop Next_Entity (P_Arr); end loop; Append_To (Args, Make_Attribute_Reference (Loc, Prefix => New_Reference_To (P_Arr, Loc), Attribute_Name => Name_Unrestricted_Access)); end if; elsif not Restricted then Append_To (Args, Make_Null (Loc)); Append_To (Args, Make_Null (Loc)); end if; if Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False or else Number_Entries (Ptyp) > 1 or else (Has_Attach_Handler (Ptyp) and then not Restricted) then Append_To (L, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( RTE (RE_Initialize_Protection_Entries), Loc), Parameter_Associations => Args)); elsif not Has_Entry and then Restricted then Append_To (L, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( RTE (RE_Initialize_Protection), Loc), Parameter_Associations => Args)); else Append_To (L, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To ( RTE (RE_Initialize_Protection_Entry), Loc), Parameter_Associations => Args)); end if; else Append_To (L, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc), Parameter_Associations => Args)); end if; if Has_Attach_Handler (Ptyp) then -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to -- make the following call: -- Install_Handlers (_object, -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access)); -- or, in the case of Ravenscar: -- Install_Handlers -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access)); declare Args : constant List_Id := New_List; Table : constant List_Id := New_List; Ritem : Node_Id := First_Rep_Item (Ptyp); begin if not Restricted then -- Appends the _object argument Append_To (Args, Make_Attribute_Reference (Loc, Prefix => Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name_uInit), Selector_Name => Make_Identifier (Loc, Name_uObject)), Attribute_Name => Name_Unchecked_Access)); end if; -- Build the Attach_Handler table argument while Present (Ritem) loop if Nkind (Ritem) = N_Pragma and then Chars (Ritem) = Name_Attach_Handler then declare Handler : constant Node_Id := First (Pragma_Argument_Associations (Ritem)); Interrupt : constant Node_Id := Next (Handler); Expr : constant Node_Id := Expression (Interrupt); begin Append_To (Table, Make_Aggregate (Loc, Expressions => New_List ( Unchecked_Convert_To (RTE (RE_System_Interrupt_Id), Expr), Make_Attribute_Reference (Loc, Prefix => Make_Selected_Component (Loc, Make_Identifier (Loc, Name_uInit), Duplicate_Subexpr_No_Checks (Expression (Handler))), Attribute_Name => Name_Access)))); end; end if; Next_Rep_Item (Ritem); end loop; -- Append the table argument we just built Append_To (Args, Make_Aggregate (Loc, Table)); -- Append the Install_Handler call to the statements Append_To (L, Make_Procedure_Call_Statement (Loc, Name => New_Reference_To (RTE (RE_Install_Handlers), Loc), Parameter_Associations => Args)); end; end if; return L; end Make_Initialize_Protection; --------------------------- -- Make_Task_Create_Call -- --------------------------- function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (Task_Rec); Name : Node_Id; Tdef : Node_Id; Tdec : Node_Id; Ttyp : Node_Id; Tnam : Name_Id; Args : List_Id; Ecount : Node_Id; begin Ttyp := Corresponding_Concurrent_Type (Task_Rec); Tnam := Chars (Ttyp); -- Get task declaration. In the case of a task type declaration, this is -- simply the parent of the task type entity. In the single task -- declaration, this parent will be the implicit type, and we can find -- the corresponding single task declaration by searching forward in the -- declaration list in the tree. -- Is the test for N_Single_Task_Declaration needed here??? Nodes of -- this type should have been removed during semantic analysis. Tdec := Parent (Ttyp); while Nkind (Tdec) /= N_Task_Type_Declaration and then Nkind (Tdec) /= N_Single_Task_Declaration loop Next (Tdec); end loop; -- Now we can find the task definition from this declaration Tdef := Task_Definition (Tdec); -- Build the parameter list for the call. Note that _Init is the name -- of the formal for the object to be initialized, which is the task -- value record itself. Args := New_List; -- Priority parameter. Set to Unspecified_Priority unless there is a -- priority pragma, in which case we take the value from the pragma. if Present (Tdef) and then Has_Priority_Pragma (Tdef) then Append_To (Args, Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name_uInit), Selector_Name => Make_Identifier (Loc, Name_uPriority))); else Append_To (Args, New_Reference_To (RTE (RE_Unspecified_Priority), Loc)); end if; -- Optional Stack parameter if Restricted_Profile then -- If the stack has been preallocated by the expander then -- pass its address. Otherwise, pass a null address. if Preallocated_Stacks_On_Target then Append_To (Args, Make_Attribute_Reference (Loc, Prefix => Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name_uInit), Selector_Name => Make_Identifier (Loc, Name_uStack)), Attribute_Name => Name_Address)); else Append_To (Args, New_Reference_To (RTE (RE_Null_Address), Loc)); end if; end if; -- Size parameter. If no Storage_Size pragma is present, then -- the size is taken from the taskZ variable for the type, which -- is either Unspecified_Size, or has been reset by the use of -- a Storage_Size attribute definition clause. If a pragma is -- present, then the size is taken from the _Size field of the -- task value record, which was set from the pragma value. if Present (Tdef) and then Has_Storage_Size_Pragma (Tdef) then Append_To (Args, Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name_uInit), Selector_Name => Make_Identifier (Loc, Name_uSize))); else Append_To (Args, New_Reference_To (Storage_Size_Variable (Ttyp), Loc)); end if; -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a -- Task_Info pragma, in which case we take the value from the pragma. if Present (Tdef) and then Has_Task_Info_Pragma (Tdef) then Append_To (Args, Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name_uInit), Selector_Name => Make_Identifier (Loc, Name_uTask_Info))); else Append_To (Args, New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc)); end if; if not Restricted_Profile then -- Number of entries. This is an expression of the form: -- -- n + _Init.a'Length + _Init.a'B'Length + ... -- -- where a,b... are the entry family names for the task definition Ecount := Build_Entry_Count_Expression ( Ttyp, Component_Items (Component_List ( Type_Definition (Parent ( Corresponding_Record_Type (Ttyp))))), Loc); Append_To (Args, Ecount); -- Master parameter. This is a reference to the _Master parameter of -- the initialization procedure, except in the case of the pragma -- Restrictions (No_Task_Hierarchy) where the value is fixed to 3. -- See comments in System.Tasking.Initialization.Init_RTS for the -- value 3. if Restriction_Active (No_Task_Hierarchy) = False then Append_To (Args, Make_Identifier (Loc, Name_uMaster)); else Append_To (Args, Make_Integer_Literal (Loc, 3)); end if; end if; -- State parameter. This is a pointer to the task body procedure. The -- required value is obtained by taking the address of the task body -- procedure and converting it (with an unchecked conversion) to the -- type required by the task kernel. For further details, see the -- description of Expand_Task_Body Append_To (Args, Unchecked_Convert_To (RTE (RE_Task_Procedure_Access), Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Get_Task_Body_Procedure (Ttyp), Loc), Attribute_Name => Name_Address))); -- Discriminants parameter. This is just the address of the task -- value record itself (which contains the discriminant values Append_To (Args, Make_Attribute_Reference (Loc, Prefix => Make_Identifier (Loc, Name_uInit), Attribute_Name => Name_Address)); -- Elaborated parameter. This is an access to the elaboration Boolean Append_To (Args, Make_Attribute_Reference (Loc, Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')), Attribute_Name => Name_Unchecked_Access)); -- Chain parameter. This is a reference to the _Chain parameter of -- the initialization procedure. Append_To (Args, Make_Identifier (Loc, Name_uChain)); -- Task name parameter. Take this from the _Task_Id parameter to the -- init call unless there is a Task_Name pragma, in which case we take -- the value from the pragma. if Present (Tdef) and then Has_Task_Name_Pragma (Tdef) then Append_To (Args, New_Copy ( Expression (First ( Pragma_Argument_Associations ( Find_Task_Or_Protected_Pragma (Tdef, Name_Task_Name)))))); else Append_To (Args, Make_Identifier (Loc, Name_uTask_Name)); end if; -- Created_Task parameter. This is the _Task_Id field of the task -- record value Append_To (Args, Make_Selected_Component (Loc, Prefix => Make_Identifier (Loc, Name_uInit), Selector_Name => Make_Identifier (Loc, Name_uTask_Id))); if Restricted_Profile then Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc); else Name := New_Reference_To (RTE (RE_Create_Task), Loc); end if; return Make_Procedure_Call_Statement (Loc, Name => Name, Parameter_Associations => Args); end Make_Task_Create_Call; ------------------------------ -- Next_Protected_Operation -- ------------------------------ function Next_Protected_Operation (N : Node_Id) return Node_Id is Next_Op : Node_Id; begin Next_Op := Next (N); while Present (Next_Op) and then Nkind (Next_Op) /= N_Subprogram_Body and then Nkind (Next_Op) /= N_Entry_Body loop Next (Next_Op); end loop; return Next_Op; end Next_Protected_Operation; -------------------------- -- Parameter_Block_Pack -- -------------------------- function Parameter_Block_Pack (Loc : Source_Ptr; Blk_Typ : Entity_Id; Actuals : List_Id; Formals : List_Id; Decls : List_Id; Stmts : List_Id) return Node_Id is Actual : Entity_Id; Expr : Node_Id := Empty; Formal : Entity_Id; Has_Param : Boolean := False; P : Entity_Id; Params : List_Id; Temp_Asn : Node_Id; Temp_Nam : Node_Id; begin Actual := First (Actuals); Formal := Defining_Identifier (First (Formals)); Params := New_List; while Present (Actual) loop if Is_By_Copy_Type (Etype (Actual)) then -- Generate: -- Jnn : aliased <formal-type> Temp_Nam := Make_Defining_Identifier (Loc, New_Internal_Name ('J')); Append_To (Decls, Make_Object_Declaration (Loc, Aliased_Present => True, Defining_Identifier => Temp_Nam, Object_Definition => New_Reference_To (Etype (Formal), Loc))); if Ekind (Formal) /= E_Out_Parameter then -- Generate: -- Jnn := <actual> Temp_Asn := New_Reference_To (Temp_Nam, Loc); Set_Assignment_OK (Temp_Asn); Append_To (Stmts, Make_Assignment_Statement (Loc, Name => Temp_Asn, Expression => New_Copy_Tree (Actual))); end if; -- Generate: -- Jnn'unchecked_access Append_To (Params, Make_Attribute_Reference (Loc, Attribute_Name => Name_Unchecked_Access, Prefix => New_Reference_To (Temp_Nam, Loc))); Has_Param := True; -- The controlling parameter is omitted else if not Is_Controlling_Actual (Actual) then Append_To (Params, Make_Reference (Loc, New_Copy_Tree (Actual))); Has_Param := True; end if; end if; Next_Actual (Actual); Next_Formal_With_Extras (Formal); end loop; if Has_Param then Expr := Make_Aggregate (Loc, Params); end if; -- Generate: -- P : Ann := ( -- J1'unchecked_access; -- <actual2>'reference; -- ...); P := Make_Defining_Identifier (Loc, New_Internal_Name ('P')); Append_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => P, Object_Definition => New_Reference_To (Blk_Typ, Loc), Expression => Expr)); return P; end Parameter_Block_Pack; ---------------------------- -- Parameter_Block_Unpack -- ---------------------------- function Parameter_Block_Unpack (Loc : Source_Ptr; P : Entity_Id; Actuals : List_Id; Formals : List_Id) return List_Id is Actual : Entity_Id; Asnmt : Node_Id; Formal : Entity_Id; Has_Asnmt : Boolean := False; Result : constant List_Id := New_List; begin Actual := First (Actuals); Formal := Defining_Identifier (First (Formals)); while Present (Actual) loop if Is_By_Copy_Type (Etype (Actual)) and then Ekind (Formal) /= E_In_Parameter then -- Generate: -- <actual> := P.<formal>; Asnmt := Make_Assignment_Statement (Loc, Name => New_Copy (Actual), Expression => Make_Explicit_Dereference (Loc, Make_Selected_Component (Loc, Prefix => New_Reference_To (P, Loc), Selector_Name => Make_Identifier (Loc, Chars (Formal))))); Set_Assignment_OK (Name (Asnmt)); Append_To (Result, Asnmt); Has_Asnmt := True; end if; Next_Actual (Actual); Next_Formal_With_Extras (Formal); end loop; if Has_Asnmt then return Result; else return New_List (Make_Null_Statement (Loc)); end if; end Parameter_Block_Unpack; ---------------------- -- Set_Discriminals -- ---------------------- procedure Set_Discriminals (Dec : Node_Id) is D : Entity_Id; Pdef : Entity_Id; D_Minal : Entity_Id; begin pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration); Pdef := Defining_Identifier (Dec); if Has_Discriminants (Pdef) then D := First_Discriminant (Pdef); while Present (D) loop D_Minal := Make_Defining_Identifier (Sloc (D), Chars => New_External_Name (Chars (D), 'D')); Set_Ekind (D_Minal, E_Constant); Set_Etype (D_Minal, Etype (D)); Set_Scope (D_Minal, Pdef); Set_Discriminal (D, D_Minal); Set_Discriminal_Link (D_Minal, D); Next_Discriminant (D); end loop; end if; end Set_Discriminals; ----------------- -- Set_Privals -- ----------------- procedure Set_Privals (Dec : Node_Id; Op : Node_Id; Loc : Source_Ptr; After_Barrier : Boolean := False) is P_Decl : Node_Id; P_Id : Entity_Id; Priv : Entity_Id; Def : Node_Id; Body_Ent : Entity_Id; For_Barrier : constant Boolean := Nkind (Op) = N_Entry_Body and then not After_Barrier; Prec_Decl : constant Node_Id := Parent (Corresponding_Record_Type (Defining_Identifier (Dec))); Prec_Def : constant Entity_Id := Type_Definition (Prec_Decl); Obj_Decl : Node_Id; P_Subtype : Entity_Id; Assoc_L : constant Elist_Id := New_Elmt_List; Op_Id : Entity_Id; begin pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration); pragma Assert (Nkind (Op) = N_Subprogram_Body or else Nkind (Op) = N_Entry_Body); Def := Protected_Definition (Dec); if Present (Private_Declarations (Def)) then P_Decl := First (Private_Declarations (Def)); while Present (P_Decl) loop if Nkind (P_Decl) = N_Component_Declaration then P_Id := Defining_Identifier (P_Decl); if For_Barrier then Priv := Make_Defining_Identifier (Loc, Chars => New_External_Name (Chars (P_Id), 'P')); else Priv := Make_Defining_Identifier (Loc, Chars => New_External_Name (Chars (P_Id))); end if; Set_Ekind (Priv, E_Variable); Set_Etype (Priv, Etype (P_Id)); Set_Scope (Priv, Scope (P_Id)); Set_Esize (Priv, Esize (Etype (P_Id))); Set_Alignment (Priv, Alignment (Etype (P_Id))); -- If the type of the component is an itype, we must create a -- new itype for the corresponding prival in each protected -- operation, to avoid scoping problems. We create new itypes -- by copying the tree for the component definition. if Is_Itype (Etype (P_Id)) then Append_Elmt (P_Id, Assoc_L); Append_Elmt (Priv, Assoc_L); if Nkind (Op) = N_Entry_Body then Op_Id := Defining_Identifier (Op); else Op_Id := Defining_Unit_Name (Specification (Op)); end if; Discard_Node (New_Copy_Tree (P_Decl, Assoc_L, New_Scope => Op_Id)); end if; Set_Protected_Operation (P_Id, Op); Set_Prival (P_Id, Priv); end if; Next (P_Decl); end loop; end if; -- There is one more implicit private decl: the object itself. "prival" -- for this is attached to the protected body defining identifier. Body_Ent := Corresponding_Body (Dec); Priv := Make_Defining_Identifier (Sloc (Body_Ent), Chars => New_External_Name (Chars (Body_Ent), 'R')); -- Set the Etype to the implicit subtype of Protection created when -- the protected type declaration was expanded. This node will not -- be analyzed until it is used as the defining identifier for the -- renaming declaration in the protected operation body, and it will -- be needed in the references expanded before that body is expanded. -- Since the Protection field is aliased, set Is_Aliased as well. Obj_Decl := First (Component_Items (Component_List (Prec_Def))); while Chars (Defining_Identifier (Obj_Decl)) /= Name_uObject loop Next (Obj_Decl); end loop; P_Subtype := Etype (Defining_Identifier (Obj_Decl)); Set_Ekind (Priv, E_Variable); Set_Etype (Priv, P_Subtype); Set_Is_Aliased (Priv); Set_Object_Ref (Body_Ent, Priv); end Set_Privals; ---------------------------- -- Update_Prival_Subtypes -- ---------------------------- procedure Update_Prival_Subtypes (N : Node_Id) is function Process (N : Node_Id) return Traverse_Result; -- Update the etype of occurrences of privals whose etype does not -- match the current Etype of the prival entity itself. procedure Update_Array_Bounds (E : Entity_Id); -- Itypes generated for array expressions may depend on the -- determinants of the protected object, and need to be processed -- separately because they are not attached to the tree. procedure Update_Index_Types (N : Node_Id); -- Similarly, update the types of expressions in indexed components -- which may depend on other discriminants. ------------- -- Process -- ------------- function Process (N : Node_Id) return Traverse_Result is begin if Is_Entity_Name (N) then declare E : constant Entity_Id := Entity (N); begin if Present (E) and then (Ekind (E) = E_Constant or else Ekind (E) = E_Variable) and then Nkind (Parent (E)) = N_Object_Renaming_Declaration and then not Is_Scalar_Type (Etype (E)) and then Etype (N) /= Etype (E) then Set_Etype (N, Etype (Entity (Original_Node (N)))); Update_Index_Types (N); elsif Present (E) and then Ekind (E) = E_Constant and then Present (Discriminal_Link (E)) then Set_Etype (N, Etype (E)); end if; end; return OK; elsif Nkind (N) = N_Defining_Identifier or else Nkind (N) = N_Defining_Operator_Symbol or else Nkind (N) = N_Defining_Character_Literal then return Skip; elsif Nkind (N) = N_String_Literal then -- Array type, but bounds are constant return OK; elsif Nkind (N) = N_Object_Declaration and then Is_Itype (Etype (Defining_Identifier (N))) and then Is_Array_Type (Etype (Defining_Identifier (N))) then Update_Array_Bounds (Etype (Defining_Identifier (N))); return OK; -- For array components of discriminated records, use the base type -- directly, because it may depend indirectly on the discriminants of -- the protected type. -- Cleaner would be a systematic mechanism to compute actual subtypes -- of private components??? elsif Nkind (N) in N_Has_Etype and then Present (Etype (N)) and then Is_Array_Type (Etype (N)) and then Nkind (N) = N_Selected_Component and then Has_Discriminants (Etype (Prefix (N))) then Set_Etype (N, Base_Type (Etype (N))); Update_Index_Types (N); return OK; else if Nkind (N) in N_Has_Etype and then Present (Etype (N)) and then Is_Itype (Etype (N)) then if Is_Array_Type (Etype (N)) then Update_Array_Bounds (Etype (N)); elsif Is_Scalar_Type (Etype (N)) then Update_Prival_Subtypes (Type_Low_Bound (Etype (N))); Update_Prival_Subtypes (Type_High_Bound (Etype (N))); end if; end if; return OK; end if; end Process; ------------------------- -- Update_Array_Bounds -- ------------------------- procedure Update_Array_Bounds (E : Entity_Id) is Ind : Node_Id; begin Ind := First_Index (E); while Present (Ind) loop Update_Prival_Subtypes (Type_Low_Bound (Etype (Ind))); Update_Prival_Subtypes (Type_High_Bound (Etype (Ind))); Next_Index (Ind); end loop; end Update_Array_Bounds; ------------------------ -- Update_Index_Types -- ------------------------ procedure Update_Index_Types (N : Node_Id) is Indx1 : Node_Id; I_Typ : Node_Id; begin -- If the prefix has an actual subtype that is different from the -- nominal one, update the types of the indices, so that the proper -- constraints are applied. Do not apply this transformation to a -- packed array, where the index type is computed for a byte array -- and is different from the source index. if Nkind (Parent (N)) = N_Indexed_Component and then not Is_Bit_Packed_Array (Etype (Prefix (Parent (N)))) then Indx1 := First (Expressions (Parent (N))); I_Typ := First_Index (Etype (N)); while Present (Indx1) and then Present (I_Typ) loop if not Is_Entity_Name (Indx1) then Set_Etype (Indx1, Base_Type (Etype (I_Typ))); end if; Next (Indx1); Next_Index (I_Typ); end loop; end if; end Update_Index_Types; procedure Traverse is new Traverse_Proc; -- Start of processing for Update_Prival_Subtypes begin Traverse (N); end Update_Prival_Subtypes; end Exp_Ch9;
with STM32GD.I2C; with STM32_SVD; use STM32_SVD; package body Drivers.Si7060 is function Init return Boolean is begin return I2C.Write_Register (Address, 16#C4#, 2#0000_0001#); end Init; function Temperature_x100 (R : out Temperature_Type) return Boolean is M, LSB, MSB : Byte; begin if not I2C.Test (Address) then return False; end if; if I2C.Write_Register (Address, 16#C4#, 2#0000_0100#) and then I2C.Read_Register (Address, 16#C4#, M) and then (M and 2#0000_0010#) /= 0 and then I2C.Read_Register (Address, 16#C1#, MSB) and then I2C.Read_Register (Address, 16#C2#, LSB) and then I2C.Write_Register (Address, 16#C4#, 2#0000_0001#) then R := Temperature_Type ( 5500 + (Integer (MSB and 2#0111_1111#) * 256 + Integer (LSB) - 16384) * 10 / 16); return True; end if; return False; end Temperature_x100; end Drivers.Si7060;
package Int_Binary_Tree is type T is limited private; function Is_In_Tree( Tree: in T; Number: in Integer ) return Boolean; procedure Insert( Tree: in out T; Number: in Integer ); procedure Remove( Tree: in out T; Number: in Integer ); procedure Print( Tree: in T ); procedure Debug_Print( Tree: in T ); private type Tree_Node; type Tree_Node_Ptr is access Tree_Node; type Tree_Node is record Data : Integer; Left : Tree_Node_Ptr; Right : Tree_Node_Ptr; end record; type T is record Root : Tree_Node_Ptr; end record; end Int_Binary_Tree;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- L I B . W R I T -- -- -- -- S p e c -- -- -- -- $Revision$ -- -- -- Copyright (C) 1992-2001 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. -- -- -- ------------------------------------------------------------------------------ -- This package contains the routines for writing the library information package Lib.Writ is ----------------------------------- -- Format of Library Information -- ----------------------------------- -- Note: the contents of the ali file are summarized in the GNAT -- user's guide, so if any non-trivial changes are made to this -- section, they should be reflected in the user's guide. -- This section describes the format of the library information that is -- associated with object files. The exact method of this association is -- potentially implementation dependent and is described and implemented -- in package From the point of view of the description here, all we -- need to know is that the information is represented as a string of -- characters that is somehow associated with an object file, and can be -- retrieved. If no library information exists for a given object file, -- then we take this as equivalent to the non-existence of the object -- file, as if source file has not been previously compiled. -- The library information is written as a series of lines of the form: -- Key_Character parameter parameter ... ------------------ -- Header Lines -- ------------------ -- The initial header lines in the file give information about the -- compilation environment, and identify other special information -- such as main program parameters. -- ---------------- -- -- V Version -- -- ---------------- -- V "xxxxxxxxxxxxxxxx" -- -- This line indicates the library output version, as defined in -- Gnatvsn. It ensures that separate object modules of a program are -- consistent. It has to be changed if anything changes which would -- affect successful binding of separately compiled modules. -- Examples of such changes are modifications in the format of the -- library info described in this package, or modifications to -- calling sequences, or to the way that data is represented. -- --------------------- -- -- M Main Program -- -- --------------------- -- M type [priority] [T=time-slice] W=? -- This line appears only if the main unit for this file is -- suitable for use as a main program. The parameters are: -- type -- P for a parameterless procedure -- F for a function returning a value of integral type -- (used for writing a main program returning an exit status) -- priority -- Present only if there was a valid pragma Priority in the -- corresponding unit to set the main task priority. It is -- an unsigned decimal integer. -- T=time-slice -- Present only if there was a valid pragma Time_Slice in the -- corresponding unit. It is an unsigned decimal integer in -- the range 0 .. 10**9 giving the time slice value in units -- of milliseconds. The actual significance of this parameter -- is target dependent. -- W=? -- This parameter indicates the wide character encoding -- method used when compiling the main program file. The ? -- character is the single character used in the -gnatW? -- switch. This is used to provide the default wide-character -- encoding for Wide_Text_IO files. -- ----------------- -- -- A Argument -- -- ----------------- -- A argument -- One of these lines appears for each of the arguments present -- in the call to the gnat1 program. This can be used if it is -- necessary to reconstruct this call (e.g. for fix and continue) -- ------------------- -- -- P Parameters -- -- ------------------- -- P <<parameters>> -- Indicates various information that applies to the compilation -- of the corresponding source unit. Parameters is a sequence of -- zero or more two letter codes that indicate configuration -- pragmas and other parameters that apply: -- -- Present if the unit uses tasking directly or indirectly and -- has one or more valid xxx_Policy pragmas that apply to the unit. -- The arguments are as follows: -- -- CE Compilation errors. If this is present it means that the -- ali file resulted from a compilation with the -gnatQ -- switch set, and illegalities were detected. The ali -- file contents may not be completely reliable, but the -- format will be correct and complete. Note that NO is -- always present if CE is present. -- -- FD Configuration pragmas apply to all the units in this -- file specifying a possibly non-standard floating point -- format (VAX float with Long_Float using D_Float) -- -- FG Configuration pragmas apply to all the units in this -- file specifying a possibly non-standard floating point -- format (VAX float with Long_Float using G_Float) -- -- FI Configuration pragmas apply to all the units in this -- file specifying a possibly non-standard floating point -- format (IEEE Float) -- -- Lx A valid Locking_Policy pragma applies to all the units -- in this file, where x is the first character (upper case) -- of the policy name (e.g. 'C' for Ceiling_Locking) -- -- NO No object. This flag indicates that the units in this -- file were not compiled to produce an object. This can -- occur as a result of the use of -gnatc, or if no object -- can be produced (e.g. when a package spec is compiled -- instead of the body, or a subunit on its own). -- -- NR No_Run_Time pragma in effect for all units in this file -- -- NS Normalize_Scalars pragma in effect for all units in -- this file -- -- Qx A valid Queueing_Policy pragma applies to all the units -- in this file, where x is the first character (upper case) -- of the policy name (e.g. 'P' for Priority_Queueing). -- -- Tx A valid Task_Dispatching_Policy pragma applies to all -- the units in this file, where x is the first character -- (upper case) of the corresponding policy name (e.g. 'F' -- for FIFO_Within_Priorities). -- -- UA Unreserve_All_Interrupts pragma was processed in one or -- more units in this file -- -- UX Generated code contains unit exception table pointer -- (i.e. it uses zero-cost exceptions, and there is at -- least one subprogram present). -- -- ZX Units in this file use zero-cost exceptions and have -- generated exception tables. If ZX is not present, the -- longjmp/setjmp exception scheme is in use. -- -- Note that language defined units never output policy (Lx,Tx,Qx) -- parameters. Language defined units must correctly handle all -- possible cases. These values are checked for consistency by the -- binder and then copied to the generated binder output file. -- --------------------- -- -- R Restrictions -- -- --------------------- -- R <<restriction-characters>> -- This line records information regarding restrictions. The -- parameter is a string of characters, one for each entry in -- Restrict.Partition_Restrictions, in order. There are three -- settings possible settings for each restriction: -- r Restricted. Unit was compiled under control of a pragma -- Restrictions for the corresponding restriction. In -- this case the unit certainly does not violate the -- Restriction, since this would have been detected by -- the compiler. -- n Not used. The unit was not compiled under control of a -- pragma Restrictions for the corresponding restriction, -- and does not make any use of the referenced feature. -- v Violated. The unit was not compiled uner control of a -- pragma Restrictions for the corresponding restriction, -- and it does indeed use the referenced feature. -- This information is used in the binder to check consistency, -- i.e. to detect cases where one unit has "r" and another unit -- has "v", which is not permitted, since these restrictions -- are partition-wide. ---------------------------- -- Compilation Unit Lines -- ---------------------------- -- Following these header lines, a set of information lines appears for -- each compilation unit that appears in the corresponding object file. -- In particular, when a package body or subprogram body is compiled, -- there will be two sets of information, one for the spec and one for -- the body. with the entry for the body appearing first. This is the -- only case in which a single ALI file contains more than one unit (in -- particular note that subunits do *not* count as compilation units for -- this purpose, and generate no library information, since they are -- inlined). -- -------------------- -- -- U Unit Header -- -- -------------------- -- The lines for each compilation unit have the following form. -- U unit-name source-name version <<attributes>> -- -- This line identifies the unit to which this section of the -- library information file applies. The first three parameters are -- the unit name in internal format, as described in package Uname, -- and the name of the source file containing the unit. -- -- Version is the version given as eight hexadecimal characters -- with upper case letters. This value is the exclusive or of the -- source checksums of the unit and all its semantically dependent -- units. -- -- The <<attributes>> are a series of two letter codes indicating -- information about the unit: -- -- DE Dynamic Elaboration. This unit was compiled with the -- dynamic elaboration model, as set by either the -gnatE -- switch or pragma Elaboration_Checks (Dynamic). -- -- EB Unit has pragma Elaborate_Body -- -- EE Elaboration entity is present which must be set true when -- the unit is elaborated. The name of the elaboration entity -- is formed from the unit name in the usual way. If EE is -- present, then this boolean must be set True as part of the -- elaboration processing routine generated by the binder. -- Note that EE can be set even if NE is set. This happens -- when the boolean is needed solely for checking for the -- case of access before elaboration. -- -- GE Unit is a generic declaration, or corresponding body -- -- IL Unit source uses a style with identifiers in all lower -- IU case (IL) or all upper case (IU). If the standard mixed- -- case usage is detected, or the compiler cannot determine -- the style, then no I parameter will appear. -- -- IS Initialize_Scalars pragma applies to this unit -- -- KM Unit source uses a style with keywords in mixed case -- KU (KM) or all upper case (KU). If the standard lower-case -- usage is detected, or the compiler cannot determine the -- style, then no K parameter will appear. -- -- NE Unit has no elaboration routine. All subprogram bodies -- and specs are in this category. Package bodies and specs -- may or may not have NE set, depending on whether or not -- elaboration code is required. Set if N_Compilation_Unit -- node has flag Has_No_Elaboration_Code set. -- -- PK Unit is package, rather than a subprogram -- -- PU Unit has pragma Pure -- -- PR Unit has pragma Preelaborate -- -- RA Unit declares a Remote Access to Class-Wide (RACW) type -- -- RC Unit has pragma Remote_Call_Interface -- -- RT Unit has pragma Remote_Types -- -- SP Unit has pragma Shared_Passive. -- -- SU Unit is a subprogram, rather than a package -- -- The attributes may appear in any order, separated by spaces. -- --------------------- -- -- W Withed Units -- -- --------------------- -- Following each U line, is a series of lines of the form -- W unit-name [source-name lib-name] [E] [EA] [ED] -- -- One of these lines is present for each unit that is mentioned in -- an explicit with clause by the current unit. The first parameter -- is the unit name in internal format. The second parameter is the -- file name of the file that must be compiled to compile this unit -- (which is usually the file for the body, except for packages -- which have no body). The third parameter is the file name of the -- library information file that contains the results of compiling -- this unit. The optional modifiers are used as follows: -- -- E pragma Elaborate applies to this unit -- -- EA pragma Elaborate_All applies to this unit -- -- ED Elaborate_All_Desirable set for this unit, which means -- that there is no Elaborate_All, but the analysis suggests -- that Program_Error may be raised if the Elaborate_All -- conditions cannot be satisfied. The binder will attempt -- to treat ED as EA if it can. -- -- The parameter source-name and lib-name are omitted for the case -- of a generic unit compiled with earlier versions of GNAT which -- did not generate object or ali files for generics. --------------------- -- Reference Lines -- --------------------- -- The reference lines contain information about references from -- any of the units in the compilation (including, body version -- and version attributes, linker options pragmas and source -- dependencies. -- ----------------------- -- -- L Linker_Options -- -- ----------------------- -- Following the unit information is an optional series of lines that -- indicates the usage of pragma Linker_Options. For each appearence -- of pragma Linker_Actions in any of the units for which unit lines -- are present, a line of the form: -- L "string" -- where string is the string from the unit line enclosed in quotes. -- Within the quotes the following can occur: -- c graphic characters in range 20-7E other than " or { -- "" indicating a single " character -- {hh} indicating a character whose code is hex hh (0-9,A-F) -- {00} [ASCII.NUL] is used as a separator character -- to separate multiple arguments of a single -- Linker_Options pragma. -- For further details, see Stringt.Write_String_Table_Entry. Note -- that wide characters in the form {hhhh} cannot be produced, since -- pragma Linker_Option accepts only String, not Wide_String. -- ------------------------------------ -- -- E External Version References -- -- ------------------------------------ -- One of these lines is present for each use of 'Body_Version or -- 'Version in any of the units of the compilation. These are used -- by the linker to determine which version symbols must be output. -- The format is simply: -- E name -- where name is the external name, i.e. the unit name with either -- a S or a B for spec or body version referenced (Body_Version -- always references the body, Version references the Spec, except -- in the case of a reference to a subprogram with no separate spec). -- Upper half and wide character codes are encoded using the same -- method as in Namet (Uhh for upper half, Whhhh for wide character, -- where hh are hex digits). -- --------------------- -- -- D Dependencies -- -- --------------------- -- The dependency lines indicate the source files on which the compiled -- units depend. This is used by the binder for consistency checking. -- These lines are also referenced by the cross-reference information. -- D source-name time-stamp checksum [subunit-name] line:file-name -- The time-stamp field contains the time stamp of the -- corresponding source file. See types.ads for details on -- time stamp representation. -- The checksum is an 8-hex digit representation of the source -- file checksum, with letters given in lower case. -- The subunit name is present only if the dependency line is for -- a subunit. It contains the fully qualified name of the subunit -- in all lower case letters. -- The line:file-name entry is present only if a Source_Reference -- pragma appeared in the source file identified by source-name. -- In this case, it gives the information from this pragma. Note -- that this allows cross-reference information to be related back -- to the original file. Note: the reason the line number comes -- first is that a leading digit immediately identifies this as -- a Source_Reference entry, rather than a subunit-name. -- A line number of zero for line: in this entry indicates that -- there is more than one source reference pragma. In this case, -- the line numbers in the cross-reference are correct, and refer -- to the original line number, but there is no information that -- allows a reader of the ALI file to determine the exact mapping -- of physical line numbers back to the original source. -- Note: blank lines are ignored when the library information is -- read, and separate sections of the file are separated by blank -- lines to ease readability. Blanks between fields are also -- ignored. -- For entries corresponding to files that were not present (and -- thus resulted in error messages), or for files that are not -- part of the dependency set, both the time stamp and checksum -- are set to all zero characters. These dummy entries are ignored -- by the binder in dependency checking, but must be present for -- proper interpretation of the cross-reference data. -------------------------- -- Cross-Reference Data -- -------------------------- -- The cross-reference data follows the dependency lines. See -- the spec of Lib.Xref for details on the format of this data. ----------------- -- Subprograms -- ----------------- procedure Ensure_System_Dependency; -- This procedure ensures that a dependency is created on system.ads. -- Even if there is no semantic dependency, Targparm has read the -- file to acquire target parameters, so we need a source dependency. procedure Write_ALI (Object : Boolean); -- This procedure writes the library information for the current main unit -- The Object parameter is true if an object file is created, and false -- otherwise. -- -- Note: in the case where we are not generating code (-gnatc mode), this -- routine only writes an ALI file if it cannot find an existing up to -- date ALI file. If it *can* find an existing up to date ALI file, then -- it reads this file and sets the Lib.Compilation_Arguments table from -- the A lines in this file. end Lib.Writ;
-- Copyright (c) 2015-2017 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Ada.Characters.Wide_Wide_Latin_1; with Ada.Wide_Wide_Text_IO; with League.Strings; with Incr.Ada_Lexers; with Incr.Lexers.Batch_Lexers; procedure Ada_Lexer_Test is type File_Source is new Incr.Lexers.Batch_Lexers.Abstract_Source with record Text : League.Strings.Universal_String; Index : Positive := 1; end record; overriding function Get_Next (Self : not null access File_Source) return Wide_Wide_Character; function Debug_Image (Value : Incr.Ada_Lexers.Token) return Wide_Wide_String; function Debug_Image (Value : Incr.Ada_Lexers.Token) return Wide_Wide_String is use Incr.Ada_Lexers; begin case Value is when Arrow_Token => return "Arrow_Token"; when Double_Dot_Token => return "Double_Dot_Token"; when Double_Star_Token => return "Double_Star_Token"; when Assignment_Token => return "Assignment_Token"; when Inequality_Token => return "Inequality_Token"; when Greater_Or_Equal_Token => return "Greater_Or_Equal_Token"; when Less_Or_Equal_Token => return "Less_Or_Equal_Token"; when Left_Label_Token => return "Left_Label_Token"; when Right_Label_Token => return "Right_Label_Token"; when Box_Token => return "Box_Token"; when Ampersand_Token => return "Ampersand_Token"; when Apostrophe_Token => return "Apostrophe_Token"; when Left_Parenthesis_Token => return "Left_Parenthesis_Token"; when Right_Parenthesis_Token => return "Right_Parenthesis_Token"; when Star_Token => return "Star_Token"; when Plus_Token => return "Plus_Token"; when Comma_Token => return "Comma_Token"; when Hyphen_Token => return "Hyphen_Token"; when Dot_Token => return "Dot_Token"; when Slash_Token => return "Slash_Token"; when Colon_Token => return "Colon_Token"; when Semicolon_Token => return "Semicolon_Token"; when Less_Token => return "Less_Token"; when Equal_Token => return "Equal_Token"; when Greater_Token => return "Greater_Token"; when Vertical_Line_Token => return "Vertical_Line_Token"; when Identifier_Token => return "Identifier_Token"; when Numeric_Literal_Token => return "Numeric_Literal_Token"; when Character_Literal_Token => return "Character_Literal_Token"; when String_Literal_Token => return "String_Literal_Token"; when Comment_Token => return "Comment_Token"; when Space_Token => return "Space_Token"; when New_Line_Token => return "New_Line_Token"; when Error_Token => return "Error_Token"; when Abort_Token => return "Abort_Token"; when Abs_Token => return "Abs_Token"; when Abstract_Token => return "Abstract_Token"; when Accept_Token => return "Accept_Token"; when Access_Token => return "Access_Token"; when Aliased_Token => return "Aliased_Token"; when All_Token => return "All_Token"; when And_Token => return "And_Token"; when Array_Token => return "Array_Token"; when At_Token => return "At_Token"; when Begin_Token => return "Begin_Token"; when Body_Token => return "Body_Token"; when Case_Token => return "Case_Token"; when Constant_Token => return "Constant_Token"; when Declare_Token => return "Declare_Token"; when Delay_Token => return "Delay_Token"; when Delta_Token => return "Delta_Token"; when Digits_Token => return "Digits_Token"; when Do_Token => return "Do_Token"; when Else_Token => return "Else_Token"; when Elsif_Token => return "Elsif_Token"; when End_Token => return "End_Token"; when Entry_Token => return "Entry_Token"; when Exception_Token => return "Exception_Token"; when Exit_Token => return "Exit_Token"; when For_Token => return "For_Token"; when Function_Token => return "Function_Token"; when Generic_Token => return "Generic_Token"; when Goto_Token => return "Goto_Token"; when If_Token => return "If_Token"; when In_Token => return "In_Token"; when Interface_Token => return "Interface_Token"; when Is_Token => return "Is_Token"; when Limited_Token => return "Limited_Token"; when Loop_Token => return "Loop_Token"; when Mod_Token => return "Mod_Token"; when New_Token => return "New_Token"; when Not_Token => return "Not_Token"; when Null_Token => return "Null_Token"; when Of_Token => return "Of_Token"; when Or_Token => return "Or_Token"; when Others_Token => return "Others_Token"; when Out_Token => return "Out_Token"; when Overriding_Token => return "Overriding_Token"; when Package_Token => return "Package_Token"; when Pragma_Token => return "Pragma_Token"; when Private_Token => return "Private_Token"; when Procedure_Token => return "Procedure_Token"; when Protected_Token => return "Protected_Token"; when Raise_Token => return "Raise_Token"; when Range_Token => return "Range_Token"; when Record_Token => return "Record_Token"; when Rem_Token => return "Rem_Token"; when Renames_Token => return "Renames_Token"; when Requeue_Token => return "Requeue_Token"; when Return_Token => return "Return_Token"; when Reverse_Token => return "Reverse_Token"; when Select_Token => return "Select_Token"; when Separate_Token => return "Separate_Token"; when Some_Token => return "Some_Token"; when Subtype_Token => return "Subtype_Token"; when Synchronized_Token => return "Synchronized_Token"; when Tagged_Token => return "Tagged_Token"; when Task_Token => return "Task_Token"; when Terminate_Token => return "Terminate_Token"; when Then_Token => return "Then_Token"; when Type_Token => return "Type_Token"; when Until_Token => return "Until_Token"; when Use_Token => return "Use_Token"; when When_Token => return "When_Token"; when While_Token => return "While_Token"; when With_Token => return "With_Token"; when Xor_Token => return "Xor_Token"; when others => return Token'Wide_Wide_Image (Value); end case; end Debug_Image; -------------- -- Get_Next -- -------------- overriding function Get_Next (Self : not null access File_Source) return Wide_Wide_Character is begin if Self.Index < Self.Text.Length then return Result : constant Wide_Wide_Character := Self.Text.Element (Self.Index).To_Wide_Wide_Character do Self.Index := Self.Index + 1; end return; else return Incr.Lexers.Batch_Lexers.End_Of_Input; end if; end Get_Next; use type Incr.Ada_Lexers.Token; Token : Incr.Ada_Lexers.Token; Source : aliased File_Source; Batch_Lexer : constant Incr.Lexers.Batch_Lexers.Batch_Lexer_Access := new Incr.Ada_Lexers.Batch_Lexer; begin while not Ada.Wide_Wide_Text_IO.End_Of_File loop declare Line : constant Wide_Wide_String := Ada.Wide_Wide_Text_IO.Get_Line; begin Source.Text.Append (Line); Source.Text.Append (Ada.Characters.Wide_Wide_Latin_1.LF); end; end loop; Batch_Lexer.Set_Source (Source'Unchecked_Access); loop Batch_Lexer.Get_Token (Token); exit when Token = 0; Ada.Wide_Wide_Text_IO.Put (Debug_Image (Token)); Ada.Wide_Wide_Text_IO.Put (' '); Ada.Wide_Wide_Text_IO.Put_Line (Batch_Lexer.Get_Text.To_Wide_Wide_String); end loop; end Ada_Lexer_Test;
------------------------------------------------------------------------------ -- -- -- GNAT LIBRARY COMPONENTS -- -- -- -- ADA.CONTAINERS.RED_BLACK_TREES.GENERIC_SET_OPERATIONS -- -- -- -- B o d y -- -- -- -- Copyright (C) 2004-2021, 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. -- -- -- -- -- -- -- -- -- -- -- -- 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/>. -- -- -- -- This unit was originally developed by Matthew J Heaney. -- ------------------------------------------------------------------------------ with System; use type System.Address; package body Ada.Containers.Red_Black_Trees.Generic_Set_Operations is pragma Warnings (Off, "variable ""Busy*"" is not referenced"); pragma Warnings (Off, "variable ""Lock*"" is not referenced"); -- See comment in Ada.Containers.Helpers ----------------------- -- Local Subprograms -- ----------------------- procedure Clear (Tree : in out Tree_Type); function Copy (Source : Tree_Type) return Tree_Type; ----------- -- Clear -- ----------- procedure Clear (Tree : in out Tree_Type) is use type Helpers.Tamper_Counts; pragma Assert (Tree.TC = (Busy => 0, Lock => 0)); Root : Node_Access := Tree.Root; pragma Warnings (Off, Root); begin Tree.Root := null; Tree.First := null; Tree.Last := null; Tree.Length := 0; Delete_Tree (Root); end Clear; ---------- -- Copy -- ---------- function Copy (Source : Tree_Type) return Tree_Type is Target : Tree_Type; begin if Source.Length = 0 then return Target; end if; Target.Root := Copy_Tree (Source.Root); Target.First := Tree_Operations.Min (Target.Root); Target.Last := Tree_Operations.Max (Target.Root); Target.Length := Source.Length; return Target; end Copy; ---------------- -- Difference -- ---------------- procedure Difference (Target : in out Tree_Type; Source : Tree_Type) is Tgt : Node_Access; Src : Node_Access; Compare : Integer; begin TC_Check (Target.TC); if Target'Address = Source'Address then Clear (Target); return; end if; if Source.Length = 0 then return; end if; Tgt := Target.First; Src := Source.First; loop if Tgt = null then exit; end if; if Src = null then exit; end if; -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare Lock_Target : With_Lock (Target.TC'Unrestricted_Access); Lock_Source : With_Lock (Source.TC'Unrestricted_Access); begin if Is_Less (Tgt, Src) then Compare := -1; elsif Is_Less (Src, Tgt) then Compare := 1; else Compare := 0; end if; end; if Compare < 0 then Tgt := Tree_Operations.Next (Tgt); elsif Compare > 0 then Src := Tree_Operations.Next (Src); else declare X : Node_Access := Tgt; begin Tgt := Tree_Operations.Next (Tgt); Tree_Operations.Delete_Node_Sans_Free (Target, X); Free (X); end; Src := Tree_Operations.Next (Src); end if; end loop; end Difference; function Difference (Left, Right : Tree_Type) return Tree_Type is begin if Left'Address = Right'Address then return Tree_Type'(others => <>); -- Empty set end if; if Left.Length = 0 then return Tree_Type'(others => <>); -- Empty set end if; if Right.Length = 0 then return Copy (Left); end if; -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare Lock_Left : With_Lock (Left.TC'Unrestricted_Access); Lock_Right : With_Lock (Right.TC'Unrestricted_Access); Tree : Tree_Type; L_Node : Node_Access; R_Node : Node_Access; Dst_Node : Node_Access; pragma Warnings (Off, Dst_Node); begin L_Node := Left.First; R_Node := Right.First; loop if L_Node = null then exit; end if; if R_Node = null then while L_Node /= null loop Insert_With_Hint (Dst_Tree => Tree, Dst_Hint => null, Src_Node => L_Node, Dst_Node => Dst_Node); L_Node := Tree_Operations.Next (L_Node); end loop; exit; end if; if Is_Less (L_Node, R_Node) then Insert_With_Hint (Dst_Tree => Tree, Dst_Hint => null, Src_Node => L_Node, Dst_Node => Dst_Node); L_Node := Tree_Operations.Next (L_Node); elsif Is_Less (R_Node, L_Node) then R_Node := Tree_Operations.Next (R_Node); else L_Node := Tree_Operations.Next (L_Node); R_Node := Tree_Operations.Next (R_Node); end if; end loop; return Tree; exception when others => Delete_Tree (Tree.Root); raise; end; end Difference; ------------------ -- Intersection -- ------------------ procedure Intersection (Target : in out Tree_Type; Source : Tree_Type) is Tgt : Node_Access; Src : Node_Access; Compare : Integer; begin if Target'Address = Source'Address then return; end if; TC_Check (Target.TC); if Source.Length = 0 then Clear (Target); return; end if; Tgt := Target.First; Src := Source.First; while Tgt /= null and then Src /= null loop -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare Lock_Target : With_Lock (Target.TC'Unrestricted_Access); Lock_Source : With_Lock (Source.TC'Unrestricted_Access); begin if Is_Less (Tgt, Src) then Compare := -1; elsif Is_Less (Src, Tgt) then Compare := 1; else Compare := 0; end if; end; if Compare < 0 then declare X : Node_Access := Tgt; begin Tgt := Tree_Operations.Next (Tgt); Tree_Operations.Delete_Node_Sans_Free (Target, X); Free (X); end; elsif Compare > 0 then Src := Tree_Operations.Next (Src); else Tgt := Tree_Operations.Next (Tgt); Src := Tree_Operations.Next (Src); end if; end loop; while Tgt /= null loop declare X : Node_Access := Tgt; begin Tgt := Tree_Operations.Next (Tgt); Tree_Operations.Delete_Node_Sans_Free (Target, X); Free (X); end; end loop; end Intersection; function Intersection (Left, Right : Tree_Type) return Tree_Type is begin if Left'Address = Right'Address then return Copy (Left); end if; -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare Lock_Left : With_Lock (Left.TC'Unrestricted_Access); Lock_Right : With_Lock (Right.TC'Unrestricted_Access); Tree : Tree_Type; L_Node : Node_Access; R_Node : Node_Access; Dst_Node : Node_Access; pragma Warnings (Off, Dst_Node); begin L_Node := Left.First; R_Node := Right.First; loop if L_Node = null then exit; end if; if R_Node = null then exit; end if; if Is_Less (L_Node, R_Node) then L_Node := Tree_Operations.Next (L_Node); elsif Is_Less (R_Node, L_Node) then R_Node := Tree_Operations.Next (R_Node); else Insert_With_Hint (Dst_Tree => Tree, Dst_Hint => null, Src_Node => L_Node, Dst_Node => Dst_Node); L_Node := Tree_Operations.Next (L_Node); R_Node := Tree_Operations.Next (R_Node); end if; end loop; return Tree; exception when others => Delete_Tree (Tree.Root); raise; end; end Intersection; --------------- -- Is_Subset -- --------------- function Is_Subset (Subset : Tree_Type; Of_Set : Tree_Type) return Boolean is begin if Subset'Address = Of_Set'Address then return True; end if; if Subset.Length > Of_Set.Length then return False; end if; -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare Lock_Subset : With_Lock (Subset.TC'Unrestricted_Access); Lock_Of_Set : With_Lock (Of_Set.TC'Unrestricted_Access); Subset_Node : Node_Access; Set_Node : Node_Access; begin Subset_Node := Subset.First; Set_Node := Of_Set.First; loop if Set_Node = null then return Subset_Node = null; end if; if Subset_Node = null then return True; end if; if Is_Less (Subset_Node, Set_Node) then return False; end if; if Is_Less (Set_Node, Subset_Node) then Set_Node := Tree_Operations.Next (Set_Node); else Set_Node := Tree_Operations.Next (Set_Node); Subset_Node := Tree_Operations.Next (Subset_Node); end if; end loop; end; end Is_Subset; ------------- -- Overlap -- ------------- function Overlap (Left, Right : Tree_Type) return Boolean is begin if Left'Address = Right'Address then return Left.Length /= 0; end if; -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare Lock_Left : With_Lock (Left.TC'Unrestricted_Access); Lock_Right : With_Lock (Right.TC'Unrestricted_Access); L_Node : Node_Access; R_Node : Node_Access; begin L_Node := Left.First; R_Node := Right.First; loop if L_Node = null or else R_Node = null then return False; end if; if Is_Less (L_Node, R_Node) then L_Node := Tree_Operations.Next (L_Node); elsif Is_Less (R_Node, L_Node) then R_Node := Tree_Operations.Next (R_Node); else return True; end if; end loop; end; end Overlap; -------------------------- -- Symmetric_Difference -- -------------------------- procedure Symmetric_Difference (Target : in out Tree_Type; Source : Tree_Type) is Tgt : Node_Access; Src : Node_Access; New_Tgt_Node : Node_Access; pragma Warnings (Off, New_Tgt_Node); Compare : Integer; begin if Target'Address = Source'Address then Clear (Target); return; end if; Tgt := Target.First; Src := Source.First; loop if Tgt = null then while Src /= null loop Insert_With_Hint (Dst_Tree => Target, Dst_Hint => null, Src_Node => Src, Dst_Node => New_Tgt_Node); Src := Tree_Operations.Next (Src); end loop; return; end if; if Src = null then return; end if; -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare Lock_Target : With_Lock (Target.TC'Unrestricted_Access); Lock_Source : With_Lock (Source.TC'Unrestricted_Access); begin if Is_Less (Tgt, Src) then Compare := -1; elsif Is_Less (Src, Tgt) then Compare := 1; else Compare := 0; end if; end; if Compare < 0 then Tgt := Tree_Operations.Next (Tgt); elsif Compare > 0 then Insert_With_Hint (Dst_Tree => Target, Dst_Hint => Tgt, Src_Node => Src, Dst_Node => New_Tgt_Node); Src := Tree_Operations.Next (Src); else declare X : Node_Access := Tgt; begin Tgt := Tree_Operations.Next (Tgt); Tree_Operations.Delete_Node_Sans_Free (Target, X); Free (X); end; Src := Tree_Operations.Next (Src); end if; end loop; end Symmetric_Difference; function Symmetric_Difference (Left, Right : Tree_Type) return Tree_Type is begin if Left'Address = Right'Address then return Tree_Type'(others => <>); -- Empty set end if; if Right.Length = 0 then return Copy (Left); end if; if Left.Length = 0 then return Copy (Right); end if; -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare Lock_Left : With_Lock (Left.TC'Unrestricted_Access); Lock_Right : With_Lock (Right.TC'Unrestricted_Access); Tree : Tree_Type; L_Node : Node_Access; R_Node : Node_Access; Dst_Node : Node_Access; pragma Warnings (Off, Dst_Node); begin L_Node := Left.First; R_Node := Right.First; loop if L_Node = null then while R_Node /= null loop Insert_With_Hint (Dst_Tree => Tree, Dst_Hint => null, Src_Node => R_Node, Dst_Node => Dst_Node); R_Node := Tree_Operations.Next (R_Node); end loop; exit; end if; if R_Node = null then while L_Node /= null loop Insert_With_Hint (Dst_Tree => Tree, Dst_Hint => null, Src_Node => L_Node, Dst_Node => Dst_Node); L_Node := Tree_Operations.Next (L_Node); end loop; exit; end if; if Is_Less (L_Node, R_Node) then Insert_With_Hint (Dst_Tree => Tree, Dst_Hint => null, Src_Node => L_Node, Dst_Node => Dst_Node); L_Node := Tree_Operations.Next (L_Node); elsif Is_Less (R_Node, L_Node) then Insert_With_Hint (Dst_Tree => Tree, Dst_Hint => null, Src_Node => R_Node, Dst_Node => Dst_Node); R_Node := Tree_Operations.Next (R_Node); else L_Node := Tree_Operations.Next (L_Node); R_Node := Tree_Operations.Next (R_Node); end if; end loop; return Tree; exception when others => Delete_Tree (Tree.Root); raise; end; end Symmetric_Difference; ----------- -- Union -- ----------- procedure Union (Target : in out Tree_Type; Source : Tree_Type) is Hint : Node_Access; procedure Process (Node : Node_Access); pragma Inline (Process); procedure Iterate is new Tree_Operations.Generic_Iteration (Process); ------------- -- Process -- ------------- procedure Process (Node : Node_Access) is begin Insert_With_Hint (Dst_Tree => Target, Dst_Hint => Hint, -- use node most recently inserted as hint Src_Node => Node, Dst_Node => Hint); end Process; -- Start of processing for Union begin if Target'Address = Source'Address then return; end if; -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare Lock_Source : With_Lock (Source.TC'Unrestricted_Access); begin Iterate (Source); end; end Union; function Union (Left, Right : Tree_Type) return Tree_Type is begin if Left'Address = Right'Address then return Copy (Left); end if; if Left.Length = 0 then return Copy (Right); end if; if Right.Length = 0 then return Copy (Left); end if; declare Lock_Left : With_Lock (Left.TC'Unrestricted_Access); Lock_Right : With_Lock (Right.TC'Unrestricted_Access); Tree : Tree_Type := Copy (Left); Hint : Node_Access; procedure Process (Node : Node_Access); pragma Inline (Process); procedure Iterate is new Tree_Operations.Generic_Iteration (Process); ------------- -- Process -- ------------- procedure Process (Node : Node_Access) is begin Insert_With_Hint (Dst_Tree => Tree, Dst_Hint => Hint, -- use node most recently inserted as hint Src_Node => Node, Dst_Node => Hint); end Process; -- Start of processing for Union begin Iterate (Right); return Tree; exception when others => Delete_Tree (Tree.Root); raise; end; end Union; end Ada.Containers.Red_Black_Trees.Generic_Set_Operations;
with Ada.Text_IO; use Ada.Text_IO; --05.02.2018 20:19:12 --http://www.radford.edu/nokie/classes/320/Tour/procs.funcs.html procedure demo is procedure printlines (numLines, numChars : Natural; c : Character) is begin for i in 1 .. numLines loop for j in 1 .. numChars loop -- put('x'); Put (c); end loop; New_Line; end loop; end printlines; --procedure half(given: natural) is --begin -- Put_Line(given / 2 ); --end half; -- no need for declare here upper : constant Integer := 12; begin printlines (2, upper, '='); -- do something printlines (3, 20, '-'); -- half (10) ; end demo;
-- C94002B.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 A MASTER UNIT, WHICH ALLOCATES TASKS OF A GLOBAL ACCESS -- TYPE MAY TERMINATE WITHOUT WAITING FOR THE ALLOCATED TASKS TO -- TERMINATE. -- SUBTESTS ARE: -- (A) A SIMPLE TASK ALLOCATOR, IN A BLOCK. -- (B) A RECORD OF TASK ALLOCATOR, IN A SUBPROGRAM. -- (C) A RECORD OF ARRAY OF TASK ALLOCATOR, IN A TASK BODY. -- JRK 10/8/81 -- SPS 11/2/82 -- SPS 11/21/82 -- JRK 11/29/82 -- TBN 1/20/86 REPLACED WITH C94006A-B.ADA AFTER LOWERING THE DELAY -- VALUES, AND MODIFYING THE COMMENTS. -- PWN 09/11/94 REMOVED PRAGMA PRIORITY FOR ADA 9X. with Impdef; WITH REPORT; USE REPORT; WITH SYSTEM; USE SYSTEM; PROCEDURE C94002B IS TASK TYPE TT IS ENTRY E; END TT; TASK BODY TT IS BEGIN ACCEPT E; ACCEPT E; END TT; BEGIN TEST ("C94002B", "CHECK THAT A MASTER UNIT, WHICH ALLOCATES " & "TASKS OF A GLOBAL ACCESS TYPE MAY TERMINATE " & "WITHOUT WAITING FOR THE ALLOCATED TASKS TO " & "TERMINATE"); -------------------------------------------------- DECLARE -- (A) TYPE A_T IS ACCESS TT; A1 : A_T; BEGIN -- (A) DECLARE A2 : A_T; BEGIN A2 := NEW TT; A2.ALL.E; A1 := A2; END; IF A1.ALL'TERMINATED THEN FAILED ("ALLOCATED TASK PREMATURELY TERMINATED - (A)"); END IF; A1.ALL.E; END; -- (A) -------------------------------------------------- DECLARE -- (B) I : INTEGER; FUNCTION F RETURN INTEGER IS TYPE RT IS RECORD T : TT; END RECORD; TYPE ART IS ACCESS RT; AR1 : ART; PROCEDURE P (AR : OUT ART) IS AR2 : ART; BEGIN AR2 := NEW RT; AR2.T.E; AR := AR2; END P; BEGIN P (AR1); IF AR1.T'TERMINATED THEN FAILED ("ALLOCATED TASK PREMATURELY TERMINATED " & "- (B)"); END IF; AR1.T.E; RETURN 0; END F; BEGIN -- (B) I := F; END; -- (B) -------------------------------------------------- DECLARE -- (C) LOOP_COUNT : INTEGER := 0; CUT_OFF : CONSTANT := 60; -- DELAY. TASK TSK IS ENTRY ENT; END TSK; TASK BODY TSK IS LOOP_COUNT1 : INTEGER := 0; CUT_OFF1 : CONSTANT := 60; -- DELAY. TYPE RAT; TYPE ARAT IS ACCESS RAT; TYPE ARR IS ARRAY (1..1) OF TT; TYPE RAT IS RECORD A : ARAT; T : ARR; END RECORD; ARA1 : ARAT; TASK TSK1 IS ENTRY ENT1 (ARA : OUT ARAT); END TSK1; TASK BODY TSK1 IS ARA2 : ARAT; BEGIN ARA2 := NEW RAT; ARA2.T(1).E; ACCEPT ENT1 (ARA : OUT ARAT) DO ARA := ARA2; END ENT1; END TSK1; BEGIN TSK1.ENT1 (ARA1); WHILE NOT TSK1'TERMINATED AND LOOP_COUNT1 < CUT_OFF1 LOOP DELAY 1.0 * Impdef.One_Second; LOOP_COUNT1 := LOOP_COUNT1 + 1; END LOOP; IF LOOP_COUNT1 >= CUT_OFF1 THEN FAILED ("DEPENDENT TASK TSK1 NOT TERMINATED " & "WITHIN ONE MINUTE - (C)"); END IF; IF ARA1.T(1)'TERMINATED THEN FAILED ("ALLOCATED TASK PREMATURELY TERMINATED " & "- (C)"); END IF; ARA1.T(1).E; END TSK; BEGIN -- (C) WHILE NOT TSK'TERMINATED AND LOOP_COUNT < CUT_OFF LOOP DELAY 2.0 * Impdef.One_Second; LOOP_COUNT := LOOP_COUNT + 1; END LOOP; IF LOOP_COUNT >= CUT_OFF THEN FAILED ("DEPENDENT TASK TSK NOT TERMINATED WITHIN " & "TWO MINUTES - (C)"); END IF; END; -- (C) -------------------------------------------------- RESULT; END C94002B;
-------------------------------------------------------------------------------- -- An Ada implementation of the Advent Of Code 2018 -- -- -- -- Day 2: Inventory Management System -- -- -- -- The following is an MCW example (outside of data) for day 2 of AOC 2018. -- -- See: <https://adventofcode.com/2018> for the whole event. -- -------------------------------------------------------------------------------- with Ada.Text_IO; with Ada.Strings.Unbounded; procedure Day02 is package ASU renames Ada.Strings.Unbounded; -- for convenience purpose type US_Array is array(Positive range <>) of ASU.Unbounded_String; -- The IDs in the input data are all the same length, so we could use a -- fixed-length String array, but it would not be very generic, and it would -- not be suited for examples either. type Natural_Couple is array(1..2) of Natural; -- This data structure will be used to store two things: -- * IDs that have exactly 2 of any letter and exactly 3 of any letter; -- * the absolute count of IDs for the previous item. -- I could/should use a record for that, but meh, later maybe. type Character_Count is array(Character range 'a' .. 'z') of Natural; -- An array indexed on characters that will be used to count occurrences. -- This is not very generic (cough), but it will do for the input. -- Creates the "String" array from the file name function Read_Input(file_name : in String) return US_Array is -- Tail-call recursion to create the final array. function Read_Input_Rec(input : in Ada.Text_IO.File_Type; acc : in US_Array) return US_Array is begin if Ada.Text_IO.End_Of_File(input) then return acc; else return Read_Input_Rec ( input, acc & (1 => ASU.To_Unbounded_String(Ada.Text_IO.Get_Line(input))) ); end if; end Read_Input_Rec; F : Ada.Text_IO.File_Type; acc : US_Array(1 .. 0); begin Ada.Text_IO.Open ( File => F, Mode => Ada.Text_IO.In_File, Name => file_name ); declare result : US_Array := Read_Input_Rec(F, acc); begin Ada.Text_IO.Close(F); return result; end; end Read_Input; -- the number that have an ID containing exactly two of any letter and then -- separately counting those with exactly three of any letter. -- You can multiply those two counts together to get a rudimentary checksum. function Checksum(nc : Natural_Couple) return Natural is begin return nc(1) * nc(2); end Checksum; function Common_Part(left, right : in String) return String is function Common_Part_Rec(li, ri : in Positive; acc : in String) return String is begin if li > left'Last then return acc; else return Common_Part_Rec ( li+1, ri+1, acc & (if left(li) = right(ri) then (1 => left(li)) else "") ); end if; end Common_Part_Rec; begin return Common_Part_Rec(left'First, right'First, ""); end Common_Part; function Part_1(input : in US_Array) return Natural is total_count : Natural_Couple := (0, 0); begin for ID of input loop declare counts : Character_Count := (others => 0); current_count : Natural_Couple := (0, 0); begin for C of ASU.To_String(ID) loop counts(C) := counts(C) + 1; end loop; for count of counts loop if count = 2 then current_count(1) := 1; elsif count = 3 then current_count(2) := 1; end if; exit when current_count = (1, 1); end loop; total_count(1) := total_count(1) + current_count(1); total_count(2) := total_count(2) + current_count(2); end; end loop; return Checksum(total_count); end Part_1; function Part_2(input : in US_Array) return String is begin for I in input'Range loop for J in I+1 .. input'Last loop declare common : constant String := Common_Part ( ASU.To_String(input(I)), ASU.To_String(input(J)) ); begin if common'Length = ASU.Length(input(I)) - 1 then return common; end if; end; end loop; end loop; return ""; end Part_2; input : constant US_Array := Read_Input("input/day02.txt"); begin Ada.Text_IO.Put_Line("What is the checksum for your list of box IDs?"); Ada.Text_IO.Put_Line(Natural'Image(Part_1(input))); Ada.Text_IO.New_Line; Ada.Text_IO.Put_Line("What letters are common between the two correct box IDs?"); Ada.Text_IO.Put_Line(Part_2(input)); end Day02;
with ObjectPack, AbstractStrategyCombinatorPackage, IntrospectorPackage, StrategyPackage; use ObjectPack, AbstractStrategyCombinatorPackage, IntrospectorPackage, StrategyPackage; package OneStrategy is ARG : constant Integer := 0; type One is new AbstractStrategyCombinator and Object with null record; ---------------------------------------------------------------------------- -- Object implementation ---------------------------------------------------------------------------- function toString(o: One) return String; ---------------------------------------------------------------------------- -- Strategy implementation ---------------------------------------------------------------------------- function visitLight(str:access One; any: ObjectPtr; intro: access Introspector'Class) return ObjectPtr; function visit(str: access One; intro: access Introspector'Class) return Integer; ---------------------------------------------------------------------------- procedure makeOne(o : in out One; v: StrategyPtr); function newOne(v: StrategyPtr) return StrategyPtr; ---------------------------------------------------------------------------- end OneStrategy;
-- This file is covered by the Internet Software Consortium (ISC) License -- Reference: ../../License.txt package Spatial_Data.Well_Known_Binary is type WKB_Byte is mod 2 ** 8; type WKB_Chain is array (Positive range <>) of WKB_Byte; WKB_INVALID : exception; function Translate_WKB (WKBinary : String) return Geometry; function produce_WKT (WKBinary : CT.Text) return String; private type WKB_exponent is mod 2 ** 11; type WKB_Identifier is mod 2 ** 12; type WKB_Hex32 is mod 2 ** 32; type WKB_IEEE754_Hex is mod 2 ** 64; type WKB_Endianness is (big_endian, little_endian); subtype WKB_Identifier_Chain is WKB_Chain (1 .. 4); subtype WKB_Double_Precision_Chain is WKB_Chain (1 .. 8); subtype WKB_Shape_Point_Chain is WKB_Chain (1 .. 16); function convert (nv : String) return WKB_Chain; function decode_endianness (value : WKB_Byte) return WKB_Endianness; function decode_hex32 (direction : WKB_Endianness; value : WKB_Identifier_Chain) return WKB_Hex32; function decode_identifier (direction : WKB_Endianness; value : WKB_Identifier_Chain) return WKB_Identifier; function get_collection_type (identifier : WKB_Identifier) return Collection_Type; function convert_to_IEEE754 (direction : WKB_Endianness; chain : WKB_Double_Precision_Chain) return Geometric_Real; function handle_coordinate (direction : WKB_Endianness; payload : WKB_Chain; marker : in out Natural) return Geometric_Real; function handle_new_point (payload : WKB_Chain; marker : in out Natural) return Geometric_Point; function handle_linestring (payload : WKB_Chain; marker : in out Natural) return Geometric_Line_String; function handle_polyrings (direction : WKB_Endianness; payload : WKB_Chain; marker : in out Natural) return Geometric_Ring; function handle_polygon (payload : WKB_Chain; marker : in out Natural) return Geometric_Polygon; procedure handle_unit_collection (flavor : Collection_Type; payload : WKB_Chain; marker : in out Natural; collection : in out Geometry); function round_to_16_digits (FP : Geometric_Real) return Geometric_Real; end Spatial_Data.Well_Known_Binary;
-- Copyright 2016-2021 Bartek thindil Jasicki -- -- This file is part of Steam Sky. -- -- Steam Sky 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. -- -- Steam Sky 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 Steam Sky. If not, see <http://www.gnu.org/licenses/>. with Ada.Strings; use Ada.Strings; with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Ada.Characters.Handling; use Ada.Characters.Handling; with Ada.Characters.Latin_1; use Ada.Characters.Latin_1; with DOM.Core; use DOM.Core; with DOM.Core.Documents; with DOM.Core.Nodes; use DOM.Core.Nodes; with DOM.Core.Elements; use DOM.Core.Elements; with Log; use Log; with Game; use Game; with Items; use Items; package body Help is procedure LoadHelp(Reader: Tree_Reader) is use Short_String; use Tiny_String; TmpHelp: Help_Data; NodesList: Node_List; HelpData: Document; Action: Data_Action; HelpIndex, HelpTitle: Unbounded_String; HelpNode: Node; begin HelpData := Get_Tree(Reader); NodesList := DOM.Core.Documents.Get_Elements_By_Tag_Name(HelpData, "entry"); Load_Help_Data : for I in 0 .. Length(NodesList) - 1 loop TmpHelp := (Index => Null_Unbounded_String, Text => Null_Unbounded_String); HelpNode := Item(NodesList, I); Action := (if Get_Attribute(HelpNode, "action")'Length > 0 then Data_Action'Value(Get_Attribute(HelpNode, "action")) else ADD); HelpIndex := To_Unbounded_String(Get_Attribute(HelpNode, "index")); HelpTitle := To_Unbounded_String(Get_Attribute(HelpNode, "title")); if Action in UPDATE | REMOVE then if not Help_Container.Contains(Help_List, HelpTitle) then raise Data_Loading_Error with "Can't " & To_Lower(Data_Action'Image(Action)) & " help '" & To_String(HelpTitle) & "', there no help with that title."; end if; elsif Help_Container.Contains(Help_List, HelpTitle) then raise Data_Loading_Error with "Can't add help '" & To_String(HelpTitle) & "', there is one with that title."; end if; if Action /= REMOVE then TmpHelp.Index := HelpIndex; if Action = UPDATE then TmpHelp := Help_List(HelpTitle); end if; if Has_Child_Nodes(HelpNode) then TmpHelp.Text := To_Unbounded_String(Node_Value(First_Child(HelpNode))); end if; if Action /= UPDATE then Help_Container.Include(Help_List, HelpTitle, TmpHelp); Log_Message("Help added: " & To_String(HelpTitle), EVERYTHING); else Help_List(HelpTitle) := TmpHelp; end if; else Help_Container.Exclude(Help_List, HelpTitle); Log_Message("Help removed: " & To_String(HelpTitle), EVERYTHING); end if; end loop Load_Help_Data; TmpHelp.Index := To_Unbounded_String("stats"); HelpTitle := To_Unbounded_String (Trim(Positive'Image(Positive(Help_List.Length) + 1), Left) & ". Attributes and skills"); TmpHelp.Text := To_Unbounded_String ("Here you will find information about all available attributes and skills in the game" & LF & LF & "{u}Attributes{/u}" & LF); for I in 1 .. Attributes_Amount loop declare Attribute: constant Attribute_Record := AttributesData_Container.Element (Container => Attributes_List, Index => I); begin Append (TmpHelp.Text, "{b}" & To_String(Attribute.Name) & "{/b}" & LF & " " & To_String(Attribute.Description) & LF & LF); end; end loop; Append(TmpHelp.Text, LF & "{u}Skills{/u}" & LF); for I in 1 .. Skills_Amount loop declare Skill: constant Skill_Record := SkillsData_Container.Element(Skills_List, I); begin Append (TmpHelp.Text, "{b}" & To_String(Skill.Name) & "{/b}" & LF & " {i}Related attribute:{/i} " & To_String (AttributesData_Container.Element (Attributes_List, Skill.Attribute) .Name) & LF); for Item of Items_List loop if Item.IType = To_Unbounded_String(To_String(Skill.Tool)) then Append (TmpHelp.Text, " {i}Training tool:{/i} " & (if Item.ShowType = Null_Unbounded_String then Item.IType else Item.ShowType) & LF); exit; end if; end loop; Append (TmpHelp.Text, " " & To_String(Skill.Description) & LF & LF); end; end loop; Help_List.Include(HelpTitle, TmpHelp); Log_Message("Help added: " & To_String(HelpTitle), EVERYTHING); end LoadHelp; end Help;
----------------------------------------------------------- -- -- -- SIGINT_HANDLER PACKAGE -- -- -- -- Copyright (c) 2017, John Leimon -- -- -- -- Permission to use, copy, modify, and/or 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. -- ----------------------------------------------------------- WITH ADA.INTERRUPTS.NAMES; USE ADA.INTERRUPTS.NAMES; PACKAGE SIGINT_HANDLER IS PROTECTED HANDLER IS PROCEDURE HANDLE; PRAGMA INTERRUPT_STATE (SIGINT, USER); PRAGMA INTERRUPT_HANDLER (HANDLE); PRAGMA ATTACH_HANDLER (HANDLE, SIGINT); END HANDLER; SIGINT : BOOLEAN := FALSE; END SIGINT_HANDLER;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- O S I N T -- -- -- -- 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. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Fmap; use Fmap; with Gnatvsn; use Gnatvsn; with Hostparm; with Namet; use Namet; with Opt; use Opt; with Output; use Output; with Sdefault; use Sdefault; with Table; with Targparm; use Targparm; with System.Case_Util; use System.Case_Util; with Unchecked_Conversion; with GNAT.HTable; package body Osint is Running_Program : Program_Type := Unspecified; -- comment required here ??? Program_Set : Boolean := False; -- comment required here ??? Std_Prefix : String_Ptr; -- Standard prefix, computed dynamically the first time Relocate_Path -- is called, and cached for subsequent calls. Empty : aliased String := ""; No_Dir : constant String_Ptr := Empty'Access; -- Used in Locate_File as a fake directory when Name is already an -- absolute path. ------------------------------------- -- Use of Name_Find and Name_Enter -- ------------------------------------- -- This package creates a number of source, ALI and object file names -- that are used to locate the actual file and for the purpose of -- message construction. These names need not be accessible by Name_Find, -- and can be therefore created by using routine Name_Enter. The files in -- question are file names with a prefix directory (ie the files not -- in the current directory). File names without a prefix directory are -- entered with Name_Find because special values might be attached to -- the various Info fields of the corresponding name table entry. ----------------------- -- Local Subprograms -- ----------------------- function Append_Suffix_To_File_Name (Name : Name_Id; Suffix : String) return Name_Id; -- Appends Suffix to Name and returns the new name function OS_Time_To_GNAT_Time (T : OS_Time) return Time_Stamp_Type; -- Convert OS format time to GNAT format time stamp function Concat (String_One : String; String_Two : String) return String; -- Concatenates 2 strings and returns the result of the concatenation function Executable_Prefix return String_Ptr; -- Returns the name of the root directory where the executable is stored. -- The executable must be located in a directory called "bin", or -- under root/lib/gcc-lib/..., or under root/libexec/gcc/... Thus, if -- the executable is stored in directory "/foo/bar/bin", this routine -- returns "/foo/bar/". Return "" if the location is not recognized -- as described above. function Update_Path (Path : String_Ptr) return String_Ptr; -- Update the specified path to replace the prefix with the location -- where GNAT is installed. See the file prefix.c in GCC for details. procedure Write_With_Check (A : Address; N : Integer); -- Writes N bytes from buffer starting at address A to file whose FD is -- stored in Output_FD, and whose file name is stored as a File_Name_Type -- in Output_File_Name. A check is made for disk full, and if this is -- detected, the file being written is deleted, and a fatal error is -- signalled. function Locate_File (N : File_Name_Type; T : File_Type; Dir : Natural; Name : String) return File_Name_Type; -- See if the file N whose name is Name exists in directory Dir. Dir is -- an index into the Lib_Search_Directories table if T = Library. -- Otherwise if T = Source, Dir is an index into the -- Src_Search_Directories table. Returns the File_Name_Type of the -- full file name if file found, or No_File if not found. function C_String_Length (S : Address) return Integer; -- Returns length of a C string. Returns zero for a null address function To_Path_String_Access (Path_Addr : Address; Path_Len : Integer) return String_Access; -- Converts a C String to an Ada String. Are we doing this to avoid -- withing Interfaces.C.Strings ??? ------------------------------ -- Other Local Declarations -- ------------------------------ EOL : constant Character := ASCII.LF; -- End of line character Number_File_Names : Int := 0; -- The total number of file names found on command line and placed in -- File_Names. Look_In_Primary_Directory_For_Current_Main : Boolean := False; -- When this variable is True, Find_File will only look in -- the Primary_Directory for the Current_Main file. -- This variable is always True for the compiler. -- It is also True for gnatmake, when the soucr name given -- on the command line has directory information. Current_Full_Source_Name : File_Name_Type := No_File; Current_Full_Source_Stamp : Time_Stamp_Type := Empty_Time_Stamp; Current_Full_Lib_Name : File_Name_Type := No_File; Current_Full_Lib_Stamp : Time_Stamp_Type := Empty_Time_Stamp; Current_Full_Obj_Name : File_Name_Type := No_File; Current_Full_Obj_Stamp : Time_Stamp_Type := Empty_Time_Stamp; -- Respectively full name (with directory info) and time stamp of -- the latest source, library and object files opened by Read_Source_File -- and Read_Library_Info. ------------------ -- Search Paths -- ------------------ Primary_Directory : constant := 0; -- This is index in the tables created below for the first directory to -- search in for source or library information files. This is the -- directory containing the latest main input file (a source file for -- the compiler or a library file for the binder). package Src_Search_Directories is new Table.Table ( Table_Component_Type => String_Ptr, Table_Index_Type => Natural, Table_Low_Bound => Primary_Directory, Table_Initial => 10, Table_Increment => 100, Table_Name => "Osint.Src_Search_Directories"); -- Table of names of directories in which to search for source (Compiler) -- files. This table is filled in the order in which the directories are -- to be searched, and then used in that order. package Lib_Search_Directories is new Table.Table ( Table_Component_Type => String_Ptr, Table_Index_Type => Natural, Table_Low_Bound => Primary_Directory, Table_Initial => 10, Table_Increment => 100, Table_Name => "Osint.Lib_Search_Directories"); -- Table of names of directories in which to search for library (Binder) -- files. This table is filled in the order in which the directories are -- to be searched and then used in that order. The reason for having two -- distinct tables is that we need them both in gnatmake. --------------------- -- File Hash Table -- --------------------- -- The file hash table is provided to free the programmer from any -- efficiency concern when retrieving full file names or time stamps of -- source files. If the programmer calls Source_File_Data (Cache => True) -- he is guaranteed that the price to retrieve the full name (ie with -- directory info) or time stamp of the file will be payed only once, -- the first time the full name is actually searched (or the first time -- the time stamp is actually retrieved). This is achieved by employing -- a hash table that stores as a key the File_Name_Type of the file and -- associates to that File_Name_Type the full file name of the file and its -- time stamp. File_Cache_Enabled : Boolean := False; -- Set to true if you want the enable the file data caching mechanism type File_Hash_Num is range 0 .. 1020; function File_Hash (F : File_Name_Type) return File_Hash_Num; -- Compute hash index for use by Simple_HTable package File_Name_Hash_Table is new GNAT.HTable.Simple_HTable ( Header_Num => File_Hash_Num, Element => File_Name_Type, No_Element => No_File, Key => File_Name_Type, Hash => File_Hash, Equal => "="); package File_Stamp_Hash_Table is new GNAT.HTable.Simple_HTable ( Header_Num => File_Hash_Num, Element => Time_Stamp_Type, No_Element => Empty_Time_Stamp, Key => File_Name_Type, Hash => File_Hash, Equal => "="); function Smart_Find_File (N : File_Name_Type; T : File_Type) return File_Name_Type; -- Exactly like Find_File except that if File_Cache_Enabled is True this -- routine looks first in the hash table to see if the full name of the -- file is already available. function Smart_File_Stamp (N : File_Name_Type; T : File_Type) return Time_Stamp_Type; -- Takes the same parameter as the routine above (N is a file name -- without any prefix directory information) and behaves like File_Stamp -- except that if File_Cache_Enabled is True this routine looks first in -- the hash table to see if the file stamp of the file is already -- available. ----------------------------- -- Add_Default_Search_Dirs -- ----------------------------- procedure Add_Default_Search_Dirs is Search_Dir : String_Access; Search_Path : String_Access; Path_File_Name : String_Access; procedure Add_Search_Dir (Search_Dir : String; Additional_Source_Dir : Boolean); procedure Add_Search_Dir (Search_Dir : String_Access; Additional_Source_Dir : Boolean); -- Add a source search dir or a library search dir, depending on the -- value of Additional_Source_Dir. procedure Get_Dirs_From_File (Additional_Source_Dir : Boolean); -- Open a path file and read the directory to search, one per line function Get_Libraries_From_Registry return String_Ptr; -- On Windows systems, get the list of installed standard libraries -- from the registry key: -- HKEY_LOCAL_MACHINE\SOFTWARE\Ada Core Technologies\ -- GNAT\Standard Libraries -- Return an empty string on other systems -------------------- -- Add_Search_Dir -- -------------------- procedure Add_Search_Dir (Search_Dir : String; Additional_Source_Dir : Boolean) is begin if Additional_Source_Dir then Add_Src_Search_Dir (Search_Dir); else Add_Lib_Search_Dir (Search_Dir); end if; end Add_Search_Dir; procedure Add_Search_Dir (Search_Dir : String_Access; Additional_Source_Dir : Boolean) is begin if Additional_Source_Dir then Add_Src_Search_Dir (Search_Dir.all); else Add_Lib_Search_Dir (Search_Dir.all); end if; end Add_Search_Dir; ------------------------ -- Get_Dirs_From_File -- ------------------------ procedure Get_Dirs_From_File (Additional_Source_Dir : Boolean) is File_FD : File_Descriptor; Buffer : String (1 .. Path_File_Name'Length + 1); Len : Natural; Actual_Len : Natural; S : String_Access; Curr : Natural; First : Natural; Ch : Character; Status : Boolean; -- For the call to Close begin -- Construct a C compatible character string buffer Buffer (1 .. Buffer'Last - 1) := Path_File_Name.all; Buffer (Buffer'Last) := ASCII.NUL; File_FD := Open_Read (Buffer'Address, Binary); -- If we cannot open the file, we ignore it, we don't fail if File_FD = Invalid_FD then return; end if; Len := Integer (File_Length (File_FD)); S := new String (1 .. Len); -- Read the file. Note that the loop is not necessary since the -- whole file is read at once except on VMS. Curr := 1; Actual_Len := Len; while Curr <= Len and then Actual_Len /= 0 loop Actual_Len := Read (File_FD, S (Curr)'Address, Len); Curr := Curr + Actual_Len; end loop; -- We are done with the file, so we close it Close (File_FD, Status); -- We ignore any error here, because we have successfully read the -- file. -- Now, we read line by line First := 1; Curr := 0; while Curr < Len loop Ch := S (Curr + 1); if Ch = ASCII.CR or else Ch = ASCII.LF or else Ch = ASCII.FF or else Ch = ASCII.VT then if First <= Curr then Add_Search_Dir (S (First .. Curr), Additional_Source_Dir); end if; First := Curr + 2; end if; Curr := Curr + 1; end loop; -- Last line is a special case, if the file does not end with -- an end of line mark. if First <= S'Last then Add_Search_Dir (S (First .. S'Last), Additional_Source_Dir); end if; end Get_Dirs_From_File; --------------------------------- -- Get_Libraries_From_Registry -- --------------------------------- function Get_Libraries_From_Registry return String_Ptr is function C_Get_Libraries_From_Registry return Address; pragma Import (C, C_Get_Libraries_From_Registry, "__gnat_get_libraries_from_registry"); function Strlen (Str : Address) return Integer; pragma Import (C, Strlen, "strlen"); procedure Strncpy (X : Address; Y : Address; Length : Integer); pragma Import (C, Strncpy, "strncpy"); Result_Ptr : Address; Result_Length : Integer; Out_String : String_Ptr; begin Result_Ptr := C_Get_Libraries_From_Registry; Result_Length := Strlen (Result_Ptr); Out_String := new String (1 .. Result_Length); Strncpy (Out_String.all'Address, Result_Ptr, Result_Length); return Out_String; end Get_Libraries_From_Registry; -- Start of processing for Add_Default_Search_Dirs begin -- After the locations specified on the command line, the next places -- to look for files are the directories specified by the appropriate -- environment variable. Get this value, extract the directory names -- and store in the tables. -- Check for eventual project path file env vars Path_File_Name := Getenv (Project_Include_Path_File); if Path_File_Name'Length > 0 then Get_Dirs_From_File (Additional_Source_Dir => True); end if; Path_File_Name := Getenv (Project_Objects_Path_File); if Path_File_Name'Length > 0 then Get_Dirs_From_File (Additional_Source_Dir => False); end if; -- On VMS, don't expand the logical name (e.g. environment variable), -- just put it into Unix (e.g. canonical) format. System services -- will handle the expansion as part of the file processing. for Additional_Source_Dir in False .. True loop if Additional_Source_Dir then Search_Path := Getenv (Ada_Include_Path); if Search_Path'Length > 0 then if Hostparm.OpenVMS then Search_Path := To_Canonical_Path_Spec ("ADA_INCLUDE_PATH:"); else Search_Path := To_Canonical_Path_Spec (Search_Path.all); end if; end if; else Search_Path := Getenv (Ada_Objects_Path); if Search_Path'Length > 0 then if Hostparm.OpenVMS then Search_Path := To_Canonical_Path_Spec ("ADA_OBJECTS_PATH:"); else Search_Path := To_Canonical_Path_Spec (Search_Path.all); end if; end if; end if; Get_Next_Dir_In_Path_Init (Search_Path); loop Search_Dir := Get_Next_Dir_In_Path (Search_Path); exit when Search_Dir = null; Add_Search_Dir (Search_Dir, Additional_Source_Dir); end loop; end loop; -- For the compiler, if --RTS= was specified, add the runtime -- directories. if RTS_Src_Path_Name /= null and then RTS_Lib_Path_Name /= null then Add_Search_Dirs (RTS_Src_Path_Name, Include); Add_Search_Dirs (RTS_Lib_Path_Name, Objects); else if not Opt.No_Stdinc then -- For WIN32 systems, look for any system libraries defined in -- the registry. These are added to both source and object -- directories. Search_Path := String_Access (Get_Libraries_From_Registry); Get_Next_Dir_In_Path_Init (Search_Path); loop Search_Dir := Get_Next_Dir_In_Path (Search_Path); exit when Search_Dir = null; Add_Search_Dir (Search_Dir, False); Add_Search_Dir (Search_Dir, True); end loop; -- The last place to look are the defaults Search_Path := Read_Default_Search_Dirs (String_Access (Update_Path (Search_Dir_Prefix)), Include_Search_File, String_Access (Update_Path (Include_Dir_Default_Name))); Get_Next_Dir_In_Path_Init (Search_Path); loop Search_Dir := Get_Next_Dir_In_Path (Search_Path); exit when Search_Dir = null; Add_Search_Dir (Search_Dir, True); end loop; end if; if not Opt.No_Stdlib and not Opt.RTS_Switch then Search_Path := Read_Default_Search_Dirs (String_Access (Update_Path (Search_Dir_Prefix)), Objects_Search_File, String_Access (Update_Path (Object_Dir_Default_Name))); Get_Next_Dir_In_Path_Init (Search_Path); loop Search_Dir := Get_Next_Dir_In_Path (Search_Path); exit when Search_Dir = null; Add_Search_Dir (Search_Dir, False); end loop; end if; end if; end Add_Default_Search_Dirs; -------------- -- Add_File -- -------------- procedure Add_File (File_Name : String; Index : Int := No_Index) is begin Number_File_Names := Number_File_Names + 1; -- As Add_File may be called for mains specified inside -- a project file, File_Names may be too short and needs -- to be extended. if Number_File_Names > File_Names'Last then File_Names := new File_Name_Array'(File_Names.all & File_Names.all); File_Indexes := new File_Index_Array'(File_Indexes.all & File_Indexes.all); end if; File_Names (Number_File_Names) := new String'(File_Name); File_Indexes (Number_File_Names) := Index; end Add_File; ------------------------ -- Add_Lib_Search_Dir -- ------------------------ procedure Add_Lib_Search_Dir (Dir : String) is begin if Dir'Length = 0 then Fail ("missing library directory name"); end if; Lib_Search_Directories.Increment_Last; Lib_Search_Directories.Table (Lib_Search_Directories.Last) := Normalize_Directory_Name (Dir); end Add_Lib_Search_Dir; --------------------- -- Add_Search_Dirs -- --------------------- procedure Add_Search_Dirs (Search_Path : String_Ptr; Path_Type : Search_File_Type) is Current_Search_Path : String_Access; begin Get_Next_Dir_In_Path_Init (String_Access (Search_Path)); loop Current_Search_Path := Get_Next_Dir_In_Path (String_Access (Search_Path)); exit when Current_Search_Path = null; if Path_Type = Include then Add_Src_Search_Dir (Current_Search_Path.all); else Add_Lib_Search_Dir (Current_Search_Path.all); end if; end loop; end Add_Search_Dirs; ------------------------ -- Add_Src_Search_Dir -- ------------------------ procedure Add_Src_Search_Dir (Dir : String) is begin if Dir'Length = 0 then Fail ("missing source directory name"); end if; Src_Search_Directories.Increment_Last; Src_Search_Directories.Table (Src_Search_Directories.Last) := Normalize_Directory_Name (Dir); end Add_Src_Search_Dir; -------------------------------- -- Append_Suffix_To_File_Name -- -------------------------------- function Append_Suffix_To_File_Name (Name : Name_Id; Suffix : String) return Name_Id is begin Get_Name_String (Name); Name_Buffer (Name_Len + 1 .. Name_Len + Suffix'Length) := Suffix; Name_Len := Name_Len + Suffix'Length; return Name_Find; end Append_Suffix_To_File_Name; --------------------- -- C_String_Length -- --------------------- function C_String_Length (S : Address) return Integer is function Strlen (S : Address) return Integer; pragma Import (C, Strlen, "strlen"); begin if S = Null_Address then return 0; else return Strlen (S); end if; end C_String_Length; ------------------------------ -- Canonical_Case_File_Name -- ------------------------------ -- For now, we only deal with the case of a-z. Eventually we should -- worry about other Latin-1 letters on systems that support this ??? procedure Canonical_Case_File_Name (S : in out String) is begin if not File_Names_Case_Sensitive then for J in S'Range loop if S (J) in 'A' .. 'Z' then S (J) := Character'Val ( Character'Pos (S (J)) + Character'Pos ('a') - Character'Pos ('A')); end if; end loop; end if; end Canonical_Case_File_Name; ------------ -- Concat -- ------------ function Concat (String_One : String; String_Two : String) return String is Buffer : String (1 .. String_One'Length + String_Two'Length); begin Buffer (1 .. String_One'Length) := String_One; Buffer (String_One'Length + 1 .. Buffer'Last) := String_Two; return Buffer; end Concat; --------------------------- -- Create_File_And_Check -- --------------------------- procedure Create_File_And_Check (Fdesc : out File_Descriptor; Fmode : Mode) is begin Output_File_Name := Name_Enter; Fdesc := Create_File (Name_Buffer'Address, Fmode); if Fdesc = Invalid_FD then Fail ("Cannot create: ", Name_Buffer (1 .. Name_Len)); end if; end Create_File_And_Check; ------------------------ -- Current_File_Index -- ------------------------ function Current_File_Index return Int is begin return File_Indexes (Current_File_Name_Index); end Current_File_Index; -------------------------------- -- Current_Library_File_Stamp -- -------------------------------- function Current_Library_File_Stamp return Time_Stamp_Type is begin return Current_Full_Lib_Stamp; end Current_Library_File_Stamp; ------------------------------- -- Current_Object_File_Stamp -- ------------------------------- function Current_Object_File_Stamp return Time_Stamp_Type is begin return Current_Full_Obj_Stamp; end Current_Object_File_Stamp; ------------------------------- -- Current_Source_File_Stamp -- ------------------------------- function Current_Source_File_Stamp return Time_Stamp_Type is begin return Current_Full_Source_Stamp; end Current_Source_File_Stamp; ---------------------------- -- Dir_In_Obj_Search_Path -- ---------------------------- function Dir_In_Obj_Search_Path (Position : Natural) return String_Ptr is begin if Opt.Look_In_Primary_Dir then return Lib_Search_Directories.Table (Primary_Directory + Position - 1); else return Lib_Search_Directories.Table (Primary_Directory + Position); end if; end Dir_In_Obj_Search_Path; ---------------------------- -- Dir_In_Src_Search_Path -- ---------------------------- function Dir_In_Src_Search_Path (Position : Natural) return String_Ptr is begin if Opt.Look_In_Primary_Dir then return Src_Search_Directories.Table (Primary_Directory + Position - 1); else return Src_Search_Directories.Table (Primary_Directory + Position); end if; end Dir_In_Src_Search_Path; --------------------- -- Executable_Name -- --------------------- function Executable_Name (Name : File_Name_Type) return File_Name_Type is Exec_Suffix : String_Access; begin if Name = No_File then return No_File; end if; Get_Name_String (Name); Exec_Suffix := Get_Executable_Suffix; for J in Exec_Suffix'Range loop Name_Len := Name_Len + 1; Name_Buffer (Name_Len) := Exec_Suffix (J); end loop; Free (Exec_Suffix); return Name_Enter; end Executable_Name; ----------------------- -- Executable_Prefix -- ----------------------- function Executable_Prefix return String_Ptr is function Get_Install_Dir (Exec : String) return String_Ptr; -- S is the executable name preceeded by the absolute or relative -- path, e.g. "c:\usr\bin\gcc.exe" or "..\bin\gcc". --------------------- -- Get_Install_Dir -- --------------------- function Get_Install_Dir (Exec : String) return String_Ptr is begin for J in reverse Exec'Range loop if Is_Directory_Separator (Exec (J)) then if J < Exec'Last - 5 then if (To_Lower (Exec (J + 1)) = 'l' and then To_Lower (Exec (J + 2)) = 'i' and then To_Lower (Exec (J + 3)) = 'b') or else (To_Lower (Exec (J + 1)) = 'b' and then To_Lower (Exec (J + 2)) = 'i' and then To_Lower (Exec (J + 3)) = 'n') then return new String'(Exec (Exec'First .. J)); end if; end if; end if; end loop; return new String'(""); end Get_Install_Dir; -- Start of processing for Executable_Prefix begin if Exec_Name = null then Exec_Name := new String (1 .. Len_Arg (0)); Osint.Fill_Arg (Exec_Name (1)'Address, 0); end if; -- First determine if a path prefix was placed in front of the -- executable name. for J in reverse Exec_Name'Range loop if Is_Directory_Separator (Exec_Name (J)) then return Get_Install_Dir (Exec_Name.all); end if; end loop; -- If we come here, the user has typed the executable name with no -- directory prefix. return Get_Install_Dir (GNAT.OS_Lib.Locate_Exec_On_Path (Exec_Name.all).all); end Executable_Prefix; ------------------ -- Exit_Program -- ------------------ procedure Exit_Program (Exit_Code : Exit_Code_Type) is begin -- The program will exit with the following status: -- 0 if the object file has been generated (with or without warnings) -- 1 if recompilation was not needed (smart recompilation) -- 2 if gnat1 has been killed by a signal (detected by GCC) -- 4 for a fatal error -- 5 if there were errors -- 6 if no code has been generated (spec) -- Note that exit code 3 is not used and must not be used as this is -- the code returned by a program aborted via C abort() routine on -- Windows. GCC checks for that case and thinks that the child process -- has been aborted. This code (exit code 3) used to be the code used -- for E_No_Code, but E_No_Code was changed to 6 for this reason. case Exit_Code is when E_Success => OS_Exit (0); when E_Warnings => OS_Exit (0); when E_No_Compile => OS_Exit (1); when E_Fatal => OS_Exit (4); when E_Errors => OS_Exit (5); when E_No_Code => OS_Exit (6); when E_Abort => OS_Abort; end case; end Exit_Program; ---------- -- Fail -- ---------- procedure Fail (S1 : String; S2 : String := ""; S3 : String := "") is begin -- We use Output in case there is a special output set up. -- In this case Set_Standard_Error will have no immediate effect. Set_Standard_Error; Osint.Write_Program_Name; Write_Str (": "); Write_Str (S1); Write_Str (S2); Write_Str (S3); Write_Eol; Exit_Program (E_Fatal); end Fail; --------------- -- File_Hash -- --------------- function File_Hash (F : File_Name_Type) return File_Hash_Num is begin return File_Hash_Num (Int (F) rem File_Hash_Num'Range_Length); end File_Hash; ---------------- -- File_Stamp -- ---------------- function File_Stamp (Name : File_Name_Type) return Time_Stamp_Type is begin if Name = No_File then return Empty_Time_Stamp; end if; Get_Name_String (Name); if not Is_Regular_File (Name_Buffer (1 .. Name_Len)) then return Empty_Time_Stamp; else Name_Buffer (Name_Len + 1) := ASCII.NUL; return OS_Time_To_GNAT_Time (File_Time_Stamp (Name_Buffer)); end if; end File_Stamp; --------------- -- Find_File -- --------------- function Find_File (N : File_Name_Type; T : File_Type) return File_Name_Type is begin Get_Name_String (N); declare File_Name : String renames Name_Buffer (1 .. Name_Len); File : File_Name_Type := No_File; Last_Dir : Natural; begin -- If we are looking for a config file, look only in the current -- directory, i.e. return input argument unchanged. Also look -- only in the current directory if we are looking for a .dg -- file (happens in -gnatD mode) if T = Config or else (Debug_Generated_Code and then Name_Len > 3 and then (Name_Buffer (Name_Len - 2 .. Name_Len) = ".dg" or else (Hostparm.OpenVMS and then Name_Buffer (Name_Len - 2 .. Name_Len) = "_dg"))) then return N; -- If we are trying to find the current main file just look in the -- directory where the user said it was. elsif Look_In_Primary_Directory_For_Current_Main and then Current_Main = N then return Locate_File (N, T, Primary_Directory, File_Name); -- Otherwise do standard search for source file else -- Check the mapping of this file name File := Mapped_Path_Name (N); -- If the file name is mapped to a path name, return the -- corresponding path name if File /= No_File then -- For locally removed file, Error_Name is returned; then -- return No_File, indicating the file is not a source. if File = Error_Name then return No_File; else return File; end if; end if; -- First place to look is in the primary directory (i.e. the same -- directory as the source) unless this has been disabled with -I- if Opt.Look_In_Primary_Dir then File := Locate_File (N, T, Primary_Directory, File_Name); if File /= No_File then return File; end if; end if; -- Finally look in directories specified with switches -I/-aI/-aO if T = Library then Last_Dir := Lib_Search_Directories.Last; else Last_Dir := Src_Search_Directories.Last; end if; for D in Primary_Directory + 1 .. Last_Dir loop File := Locate_File (N, T, D, File_Name); if File /= No_File then return File; end if; end loop; return No_File; end if; end; end Find_File; ----------------------- -- Find_Program_Name -- ----------------------- procedure Find_Program_Name is Command_Name : String (1 .. Len_Arg (0)); Cindex1 : Integer := Command_Name'First; Cindex2 : Integer := Command_Name'Last; begin Fill_Arg (Command_Name'Address, 0); -- The program name might be specified by a full path name. However, -- we don't want to print that all out in an error message, so the -- path might need to be stripped away. for J in reverse Cindex1 .. Cindex2 loop if Is_Directory_Separator (Command_Name (J)) then Cindex1 := J + 1; exit; end if; end loop; -- Command_Name(Cindex1 .. Cindex2) is now the equivalent of the -- POSIX command "basename argv[0]" -- Strip off any versioning information such as found on VMS. -- This would take the form of TOOL.exe followed by a ";" or "." -- and a sequence of one or more numbers. if Command_Name (Cindex2) in '0' .. '9' then for J in reverse Cindex1 .. Cindex2 loop if Command_Name (J) = '.' or Command_Name (J) = ';' then Cindex2 := J - 1; exit; end if; exit when Command_Name (J) not in '0' .. '9'; end loop; end if; -- Strip off any executable extension (usually nothing or .exe) -- but formally reported by autoconf in the variable EXEEXT if Cindex2 - Cindex1 >= 4 then if To_Lower (Command_Name (Cindex2 - 3)) = '.' and then To_Lower (Command_Name (Cindex2 - 2)) = 'e' and then To_Lower (Command_Name (Cindex2 - 1)) = 'x' and then To_Lower (Command_Name (Cindex2)) = 'e' then Cindex2 := Cindex2 - 4; end if; end if; Name_Len := Cindex2 - Cindex1 + 1; Name_Buffer (1 .. Name_Len) := Command_Name (Cindex1 .. Cindex2); end Find_Program_Name; ------------------------ -- Full_Lib_File_Name -- ------------------------ function Full_Lib_File_Name (N : File_Name_Type) return File_Name_Type is begin return Find_File (N, Library); end Full_Lib_File_Name; ---------------------------- -- Full_Library_Info_Name -- ---------------------------- function Full_Library_Info_Name return File_Name_Type is begin return Current_Full_Lib_Name; end Full_Library_Info_Name; --------------------------- -- Full_Object_File_Name -- --------------------------- function Full_Object_File_Name return File_Name_Type is begin return Current_Full_Obj_Name; end Full_Object_File_Name; ---------------------- -- Full_Source_Name -- ---------------------- function Full_Source_Name return File_Name_Type is begin return Current_Full_Source_Name; end Full_Source_Name; ---------------------- -- Full_Source_Name -- ---------------------- function Full_Source_Name (N : File_Name_Type) return File_Name_Type is begin return Smart_Find_File (N, Source); end Full_Source_Name; ------------------- -- Get_Directory -- ------------------- function Get_Directory (Name : File_Name_Type) return File_Name_Type is begin Get_Name_String (Name); for J in reverse 1 .. Name_Len loop if Is_Directory_Separator (Name_Buffer (J)) then Name_Len := J; return Name_Find; end if; end loop; Name_Len := Hostparm.Normalized_CWD'Length; Name_Buffer (1 .. Name_Len) := Hostparm.Normalized_CWD; return Name_Find; end Get_Directory; -------------------------- -- Get_Next_Dir_In_Path -- -------------------------- Search_Path_Pos : Integer; -- Keeps track of current position in search path. Initialized by the -- call to Get_Next_Dir_In_Path_Init, updated by Get_Next_Dir_In_Path. function Get_Next_Dir_In_Path (Search_Path : String_Access) return String_Access is Lower_Bound : Positive := Search_Path_Pos; Upper_Bound : Positive; begin loop while Lower_Bound <= Search_Path'Last and then Search_Path.all (Lower_Bound) = Path_Separator loop Lower_Bound := Lower_Bound + 1; end loop; exit when Lower_Bound > Search_Path'Last; Upper_Bound := Lower_Bound; while Upper_Bound <= Search_Path'Last and then Search_Path.all (Upper_Bound) /= Path_Separator loop Upper_Bound := Upper_Bound + 1; end loop; Search_Path_Pos := Upper_Bound; return new String'(Search_Path.all (Lower_Bound .. Upper_Bound - 1)); end loop; return null; end Get_Next_Dir_In_Path; ------------------------------- -- Get_Next_Dir_In_Path_Init -- ------------------------------- procedure Get_Next_Dir_In_Path_Init (Search_Path : String_Access) is begin Search_Path_Pos := Search_Path'First; end Get_Next_Dir_In_Path_Init; -------------------------------------- -- Get_Primary_Src_Search_Directory -- -------------------------------------- function Get_Primary_Src_Search_Directory return String_Ptr is begin return Src_Search_Directories.Table (Primary_Directory); end Get_Primary_Src_Search_Directory; ------------------------ -- Get_RTS_Search_Dir -- ------------------------ function Get_RTS_Search_Dir (Search_Dir : String; File_Type : Search_File_Type) return String_Ptr is procedure Get_Current_Dir (Dir : System.Address; Length : System.Address); pragma Import (C, Get_Current_Dir, "__gnat_get_current_dir"); Max_Path : Integer; pragma Import (C, Max_Path, "__gnat_max_path_len"); -- Maximum length of a path name Current_Dir : String_Ptr; Default_Search_Dir : String_Access; Default_Suffix_Dir : String_Access; Local_Search_Dir : String_Access; Norm_Search_Dir : String_Access; Result_Search_Dir : String_Access; Search_File : String_Access; Temp_String : String_Ptr; begin -- Add a directory separator at the end of the directory if necessary -- so that we can directly append a file to the directory if Search_Dir (Search_Dir'Last) /= Directory_Separator then Local_Search_Dir := new String' (Concat (Search_Dir, String'(1 => Directory_Separator))); else Local_Search_Dir := new String'(Search_Dir); end if; if File_Type = Include then Search_File := Include_Search_File; Default_Suffix_Dir := new String'("adainclude"); else Search_File := Objects_Search_File; Default_Suffix_Dir := new String'("adalib"); end if; Norm_Search_Dir := To_Canonical_Path_Spec (Local_Search_Dir.all); if Is_Absolute_Path (Norm_Search_Dir.all) then -- We first verify if there is a directory Include_Search_Dir -- containing default search directories Result_Search_Dir := Read_Default_Search_Dirs (Norm_Search_Dir, Search_File, null); Default_Search_Dir := new String' (Concat (Norm_Search_Dir.all, Default_Suffix_Dir.all)); Free (Norm_Search_Dir); if Result_Search_Dir /= null then return String_Ptr (Result_Search_Dir); elsif Is_Directory (Default_Search_Dir.all) then return String_Ptr (Default_Search_Dir); else return null; end if; -- Search in the current directory else -- Get the current directory declare Buffer : String (1 .. Max_Path + 2); Path_Len : Natural := Max_Path; begin Get_Current_Dir (Buffer'Address, Path_Len'Address); if Buffer (Path_Len) /= Directory_Separator then Path_Len := Path_Len + 1; Buffer (Path_Len) := Directory_Separator; end if; Current_Dir := new String'(Buffer (1 .. Path_Len)); end; Norm_Search_Dir := new String'(Concat (Current_Dir.all, Local_Search_Dir.all)); Result_Search_Dir := Read_Default_Search_Dirs (Norm_Search_Dir, Search_File, null); Default_Search_Dir := new String' (Concat (Norm_Search_Dir.all, Default_Suffix_Dir.all)); Free (Norm_Search_Dir); if Result_Search_Dir /= null then return String_Ptr (Result_Search_Dir); elsif Is_Directory (Default_Search_Dir.all) then return String_Ptr (Default_Search_Dir); else -- Search in Search_Dir_Prefix/Search_Dir Norm_Search_Dir := new String' (Concat (Update_Path (Search_Dir_Prefix).all, Local_Search_Dir.all)); Result_Search_Dir := Read_Default_Search_Dirs (Norm_Search_Dir, Search_File, null); Default_Search_Dir := new String' (Concat (Norm_Search_Dir.all, Default_Suffix_Dir.all)); Free (Norm_Search_Dir); if Result_Search_Dir /= null then return String_Ptr (Result_Search_Dir); elsif Is_Directory (Default_Search_Dir.all) then return String_Ptr (Default_Search_Dir); else -- We finally search in Search_Dir_Prefix/rts-Search_Dir Temp_String := new String' (Concat (Update_Path (Search_Dir_Prefix).all, "rts-")); Norm_Search_Dir := new String'(Concat (Temp_String.all, Local_Search_Dir.all)); Result_Search_Dir := Read_Default_Search_Dirs (Norm_Search_Dir, Search_File, null); Default_Search_Dir := new String' (Concat (Norm_Search_Dir.all, Default_Suffix_Dir.all)); Free (Norm_Search_Dir); if Result_Search_Dir /= null then return String_Ptr (Result_Search_Dir); elsif Is_Directory (Default_Search_Dir.all) then return String_Ptr (Default_Search_Dir); else return null; end if; end if; end if; end if; end Get_RTS_Search_Dir; -------------------------------- -- Include_Dir_Default_Prefix -- -------------------------------- function Include_Dir_Default_Prefix return String is Include_Dir : String_Access := String_Access (Update_Path (Include_Dir_Default_Name)); begin if Include_Dir = null then return ""; else declare Result : constant String := Include_Dir.all; begin Free (Include_Dir); return Result; end; end if; end Include_Dir_Default_Prefix; ---------------- -- Initialize -- ---------------- procedure Initialize is begin Number_File_Names := 0; Current_File_Name_Index := 0; Src_Search_Directories.Init; Lib_Search_Directories.Init; -- Start off by setting all suppress options to False, these will -- be reset later (turning some on if -gnato is not specified, and -- turning all of them on if -gnatp is specified). Suppress_Options := (others => False); -- Reserve the first slot in the search paths table. This is the -- directory of the main source file or main library file and is -- filled in by each call to Next_Main_Source/Next_Main_Lib_File with -- the directory specified for this main source or library file. This -- is the directory which is searched first by default. This default -- search is inhibited by the option -I- for both source and library -- files. Src_Search_Directories.Set_Last (Primary_Directory); Src_Search_Directories.Table (Primary_Directory) := new String'(""); Lib_Search_Directories.Set_Last (Primary_Directory); Lib_Search_Directories.Table (Primary_Directory) := new String'(""); end Initialize; ---------------------------- -- Is_Directory_Separator -- ---------------------------- function Is_Directory_Separator (C : Character) return Boolean is begin -- In addition to the default directory_separator allow the '/' to -- act as separator since this is allowed in MS-DOS, Windows 95/NT, -- and OS2 ports. On VMS, the situation is more complicated because -- there are two characters to check for. return C = Directory_Separator or else C = '/' or else (Hostparm.OpenVMS and then (C = ']' or else C = ':')); end Is_Directory_Separator; ------------------------- -- Is_Readonly_Library -- ------------------------- function Is_Readonly_Library (File : File_Name_Type) return Boolean is begin Get_Name_String (File); pragma Assert (Name_Buffer (Name_Len - 3 .. Name_Len) = ".ali"); return not Is_Writable_File (Name_Buffer (1 .. Name_Len)); end Is_Readonly_Library; ------------------- -- Lib_File_Name -- ------------------- function Lib_File_Name (Source_File : File_Name_Type; Munit_Index : Nat := 0) return File_Name_Type is begin Get_Name_String (Source_File); for J in reverse 2 .. Name_Len loop if Name_Buffer (J) = '.' then Name_Len := J - 1; exit; end if; end loop; if Munit_Index /= 0 then Add_Char_To_Name_Buffer (Multi_Unit_Index_Character); Add_Nat_To_Name_Buffer (Munit_Index); end if; Add_Char_To_Name_Buffer ('.'); Add_Str_To_Name_Buffer (ALI_Suffix.all); return Name_Find; end Lib_File_Name; ------------------------ -- Library_File_Stamp -- ------------------------ function Library_File_Stamp (N : File_Name_Type) return Time_Stamp_Type is begin return File_Stamp (Find_File (N, Library)); end Library_File_Stamp; ----------------- -- Locate_File -- ----------------- function Locate_File (N : File_Name_Type; T : File_Type; Dir : Natural; Name : String) return File_Name_Type is Dir_Name : String_Ptr; begin -- If Name is already an absolute path, do not look for a directory if Is_Absolute_Path (Name) then Dir_Name := No_Dir; elsif T = Library then Dir_Name := Lib_Search_Directories.Table (Dir); else pragma Assert (T /= Config); Dir_Name := Src_Search_Directories.Table (Dir); end if; declare Full_Name : String (1 .. Dir_Name'Length + Name'Length); begin Full_Name (1 .. Dir_Name'Length) := Dir_Name.all; Full_Name (Dir_Name'Length + 1 .. Full_Name'Length) := Name; if not Is_Regular_File (Full_Name) then return No_File; else -- If the file is in the current directory then return N itself if Dir_Name'Length = 0 then return N; else Name_Len := Full_Name'Length; Name_Buffer (1 .. Name_Len) := Full_Name; return Name_Enter; end if; end if; end; end Locate_File; ------------------------------- -- Matching_Full_Source_Name -- ------------------------------- function Matching_Full_Source_Name (N : File_Name_Type; T : Time_Stamp_Type) return File_Name_Type is begin Get_Name_String (N); declare File_Name : constant String := Name_Buffer (1 .. Name_Len); File : File_Name_Type := No_File; Last_Dir : Natural; begin if Opt.Look_In_Primary_Dir then File := Locate_File (N, Source, Primary_Directory, File_Name); if File /= No_File and then T = File_Stamp (N) then return File; end if; end if; Last_Dir := Src_Search_Directories.Last; for D in Primary_Directory + 1 .. Last_Dir loop File := Locate_File (N, Source, D, File_Name); if File /= No_File and then T = File_Stamp (File) then return File; end if; end loop; return No_File; end; end Matching_Full_Source_Name; ---------------- -- More_Files -- ---------------- function More_Files return Boolean is begin return (Current_File_Name_Index < Number_File_Names); end More_Files; ------------------------------- -- Nb_Dir_In_Obj_Search_Path -- ------------------------------- function Nb_Dir_In_Obj_Search_Path return Natural is begin if Opt.Look_In_Primary_Dir then return Lib_Search_Directories.Last - Primary_Directory + 1; else return Lib_Search_Directories.Last - Primary_Directory; end if; end Nb_Dir_In_Obj_Search_Path; ------------------------------- -- Nb_Dir_In_Src_Search_Path -- ------------------------------- function Nb_Dir_In_Src_Search_Path return Natural is begin if Opt.Look_In_Primary_Dir then return Src_Search_Directories.Last - Primary_Directory + 1; else return Src_Search_Directories.Last - Primary_Directory; end if; end Nb_Dir_In_Src_Search_Path; -------------------- -- Next_Main_File -- -------------------- function Next_Main_File return File_Name_Type is File_Name : String_Ptr; Dir_Name : String_Ptr; Fptr : Natural; begin pragma Assert (More_Files); Current_File_Name_Index := Current_File_Name_Index + 1; -- Get the file and directory name File_Name := File_Names (Current_File_Name_Index); Fptr := File_Name'First; for J in reverse File_Name'Range loop if File_Name (J) = Directory_Separator or else File_Name (J) = '/' then if J = File_Name'Last then Fail ("File name missing"); end if; Fptr := J + 1; exit; end if; end loop; -- Save name of directory in which main unit resides for use in -- locating other units Dir_Name := new String'(File_Name (File_Name'First .. Fptr - 1)); case Running_Program is when Compiler => Src_Search_Directories.Table (Primary_Directory) := Dir_Name; Look_In_Primary_Directory_For_Current_Main := True; when Make => Src_Search_Directories.Table (Primary_Directory) := Dir_Name; if Fptr > File_Name'First then Look_In_Primary_Directory_For_Current_Main := True; end if; when Binder | Gnatls => Dir_Name := Normalize_Directory_Name (Dir_Name.all); Lib_Search_Directories.Table (Primary_Directory) := Dir_Name; when Unspecified => null; end case; Name_Len := File_Name'Last - Fptr + 1; Name_Buffer (1 .. Name_Len) := File_Name (Fptr .. File_Name'Last); Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len)); Current_Main := File_Name_Type (Name_Find); -- In the gnatmake case, the main file may have not have the -- extension. Try ".adb" first then ".ads" if Running_Program = Make then declare Orig_Main : constant File_Name_Type := Current_Main; begin if Strip_Suffix (Orig_Main) = Orig_Main then Current_Main := Append_Suffix_To_File_Name (Orig_Main, ".adb"); if Full_Source_Name (Current_Main) = No_File then Current_Main := Append_Suffix_To_File_Name (Orig_Main, ".ads"); if Full_Source_Name (Current_Main) = No_File then Current_Main := Orig_Main; end if; end if; end if; end; end if; return Current_Main; end Next_Main_File; ------------------------------ -- Normalize_Directory_Name -- ------------------------------ function Normalize_Directory_Name (Directory : String) return String_Ptr is function Is_Quoted (Path : String) return Boolean; pragma Inline (Is_Quoted); -- Returns true if Path is quoted (either double or single quotes) --------------- -- Is_Quoted -- --------------- function Is_Quoted (Path : String) return Boolean is First : constant Character := Path (Path'First); Last : constant Character := Path (Path'Last); begin if (First = ''' and then Last = ''') or else (First = '"' and then Last = '"') then return True; else return False; end if; end Is_Quoted; Result : String_Ptr; -- Start of processing for Normalize_Directory_Name begin if Directory'Length = 0 then Result := new String'(Hostparm.Normalized_CWD); elsif Is_Directory_Separator (Directory (Directory'Last)) then Result := new String'(Directory); elsif Is_Quoted (Directory) then -- This is a quoted string, it certainly means that the directory -- contains some spaces for example. We can safely remove the quotes -- here as the OS_Lib.Normalize_Arguments will be called before any -- spawn routines. This ensure that quotes will be added when needed. Result := new String (1 .. Directory'Length - 1); Result (1 .. Directory'Length - 1) := Directory (Directory'First + 1 .. Directory'Last - 1); Result (Result'Last) := Directory_Separator; else Result := new String (1 .. Directory'Length + 1); Result (1 .. Directory'Length) := Directory; Result (Directory'Length + 1) := Directory_Separator; end if; return Result; end Normalize_Directory_Name; --------------------- -- Number_Of_Files -- --------------------- function Number_Of_Files return Int is begin return Number_File_Names; end Number_Of_Files; ------------------------------- -- Object_Dir_Default_Prefix -- ------------------------------- function Object_Dir_Default_Prefix return String is Object_Dir : String_Access := String_Access (Update_Path (Object_Dir_Default_Name)); begin if Object_Dir = null then return ""; else declare Result : constant String := Object_Dir.all; begin Free (Object_Dir); return Result; end; end if; end Object_Dir_Default_Prefix; ---------------------- -- Object_File_Name -- ---------------------- function Object_File_Name (N : File_Name_Type) return File_Name_Type is begin if N = No_File then return No_File; end if; Get_Name_String (N); Name_Len := Name_Len - ALI_Suffix'Length - 1; for J in Target_Object_Suffix'Range loop Name_Len := Name_Len + 1; Name_Buffer (Name_Len) := Target_Object_Suffix (J); end loop; return Name_Enter; end Object_File_Name; -------------------------- -- OS_Time_To_GNAT_Time -- -------------------------- function OS_Time_To_GNAT_Time (T : OS_Time) return Time_Stamp_Type is GNAT_Time : Time_Stamp_Type; Y : Year_Type; Mo : Month_Type; D : Day_Type; H : Hour_Type; Mn : Minute_Type; S : Second_Type; begin GM_Split (T, Y, Mo, D, H, Mn, S); Make_Time_Stamp (Year => Nat (Y), Month => Nat (Mo), Day => Nat (D), Hour => Nat (H), Minutes => Nat (Mn), Seconds => Nat (S), TS => GNAT_Time); return GNAT_Time; end OS_Time_To_GNAT_Time; ------------------ -- Program_Name -- ------------------ function Program_Name (Nam : String) return String_Access is Res : String_Access; begin -- Get the name of the current program being executed Find_Program_Name; -- Find the target prefix if any, for the cross compilation case -- for instance in "alpha-dec-vxworks-gcc" the target prefix is -- "alpha-dec-vxworks-" while Name_Len > 0 loop -- All done if we find the last hyphen if Name_Buffer (Name_Len) = '-' then exit; -- If directory separator found, we don't want to look further -- since in this case, no prefix has been found. elsif Is_Directory_Separator (Name_Buffer (Name_Len)) then Name_Len := 0; exit; end if; Name_Len := Name_Len - 1; end loop; -- Create the new program name Res := new String (1 .. Name_Len + Nam'Length); Res.all (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); Res.all (Name_Len + 1 .. Name_Len + Nam'Length) := Nam; return Res; end Program_Name; ------------------------------ -- Read_Default_Search_Dirs -- ------------------------------ function Read_Default_Search_Dirs (Search_Dir_Prefix : String_Access; Search_File : String_Access; Search_Dir_Default_Name : String_Access) return String_Access is Prefix_Len : constant Integer := Search_Dir_Prefix.all'Length; Buffer : String (1 .. Prefix_Len + Search_File.all'Length + 1); File_FD : File_Descriptor; S, S1 : String_Access; Len : Integer; Curr : Integer; Actual_Len : Integer; J1 : Integer; Prev_Was_Separator : Boolean; Nb_Relative_Dir : Integer; function Is_Relative (S : String; K : Positive) return Boolean; pragma Inline (Is_Relative); -- Returns True if a relative directory specification is found -- in S at position K, False otherwise. ----------------- -- Is_Relative -- ----------------- function Is_Relative (S : String; K : Positive) return Boolean is begin return not Is_Absolute_Path (S (K .. S'Last)); end Is_Relative; -- Start of processing for Read_Default_Search_Dirs begin -- Construct a C compatible character string buffer Buffer (1 .. Search_Dir_Prefix.all'Length) := Search_Dir_Prefix.all; Buffer (Search_Dir_Prefix.all'Length + 1 .. Buffer'Last - 1) := Search_File.all; Buffer (Buffer'Last) := ASCII.NUL; File_FD := Open_Read (Buffer'Address, Binary); if File_FD = Invalid_FD then return Search_Dir_Default_Name; end if; Len := Integer (File_Length (File_FD)); -- An extra character for a trailing Path_Separator is allocated S := new String (1 .. Len + 1); S (Len + 1) := Path_Separator; -- Read the file. Note that the loop is not necessary since the -- whole file is read at once except on VMS. Curr := 1; Actual_Len := Len; while Actual_Len /= 0 loop Actual_Len := Read (File_FD, S (Curr)'Address, Len); Curr := Curr + Actual_Len; end loop; -- Process the file, translating line and file ending -- control characters to a path separator character. Prev_Was_Separator := True; Nb_Relative_Dir := 0; for J in 1 .. Len loop if S (J) in ASCII.NUL .. ASCII.US or else S (J) = ' ' then S (J) := Path_Separator; end if; if S (J) = Path_Separator then Prev_Was_Separator := True; else if Prev_Was_Separator and then Is_Relative (S.all, J) then Nb_Relative_Dir := Nb_Relative_Dir + 1; end if; Prev_Was_Separator := False; end if; end loop; if Nb_Relative_Dir = 0 then return S; end if; -- Add the Search_Dir_Prefix to all relative paths S1 := new String (1 .. S'Length + Nb_Relative_Dir * Prefix_Len); J1 := 1; Prev_Was_Separator := True; for J in 1 .. Len + 1 loop if S (J) = Path_Separator then Prev_Was_Separator := True; else if Prev_Was_Separator and then Is_Relative (S.all, J) then S1 (J1 .. J1 + Prefix_Len - 1) := Search_Dir_Prefix.all; J1 := J1 + Prefix_Len; end if; Prev_Was_Separator := False; end if; S1 (J1) := S (J); J1 := J1 + 1; end loop; Free (S); return S1; end Read_Default_Search_Dirs; ----------------------- -- Read_Library_Info -- ----------------------- function Read_Library_Info (Lib_File : File_Name_Type; Fatal_Err : Boolean := False) return Text_Buffer_Ptr is Lib_FD : File_Descriptor; -- The file descriptor for the current library file. A negative value -- indicates failure to open the specified source file. Text : Text_Buffer_Ptr; -- Allocated text buffer Status : Boolean; -- For the calls to Close begin Current_Full_Lib_Name := Find_File (Lib_File, Library); Current_Full_Obj_Name := Object_File_Name (Current_Full_Lib_Name); if Current_Full_Lib_Name = No_File then if Fatal_Err then Fail ("Cannot find: ", Name_Buffer (1 .. Name_Len)); else Current_Full_Obj_Stamp := Empty_Time_Stamp; return null; end if; end if; Get_Name_String (Current_Full_Lib_Name); Name_Buffer (Name_Len + 1) := ASCII.NUL; -- Open the library FD, note that we open in binary mode, because as -- documented in the spec, the caller is expected to handle either -- DOS or Unix mode files, and there is no point in wasting time on -- text translation when it is not required. Lib_FD := Open_Read (Name_Buffer'Address, Binary); if Lib_FD = Invalid_FD then if Fatal_Err then Fail ("Cannot open: ", Name_Buffer (1 .. Name_Len)); else Current_Full_Obj_Stamp := Empty_Time_Stamp; return null; end if; end if; -- Check for object file consistency if requested if Opt.Check_Object_Consistency then Current_Full_Lib_Stamp := File_Stamp (Current_Full_Lib_Name); Current_Full_Obj_Stamp := File_Stamp (Current_Full_Obj_Name); if Current_Full_Obj_Stamp (1) = ' ' then -- When the library is readonly, always assume that -- the object is consistent. if Is_Readonly_Library (Current_Full_Lib_Name) then Current_Full_Obj_Stamp := Current_Full_Lib_Stamp; elsif Fatal_Err then Get_Name_String (Current_Full_Obj_Name); Close (Lib_FD, Status); -- No need to check the status, we fail anyway Fail ("Cannot find: ", Name_Buffer (1 .. Name_Len)); else Current_Full_Obj_Stamp := Empty_Time_Stamp; Close (Lib_FD, Status); -- No need to check the status, we return null anyway return null; end if; end if; end if; -- Read data from the file declare Len : constant Integer := Integer (File_Length (Lib_FD)); -- Length of source file text. If it doesn't fit in an integer -- we're probably stuck anyway (>2 gigs of source seems a lot!) Actual_Len : Integer := 0; Lo : constant Text_Ptr := 0; -- Low bound for allocated text buffer Hi : Text_Ptr := Text_Ptr (Len); -- High bound for allocated text buffer. Note length is Len + 1 -- which allows for extra EOF character at the end of the buffer. begin -- Allocate text buffer. Note extra character at end for EOF Text := new Text_Buffer (Lo .. Hi); -- Some systems (e.g. VMS) have file types that require one -- read per line, so read until we get the Len bytes or until -- there are no more characters. Hi := Lo; loop Actual_Len := Read (Lib_FD, Text (Hi)'Address, Len); Hi := Hi + Text_Ptr (Actual_Len); exit when Actual_Len = Len or Actual_Len <= 0; end loop; Text (Hi) := EOF; end; -- Read is complete, close file and we are done Close (Lib_FD, Status); -- The status should never be False. But, if it is, what can we do? -- So, we don't test it. return Text; end Read_Library_Info; ---------------------- -- Read_Source_File -- ---------------------- procedure Read_Source_File (N : File_Name_Type; Lo : Source_Ptr; Hi : out Source_Ptr; Src : out Source_Buffer_Ptr; T : File_Type := Source) is Source_File_FD : File_Descriptor; -- The file descriptor for the current source file. A negative value -- indicates failure to open the specified source file. Len : Integer; -- Length of file. Assume no more than 2 gigabytes of source! Actual_Len : Integer; Status : Boolean; -- For the call to Close -- LLVM local pragma Warnings (Off, Status); begin Current_Full_Source_Name := Find_File (N, T); Current_Full_Source_Stamp := File_Stamp (Current_Full_Source_Name); if Current_Full_Source_Name = No_File then -- If we were trying to access the main file and we could not -- find it we have an error. if N = Current_Main then Get_Name_String (N); Fail ("Cannot find: ", Name_Buffer (1 .. Name_Len)); end if; Src := null; Hi := No_Location; return; end if; Get_Name_String (Current_Full_Source_Name); Name_Buffer (Name_Len + 1) := ASCII.NUL; -- Open the source FD, note that we open in binary mode, because as -- documented in the spec, the caller is expected to handle either -- DOS or Unix mode files, and there is no point in wasting time on -- text translation when it is not required. Source_File_FD := Open_Read (Name_Buffer'Address, Binary); if Source_File_FD = Invalid_FD then Src := null; Hi := No_Location; return; end if; -- Prepare to read data from the file Len := Integer (File_Length (Source_File_FD)); -- Set Hi so that length is one more than the physical length, -- allowing for the extra EOF character at the end of the buffer Hi := Lo + Source_Ptr (Len); -- Do the actual read operation declare subtype Actual_Source_Buffer is Source_Buffer (Lo .. Hi); -- Physical buffer allocated type Actual_Source_Ptr is access Actual_Source_Buffer; -- This is the pointer type for the physical buffer allocated Actual_Ptr : constant Actual_Source_Ptr := new Actual_Source_Buffer; -- And this is the actual physical buffer begin -- Allocate source buffer, allowing extra character at end for EOF -- Some systems (e.g. VMS) have file types that require one -- read per line, so read until we get the Len bytes or until -- there are no more characters. Hi := Lo; loop Actual_Len := Read (Source_File_FD, Actual_Ptr (Hi)'Address, Len); Hi := Hi + Source_Ptr (Actual_Len); exit when Actual_Len = Len or Actual_Len <= 0; end loop; Actual_Ptr (Hi) := EOF; -- Now we need to work out the proper virtual origin pointer to -- return. This is exactly Actual_Ptr (0)'Address, but we have -- to be careful to suppress checks to compute this address. declare pragma Suppress (All_Checks); pragma Warnings (Off); -- This use of unchecked conversion is aliasing safe function To_Source_Buffer_Ptr is new Unchecked_Conversion (Address, Source_Buffer_Ptr); pragma Warnings (On); begin Src := To_Source_Buffer_Ptr (Actual_Ptr (0)'Address); end; end; -- Read is complete, get time stamp and close file and we are done Close (Source_File_FD, Status); -- The status should never be False. But, if it is, what can we do? -- So, we don't test it. end Read_Source_File; ------------------- -- Relocate_Path -- ------------------- function Relocate_Path (Prefix : String; Path : String) return String_Ptr is S : String_Ptr; procedure set_std_prefix (S : String; Len : Integer); pragma Import (C, set_std_prefix); begin if Std_Prefix = null then Std_Prefix := Executable_Prefix; if Std_Prefix.all /= "" then -- Remove trailing directory separator when calling set_std_prefix set_std_prefix (Std_Prefix.all, Std_Prefix'Length - 1); end if; end if; if Path (Prefix'Range) = Prefix then if Std_Prefix.all /= "" then S := new String (1 .. Std_Prefix'Length + Path'Last - Prefix'Last); S (1 .. Std_Prefix'Length) := Std_Prefix.all; S (Std_Prefix'Length + 1 .. S'Last) := Path (Prefix'Last + 1 .. Path'Last); return S; end if; end if; return new String'(Path); end Relocate_Path; ----------------- -- Set_Program -- ----------------- procedure Set_Program (P : Program_Type) is begin if Program_Set then Fail ("Set_Program called twice"); end if; Program_Set := True; Running_Program := P; end Set_Program; ---------------- -- Shared_Lib -- ---------------- function Shared_Lib (Name : String) return String is Library : String (1 .. Name'Length + Library_Version'Length + 3); -- 3 = 2 for "-l" + 1 for "-" before lib version begin Library (1 .. 2) := "-l"; Library (3 .. 2 + Name'Length) := Name; Library (3 + Name'Length) := '-'; Library (4 + Name'Length .. Library'Last) := Library_Version; if OpenVMS_On_Target then for K in Library'First + 2 .. Library'Last loop if Library (K) = '.' or else Library (K) = '-' then Library (K) := '_'; end if; end loop; end if; return Library; end Shared_Lib; ---------------------- -- Smart_File_Stamp -- ---------------------- function Smart_File_Stamp (N : File_Name_Type; T : File_Type) return Time_Stamp_Type is Time_Stamp : Time_Stamp_Type; begin if not File_Cache_Enabled then return File_Stamp (Find_File (N, T)); end if; Time_Stamp := File_Stamp_Hash_Table.Get (N); if Time_Stamp (1) = ' ' then Time_Stamp := File_Stamp (Smart_Find_File (N, T)); File_Stamp_Hash_Table.Set (N, Time_Stamp); end if; return Time_Stamp; end Smart_File_Stamp; --------------------- -- Smart_Find_File -- --------------------- function Smart_Find_File (N : File_Name_Type; T : File_Type) return File_Name_Type is Full_File_Name : File_Name_Type; begin if not File_Cache_Enabled then return Find_File (N, T); end if; Full_File_Name := File_Name_Hash_Table.Get (N); if Full_File_Name = No_File then Full_File_Name := Find_File (N, T); File_Name_Hash_Table.Set (N, Full_File_Name); end if; return Full_File_Name; end Smart_Find_File; ---------------------- -- Source_File_Data -- ---------------------- procedure Source_File_Data (Cache : Boolean) is begin File_Cache_Enabled := Cache; end Source_File_Data; ----------------------- -- Source_File_Stamp -- ----------------------- function Source_File_Stamp (N : File_Name_Type) return Time_Stamp_Type is begin return Smart_File_Stamp (N, Source); end Source_File_Stamp; --------------------- -- Strip_Directory -- --------------------- function Strip_Directory (Name : File_Name_Type) return File_Name_Type is begin Get_Name_String (Name); for J in reverse 1 .. Name_Len - 1 loop -- If we find the last directory separator if Is_Directory_Separator (Name_Buffer (J)) then -- Return the part of Name that follows this last directory -- separator. Name_Buffer (1 .. Name_Len - J) := Name_Buffer (J + 1 .. Name_Len); Name_Len := Name_Len - J; return Name_Find; end if; end loop; -- There were no directory separator, just return Name return Name; end Strip_Directory; ------------------ -- Strip_Suffix -- ------------------ function Strip_Suffix (Name : File_Name_Type) return File_Name_Type is begin Get_Name_String (Name); for J in reverse 2 .. Name_Len loop -- If we found the last '.', return part of Name that precedes it if Name_Buffer (J) = '.' then Name_Len := J - 1; return Name_Enter; end if; end loop; return Name; end Strip_Suffix; --------------------------- -- To_Canonical_Dir_Spec -- --------------------------- function To_Canonical_Dir_Spec (Host_Dir : String; Prefix_Style : Boolean) return String_Access is function To_Canonical_Dir_Spec (Host_Dir : Address; Prefix_Flag : Integer) return Address; pragma Import (C, To_Canonical_Dir_Spec, "__gnat_to_canonical_dir_spec"); C_Host_Dir : String (1 .. Host_Dir'Length + 1); Canonical_Dir_Addr : Address; Canonical_Dir_Len : Integer; begin C_Host_Dir (1 .. Host_Dir'Length) := Host_Dir; C_Host_Dir (C_Host_Dir'Last) := ASCII.NUL; if Prefix_Style then Canonical_Dir_Addr := To_Canonical_Dir_Spec (C_Host_Dir'Address, 1); else Canonical_Dir_Addr := To_Canonical_Dir_Spec (C_Host_Dir'Address, 0); end if; Canonical_Dir_Len := C_String_Length (Canonical_Dir_Addr); if Canonical_Dir_Len = 0 then return null; else return To_Path_String_Access (Canonical_Dir_Addr, Canonical_Dir_Len); end if; exception when others => Fail ("erroneous directory spec: ", Host_Dir); return null; end To_Canonical_Dir_Spec; --------------------------- -- To_Canonical_File_List -- --------------------------- function To_Canonical_File_List (Wildcard_Host_File : String; Only_Dirs : Boolean) return String_Access_List_Access is function To_Canonical_File_List_Init (Host_File : Address; Only_Dirs : Integer) return Integer; pragma Import (C, To_Canonical_File_List_Init, "__gnat_to_canonical_file_list_init"); function To_Canonical_File_List_Next return Address; pragma Import (C, To_Canonical_File_List_Next, "__gnat_to_canonical_file_list_next"); procedure To_Canonical_File_List_Free; pragma Import (C, To_Canonical_File_List_Free, "__gnat_to_canonical_file_list_free"); Num_Files : Integer; C_Wildcard_Host_File : String (1 .. Wildcard_Host_File'Length + 1); begin C_Wildcard_Host_File (1 .. Wildcard_Host_File'Length) := Wildcard_Host_File; C_Wildcard_Host_File (C_Wildcard_Host_File'Last) := ASCII.NUL; -- Do the expansion and say how many there are Num_Files := To_Canonical_File_List_Init (C_Wildcard_Host_File'Address, Boolean'Pos (Only_Dirs)); declare Canonical_File_List : String_Access_List (1 .. Num_Files); Canonical_File_Addr : Address; Canonical_File_Len : Integer; begin -- Retrieve the expanded directoy names and build the list for J in 1 .. Num_Files loop Canonical_File_Addr := To_Canonical_File_List_Next; Canonical_File_Len := C_String_Length (Canonical_File_Addr); Canonical_File_List (J) := To_Path_String_Access (Canonical_File_Addr, Canonical_File_Len); end loop; -- Free up the storage To_Canonical_File_List_Free; return new String_Access_List'(Canonical_File_List); end; end To_Canonical_File_List; ---------------------------- -- To_Canonical_File_Spec -- ---------------------------- function To_Canonical_File_Spec (Host_File : String) return String_Access is function To_Canonical_File_Spec (Host_File : Address) return Address; pragma Import (C, To_Canonical_File_Spec, "__gnat_to_canonical_file_spec"); C_Host_File : String (1 .. Host_File'Length + 1); Canonical_File_Addr : Address; Canonical_File_Len : Integer; begin C_Host_File (1 .. Host_File'Length) := Host_File; C_Host_File (C_Host_File'Last) := ASCII.NUL; Canonical_File_Addr := To_Canonical_File_Spec (C_Host_File'Address); Canonical_File_Len := C_String_Length (Canonical_File_Addr); if Canonical_File_Len = 0 then return null; else return To_Path_String_Access (Canonical_File_Addr, Canonical_File_Len); end if; exception when others => Fail ("erroneous file spec: ", Host_File); return null; end To_Canonical_File_Spec; ---------------------------- -- To_Canonical_Path_Spec -- ---------------------------- function To_Canonical_Path_Spec (Host_Path : String) return String_Access is function To_Canonical_Path_Spec (Host_Path : Address) return Address; pragma Import (C, To_Canonical_Path_Spec, "__gnat_to_canonical_path_spec"); C_Host_Path : String (1 .. Host_Path'Length + 1); Canonical_Path_Addr : Address; Canonical_Path_Len : Integer; begin C_Host_Path (1 .. Host_Path'Length) := Host_Path; C_Host_Path (C_Host_Path'Last) := ASCII.NUL; Canonical_Path_Addr := To_Canonical_Path_Spec (C_Host_Path'Address); Canonical_Path_Len := C_String_Length (Canonical_Path_Addr); -- Return a null string (vice a null) for zero length paths, for -- compatibility with getenv(). return To_Path_String_Access (Canonical_Path_Addr, Canonical_Path_Len); exception when others => Fail ("erroneous path spec: ", Host_Path); return null; end To_Canonical_Path_Spec; --------------------------- -- To_Host_Dir_Spec -- --------------------------- function To_Host_Dir_Spec (Canonical_Dir : String; Prefix_Style : Boolean) return String_Access is function To_Host_Dir_Spec (Canonical_Dir : Address; Prefix_Flag : Integer) return Address; pragma Import (C, To_Host_Dir_Spec, "__gnat_to_host_dir_spec"); C_Canonical_Dir : String (1 .. Canonical_Dir'Length + 1); Host_Dir_Addr : Address; Host_Dir_Len : Integer; begin C_Canonical_Dir (1 .. Canonical_Dir'Length) := Canonical_Dir; C_Canonical_Dir (C_Canonical_Dir'Last) := ASCII.NUL; if Prefix_Style then Host_Dir_Addr := To_Host_Dir_Spec (C_Canonical_Dir'Address, 1); else Host_Dir_Addr := To_Host_Dir_Spec (C_Canonical_Dir'Address, 0); end if; Host_Dir_Len := C_String_Length (Host_Dir_Addr); if Host_Dir_Len = 0 then return null; else return To_Path_String_Access (Host_Dir_Addr, Host_Dir_Len); end if; end To_Host_Dir_Spec; ---------------------------- -- To_Host_File_Spec -- ---------------------------- function To_Host_File_Spec (Canonical_File : String) return String_Access is function To_Host_File_Spec (Canonical_File : Address) return Address; pragma Import (C, To_Host_File_Spec, "__gnat_to_host_file_spec"); C_Canonical_File : String (1 .. Canonical_File'Length + 1); Host_File_Addr : Address; Host_File_Len : Integer; begin C_Canonical_File (1 .. Canonical_File'Length) := Canonical_File; C_Canonical_File (C_Canonical_File'Last) := ASCII.NUL; Host_File_Addr := To_Host_File_Spec (C_Canonical_File'Address); Host_File_Len := C_String_Length (Host_File_Addr); if Host_File_Len = 0 then return null; else return To_Path_String_Access (Host_File_Addr, Host_File_Len); end if; end To_Host_File_Spec; --------------------------- -- To_Path_String_Access -- --------------------------- function To_Path_String_Access (Path_Addr : Address; Path_Len : Integer) return String_Access is subtype Path_String is String (1 .. Path_Len); type Path_String_Access is access Path_String; function Address_To_Access is new Unchecked_Conversion (Source => Address, Target => Path_String_Access); Path_Access : constant Path_String_Access := Address_To_Access (Path_Addr); Return_Val : String_Access; begin Return_Val := new String (1 .. Path_Len); for J in 1 .. Path_Len loop Return_Val (J) := Path_Access (J); end loop; return Return_Val; end To_Path_String_Access; ----------------- -- Update_Path -- ----------------- function Update_Path (Path : String_Ptr) return String_Ptr is function C_Update_Path (Path, Component : Address) return Address; pragma Import (C, C_Update_Path, "update_path"); function Strlen (Str : Address) return Integer; pragma Import (C, Strlen, "strlen"); procedure Strncpy (X : Address; Y : Address; Length : Integer); pragma Import (C, Strncpy, "strncpy"); In_Length : constant Integer := Path'Length; In_String : String (1 .. In_Length + 1); Component_Name : aliased String := "GCC" & ASCII.NUL; Result_Ptr : Address; Result_Length : Integer; Out_String : String_Ptr; begin In_String (1 .. In_Length) := Path.all; In_String (In_Length + 1) := ASCII.NUL; Result_Ptr := C_Update_Path (In_String'Address, Component_Name'Address); Result_Length := Strlen (Result_Ptr); Out_String := new String (1 .. Result_Length); Strncpy (Out_String.all'Address, Result_Ptr, Result_Length); return Out_String; end Update_Path; ---------------- -- Write_Info -- ---------------- procedure Write_Info (Info : String) is begin Write_With_Check (Info'Address, Info'Length); Write_With_Check (EOL'Address, 1); end Write_Info; ------------------------ -- Write_Program_Name -- ------------------------ procedure Write_Program_Name is Save_Buffer : constant String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); begin Find_Program_Name; -- Convert the name to lower case so error messages are the same on -- all systems. for J in 1 .. Name_Len loop if Name_Buffer (J) in 'A' .. 'Z' then Name_Buffer (J) := Character'Val (Character'Pos (Name_Buffer (J)) + 32); end if; end loop; Write_Str (Name_Buffer (1 .. Name_Len)); -- Restore Name_Buffer which was clobbered by the call to -- Find_Program_Name Name_Len := Save_Buffer'Last; Name_Buffer (1 .. Name_Len) := Save_Buffer; end Write_Program_Name; ---------------------- -- Write_With_Check -- ---------------------- procedure Write_With_Check (A : Address; N : Integer) is Ignore : Boolean; begin if N = Write (Output_FD, A, N) then return; else Write_Str ("error: disk full writing "); Write_Name_Decoded (Output_File_Name); Write_Eol; Name_Len := Name_Len + 1; Name_Buffer (Name_Len) := ASCII.NUL; Delete_File (Name_Buffer'Address, Ignore); Exit_Program (E_Fatal); end if; end Write_With_Check; ---------------------------- -- Package Initialization -- ---------------------------- begin Initialization : declare function Get_Default_Identifier_Character_Set return Character; pragma Import (C, Get_Default_Identifier_Character_Set, "__gnat_get_default_identifier_character_set"); -- Function to determine the default identifier character set, -- which is system dependent. See Opt package spec for a list of -- the possible character codes and their interpretations. function Get_Maximum_File_Name_Length return Int; pragma Import (C, Get_Maximum_File_Name_Length, "__gnat_get_maximum_file_name_length"); -- Function to get maximum file name length for system begin Identifier_Character_Set := Get_Default_Identifier_Character_Set; Maximum_File_Name_Length := Get_Maximum_File_Name_Length; -- Following should be removed by having above function return -- Integer'Last as indication of no maximum instead of -1 ??? if Maximum_File_Name_Length = -1 then Maximum_File_Name_Length := Int'Last; end if; Src_Search_Directories.Set_Last (Primary_Directory); Src_Search_Directories.Table (Primary_Directory) := new String'(""); Lib_Search_Directories.Set_Last (Primary_Directory); Lib_Search_Directories.Table (Primary_Directory) := new String'(""); Osint.Initialize; end Initialization; end Osint;
-- AOC, Day 2 with Ada.Text_IO; use Ada.Text_IO; with IntCode; procedure main is subtype Input_Int is Integer range 0 .. 99; function run_once(noun : in Input_Int; verb : in Input_Int) return Integer is begin IntCode.load_file("day2_input.txt"); IntCode.poke(1, Integer(noun)); IntCode.poke(2, Integer(verb)); IntCode.eval; return IntCode.peek(0); end run_once; target : constant Integer := 19690720; result : Integer; begin put_line("Part 1: " & Integer'Image(run_once(12, 2))); for noun in Input_Int'Range loop for verb in Input_Int'Range loop result := run_once(noun, verb); if result = target then put_line("Found target, noun: " & Integer'Image(noun) & ", verb: " & Integer'Image(verb)); put_line("Part 2: " & Integer'Image((100 * noun) + verb)); end if; end loop; end loop; end main;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S Y S T E M . E X C E P T I O N _ T A B L E -- -- -- -- B o d y -- -- -- -- Copyright (C) 1996-2014, 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. -- -- -- ------------------------------------------------------------------------------ pragma Compiler_Unit_Warning; with System.Soft_Links; use System.Soft_Links; package body System.Exception_Table is use System.Standard_Library; type Hash_Val is mod 2 ** 8; subtype Hash_Idx is Hash_Val range 1 .. 37; HTable : array (Hash_Idx) of aliased Exception_Data_Ptr; -- Actual hash table containing all registered exceptions -- -- The table is very small and the hash function weak, as looking up -- registered exceptions is rare and minimizing space and time overhead -- of registration is more important. In addition, it is expected that the -- exceptions that need to be looked up are registered dynamically, and -- therefore will be at the begin of the hash chains. -- -- The table differs from System.HTable.Static_HTable in that the final -- element of each chain is not marked by null, but by a pointer to self. -- This way it is possible to defend against the same entry being inserted -- twice, without having to do a lookup which is relatively expensive for -- programs with large number -- -- All non-local subprograms use the global Task_Lock to protect against -- concurrent use of the exception table. This is needed as local -- exceptions may be declared concurrently with those declared at the -- library level. -- Local Subprograms generic with procedure Process (T : Exception_Data_Ptr; More : out Boolean); procedure Iterate; -- Iterate over all function Lookup (Name : String) return Exception_Data_Ptr; -- Find and return the Exception_Data of the exception with the given Name -- (which must be in all uppercase), or null if none was registered. procedure Register (Item : Exception_Data_Ptr); -- Register an exception with the given Exception_Data in the table. function Has_Name (Item : Exception_Data_Ptr; Name : String) return Boolean; -- Return True iff Item.Full_Name and Name are equal. Both names are -- assumed to be in all uppercase and end with ASCII.NUL. function Hash (S : String) return Hash_Idx; -- Return the index in the hash table for S, which is assumed to be all -- uppercase and end with ASCII.NUL. -------------- -- Has_Name -- -------------- function Has_Name (Item : Exception_Data_Ptr; Name : String) return Boolean is S : constant Big_String_Ptr := To_Ptr (Item.Full_Name); J : Integer := S'First; begin for K in Name'Range loop -- Note that as both items are terminated with ASCII.NUL, the -- comparison below must fail for strings of different lengths. if S (J) /= Name (K) then return False; end if; J := J + 1; end loop; return True; end Has_Name; ------------ -- Lookup -- ------------ function Lookup (Name : String) return Exception_Data_Ptr is Prev : Exception_Data_Ptr; Curr : Exception_Data_Ptr; begin Curr := HTable (Hash (Name)); Prev := null; while Curr /= Prev loop if Has_Name (Curr, Name) then return Curr; end if; Prev := Curr; Curr := Curr.HTable_Ptr; end loop; return null; end Lookup; ---------- -- Hash -- ---------- function Hash (S : String) return Hash_Idx is Hash : Hash_Val := 0; begin for J in S'Range loop exit when S (J) = ASCII.NUL; Hash := Hash xor Character'Pos (S (J)); end loop; return Hash_Idx'First + Hash mod (Hash_Idx'Last - Hash_Idx'First + 1); end Hash; ------------- -- Iterate -- ------------- procedure Iterate is More : Boolean; Prev, Curr : Exception_Data_Ptr; begin Outer : for Idx in HTable'Range loop Prev := null; Curr := HTable (Idx); while Curr /= Prev loop Process (Curr, More); exit Outer when not More; Prev := Curr; Curr := Curr.HTable_Ptr; end loop; end loop Outer; end Iterate; -------------- -- Register -- -------------- procedure Register (Item : Exception_Data_Ptr) is begin if Item.HTable_Ptr = null then Prepend_To_Chain : declare Chain : Exception_Data_Ptr renames HTable (Hash (To_Ptr (Item.Full_Name).all)); begin if Chain = null then Item.HTable_Ptr := Item; else Item.HTable_Ptr := Chain; end if; Chain := Item; end Prepend_To_Chain; end if; end Register; ------------------------------- -- Get_Registered_Exceptions -- ------------------------------- procedure Get_Registered_Exceptions (List : out Exception_Data_Array; Last : out Integer) is procedure Get_One (Item : Exception_Data_Ptr; More : out Boolean); -- Add Item to List (List'First .. Last) by first incrementing Last -- and storing Item in List (Last). Last should be in List'First - 1 -- and List'Last. procedure Get_All is new Iterate (Get_One); -- Store all registered exceptions in List, updating Last ------------- -- Get_One -- ------------- procedure Get_One (Item : Exception_Data_Ptr; More : out Boolean) is begin if Last < List'Last then Last := Last + 1; List (Last) := Item; More := True; else More := False; end if; end Get_One; begin -- In this routine the invariant is that List (List'First .. Last) -- contains the registered exceptions retrieved so far. Last := List'First - 1; Lock_Task.all; Get_All; Unlock_Task.all; end Get_Registered_Exceptions; ------------------------ -- Internal_Exception -- ------------------------ function Internal_Exception (X : String; Create_If_Not_Exist : Boolean := True) return Exception_Data_Ptr is -- If X was not yet registered and Create_if_Not_Exist is True, -- dynamically allocate and register a new exception. type String_Ptr is access all String; Dyn_Copy : String_Ptr; Copy : aliased String (X'First .. X'Last + 1); Result : Exception_Data_Ptr; begin Lock_Task.all; Copy (X'Range) := X; Copy (Copy'Last) := ASCII.NUL; Result := Lookup (Copy); -- If unknown exception, create it on the heap. This is a legitimate -- situation in the distributed case when an exception is defined -- only in a partition if Result = null and then Create_If_Not_Exist then Dyn_Copy := new String'(Copy); Result := new Exception_Data' (Not_Handled_By_Others => False, Lang => 'A', Name_Length => Copy'Length, Full_Name => Dyn_Copy.all'Address, HTable_Ptr => null, Foreign_Data => Null_Address, Raise_Hook => null); Register (Result); end if; Unlock_Task.all; return Result; end Internal_Exception; ------------------------ -- Register_Exception -- ------------------------ procedure Register_Exception (X : Exception_Data_Ptr) is begin Lock_Task.all; Register (X); Unlock_Task.all; end Register_Exception; --------------------------------- -- Registered_Exceptions_Count -- --------------------------------- function Registered_Exceptions_Count return Natural is Count : Natural := 0; procedure Count_Item (Item : Exception_Data_Ptr; More : out Boolean); -- Update Count for given Item procedure Count_Item (Item : Exception_Data_Ptr; More : out Boolean) is pragma Unreferenced (Item); begin Count := Count + 1; More := Count < Natural'Last; end Count_Item; procedure Count_All is new Iterate (Count_Item); begin Lock_Task.all; Count_All; Unlock_Task.all; return Count; end Registered_Exceptions_Count; begin -- Register the standard exceptions at elaboration time -- We don't need to use the locking version here as the elaboration -- will not be concurrent and no tasks can call any subprograms of this -- unit before it has been elaborated. Register (Abort_Signal_Def'Access); Register (Tasking_Error_Def'Access); Register (Storage_Error_Def'Access); Register (Program_Error_Def'Access); Register (Numeric_Error_Def'Access); Register (Constraint_Error_Def'Access); end System.Exception_Table;
with Ada.Unchecked_Deallocation; package body Serialization.YAML is use type Ada.Strings.Unbounded.String_Access; use type Standard.YAML.Event_Type; Null_String : aliased String := ""; procedure Free is new Ada.Unchecked_Deallocation (Serializer, Serializer_Access); procedure Free_And_Null (X : in out Ada.Strings.Unbounded.String_Access) is begin if X /= Null_String'Access then Ada.Strings.Unbounded.Free (X); X := Null_String'Access; end if; end Free_And_Null; procedure Free is new Ada.Unchecked_Deallocation (Reader, Reader_Access); procedure Free is new Ada.Unchecked_Deallocation (Writer, Writer_Access); -- private implementation overriding procedure Finalize (Object : in out Reference_Type) is begin Free (Object.Serializer_Body); if Object.Reader_Body /= null then if Object.Reader_Body.Next_Name /= Null_String'Access then Ada.Strings.Unbounded.Free (Object.Reader_Body.Next_Name); end if; if Object.Reader_Body.Next_Value /= Null_String'Access then Ada.Strings.Unbounded.Free (Object.Reader_Body.Next_Value); end if; Free (Object.Reader_Body); end if; if Object.Writer_Body /= null then Ada.Strings.Unbounded.Free (Object.Writer_Body.Tag); Free (Object.Writer_Body); end if; end Finalize; -- reading procedure Handle ( Object : not null access Reader; Event : in Standard.YAML.Event) is begin case Event.Event_Type is when Standard.YAML.Alias => Object.Next_Kind := Value; Free_And_Null (Object.Next_Value); if Object.Level = 0 then Standard.YAML.Get_Document_End (Object.Parser.all); end if; when Standard.YAML.Scalar => Object.Next_Kind := Value; Free_And_Null (Object.Next_Value); Object.Next_Value := new String'(Event.Value.all); if Object.Level = 0 then Standard.YAML.Get_Document_End (Object.Parser.all); end if; when Standard.YAML.Sequence_Start => Object.Next_Kind := Enter_Sequence; Free_And_Null (Object.Next_Value); Object.Level := Object.Level + 1; when Standard.YAML.Sequence_End => Object.Next_Kind := Leave_Sequence; Free_And_Null (Object.Next_Value); Object.Level := Object.Level - 1; if Object.Level = 0 then Standard.YAML.Get_Document_End (Object.Parser.all); end if; when Standard.YAML.Mapping_Start => Object.Next_Kind := Enter_Mapping; Free_And_Null (Object.Next_Value); Object.Level := Object.Level + 1; when Standard.YAML.Mapping_End => Object.Next_Kind := Leave_Mapping; Free_And_Null (Object.Next_Value); Object.Level := Object.Level - 1; if Object.Level = 0 then Standard.YAML.Get_Document_End (Object.Parser.all); end if; when Standard.YAML.No_Event | Standard.YAML.Stream_Start | Standard.YAML.Stream_End | Standard.YAML.Document_Start | Standard.YAML.Document_End => Object.Next_Kind := End_Of_Stream; Free_And_Null (Object.Next_Value); end case; end Handle; procedure Advance_Start (Object : not null access Reader; Tag : in String) is Parsing_Entry : aliased Standard.YAML.Parsing_Entry_Type; begin Standard.YAML.Get (Object.Parser.all, Parsing_Entry); declare Event : Standard.YAML.Event renames Standard.YAML.Value (Parsing_Entry).Element.all; begin if Event.Tag /= null then declare Event_Tag : String renames Event.Tag.all; First : Positive := Event_Tag'First; begin if First <= Event_Tag'Last and then Event_Tag (First) = '!' then First := First + 1; end if; if Event_Tag (First .. Event_Tag'Last) /= Tag then raise Standard.YAML.Data_Error with """" & Event_Tag & """ is not expected tag (""" & Tag & """) ."; end if; end; end if; Handle (Object, Event); end; end Advance_Start; -- implementation of reading function Reading ( Parser : not null access Standard.YAML.Parser; Tag : String) return Reference_Type is pragma Suppress (Accessibility_Check); R : Reader_Access; S : Serializer_Access; In_Controlled : Boolean := False; begin R := new Reader'( Parser => Parser, Next_Kind => End_Of_Stream, Next_Name => Null_String'Access, Next_Value => Null_String'Access, Level => 0); S := new Serializer'(Direction => Reading, Reader => R); return Result : constant Reference_Type := (Ada.Finalization.Limited_Controlled with Serializer => S, Serializer_Body => S, Reader_Body => R, Writer_Body => null) do pragma Unreferenced (Result); In_Controlled := True; Standard.YAML.Get_Document_Start (R.Parser.all); Advance_Start (R, Tag); end return; exception when others => if not In_Controlled then if R /= null then if R.Next_Name /= Null_String'Access then Ada.Strings.Unbounded.Free (R.Next_Name); end if; if R.Next_Value /= Null_String'Access then Ada.Strings.Unbounded.Free (R.Next_Value); end if; Free (R); end if; Free (S); end if; raise; end Reading; -- private implementation of reading overriding function Next_Kind (Object : not null access Reader) return Stream_Element_Kind is begin return Object.Next_Kind; end Next_Kind; overriding function Next_Name (Object : not null access Reader) return not null access constant String is begin return Object.Next_Name; end Next_Name; overriding function Next_Value (Object : not null access Reader) return not null access constant String is begin return Object.Next_Value; end Next_Value; overriding procedure Advance ( Object : not null access Reader; Position : in State) is begin Free_And_Null (Object.Next_Name); if Position = In_Mapping then declare Parsing_Entry : aliased Standard.YAML.Parsing_Entry_Type; begin Standard.YAML.Get (Object.Parser.all, Parsing_Entry); declare Event : Standard.YAML.Event renames Standard.YAML.Value (Parsing_Entry).Element.all; begin case Event.Event_Type is when Standard.YAML.Scalar => Object.Next_Name := new String'(Event.Value.all); when Standard.YAML.Mapping_Start | Standard.YAML.Sequence_Start => Handle (Object, Event); -- complex mapping key Advance_Structure (Object, In_Mapping); Free_And_Null (Object.Next_Name); when others => Handle (Object, Event); -- leaving return; end case; end; end; end if; declare Parsing_Entry : aliased Standard.YAML.Parsing_Entry_Type; begin Standard.YAML.Get (Object.Parser.all, Parsing_Entry); Handle (Object, Standard.YAML.Value (Parsing_Entry).Element.all); end; end Advance; -- writing procedure Emit_Name (Object : not null access Writer; Name : in String) is begin Standard.YAML.Put ( Object.Emitter.all, (Event_Type => Standard.YAML.Scalar, Anchor => null, Tag => null, Value => Name'Unrestricted_Access, Plain_Implicit_Tag => True, Quoted_Implicit_Tag => True, Scalar_Style => Standard.YAML.Any)); end Emit_Name; -- implementation of writing function Writing ( Emitter : not null access Standard.YAML.Emitter; Tag : String) return Reference_Type is pragma Suppress (Accessibility_Check); T : Ada.Strings.Unbounded.String_Access; W : Writer_Access; S : Serializer_Access; In_Controlled : Boolean := False; begin if Tag /= "" then T := new String'("!" & Tag); else T := null; end if; W := new Writer'(Emitter => Emitter, Tag => T, Level => 0); S := new Serializer'(Direction => Writing, Writer => W); return Result : constant Reference_Type := (Ada.Finalization.Limited_Controlled with Serializer => S, Serializer_Body => S, Reader_Body => null, Writer_Body => W) do pragma Unreferenced (Result); In_Controlled := True; Standard.YAML.Put_Document_Start (Emitter.all); end return; exception when others => if not In_Controlled then Ada.Strings.Unbounded.Free (T); Free (W); Free (S); end if; raise; end Writing; -- private implementation of writing overriding procedure Put ( Object : not null access Writer; Name : in String; Item : in String) is Tag : Ada.Strings.Unbounded.String_Access := null; Implicit_Tag : Boolean; begin if Name /= "" then if Object.Tag /= null then raise Program_Error; end if; Emit_Name (Object, Name); Implicit_Tag := True; else if Object.Tag /= null then Tag := Object.Tag; Implicit_Tag := False; else Implicit_Tag := True; end if; end if; Standard.YAML.Put ( Object.Emitter.all, (Event_Type => Standard.YAML.Scalar, Anchor => null, Tag => Tag, Value => Item'Unrestricted_Access, Plain_Implicit_Tag => Implicit_Tag, Quoted_Implicit_Tag => Implicit_Tag, Scalar_Style => Standard.YAML.Any)); if Tag /= null then Object.Tag := null; Ada.Strings.Unbounded.Free (Tag); end if; if Object.Level = 0 then Standard.YAML.Put_Document_End (Object.Emitter.all); end if; end Put; overriding procedure Enter_Mapping ( Object : not null access Writer; Name : in String) is Tag : Ada.Strings.Unbounded.String_Access := null; Implicit_Tag : Boolean; begin if Name /= "" then if Object.Tag /= null then raise Program_Error; end if; Emit_Name (Object, Name); Implicit_Tag := True; else if Object.Tag /= null then Tag := Object.Tag; Implicit_Tag := False; else Implicit_Tag := True; end if; end if; Standard.YAML.Put ( Object.Emitter.all, (Event_Type => Standard.YAML.Mapping_Start, Anchor => null, Tag => Tag, Implicit_Tag => Implicit_Tag, Mapping_Style => Standard.YAML.Any)); if Tag /= null then Object.Tag := null; Ada.Strings.Unbounded.Free (Tag); end if; Object.Level := Object.Level + 1; end Enter_Mapping; overriding procedure Leave_Mapping (Object : not null access Writer) is begin Standard.YAML.Put ( Object.Emitter.all, (Event_Type => Standard.YAML.Mapping_End)); Object.Level := Object.Level - 1; if Object.Level = 0 then Standard.YAML.Put_Document_End (Object.Emitter.all); end if; end Leave_Mapping; overriding procedure Enter_Sequence ( Object : not null access Writer; Name : in String) is Tag : Ada.Strings.Unbounded.String_Access := null; Implicit_Tag : Boolean; begin if Name /= "" then if Object.Tag /= null then raise Program_Error; end if; Emit_Name (Object, Name); Implicit_Tag := True; else if Object.Tag /= null then Tag := Object.Tag; Implicit_Tag := False; else Implicit_Tag := True; end if; end if; Standard.YAML.Put ( Object.Emitter.all, (Event_Type => Standard.YAML.Sequence_Start, Anchor => null, Tag => Tag, Implicit_Tag => Implicit_Tag, Sequence_Style => Standard.YAML.Any)); if Tag /= null then Object.Tag := null; Ada.Strings.Unbounded.Free (Tag); end if; Object.Level := Object.Level + 1; end Enter_Sequence; overriding procedure Leave_Sequence (Object : not null access Writer) is begin Standard.YAML.Put ( Object.Emitter.all, (Event_Type => Standard.YAML.Sequence_End)); Object.Level := Object.Level - 1; if Object.Level = 0 then Standard.YAML.Put_Document_End (Object.Emitter.all); end if; end Leave_Sequence; end Serialization.YAML;
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- package Meta is pragma Pure; end Meta;
-- -- The author disclaims copyright to this source code. In place of -- a legal notice, here is a blessing: -- -- May you do good and not evil. -- May you find forgiveness for yourself and forgive others. -- May you share freely, not taking more than you give. -- with Ada.Strings.Unbounded; with Database.Jobs; with Database.Events; with Commands; with Navigate; with Symbols; package body Web_IO is function Help_Image return HTML_String is use Ada.Strings.Unbounded; S : Unbounded_String; begin Append (S, "<table>"); for Line of Commands.Help_Lines loop Append (S, "<tr><td>" & Line.Command & "</td><td>" & Line.Comment & "</td></tr>"); end loop; Append (S, "</table>"); return To_String (S); end Help_Image; function Jobs_Image return String is use Navigate; use Ada.Strings.Unbounded; use type Types.Job_Id; S : Ada.Strings.Unbounded.Unbounded_String; begin if List.Set.Is_Empty then return "<p>oO No Jobs Oo</p>"; end if; Append (S, "<table><tr><th>DN</th><th>Ref</th><th>Title</th></tr>"); for Index in List.Set.First_Index .. List.Set.Last_Index loop -- Highlight if List.Set (Index).Id = List.Current then Append (S, "<tr style=""Background-Color:#Dddd2222"">"); else Append (S, "<tr>"); end if; -- DONE if Database.Events.Is_Done (List.Set (Index).Id) then Append (S, "<td>" & Symbols.HTML (Symbols.Black_Star) & "</td>"); else Append (S, "<td>" & Symbols.HTML (Symbols.White_Star) & "</td>"); end if; -- Reference Append (S, "<td><a href=""/?cmd=set%20job%20" & List.Refs (Index).Ref & """>" & List.Refs (Index).Ref & "</a></td>"); -- Title if List.Refs (Index).Level = 0 then Append (S, "<td>" & To_String (List.Set (Index).Title) & "</td>"); else Append (S, "<td>" & "___" & To_String (List.Set (Index).Title) & "</td>"); end if; Append (S, "</tr>"); end loop; Append (S, "</table>"); return To_String (S); end Jobs_Image; function Job_Image (Job : in Types.Job_Id) return HTML_String is use Database.Events; use Ada.Strings.Unbounded; Info : constant Types.Job_Info := Database.Jobs.Get_Job_Info (Job); Events : constant Event_Lists.Vector := Get_Job_Events (Job); Done : constant Boolean := Is_Done (Job); Done_Image : constant String := Boolean'Image (Done); A : Unbounded_String := "<p>Title (" & Info.Title & ") (Id " & Job'Img & ")</p>" & "<p>Parent (Id " & Info.Parent'Img & ")</p>" & "<p>Owner (" & Info.Owner & "</p>" & "<p>Status DONE: " & Done_Image & "</p>"; begin Append (A, "<table><tr><th>Date Time</th><th>Event</th></tr>"); for Event of Events loop Append (A, "<tr>" & "<td>" & Event.Stamp & "</td>" & "<td>" & Event.Kind & "</td>" & "</tr>"); end loop; Append (A, "</table>"); return To_String (A); end Job_Image; end Web_IO;
with Tkmrpc.Operations.Ees; with Tkmrpc.Operation_Handlers.Ees.Esa_Acquire; with Tkmrpc.Operation_Handlers.Ees.Esa_Expire; package body Tkmrpc.Dispatchers.Ees is ------------------------------------------------------------------------- procedure Dispatch (Req : Request.Data_Type; Res : out Response.Data_Type) is begin case Req.Header.Operation is when Operations.Ees.Esa_Acquire => Operation_Handlers.Ees.Esa_Acquire.Handle (Req => Req, Res => Res); when Operations.Ees.Esa_Expire => Operation_Handlers.Ees.Esa_Expire.Handle (Req => Req, Res => Res); when others => Res := Response.Null_Data; Res.Header.Operation := Req.Header.Operation; end case; Res.Header.Request_Id := Req.Header.Request_Id; end Dispatch; end Tkmrpc.Dispatchers.Ees;
-- see OpenUxAS\src\Services\AutomationRequestValidatorService.h with DOM.Core; with Automation_Request_Validator; use Automation_Request_Validator; with Automation_Request_Validator_Communication; use Automation_Request_Validator_Communication; package UxAS.Comms.LMCP_Net_Client.Service.Automation_Request_Validation is type Automation_Request_Validator_Service is new Service_Base with private; type Automation_Request_Validator_Service_Ref is access all Automation_Request_Validator_Service; Type_Name : constant String := "AutomationRequestValidatorService"; Directory_Name : constant String := ""; -- static const std::vector<std::string> -- s_registryServiceTypeNames() function Registry_Service_Type_Names return Service_Type_Names_List; -- static ServiceBase* -- create() function Create return Any_Service; private -- static -- ServiceBase::CreationRegistrar<AutomationRequestValidatorService> s_registrar; -- see the package body executable part type Automation_Request_Validator_Service is new Service_Base with record -- TODO: implement these timers, maybe using Timing_Events, but maybe using -- tasks because their purpose is to call send outgoing messages at the -- desired rate -- -- this timer is used to track time for the system to respond to automation requests */ -- uint64_t m_responseTimerId{0}; -- -- this timer is used to track time for the system to wait for task initialization */ -- uint64_t m_taskInitTimerId{0}; -- the maximum time to wait for a response (in ms)*/ -- uint32_t m_maxResponseTime_ms = {5000}; // default: 5000 ms Max_Response_Time : UInt32 := 5000; -- milliseconds Config : Automation_Request_Validator_Configuration_Data; Mailbox : Automation_Request_Validator_Mailbox; State : Automation_Request_Validator_State; end record; overriding procedure Configure (This : in out Automation_Request_Validator_Service; XML_Node : DOM.Core.Element; Result : out Boolean); overriding procedure Initialize (This : in out Automation_Request_Validator_Service; Result : out Boolean); overriding procedure Process_Received_LMCP_Message (This : in out Automation_Request_Validator_Service; Received_Message : not null Any_LMCP_Message; Should_Terminate : out Boolean); -- TODO: TIMER CALLBACKS -- this function gets called when the response timer expires -- void OnResponseTimeout(); -- this function gets called when the tasks involved have not reported initialization in time -- void OnTasksReadyTimeout(); end UxAS.Comms.LMCP_Net_Client.Service.Automation_Request_Validation;
with openGL; package gel.Conversions is function to_GL (Self : in math.Real) return opengl.Real; function to_GL (Self : in math.Vector_3) return opengl.Vector_3; function to_GL (Self : in math.Matrix_3x3) return opengl.Matrix_3x3; function to_GL (Self : in math.Matrix_4x4) return opengl.Matrix_4x4; function to_GL (Self : in geometry_3d.bounding_Box) return opengl.Bounds; function to_Math (Self : in opengl.Vector_3) return math.Vector_3; end gel.Conversions;
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS -- -- -- -- S Y S T E M . V X W O R K S . E X T -- -- -- -- S p e c -- -- -- -- Copyright (C) 2008-2014, 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 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/>. -- -- -- ------------------------------------------------------------------------------ -- This package provides vxworks specific support functions needed -- by System.OS_Interface. -- This is the VxWorks 5 and VxWorks MILS version of this package with Interfaces.C; package System.VxWorks.Ext is pragma Preelaborate; subtype SEM_ID is Long_Integer; -- typedef struct semaphore *SEM_ID; type sigset_t is mod 2 ** Interfaces.C.long'Size; type t_id is new Long_Integer; subtype int is Interfaces.C.int; subtype unsigned is Interfaces.C.unsigned; type Interrupt_Handler is access procedure (parameter : System.Address); pragma Convention (C, Interrupt_Handler); type Interrupt_Vector is new System.Address; function Int_Lock return int; pragma Import (C, Int_Lock, "intLock"); function Int_Unlock (Old : int) return int; pragma Import (C, Int_Unlock, "intUnlock"); function Interrupt_Connect (Vector : Interrupt_Vector; Handler : Interrupt_Handler; Parameter : System.Address := System.Null_Address) return int; pragma Import (C, Interrupt_Connect, "intConnect"); function Interrupt_Context return int; pragma Import (C, Interrupt_Context, "intContext"); function Interrupt_Number_To_Vector (intNum : int) return Interrupt_Vector; pragma Import (C, Interrupt_Number_To_Vector, "__gnat_inum_to_ivec"); function semDelete (Sem : SEM_ID) return int; pragma Import (C, semDelete, "semDelete"); function Task_Cont (tid : t_id) return int; pragma Import (C, Task_Cont, "taskResume"); function Task_Stop (tid : t_id) return int; pragma Import (C, Task_Stop, "taskSuspend"); function kill (pid : t_id; sig : int) return int; pragma Import (C, kill, "kill"); function getpid return t_id; pragma Import (C, getpid, "taskIdSelf"); function Set_Time_Slice (ticks : int) return int; pragma Import (C, Set_Time_Slice, "kernelTimeSlice"); -------------------------------- -- Processor Affinity for SMP -- -------------------------------- function taskCpuAffinitySet (tid : t_id; CPU : int) return int; pragma Convention (C, taskCpuAffinitySet); -- For SMP run-times set the CPU affinity. -- For uniprocessor systems return ERROR status. function taskMaskAffinitySet (tid : t_id; CPU_Set : unsigned) return int; pragma Convention (C, taskMaskAffinitySet); -- For SMP run-times set the CPU mask affinity. -- For uniprocessor systems return ERROR status. end System.VxWorks.Ext;
with SDL; with SDL.Video.Windows; with SDL.Video.Windows.Makers; with SDL.Video.Surfaces; with SDL.Video.Palettes; use SDL.Video.Palettes; with SDL.Video.Pixels; with SDL.Video.Pixel_Formats; use SDL.Video.Pixel_Formats; with SDL.Video.Textures; use SDL.Video.Textures; with SDL.Video.Textures.Makers; with SDL.Video.Renderers; with SDL.Video.Renderers.Makers; use SDL.Video; with Interfaces.C; use Interfaces.C; with Ada.Unchecked_Conversion; with System; use System; package body SDL_Display is W : SDL.Video.Windows.Window; Renderer : SDL.Video.Renderers.Renderer; Texture : SDL.Video.Textures.Texture; SDL_Pixels : System.Address := System.Null_Address; type Texture_1D_Array is array (Natural range <>) of aliased SDL_Pixel; procedure Lock is new SDL.Video.Textures.Lock (Pixel_Pointer_Type => System.Address); function Rendering return Boolean is (SDL_Pixels /= System.Null_Address); ------------------ -- Start_Render -- ------------------ procedure Start_Render is begin Lock (Texture, SDL_Pixels); end Start_Render; ------------------------ -- Draw_Vertical_Line -- ------------------------ procedure Draw_Vertical_Line (X, Start_Y, Stop_Y : Integer; C : SDL_Pixel) is Width : constant Natural := Texture.Get_Size.Width; Height : constant Natural := Texture.Get_Size.Height; Bounded_Start : constant Natural := (if Start_Y > 0 then Start_Y else 0); begin if X in 0 .. Width - 1 then declare Actual_Pixels : Texture_1D_Array (0 .. Natural (Width * Height - 1)) with Address => SDL_Pixels; begin for Y in Bounded_Start .. Integer'Min (Stop_Y, Height - 1) loop Actual_Pixels (X + Y * Natural (Width)) := C; end loop; end; end if; end Draw_Vertical_Line; ---------- -- Fill -- ---------- procedure Fill (C : SDL_Pixel) is Width : constant Natural := Texture.Get_Size.Width; Height : constant Natural := Texture.Get_Size.Height; begin declare Actual_Pixels : Texture_1D_Array (0 .. Natural (Width * Height - 1)) with Address => SDL_Pixels; begin for Elt of Actual_Pixels loop Elt := C; end loop; end; end Fill; ---------------- -- End_Render -- ---------------- procedure End_Render is Width : constant Natural := Texture.Get_Size.Width; Height : constant Natural := Texture.Get_Size.Height; begin Texture.Unlock; SDL_Pixels := System.Null_Address; Renderer.Clear; Renderer.Copy (Texture, To => (0, 0, int (Width), int (Height))); Renderer.Present; end End_Render; ------------------ -- To_SDL_Color -- ------------------ function To_SDL_Color (R, G, B : Unsigned_8) return SDL_Pixel is RB : constant Unsigned_16 := Shift_Right (Unsigned_16 (R), 3) and 16#1F#; GB : constant Unsigned_16 := Shift_Right (Unsigned_16 (G), 2) and 16#3F#; BB : constant Unsigned_16 := Shift_Right (Unsigned_16 (B), 3) and 16#1F#; begin return (Shift_Left (RB, 11) or Shift_Left (GB, 5) or BB); end To_SDL_Color; ---------------- -- Initialize -- ---------------- procedure Initialize is begin if not SDL.Initialise (Flags => SDL.Enable_Screen) then raise Program_Error with "SDL Video init failed"; end if; SDL.Video.Windows.Makers.Create (W, "Ada Voxel", 0, 0, Screen_Width, Screen_Height, Flags => SDL.Video.Windows.Resizable); SDL.Video.Renderers.Makers.Create (Renderer, W); SDL.Video.Textures.Makers.Create (Tex => Texture, Renderer => Renderer, Format => SDL.Video.Pixel_Formats.Pixel_Format_RGB_565, Kind => SDL.Video.Textures.Streaming, Size => (Screen_Width, Screen_Height)); end Initialize; begin Initialize; end SDL_Display;
pragma License (Unrestricted); -- extended unit with Ada.Colors; private with System.Native_Text_IO.Terminal_Colors; package Ada.Text_IO.Terminal.Colors is -- Additional terminal-color handling subprograms. type Color is private; function To_Color (Item : Ada.Colors.RGB) return Color; function To_Grayscale_Color (Item : Ada.Colors.Brightness) return Color; pragma Inline (To_Color); -- renamed pragma Inline (To_Grayscale_Color); -- renamed type Boolean_Parameter (Changing : Boolean := False) is record case Changing is when False => null; when True => Item : Boolean; end case; end record; type Color_Parameter (Changing : Boolean := False) is record case Changing is when False => null; when True => Item : Color; end case; end record; -- for shorthand function "+" (Item : Boolean) return Boolean_Parameter; function "+" (Item : Color) return Color_Parameter; pragma Inline ("+"); procedure Set_Color ( File : File_Type; -- Output_File_Type Reset : Boolean := False; Bold : Boolean_Parameter := (Changing => False); -- only POSIX Underline : Boolean_Parameter := (Changing => False); Blink : Boolean_Parameter := (Changing => False); -- only POSIX Reversed : Boolean_Parameter := (Changing => False); Foreground : Color_Parameter := (Changing => False); Background : Color_Parameter := (Changing => False)); procedure Reset_Color ( File : File_Type); -- Output_File_Type private type Color is new System.Native_Text_IO.Terminal_Colors.Color; function To_Color (Item : Ada.Colors.RGB) return Color renames RGB_To_Color; function To_Grayscale_Color (Item : Ada.Colors.Brightness) return Color renames Brightness_To_Grayscale_Color; end Ada.Text_IO.Terminal.Colors;
-- Copyright (c) 2015-2017 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Incr.Nodes.Tokens; with Incr.Nodes.Ultra_Roots; package body Incr.Documents is package body Constructors is procedure Initialize (Self : aliased in out Document'Class; Root : Nodes.Node_Access) is Child : constant Nodes.Ultra_Roots.Ultra_Root_Access := new Nodes.Ultra_Roots.Ultra_Root (Self'Unchecked_Access); begin Nodes.Ultra_Roots.Constructors.Initialize (Child.all, Root); Self.Ultra_Root := Child; end Initialize; end Constructors; ------------ -- Commit -- ------------ not overriding procedure Commit (Self : in out Document) is Next : Version_Trees.Version; begin Self.Ultra_Root.On_Commit (null); Self.History.Start_Change (Self.History.Changing, Next); end Commit; ------------------- -- End_Of_Stream -- ------------------- function End_Of_Stream (Self : Document) return Nodes.Tokens.Token_Access is Result : constant Nodes.Node_Access := Self.Ultra_Root.Child (Index => 3, Time => Self.History.Changing); begin return Nodes.Tokens.Token_Access (Result); end End_Of_Stream; --------------------- -- Start_Of_Stream -- --------------------- function Start_Of_Stream (Self : Document) return Nodes.Tokens.Token_Access is Result : constant Nodes.Node_Access := Self.Ultra_Root.Child (Index => 1, Time => Self.History.Changing); begin return Nodes.Tokens.Token_Access (Result); end Start_Of_Stream; ---------------- -- Ultra_Root -- ---------------- not overriding function Ultra_Root (Self : Document) return Nodes.Node_Access is begin return Self.Ultra_Root; end Ultra_Root; end Incr.Documents;
------------------------------------------------------------------------------ -- Copyright (c) 2015, Natacha Porté -- -- -- -- 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. -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Natools.Web.Filters provides an interface for stream filters which -- -- interface between Write primitives, and a containers for a filter stack -- -- and a filter map. -- ------------------------------------------------------------------------------ with Ada.Streams; private with Ada.Containers.Indefinite_Doubly_Linked_Lists; package Natools.Web.Filters is pragma Preelaborate; type Filter is interface; procedure Apply (Object : in Filter; Output : in out Ada.Streams.Root_Stream_Type'Class; Data : in Ada.Streams.Stream_Element_Array) is abstract; -- Apply the filter described by Object on Data and append it to Output type Stack is new Filter with private; -- Stack of filters type Side is (Top, Bottom); -- Side on the filter stack: Top is closest to original data, -- Bottom is closest to output stream. overriding procedure Apply (Object : in Stack; Output : in out Ada.Streams.Root_Stream_Type'Class; Data : in Ada.Streams.Stream_Element_Array); -- Apply the whole fiter stack on Data not overriding procedure Insert (Container : in out Stack; Element : in Filter'Class; On : in Side := Top); -- Insert Element in Container not overriding procedure Remove (Container : in out Stack; Element : in Filter'Class; From : in Side := Top); -- Remove the element of Container on the given side, checking it's -- equal to Element (otherwise Program_Error is raised). private package Filter_Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists (Filter'Class); type Stack is new Filter with record Backend : Filter_Lists.List; end record; end Natools.Web.Filters;
-- -- Copyright (c) 2008-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. -- with Ada.Unchecked_Deallocation; package body Ahven.SList is procedure Remove (Ptr : Node_Access) is procedure Free is new Ada.Unchecked_Deallocation (Object => Node, Name => Node_Access); My_Ptr : Node_Access := Ptr; begin Ptr.Next := null; Free (My_Ptr); end Remove; procedure Append (Target : in out List; Node_Data : Element_Type) is New_Node : Node_Access := null; begin if Target.Size = Count_Type'Last then raise List_Full; end if; New_Node := new Node'(Data => Node_Data, Next => null); if Target.Last = null then Target.First := New_Node; else Target.Last.Next := New_Node; end if; Target.Last := New_Node; Target.Size := Target.Size + 1; end Append; procedure Clear (Target : in out List) is Current_Node : Node_Access := Target.First; Next_Node : Node_Access := null; begin while Current_Node /= null loop Next_Node := Current_Node.Next; Remove (Current_Node); Current_Node := Next_Node; end loop; Target.First := null; Target.Last := null; Target.Size := 0; end Clear; function First (Target : List) return Cursor is begin return Cursor (Target.First); end First; function Next (Position : Cursor) return Cursor is begin if Position = null then raise Invalid_Cursor; end if; return Cursor (Position.Next); end Next; function Data (Position : Cursor) return Element_Type is begin if Position = null then raise Invalid_Cursor; end if; return Position.Data; end Data; function Is_Valid (Position : Cursor) return Boolean is begin return Position /= null; end Is_Valid; function Length (Target : List) return Count_Type is begin return Target.Size; end Length; procedure For_Each (Target : List) is Current_Node : Node_Access := Target.First; begin while Current_Node /= null loop Action (Current_Node.Data); Current_Node := Current_Node.Next; end loop; end For_Each; procedure Initialize (Target : in out List) is begin Target.Last := null; Target.First := null; Target.Size := 0; end Initialize; procedure Finalize (Target : in out List) is begin Clear (Target); end Finalize; procedure Adjust (Target : in out List) is Target_Last : Node_Access := null; Target_First : Node_Access := null; Current : Node_Access := Target.First; New_Node : Node_Access; begin -- Recreate the list using the same data while Current /= null loop New_Node := new Node'(Data => Current.Data, Next => null); if Target_Last = null then Target_First := New_Node; else Target_Last.Next := New_Node; end if; Target_Last := New_Node; Current := Current.Next; end loop; Target.First := Target_First; Target.Last := Target_Last; -- No need to adjust size, it is same as before copying end Adjust; end Ahven.SList;
with Ada.Unchecked_Conversion, Interfaces.C.Extensions; package body Libtcod.Maps.Paths is use path_h, Interfaces.C, Interfaces.C.Extensions; subtype Limited_Controlled is Ada.Finalization.Limited_Controlled; type Int_Ptr is access all int; type X_Pos_Ptr is access all X_Pos; type Y_Pos_Ptr is access all Y_Pos; function X_Ptr_To_Int_Ptr is new Ada.Unchecked_Conversion (Source => X_Pos_Ptr, Target => Int_Ptr); function Y_Ptr_To_Int_Ptr is new Ada.Unchecked_Conversion (Source => Y_Pos_Ptr, Target => Int_Ptr); --------------- -- make_path -- --------------- function make_path(m : Map; diagonal_cost : Cost) return Path is begin return p : Path := Path'(Limited_Controlled with TCOD_path_new_using_map(m.data, Float(diagonal_cost))); end make_path; overriding procedure Finalize(p : in out Path) is begin TCOD_path_delete(p.data); end Finalize; ------------- -- compute -- ------------- function compute(p : in out Path; start_x : X_Pos; start_y : Y_Pos; end_x : X_Pos; end_y : Y_Pos) return Boolean is (Boolean(TCOD_path_compute(p.data, int(start_x), int(start_y), int(end_x), int(end_y)))); ---------- -- walk -- ---------- function walk(p : Path; x : aliased out X_Pos; y : aliased out Y_Pos; recalc_when_needed : Boolean := True) return Boolean is (Boolean(TCOD_path_walk(p.data, X_Ptr_To_Int_Ptr(x'Unchecked_Access), Y_Ptr_To_Int_Ptr(y'Unchecked_Access), bool(recalc_when_needed)))); --------- -- get -- --------- procedure get(p : Path; i : Index; x : aliased out X_Pos; y : aliased out Y_Pos) is begin TCOD_path_get(p.data, int(i), X_Ptr_To_Int_Ptr(x'Unchecked_Access), Y_Ptr_To_Int_Ptr(y'Unchecked_Access)); end get; --------------- -- get_start -- --------------- procedure get_start(p : Path; x : aliased out X_Pos; y : aliased out Y_Pos) is begin TCOD_path_get_origin(p.data, X_Ptr_To_Int_Ptr(x'Unchecked_Access), Y_Ptr_To_Int_Ptr(y'Unchecked_Access)); end get_start; ------------- -- get_end -- ------------- procedure get_end(p : Path; x : aliased out X_Pos; y : aliased out Y_Pos) is begin TCOD_path_get_destination(p.data, X_Ptr_To_Int_Ptr(x'Unchecked_Access), Y_Ptr_To_Int_Ptr(y'Unchecked_Access)); end get_end; ----------- -- empty -- ----------- function empty(p : Path) return Boolean is (Boolean(TCOD_path_is_empty(p.data))); ---------- -- size -- ---------- function size(p : Path) return Natural is (Natural(TCOD_path_size(p.data))); ---------------------- -- reverse_in_place -- ---------------------- procedure reverse_in_place(p : in out Path) is begin TCOD_path_reverse(p.data); end reverse_in_place; end Libtcod.Maps.Paths;
package body ACO.Messages is function CAN_Id (Msg : Message) return Id_Type is (Msg.CAN_Id.Id); function Func_Code (Msg : Message) return Function_Code is (Msg.CAN_Id.Code); function Node_Id (Msg : Message) return Node_Nr is (Msg.CAN_Id.Node); function Create (CAN_Id : Id_Type; RTR : Boolean; DLC : Data_Length; Data : Msg_Data) return Message is begin return (CAN_Id => (True, CAN_Id), RTR => RTR, Length => DLC, Data => Data); end Create; function Create (CAN_Id : Id_Type; RTR : Boolean; Data : Data_Array) return Message is Len : constant Natural := Msg_Data'Length - Data'Length; Fill : constant Data_Array (Msg_Data'First .. Msg_Data'First + Len - 1) := (others => Fill_Data); begin return (CAN_Id => (True, CAN_Id), RTR => RTR, Length => Data'Length, Data => Data & Fill); end Create; function Create (Code : Function_Code; Node : Node_Nr; RTR : Boolean; Data : Data_Array) return Message is Tmp : constant CAN_Id_Type := (False, Code, Node); begin return Create (CAN_Id => Tmp.Id, RTR => RTR, Data => Data); end Create; function Trim (S : String) return String is (if S'Length > 1 and then S (S'First) = ' ' then S (S'First + 1 .. S'Last) else S); function Image (Msg : in Message) return String is -- Yuck, but avoids Unbounded_String Data : constant String := "[" & Trim (Msg.Data (0)'Img) & "," & Msg.Data (1)'Img & "," & Msg.Data (2)'Img & "," & Msg.Data (3)'Img & "," & Msg.Data (4)'Img & "," & Msg.Data (5)'Img & "," & Msg.Data (6)'Img & "," & Msg.Data (7)'Img & "]"; begin return "<message" & " code=""" & Trim (Msg.CAN_Id.Code'Img) & """" & " node=""" & Trim (Msg.CAN_Id.Node'Img) & """" & " rtr=""" & Trim (Msg.RTR'Img) & """" & " dlc=""" & Trim (Msg.Length'Img) & """" & ">" & Data & "</message>"; end Image; function Image (CAN_Id : CAN_Id_Type) return String is begin return Trim (CAN_Id.Id'Img) & " (Node=" & Trim (CAN_Id.Node'Img) & ", Code=" & Trim (CAN_Id.Code'Img) & ")"; end Image; procedure Print (Stream : not null access Ada.Streams.Root_Stream_Type'Class; Msg : in Message) is use Ada.Streams; -- Plain text S : constant String := Image (Msg); Buffer : Stream_Element_Array (1 .. Stream_Element_Offset (S'Length)); begin for I in Buffer'Range loop Buffer (I) := Stream_Element (Character'Pos (S (Natural (I)))); end loop; Stream.Write (Buffer); end Print; end ACO.Messages;
-- part of AdaYaml, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "copying.txt" with Ada.Unchecked_Deallocation; -- we need to explicitly with all annotations because their package -- initialization adds them to the annotation map. with Yaml.Transformator.Annotation.Identity; with Yaml.Transformator.Annotation.Concatenation; with Yaml.Transformator.Annotation.Vars; with Yaml.Transformator.Annotation.For_Loop; with Yaml.Transformator.Annotation.Inject; pragma Unreferenced (Yaml.Transformator.Annotation.Concatenation); pragma Unreferenced (Yaml.Transformator.Annotation.Vars); pragma Unreferenced (Yaml.Transformator.Annotation.For_Loop); pragma Unreferenced (Yaml.Transformator.Annotation.Inject); package body Yaml.Transformator.Annotation_Processor is use type Text.Reference; use type Annotation.Node_Context_Type; procedure Free_Array is new Ada.Unchecked_Deallocation (Node_Array, Node_Array_Pointer); procedure Free_Transformator is new Ada.Unchecked_Deallocation (Transformator.Instance'Class, Transformator.Pointer); function New_Processor (Pool : Text.Pool.Reference; Externals : Events.Store.Reference := Events.Store.New_Store) return Pointer is (new Instance'(Ada.Finalization.Limited_Controlled with Pool => Pool, Context => Events.Context.Create (Externals), others => <>)); procedure Finalize_Finished_Annotation_Impl (Object : in out Instance) is begin if Object.Level_Count = Object.Annotations (Object.Annotation_Count).Depth and then not Object.Annotations (Object.Annotation_Count).Impl.Has_Next then if Object.Annotations (Object.Annotation_Count).Swallows_Next then Object.Current_State := Swallowing_Document_End; Object.Current := (Kind => Document_End, others => <>); end if; Free_Transformator (Object.Annotations (Object.Annotation_Count).Impl); Object.Annotation_Count := Object.Annotation_Count - 1; if Object.Annotation_Count = 0 and Object.Next_Event_Storage = Yes then if Object.Current_State = Existing then Object.Next_Event_Storage := Finishing; else Object.Next_Event_Storage := No; end if; end if; end if; end Finalize_Finished_Annotation_Impl; procedure Shift_Through (Object : in out Instance; Start : Natural; E : Event) with Pre => Start <= Object.Annotation_Count is Cur_Annotation : Natural := Start; Cur_Event : Event := E; begin while Cur_Annotation > 0 loop Object.Annotations (Cur_Annotation).Impl.Put (Cur_Event); if Object.Annotations (Cur_Annotation).Impl.Has_Next then Cur_Event := Object.Annotations (Cur_Annotation).Impl.Next; if (Cur_Annotation = Object.Annotation_Count and Object.May_Finish_Transformation) then Finalize_Finished_Annotation_Impl (Object); end if; Cur_Annotation := Cur_Annotation - 1; else loop Cur_Annotation := Cur_Annotation + 1; if Cur_Annotation > Object.Annotation_Count then if Object.May_Finish_Transformation then Finalize_Finished_Annotation_Impl (Object); end if; return; end if; if Object.Annotations (Cur_Annotation).Impl.Has_Next then Cur_Event := Object.Annotations (Cur_Annotation).Impl.Next; if (Cur_Annotation = Object.Annotation_Count and Object.May_Finish_Transformation) then Finalize_Finished_Annotation_Impl (Object); end if; Cur_Annotation := Cur_Annotation - 1; exit; end if; end loop; end if; end loop; Object.Current := Cur_Event; Object.Current_State := (if Object.Current_State = Event_Held_Back then Releasing_Held_Back else Existing); end Shift_Through; procedure Append (Object : in out Instance; E : Event) is begin if Object.Annotation_Count > 0 then if Object.Current_State = Event_Held_Back then Object.May_Finish_Transformation := Object.Held_Back.Kind in Sequence_End | Mapping_End | Scalar | Alias; if E.Kind = Annotation_Start then if Object.Annotation_Count = 1 then Object.Current := Object.Held_Back; Object.Held_Back := E; Object.Current_State := Releasing_Held_Back; return; else Shift_Through (Object, Object.Annotation_Count, Object.Held_Back); end if; else Shift_Through (Object, Object.Annotation_Count, Object.Held_Back); end if; if Object.Current_State = Existing then Object.Held_Back := E; Object.Current_State := Releasing_Held_Back; return; end if; Object.Current_State := Absent; end if; Object.May_Finish_Transformation := E.Kind in Sequence_End | Mapping_End | Scalar | Alias; Shift_Through (Object, Object.Annotation_Count, E); elsif Object.Current_State = Event_Held_Back then Object.Current := Object.Held_Back; Object.Held_Back := E; Object.Current_State := Releasing_Held_Back; else Object.Current := E; Object.Current_State := Existing; end if; end Append; generic type Element_Type is private; type Array_Type is array (Positive range <>) of Element_Type; type Pointer_Type is access Array_Type; procedure Grow (Target : in out not null Pointer_Type; Last : in out Natural); procedure Grow (Target : in out not null Pointer_Type; Last : in out Natural) is procedure Free_Array is new Ada.Unchecked_Deallocation (Array_Type, Pointer_Type); begin if Last = Target'Last then declare Old_Array : Pointer_Type := Target; begin Target := new Array_Type (1 .. Last * 2); Target (1 .. Last) := Old_Array.all; Free_Array (Old_Array); end; end if; Last := Last + 1; end Grow; procedure Grow_Levels is new Grow (Annotation.Node_Context_Type, Level_Array, Level_Array_Pointer); procedure Grow_Annotations is new Grow (Annotated_Node, Node_Array, Node_Array_Pointer); procedure Put (Object : in out Instance; E : Event) is Locals : constant Events.Store.Accessor := Object.Context.Document_Store; begin if Object.Level_Count > 0 then case Object.Levels (Object.Level_Count) is when Annotation.Mapping_Key => Object.Levels (Object.Level_Count) := Annotation.Mapping_Value; when Annotation.Mapping_Value => Object.Levels (Object.Level_Count) := Annotation.Mapping_Key; when others => null; end case; end if; case E.Kind is when Annotation_Start => Locals.Memorize (E); declare use type Annotation.Maps.Cursor; Pos : constant Annotation.Maps.Cursor := (if E.Namespace = Standard_Annotation_Namespace then Annotation.Map.Find (E.Name.Value) else Annotation.Maps.No_Element); begin Grow_Annotations (Object.Annotations, Object.Annotation_Count); if Object.Annotation_Count = 1 then Object.Next_Event_Storage := (if E.Annotation_Properties.Anchor /= Text.Empty then Searching else No); end if; declare Swallows_Previous : Boolean := False; Impl : constant Transformator.Pointer := (if Pos = Annotation.Maps.No_Element then Annotation.Identity.New_Identity else Annotation.Maps.Element (Pos).all (Object.Pool, Object.Levels (Object.Level_Count), Object.Context, Swallows_Previous)); begin Object.Annotations (Object.Annotation_Count) := (Impl => Impl, Depth => Object.Level_Count, Swallows_Next => Swallows_Previous and Object.Level_Count = 1); if Swallows_Previous then if Object.Current_State /= Event_Held_Back then raise Annotation_Error with E.Namespace & E.Name & " applied to a value of a non-scalar mapping key"; end if; Object.Current_State := Absent; end if; Object.Append (E); end; end; Grow_Levels (Object.Levels, Object.Level_Count); Object.Levels (Object.Level_Count) := Annotation.Parameter_Item; when Annotation_End => Locals.Memorize (E); Object.Append (E); Object.Level_Count := Object.Level_Count - 1; when Document_Start => Locals.Clear; Object.Held_Back := E; Object.Current_State := Event_Held_Back; Grow_Levels (Object.Levels, Object.Level_Count); Object.Levels (Object.Level_Count) := Annotation.Document_Root; when Mapping_Start => Locals.Memorize (E); Object.Append (E); Grow_Levels (Object.Levels, Object.Level_Count); Object.Levels (Object.Level_Count) := Annotation.Mapping_Value; when Sequence_Start => Locals.Memorize (E); Object.Append (E); Grow_Levels (Object.Levels, Object.Level_Count); Object.Levels (Object.Level_Count) := Annotation.Sequence_Item; when Mapping_End | Sequence_End => Object.Level_Count := Object.Level_Count - 1; Locals.Memorize (E); Object.Append (E); when Document_End => if Object.Current_State = Swallowing_Document_End then Object.Current_State := Absent; else Object.Current := E; Object.Current_State := Existing; end if; Object.Level_Count := Object.Level_Count - 1; when Scalar => Locals.Memorize (E); if Object.Levels (Object.Level_Count) = Annotation.Mapping_Key then Object.Held_Back := E; Object.Current_State := Event_Held_Back; else Object.Append (E); end if; when Alias => Locals.Memorize (E); Object.Append (E); when Stream_Start | Stream_End => Object.Append (E); end case; end Put; function Has_Next (Object : Instance) return Boolean is (Object.Current_State in Existing | Releasing_Held_Back | Localizing_Alias or (Object.Current_State = Swallowing_Document_End and Object.Current.Kind /= Document_End)); function Next (Object : in out Instance) return Event is procedure Look_For_Additional_Element is begin if Object.Current_State /= Releasing_Held_Back then Object.Current_State := Absent; end if; for Cur_Annotation in 1 .. Object.Annotation_Count loop if Object.Annotations (Cur_Annotation).Impl.Has_Next then declare Next_Event : constant Event := Object.Annotations (Cur_Annotation).Impl.Next; begin if Cur_Annotation = Object.Annotation_Count and Object.May_Finish_Transformation then Finalize_Finished_Annotation_Impl (Object); end if; Shift_Through (Object, Cur_Annotation - 1, Next_Event); end; exit; end if; end loop; if Object.Current_State = Releasing_Held_Back then Object.Current_State := Absent; if Object.Annotation_Count > 0 then Object.May_Finish_Transformation := Object.Held_Back.Kind in Sequence_End | Mapping_End | Scalar | Alias; Shift_Through (Object, Object.Annotation_Count, Object.Held_Back); else Object.Current := Object.Held_Back; Object.Current_State := Existing; end if; end if; end Look_For_Additional_Element; procedure Update_Exists_In_Output (Anchor : Text.Reference) is use type Events.Context.Cursor; begin if Anchor /= Text.Empty then declare Pos : Events.Context.Cursor := Events.Context.Position (Object.Context, Anchor); begin if Pos /= Events.Context.No_Element then declare Referenced : constant Event := Events.Context.First (Pos); begin if Referenced.Start_Position = Object.Current.Start_Position and Referenced.Kind = Object.Current.Kind then Events.Context.Set_Exists_In_Output (Pos); end if; end; end if; end; end if; end Update_Exists_In_Output; procedure Update_Next_Storage (E : Event) is begin case Object.Next_Event_Storage is when Searching => if (case E.Kind is when Annotation_Start => E.Annotation_Properties.Anchor /= Text.Empty, when Mapping_Start | Sequence_Start => E.Collection_Properties.Anchor /= Text.Empty, when Scalar => E.Scalar_Properties.Anchor /= Text.Empty, when others => False) then Object.Context.Transformed_Store.Memorize (E); Object.Next_Event_Storage := Yes; else Object.Next_Event_Storage := No; end if; when Finishing => Object.Context.Transformed_Store.Memorize (E); Object.Next_Event_Storage := No; when Yes => Object.Context.Transformed_Store.Memorize (E); when No => null; end case; end Update_Next_Storage; begin case Object.Current_State is when Existing | Releasing_Held_Back => case Object.Current.Kind is when Alias => if Object.Current_State = Releasing_Held_Back then raise Program_Error with "internal error: alias may never generated while event is held back!"; end if; declare Pos : Events.Context.Cursor := Events.Context.Position (Object.Context, Object.Current.Target); begin if not Events.Context.Exists_In_Ouput (Pos) then Events.Context.Set_Exists_In_Output (Pos); Object.Current_Stream := Events.Context.Retrieve (Pos).Optional; return Ret : constant Event := Object.Current_Stream.Value.Next do Update_Next_Storage (Ret); case Ret.Kind is when Scalar => Object.Current_Stream.Clear; Look_For_Additional_Element; when Mapping_Start | Sequence_Start => Object.Current_State := Localizing_Alias; Object.Stream_Depth := Object.Stream_Depth + 1; when others => raise Program_Error with "alias refers to " & Object.Current.Kind'Img; end case; end return; end if; end; when Scalar => Update_Exists_In_Output (Object.Current.Scalar_Properties.Anchor); when Mapping_Start | Sequence_Start => Update_Exists_In_Output (Object.Current.Collection_Properties.Anchor); when others => null; end case; return Ret : constant Event := Object.Current do Update_Next_Storage (Ret); Look_For_Additional_Element; end return; when Localizing_Alias => return Ret : constant Event := Object.Current_Stream.Value.Next do Update_Next_Storage (Ret); case Ret.Kind is when Mapping_Start | Sequence_Start => Object.Stream_Depth := Object.Stream_Depth + 1; when Mapping_End | Sequence_End => Object.Stream_Depth := Object.Stream_Depth - 1; if Object.Stream_Depth = 0 then Object.Current_Stream.Clear; Look_For_Additional_Element; end if; when others => null; end case; end return; when Swallowing_Document_End => if Object.Current.Kind = Document_End then raise Constraint_Error with "no event to retrieve"; else return Ret : constant Event := Object.Current do Update_Next_Storage (Ret); Object.Current := (Kind => Document_End, others => <>); end return; end if; when Absent | Event_Held_Back => raise Constraint_Error with "no event to retrieve"; end case; end Next; procedure Finalize (Object : in out Instance) is Ptr : Node_Array_Pointer := Object.Annotations; begin for I in 1 .. Object.Annotation_Count loop Free_Transformator (Object.Annotations (I).Impl); end loop; Free_Array (Ptr); end Finalize; end Yaml.Transformator.Annotation_Processor;
with Ada.Text_IO; with PrimeInstances; with Ada.Containers.Vectors; package body Problem_47 is package IO renames Ada.Text_IO; package Positive_Primes renames PrimeInstances.Positive_Primes; package Positive_Vectors is new Ada.Containers.Vectors(Index_Type => Positive, Element_Type => Positive); procedure Solve is gen : Positive_Primes.Prime_Generator := Positive_Primes.Make_Generator; searching : constant := 4; next_prime : Positive; primes : Positive_Vectors.Vector := Positive_Vectors.Empty_Vector; function Num_Factors(num : Positive) return Natural is factor_count : Natural := 0; function "=" (left,right : Positive_Vectors.Cursor) return Boolean renames Positive_Vectors."="; prime_cursor : Positive_Vectors.Cursor := primes.First; begin while prime_cursor /= Positive_Vectors.No_Element loop declare prime : constant Positive := Positive_Vectors.Element(prime_cursor); begin Positive_Vectors.Next(prime_cursor); exit when prime > num; if num mod prime = 0 then factor_count := Natural'Succ(factor_count); end if; end; end loop; return factor_count; end; begin loop Positive_Primes.Next_Prime(gen, next_prime); primes.Append(next_prime); exit when next_prime > 644; end loop; composite_search: for composite_base in 161 .. 1_000_000 loop declare composite : constant Positive := composite_base * searching; begin while composite > next_prime loop Positive_Primes.Next_Prime(gen, next_prime); primes.Append(next_prime); end loop; if Num_Factors(composite) = searching then declare prime_count : Positive := 1; smallest : Positive := composite; begin for comp in reverse composite - (searching - 1) .. composite - 1 loop if Num_Factors(comp) = searching then prime_count := prime_count + 1; smallest := comp; else exit; end if; end loop; for comp in composite + 1 .. composite + (searching - 1) loop if Num_Factors(comp) = searching then prime_count := prime_count + 1; if prime_count = searching then IO.Put_Line(Positive'Image(smallest)); exit composite_search; end if; else exit; end if; end loop; end; end if; end; end loop composite_search; end Solve; end Problem_47;
with Ada.Integer_Text_IO; with Ada.Text_IO; with Ada.Numerics.Elementary_Functions; with PrimeInstances; package body Problem_05 is package IO renames Ada.Text_IO; package I_IO renames Ada.Integer_Text_IO; package Math renames Ada.Numerics.Elementary_Functions; procedure Solve is package Positive_Primes renames PrimeInstances.Positive_Primes; max_num : constant Positive := 20; max_num_float : constant Float := Float(max_num); max_multiple_prime : constant Positive := Positive(Float'Floor(Math.Sqrt(max_num_float))); gen : Positive_Primes.Prime_Generator := Positive_Primes.Make_Generator(20); prime : Positive; result : Positive := 1; begin loop Positive_Primes.Next_Prime(gen, prime); exit when prime = 1; if prime <= max_multiple_prime then result := result * (prime **Positive(Float'Floor(Math.Log(max_num_float, Base => Float(prime))))); else result := result * prime; end if; end loop; I_IO.Put(result); IO.New_Line; end Solve; end Problem_05;
pragma Source_Reference (3, "p1.adb"); procedure Source_Ref1 is begin null; end;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E M _ C H 1 3 -- -- -- -- S p e c -- -- -- -- Copyright (C) 1992-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. 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 COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Table; with Types; use Types; with Uintp; use Uintp; package Sem_Ch13 is procedure Analyze_At_Clause (N : Node_Id); procedure Analyze_Attribute_Definition_Clause (N : Node_Id); procedure Analyze_Enumeration_Representation_Clause (N : Node_Id); procedure Analyze_Free_Statement (N : Node_Id); procedure Analyze_Freeze_Entity (N : Node_Id); procedure Analyze_Freeze_Generic_Entity (N : Node_Id); procedure Analyze_Record_Representation_Clause (N : Node_Id); procedure Analyze_Code_Statement (N : Node_Id); procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id); -- This procedure is called to analyze aspect specifications for node N. E -- is the corresponding entity declared by the declaration node N. Callers -- should check that Has_Aspects (N) is True before calling this routine. procedure Analyze_Aspect_Specifications_On_Body_Or_Stub (N : Node_Id); -- Analyze the aspect specifications of [generic] subprogram body or stub -- N. Callers should check that Has_Aspects (N) is True before calling the -- routine. This routine diagnoses misplaced aspects that should appear on -- the initial declaration of N and offers suggestions for replacements. procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id); -- Called from Freeze where R is a record entity for which reverse bit -- order is specified and there is at least one component clause. Note: -- component positions are normally adjusted as per AI95-0133, unless -- -gnatd.p is used to restore original Ada 95 mode. procedure Check_Record_Representation_Clause (N : Node_Id); -- This procedure completes the analysis of a record representation clause -- N. It is called at freeze time after adjustment of component clause bit -- positions for possible non-standard bit order. In the case of Ada 2005 -- (machine scalar) mode, this adjustment can make substantial changes, so -- some checks, in particular for component overlaps cannot be done at the -- time the record representation clause is first seen, but must be delayed -- till freeze time, and in particular is called after calling the above -- procedure for adjusting record bit positions for reverse bit order. procedure Initialize; -- Initialize internal tables for new compilation procedure Kill_Rep_Clause (N : Node_Id); -- This procedure is called for a rep clause N when we are in -gnatI mode -- (Ignore_Rep_Clauses). It replaces the node N with a null statement. This -- is only called if Ignore_Rep_Clauses is True. procedure Set_Enum_Esize (T : Entity_Id); -- This routine sets the Esize field for an enumeration type T, based -- on the current representation information available for T. Note that -- the setting of the RM_Size field is not affected. This routine also -- initializes the alignment field to zero. function Minimum_Size (T : Entity_Id; Biased : Boolean := False) return Nat; -- Given an elementary type, determines the minimum number of bits required -- to represent all values of the type. This function may not be called -- with any other types. If the flag Biased is set True, then the minimum -- size calculation that biased representation is used in the case of a -- discrete type, e.g. the range 7..8 gives a minimum size of 4 with -- Biased set to False, and 1 with Biased set to True. Note that the -- biased parameter only has an effect if the type is not biased, it -- causes Minimum_Size to indicate the minimum size of an object with -- the given type, of the size the type would have if it were biased. If -- the type is already biased, then Minimum_Size returns the biased size, -- regardless of the setting of Biased. Also, fixed-point types are never -- biased in the current implementation. If the size is not known at -- compile time, this function returns 0. procedure Check_Constant_Address_Clause (Expr : Node_Id; U_Ent : Entity_Id); -- Expr is an expression for an address clause. This procedure checks -- that the expression is constant, in the limited sense that it is safe -- to evaluate it at the point the object U_Ent is declared, rather than -- at the point of the address clause. The condition for this to be true -- is that the expression has no variables, no constants declared after -- U_Ent, and no calls to non-pure functions. If this condition is not -- met, then an appropriate error message is posted. This check is applied -- at the point an object with an address clause is frozen, as well as for -- address clauses for tasks and entries. procedure Check_Size (N : Node_Id; T : Entity_Id; Siz : Uint; Biased : out Boolean); -- Called when size Siz is specified for subtype T. This subprogram checks -- that the size is appropriate, posting errors on node N as required. -- This check is effective for elementary types and bit-packed arrays. -- For other non-elementary types, a check is only made if an explicit -- size has been given for the type (and the specified size must match). -- The parameter Biased is set False if the size specified did not require -- the use of biased representation, and True if biased representation -- was required to meet the size requirement. Note that Biased is only -- set if the type is not currently biased, but biasing it is the only -- way to meet the requirement. If the type is currently biased, then -- this biased size is used in the initial check, and Biased is False. -- If the size is too small, and an error message is given, then both -- Esize and RM_Size are reset to the allowed minimum value in T. function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean; -- Called at start of processing a representation clause/pragma. Used to -- check that the representation item is not being applied to an incomplete -- type or to a generic formal type or a type derived from a generic formal -- type. Returns False if no such error occurs. If this error does occur, -- appropriate error messages are posted on node N, and True is returned. generic with procedure Replace_Type_Reference (N : Node_Id); procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id); -- This is used to scan an expression for a predicate or invariant aspect -- replacing occurrences of the name of the subtype to which the aspect -- applies with appropriate references to the parameter of the predicate -- function or invariant procedure. The procedure passed as a generic -- parameter does the actual replacement of node N, which is either a -- simple direct reference to T, or a selected component that represents -- an appropriately qualified occurrence of T. function Rep_Item_Too_Late (T : Entity_Id; N : Node_Id; FOnly : Boolean := False) return Boolean; -- Called at the start of processing a representation clause or a -- representation pragma. Used to check that a representation item for -- entity T does not appear too late (according to the rules in RM 13.1(9) -- and RM 13.1(10)). N is the associated node, which in the pragma case -- is the pragma or representation clause itself, used for placing error -- messages if the item is too late. -- -- Fonly is a flag that causes only the freezing rule (para 9) to be -- applied, and the tests of para 10 are skipped. This is appropriate for -- both subtype related attributes (Alignment and Size) and for stream -- attributes, which, although certainly not subtype related attributes, -- clearly should not be subject to the para 10 restrictions (see -- AI95-00137). Similarly, we also skip the para 10 restrictions for -- the Storage_Size case where they also clearly do not apply, and for -- Stream_Convert which is in the same category as the stream attributes. -- -- If the rep item is too late, an appropriate message is output and True -- is returned, which is a signal that the caller should abandon processing -- for the item. If the item is not too late, then False is returned, and -- the caller can continue processing the item. -- -- If no error is detected, this call also as a side effect links the -- representation item onto the head of the representation item chain -- (referenced by the First_Rep_Item field of the entity). -- -- Note: Rep_Item_Too_Late must be called with the underlying type in the -- case of a private or incomplete type. The protocol is to first check for -- Rep_Item_Too_Early using the initial entity, then take the underlying -- type, then call Rep_Item_Too_Late on the result. -- -- Note: Calls to Rep_Item_Too_Late are ignored for the case of attribute -- definition clauses which have From_Aspect_Specification set. This is -- because such clauses are linked on to the Rep_Item chain in procedure -- Sem_Ch13.Analyze_Aspect_Specifications. See that procedure for details. function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean; -- Given two types, where the two types are related by possible derivation, -- determines if the two types have the same representation, or different -- representations, requiring the special processing for representation -- change. A False result is possible only for array, enumeration or -- record types. procedure Validate_Compile_Time_Warning_Error (N : Node_Id); -- N is a pragma Compile_Time_Error or Compile_Warning_Error whose boolean -- expression is not known at compile time. This procedure makes an entry -- in a table. The actual checking is performed by Validate_Compile_Time_ -- Warning_Errors, which is invoked after calling the back end. procedure Validate_Compile_Time_Warning_Errors; -- This routine is called after calling the back end to validate pragmas -- Compile_Time_Error and Compile_Time_Warning for size and alignment -- appropriateness. The reason it is called that late is to take advantage -- of any back-annotation of size and alignment performed by the back end. procedure Validate_Unchecked_Conversion (N : Node_Id; Act_Unit : Entity_Id); -- Validate a call to unchecked conversion. N is the node for the actual -- instantiation, which is used only for error messages. Act_Unit is the -- entity for the instantiation, from which the actual types etc. for this -- instantiation can be determined. This procedure makes an entry in a -- table and/or generates an N_Validate_Unchecked_Conversion node. The -- actual checking is done in Validate_Unchecked_Conversions or in the -- back end as required. procedure Validate_Unchecked_Conversions; -- This routine is called after calling the back end to validate unchecked -- conversions for size and alignment appropriateness. The reason it is -- called that late is to take advantage of any back-annotation of size -- and alignment performed by the back end. procedure Validate_Address_Clauses; -- This is called after the back end has been called (and thus after the -- alignments of objects have been back annotated). It goes through the -- table of saved address clauses checking for suspicious alignments and -- if necessary issuing warnings. procedure Validate_Independence; -- This is called after the back end has been called (and thus after the -- layout of components has been back annotated). It goes through the -- table of saved pragma Independent[_Component] entries, checking that -- independence can be achieved, and if necessary issuing error messages. ------------------------------------- -- Table for Validate_Independence -- ------------------------------------- -- If a legal pragma Independent or Independent_Components is given for -- an entity, then an entry is made in this table, to be checked by a -- call to Validate_Independence after back annotation of layout is done. type Independence_Check_Record is record N : Node_Id; -- The pragma Independent or Independent_Components E : Entity_Id; -- The entity to which it applies end record; package Independence_Checks is new Table.Table ( Table_Component_Type => Independence_Check_Record, Table_Index_Type => Int, Table_Low_Bound => 1, Table_Initial => 20, Table_Increment => 200, Table_Name => "Independence_Checks"); ----------------------------------- -- Handling of Aspect Visibility -- ----------------------------------- -- The visibility of aspects is tricky. First, the visibility is delayed -- to the freeze point. This is not too complicated, what we do is simply -- to leave the aspect "laying in wait" for the freeze point, and at that -- point materialize and analyze the corresponding attribute definition -- clause or pragma. There is some special processing for preconditions -- and postonditions, where the pragmas themselves deal with the required -- delay, but basically the approach is the same, delay analysis of the -- expression to the freeze point. -- Much harder is the requirement for diagnosing cases in which an early -- freeze causes a change in visibility. Consider: -- package AspectVis is -- R_Size : constant Integer := 32; -- -- package Inner is -- type R is new Integer with -- Size => R_Size; -- F : R; -- freezes -- R_Size : constant Integer := 64; -- S : constant Integer := R'Size; -- 32 not 64 -- end Inner; -- end AspectVis; -- Here the 32 not 64 shows what would be expected if this program were -- legal, since the evaluation of R_Size has to be done at the freeze -- point and gets the outer definition not the inner one. -- But the language rule requires this program to be diagnosed as illegal -- because the visibility changes between the freeze point and the end of -- the declarative region. -- To meet this requirement, we first note that the Expression field of the -- N_Aspect_Specification node holds the raw unanalyzed expression, which -- will get used in processing the aspect. At the time of analyzing the -- N_Aspect_Specification node, we create a complete copy of the expression -- and store it in the entity field of the Identifier (an odd usage, but -- the identifier is not used except to identify the aspect, so its Entity -- field is otherwise unused, and we are short of room in the node). -- This copy stays unanalyzed up to the freeze point, where we analyze the -- resulting pragma or attribute definition clause, except that in the -- case of invariants and predicates, we mark occurrences of the subtype -- name as having the entity of the subprogram parameter, so that they -- will not cause trouble in the following steps. -- Then at the freeze point, we create another copy of this unanalyzed -- expression. By this time we no longer need the Expression field for -- other purposes, so we can store it there. Now we have two copies of -- the original unanalyzed expression. One of them gets preanalyzed at -- the freeze point to capture the visibility at the freeze point. -- Now when we hit the freeze all at the end of the declarative part, if -- we come across a frozen entity with delayed aspects, we still have one -- copy of the unanalyzed expression available in the node, and we again -- do a preanalysis using that copy and the visibility at the end of the -- declarative part. Now we have two preanalyzed expression (preanalysis -- is good enough, since we are only interested in referenced entities). -- One captures the visibility at the freeze point, the other captures the -- visibility at the end of the declarative part. We see if the entities -- in these two expressions are the same, by seeing if the two expressions -- are fully conformant, and if not, issue appropriate error messages. -- Quite an awkward approach, but this is an awkard requirement procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id); -- Analyze all the delayed aspects for entity E at freezing point. This -- includes dealing with inheriting delayed aspects from the parent type -- in the case where a derived type is frozen. procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id); -- Performs the processing described above at the freeze point, ASN is the -- N_Aspect_Specification node for the aspect. procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id); -- Performs the processing described above at the freeze all point, and -- issues appropriate error messages if the visibility has indeed changed. -- Again, ASN is the N_Aspect_Specification node for the aspect. procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id); -- Given an entity Typ that denotes a derived type or a subtype, this -- routine performs the inheritance of aspects at the freeze point. procedure Resolve_Aspect_Expressions (E : Entity_Id); -- Name resolution of an aspect expression happens at the end of the -- current declarative part or at the freeze point for the entity, -- whichever comes first. For declarations in the visible part of a -- package, name resolution takes place before analysis of the private -- part even though the freeze point of the entity may appear later. procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id); -- For SPARK 2014 formal containers. The expression has the form of an -- aggregate, and each entry must denote a function with the proper syntax -- for First, Next, and Has_Element. Optionally an Element primitive may -- also be defined. ----------------------------------------------------------- -- Visibility of Discriminants in Aspect Specifications -- ----------------------------------------------------------- -- The discriminants of a type are visible when analyzing the aspect -- specifications of a type declaration or protected type declaration, -- but not when analyzing those of a subtype declaration. The following -- routines enforce this distinction. procedure Install_Discriminants (E : Entity_Id); -- Make visible the discriminants of type entity E procedure Push_Scope_And_Install_Discriminants (E : Entity_Id); -- Push scope E and makes visible the discriminants of type entity E if E -- has discriminants and is not a subtype. procedure Uninstall_Discriminants (E : Entity_Id); -- Remove visibility to the discriminants of type entity E procedure Uninstall_Discriminants_And_Pop_Scope (E : Entity_Id); -- Remove visibility to the discriminants of type entity E and pop the -- scope stack if E has discriminants and is not a subtype. end Sem_Ch13;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S W I T C H -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2011, 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. 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 COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Osint; use Osint; with Output; use Output; package body Switch is ---------------- -- Bad_Switch -- ---------------- procedure Bad_Switch (Switch : Character) is begin Osint.Fail ("invalid switch: " & Switch); end Bad_Switch; procedure Bad_Switch (Switch : String) is begin Osint.Fail ("invalid switch: " & Switch); end Bad_Switch; ------------------------------ -- Check_Version_And_Help_G -- ------------------------------ procedure Check_Version_And_Help_G (Tool_Name : String; Initial_Year : String; Version_String : String := Gnatvsn.Gnat_Version_String) is Version_Switch_Present : Boolean := False; Help_Switch_Present : Boolean := False; Next_Arg : Natural; begin -- First check for --version or --help Next_Arg := 1; while Next_Arg < Arg_Count loop declare Next_Argv : String (1 .. Len_Arg (Next_Arg)); begin Fill_Arg (Next_Argv'Address, Next_Arg); if Next_Argv = Version_Switch then Version_Switch_Present := True; elsif Next_Argv = Help_Switch then Help_Switch_Present := True; end if; Next_Arg := Next_Arg + 1; end; end loop; -- If --version was used, display version and exit if Version_Switch_Present then Set_Standard_Output; Display_Version (Tool_Name, Initial_Year, Version_String); Write_Str (Gnatvsn.Gnat_Free_Software); Write_Eol; Write_Eol; Exit_Program (E_Success); end if; -- If --help was used, display help and exit if Help_Switch_Present then Set_Standard_Output; Usage; Write_Eol; Write_Line ("Report bugs to report@adacore.com"); Exit_Program (E_Success); end if; end Check_Version_And_Help_G; ------------------------------------ -- Display_Usage_Version_And_Help -- ------------------------------------ procedure Display_Usage_Version_And_Help is begin Write_Str (" --version Display version and exit"); Write_Eol; Write_Str (" --help Display usage and exit"); Write_Eol; Write_Eol; end Display_Usage_Version_And_Help; --------------------- -- Display_Version -- --------------------- procedure Display_Version (Tool_Name : String; Initial_Year : String; Version_String : String := Gnatvsn.Gnat_Version_String) is begin Write_Str (Tool_Name); Write_Char (' '); Write_Str (Version_String); Write_Eol; Write_Str ("Copyright (C) "); Write_Str (Initial_Year); Write_Char ('-'); Write_Str (Gnatvsn.Current_Year); Write_Str (", "); Write_Str (Gnatvsn.Copyright_Holder); Write_Eol; end Display_Version; ------------------------- -- Is_Front_End_Switch -- ------------------------- function Is_Front_End_Switch (Switch_Chars : String) return Boolean is Ptr : constant Positive := Switch_Chars'First; begin return Is_Switch (Switch_Chars) and then (Switch_Chars (Ptr + 1) = 'I' or else (Switch_Chars'Length >= 5 and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "gnat") or else (Switch_Chars'Length >= 5 and then Switch_Chars (Ptr + 2 .. Ptr + 4) = "RTS")); end Is_Front_End_Switch; ---------------------------- -- Is_Internal_GCC_Switch -- ---------------------------- function Is_Internal_GCC_Switch (Switch_Chars : String) return Boolean is First : constant Natural := Switch_Chars'First + 1; Last : constant Natural := Switch_Last (Switch_Chars); begin return Is_Switch (Switch_Chars) and then (Switch_Chars (First .. Last) = "-param" or else Switch_Chars (First .. Last) = "dumpbase" or else Switch_Chars (First .. Last) = "auxbase-strip" or else Switch_Chars (First .. Last) = "auxbase"); end Is_Internal_GCC_Switch; --------------- -- Is_Switch -- --------------- function Is_Switch (Switch_Chars : String) return Boolean is begin return Switch_Chars'Length > 1 and then Switch_Chars (Switch_Chars'First) = '-'; end Is_Switch; ----------------- -- Switch_last -- ----------------- function Switch_Last (Switch_Chars : String) return Natural is Last : constant Natural := Switch_Chars'Last; begin if Last >= Switch_Chars'First and then Switch_Chars (Last) = ASCII.NUL then return Last - 1; else return Last; end if; end Switch_Last; ----------------- -- Nat_Present -- ----------------- function Nat_Present (Switch_Chars : String; Max : Integer; Ptr : Integer) return Boolean is begin return (Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9') or else (Ptr < Max and then Switch_Chars (Ptr) = '=' and then Switch_Chars (Ptr + 1) in '0' .. '9'); end Nat_Present; -------------- -- Scan_Nat -- -------------- procedure Scan_Nat (Switch_Chars : String; Max : Integer; Ptr : in out Integer; Result : out Nat; Switch : Character) is begin Result := 0; if not Nat_Present (Switch_Chars, Max, Ptr) then Osint.Fail ("missing numeric value for switch: " & Switch); end if; if Switch_Chars (Ptr) = '=' then Ptr := Ptr + 1; end if; while Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' loop Result := Result * 10 + Character'Pos (Switch_Chars (Ptr)) - Character'Pos ('0'); Ptr := Ptr + 1; if Result > Switch_Max_Value then Osint.Fail ("numeric value out of range for switch: " & Switch); end if; end loop; end Scan_Nat; -------------- -- Scan_Pos -- -------------- procedure Scan_Pos (Switch_Chars : String; Max : Integer; Ptr : in out Integer; Result : out Pos; Switch : Character) is Temp : Nat; begin Scan_Nat (Switch_Chars, Max, Ptr, Temp, Switch); if Temp = 0 then Osint.Fail ("numeric value out of range for switch: " & Switch); end if; Result := Temp; end Scan_Pos; end Switch;
pragma Ada_2012; with Ada.Directories; with Ada.Text_IO; with Ada.Strings.Fixed; with Ada.Characters.Handling; with Generator.Frontmatter; with Generator.Rssfeed; with Generator.Sitemap; with Ada.Text_IO.Text_Streams; with Ada.Streams; with Ada.Streams.Stream_IO; with Ada.Numerics.Discrete_Random; with Progress_Indicators.Spinners; with Version; with Globals; package body Generator is use Ada.Directories; use Ada.Text_IO; use Progress_Indicators.Spinners; package CH renames Ada.Characters.Handling; package CC renames Ada.Characters.Conversions; package DIR renames Ada.Directories; subtype Die is Integer range 1 .. 256; subtype Dice is Integer range 2 * Die'First .. 2 * Die'Last; package Random_Integer is new Ada.Numerics.Discrete_Random (Die); use Random_Integer; function "<" (Left, Right : Document) return Boolean is begin return Left.Basename < Right.Basename; end "<"; function Find (List : Document_Container.List; Name : XString) return Cursor is begin for aDocument in List.Iterate loop if Element (aDocument).Basename = Name then return aDocument; end if; end loop; return No_Element; end Find; ------------------ -- Process_File -- ------------------ procedure Process_File (List : out Document_Container.List; Filepath : String; Targetpath : String; Linkpath : String) is Extension : constant String := CH.To_Upper (DIR.Extension (Filepath)); begin if Extension = "MD" or else Extension = "MARKDOWN" then List.Append ( Generator.Frontmatter.Read (Filepath, Targetpath, Linkpath) ); declare Filein : Ada.Streams.Stream_IO.File_Type; Fileout : Ada.Text_IO.File_Type; begin null; -- Ada.Streams.Stream_IO.Open -- (Filein, Ada.Streams.Stream_IO.In_File, Filepath); -- Ada.Text_IO.Create -- (Fileout, Ada.Text_IO.Out_File,Targetpath); -- Renderer.Set_Output -- (Ada.Text_IO.Text_Streams.Stream(Fileout)); -- Generator.Markdown.To_HTML (Filein); end; elsif Extension = "HTML" or else Extension = "HTM" then List.Append ( Generator.Frontmatter.Read (Filepath, Targetpath, Linkpath) ); elsif Extension = "TMPLT" then List.Append ( Generator.Frontmatter.Read (Filepath, Targetpath, Linkpath) ); else if DIR.Exists (Targetpath) then DIR.Delete_File (Targetpath); end if; Copy_File (Filepath, Targetpath); end if; end Process_File; ----------------------- -- Process_Directory -- ----------------------- procedure Process_Directory (List : out Document_Container.List; Source_Directory : String; Target_Directory : String; LinkpathIn : String) is Linkpath : constant String := Ada.Strings.Fixed.Trim (LinkpathIn, Slash, Slash); Dir : Directory_Entry_Type; Dir_Search : Search_Type; begin if Exists (Source_Directory) then Start_Search (Search => Dir_Search, Directory => Source_Directory, Pattern => "*"); loop Get_Next_Entry (Dir_Search, Dir); if Simple_Name (Dir) /= "." and then Simple_Name (Dir) /= ".." then declare Name : constant String := Simple_Name (Dir); Fullname : constant String := Full_Name (Dir); Targetname : constant String := Compose (Target_Directory, Name); Basename : constant String := Base_Name (Fullname); Process : constant Boolean := Name /= "." and Name /= ".." and Ada.Strings.Fixed.Head (Name, 1) /= "_"; begin if Process then if Debug then Ada.Text_IO.Put_Line (Fullname); end if; if Kind (Dir) = Ordinary_File then Process_File ( List, Fullname, Targetname, Linkpath & "/" & Basename & ".html"); else if not Exists (Targetname) then Create_Directory (Targetname); end if; Process_Directory ( List, Fullname, Targetname, Linkpath & "/" & Name); end if; end if; end; end if; exit when not More_Entries (Dir_Search); end loop; End_Search (Dir_Search); end if; end Process_Directory; function Get_Nav_Links ( Document : Cursor; List : Document_Container.List) return Translate_Set is Set : Translate_Set; P : Cursor := Previous (Document); N : Cursor := Next (Document); begin if P = No_Element then P := Last (List); end if; Insert (Set, Assoc ("previouslink", CC.To_String (To_String (Element (P).Linkpath)))); if N = No_Element then N := First (List); end if; Insert (Set, Assoc ("nextlink", CC.To_String (To_String (Element (N).Linkpath)))); return Set; end Get_Nav_Links; procedure Process_Documents ( List : Document_Container.List; Set : Translate_Set; Layoutfolder : String; Source_Directory : String; Targetpath : String) is begin for Document in List.Iterate loop if Debug then Ada.Text_IO.Put_Line ( CC.To_String ( To_String ( Element (Document).Targetpath)) ); end if; if Length (Element (Document).Layout) > 0 then declare Name : constant String := CC.To_String ( To_String (Element (Document).Layout) ); Base_Name : constant String := DIR.Base_Name (Name); Extension : constant String := DIR.Extension (Name); Layoutfile : constant String := DIR.Compose (Layoutfolder, Base_Name, Extension); Combined_Set : Translate_Set; Filename : constant String := CC.To_String ( To_String (Element (Document).Targetpath) ); begin Insert (Combined_Set, Set); Insert (Combined_Set, Element (Document).T); Insert (Combined_Set, Get_Nav_Links (Document, List)); if DIR.Exists (Layoutfile) then declare F : File_Type; Template : constant String := Templates_Parser.Parse (Layoutfile, Combined_Set); begin if Exists (Filename) then Delete_File (Filename); end if; Create (F, Mode => Out_File, Name => Filename); Put (F, Template); Close (F); end; else Ada.Text_IO.Put_Line ("Layoutfile " & Layoutfile & " does not exist"); end if; end; else Ada.Text_IO.Put_Line ("Layout for " & CC.To_String (To_String ( Element (Document).Filepath)) & " is not defined" ); end if; end loop; end Process_Documents; function Create_Vector ( List : Document_Container.List; Prefix : String) return Translate_Set is Set : Translate_Set; Pagepath : Tag; Pagename : Tag; Pageexcerpt : Tag; begin for Document of List loop declare Name : constant String := Read_From_Set (Document.T, "title"); Base_Name : constant String := CC.To_String (To_String (Document.Basename)); Excerpt : constant String := Read_From_Set (Document.T, "title"); begin Pagepath := Pagepath & Ada.Strings.Fixed.Trim ( CC.To_String (To_String (Document.Linkpath)), Slash, Slash); Pageexcerpt := Pageexcerpt & Excerpt; if Name'Length > 0 then Pagename := Pagename & Name; else Pagename := Pagename & Base_Name; end if; end; end loop; Insert (Set, Assoc (Prefix & "path", Pagepath)); Insert (Set, Assoc (Prefix & "name", Pagename)); Insert (Set, Assoc (Prefix & "excerpt", Pageexcerpt)); return Set; end Create_Vector; function Read_From_Set ( Set : Translate_Set; Token : String) return String is Assoc : constant Association := Get (Set, Token); begin if Assoc /= Null_Association then return Get (Assoc); end if; return ""; end Read_From_Set; ----------- -- Start -- ----------- procedure Start ( Source_Directory : String; Target_Directory : String) is Config_Path : constant String := DIR.Compose (Source_Directory, Globals.Site_Configuration_Name); Layoutfolder : constant String := Compose (Source_Directory, Globals.Layout_Folder_Name); Blog_Source_Directory : constant String := Compose (Source_Directory, Globals.Posts_Source_Folder_Name); Blog_Target_Directory : constant String := Compose (Target_Directory, Globals.Blog_Target_Folder_Name); Documents : Document_Container.List; Posts : Document_Container.List; Set : Translate_Set; Site_Set : Translate_Set; G : Random_Integer.Generator; D : Dice; Indicator : Spinner := Make; Index: Cursor := No_Element; begin Ada.Text_IO.Put (Value (Indicator)); Site_Set := Null_Set; if Exists (Config_Path) then Generator.Frontmatter.Read_Content (Config_Path, Site_Set); else Ada.Text_IO.Put_Line ("No site configuration found at " & Config_Path); end if; -- Copy static files and directories and create List of pages. Process_Directory (Documents, Source_Directory, Target_Directory, ""); Sort (Documents); Index := Find (Documents, To_XString ("index")); if Index /= No_Element then Prepend (Documents, Element (Index)); Delete (Documents, Index); end if; -- Process blog if Exists (Blog_Source_Directory) then -- Copy static files and directories and create List of pages. if not Exists (Blog_Target_Directory) then Create_Directory (Blog_Target_Directory); end if; Process_Directory (Posts, Blog_Source_Directory, Blog_Target_Directory, Globals.Blog_Target_Folder_Name); end if; Sort (Posts); Insert (Set, Create_Vector (Documents, "page")); Insert (Set, Create_Vector (Posts, "post")); Insert (Set, Site_Set); Insert (Set, Assoc ("meta_generator_link", Version.Link)); Insert (Set, Assoc ("meta_generator", Version.Name)); Insert (Set, Assoc ("meta_generator_version", Version.Current)); Reset (G); D := Random (G); Insert (Set, Assoc ("meta_cachebuster", Ada.Strings.Fixed.Trim (D'Image, Ada.Strings.Both))); -- Create RSS feed Insert (Set, Assoc ("atomfeedurl", Generator.Rssfeed.Create (Posts, Target_Directory, Site_Set)) ); -- Create RSS feed Insert (Set, Assoc ("sitemapurl", Generator.Sitemap.Create (Posts, Documents, Target_Directory, Site_Set)) ); -- Process non-static files Process_Documents (Documents, Set, Layoutfolder, Source_Directory, Target_Directory); Process_Documents (Posts, Set, Layoutfolder, Blog_Source_Directory, Blog_Target_Directory); Disable_All; Ada.Text_IO.Put (Value (Indicator)); end Start; end Generator;
type Arr_Type is array (Integer range <>) of Lower_Case; A : Arr_Type (1 .. 26) := "abcdefghijklmnopqrstuvwxyz";
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS -- -- -- -- S Y S T E M . B B . T H R E A D S . Q U E U E S -- -- -- -- B o d y -- -- -- -- Copyright (C) 1999-2002 Universidad Politecnica de Madrid -- -- Copyright (C) 2003-2005 The European Space Agency -- -- Copyright (C) 2003-2021, AdaCore -- -- -- -- 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 3, 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. -- -- -- -- -- -- -- -- -- -- -- -- 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/>. -- -- -- -- GNARL was developed by the GNARL team at Florida State University. -- -- Extensive contributions were provided by Ada Core Technologies, Inc. -- -- -- -- The port of GNARL to bare board targets was initially developed by the -- -- Real-Time Systems Group at the Technical University of Madrid. -- -- -- ------------------------------------------------------------------------------ pragma Restrictions (No_Elaboration_Code); package body System.BB.Threads.Queues is use System.Multiprocessors; use System.BB.Board_Support.Multiprocessors; ---------------- -- Local data -- ---------------- Alarms_Table : array (CPU) of Thread_Id := (others => Null_Thread_Id); pragma Volatile_Components (Alarms_Table); -- Identifier of the thread that is in the first place of the alarm queue --------------------- -- Change_Priority -- --------------------- procedure Change_Priority (Thread : Thread_Id; Priority : Integer) is CPU_Id : constant CPU := BOSUMU.Current_CPU; Head : Thread_Id; Prev_Pointer : Thread_Id; begin -- A CPU can only change the priority of its own tasks pragma Assert (CPU_Id = Get_CPU (Thread)); -- Return now if there is no change. This is a rather common case, as -- it happens if user is not using priorities, or if the priority of -- an interrupt handler is the same as the priority of the interrupt. -- In any case, the check is quick enough. if Thread.Active_Priority = Priority then return; end if; -- Change the active priority. The base priority does not change Thread.Active_Priority := Priority; -- Outside of the executive kernel, the running thread is also the first -- thread in the First_Thread_Table list. This is also true in general -- within the kernel, except during transcient period when a task is -- extracted from the list (blocked by a delay until or on an entry), -- when a task is inserted (after a wakeup), after a yield or after -- this procedure. But then a context_switch put things in order. -- However, on ARM Cortex-M, context switches can be delayed by -- interrupts. They are performed via a special interrupt (Pend_SV), -- which is at the lowest priority. This has three consequences: -- A) it is not possible to have tasks in the Interrupt_Priority range -- B) the head of First_Thread_Table list may be different from the -- running thread within user interrupt handler -- C) the running thread may not be in the First_Thread_Table list. -- The following scenario shows case B: while a thread is running, an -- interrupt awakes a task at a higher priority; it is put in front of -- the First_Thread_Table queue, and a context switch is requested. But -- before the end of the interrupt, another interrupt triggers. It -- increases the priority of the current thread, which is not the -- first in queue. -- The following scenario shows case C: a task is executing a delay -- until and therefore it is removed from the First_Thread_Table. But -- before the context switch, an interrupt triggers and change the -- priority of the running thread. -- First, find THREAD in the queue and remove it temporarly. Head := First_Thread_Table (CPU_Id); if Head = Thread then -- This is the very common case: THREAD is the first in the queue if Thread.Next = Null_Thread_Id or else Priority >= Thread.Next.Active_Priority then -- Already at the right place. return; end if; -- Remove THREAD from the queue Head := Thread.Next; else -- Uncommon case: less than 0.1% on a Cortex-M test. -- Search the thread before THREAD. Prev_Pointer := Head; loop if Prev_Pointer = null then -- THREAD is not in the queue. This corresponds to case B. return; end if; exit when Prev_Pointer.Next = Thread; Prev_Pointer := Prev_Pointer.Next; end loop; -- Remove THREAD from the queue. Prev_Pointer.Next := Thread.Next; end if; -- Now insert THREAD. -- FIFO_Within_Priorities dispatching policy. In ALRM D.2.2 it is -- said that when the active priority is lowered due to the loss of -- inherited priority (the only possible case within the Ravenscar -- profile) the task is added at the head of the ready queue for -- its new active priority. if Priority >= Head.Active_Priority then -- THREAD is the highest priority thread, so put it in the front of -- the queue. Thread.Next := Head; Head := Thread; else -- Search the right place in the queue. Prev_Pointer := Head; while Prev_Pointer.Next /= Null_Thread_Id and then Priority < Prev_Pointer.Next.Active_Priority loop Prev_Pointer := Prev_Pointer.Next; end loop; Thread.Next := Prev_Pointer.Next; Prev_Pointer.Next := Thread; end if; First_Thread_Table (CPU_Id) := Head; end Change_Priority; --------------------------- -- Context_Switch_Needed -- --------------------------- function Context_Switch_Needed return Boolean is begin -- A context switch is needed when there is a higher priority task ready -- to execute. It means that First_Thread is not null and it is not -- equal to the task currently executing (Running_Thread). return First_Thread /= Running_Thread; end Context_Switch_Needed; ---------------------- -- Current_Priority -- ---------------------- function Current_Priority (CPU_Id : System.Multiprocessors.CPU) return Integer is Thread : constant Thread_Id := Running_Thread_Table (CPU_Id); begin if Thread = null or else Thread.State /= Threads.Runnable then return System.Any_Priority'First; else return Thread.Active_Priority; end if; end Current_Priority; ------------- -- Extract -- ------------- procedure Extract (Thread : Thread_Id) is CPU_Id : constant CPU := Get_CPU (Thread); begin -- A CPU can only modify its own tasks queues pragma Assert (CPU_Id = Current_CPU); First_Thread_Table (CPU_Id) := Thread.Next; Thread.Next := Null_Thread_Id; end Extract; ------------------ -- First_Thread -- ------------------ function First_Thread return Thread_Id is begin return First_Thread_Table (Current_CPU); end First_Thread; ------------------------- -- Get_Next_Alarm_Time -- ------------------------- function Get_Next_Alarm_Time (CPU_Id : CPU) return System.BB.Time.Time is Thread : Thread_Id; begin Thread := Alarms_Table (CPU_Id); if Thread = Null_Thread_Id then -- If alarm queue is empty then next alarm to raise will be Time'Last return System.BB.Time.Time'Last; else return Thread.Alarm_Time; end if; end Get_Next_Alarm_Time; ------------ -- Insert -- ------------ procedure Insert (Thread : Thread_Id) is Aux_Pointer : Thread_Id; CPU_Id : constant CPU := Get_CPU (Thread); begin -- A CPU can only insert a task to its own queue, except during -- elaboration where the main CPU will add new tasks to their -- respective CPU's queues. Since the runtime doesn't have a -- mechanism to detect when elaboration has finished, the assertion -- can only catch non-Main CPUs accessing the wrong CPU queues. pragma Assert (CPU_Id = Current_CPU or else CPU_Id = CPU'First); -- No insertion if the task is already at the head of the queue if First_Thread_Table (CPU_Id) = Thread then null; -- Insert at the head of queue if there is no other thread with a higher -- priority. elsif First_Thread_Table (CPU_Id) = Null_Thread_Id or else Thread.Active_Priority > First_Thread_Table (CPU_Id).Active_Priority then Thread.Next := First_Thread_Table (CPU_Id); First_Thread_Table (CPU_Id) := Thread; -- Middle or tail insertion else -- Look for the Aux_Pointer to insert the thread just after it Aux_Pointer := First_Thread_Table (CPU_Id); while Aux_Pointer.Next /= Null_Thread_Id and then Aux_Pointer.Next /= Thread and then Aux_Pointer.Next.Active_Priority >= Thread.Active_Priority loop Aux_Pointer := Aux_Pointer.Next; end loop; -- If we found the thread already in the queue, then we need to move -- it to its right place. if Aux_Pointer.Next = Thread then -- Extract it from its current location Aux_Pointer.Next := Thread.Next; -- Look for the Aux_Pointer to insert the thread just after it while Aux_Pointer.Next /= Null_Thread_Id and then Aux_Pointer.Next.Active_Priority >= Thread.Active_Priority loop Aux_Pointer := Aux_Pointer.Next; end loop; end if; -- Insert the thread after the Aux_Pointer Thread.Next := Aux_Pointer.Next; Aux_Pointer.Next := Thread; end if; end Insert; ------------------ -- Insert_Alarm -- ------------------ procedure Insert_Alarm (T : System.BB.Time.Time; Thread : Thread_Id; Is_First : out Boolean) is CPU_Id : constant CPU := Get_CPU (Thread); Alarm_Id_Aux : Thread_Id; begin -- A CPU can only insert alarm in its own queue pragma Assert (CPU_Id = Current_CPU); -- Set the Alarm_Time within the thread descriptor Thread.Alarm_Time := T; -- Case of empty queue, or new alarm expires earlier, insert the thread -- as the first thread. if Alarms_Table (CPU_Id) = Null_Thread_Id or else T < Alarms_Table (CPU_Id).Alarm_Time then Thread.Next_Alarm := Alarms_Table (CPU_Id); Alarms_Table (CPU_Id) := Thread; Is_First := True; -- Otherwise, place in the middle else -- Find the minimum greater than T alarm within the alarm queue Alarm_Id_Aux := Alarms_Table (CPU_Id); while Alarm_Id_Aux.Next_Alarm /= Null_Thread_Id and then Alarm_Id_Aux.Next_Alarm.Alarm_Time < T loop Alarm_Id_Aux := Alarm_Id_Aux.Next_Alarm; end loop; Thread.Next_Alarm := Alarm_Id_Aux.Next_Alarm; Alarm_Id_Aux.Next_Alarm := Thread; Is_First := False; end if; end Insert_Alarm; -------------------- -- Running_Thread -- -------------------- function Running_Thread return Thread_Id is begin return Running_Thread_Table (Current_CPU); end Running_Thread; --------------------------- -- Wakeup_Expired_Alarms -- --------------------------- procedure Wakeup_Expired_Alarms (Now : Time.Time) is use Time; CPU_Id : constant CPU := Current_CPU; Wakeup_Thread : Thread_Id; begin -- Extract all the threads whose delay has expired while Get_Next_Alarm_Time (CPU_Id) <= Now loop -- Extract the task(s) that was waiting in the alarm queue and insert -- it in the ready queue. Wakeup_Thread := Alarms_Table (CPU_Id); Alarms_Table (CPU_Id) := Wakeup_Thread.Next_Alarm; Wakeup_Thread.Alarm_Time := System.BB.Time.Time'Last; Wakeup_Thread.Next_Alarm := Null_Thread_Id; -- We can only awake tasks that are delay statement pragma Assert (Wakeup_Thread.State = Delayed); Wakeup_Thread.State := Runnable; Insert (Wakeup_Thread); end loop; -- Note: the caller (BB.Time.Alarm_Handler) must set the next alarm end Wakeup_Expired_Alarms; ----------- -- Yield -- ----------- procedure Yield (Thread : Thread_Id) is CPU_Id : constant CPU := Get_CPU (Thread); Prio : constant Integer := Thread.Active_Priority; Aux_Pointer : Thread_Id; begin -- A CPU can only modify its own tasks queues pragma Assert (CPU_Id = Current_CPU); if Thread.Next /= Null_Thread_Id and then Thread.Next.Active_Priority = Prio then First_Thread_Table (CPU_Id) := Thread.Next; -- Look for the Aux_Pointer to insert the thread just after it Aux_Pointer := First_Thread_Table (CPU_Id); while Aux_Pointer.Next /= Null_Thread_Id and then Prio = Aux_Pointer.Next.Active_Priority loop Aux_Pointer := Aux_Pointer.Next; end loop; -- Insert the thread after the Aux_Pointer Thread.Next := Aux_Pointer.Next; Aux_Pointer.Next := Thread; end if; end Yield; ------------------ -- Queue_Length -- ------------------ function Queue_Length return Natural is Res : Natural := 0; T : Thread_Id := First_Thread_Table (Current_CPU); begin while T /= null loop Res := Res + 1; T := T.Next; end loop; return Res; end Queue_Length; ------------------- -- Queue_Ordered -- ------------------- function Queue_Ordered return Boolean is T : Thread_Id := First_Thread_Table (Current_CPU); N : Thread_Id; begin if T = Null_Thread_Id then -- True if the queue is empty return True; end if; loop N := T.Next; if N = Null_Thread_Id then -- True if at end of the queue return True; end if; if T.Active_Priority < N.Active_Priority then return False; end if; T := N; end loop; end Queue_Ordered; end System.BB.Threads.Queues;
package Mat is function Lnko ( A, B : Positive ) return Positive; function Faktorialis( N: Natural ) return Positive; end Mat;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2021, 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. -- -- -- ------------------------------------------------------------------------------ -- This file provides NOP-compatible hint functions for devices using the -- ARMv6-M, ARMv7-M, and ARMv8-M instruction sets. -- -- Source: -- -- ARMv6-M Architecture Reference Manual -- A6.6 Hint Instructions -- https://developer.arm.com/documentation/ddi0419/e package Cortex_M.Hints is procedure Send_Event with Inline; -- A6.7.57 SEV -- -- Causes an event to be signaled to all CPUs within a multiprocessor -- system. procedure Wait_For_Event with Inline; -- A6.7.75 WFE -- -- Permits the processor to enter a low-power state until one of a number -- of events occurs, including events signaled by the SEV instruction on -- any processor in a multiprocessor system. procedure Wait_For_Interrupt with Inline; -- A6.7.76 WFI -- -- Suspends execution until one of a number of events occurs. procedure Yield with Inline; -- A6.7.77 YIELD -- -- Enables software with a multithreading capability to indicate to the -- hardware that it is performing a task, for example a spinlock, that -- could be swapped out to improve overall system performance. Hardware -- can use this hint to suspend and resume multiple code threads if it -- supports the capability. end Cortex_M.Hints;