repo_name
stringlengths
9
74
language
stringclasses
1 value
length_bytes
int64
11
9.34M
extension
stringclasses
2 values
content
stringlengths
11
9.34M
AdaCore/Ada_Drivers_Library
Ada
10,874
ads
-- This spec has been automatically generated from STM32F40x.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package STM32_SVD.SPI is pragma Preelaborate; --------------- -- Registers -- --------------- subtype CR1_BR_Field is HAL.UInt3; -- control register 1 type CR1_Register is record -- Clock phase CPHA : Boolean := False; -- Clock polarity CPOL : Boolean := False; -- Master selection MSTR : Boolean := False; -- Baud rate control BR : CR1_BR_Field := 16#0#; -- SPI enable SPE : Boolean := False; -- Frame format LSBFIRST : Boolean := False; -- Internal slave select SSI : Boolean := False; -- Software slave management SSM : Boolean := False; -- Receive only RXONLY : Boolean := False; -- Data frame format DFF : Boolean := False; -- CRC transfer next CRCNEXT : Boolean := False; -- Hardware CRC calculation enable CRCEN : Boolean := False; -- Output enable in bidirectional mode BIDIOE : Boolean := False; -- Bidirectional data mode enable BIDIMODE : Boolean := False; -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR1_Register use record CPHA at 0 range 0 .. 0; CPOL at 0 range 1 .. 1; MSTR at 0 range 2 .. 2; BR at 0 range 3 .. 5; SPE at 0 range 6 .. 6; LSBFIRST at 0 range 7 .. 7; SSI at 0 range 8 .. 8; SSM at 0 range 9 .. 9; RXONLY at 0 range 10 .. 10; DFF at 0 range 11 .. 11; CRCNEXT at 0 range 12 .. 12; CRCEN at 0 range 13 .. 13; BIDIOE at 0 range 14 .. 14; BIDIMODE at 0 range 15 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- control register 2 type CR2_Register is record -- Rx buffer DMA enable RXDMAEN : Boolean := False; -- Tx buffer DMA enable TXDMAEN : Boolean := False; -- SS output enable SSOE : Boolean := False; -- unspecified Reserved_3_3 : HAL.Bit := 16#0#; -- Frame format FRF : Boolean := False; -- Error interrupt enable ERRIE : Boolean := False; -- RX buffer not empty interrupt enable RXNEIE : Boolean := False; -- Tx buffer empty interrupt enable TXEIE : Boolean := False; -- unspecified Reserved_8_31 : HAL.UInt24 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR2_Register use record RXDMAEN at 0 range 0 .. 0; TXDMAEN at 0 range 1 .. 1; SSOE at 0 range 2 .. 2; Reserved_3_3 at 0 range 3 .. 3; FRF at 0 range 4 .. 4; ERRIE at 0 range 5 .. 5; RXNEIE at 0 range 6 .. 6; TXEIE at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- status register type SR_Register is record -- Read-only. Receive buffer not empty RXNE : Boolean := False; -- Read-only. Transmit buffer empty TXE : Boolean := True; -- Read-only. Channel side CHSIDE : Boolean := False; -- Read-only. Underrun flag UDR : Boolean := False; -- CRC error flag CRCERR : Boolean := False; -- Read-only. Mode fault MODF : Boolean := False; -- Read-only. Overrun flag OVR : Boolean := False; -- Read-only. Busy flag BSY : Boolean := False; -- Read-only. TI frame format error TIFRFE : Boolean := False; -- unspecified Reserved_9_31 : HAL.UInt23 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SR_Register use record RXNE at 0 range 0 .. 0; TXE at 0 range 1 .. 1; CHSIDE at 0 range 2 .. 2; UDR at 0 range 3 .. 3; CRCERR at 0 range 4 .. 4; MODF at 0 range 5 .. 5; OVR at 0 range 6 .. 6; BSY at 0 range 7 .. 7; TIFRFE at 0 range 8 .. 8; Reserved_9_31 at 0 range 9 .. 31; end record; subtype DR_DR_Field is HAL.UInt16; -- data register type DR_Register is record -- Data register DR : DR_DR_Field := 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 DR_Register use record DR at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype CRCPR_CRCPOLY_Field is HAL.UInt16; -- CRC polynomial register type CRCPR_Register is record -- CRC polynomial register CRCPOLY : CRCPR_CRCPOLY_Field := 16#7#; -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CRCPR_Register use record CRCPOLY at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype RXCRCR_RxCRC_Field is HAL.UInt16; -- RX CRC register type RXCRCR_Register is record -- Read-only. Rx CRC register RxCRC : RXCRCR_RxCRC_Field; -- unspecified Reserved_16_31 : HAL.UInt16; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for RXCRCR_Register use record RxCRC at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype TXCRCR_TxCRC_Field is HAL.UInt16; -- TX CRC register type TXCRCR_Register is record -- Read-only. Tx CRC register TxCRC : TXCRCR_TxCRC_Field; -- unspecified Reserved_16_31 : HAL.UInt16; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for TXCRCR_Register use record TxCRC at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype I2SCFGR_DATLEN_Field is HAL.UInt2; subtype I2SCFGR_I2SSTD_Field is HAL.UInt2; subtype I2SCFGR_I2SCFG_Field is HAL.UInt2; -- I2S configuration register type I2SCFGR_Register is record -- Channel length (number of bits per audio channel) CHLEN : Boolean := False; -- Data length to be transferred DATLEN : I2SCFGR_DATLEN_Field := 16#0#; -- Steady state clock polarity CKPOL : Boolean := False; -- I2S standard selection I2SSTD : I2SCFGR_I2SSTD_Field := 16#0#; -- unspecified Reserved_6_6 : HAL.Bit := 16#0#; -- PCM frame synchronization PCMSYNC : Boolean := False; -- I2S configuration mode I2SCFG : I2SCFGR_I2SCFG_Field := 16#0#; -- I2S Enable I2SE : Boolean := False; -- I2S mode selection I2SMOD : Boolean := False; -- unspecified Reserved_12_31 : HAL.UInt20 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for I2SCFGR_Register use record CHLEN at 0 range 0 .. 0; DATLEN at 0 range 1 .. 2; CKPOL at 0 range 3 .. 3; I2SSTD at 0 range 4 .. 5; Reserved_6_6 at 0 range 6 .. 6; PCMSYNC at 0 range 7 .. 7; I2SCFG at 0 range 8 .. 9; I2SE at 0 range 10 .. 10; I2SMOD at 0 range 11 .. 11; Reserved_12_31 at 0 range 12 .. 31; end record; subtype I2SPR_I2SDIV_Field is HAL.UInt8; -- I2S prescaler register type I2SPR_Register is record -- I2S Linear prescaler I2SDIV : I2SPR_I2SDIV_Field := 16#A#; -- Odd factor for the prescaler ODD : Boolean := False; -- Master clock output enable MCKOE : Boolean := False; -- unspecified Reserved_10_31 : HAL.UInt22 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for I2SPR_Register use record I2SDIV at 0 range 0 .. 7; ODD at 0 range 8 .. 8; MCKOE at 0 range 9 .. 9; Reserved_10_31 at 0 range 10 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Serial peripheral interface type SPI_Peripheral is record -- control register 1 CR1 : aliased CR1_Register; -- control register 2 CR2 : aliased CR2_Register; -- status register SR : aliased SR_Register; -- data register DR : aliased DR_Register; -- CRC polynomial register CRCPR : aliased CRCPR_Register; -- RX CRC register RXCRCR : aliased RXCRCR_Register; -- TX CRC register TXCRCR : aliased TXCRCR_Register; -- I2S configuration register I2SCFGR : aliased I2SCFGR_Register; -- I2S prescaler register I2SPR : aliased I2SPR_Register; end record with Volatile; for SPI_Peripheral use record CR1 at 16#0# range 0 .. 31; CR2 at 16#4# range 0 .. 31; SR at 16#8# range 0 .. 31; DR at 16#C# range 0 .. 31; CRCPR at 16#10# range 0 .. 31; RXCRCR at 16#14# range 0 .. 31; TXCRCR at 16#18# range 0 .. 31; I2SCFGR at 16#1C# range 0 .. 31; I2SPR at 16#20# range 0 .. 31; end record; -- Serial peripheral interface I2S2ext_Periph : aliased SPI_Peripheral with Import, Address => System'To_Address (16#40003400#); -- Serial peripheral interface I2S3ext_Periph : aliased SPI_Peripheral with Import, Address => System'To_Address (16#40004000#); -- Serial peripheral interface SPI1_Periph : aliased SPI_Peripheral with Import, Address => System'To_Address (16#40013000#); -- Serial peripheral interface SPI2_Periph : aliased SPI_Peripheral with Import, Address => System'To_Address (16#40003800#); -- Serial peripheral interface SPI3_Periph : aliased SPI_Peripheral with Import, Address => System'To_Address (16#40003C00#); end STM32_SVD.SPI;
reznikmm/matreshka
Ada
3,949
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2013, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.ODF_Attributes.Style.Text_Underline_Color; package ODF.DOM.Attributes.Style.Text_Underline_Color.Internals is function Create (Node : Matreshka.ODF_Attributes.Style.Text_Underline_Color.Style_Text_Underline_Color_Access) return ODF.DOM.Attributes.Style.Text_Underline_Color.ODF_Style_Text_Underline_Color; function Wrap (Node : Matreshka.ODF_Attributes.Style.Text_Underline_Color.Style_Text_Underline_Color_Access) return ODF.DOM.Attributes.Style.Text_Underline_Color.ODF_Style_Text_Underline_Color; end ODF.DOM.Attributes.Style.Text_Underline_Color.Internals;
reznikmm/matreshka
Ada
3,659
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Elements; package ODF.DOM.Draw_Caption_Elements is pragma Preelaborate; type ODF_Draw_Caption is limited interface and XML.DOM.Elements.DOM_Element; type ODF_Draw_Caption_Access is access all ODF_Draw_Caption'Class with Storage_Size => 0; end ODF.DOM.Draw_Caption_Elements;
zhmu/ananas
Ada
4,542
adb
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- A D A . C O M M A N D _ L I N E -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2022, 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. -- -- -- ------------------------------------------------------------------------------ with System; use System; package body Ada.Command_Line is function Arg_Count return Natural; pragma Import (C, Arg_Count, "__gnat_arg_count"); procedure Fill_Arg (A : System.Address; Arg_Num : Integer); pragma Import (C, Fill_Arg, "__gnat_fill_arg"); function Len_Arg (Arg_Num : Integer) return Integer; pragma Import (C, Len_Arg, "__gnat_len_arg"); ----------------------- -- Local Subprograms -- ----------------------- function Initialized return Boolean; -- Checks to ensure that gnat_argc and gnat_argv have been properly -- initialized. Returns false if not, or if argv / argc are -- unsupported on the target (e.g. VxWorks). -------------- -- Argument -- -------------- function Argument (Number : Positive) return String is begin if Number > Argument_Count then raise Constraint_Error; end if; declare Num : constant Positive := (if Remove_Args = null then Number else Remove_Args (Number)); Arg : aliased String (1 .. Len_Arg (Num)); begin Fill_Arg (Arg'Address, Num); return Arg; end; end Argument; -------------------- -- Argument_Count -- -------------------- function Argument_Count return Natural is begin if not Initialized then -- RM A.15 (11) return 0; end if; if Remove_Args = null then return Arg_Count - 1; else return Remove_Count; end if; end Argument_Count; ----------------- -- Initialized -- ----------------- function Initialized return Boolean is gnat_argv : System.Address; pragma Import (C, gnat_argv, "gnat_argv"); begin return gnat_argv /= System.Null_Address; end Initialized; ------------------ -- Command_Name -- ------------------ function Command_Name return String is begin if not Initialized then return ""; end if; declare Arg : aliased String (1 .. Len_Arg (0)); begin Fill_Arg (Arg'Address, 0); return Arg; end; end Command_Name; end Ada.Command_Line;
reznikmm/matreshka
Ada
3,774
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Attributes; package ODF.DOM.Fo_Hyphenation_Ladder_Count_Attributes is pragma Preelaborate; type ODF_Fo_Hyphenation_Ladder_Count_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Fo_Hyphenation_Ladder_Count_Attribute_Access is access all ODF_Fo_Hyphenation_Ladder_Count_Attribute'Class with Storage_Size => 0; end ODF.DOM.Fo_Hyphenation_Ladder_Count_Attributes;
zertovitch/excel-writer
Ada
718
ads
-- Freeware, author: J-P. Rosen, http://www.adalog.fr/ package CSV is type Bounds is record Start : Positive; Stop : Natural; end record; type Fields_Bounds is array (Positive range <>) of Bounds; function Get_Bounds (Item : String; Separator : Character := ',') return Fields_Bounds; function Extract (Item : String; Fields : Fields_Bounds; Column : Positive; Do_Unquote : Boolean := True) return String; function Quote (Item : String) return String; function Unquote (Item : String) return String; function Unquote (Item : String; Slice : Bounds; Size : Natural := 0) return String; end CSV;
LiberatorUSA/GUCEF
Ada
4,444
ads
---------------------------------------------------------------- -- ZLib for Ada thick binding. -- -- -- -- Copyright (C) 2002-2003 Dmitriy Anisimkov -- -- -- -- Open source license information is in the zlib.ads file. -- ---------------------------------------------------------------- -- $Id: zlib-streams.ads,v 1.12 2004/05/31 10:53:40 vagul Exp $ package ZLib.Streams is type Stream_Mode is (In_Stream, Out_Stream, Duplex); type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class; type Stream_Type is new Ada.Streams.Root_Stream_Type with private; procedure Read (Stream : in out Stream_Type; Item : out Ada.Streams.Stream_Element_Array; Last : out Ada.Streams.Stream_Element_Offset); procedure Write (Stream : in out Stream_Type; Item : in Ada.Streams.Stream_Element_Array); procedure Flush (Stream : in out Stream_Type; Mode : in Flush_Mode := Sync_Flush); -- Flush the written data to the back stream, -- all data placed to the compressor is flushing to the Back stream. -- Should not be used untill necessary, becouse it is decreasing -- compression. function Read_Total_In (Stream : in Stream_Type) return Count; pragma Inline (Read_Total_In); -- Return total number of bytes read from back stream so far. function Read_Total_Out (Stream : in Stream_Type) return Count; pragma Inline (Read_Total_Out); -- Return total number of bytes read so far. function Write_Total_In (Stream : in Stream_Type) return Count; pragma Inline (Write_Total_In); -- Return total number of bytes written so far. function Write_Total_Out (Stream : in Stream_Type) return Count; pragma Inline (Write_Total_Out); -- Return total number of bytes written to the back stream. procedure Create (Stream : out Stream_Type; Mode : in Stream_Mode; Back : in Stream_Access; Back_Compressed : in Boolean; Level : in Compression_Level := Default_Compression; Strategy : in Strategy_Type := Default_Strategy; Header : in Header_Type := Default; Read_Buffer_Size : in Ada.Streams.Stream_Element_Offset := Default_Buffer_Size; Write_Buffer_Size : in Ada.Streams.Stream_Element_Offset := Default_Buffer_Size); -- Create the Comression/Decompression stream. -- If mode is In_Stream then Write operation is disabled. -- If mode is Out_Stream then Read operation is disabled. -- If Back_Compressed is true then -- Data written to the Stream is compressing to the Back stream -- and data read from the Stream is decompressed data from the Back stream. -- If Back_Compressed is false then -- Data written to the Stream is decompressing to the Back stream -- and data read from the Stream is compressed data from the Back stream. -- !!! When the Need_Header is False ZLib-Ada is using undocumented -- ZLib 1.1.4 functionality to do not create/wait for ZLib headers. function Is_Open (Stream : Stream_Type) return Boolean; procedure Close (Stream : in out Stream_Type); private use Ada.Streams; type Buffer_Access is access all Stream_Element_Array; type Stream_Type is new Root_Stream_Type with record Mode : Stream_Mode; Buffer : Buffer_Access; Rest_First : Stream_Element_Offset; Rest_Last : Stream_Element_Offset; -- Buffer for Read operation. -- We need to have this buffer in the record -- becouse not all read data from back stream -- could be processed during the read operation. Buffer_Size : Stream_Element_Offset; -- Buffer size for write operation. -- We do not need to have this buffer -- in the record becouse all data could be -- processed in the write operation. Back : Stream_Access; Reader : Filter_Type; Writer : Filter_Type; end record; end ZLib.Streams;
AdaCore/training_material
Ada
1,436
adb
with Ada.Containers; use Ada.Containers; with Loop_Types; use Loop_Types; use Loop_Types.Lists.Formal_Model; package body Loop_Init is procedure Init_Table (T : out Table) is begin for J in T'Range loop T(J) := 0; pragma Loop_Invariant (for all K in T'First .. J => T(K)'Initialized); pragma Loop_Invariant (for all K in T'First .. J => T(K) = 0); end loop; end Init_Table; procedure Bump_Table (T : in out Table) is begin for J in T'Range loop T(J + 0) := T (J) + 1; pragma Loop_Invariant (for all K in T'First .. J => T(K) = T'Loop_Entry(K) + 1); pragma Loop_Invariant (for all K in J .. T'Last => (if K > J then T(K) = T'Loop_Entry(K))); end loop; end Bump_Table; procedure Init_Vector (V : in out Vector) is begin for J in V.First_Index .. V.Last_Index loop V.Replace_Element (J, 0); pragma Loop_Invariant (V.Last_Index = V.Last_Index'Loop_Entry); pragma Loop_Invariant (for all K in V.First_Index .. J => V.Element (K) = 0); end loop; end Init_Vector; procedure Init_List (L : in out List) is begin for Cu in L loop L.Replace_Element (Cu, 0); pragma Loop_Invariant (for all I in 1 .. Positions (L).Get (Cu) => Model (L).Get (I) = 0); end loop; end Init_List; end Loop_Init;
landgraf/nanomsg-ada
Ada
3,044
adb
-- The MIT License (MIT) -- Copyright (c) 2015 Pavel Zhukov <[email protected]> -- 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 Nanomsg.Domains; with Aunit.Assertions; with Nanomsg.Messages; with Nanomsg.Pipeline; package body Nanomsg.Test_Message_Long_Text is procedure Run_Test (T : in out TC) is use Aunit.Assertions; Address : constant String := "tcp://127.0.0.1:5555"; Text : constant String (1 .. 2 ** 16 ) := ( others => 'K'); Msg1 : Nanomsg.Messages.Message_T; Msg2 : Nanomsg.Messages.Message_T := Nanomsg.Messages.Empty_Message; begin Nanomsg.Messages.From_String (Msg1, Text); Nanomsg.Socket.Init (T.Socket1, Nanomsg.Domains.Af_Sp, Nanomsg.Pipeline.Nn_Push); Nanomsg.Socket.Init (T.Socket2, Nanomsg.Domains.Af_Sp, Nanomsg.Pipeline.Nn_Pull); Assert (Condition => not T.Socket1.Is_Null, Message => "Failed to initialize socket1"); Assert (Condition => not T.Socket2.Is_Null, Message => "Failed to initialize socket2"); Assert (Condition => T.Socket1.Get_Fd /= T.Socket2.Get_Fd, Message => "Descriptors collision!"); Nanomsg.Socket.Connect (T.Socket1, Address); Nanomsg.Socket.Bind (T.Socket2, "tcp://*:5555"); T.Socket1.Send (Msg1); T.Socket2.Receive (Msg2); Assert (Condition => Msg1.Text = Msg2.Text, Message => "Message transfer failed. Texts are not identical" & Ascii.Lf & "Sent: " & Msg1.Text & "; Received: " & Msg2.Text); end Run_Test; function Name (T : TC) return Message_String is begin return Aunit.Format ("Test case name : Long message send/receive"); end Name; procedure Tear_Down (T : in out Tc) is begin if T.Socket1.Get_Fd >= 0 then T.Socket1.Close; end if; if T.Socket2.Get_Fd >= 0 then T.Socket2.Close; end if; end Tear_Down; end Nanomsg.Test_Message_Long_Text;
sungyeon/drake
Ada
1,255
ads
pragma License (Unrestricted); -- implementation unit specialized for FreeBSD (or Linux) with System.Storage_Elements; package System.Unbounded_Allocators is -- Separated storage pool for local scope. pragma Preelaborate; type Unbounded_Allocator is limited private; procedure Initialize (Object : in out Unbounded_Allocator); procedure Finalize (Object : in out Unbounded_Allocator); procedure Allocate ( Allocator : Unbounded_Allocator; Storage_Address : out Address; Size_In_Storage_Elements : Storage_Elements.Storage_Count; Alignment : Storage_Elements.Storage_Count); procedure Deallocate ( Allocator : Unbounded_Allocator; Storage_Address : Address; Size_In_Storage_Elements : Storage_Elements.Storage_Count; Alignment : Storage_Elements.Storage_Count); function Allocator_Of (Storage_Address : Address) return Unbounded_Allocator; private type Header; type Header_Access is access all Header; type Header is record Previous : Header_Access; -- low 1 bit is set if sentinel Next : Header_Access; end record; pragma Suppress_Initialization (Header); type Unbounded_Allocator is new Header_Access; end System.Unbounded_Allocators;
cborao/Ada-P3
Ada
2,570
adb
--PRÁCTICA 3: CÉSAR BORAO MORATINOS (Maps_G_Array.adb) with Ada.Text_IO; with Ada.Strings.Unbounded; package body Maps_G is package ASU renames Ada.Strings.Unbounded; procedure Put (M: in out Map; Key: Key_Type; Value: Value_Type) is Position: Natural := 1; Found: Boolean; begin Found := False; if M.P_Array = null then M.P_Array := new Cell_Array; M.P_Array(1) := (Key,Value,True); M.Length := 1; Found := True; else while not Found and Position <= M.Length loop if M.P_Array(Position).Key = Key then M.P_Array(Position).Value := Value; Found := True; end if; Position := Position+1; end loop; if not Found then if M.Length >= Max_Clients then raise Full_Map; end if; M.P_Array(Position) := (Key,Value,True); M.Length := M.Length + 1; end if; end if; end Put; procedure Get (M: Map; Key: in Key_Type; Value: out Value_Type; Success: out Boolean) is Position: Natural := 1; begin if M.P_Array = null then Success := False; else Success := False; while not Success and Position <= M.Length loop if M.P_Array(Position).Key = Key then Value := M.P_Array(Position).Value; Success := True; end if; Position := Position + 1; end loop; end if; end Get; procedure Delete (M: in out Map; Key: in Key_Type; Success: out Boolean) is Position: Natural := 1; begin Success := False; while not Success and Position <= M.Length loop if M.P_Array(Position).Key = Key then Success := True; for I in Position..M.Length-1 loop M.P_Array(I) := M.P_Array(I+1); end loop; end if; Position := Position + 1; end loop; M.Length := M.Length - 1; end Delete; function Map_Length (M: Map) return Natural is begin return M.Length; end Map_Length; function First (M: Map) return Cursor is C: Cursor; begin C.M := M; C.Position := 1; return C; end First; procedure Next (C: in out Cursor) is begin C.Position := C.Position + 1; end; function Has_Element (C: Cursor) return Boolean is begin if C.Position > C.M.Length then return False; else return C.M.P_Array(C.Position).Full; end if; end Has_Element; function Element (C: Cursor) return Element_Type is Element: Element_Type; begin if Has_Element (C) then Element.Key := C.M.P_Array(C.Position).Key; Element.Value := C.M.P_Array(C.Position).Value; else raise No_Element; end if; return Element; end Element; end Maps_G;
diffblue/cbmc
Ada
97
adb
with User; with Library; procedure Entry_Point is begin User; Library (-5); end Entry_Point;
reznikmm/matreshka
Ada
3,651
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ with AMF.Elements.Generic_Hash; function AMF.UMLDI.UML_Interaction_Diagrams.Hash is new AMF.Elements.Generic_Hash (UMLDI_UML_Interaction_Diagram, UMLDI_UML_Interaction_Diagram_Access);
AdaCore/training_material
Ada
11,566
ads
pragma Ada_2005; pragma Style_Checks (Off); with Interfaces.C; use Interfaces.C; with Interfaces.C.Strings; with Interfaces.C.Extensions; with System; package basetsd_h is -- unsupported macro: SPOINTER_32 POINTER_SIGNED POINTER_32 -- unsupported macro: UPOINTER_32 POINTER_UNSIGNED POINTER_32 ADDRESS_TAG_BIT : constant := 16#80000000#; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:97 -- arg-macro: function HandleToULong (h) -- return (ULONG)(ULONG_PTR)(h); -- arg-macro: function HandleToLong (h) -- return (LONG)(LONG_PTR) (h); -- arg-macro: function ULongToHandle (ul) -- return (HANDLE)(ULONG_PTR) (ul); -- arg-macro: function LongToHandle (h) -- return (HANDLE)(LONG_PTR) (h); -- arg-macro: function PtrToUlong (p) -- return (ULONG)(ULONG_PTR) (p); -- arg-macro: function PtrToLong (p) -- return (LONG)(LONG_PTR) (p); -- arg-macro: function PtrToUint (p) -- return (UINT)(UINT_PTR) (p); -- arg-macro: function PtrToInt (p) -- return (INT)(INT_PTR) (p); -- arg-macro: function PtrToUshort (p) -- return (unsigned short)(ULONG_PTR)(p); -- arg-macro: function PtrToShort (p) -- return (short)(LONG_PTR)(p); -- arg-macro: function IntToPtr (i) -- return (VOID *)(INT_PTR)((int)i); -- arg-macro: function UIntToPtr (ui) -- return (VOID *)(UINT_PTR)((unsigned int)ui); -- arg-macro: function LongToPtr (l) -- return (VOID *)(LONG_PTR)((long)l); -- arg-macro: function ULongToPtr (ul) -- return (VOID *)(ULONG_PTR)((unsigned long)ul); -- arg-macro: function Ptr32ToPtr (p) -- return (void *) (ULONG_PTR) p; -- arg-macro: function Handle32ToHandle (h) -- return Ptr32ToPtr(h); -- arg-macro: function PtrToPtr32 (p) -- return (void *) (ULONG_PTR) p; -- arg-macro: function HandleToHandle32 (h) -- return PtrToPtr32(h); -- arg-macro: procedure HandleToUlong (h) -- HandleToULong(h) -- arg-macro: procedure UlongToHandle (ul) -- ULongToHandle(ul) -- arg-macro: procedure UlongToPtr (ul) -- ULongToPtr(ul) -- arg-macro: procedure UintToPtr (ui) -- UIntToPtr(ui) -- unsupported macro: MAXUINT_PTR (~((UINT_PTR)0)) -- unsupported macro: MAXINT_PTR ((INT_PTR)(MAXUINT_PTR >> 1)) -- unsupported macro: MININT_PTR (~MAXINT_PTR) -- unsupported macro: MAXULONG_PTR (~((ULONG_PTR)0)) -- unsupported macro: MAXLONG_PTR ((LONG_PTR)(MAXULONG_PTR >> 1)) -- unsupported macro: MINLONG_PTR (~MAXLONG_PTR) -- unsupported macro: MAXUHALF_PTR ((UHALF_PTR)~0) -- unsupported macro: MAXHALF_PTR ((HALF_PTR)(MAXUHALF_PTR >> 1)) -- unsupported macro: MINHALF_PTR (~MAXHALF_PTR) subtype POINTER_64_INT is unsigned_long; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:14 subtype INT8 is char; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:30 type PINT8 is new Interfaces.C.Strings.chars_ptr; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:30 subtype INT16 is short; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:31 type PINT16 is access all short; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:31 subtype INT32 is int; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:32 type PINT32 is access all int; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:32 subtype INT64 is Long_Long_Integer; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:33 type PINT64 is access all Long_Long_Integer; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:33 subtype UINT8 is unsigned_char; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:34 type PUINT8 is access all unsigned_char; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:34 subtype UINT16 is unsigned_short; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:35 type PUINT16 is access all unsigned_short; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:35 subtype UINT32 is unsigned; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:36 type PUINT32 is access all unsigned; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:36 subtype UINT64 is Extensions.unsigned_long_long; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:37 type PUINT64 is access all Extensions.unsigned_long_long; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:37 subtype LONG32 is int; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:38 type PLONG32 is access all int; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:38 subtype ULONG32 is unsigned; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:39 type PULONG32 is access all unsigned; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:39 subtype DWORD32 is unsigned; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:40 type PDWORD32 is access all unsigned; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:40 subtype INT_PTR is int; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:53 type PINT_PTR is access all int; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:53 subtype UINT_PTR is unsigned; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:54 type PUINT_PTR is access all unsigned; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:54 subtype LONG_PTR is long; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:55 type PLONG_PTR is access all long; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:55 subtype ULONG_PTR is unsigned_long; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:56 type PULONG_PTR is access all unsigned_long; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:56 subtype UHALF_PTR is unsigned_short; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:99 type PUHALF_PTR is access all unsigned_short; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:99 subtype HALF_PTR is short; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:100 type PHALF_PTR is access all short; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:100 subtype SHANDLE_PTR is long; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:101 subtype HANDLE_PTR is unsigned_long; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:102 function PtrToPtr64 (p : System.Address) return System.Address; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:120 pragma Import (C, PtrToPtr64, "PtrToPtr64"); function Ptr64ToPtr (p : System.Address) return System.Address; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:121 pragma Import (C, Ptr64ToPtr, "Ptr64ToPtr"); function HandleToHandle64 (h : System.Address) return System.Address; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:122 pragma Import (C, HandleToHandle64, "HandleToHandle64"); function Handle64ToHandle (h : System.Address) return System.Address; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:123 pragma Import (C, Handle64ToHandle, "Handle64ToHandle"); subtype SIZE_T is ULONG_PTR; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:149 type PSIZE_T is access all ULONG_PTR; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:149 subtype SSIZE_T is LONG_PTR; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:150 type PSSIZE_T is access all LONG_PTR; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:150 subtype DWORD_PTR is ULONG_PTR; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:151 type PDWORD_PTR is access all ULONG_PTR; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:151 subtype LONG64 is Long_Long_Integer; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:152 type PLONG64 is access all Long_Long_Integer; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:152 subtype ULONG64 is Extensions.unsigned_long_long; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:153 type PULONG64 is access all Extensions.unsigned_long_long; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:153 subtype DWORD64 is Extensions.unsigned_long_long; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:154 type PDWORD64 is access all Extensions.unsigned_long_long; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:154 subtype KAFFINITY is ULONG_PTR; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:155 type PKAFFINITY is access all KAFFINITY; -- c:\home\ochem\install\bin\../lib/gcc/i686-pc-mingw32/4.7.3/../../../../i686-pc-mingw32/include/basetsd.h:156 end basetsd_h;
reznikmm/matreshka
Ada
3,719
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Elements; package ODF.DOM.Number_Scientific_Number_Elements is pragma Preelaborate; type ODF_Number_Scientific_Number is limited interface and XML.DOM.Elements.DOM_Element; type ODF_Number_Scientific_Number_Access is access all ODF_Number_Scientific_Number'Class with Storage_Size => 0; end ODF.DOM.Number_Scientific_Number_Elements;
AdaCore/libadalang
Ada
997
adb
procedure Gen_Cmp is generic type Element_Type is private; type Index_Type is (<>); type Array_Type is array (Index_Type range <>) of Element_Type; with function ">" (Left, Right : Element_Type) return Boolean is <>; procedure Gen (Data : in out Array_Type); procedure Gen (Data : in out Array_Type) is begin null; end; type Alpha is (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z); type My_Array is array (Alpha range <>) of Integer; function Less_Than (L, R : Integer) return Boolean is begin return L < R; end; procedure Flag1 is new Gen (Element_Type => Integer, Index_Type => Alpha, Array_Type => My_Array, ">" => Less_Than); --% node.p_inst_params procedure Flag2 is new Gen (Integer, Alpha, My_Array, Less_Than); --% node.p_inst_params begin null; end;
reznikmm/matreshka
Ada
4,009
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with ODF.DOM.Draw_Stroke_Dash_Attributes; package Matreshka.ODF_Draw.Stroke_Dash_Attributes is type Draw_Stroke_Dash_Attribute_Node is new Matreshka.ODF_Draw.Abstract_Draw_Attribute_Node and ODF.DOM.Draw_Stroke_Dash_Attributes.ODF_Draw_Stroke_Dash_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Draw_Stroke_Dash_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Draw_Stroke_Dash_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Draw.Stroke_Dash_Attributes;
Tim-Tom/project-euler
Ada
579
ads
package Problem_72 is -- Consider the fraction, n/d, where n and d are positive integers. If n<d and HCF(n,d)=1, it is -- called a reduced proper fraction. -- If we list the set of reduced proper fractions for d ≤ 8 in ascending order of size, we get: -- 1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, -- 6/7, 7/8 -- It can be seen that there are 21 elements in this set. -- How many elements would be contained in the set of reduced proper fractions for d ≤ 1,000,000? procedure Solve; end Problem_72;
charlie5/aIDE
Ada
2,108
adb
with AdaM.Factory; package body AdaM.a_Type.modular_type is -- Storage Pool -- record_Version : constant := 1; pool_Size : constant := 5_000; package Pool is new AdaM.Factory.Pools (storage_Folder => ".adam-store", pool_Name => "modular_types", max_Items => pool_Size, record_Version => record_Version, Item => modular_type.item, View => modular_type.view); -- Forge -- procedure define (Self : in out Item; Name : in String) is begin Self.Name := +Name; end define; overriding procedure destruct (Self : in out Item) is begin null; end destruct; function new_Type (Name : in String := "") return modular_type.View is new_View : constant modular_type.view := Pool.new_Item; begin define (modular_type.item (new_View.all), Name); return new_View; end new_Type; procedure free (Self : in out modular_type.view) is begin destruct (a_Type.item (Self.all)); Pool.free (Self); end free; -- Attributes -- overriding function Id (Self : access Item) return AdaM.Id is begin return Pool.to_Id (Self); end Id; overriding function to_Source (Self : in Item) return text_Vectors.Vector is pragma Unreferenced (Self); the_Source : text_Vectors.Vector; begin raise Program_Error with "TODO"; return the_Source; end to_Source; -- Streams -- procedure View_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class; Self : in View) renames Pool.View_write; procedure View_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class; Self : out View) renames Pool.View_read; end AdaM.a_Type.modular_type;
AdaCore/training_material
Ada
120
ads
package Console is procedure Print (S : String := ""; New_Line : Boolean := True); end Console;
soccasys/Ada_Drivers_Library
Ada
2,022
ads
-- This package was generated by the Ada_Drivers_Library project wizard script package ADL_Config is Vendor : constant String := "Nordic"; -- From board definition Max_Mount_Points : constant := 2; -- From default value Boot_Memory : constant String := "flash"; -- From default value Max_Mount_Name_Length : constant := 128; -- From default value Runtime_Profile : constant String := "zfp"; -- From command line Device_Name : constant String := "nRF52832xxAA"; -- From board definition Device_Family : constant String := "nRF52"; -- From board definition Has_Ravenscar_SFP_Runtime : constant String := "False"; -- From board definition Runtime_Name : constant String := "zfp-cortex-m4f"; -- From default value Has_Ravenscar_Full_Runtime : constant String := "False"; -- From board definition CPU_Core : constant String := "ARM Cortex-M4F"; -- From mcu definition Board : constant String := "NRF52_DK"; -- From command line Has_ZFP_Runtime : constant String := "True"; -- From board definition Number_Of_Interrupts : constant := 128; -- From MCU definition Has_Custom_Memory_Area_1 : constant Boolean := False; -- From default value Use_Startup_Gen : constant Boolean := True; -- From command line Max_Path_Length : constant := 1024; -- From default value Runtime_Name_Suffix : constant String := "cortex-m4f"; -- From board definition Architecture : constant String := "ARM"; -- From board definition end ADL_Config;
sparre/ALSA-binding
Ada
11,082
ads
-- The Beer-Ware License (revision 42) -- -- Jacob Sparre Andersen <[email protected]> wrote this. As long as you -- retain this notice you can do whatever you want with this stuff. If we meet -- some day, and you think this stuff is worth it, you can buy me a beer in -- return. -- -- Jacob Sparre Andersen with Interfaces.C, Interfaces.C.Strings; with Sound.Constants; private package Sound.ALSA is use type Interfaces.C.int; type void_ptr is private; type snd_pcm_t_ptr is private; type snd_pcm_stream_t is (Playback, Capture); for snd_pcm_stream_t use (Playback => Sound.Constants.Playback_Stream, Capture => Sound.Constants.Capture_Stream); Value : constant array (Line_Mode) of snd_pcm_stream_t := (Input => Capture, Output => Playback); type snd_pcm_state_t is (Open, Setup, Prepared, Running, XRun, Draining, Paused, Suspended, Disconnected); for snd_pcm_state_t use (Open => Sound.Constants.State_Open, Setup => Sound.Constants.State_Setup, Prepared => Sound.Constants.State_Prepared, Running => Sound.Constants.State_Running, XRun => Sound.Constants.State_XRun, Draining => Sound.Constants.State_Draining, Paused => Sound.Constants.State_Paused, Suspended => Sound.Constants.State_Suspended, Disconnected => Sound.Constants.State_Disconnected); type snd_pcm_format_t is (Unknown, Signed_8_Bit, Unsigned_8_Bit, Signed_16_Bit_Little_Endian, Signed_16_Bit_Big_Endian, Unsigned_16_Bit_Little_Endian, Unsigned_16_Bit_Big_Endian, Signed_24_Bit_Little_Endian, Signed_24_Bit_Big_Endian, Unsigned_24_Bit_Little_Endian, Unsigned_24_Bit_Big_Endian, Signed_32_Bit_Little_Endian, Signed_32_Bit_Big_Endian, Unsigned_32_Bit_Little_Endian, Unsigned_32_Bit_Big_Endian, FLOAT_Little_Endian, FLOAT_Big_Endian, FLOAT64_Little_Endian, FLOAT64_Big_Endian, IEC958_SUBFRAME_Little_Endian, IEC958_SUBFRAME_Big_Endian, MU_LAW, A_LAW, IMA_ADPCM, MPEG, GSM, SPECIAL, S24_3LE, S24_3BE, U24_3LE, U24_3BE, S20_3LE, S20_3BE, U20_3LE, U20_3BE, S18_3LE, S18_3BE, U18_3LE, U18_3BE); for snd_pcm_format_t use (Unknown => Sound.Constants.Format_Unknown, Signed_8_Bit => Sound.Constants.Format_Signed_8_Bit, Unsigned_8_Bit => Sound.Constants.Format_Unsigned_8_Bit, Signed_16_Bit_Little_Endian => Sound.Constants.Format_Signed_16_Bit_Little_Endian, Signed_16_Bit_Big_Endian => Sound.Constants.Format_Signed_16_Bit_Big_Endian, Unsigned_16_Bit_Little_Endian => Sound.Constants.Format_Unsigned_16_Bit_Little_Endian, Unsigned_16_Bit_Big_Endian => Sound.Constants.Format_Unsigned_16_Bit_Big_Endian, Signed_24_Bit_Little_Endian => Sound.Constants.Format_Signed_24_Bit_Little_Endian, Signed_24_Bit_Big_Endian => Sound.Constants.Format_Signed_24_Bit_Big_Endian, Unsigned_24_Bit_Little_Endian => Sound.Constants.Format_Unsigned_24_Bit_Little_Endian, Unsigned_24_Bit_Big_Endian => Sound.Constants.Format_Unsigned_24_Bit_Big_Endian, Signed_32_Bit_Little_Endian => Sound.Constants.Format_Signed_32_Bit_Little_Endian, Signed_32_Bit_Big_Endian => Sound.Constants.Format_Signed_32_Bit_Big_Endian, Unsigned_32_Bit_Little_Endian => Sound.Constants.Format_Unsigned_32_Bit_Little_Endian, Unsigned_32_Bit_Big_Endian => Sound.Constants.Format_Unsigned_32_Bit_Big_Endian, FLOAT_Little_Endian => Sound.Constants.Format_FLOAT_LE, FLOAT_Big_Endian => Sound.Constants.Format_FLOAT_BE, FLOAT64_Little_Endian => Sound.Constants.Format_FLOAT64_LE, FLOAT64_Big_Endian => Sound.Constants.Format_FLOAT64_BE, IEC958_SUBFRAME_Little_Endian => Sound.Constants.Format_IEC958_SUBFRAME_LE, IEC958_SUBFRAME_Big_Endian => Sound.Constants.Format_IEC958_SUBFRAME_BE, MU_LAW => Sound.Constants.Format_MU_LAW, A_LAW => Sound.Constants.Format_A_LAW, IMA_ADPCM => Sound.Constants.Format_IMA_ADPCM, MPEG => Sound.Constants.Format_MPEG, GSM => Sound.Constants.Format_GSM, SPECIAL => Sound.Constants.Format_SPECIAL, S24_3LE => Sound.Constants.Format_S24_3LE, S24_3BE => Sound.Constants.Format_S24_3BE, U24_3LE => Sound.Constants.Format_U24_3LE, U24_3BE => Sound.Constants.Format_U24_3BE, S20_3LE => Sound.Constants.Format_S20_3LE, S20_3BE => Sound.Constants.Format_S20_3BE, U20_3LE => Sound.Constants.Format_U20_3LE, U20_3BE => Sound.Constants.Format_U20_3BE, S18_3LE => Sound.Constants.Format_S18_3LE, S18_3BE => Sound.Constants.Format_S18_3BE, U18_3LE => Sound.Constants.Format_U18_3LE, U18_3BE => Sound.Constants.Format_U18_3BE); for snd_pcm_format_t'Size use Interfaces.C.int'Size; function Signed_16_Bit return snd_pcm_format_t; function Unsigned_16_Bit return snd_pcm_format_t; type snd_pcm_access_t is (Memory_Mapped_Interleaved, Memory_Mapped_Noninterleaved, Memory_Mapped_Complex, Read_Write_Interleaved, Read_Write_Noninterleaved); for snd_pcm_access_t use (Memory_Mapped_Interleaved => Constants.Access_Memory_Mapped_Interleaved, Memory_Mapped_Noninterleaved => Constants.Access_Memory_Mapped_Noninterleaved, Memory_Mapped_Complex => Constants.Access_Memory_Mapped_Complex, Read_Write_Interleaved => Constants.Access_Read_Write_Interleaved, Read_Write_Noninterleaved => Constants.Access_Read_Write_Noninterleaved); for snd_pcm_access_t'Size use Interfaces.C.int'Size; type snd_pcm_hw_params_t is private; type snd_pcm_sframes_t is new Interfaces.C.long; type snd_pcm_uframes_t is new Interfaces.C.unsigned_long; subtype Approximation_Direction is Interfaces.C.int range -1 .. 1; type Boolean is new Standard.Boolean; for Boolean'Size use Interfaces.C.unsigned'Size; function snd_pcm_open (pcmp : access snd_pcm_t_ptr; name : in Interfaces.C.Strings.chars_ptr; stream : in snd_pcm_stream_t; mode : in Interfaces.C.int) return Interfaces.C.int; pragma Import (C, snd_pcm_open); function snd_pcm_close (pcm : in snd_pcm_t_ptr) return Interfaces.C.int; pragma Import (C, snd_pcm_close); function snd_pcm_state (pcm : in snd_pcm_t_ptr) return snd_pcm_state_t; pragma Import (C, snd_pcm_state); function snd_pcm_hw_params_any (pcm : in snd_pcm_t_ptr; params : access snd_pcm_hw_params_t) return Interfaces.C.int; pragma Import (C, snd_pcm_hw_params_any); function snd_pcm_hw_params_set_rate_resample (pcm : in snd_pcm_t_ptr; params : access snd_pcm_hw_params_t; val : in Boolean) return Interfaces.C.int; pragma Import (C, snd_pcm_hw_params_set_rate_resample); function snd_pcm_hw_params_set_access (pcm : in snd_pcm_t_ptr; params : access snd_pcm_hw_params_t; val : in snd_pcm_access_t) return Interfaces.C.int; pragma Import (C, snd_pcm_hw_params_set_access); function snd_pcm_hw_params_set_format (pcm : in snd_pcm_t_ptr; params : access snd_pcm_hw_params_t; format : in snd_pcm_format_t) return Interfaces.C.int; pragma Import (C, snd_pcm_hw_params_set_format); function snd_pcm_hw_params_set_channels (pcm : in snd_pcm_t_ptr; params : access snd_pcm_hw_params_t; val : in Interfaces.C.unsigned) return Interfaces.C.int; pragma Import (C, snd_pcm_hw_params_set_channels); function snd_pcm_hw_params_set_rate_near (pcm : in snd_pcm_t_ptr; params : access snd_pcm_hw_params_t; val : access Interfaces.C.unsigned; dir : access Approximation_Direction) return Interfaces.C.int; pragma Import (C, snd_pcm_hw_params_set_rate_near); function snd_pcm_hw_params_set_buffer_time_near (pcm : in snd_pcm_t_ptr; params : access snd_pcm_hw_params_t; val : access Interfaces.C.unsigned; dir : access Approximation_Direction) return Interfaces.C.int; pragma Import (C, snd_pcm_hw_params_set_buffer_time_near); function snd_pcm_hw_params_set_period_time_near (pcm : in snd_pcm_t_ptr; params : access snd_pcm_hw_params_t; val : access Interfaces.C.unsigned; dir : access Approximation_Direction) return Interfaces.C.int; pragma Import (C, snd_pcm_hw_params_set_period_time_near); function snd_pcm_hw_params (pcm : in snd_pcm_t_ptr; params : access snd_pcm_hw_params_t) return Interfaces.C.int; pragma Import (C, snd_pcm_hw_params); private type void_ptr is new Interfaces.C.Strings.chars_ptr; type snd_pcm_t_ptr is new Interfaces.C.Strings.chars_ptr; type hw_params_Bits is array (1 .. Sound.Constants.hw_params_Size) of Standard.Boolean; pragma Pack (hw_params_Bits); for hw_params_Bits'Size use Sound.Constants.hw_params_Size; type snd_pcm_hw_params_t is record Content : hw_params_Bits := (others => False); end record; pragma Pack (snd_pcm_hw_params_t); for snd_pcm_hw_params_t'Size use Sound.Constants.hw_params_Size; end Sound.ALSA;
reznikmm/matreshka
Ada
6,822
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Office.Script_Elements is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Office_Script_Element_Node is begin return Self : Office_Script_Element_Node do Matreshka.ODF_Office.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Office_Prefix); end return; end Create; ---------------- -- Enter_Node -- ---------------- overriding procedure Enter_Node (Self : not null access Office_Script_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Enter_Office_Script (ODF.DOM.Office_Script_Elements.ODF_Office_Script_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Enter_Node (Visitor, Control); end if; end Enter_Node; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Office_Script_Element_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Script_Element; end Get_Local_Name; ---------------- -- Leave_Node -- ---------------- overriding procedure Leave_Node (Self : not null access Office_Script_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Leave_Office_Script (ODF.DOM.Office_Script_Elements.ODF_Office_Script_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Leave_Node (Visitor, Control); end if; end Leave_Node; ---------------- -- Visit_Node -- ---------------- overriding procedure Visit_Node (Self : not null access Office_Script_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then ODF.DOM.Iterators.Abstract_ODF_Iterator'Class (Iterator).Visit_Office_Script (Visitor, ODF.DOM.Office_Script_Elements.ODF_Office_Script_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Visit_Node (Iterator, Visitor, Control); end if; end Visit_Node; begin Matreshka.DOM_Documents.Register_Element (Matreshka.ODF_String_Constants.Office_URI, Matreshka.ODF_String_Constants.Script_Element, Office_Script_Element_Node'Tag); end Matreshka.ODF_Office.Script_Elements;
reznikmm/matreshka
Ada
47,032
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012-2015, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ pragma Restrictions (No_Elaboration_Code); -- GNAT: enforce generation of preinitialized data section instead of -- generation of elaboration code. package Matreshka.Internals.Unicode.Ucd.Core_0004 is pragma Preelaborate; Group_0004 : aliased constant Core_Second_Stage := (16#01# => -- 0401 (Uppercase_Letter, Ambiguous, Other, A_Letter, Upper, Alphabetic, (Alphabetic | Cased | Changes_When_Lowercased | Changes_When_Casefolded | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Uppercase | XID_Continue | XID_Start | Changes_When_NFKC_Casefolded => True, others => False)), 16#10# .. 16#2F# => -- 0410 .. 042F (Uppercase_Letter, Ambiguous, Other, A_Letter, Upper, Alphabetic, (Alphabetic | Cased | Changes_When_Lowercased | Changes_When_Casefolded | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Uppercase | XID_Continue | XID_Start | Changes_When_NFKC_Casefolded => True, others => False)), 16#30# .. 16#4F# => -- 0430 .. 044F (Lowercase_Letter, Ambiguous, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#50# => -- 0450 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#51# => -- 0451 (Lowercase_Letter, Ambiguous, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#52# .. 16#55# => -- 0452 .. 0455 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#56# => -- 0456 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Soft_Dotted | Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#57# => -- 0457 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#58# => -- 0458 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Soft_Dotted | Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#59# .. 16#5F# => -- 0459 .. 045F (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#61# => -- 0461 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#63# => -- 0463 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#65# => -- 0465 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#67# => -- 0467 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#69# => -- 0469 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#6B# => -- 046B (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#6D# => -- 046D (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#6F# => -- 046F (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#71# => -- 0471 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#73# => -- 0473 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#75# => -- 0475 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#77# => -- 0477 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#79# => -- 0479 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#7B# => -- 047B (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#7D# => -- 047D (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#7F# => -- 047F (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#81# => -- 0481 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#82# => -- 0482 (Other_Symbol, Neutral, Other, Other, Other, Alphabetic, (Grapheme_Base => True, others => False)), 16#83# .. 16#87# => -- 0483 .. 0487 (Nonspacing_Mark, Neutral, Extend, Extend, Extend, Combining_Mark, (Diacritic | Case_Ignorable | Grapheme_Extend | ID_Continue | XID_Continue => True, others => False)), 16#88# .. 16#89# => -- 0488 .. 0489 (Enclosing_Mark, Neutral, Extend, Extend, Extend, Combining_Mark, (Case_Ignorable | Grapheme_Extend => True, others => False)), 16#8B# => -- 048B (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#8D# => -- 048D (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#8F# => -- 048F (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#91# => -- 0491 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#93# => -- 0493 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#95# => -- 0495 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#97# => -- 0497 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#99# => -- 0499 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#9B# => -- 049B (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#9D# => -- 049D (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#9F# => -- 049F (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#A1# => -- 04A1 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#A3# => -- 04A3 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#A5# => -- 04A5 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#A7# => -- 04A7 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#A9# => -- 04A9 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#AB# => -- 04AB (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#AD# => -- 04AD (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#AF# => -- 04AF (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#B1# => -- 04B1 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#B3# => -- 04B3 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#B5# => -- 04B5 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#B7# => -- 04B7 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#B9# => -- 04B9 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#BB# => -- 04BB (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#BD# => -- 04BD (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#BF# => -- 04BF (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#C2# => -- 04C2 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#C4# => -- 04C4 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#C6# => -- 04C6 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#C8# => -- 04C8 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#CA# => -- 04CA (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#CC# => -- 04CC (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#CE# .. 16#CF# => -- 04CE .. 04CF (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#D1# => -- 04D1 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#D3# => -- 04D3 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#D5# => -- 04D5 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#D7# => -- 04D7 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#D9# => -- 04D9 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#DB# => -- 04DB (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#DD# => -- 04DD (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#DF# => -- 04DF (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#E1# => -- 04E1 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#E3# => -- 04E3 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#E5# => -- 04E5 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#E7# => -- 04E7 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#E9# => -- 04E9 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#EB# => -- 04EB (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#ED# => -- 04ED (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#EF# => -- 04EF (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#F1# => -- 04F1 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#F3# => -- 04F3 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#F5# => -- 04F5 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#F7# => -- 04F7 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#F9# => -- 04F9 (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#FB# => -- 04FB (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#FD# => -- 04FD (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), 16#FF# => -- 04FF (Lowercase_Letter, Neutral, Other, A_Letter, Lower, Alphabetic, (Alphabetic | Cased | Changes_When_Uppercased | Changes_When_Titlecased | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Lowercase | XID_Continue | XID_Start => True, others => False)), others => (Uppercase_Letter, Neutral, Other, A_Letter, Upper, Alphabetic, (Alphabetic | Cased | Changes_When_Lowercased | Changes_When_Casefolded | Changes_When_Casemapped | Grapheme_Base | ID_Continue | ID_Start | Uppercase | XID_Continue | XID_Start | Changes_When_NFKC_Casefolded => True, others => False))); end Matreshka.Internals.Unicode.Ucd.Core_0004;
reznikmm/matreshka
Ada
4,642
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Web Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014-2017, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with League.Strings; with Servlet.Contexts; with Servlet.Context_Listeners; package Servlet.Application is procedure Initialize (Application_Name : League.Strings.Universal_String; Application_Version : League.Strings.Universal_String; Organization_Name : League.Strings.Universal_String; Organization_Domain : League.Strings.Universal_String); -- Initialize servlet container. It detects run of application under -- FastCGI environment and use it when possible, or fallback to start as -- standalone AWS server when it supports was enabled at build time. procedure Execute; procedure Finalize; procedure Add_Listener (Listener : not null Servlet.Context_Listeners.Servlet_Context_Listener_Access); -- Adds Servlet_Context_Listener. Context_Initialized subprogram of this -- interface will be called during execution of Initialize subprogram; and -- Context_Destoyed subprogram will be called during execution of Finalize -- subprogram. function Get_Servlet_Context return not null Servlet.Contexts.Servlet_Context_Access; -- Returns servlet context of the initialized servlet container. -- Application should use this context to add and configure servlets and -- filters. end Servlet.Application;
zhmu/ananas
Ada
10,986
adb
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- L I V E -- -- -- -- B o d y -- -- -- -- Copyright (C) 2000-2022, 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 Atree; use Atree; with Einfo; use Einfo; with Einfo.Entities; use Einfo.Entities; with Einfo.Utils; use Einfo.Utils; with Lib; use Lib; with Nlists; use Nlists; with Sem_Aux; use Sem_Aux; with Sem_Util; use Sem_Util; with Sinfo; use Sinfo; with Sinfo.Nodes; use Sinfo.Nodes; with Sinfo.Utils; use Sinfo.Utils; with Types; use Types; package body Live is -- Name_Set -- The Name_Set type is used to store the temporary mark bits used by the -- garbage collection of entities. Using a separate array prevents using up -- any valuable per-node space and possibly results in better locality and -- cache usage. type Name_Set is array (Node_Id'Base range <>) of Boolean; -- We use 'Base here, in case we want to add a predicate to Node_Id pragma Pack (Name_Set); function Marked (Marks : Name_Set; Name : Node_Id) return Boolean; pragma Inline (Marked); procedure Set_Marked (Marks : in out Name_Set; Name : Node_Id; Mark : Boolean := True); pragma Inline (Set_Marked); -- Algorithm -- The problem of finding live entities is solved in two steps: procedure Mark (Root : Node_Id; Marks : out Name_Set); -- Mark all live entities in Root as Marked procedure Sweep (Root : Node_Id; Marks : Name_Set); -- For all unmarked entities in Root set Is_Eliminated to true -- The Mark phase is split into two phases: procedure Init_Marked (Root : Node_Id; Marks : out Name_Set); -- For all subprograms, reset Is_Public flag if a pragma Eliminate applies -- to the entity, and set the Marked flag to Is_Public. procedure Trace_Marked (Root : Node_Id; Marks : in out Name_Set); -- Traverse the tree skipping any unmarked subprogram bodies. All visited -- entities are marked, as well as entities denoted by a visited identifier -- or operator. When an entity is first marked it is traced as well. -- Local functions function Body_Of (E : Entity_Id) return Node_Id; -- Returns subprogram body corresponding to entity E function Spec_Of (N : Node_Id) return Entity_Id; -- Given a subprogram body N, return defining identifier of its declaration ------------- -- Body_Of -- ------------- function Body_Of (E : Entity_Id) return Node_Id is Decl : constant Node_Id := Unit_Declaration_Node (E); Kind : constant Node_Kind := Nkind (Decl); Result : Node_Id; begin if Kind = N_Subprogram_Body then Result := Decl; elsif Kind /= N_Subprogram_Declaration and Kind /= N_Subprogram_Body_Stub then Result := Empty; else Result := Corresponding_Body (Decl); if Result /= Empty then Result := Unit_Declaration_Node (Result); end if; end if; return Result; end Body_Of; ------------------------------ -- Collect_Garbage_Entities -- ------------------------------ procedure Collect_Garbage_Entities is Root : constant Node_Id := Cunit (Main_Unit); Marks : Name_Set (0 .. Last_Node_Id); begin Mark (Root, Marks); Sweep (Root, Marks); end Collect_Garbage_Entities; ----------------- -- Init_Marked -- ----------------- procedure Init_Marked (Root : Node_Id; Marks : out Name_Set) is function Process (N : Node_Id) return Traverse_Result; procedure Traverse is new Traverse_Proc (Process); ------------- -- Process -- ------------- function Process (N : Node_Id) return Traverse_Result is begin case Nkind (N) is when N_Entity'Range => if Is_Eliminated (N) then Set_Is_Public (N, False); end if; Set_Marked (Marks, N, Is_Public (N)); when N_Subprogram_Body => Traverse (Spec_Of (N)); when N_Package_Body_Stub => if Present (Library_Unit (N)) then Traverse (Proper_Body (Unit (Library_Unit (N)))); end if; when N_Package_Body => declare Elmt : Node_Id := First (Declarations (N)); begin while Present (Elmt) loop Traverse (Elmt); Next (Elmt); end loop; end; when others => null; end case; return OK; end Process; -- Start of processing for Init_Marked begin Marks := (others => False); Traverse (Root); end Init_Marked; ---------- -- Mark -- ---------- procedure Mark (Root : Node_Id; Marks : out Name_Set) is begin Init_Marked (Root, Marks); Trace_Marked (Root, Marks); end Mark; ------------ -- Marked -- ------------ function Marked (Marks : Name_Set; Name : Node_Id) return Boolean is begin return Marks (Name); end Marked; ---------------- -- Set_Marked -- ---------------- procedure Set_Marked (Marks : in out Name_Set; Name : Node_Id; Mark : Boolean := True) is begin Marks (Name) := Mark; end Set_Marked; ------------- -- Spec_Of -- ------------- function Spec_Of (N : Node_Id) return Entity_Id is begin if Acts_As_Spec (N) then return Defining_Entity (N); else return Corresponding_Spec (N); end if; end Spec_Of; ----------- -- Sweep -- ----------- procedure Sweep (Root : Node_Id; Marks : Name_Set) is function Process (N : Node_Id) return Traverse_Result; procedure Traverse is new Traverse_Proc (Process); ------------- -- Process -- ------------- function Process (N : Node_Id) return Traverse_Result is begin case Nkind (N) is when N_Entity'Range => Set_Is_Eliminated (N, not Marked (Marks, N)); when N_Subprogram_Body => Traverse (Spec_Of (N)); when N_Package_Body_Stub => if Present (Library_Unit (N)) then Traverse (Proper_Body (Unit (Library_Unit (N)))); end if; when N_Package_Body => declare Elmt : Node_Id := First (Declarations (N)); begin while Present (Elmt) loop Traverse (Elmt); Next (Elmt); end loop; end; when others => null; end case; return OK; end Process; -- Start of processing for Sweep begin Traverse (Root); end Sweep; ------------------ -- Trace_Marked -- ------------------ procedure Trace_Marked (Root : Node_Id; Marks : in out Name_Set) is function Process (N : Node_Id) return Traverse_Result; procedure Process (N : Node_Id); procedure Traverse is new Traverse_Proc (Process); ------------- -- Process -- ------------- procedure Process (N : Node_Id) is Result : Traverse_Result; pragma Warnings (Off, Result); begin Result := Process (N); end Process; function Process (N : Node_Id) return Traverse_Result is Result : Traverse_Result := OK; B : Node_Id; E : Entity_Id; begin case Nkind (N) is when N_Generic_Declaration'Range | N_Pragma | N_Subprogram_Body_Stub | N_Subprogram_Declaration => Result := Skip; when N_Subprogram_Body => if not Marked (Marks, Spec_Of (N)) then Result := Skip; end if; when N_Package_Body_Stub => if Present (Library_Unit (N)) then Traverse (Proper_Body (Unit (Library_Unit (N)))); end if; when N_Expanded_Name | N_Identifier | N_Operator_Symbol => E := Entity (N); if E /= Empty and then not Marked (Marks, E) then Process (E); if Is_Subprogram (E) then B := Body_Of (E); if B /= Empty then Traverse (B); end if; end if; end if; when N_Entity'Range => if (Ekind (N) = E_Component) and then not Marked (Marks, N) then if Present (Discriminant_Checking_Func (N)) then Process (Discriminant_Checking_Func (N)); end if; end if; Set_Marked (Marks, N); when others => null; end case; return Result; end Process; -- Start of processing for Trace_Marked begin Traverse (Root); end Trace_Marked; end Live;
annexi-strayline/AURA
Ada
5,968
adb
------------------------------------------------------------------------------ -- -- -- Ada User Repository Annex (AURA) -- -- Reference Implementation -- -- -- -- ------------------------------------------------------------------------ -- -- -- -- Copyright (C) 2020-2021, ANNEXI-STRAYLINE Trans-Human Ltd. -- -- All rights reserved. -- -- -- -- Original Contributors: -- -- * Richard Wai (ANNEXI-STRAYLINE) -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- -- -- * Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ with Registrar.Source_Files; separate (Registrar.Implementation_Hashing) package body Crunch_Orders is ----------- -- Image -- ----------- function Image (Order: Crunch_Order) return String is ("[Crunch_Order] (Registrar.Implementation_Hashing)" & New_Line & " Target Unit: " & Order.Source_Set.all (Order.Collection_Set.all(Order.Collector).Target_Unit) .Name.To_UTF8_String); ------------- -- Execute -- ------------- procedure Execute (Order: in out Crunch_Order) is procedure Free_Hash_Queue is new Ada.Unchecked_Deallocation (Object => Hash_Queues.Queue, Name => Hash_Queue_Access); Collector: Collection_Unit; Spec_Hash : Stream_Hashing.Hash_Type; Crunched_Hash: Stream_Hashing.Hash_Type; procedure Update_Hash (Item: in out Library_Units.Library_Unit) is begin Item.Specification_Hash := Spec_Hash; Item.Implementation_Hash := Crunched_Hash; end Update_Hash; begin -- Extract the Collector from the Collection_Set Collector := Order.Collection_Set.all(Order.Collector); Stream_Hashing.Collective.Compute_Collective_Hash (Hash_Queue => Collector.Hash_Queue.all, Collective_Hash => Crunched_Hash); declare use Registrar.Source_Files; Spec_File: Source_File_Access renames Order.Source_Set.all(Collector.Target_Unit).Spec_File; begin if Spec_File /= null then Spec_Hash := Spec_File.Hash; end if; -- Otherwise the hash should be assumed to be invalid since this unit -- does not have a specification end; -- Modifiy in-place Registry.All_Library_Units.Modify (Match => Order.Source_Set.all(Collector.Target_Unit), Process => Update_Hash'Access); Free_Hash_Queue (Collector.Hash_Queue); end Execute; ------------------- -- Phase_Trigger -- ------------------- procedure Phase_Trigger (Order: in out Crunch_Order) is New_Order: Cleanup_Order; begin -- We can leave the Beacon now, since we are not relying on any more -- phase triggers after this one. The Cleanup_Order simply deallocates -- the sets we were using up to this point Guard_Beacon.Leave; New_Order.Source_Set := Order.Source_Set; New_Order.Collection_Set := Order.Collection_Set; Workers.Enqueue_Order (New_Order); end Phase_Trigger; end Crunch_Orders;
reznikmm/matreshka
Ada
4,684
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Visitors; with ODF.DOM.Text_Chapter_Elements; package Matreshka.ODF_Text.Chapter_Elements is type Text_Chapter_Element_Node is new Matreshka.ODF_Text.Abstract_Text_Element_Node and ODF.DOM.Text_Chapter_Elements.ODF_Text_Chapter with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Text_Chapter_Element_Node; overriding function Get_Local_Name (Self : not null access constant Text_Chapter_Element_Node) return League.Strings.Universal_String; overriding procedure Enter_Node (Self : not null access Text_Chapter_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control); overriding procedure Leave_Node (Self : not null access Text_Chapter_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control); overriding procedure Visit_Node (Self : not null access Text_Chapter_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control); end Matreshka.ODF_Text.Chapter_Elements;
AdaCore/gpr
Ada
41,187
adb
-- -- Copyright (C) 2014-2022, AdaCore -- SPDX-License-Identifier: Apache-2.0 -- with Ada.Strings.Unbounded; with Ada.Text_IO; use Ada.Text_IO; with Ada.Unchecked_Conversion; with System; with GNATCOLL.VFS; with Gpr_Parser_Support.Errors; use Gpr_Parser_Support.Errors; with Gpr_Parser_Support.Generic_API.Introspection; use Gpr_Parser_Support.Generic_API.Introspection; with Gpr_Parser_Support.Hashes; use Gpr_Parser_Support.Hashes; with Gpr_Parser_Support.Internal.Descriptor; use Gpr_Parser_Support.Internal.Descriptor; with Gpr_Parser_Support.Lexical_Envs; use Gpr_Parser_Support.Lexical_Envs; with Gpr_Parser_Support.Names; use Gpr_Parser_Support.Names; with Gpr_Parser_Support.Types; use Gpr_Parser_Support.Types; package body Gpr_Parser_Support.Generic_API.Analysis is function Wrap_Context (Id : Language_Id; Context : Internal_Context) return Lk_Context with Export, External_Name => External_Name_Prefix & "wrap_context"; function Unwrap_Context (Context : Lk_Context) return Internal_Context with Export, External_Name => External_Name_Prefix & "unwrap_context"; -- Public/private converters for contexts function Wrap_Unit (Id : Language_Id; Unit : Internal_Unit) return Lk_Unit with Export, External_Name => External_Name_Prefix & "wrap_unit"; function Unwrap_Unit (Unit : Lk_Unit) return Internal_Unit with Export, External_Name => External_Name_Prefix & "unwrap_unit"; -- Public/private converters for units function Wrap_Node (Id : Language_Id; Node : Internal_Entity) return Lk_Node with Export, External_Name => External_Name_Prefix & "wrap_node"; function Unwrap_Node (Node : Lk_Node) return Internal_Entity with Export, External_Name => External_Name_Prefix & "unwrap_node"; -- Public/private converters for nodes function Wrap_Token (Id : Any_Language_Id; Token : Internal_Token; Safety_Net : Token_Safety_Net) return Lk_Token with Export, External_Name => External_Name_Prefix & "wrap_token"; procedure Unwrap_Token (Token : Lk_Token; Id : out Any_Language_Id; Data : out Internal_Token; Safety_Net : out Token_Safety_Net) with Export, External_Name => External_Name_Prefix & "unwrap_token"; -- Public/private converters for tokens function Create_Node_Safety_Net (Unit : Lk_Unit'Class; Rebindings : Env_Rebindings) return Node_Safety_Net; -- Create a safety net for a node, to make sure that later access to that -- node does not use a stale unit or stale rebindings. function Create_Token_Safety_Net (TDH : Token_Data_Handler_Access; Unit : Lk_Unit'Class) return Token_Safety_Net; -- Create a safety net for a token, to make sure that later access to that -- token does not use stale data. procedure Check_Safety_Net (Node : Lk_Node'Class); -- Check that the unit and rebindings referenced by Node are not stale. -- Raise a ``Stale_Reference_Error`` exception if one of them are stale. procedure Check_Safety_Net (Token : Lk_Token'Class); -- Raise a ``Stale_Reference_Error`` exception in ``Token`` is stale procedure Reject_Null_Context (Context : Lk_Context'Class); procedure Reject_Null_Unit (Unit : Lk_Unit'Class); procedure Reject_Null_Node (Node : Lk_Node'Class); procedure Reject_Null_Token (Token : Lk_Token'Class); -- Raise a ``Precondition_Failure`` exception if -- ``Context``/``Unit``/``Node``/``Token`` is null. procedure Check_Same_Unit (Left, Right : Lk_Token'Class); -- Raise a ``Precondition_Failure`` exception if ``Left`` and ``Right`` do -- not belong to the same unit. function Wrap_Node (Node : Internal_Node; Origin_Node : Lk_Node'Class) return Lk_Node; -- Return a public node to wrap ``Node``. Use safety net and entity info -- from ``Origin_Node``. function Wrap (Token : Internal_Token; Unit : Lk_Unit'Class) return Lk_Token; -- Return a public token reference to wrap ``Token``. ``Unit`` must own -- the unit that produced this token. function Wrap (Token : Internal_Token; Node : Lk_Node'Class) return Lk_Token; -- Return a public token reference to wrap ``Token``. ``Node`` must belong -- to the same analysis unit. function Wrap_Token (Token : Internal_Token; Origin_Token : Lk_Token'Class) return Lk_Token; -- Return a public token reference to wrap ``Token``. Use safety net from -- ``Origin Token``. function "+" (Kind : Raw_Token_Kind) return Token_Kind_Index is (Token_Kind_Index (Kind + 1)); -- ``Raw_Token_Kind`` is a 0-based index type, whereas ``Token_Kind_Index`` -- is a 1-based one. ---------------------------- -- Create_Node_Safety_Net -- ---------------------------- function Create_Node_Safety_Net (Unit : Lk_Unit'Class; Rebindings : Env_Rebindings) return Node_Safety_Net is Desc : Language_Descriptor renames Unit.Context.Desc.all; Context : constant Internal_Context := Unit.Context.Internal; begin return (Context => Context, Context_Version => Desc.Context_Version (Context), Unit => Unit.Internal, Unit_Version => Desc.Unit_Version (Unit.Internal), Rebindings_Version => (if Rebindings = null then 0 else Rebindings.Version)); end Create_Node_Safety_Net; ----------------------------- -- Create_Token_Safety_Net -- ----------------------------- function Create_Token_Safety_Net (TDH : Token_Data_Handler_Access; Unit : Lk_Unit'Class) return Token_Safety_Net is Desc : Language_Descriptor renames Unit.Context.Desc.all; Context : constant Internal_Context := Unit.Context.Internal; begin return (Context => Context, Context_Version => Desc.Context_Version (Context), TDH_Version => TDH.Version); end Create_Token_Safety_Net; ---------------------- -- Check_Safety_Net -- ---------------------- procedure Check_Safety_Net (Node : Lk_Node'Class) is Desc : constant Any_Language_Id := Node.Desc; Entity : Internal_Entity renames Node.Internal; Safety_Net : Node_Safety_Net renames Node.Safety_Net; begin -- Nothing to check if Node is null. If it is not, we know that the unit -- and the context both are not null. if Node.Internal.Node = No_Internal_Node then return; end if; -- Check that the context has not been released since the creation of -- this safety net. if Desc.Context_Version (Safety_Net.Context) /= Safety_Net.Context_Version then raise Stale_Reference_Error with "context was released"; -- Then check that the unit version is the same elsif Desc.Unit_Version (Safety_Net.Unit) /= Safety_Net.Unit_Version then raise Stale_Reference_Error with "unit was reparsed"; -- Then check that the rebindings reference, if not-null, is not stale elsif Entity.Rebindings /= null and then Entity.Rebindings.Version /= Safety_Net.Rebindings_Version then raise Stale_Reference_Error with "related unit was reparsed"; end if; end Check_Safety_Net; ---------------------- -- Check_Safety_Net -- ---------------------- procedure Check_Safety_Net (Token : Lk_Token'Class) is Desc : constant Any_Language_Id := Token.Desc; Safety_Net : Token_Safety_Net renames Token.Safety_Net; begin -- Nothing to check if TDH is null. If it is not, we know that the -- context is not null. if Token.TDH = null then return; end if; -- Check that the context has not been released since the creation of -- this safety net. if Desc.Context_Version (Safety_Net.Context) /= Safety_Net.Context_Version then raise Stale_Reference_Error with "context was released"; -- Then check that the TDH version is the same elsif Token.TDH.Version /= Safety_Net.TDH_Version then raise Stale_Reference_Error with "unit was reparsed"; end if; end Check_Safety_Net; ------------------------- -- Reject_Null_Context -- ------------------------- procedure Reject_Null_Context (Context : Lk_Context'Class) is begin if Context.Internal = No_Internal_Context then raise Precondition_Failure with "null context"; end if; end Reject_Null_Context; ---------------------- -- Reject_Null_Unit -- ---------------------- procedure Reject_Null_Unit (Unit : Lk_Unit'Class) is begin if Unit.Context.Internal = No_Internal_Context then raise Precondition_Failure with "null unit"; end if; end Reject_Null_Unit; ---------------------- -- Reject_Null_Node -- ---------------------- procedure Reject_Null_Node (Node : Lk_Node'Class) is begin if Node.Internal.Node = No_Internal_Node then raise Precondition_Failure with "null node"; end if; end Reject_Null_Node; ----------------------- -- Reject_Null_Token -- ----------------------- procedure Reject_Null_Token (Token : Lk_Token'Class) is begin if Token.Desc = null then raise Precondition_Failure with "null token"; end if; end Reject_Null_Token; --------------------- -- Check_Same_Unit -- --------------------- procedure Check_Same_Unit (Left, Right : Lk_Token'Class) is begin if Left.TDH /= Right.TDH then raise Precondition_Failure with "tokens from different units"; end if; end Check_Same_Unit; --------------- -- Wrap_Node -- --------------- function Wrap_Node (Node : Internal_Node; Origin_Node : Lk_Node'Class) return Lk_Node is E : Internal_Entity renames Origin_Node.Internal; begin -- Null nodes must always be equal to the dedicated constant if Node = No_Internal_Node then return No_Lk_Node; end if; -- Create a new metadata ownership share for the result if E.Metadata /= Origin_Node.Desc.Null_Metadata then Origin_Node.Desc.Node_Metadata_Inc_Ref (E.Metadata); end if; return (Ada.Finalization.Controlled with Desc => Origin_Node.Desc, Internal => (Node => Node, Rebindings => E.Rebindings, From_Rebound => E.From_Rebound, Metadata => E.Metadata), Safety_Net => Origin_Node.Safety_Net); end Wrap_Node; ---------- -- Wrap -- ---------- function Wrap (Token : Internal_Token; Unit : Lk_Unit'Class) return Lk_Token is begin -- Null token must always be equal to the dedicated constant if Token.Index = No_Token_Or_Trivia_Index then return No_Lk_Token; end if; declare Desc : constant Any_Language_Id := Unit.Context.Desc; Safety_Net : constant Token_Safety_Net := Create_Token_Safety_Net (Token.TDH, Unit); begin return (Desc, Token.TDH, Token.Index, Safety_Net); end; end Wrap; ---------- -- Wrap -- ---------- function Wrap (Token : Internal_Token; Node : Lk_Node'Class) return Lk_Token is begin return Wrap (Token, Node.Unit); end Wrap; ---------------- -- Wrap_Token -- ---------------- function Wrap_Token (Token : Internal_Token; Origin_Token : Lk_Token'Class) return Lk_Token is begin -- Null token must always be equal to the dedicated constant if Token.Index = No_Token_Or_Trivia_Index then return No_Lk_Token; end if; return (Desc => Origin_Token.Desc, TDH => Token.TDH, Index => Token.Index, Safety_Net => Origin_Token.Safety_Net); end Wrap_Token; -------------------- -- Create_Context -- -------------------- function Create_Context (Language : Language_Id; Charset : String := ""; File_Reader : File_Reader_Reference := No_File_Reader_Reference; With_Trivia : Boolean := True; Tab_Stop : Natural := 0) return Lk_Context is Result : constant Internal_Context := Language.Create_Context (Charset, File_Reader, With_Trivia, Tab_Stop); begin return (Ada.Finalization.Controlled with Desc => Language, Internal => Result); end Create_Context; -------------- -- Language -- -------------- function Language (Self : Lk_Context) return Language_Id is begin Reject_Null_Context (Self); return Self.Desc; end Language; ---------- -- Hash -- ---------- function Hash (Self : Lk_Context) return Hash_Type is begin return Hash (Self.Internal); end Hash; -------------- -- Has_Unit -- -------------- function Has_Unit (Self : Lk_Context; Unit_Filename : String) return Boolean is begin Reject_Null_Context (Self); return Self.Desc.Context_Has_Unit (Self.Internal, Unit_Filename); end Has_Unit; ------------------- -- Get_From_File -- ------------------- function Get_From_File (Self : Lk_Context'Class; Filename : String; Charset : String := ""; Reparse : Boolean := False; Rule : Grammar_Rule_Ref := No_Grammar_Rule_Ref) return Lk_Unit is Result : Internal_Unit; begin Reject_Null_Context (Self); declare Desc : Language_Descriptor renames Self.Desc.all; Actual_Rule : Grammar_Rule_Index; begin if Rule = No_Grammar_Rule_Ref then Actual_Rule := Desc.Default_Grammar_Rule; else Actual_Rule := To_Index (Rule); end if; Result := Self.Desc.Context_Get_From_File (Self.Internal, Filename, Charset, Reparse, Actual_Rule); return (Result, Lk_Context (Self)); end; end Get_From_File; -------------- -- Language -- -------------- function Language (Self : Lk_Unit) return Language_Id is begin Reject_Null_Unit (Self); return Self.Context.Desc; end Language; ---------- -- Hash -- ---------- function Hash (Self : Lk_Unit) return Hash_Type is begin return Hash (Self.Internal); end Hash; -------------- -- Get_Line -- -------------- overriding function Get_Line (Self : Lk_Unit; Line_Number : Positive) return Text_Type is begin Reject_Null_Unit (Self); return Self.Context.Desc.Unit_Get_Line (Self.Internal, Line_Number); end Get_Line; ------------- -- Context -- ------------- function Context (Self : Lk_Unit'Class) return Lk_Context is begin Reject_Null_Unit (Self); return Self.Context; end Context; -------------- -- Filename -- -------------- function Filename (Self : Lk_Unit) return String is begin Reject_Null_Unit (Self); declare Desc : Language_Descriptor renames Self.Context.Desc.all; begin return Desc.Unit_Filename (Self.Internal); end; end Filename; ---------- -- Root -- ---------- function Root (Self : Lk_Unit'Class) return Lk_Node is function Wrap (Node : Internal_Node; Unit : Lk_Unit'Class) return Lk_Node with Inline_Always; -- Return a public node to wrap ``Node``, given an existing non-null -- reference to its owning Unit. ---------- -- Wrap -- ---------- function Wrap (Node : Internal_Node; Unit : Lk_Unit'Class) return Lk_Node is Desc : constant Any_Language_Id := Unit.Context.Desc; Entity : constant Internal_Entity := (Node, null, False, Desc.Null_Metadata); Safety_Net : constant Node_Safety_Net := Create_Node_Safety_Net (Unit, null); begin return (Ada.Finalization.Controlled with Desc, Entity, Safety_Net); end Wrap; begin Reject_Null_Unit (Self); declare Desc : Language_Descriptor renames Self.Context.Desc.all; Result : constant Internal_Node := Desc.Unit_Root (Self.Internal); begin return Wrap (Result, Self); end; end Root; ----------------- -- First_Token -- ----------------- function First_Token (Self : Lk_Unit'Class) return Lk_Token is begin Reject_Null_Unit (Self); declare Desc : Language_Descriptor renames Self.Context.Desc.all; Result : constant Internal_Token := Desc.Unit_First_Token (Self.Internal); begin return Wrap (Result, Self); end; end First_Token; ---------------- -- Last_Token -- ---------------- function Last_Token (Self : Lk_Unit'Class) return Lk_Token is begin Reject_Null_Unit (Self); declare Desc : Language_Descriptor renames Self.Context.Desc.all; Result : constant Internal_Token := Desc.Unit_Last_Token (Self.Internal); begin return Wrap (Result, Self); end; end Last_Token; ---------- -- Text -- ---------- function Text (Self : Lk_Unit) return Text_Type is begin return Text (Self.First_Token, Self.Last_Token); end Text; -------------- -- Language -- -------------- function Language (Self : Lk_Node) return Language_Id is begin Check_Safety_Net (Self); Reject_Null_Node (Self); return Self.Desc; end Language; ---------- -- Hash -- ---------- function Hash (Self : Lk_Node) return Hash_Type is begin return Combine (Hash (Self.Internal.Node), Hash (Self.Internal.Rebindings)); end Hash; ---------- -- Unit -- ---------- function Unit (Self : Lk_Node'Class) return Lk_Unit is begin Check_Safety_Net (Self); Reject_Null_Node (Self); declare Ctx : constant Internal_Context := Self.Safety_Net.Context; U : constant Internal_Unit := Self.Safety_Net.Unit; Desc : constant Any_Language_Id := Self.Desc; begin -- Create an ownership share for the context embedded in the result -- before returning. Desc.Context_Inc_Ref (Ctx); return (Internal => U, Context => (Ada.Finalization.Controlled with Desc => Desc, Internal => Ctx)); end; end Unit; ------------- -- Is_Null -- ------------- function Is_Null (Self : Lk_Node) return Boolean is begin return Self.Internal.Node = No_Internal_Node; end Is_Null; --------- -- "=" -- --------- function "=" (Left, Right : Lk_Node) return Boolean is begin Check_Safety_Net (Left); Check_Safety_Net (Right); -- We only want to take the node into account when determining whether a -- node is null or not, not the rest of the entity info. In particular, -- for a null node, metadata might not be null (because it's a pointer -- to the null metadata of the specific language). if Left.Internal.Node = No_Internal_Node or else Right.Internal.Node = No_Internal_Node then return Left.Internal.Node = Right.Internal.Node; end if; return (Left.Internal.Node = Right.Internal.Node and then Left.Internal.Rebindings = Right.Internal.Rebindings and then -- Check that metadata values are the same Left.Desc.Node_Metadata_Compare (Left.Internal.Metadata, Right.Internal.Metadata)); end "="; ----------- -- Image -- ----------- function Image (Self : Lk_Node) return String is begin Check_Safety_Net (Self); return (if Self.Internal.Node = No_Internal_Node then "None" else Self.Desc.Entity_Image (Self.Internal)); end Image; ----------- -- Print -- ----------- procedure Print (Node : Lk_Node; Show_Slocs : Boolean := True; Line_Prefix : String := "") is T : constant Type_Ref := Type_Of (Node); Attr_Prefix : constant String := Line_Prefix & "|"; Children_Prefix : constant String := Line_Prefix & "| "; begin if Node = No_Lk_Node then Put_Line (Line_Prefix & "None"); return; end if; Put (Line_Prefix & Debug_Name (T)); if Show_Slocs then Put ("[" & Image (Node.Sloc_Range) & "]"); end if; if Node.Is_Incomplete then Put (" <<INCOMPLETE>>"); end if; if Is_Token_Node (T) then Put_Line (": " & Image (Node.Text)); elsif Is_List_Node (T) then if Node.Children_Count = 0 then Put_Line (": <empty list>"); return; end if; New_Line; for Child of Node.Children loop if Child /= No_Lk_Node then Child.Print (Show_Slocs, Children_Prefix); end if; end loop; return; else -- This is for regular nodes: display each field New_Line; for M of Members (T) loop if not Is_Property (M) then declare Child : constant Lk_Node := As_Node (Eval_Node_Member (Node, M)); Name : constant String := Image (Format_Name (Member_Name (M), Lower)); begin Put (Attr_Prefix & Name & ":"); if Child /= No_Lk_Node then New_Line; Child.Print (Show_Slocs, Children_Prefix); else Put_Line (" <null>"); end if; end; end if; end loop; end if; end Print; ------------ -- Parent -- ------------ function Parent (Self : Lk_Node'Class) return Lk_Node is begin Check_Safety_Net (Self); Reject_Null_Node (Self); return Wrap_Node (Self.Desc, Self.Desc.Node_Parent (Self.Internal)); end Parent; ------------- -- Parents -- ------------- function Parents (Self : Lk_Node; With_Self : Boolean := True) return Lk_Node_Array is Id : Any_Language_Id renames Self.Desc; begin Check_Safety_Net (Self); Reject_Null_Node (Self); declare Parents : constant Internal_Entity_Array := Id.Node_Parents (Self.Internal, With_Self); begin return Result : Lk_Node_Array (Parents'Range) do for I in Parents'Range loop Result (I) := Wrap_Node (Id, Parents (I)); end loop; end return; end; end Parents; -------------------- -- Children_Count -- -------------------- function Children_Count (Self : Lk_Node) return Natural is begin Check_Safety_Net (Self); Reject_Null_Node (Self); return Self.Desc.Node_Children_Count (Self.Internal.Node); end Children_Count; --------------- -- Get_Child -- --------------- procedure Get_Child (Self : Lk_Node'Class; Index : Positive; Index_In_Bounds : out Boolean; Result : out Lk_Node) is Internal_Result : Internal_Node; begin Check_Safety_Net (Self); Reject_Null_Node (Self); Self.Desc.Node_Get_Child (Self.Internal.Node, Index, Index_In_Bounds, Internal_Result); Result := Wrap_Node (Internal_Result, Self); end Get_Child; ----------- -- Child -- ----------- function Child (Self : Lk_Node'Class; Index : Positive) return Lk_Node is Dummy : Boolean; begin -- The Child overload call below takes care of sanitizing Self return Result : Lk_Node do Self.Get_Child (Index, Dummy, Result); end return; end Child; -------------- -- Children -- -------------- function Children (Self : Lk_Node) return Lk_Node_Array is -- The following call to Children_Count below takes care of sanitizing -- Self. Count : constant Natural := Self.Children_Count; begin return Result : Lk_Node_Array (1 .. Count) do for I in Result'Range loop Result (I) := Self.Child (I); end loop; end return; end Children; ------------------ -- Next_Sibling -- ------------------ function Next_Sibling (Self : Lk_Node'Class) return Lk_Node is begin Check_Safety_Net (Self); Reject_Null_Node (Self); return Wrap_Node (Self.Desc.Node_Fetch_Sibling (Self.Internal.Node, 1), Self); end Next_Sibling; ---------------------- -- Previous_Sibling -- ---------------------- function Previous_Sibling (Self : Lk_Node'Class) return Lk_Node is begin return Wrap_Node (Self.Desc.Node_Fetch_Sibling (Self.Internal.Node, -1), Self); end Previous_Sibling; -------------- -- Is_Ghost -- -------------- function Is_Ghost (Self : Lk_Node) return Boolean is begin Check_Safety_Net (Self); Reject_Null_Node (Self); return Self.Desc.Node_Is_Ghost (Self.Internal.Node); end Is_Ghost; ------------------ -- Is_List_Node -- ------------------ function Is_List_Node (Self : Lk_Node'Class) return Boolean is begin return Is_List_Node (Type_Of (Lk_Node (Self))); end Is_List_Node; ------------------- -- Is_Token_Node -- ------------------- function Is_Token_Node (Self : Lk_Node'Class) return Boolean is begin return Is_Token_Node (Type_Of (Lk_Node (Self))); end Is_Token_Node; -------------- -- Traverse -- -------------- function Traverse (Self : Lk_Node; Visit : access function (Node : Lk_Node) return Visit_Status) return Visit_Status is Desc : Language_Descriptor renames Self.Desc.all; function Process (N : Internal_Node) return Visit_Status; ------------- -- Process -- ------------- function Process (N : Internal_Node) return Visit_Status is Status : Visit_Status := Into; begin if N /= No_Internal_Node then Status := Visit (Wrap_Node (N, Self)); -- Skip processing the child nodes if the returned status is Over -- or Stop. In the former case the previous call to Visit has -- taken care of processing the needed children, and in the -- latter case we must immediately stop processing the tree. if Status = Into then for I in 1 .. Desc.Node_Children_Count (N) loop declare Child : Internal_Node; Index_In_Bounds : Boolean; begin Desc.Node_Get_Child (N, I, Index_In_Bounds, Child); pragma Assert (Index_In_Bounds); if Child /= No_Internal_Node then Status := Process (Child); exit when Status /= Into; end if; end; end loop; end if; end if; -- At this stage the Over status has no sense and we just continue -- processing the tree unless Status is Stop. return (if Status = Stop then Stop else Into); end Process; begin Check_Safety_Net (Self); return Process (Self.Internal.Node); end Traverse; -------------- -- Traverse -- -------------- procedure Traverse (Self : Lk_Node; Visit : access function (Node : Lk_Node) return Visit_Status) is Dummy : Visit_Status := Self.Traverse (Visit); begin null; end Traverse; ----------------- -- Token_Start -- ----------------- function Token_Start (Self : Lk_Node'Class) return Lk_Token is begin Check_Safety_Net (Self); Reject_Null_Node (Self); declare Desc : Language_Descriptor renames Self.Desc.all; Result : constant Internal_Token := Desc.Node_Token_Start (Self.Internal.Node); begin return Wrap (Result, Self); end; end Token_Start; --------------- -- Token_End -- --------------- function Token_End (Self : Lk_Node'Class) return Lk_Token is begin Check_Safety_Net (Self); Reject_Null_Node (Self); declare Desc : Language_Descriptor renames Self.Desc.all; Result : constant Internal_Token := Desc.Node_Token_End (Self.Internal.Node); begin return Wrap (Result, Self); end; end Token_End; ---------- -- Text -- ---------- function Text (Self : Lk_Node) return Text_Type is begin Check_Safety_Net (Self); Reject_Null_Node (Self); return Self.Desc.Node_Text (Self.Internal.Node); end Text; ---------------- -- Sloc_Range -- ---------------- function Sloc_Range (Self : Lk_Node) return Source_Location_Range is begin Check_Safety_Net (Self); Reject_Null_Node (Self); return Self.Desc.Node_Sloc_Range (Self.Internal.Node); end Sloc_Range; ------------------- -- Is_Incomplete -- ------------------- function Is_Incomplete (Self : Lk_Node) return Boolean is LGC : Lk_Node; begin if Is_List_Node (Type_Of (Self)) then LGC := (if Self.Children_Count /= 0 then Self.Child (Self.Children_Count) else No_Lk_Node); return LGC /= No_Lk_Node and then LGC.Is_Incomplete; else return Self.Desc.Node_Last_Attempted_Child (Self.Internal.Node) > -1; end if; end Is_Incomplete; -------------- -- Language -- -------------- function Language (Self : Lk_Token) return Language_Id is begin Check_Safety_Net (Self); Reject_Null_Token (Self); return Self.Desc; end Language; ---------- -- Hash -- ---------- function Hash (Self : Lk_Token) return Hash_Type is begin return Combine ((Hash (Self.TDH), Hash_Type (Self.Index.Token), Hash_Type (Self.Index.Trivia))); end Hash; ---------- -- Unit -- ---------- function Unit (Self : Lk_Token'Class) return Lk_Unit is begin Check_Safety_Net (Self); Reject_Null_Token (Self); declare function "+" is new Ada.Unchecked_Conversion (System.Address, Internal_Unit); Ctx : constant Internal_Context := Self.Safety_Net.Context; U : constant Internal_Unit := +Self.TDH.Owner; Desc : constant Any_Language_Id := Self.Desc; begin -- Create an ownership share for the context embedded in the result -- before returning. Desc.Context_Inc_Ref (Ctx); return (Internal => U, Context => (Ada.Finalization.Controlled with Desc => Desc, Internal => Ctx)); end; end Unit; ------------- -- Is_Null -- ------------- function Is_Null (Self : Lk_Token) return Boolean is begin return Self.Desc = null; end Is_Null; ---------- -- Kind -- ---------- function Kind (Self : Lk_Token) return Token_Kind_Ref is D : Stored_Token_Data; begin Check_Safety_Net (Self); Reject_Null_Token (Self); D := Data (Self.Index, Self.TDH.all); return From_Index (Self.Desc, +D.Kind); end Kind; --------- -- "<" -- --------- function "<" (Left, Right : Lk_Token) return Boolean is begin Check_Safety_Net (Left); Check_Safety_Net (Right); Check_Same_Unit (Left, Right); if Left.Index.Token < Right.Index.Token then return True; elsif Left.Index.Token = Right.Index.Token then return Left.Index.Trivia < Right.Index.Trivia; else return False; end if; end "<"; ---------- -- Next -- ---------- function Next (Self : Lk_Token'Class; Exclude_Trivia : Boolean := False) return Lk_Token is Result : Token_Or_Trivia_Index; begin Check_Safety_Net (Self); if Self.Is_Null then return No_Lk_Token; end if; Result := Next (Self.Index, Self.TDH.all, Exclude_Trivia); return Wrap_Token ((Self.TDH, Result), Self); end Next; -------------- -- Previous -- -------------- function Previous (Self : Lk_Token'Class; Exclude_Trivia : Boolean := False) return Lk_Token is Result : Token_Or_Trivia_Index; begin Check_Safety_Net (Self); if Self.Is_Null then return No_Lk_Token; end if; Result := Previous (Self.Index, Self.TDH.all, Exclude_Trivia); return Wrap_Token ((Self.TDH, Result), Self); end Previous; ----------- -- Image -- ----------- function Image (Self : Lk_Token) return String is begin Check_Safety_Net (Self); if Self.Is_Null then return "<No Token>"; end if; declare Name : constant Name_Type := Token_Kind_Name (Self.Kind); Text : constant Text_Type := Self.Text; begin return "<Token Kind=" & Image (Format_Name (Name, Camel_With_Underscores)) & " Text=" & Image (Text, With_Quotes => True) & ">"; end; end Image; ---------- -- Text -- ---------- function Text (Self : Lk_Token) return Text_Type is D : Stored_Token_Data; begin Check_Safety_Net (Self); Reject_Null_Token (Self); D := Data (Self.Index, Self.TDH.all); return Self.TDH.Source_Buffer (D.Source_First .. D.Source_Last); end Text; ---------- -- Text -- ---------- function Text (First, Last : Lk_Token) return Text_Type is FD, LD : Stored_Token_Data; begin Check_Safety_Net (First); Check_Safety_Net (Last); Check_Same_Unit (First, Last); FD := Data (First.Index, First.TDH.all); LD := Data (Last.Index, First.TDH.all); return First.TDH.Source_Buffer (FD.Source_First .. LD.Source_Last); end Text; --------------- -- Is_Trivia -- --------------- function Is_Trivia (Self : Lk_Token) return Boolean is begin Check_Safety_Net (Self); Reject_Null_Token (Self); return Self.Index.Trivia /= No_Token_Index; end Is_Trivia; ----------- -- Index -- ----------- function Index (Self : Lk_Token) return Token_Index is begin Check_Safety_Net (Self); Reject_Null_Token (Self); return (if Self.Index.Trivia = No_Token_Index then Self.Index.Token else Self.Index.Trivia); end Index; ---------------- -- Sloc_Range -- ---------------- function Sloc_Range (Self : Lk_Token) return Source_Location_Range is begin Check_Safety_Net (Self); Reject_Null_Token (Self); return Sloc_Range (Self.TDH.all, Data (Self.Index, Self.TDH.all)); end Sloc_Range; ------------------- -- Is_Equivalent -- ------------------- function Is_Equivalent (Left, Right : Lk_Token) return Boolean is begin Check_Safety_Net (Left); Check_Safety_Net (Right); Reject_Null_Token (Left); Reject_Null_Token (Right); if Left.Desc /= Right.Desc then raise Precondition_Failure with "inconsistent languages"; end if; return Left.Desc.Token_Is_Equivalent.all (Left => (Left.TDH, Left.Index), Right => (Right.TDH, Right.Index), Left_SN => Left.Safety_Net, Right_SN => Right.Safety_Net); end Is_Equivalent; --------------------- -- Origin_Filename -- --------------------- function Origin_Filename (Self : Lk_Token) return String is use GNATCOLL.VFS; begin Check_Safety_Net (Self); Reject_Null_Token (Self); return +Self.TDH.Filename.Full_Name; end Origin_Filename; -------------------- -- Origin_Charset -- -------------------- function Origin_Charset (Self : Lk_Token) return String is use Ada.Strings.Unbounded; begin Check_Safety_Net (Self); Reject_Null_Token (Self); return To_String (Self.TDH.Charset); end Origin_Charset; ---------------- -- Initialize -- ---------------- overriding procedure Initialize (Self : in out Lk_Context) is begin Self.Desc := null; Self.Internal := No_Internal_Context; end Initialize; ------------ -- Adjust -- ------------ overriding procedure Adjust (Self : in out Lk_Context) is begin if Self.Internal /= No_Internal_Context then Self.Desc.Context_Inc_Ref (Self.Internal); end if; end Adjust; -------------- -- Finalize -- -------------- overriding procedure Finalize (Self : in out Lk_Context) is begin if Self.Internal /= No_Internal_Context then Self.Desc.Context_Dec_Ref (Self.Internal); Self.Initialize; end if; end Finalize; ---------------- -- Initialize -- ---------------- overriding procedure Initialize (Self : in out Lk_Node) is begin Self.Desc := null; Self.Internal := No_Internal_Entity; Self.Safety_Net := No_Node_Safety_Net; end Initialize; ------------ -- Adjust -- ------------ overriding procedure Adjust (Self : in out Lk_Node) is begin if Self.Internal.Node /= No_Internal_Node and then Self.Internal.Metadata /= Self.Desc.Null_Metadata then Self.Desc.Node_Metadata_Inc_Ref (Self.Internal.Metadata); end if; end Adjust; -------------- -- Finalize -- -------------- overriding procedure Finalize (Self : in out Lk_Node) is begin if Self.Internal.Node /= No_Internal_Node then if Self.Internal.Metadata /= Self.Desc.Null_Metadata then Self.Desc.Node_Metadata_Dec_Ref (Self.Internal.Metadata); end if; Self.Initialize; end if; end Finalize; ------------------ -- Wrap_Context -- ------------------ function Wrap_Context (Id : Language_Id; Context : Internal_Context) return Lk_Context is begin if Context = No_Internal_Context then return No_Lk_Context; end if; Id.Context_Inc_Ref (Context); return (Ada.Finalization.Controlled with Desc => Id, Internal => Context); end Wrap_Context; -------------------- -- Unwrap_Context -- -------------------- function Unwrap_Context (Context : Lk_Context) return Internal_Context is begin return Context.Internal; end Unwrap_Context; --------------- -- Wrap_Unit -- --------------- function Wrap_Unit (Id : Language_Id; Unit : Internal_Unit) return Lk_Unit is Context : Internal_Context; begin if Unit = No_Internal_Unit then return No_Lk_Unit; end if; Context := Id.Unit_Context (Unit); return (Internal => Unit, Context => Wrap_Context (Id, Context)); end Wrap_Unit; ----------------- -- Unwrap_Unit -- ----------------- function Unwrap_Unit (Unit : Lk_Unit) return Internal_Unit is begin return Unit.Internal; end Unwrap_Unit; --------------- -- Wrap_Node -- --------------- function Wrap_Node (Id : Language_Id; Node : Internal_Entity) return Lk_Node is Context : Internal_Context; Unit : Internal_Unit; begin if Node.Node = No_Internal_Node then return No_Lk_Node; end if; Unit := Id.Node_Unit (Node.Node); Context := Id.Unit_Context (Unit); return (Ada.Finalization.Controlled with Id, Node, Create_Node_Safety_Net (Id, Context, Unit, Node.Rebindings)); end Wrap_Node; ----------------- -- Unwrap_Node -- ----------------- function Unwrap_Node (Node : Lk_Node) return Internal_Entity is begin Check_Safety_Net (Node); return Node.Internal; end Unwrap_Node; ---------------- -- Wrap_Token -- ---------------- function Wrap_Token (Id : Any_Language_Id; Token : Internal_Token; Safety_Net : Token_Safety_Net) return Lk_Token is begin return (Id, Token.TDH, Token.Index, Safety_Net); end Wrap_Token; ------------------ -- Unwrap_Token -- ------------------ procedure Unwrap_Token (Token : Lk_Token; Id : out Any_Language_Id; Data : out Internal_Token; Safety_Net : out Token_Safety_Net) is begin Id := Token.Desc; Data := (Token.TDH, Token.Index); Safety_Net := Token.Safety_Net; end Unwrap_Token; end Gpr_Parser_Support.Generic_API.Analysis;
afrl-rq/OpenUxAS
Ada
974
adb
with Ada.Text_IO; use Ada.Text_IO; package body UxAS.Comms.LMCP_Net_Client.Service.Example_Spark_Service.SPARK with SPARK_Mode is --------------------------- -- Handle_MissionCommand -- --------------------------- procedure Handle_MissionCommand (This : Example_Spark_Service; Command : My_Object_Any; Recognized_Id : out Boolean) is begin if Recognized_VehicleId_From_Previous_AutomationResponse (This, MissionCommand (Deref (Command)).getVehicleID) then Put_Line ("**ExampleSparkService**: Got MissionCommand with VehicleID " & MissionCommand (Deref (Command)).getVehicleID'Image & " previously seen in an AutomationResponse"); Recognized_Id := True; else Recognized_Id := False; end if; end Handle_MissionCommand; end UxAS.Comms.LMCP_Net_Client.Service.Example_Spark_Service.SPARK;
riccardo-bernardini/eugen
Ada
944
ads
with Ada.Tags; package Project_Processor.Parsers.Abstract_Parsers is type Abstract_Parser is interface; function Create (Params : not null access Plugins.Parameter_Maps.Map) return Abstract_Parser is abstract; procedure Parse (Parser : in out Abstract_Parser; Project : out EU_Projects.Projects.Project_Descriptor; Input : String) is abstract; procedure Register (Format : Parser_ID; Tag : Ada.Tags.Tag) with Pre => Ada.Tags.Is_Descendant_At_Same_Level (Descendant => Tag, Ancestor => Abstract_Parser'Tag); function Get_Parser (Format : Parser_ID; Parameters : Parser_Parameter_access) return Abstract_Parser'Class; function Is_Known (Format : Parser_ID) return Boolean; end Project_Processor.Parsers.Abstract_Parsers;
flyx/OpenGLAda
Ada
4,920
adb
-- part of OpenGLAda, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "COPYING" with Ada.Text_IO; with GL.Buffers; use GL.Buffers; with GL.Immediate; use GL.Immediate; with GL.Fixed.Matrix; use GL.Fixed.Matrix; use GL.Fixed; with GL.Fixed.Textures; with GL.Types.Colors; use GL.Types; with GL.Objects.Textures.Targets; with GL.Objects.Renderbuffers; with GL.Objects.Framebuffers; with GL.Pixels; with GL.Toggles; with GL.Window; with GL_Test.Display_Backend; procedure GL_Test.Framebuffers is use GL.Types.Doubles; Target_Texture : GL.Objects.Textures.Texture; begin Display_Backend.Init; Display_Backend.Open_Window (Width => 500, Height => 500); Projection.Load_Identity; Projection.Apply_Orthogonal (-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); -- draw stuff to a texture declare use GL.Objects.Textures.Targets; use type GL.Objects.Framebuffers.Framebuffer_Status; Framebuffer : GL.Objects.Framebuffers.Framebuffer; Depth_Buffer : GL.Objects.Renderbuffers.Renderbuffer; begin Target_Texture.Initialize_Id; Texture_2D.Bind (Target_Texture); Texture_2D.Set_X_Wrapping (GL.Objects.Textures.Repeat); Texture_2D.Set_Y_Wrapping (GL.Objects.Textures.Repeat); Texture_2D.Set_Minifying_Filter (GL.Objects.Textures.Nearest); Texture_2D.Set_Magnifying_Filter (GL.Objects.Textures.Nearest); Texture_2D.Load_Empty_Texture (0, GL.Pixels.RGB8, 256, 256); Framebuffer.Initialize_Id; GL.Objects.Framebuffers.Read_And_Draw_Target.Bind (Framebuffer); GL.Objects.Framebuffers.Read_And_Draw_Target.Attach_Texture (GL.Objects.Framebuffers.Color_Attachment_0, Target_Texture, 0); Depth_Buffer.Initialize_Id; GL.Objects.Renderbuffers.Active_Renderbuffer.Bind (Depth_Buffer); GL.Objects.Renderbuffers.Active_Renderbuffer.Allocate (GL.Pixels.Depth_Component24, 256, 256); GL.Objects.Framebuffers.Read_And_Draw_Target.Attach_Renderbuffer (GL.Objects.Framebuffers.Depth_Attachment, Depth_Buffer); if GL.Objects.Framebuffers.Read_And_Draw_Target.Status /= GL.Objects.Framebuffers.Complete then Ada.Text_IO.Put_Line ("Error: Framebuffer status is " & GL.Objects.Framebuffers.Read_And_Draw_Target.Status'Img); return; end if; GL.Buffers.Set_Active_Buffer (GL.Buffers.Color_Attachment0); GL.Window.Set_Viewport (0, 0, 256, 256); GL.Toggles.Enable (GL.Toggles.Depth_Test); Clear (Buffer_Bits'(others => True)); declare Token : Input_Token := Start (Quads); begin Set_Color (Colors.Color'(1.0, 0.0, 0.0, 1.0)); Token.Add_Vertex (Vector3'(-0.5, -0.5, -0.5)); Token.Add_Vertex (Vector3'(-0.5, 0.25, -0.5)); Token.Add_Vertex (Vector3'(0.25, 0.25, -0.5)); Token.Add_Vertex (Vector3'(0.25, -0.5, -0.5)); Set_Color (Colors.Color'(0.0, 1.0, 0.0, 1.0)); Token.Add_Vertex (Vector3'(0.0, -0.75, 0.5)); Token.Add_Vertex (Vector3'(0.9, -0.75, 0.5)); Token.Add_Vertex (Vector3'(0.9, 0.0, 0.5)); Token.Add_Vertex (Vector3'(0.0, 0.0, 0.5)); Set_Color (Colors.Color'(0.0, 0.0, 1.0, 1.0)); Token.Add_Vertex (Vector3'(-0.25, -0.25, 0.0)); Token.Add_Vertex (Vector3'(-0.25, 0.5, 0.0)); Token.Add_Vertex (Vector3'(0.5, 0.5, 0.0)); Token.Add_Vertex (Vector3'(0.5, -0.25, 0.0)); end; GL.Finish; GL.Objects.Framebuffers.Read_And_Draw_Target.Bind (GL.Objects.Framebuffers.Default_Framebuffer); GL.Objects.Renderbuffers.Active_Renderbuffer.Bind (GL.Objects.Renderbuffers.No_Renderbuffer); end; GL.Window.Set_Viewport (0, 0, 500, 500); while not Display_Backend.Escape_Pressed and Display_Backend.Window_Opened loop Clear (Buffer_Bits'(others => True)); GL.Objects.Textures.Set_Active_Unit (0); GL.Toggles.Enable (GL.Toggles.Texture_2D); -- don't let the color affect the texture rendering GL.Fixed.Textures.Set_Tex_Function (GL.Fixed.Textures.Decal); declare Token : Input_Token := Start (Quads); begin GL.Immediate.Set_Texture_Coordinates (Vector2'(0.0, 0.0)); Token.Add_Vertex (Vector2'(-1.0, -1.0)); GL.Immediate.Set_Texture_Coordinates (Vector2'(1.0, 0.0)); Token.Add_Vertex (Vector2'(1.0, -1.0)); GL.Immediate.Set_Texture_Coordinates (Vector2'(1.0, 1.0)); Token.Add_Vertex (Vector2'(1.0, 1.0)); GL.Immediate.Set_Texture_Coordinates (Vector2'(0.0, 1.0)); Token.Add_Vertex (Vector2'(-1.0, 1.0)); end; GL.Toggles.Disable (GL.Toggles.Texture_2D); GL.Flush; Display_Backend.Swap_Buffers; Display_Backend.Poll_Events; end loop; Display_Backend.Shutdown; end GL_Test.Framebuffers;
Vovanium/Encodings
Ada
295
ads
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1; with Encodings.Line_Endings.Generic_Strip_CR; package Encodings.Line_Endings.Strip_CR is new Generic_Strip_CR( Character_Type => Character, String_Type => String, Carriage_Return => CR, Line_Feed => LF, Coder_Base => Coder_Base );
msrLi/portingSources
Ada
878
ads
-- Copyright 2010-2014 Free Software Foundation, Inc. -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see <http://www.gnu.org/licenses/>. package Pck is procedure Put_Line (S : String); -- Stub implementation of Put_Line to avoid a dependency on Text_IO. -- Does actually nothing. end Pck;
reznikmm/matreshka
Ada
39,886
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ with AMF.CMOF.Associations; with AMF.CMOF.Classes; with AMF.CMOF.Data_Types; with AMF.Factories.UML_Factories; with AMF.Links; with AMF.UML.Abstractions; with AMF.UML.Accept_Call_Actions; with AMF.UML.Accept_Event_Actions; with AMF.UML.Action_Execution_Specifications; with AMF.UML.Action_Input_Pins; with AMF.UML.Activities; with AMF.UML.Activity_Final_Nodes; with AMF.UML.Activity_Parameter_Nodes; with AMF.UML.Activity_Partitions; with AMF.UML.Actors; with AMF.UML.Add_Structural_Feature_Value_Actions; with AMF.UML.Add_Variable_Value_Actions; with AMF.UML.Any_Receive_Events; with AMF.UML.Artifacts; with AMF.UML.Association_Classes; with AMF.UML.Associations; with AMF.UML.Behavior_Execution_Specifications; with AMF.UML.Broadcast_Signal_Actions; with AMF.UML.Call_Behavior_Actions; with AMF.UML.Call_Events; with AMF.UML.Call_Operation_Actions; with AMF.UML.Central_Buffer_Nodes; with AMF.UML.Change_Events; with AMF.UML.Classes; with AMF.UML.Classifier_Template_Parameters; with AMF.UML.Clauses; with AMF.UML.Clear_Association_Actions; with AMF.UML.Clear_Structural_Feature_Actions; with AMF.UML.Clear_Variable_Actions; with AMF.UML.Collaboration_Uses; with AMF.UML.Collaborations; with AMF.UML.Combined_Fragments; with AMF.UML.Comments; with AMF.UML.Communication_Paths; with AMF.UML.Component_Realizations; with AMF.UML.Components; with AMF.UML.Conditional_Nodes; with AMF.UML.Connectable_Element_Template_Parameters; with AMF.UML.Connection_Point_References; with AMF.UML.Connector_Ends; with AMF.UML.Connectors; with AMF.UML.Consider_Ignore_Fragments; with AMF.UML.Constraints; with AMF.UML.Continuations; with AMF.UML.Control_Flows; with AMF.UML.Create_Link_Actions; with AMF.UML.Create_Link_Object_Actions; with AMF.UML.Create_Object_Actions; with AMF.UML.Data_Store_Nodes; with AMF.UML.Data_Types; with AMF.UML.Decision_Nodes; with AMF.UML.Dependencies; with AMF.UML.Deployment_Specifications; with AMF.UML.Deployments; with AMF.UML.Destroy_Link_Actions; with AMF.UML.Destroy_Object_Actions; with AMF.UML.Destruction_Occurrence_Specifications; with AMF.UML.Devices; with AMF.UML.Duration_Constraints; with AMF.UML.Duration_Intervals; with AMF.UML.Duration_Observations; with AMF.UML.Durations; with AMF.UML.Element_Imports; with AMF.UML.Enumeration_Literals; with AMF.UML.Enumerations; with AMF.UML.Exception_Handlers; with AMF.UML.Execution_Environments; with AMF.UML.Execution_Occurrence_Specifications; with AMF.UML.Expansion_Nodes; with AMF.UML.Expansion_Regions; with AMF.UML.Expressions; with AMF.UML.Extends; with AMF.UML.Extension_Ends; with AMF.UML.Extension_Points; with AMF.UML.Extensions; with AMF.UML.Final_States; with AMF.UML.Flow_Final_Nodes; with AMF.UML.Fork_Nodes; with AMF.UML.Function_Behaviors; with AMF.UML.Gates; with AMF.UML.General_Orderings; with AMF.UML.Generalization_Sets; with AMF.UML.Generalizations; with AMF.UML.Images; with AMF.UML.Includes; with AMF.UML.Information_Flows; with AMF.UML.Information_Items; with AMF.UML.Initial_Nodes; with AMF.UML.Input_Pins; with AMF.UML.Instance_Specifications; with AMF.UML.Instance_Values; with AMF.UML.Interaction_Constraints; with AMF.UML.Interaction_Operands; with AMF.UML.Interaction_Uses; with AMF.UML.Interactions; with AMF.UML.Interface_Realizations; with AMF.UML.Interfaces; with AMF.UML.Interruptible_Activity_Regions; with AMF.UML.Interval_Constraints; with AMF.UML.Intervals; with AMF.UML.Join_Nodes; with AMF.UML.Lifelines; with AMF.UML.Link_End_Creation_Datas; with AMF.UML.Link_End_Datas; with AMF.UML.Link_End_Destruction_Datas; with AMF.UML.Literal_Booleans; with AMF.UML.Literal_Integers; with AMF.UML.Literal_Nulls; with AMF.UML.Literal_Reals; with AMF.UML.Literal_Strings; with AMF.UML.Literal_Unlimited_Naturals; with AMF.UML.Loop_Nodes; with AMF.UML.Manifestations; with AMF.UML.Merge_Nodes; with AMF.UML.Message_Occurrence_Specifications; with AMF.UML.Messages; with AMF.UML.Models; with AMF.UML.Nodes; with AMF.UML.Object_Flows; with AMF.UML.Occurrence_Specifications; with AMF.UML.Opaque_Actions; with AMF.UML.Opaque_Behaviors; with AMF.UML.Opaque_Expressions; with AMF.UML.Operation_Template_Parameters; with AMF.UML.Operations; with AMF.UML.Output_Pins; with AMF.UML.Package_Imports; with AMF.UML.Package_Merges; with AMF.UML.Packages; with AMF.UML.Parameter_Sets; with AMF.UML.Parameters; with AMF.UML.Part_Decompositions; with AMF.UML.Ports; with AMF.UML.Primitive_Types; with AMF.UML.Profile_Applications; with AMF.UML.Profiles; with AMF.UML.Properties; with AMF.UML.Protocol_Conformances; with AMF.UML.Protocol_State_Machines; with AMF.UML.Protocol_Transitions; with AMF.UML.Pseudostates; with AMF.UML.Qualifier_Values; with AMF.UML.Raise_Exception_Actions; with AMF.UML.Read_Extent_Actions; with AMF.UML.Read_Is_Classified_Object_Actions; with AMF.UML.Read_Link_Actions; with AMF.UML.Read_Link_Object_End_Actions; with AMF.UML.Read_Link_Object_End_Qualifier_Actions; with AMF.UML.Read_Self_Actions; with AMF.UML.Read_Structural_Feature_Actions; with AMF.UML.Read_Variable_Actions; with AMF.UML.Realizations; with AMF.UML.Receptions; with AMF.UML.Reclassify_Object_Actions; with AMF.UML.Redefinable_Template_Signatures; with AMF.UML.Reduce_Actions; with AMF.UML.Regions; with AMF.UML.Remove_Structural_Feature_Value_Actions; with AMF.UML.Remove_Variable_Value_Actions; with AMF.UML.Reply_Actions; with AMF.UML.Send_Object_Actions; with AMF.UML.Send_Signal_Actions; with AMF.UML.Sequence_Nodes; with AMF.UML.Signal_Events; with AMF.UML.Signals; with AMF.UML.Slots; with AMF.UML.Start_Classifier_Behavior_Actions; with AMF.UML.Start_Object_Behavior_Actions; with AMF.UML.State_Invariants; with AMF.UML.State_Machines; with AMF.UML.States; with AMF.UML.Stereotypes; with AMF.UML.String_Expressions; with AMF.UML.Structured_Activity_Nodes; with AMF.UML.Substitutions; with AMF.UML.Template_Bindings; with AMF.UML.Template_Parameter_Substitutions; with AMF.UML.Template_Parameters; with AMF.UML.Template_Signatures; with AMF.UML.Test_Identity_Actions; with AMF.UML.Time_Constraints; with AMF.UML.Time_Events; with AMF.UML.Time_Expressions; with AMF.UML.Time_Intervals; with AMF.UML.Time_Observations; with AMF.UML.Transitions; with AMF.UML.Triggers; with AMF.UML.Unmarshall_Actions; with AMF.UML.Usages; with AMF.UML.Use_Cases; with AMF.UML.Value_Pins; with AMF.UML.Value_Specification_Actions; with AMF.UML.Variables; with League.Holders; package AMF.Internals.Factories.UML_Factories is type UML_Factory is limited new AMF.Internals.Factories.Metamodel_Factory_Base and AMF.Factories.UML_Factories.UML_Factory with null record; overriding function Convert_To_String (Self : not null access UML_Factory; Data_Type : not null access AMF.CMOF.Data_Types.CMOF_Data_Type'Class; Value : League.Holders.Holder) return League.Strings.Universal_String; overriding function Create (Self : not null access UML_Factory; Meta_Class : not null access AMF.CMOF.Classes.CMOF_Class'Class) return not null AMF.Elements.Element_Access; overriding function Create_From_String (Self : not null access UML_Factory; Data_Type : not null access AMF.CMOF.Data_Types.CMOF_Data_Type'Class; Image : League.Strings.Universal_String) return League.Holders.Holder; overriding function Create_Link (Self : not null access UML_Factory; Association : not null access AMF.CMOF.Associations.CMOF_Association'Class; First_Element : not null AMF.Elements.Element_Access; Second_Element : not null AMF.Elements.Element_Access) return not null AMF.Links.Link_Access; overriding function Get_Package (Self : not null access constant UML_Factory) return AMF.CMOF.Packages.Collections.Set_Of_CMOF_Package; function Constructor (Extent : AMF.Internals.AMF_Extent) return not null AMF.Factories.Factory_Access; function Get_Package return not null AMF.CMOF.Packages.CMOF_Package_Access; function Create_Abstraction (Self : not null access UML_Factory) return AMF.UML.Abstractions.UML_Abstraction_Access; function Create_Accept_Call_Action (Self : not null access UML_Factory) return AMF.UML.Accept_Call_Actions.UML_Accept_Call_Action_Access; function Create_Accept_Event_Action (Self : not null access UML_Factory) return AMF.UML.Accept_Event_Actions.UML_Accept_Event_Action_Access; function Create_Action_Execution_Specification (Self : not null access UML_Factory) return AMF.UML.Action_Execution_Specifications.UML_Action_Execution_Specification_Access; function Create_Action_Input_Pin (Self : not null access UML_Factory) return AMF.UML.Action_Input_Pins.UML_Action_Input_Pin_Access; function Create_Activity (Self : not null access UML_Factory) return AMF.UML.Activities.UML_Activity_Access; function Create_Activity_Final_Node (Self : not null access UML_Factory) return AMF.UML.Activity_Final_Nodes.UML_Activity_Final_Node_Access; function Create_Activity_Parameter_Node (Self : not null access UML_Factory) return AMF.UML.Activity_Parameter_Nodes.UML_Activity_Parameter_Node_Access; function Create_Activity_Partition (Self : not null access UML_Factory) return AMF.UML.Activity_Partitions.UML_Activity_Partition_Access; function Create_Actor (Self : not null access UML_Factory) return AMF.UML.Actors.UML_Actor_Access; function Create_Add_Structural_Feature_Value_Action (Self : not null access UML_Factory) return AMF.UML.Add_Structural_Feature_Value_Actions.UML_Add_Structural_Feature_Value_Action_Access; function Create_Add_Variable_Value_Action (Self : not null access UML_Factory) return AMF.UML.Add_Variable_Value_Actions.UML_Add_Variable_Value_Action_Access; function Create_Any_Receive_Event (Self : not null access UML_Factory) return AMF.UML.Any_Receive_Events.UML_Any_Receive_Event_Access; function Create_Artifact (Self : not null access UML_Factory) return AMF.UML.Artifacts.UML_Artifact_Access; function Create_Association (Self : not null access UML_Factory) return AMF.UML.Associations.UML_Association_Access; function Create_Association_Class (Self : not null access UML_Factory) return AMF.UML.Association_Classes.UML_Association_Class_Access; function Create_Behavior_Execution_Specification (Self : not null access UML_Factory) return AMF.UML.Behavior_Execution_Specifications.UML_Behavior_Execution_Specification_Access; function Create_Broadcast_Signal_Action (Self : not null access UML_Factory) return AMF.UML.Broadcast_Signal_Actions.UML_Broadcast_Signal_Action_Access; function Create_Call_Behavior_Action (Self : not null access UML_Factory) return AMF.UML.Call_Behavior_Actions.UML_Call_Behavior_Action_Access; function Create_Call_Event (Self : not null access UML_Factory) return AMF.UML.Call_Events.UML_Call_Event_Access; function Create_Call_Operation_Action (Self : not null access UML_Factory) return AMF.UML.Call_Operation_Actions.UML_Call_Operation_Action_Access; function Create_Central_Buffer_Node (Self : not null access UML_Factory) return AMF.UML.Central_Buffer_Nodes.UML_Central_Buffer_Node_Access; function Create_Change_Event (Self : not null access UML_Factory) return AMF.UML.Change_Events.UML_Change_Event_Access; function Create_Class (Self : not null access UML_Factory) return AMF.UML.Classes.UML_Class_Access; function Create_Classifier_Template_Parameter (Self : not null access UML_Factory) return AMF.UML.Classifier_Template_Parameters.UML_Classifier_Template_Parameter_Access; function Create_Clause (Self : not null access UML_Factory) return AMF.UML.Clauses.UML_Clause_Access; function Create_Clear_Association_Action (Self : not null access UML_Factory) return AMF.UML.Clear_Association_Actions.UML_Clear_Association_Action_Access; function Create_Clear_Structural_Feature_Action (Self : not null access UML_Factory) return AMF.UML.Clear_Structural_Feature_Actions.UML_Clear_Structural_Feature_Action_Access; function Create_Clear_Variable_Action (Self : not null access UML_Factory) return AMF.UML.Clear_Variable_Actions.UML_Clear_Variable_Action_Access; function Create_Collaboration (Self : not null access UML_Factory) return AMF.UML.Collaborations.UML_Collaboration_Access; function Create_Collaboration_Use (Self : not null access UML_Factory) return AMF.UML.Collaboration_Uses.UML_Collaboration_Use_Access; function Create_Combined_Fragment (Self : not null access UML_Factory) return AMF.UML.Combined_Fragments.UML_Combined_Fragment_Access; function Create_Comment (Self : not null access UML_Factory) return AMF.UML.Comments.UML_Comment_Access; function Create_Communication_Path (Self : not null access UML_Factory) return AMF.UML.Communication_Paths.UML_Communication_Path_Access; function Create_Component (Self : not null access UML_Factory) return AMF.UML.Components.UML_Component_Access; function Create_Component_Realization (Self : not null access UML_Factory) return AMF.UML.Component_Realizations.UML_Component_Realization_Access; function Create_Conditional_Node (Self : not null access UML_Factory) return AMF.UML.Conditional_Nodes.UML_Conditional_Node_Access; function Create_Connectable_Element_Template_Parameter (Self : not null access UML_Factory) return AMF.UML.Connectable_Element_Template_Parameters.UML_Connectable_Element_Template_Parameter_Access; function Create_Connection_Point_Reference (Self : not null access UML_Factory) return AMF.UML.Connection_Point_References.UML_Connection_Point_Reference_Access; function Create_Connector (Self : not null access UML_Factory) return AMF.UML.Connectors.UML_Connector_Access; function Create_Connector_End (Self : not null access UML_Factory) return AMF.UML.Connector_Ends.UML_Connector_End_Access; function Create_Consider_Ignore_Fragment (Self : not null access UML_Factory) return AMF.UML.Consider_Ignore_Fragments.UML_Consider_Ignore_Fragment_Access; function Create_Constraint (Self : not null access UML_Factory) return AMF.UML.Constraints.UML_Constraint_Access; function Create_Continuation (Self : not null access UML_Factory) return AMF.UML.Continuations.UML_Continuation_Access; function Create_Control_Flow (Self : not null access UML_Factory) return AMF.UML.Control_Flows.UML_Control_Flow_Access; function Create_Create_Link_Action (Self : not null access UML_Factory) return AMF.UML.Create_Link_Actions.UML_Create_Link_Action_Access; function Create_Create_Link_Object_Action (Self : not null access UML_Factory) return AMF.UML.Create_Link_Object_Actions.UML_Create_Link_Object_Action_Access; function Create_Create_Object_Action (Self : not null access UML_Factory) return AMF.UML.Create_Object_Actions.UML_Create_Object_Action_Access; function Create_Data_Store_Node (Self : not null access UML_Factory) return AMF.UML.Data_Store_Nodes.UML_Data_Store_Node_Access; function Create_Data_Type (Self : not null access UML_Factory) return AMF.UML.Data_Types.UML_Data_Type_Access; function Create_Decision_Node (Self : not null access UML_Factory) return AMF.UML.Decision_Nodes.UML_Decision_Node_Access; function Create_Dependency (Self : not null access UML_Factory) return AMF.UML.Dependencies.UML_Dependency_Access; function Create_Deployment (Self : not null access UML_Factory) return AMF.UML.Deployments.UML_Deployment_Access; function Create_Deployment_Specification (Self : not null access UML_Factory) return AMF.UML.Deployment_Specifications.UML_Deployment_Specification_Access; function Create_Destroy_Link_Action (Self : not null access UML_Factory) return AMF.UML.Destroy_Link_Actions.UML_Destroy_Link_Action_Access; function Create_Destroy_Object_Action (Self : not null access UML_Factory) return AMF.UML.Destroy_Object_Actions.UML_Destroy_Object_Action_Access; function Create_Destruction_Occurrence_Specification (Self : not null access UML_Factory) return AMF.UML.Destruction_Occurrence_Specifications.UML_Destruction_Occurrence_Specification_Access; function Create_Device (Self : not null access UML_Factory) return AMF.UML.Devices.UML_Device_Access; function Create_Duration (Self : not null access UML_Factory) return AMF.UML.Durations.UML_Duration_Access; function Create_Duration_Constraint (Self : not null access UML_Factory) return AMF.UML.Duration_Constraints.UML_Duration_Constraint_Access; function Create_Duration_Interval (Self : not null access UML_Factory) return AMF.UML.Duration_Intervals.UML_Duration_Interval_Access; function Create_Duration_Observation (Self : not null access UML_Factory) return AMF.UML.Duration_Observations.UML_Duration_Observation_Access; function Create_Element_Import (Self : not null access UML_Factory) return AMF.UML.Element_Imports.UML_Element_Import_Access; function Create_Enumeration (Self : not null access UML_Factory) return AMF.UML.Enumerations.UML_Enumeration_Access; function Create_Enumeration_Literal (Self : not null access UML_Factory) return AMF.UML.Enumeration_Literals.UML_Enumeration_Literal_Access; function Create_Exception_Handler (Self : not null access UML_Factory) return AMF.UML.Exception_Handlers.UML_Exception_Handler_Access; function Create_Execution_Environment (Self : not null access UML_Factory) return AMF.UML.Execution_Environments.UML_Execution_Environment_Access; function Create_Execution_Occurrence_Specification (Self : not null access UML_Factory) return AMF.UML.Execution_Occurrence_Specifications.UML_Execution_Occurrence_Specification_Access; function Create_Expansion_Node (Self : not null access UML_Factory) return AMF.UML.Expansion_Nodes.UML_Expansion_Node_Access; function Create_Expansion_Region (Self : not null access UML_Factory) return AMF.UML.Expansion_Regions.UML_Expansion_Region_Access; function Create_Expression (Self : not null access UML_Factory) return AMF.UML.Expressions.UML_Expression_Access; function Create_Extend (Self : not null access UML_Factory) return AMF.UML.Extends.UML_Extend_Access; function Create_Extension (Self : not null access UML_Factory) return AMF.UML.Extensions.UML_Extension_Access; function Create_Extension_End (Self : not null access UML_Factory) return AMF.UML.Extension_Ends.UML_Extension_End_Access; function Create_Extension_Point (Self : not null access UML_Factory) return AMF.UML.Extension_Points.UML_Extension_Point_Access; function Create_Final_State (Self : not null access UML_Factory) return AMF.UML.Final_States.UML_Final_State_Access; function Create_Flow_Final_Node (Self : not null access UML_Factory) return AMF.UML.Flow_Final_Nodes.UML_Flow_Final_Node_Access; function Create_Fork_Node (Self : not null access UML_Factory) return AMF.UML.Fork_Nodes.UML_Fork_Node_Access; function Create_Function_Behavior (Self : not null access UML_Factory) return AMF.UML.Function_Behaviors.UML_Function_Behavior_Access; function Create_Gate (Self : not null access UML_Factory) return AMF.UML.Gates.UML_Gate_Access; function Create_General_Ordering (Self : not null access UML_Factory) return AMF.UML.General_Orderings.UML_General_Ordering_Access; function Create_Generalization (Self : not null access UML_Factory) return AMF.UML.Generalizations.UML_Generalization_Access; function Create_Generalization_Set (Self : not null access UML_Factory) return AMF.UML.Generalization_Sets.UML_Generalization_Set_Access; function Create_Image (Self : not null access UML_Factory) return AMF.UML.Images.UML_Image_Access; function Create_Include (Self : not null access UML_Factory) return AMF.UML.Includes.UML_Include_Access; function Create_Information_Flow (Self : not null access UML_Factory) return AMF.UML.Information_Flows.UML_Information_Flow_Access; function Create_Information_Item (Self : not null access UML_Factory) return AMF.UML.Information_Items.UML_Information_Item_Access; function Create_Initial_Node (Self : not null access UML_Factory) return AMF.UML.Initial_Nodes.UML_Initial_Node_Access; function Create_Input_Pin (Self : not null access UML_Factory) return AMF.UML.Input_Pins.UML_Input_Pin_Access; function Create_Instance_Specification (Self : not null access UML_Factory) return AMF.UML.Instance_Specifications.UML_Instance_Specification_Access; function Create_Instance_Value (Self : not null access UML_Factory) return AMF.UML.Instance_Values.UML_Instance_Value_Access; function Create_Interaction (Self : not null access UML_Factory) return AMF.UML.Interactions.UML_Interaction_Access; function Create_Interaction_Constraint (Self : not null access UML_Factory) return AMF.UML.Interaction_Constraints.UML_Interaction_Constraint_Access; function Create_Interaction_Operand (Self : not null access UML_Factory) return AMF.UML.Interaction_Operands.UML_Interaction_Operand_Access; function Create_Interaction_Use (Self : not null access UML_Factory) return AMF.UML.Interaction_Uses.UML_Interaction_Use_Access; function Create_Interface (Self : not null access UML_Factory) return AMF.UML.Interfaces.UML_Interface_Access; function Create_Interface_Realization (Self : not null access UML_Factory) return AMF.UML.Interface_Realizations.UML_Interface_Realization_Access; function Create_Interruptible_Activity_Region (Self : not null access UML_Factory) return AMF.UML.Interruptible_Activity_Regions.UML_Interruptible_Activity_Region_Access; function Create_Interval (Self : not null access UML_Factory) return AMF.UML.Intervals.UML_Interval_Access; function Create_Interval_Constraint (Self : not null access UML_Factory) return AMF.UML.Interval_Constraints.UML_Interval_Constraint_Access; function Create_Join_Node (Self : not null access UML_Factory) return AMF.UML.Join_Nodes.UML_Join_Node_Access; function Create_Lifeline (Self : not null access UML_Factory) return AMF.UML.Lifelines.UML_Lifeline_Access; function Create_Link_End_Creation_Data (Self : not null access UML_Factory) return AMF.UML.Link_End_Creation_Datas.UML_Link_End_Creation_Data_Access; function Create_Link_End_Data (Self : not null access UML_Factory) return AMF.UML.Link_End_Datas.UML_Link_End_Data_Access; function Create_Link_End_Destruction_Data (Self : not null access UML_Factory) return AMF.UML.Link_End_Destruction_Datas.UML_Link_End_Destruction_Data_Access; function Create_Literal_Boolean (Self : not null access UML_Factory) return AMF.UML.Literal_Booleans.UML_Literal_Boolean_Access; function Create_Literal_Integer (Self : not null access UML_Factory) return AMF.UML.Literal_Integers.UML_Literal_Integer_Access; function Create_Literal_Null (Self : not null access UML_Factory) return AMF.UML.Literal_Nulls.UML_Literal_Null_Access; function Create_Literal_Real (Self : not null access UML_Factory) return AMF.UML.Literal_Reals.UML_Literal_Real_Access; function Create_Literal_String (Self : not null access UML_Factory) return AMF.UML.Literal_Strings.UML_Literal_String_Access; function Create_Literal_Unlimited_Natural (Self : not null access UML_Factory) return AMF.UML.Literal_Unlimited_Naturals.UML_Literal_Unlimited_Natural_Access; function Create_Loop_Node (Self : not null access UML_Factory) return AMF.UML.Loop_Nodes.UML_Loop_Node_Access; function Create_Manifestation (Self : not null access UML_Factory) return AMF.UML.Manifestations.UML_Manifestation_Access; function Create_Merge_Node (Self : not null access UML_Factory) return AMF.UML.Merge_Nodes.UML_Merge_Node_Access; function Create_Message (Self : not null access UML_Factory) return AMF.UML.Messages.UML_Message_Access; function Create_Message_Occurrence_Specification (Self : not null access UML_Factory) return AMF.UML.Message_Occurrence_Specifications.UML_Message_Occurrence_Specification_Access; function Create_Model (Self : not null access UML_Factory) return AMF.UML.Models.UML_Model_Access; function Create_Node (Self : not null access UML_Factory) return AMF.UML.Nodes.UML_Node_Access; function Create_Object_Flow (Self : not null access UML_Factory) return AMF.UML.Object_Flows.UML_Object_Flow_Access; function Create_Occurrence_Specification (Self : not null access UML_Factory) return AMF.UML.Occurrence_Specifications.UML_Occurrence_Specification_Access; function Create_Opaque_Action (Self : not null access UML_Factory) return AMF.UML.Opaque_Actions.UML_Opaque_Action_Access; function Create_Opaque_Behavior (Self : not null access UML_Factory) return AMF.UML.Opaque_Behaviors.UML_Opaque_Behavior_Access; function Create_Opaque_Expression (Self : not null access UML_Factory) return AMF.UML.Opaque_Expressions.UML_Opaque_Expression_Access; function Create_Operation (Self : not null access UML_Factory) return AMF.UML.Operations.UML_Operation_Access; function Create_Operation_Template_Parameter (Self : not null access UML_Factory) return AMF.UML.Operation_Template_Parameters.UML_Operation_Template_Parameter_Access; function Create_Output_Pin (Self : not null access UML_Factory) return AMF.UML.Output_Pins.UML_Output_Pin_Access; function Create_Package (Self : not null access UML_Factory) return AMF.UML.Packages.UML_Package_Access; function Create_Package_Import (Self : not null access UML_Factory) return AMF.UML.Package_Imports.UML_Package_Import_Access; function Create_Package_Merge (Self : not null access UML_Factory) return AMF.UML.Package_Merges.UML_Package_Merge_Access; function Create_Parameter (Self : not null access UML_Factory) return AMF.UML.Parameters.UML_Parameter_Access; function Create_Parameter_Set (Self : not null access UML_Factory) return AMF.UML.Parameter_Sets.UML_Parameter_Set_Access; function Create_Part_Decomposition (Self : not null access UML_Factory) return AMF.UML.Part_Decompositions.UML_Part_Decomposition_Access; function Create_Port (Self : not null access UML_Factory) return AMF.UML.Ports.UML_Port_Access; function Create_Primitive_Type (Self : not null access UML_Factory) return AMF.UML.Primitive_Types.UML_Primitive_Type_Access; function Create_Profile (Self : not null access UML_Factory) return AMF.UML.Profiles.UML_Profile_Access; function Create_Profile_Application (Self : not null access UML_Factory) return AMF.UML.Profile_Applications.UML_Profile_Application_Access; function Create_Property (Self : not null access UML_Factory) return AMF.UML.Properties.UML_Property_Access; function Create_Protocol_Conformance (Self : not null access UML_Factory) return AMF.UML.Protocol_Conformances.UML_Protocol_Conformance_Access; function Create_Protocol_State_Machine (Self : not null access UML_Factory) return AMF.UML.Protocol_State_Machines.UML_Protocol_State_Machine_Access; function Create_Protocol_Transition (Self : not null access UML_Factory) return AMF.UML.Protocol_Transitions.UML_Protocol_Transition_Access; function Create_Pseudostate (Self : not null access UML_Factory) return AMF.UML.Pseudostates.UML_Pseudostate_Access; function Create_Qualifier_Value (Self : not null access UML_Factory) return AMF.UML.Qualifier_Values.UML_Qualifier_Value_Access; function Create_Raise_Exception_Action (Self : not null access UML_Factory) return AMF.UML.Raise_Exception_Actions.UML_Raise_Exception_Action_Access; function Create_Read_Extent_Action (Self : not null access UML_Factory) return AMF.UML.Read_Extent_Actions.UML_Read_Extent_Action_Access; function Create_Read_Is_Classified_Object_Action (Self : not null access UML_Factory) return AMF.UML.Read_Is_Classified_Object_Actions.UML_Read_Is_Classified_Object_Action_Access; function Create_Read_Link_Action (Self : not null access UML_Factory) return AMF.UML.Read_Link_Actions.UML_Read_Link_Action_Access; function Create_Read_Link_Object_End_Action (Self : not null access UML_Factory) return AMF.UML.Read_Link_Object_End_Actions.UML_Read_Link_Object_End_Action_Access; function Create_Read_Link_Object_End_Qualifier_Action (Self : not null access UML_Factory) return AMF.UML.Read_Link_Object_End_Qualifier_Actions.UML_Read_Link_Object_End_Qualifier_Action_Access; function Create_Read_Self_Action (Self : not null access UML_Factory) return AMF.UML.Read_Self_Actions.UML_Read_Self_Action_Access; function Create_Read_Structural_Feature_Action (Self : not null access UML_Factory) return AMF.UML.Read_Structural_Feature_Actions.UML_Read_Structural_Feature_Action_Access; function Create_Read_Variable_Action (Self : not null access UML_Factory) return AMF.UML.Read_Variable_Actions.UML_Read_Variable_Action_Access; function Create_Realization (Self : not null access UML_Factory) return AMF.UML.Realizations.UML_Realization_Access; function Create_Reception (Self : not null access UML_Factory) return AMF.UML.Receptions.UML_Reception_Access; function Create_Reclassify_Object_Action (Self : not null access UML_Factory) return AMF.UML.Reclassify_Object_Actions.UML_Reclassify_Object_Action_Access; function Create_Redefinable_Template_Signature (Self : not null access UML_Factory) return AMF.UML.Redefinable_Template_Signatures.UML_Redefinable_Template_Signature_Access; function Create_Reduce_Action (Self : not null access UML_Factory) return AMF.UML.Reduce_Actions.UML_Reduce_Action_Access; function Create_Region (Self : not null access UML_Factory) return AMF.UML.Regions.UML_Region_Access; function Create_Remove_Structural_Feature_Value_Action (Self : not null access UML_Factory) return AMF.UML.Remove_Structural_Feature_Value_Actions.UML_Remove_Structural_Feature_Value_Action_Access; function Create_Remove_Variable_Value_Action (Self : not null access UML_Factory) return AMF.UML.Remove_Variable_Value_Actions.UML_Remove_Variable_Value_Action_Access; function Create_Reply_Action (Self : not null access UML_Factory) return AMF.UML.Reply_Actions.UML_Reply_Action_Access; function Create_Send_Object_Action (Self : not null access UML_Factory) return AMF.UML.Send_Object_Actions.UML_Send_Object_Action_Access; function Create_Send_Signal_Action (Self : not null access UML_Factory) return AMF.UML.Send_Signal_Actions.UML_Send_Signal_Action_Access; function Create_Sequence_Node (Self : not null access UML_Factory) return AMF.UML.Sequence_Nodes.UML_Sequence_Node_Access; function Create_Signal (Self : not null access UML_Factory) return AMF.UML.Signals.UML_Signal_Access; function Create_Signal_Event (Self : not null access UML_Factory) return AMF.UML.Signal_Events.UML_Signal_Event_Access; function Create_Slot (Self : not null access UML_Factory) return AMF.UML.Slots.UML_Slot_Access; function Create_Start_Classifier_Behavior_Action (Self : not null access UML_Factory) return AMF.UML.Start_Classifier_Behavior_Actions.UML_Start_Classifier_Behavior_Action_Access; function Create_Start_Object_Behavior_Action (Self : not null access UML_Factory) return AMF.UML.Start_Object_Behavior_Actions.UML_Start_Object_Behavior_Action_Access; function Create_State (Self : not null access UML_Factory) return AMF.UML.States.UML_State_Access; function Create_State_Invariant (Self : not null access UML_Factory) return AMF.UML.State_Invariants.UML_State_Invariant_Access; function Create_State_Machine (Self : not null access UML_Factory) return AMF.UML.State_Machines.UML_State_Machine_Access; function Create_Stereotype (Self : not null access UML_Factory) return AMF.UML.Stereotypes.UML_Stereotype_Access; function Create_String_Expression (Self : not null access UML_Factory) return AMF.UML.String_Expressions.UML_String_Expression_Access; function Create_Structured_Activity_Node (Self : not null access UML_Factory) return AMF.UML.Structured_Activity_Nodes.UML_Structured_Activity_Node_Access; function Create_Substitution (Self : not null access UML_Factory) return AMF.UML.Substitutions.UML_Substitution_Access; function Create_Template_Binding (Self : not null access UML_Factory) return AMF.UML.Template_Bindings.UML_Template_Binding_Access; function Create_Template_Parameter (Self : not null access UML_Factory) return AMF.UML.Template_Parameters.UML_Template_Parameter_Access; function Create_Template_Parameter_Substitution (Self : not null access UML_Factory) return AMF.UML.Template_Parameter_Substitutions.UML_Template_Parameter_Substitution_Access; function Create_Template_Signature (Self : not null access UML_Factory) return AMF.UML.Template_Signatures.UML_Template_Signature_Access; function Create_Test_Identity_Action (Self : not null access UML_Factory) return AMF.UML.Test_Identity_Actions.UML_Test_Identity_Action_Access; function Create_Time_Constraint (Self : not null access UML_Factory) return AMF.UML.Time_Constraints.UML_Time_Constraint_Access; function Create_Time_Event (Self : not null access UML_Factory) return AMF.UML.Time_Events.UML_Time_Event_Access; function Create_Time_Expression (Self : not null access UML_Factory) return AMF.UML.Time_Expressions.UML_Time_Expression_Access; function Create_Time_Interval (Self : not null access UML_Factory) return AMF.UML.Time_Intervals.UML_Time_Interval_Access; function Create_Time_Observation (Self : not null access UML_Factory) return AMF.UML.Time_Observations.UML_Time_Observation_Access; function Create_Transition (Self : not null access UML_Factory) return AMF.UML.Transitions.UML_Transition_Access; function Create_Trigger (Self : not null access UML_Factory) return AMF.UML.Triggers.UML_Trigger_Access; function Create_Unmarshall_Action (Self : not null access UML_Factory) return AMF.UML.Unmarshall_Actions.UML_Unmarshall_Action_Access; function Create_Usage (Self : not null access UML_Factory) return AMF.UML.Usages.UML_Usage_Access; function Create_Use_Case (Self : not null access UML_Factory) return AMF.UML.Use_Cases.UML_Use_Case_Access; function Create_Value_Pin (Self : not null access UML_Factory) return AMF.UML.Value_Pins.UML_Value_Pin_Access; function Create_Value_Specification_Action (Self : not null access UML_Factory) return AMF.UML.Value_Specification_Actions.UML_Value_Specification_Action_Access; function Create_Variable (Self : not null access UML_Factory) return AMF.UML.Variables.UML_Variable_Access; end AMF.Internals.Factories.UML_Factories;
jhumphry/PRNG_Zoo
Ada
13,288
adb
-- -- PRNG Zoo -- Copyright (c) 2014 - 2015, James Humphry -- -- 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. -- Includes material derived from mt19937ar.c: -- Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, -- All rights reserved. -- Includes material derived from mt19937-64.c: -- Copyright (C) 2004, Makoto Matsumoto and Takuji Nishimura, -- All rights reserved. -- The copyright conditions notice of both follows: -- -- 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. The names of its contributors 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 OWNER OR -- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- Includes material derived from tinymt64.h and tinymt64.c: -- Copyright (C) 2011, 2013 Mutsuo Saito, Makoto Matsumoto, -- Hiroshima University and The University of Tokyo. -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are -- met: -- -- * Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- * Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials provided -- with the distribution. -- * Neither the name of the Hiroshima University nor the names of -- its contributors may be used to endorse or promote products -- derived from this software without specific prior written -- permission. -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package body PRNG_Zoo.MT is -- Mersenne Twister constants N : constant := 624; M : constant := 397; MATRIX_A : constant U32 := 16#9908B0DF#; UPPER_MASK : constant U32 := 16#80000000#; LOWER_MASK : constant U32 := 16#7FFFFFFF#; -- Mersenne Twister 64-bit constants NN : constant := 312; MM : constant := 156; MATRIX_A_64 : constant U64 := 16#B5026F5AA96619E9#; UM : constant U64 := 16#FFFFFFFF80000000#; LM : constant U64 := 16#7FFFFFFF#; -- TinyMT 64-bit constants TINYMT64_MEXP : constant := 127; TINYMT64_SH0 : constant := 12; TINYMT64_SH1 : constant := 11; TINYMT64_SH8 : constant := 8; TINYMT64_MASK : constant U64 := 16#7fffffffffffffff#; MIN_LOOP : constant := 8; pragma Unreferenced(TINYMT64_MEXP); ----------- -- Reset -- ----------- procedure Reset (G: in out MT19937; S: in U64) is begin G.s(0) := U32(S and 16#FFFFFFFF#); G.p := 0; for I in MT_Index range 1..MT_Index(N-1) loop G.s(I) := 1812433253 * (G.s(I-1) xor Shift_Right(G.s(I-1), 30)) + U32(I); end loop; end Reset; procedure Reset (G: in out MT19937; S: in U64_array) is key : constant U64_array(0..S'Length-1) := S; i : MT_Index; j : Integer; begin Reset(G, U64(19650218)); i := 1; j := 0; for k in reverse 1..(if N > key'Length then N else key'Length) loop G.s(i) := (G.s(i) xor ((G.s(i-1) xor Shift_Right(G.s(i-1), 30)) * 1664525)) + U32(key(j) and 16#FFFFFFFF#) + U32(j); i := i + 1; j := (j + 1) mod key'Length; if i=0 then G.s(0) := G.s(MT_Index(N-1)); i := 1; end if; end loop; for k in reverse 1..MT_Index(N-1) loop G.s(i) := (G.s(i) xor ((G.s(i-1) xor Shift_Right(G.s(i-1), 30)) * 1566083941)) - U32(i); i := i + 1; if i=0 then G.s(0) := G.s(MT_Index(N-1)); i := 1; end if; end loop; G.s(0) := 16#80000000#; end Reset; -------------- -- Generate -- -------------- function Generate (G: in out MT19937) return U32 is y : U32; begin if G.p = 0 then for I in MT_Index'Range loop y := (G.s(I) and UPPER_MASK) or (G.s(I+1) and LOWER_MASK); G.s(I) := G.s(I+M) xor Shift_Right(y, 1); if (y mod 2) = 1 then G.s(I) := G.s(I) xor MATRIX_A; end if; end loop; end if; y := G.s(G.p); y := y xor Shift_Right(y, 11); y := y xor (Shift_Left(y, 7) and 16#9d2c5680#); y := y xor (Shift_Left(y, 15) and 16#efc60000#); y := y xor Shift_Right(y, 18); G.p := G.p + 1; return y; end Generate; ----------- -- Reset -- ----------- procedure Reset (G: in out MT19937_64; S: in U64) is begin G.s(0) := S; G.p := 0; for I in MT_Index_64 range 1..MT_Index_64(NN-1) loop G.s(I) := 6364136223846793005 * (G.s(I-1) xor Shift_Right(G.s(I-1), 62)) + U64(I); end loop; end Reset; procedure Reset (G: in out MT19937_64; S: in U64_array) is key : constant U64_array(0..S'Length-1) := S; i : MT_Index_64; j : Integer; begin Reset(G, U64(19650218)); i := 1; j := 0; for k in reverse 1..(if NN > key'Length then NN else key'Length) loop G.s(i) := (G.s(i) xor ((G.s(i-1) xor Shift_Right(G.s(i-1), 62)) * 3935559000370003845)) + key(j) + U64(j); i := i + 1; j := (j + 1) mod key'Length; if i=0 then G.s(0) := G.s(MT_Index_64(NN-1)); i := 1; end if; end loop; for k in reverse 1..MT_Index_64(NN-1) loop G.s(i) := (G.s(i) xor ((G.s(i-1) xor Shift_Right(G.s(i-1), 62)) * 2862933555777941757)) - U64(i); i := i + 1; if i=0 then G.s(0) := G.s(MT_Index_64(NN-1)); i := 1; end if; end loop; G.s(0) := Shift_Left(U64(1),63); end Reset; -------------- -- Generate -- -------------- function Generate (G: in out MT19937_64) return U64 is x : U64; begin if G.p = 0 then for I in MT_Index_64'Range loop x := (G.s(I) and UM) or (G.s(I+1) and LM); G.s(I) := G.s(I+MM) xor Shift_Right(x, 1); if (x mod 2) = 1 then G.s(I) := G.s(I) xor MATRIX_A_64; end if; end loop; end if; x := G.s(G.p); x := x xor (Shift_Right(x, 29) and 16#5555555555555555#); x := x xor (Shift_Left(x, 17) and 16#71D67FFFEDA60000#); x := x xor (Shift_Left(x, 37) and 16#FFF7EEE000000000#); x := x xor Shift_Right(x, 43); G.p := G.p + 1; return x; end Generate; ----------- -- Reset -- ----------- procedure period_certification(random : in out TinyMT_64) is begin if ((random.status(0) and TINYMT64_MASK) = 0) and (random.status(1) = 0) then random.status(0) := Character'Pos('T'); random.status(1) := Character'Pos('M'); end if; end period_certification; procedure Reset(G: in out TinyMT_64; S: in U64) is begin G.status(0) := S xor Shift_Left(U64(G.mat1), 32); G.status(1) := U64(G.mat2) xor G.tmat; for I in U64 range 1..(MIN_LOOP-1) loop G.status(I and 1) := G.status(I and 1) xor (I + U64'(6364136223846793005) * (G.status((I-1) and 1) xor Shift_Right(G.status((I-1) and 1), 62))); end loop; period_certification(G); end Reset; procedure Reset(G: in out TinyMT_64; S: in U64_array) is function ini_func1(x : U64) return U64 is ((x xor Shift_Right(x, 59)) * U64(2173292883993)); function ini_func2(x : U64) return U64 is ((x xor Shift_Right(x, 59)) * U64(58885565329898161)); lag : constant := 1; mid : constant := 1; size : constant := 4; type i_type is mod(size); i : i_type; count : Integer; r : U64; st : array (i_type) of U64 := (0, U64(G.mat1), U64(G.mat2), G.tmat); begin count := Integer'Max(S'Length + 1, MIN_LOOP); r := ini_func1(st(0) xor st(mid) xor st(i_type(size-1))); st(mid) := st(mid) + r; r := r + S'Length; st(mid + lag) := st(mid + lag) + r; st(0) := r; count := count - 1; i := 1; for j in 0..(Integer'Min(count,S'Length)-1) loop r := ini_func1(st(i) xor st(i + mid) xor st(i + i_type(size-1))); st(i + mid) := st(i + mid) + r; r := r + S(S'First + j) + U64(i); st(i+mid+lag) := st(i+mid+lag) + r; st(i) := r; i := (i + 1); end loop; for j in S'Length .. (count-1) loop r := ini_func1(st(i) xor st(i + mid) xor st(i + i_type(size-1))); st(i + mid) := st(i + mid) + r; r := r + U64(i); st(i+mid+lag) := st(i+mid+lag) + r; st(i) := r; i := (i + 1); end loop; for j in 0..(size - 1) loop r := ini_func2(st(i) + st(i + mid) + st(i + i_type(size-1))); st(i + mid) := st(i + mid) xor r; r := r - U64(i); st(i+mid+lag) := st(i+mid+lag) xor r; st(i) := r; i := (i + 1); end loop; G.status(0) := st(0) xor st(1); G.status(1) := st(2) xor st(3); period_certification(G); end Reset; -------------- -- Generate -- -------------- function Generate(G: in out TinyMT_64) return U64 is procedure tinymt64_next_state(random : in out TinyMT_64) with inline is x : U64; begin random.status(0) := random.status(0) and TINYMT64_MASK; x := random.status(0) xor random.status(1); x := x xor Shift_Left(x, TINYMT64_SH0); x := x xor Shift_Right(x, 32); x := x xor Shift_Left(x, 32); x := x xor Shift_Left(x, TINYMT64_SH1); random.status(0) := random.status(1); random.status(1) := x; random.status(0) := random.status(0) xor (if (x and 1)=1 then U64(random.mat1) else 0); random.status(1) := random.status(1) xor (if (x and 1)=1 then Shift_Left(U64(random.mat2),32) else 0); end tinymt64_next_state; function tinymt64_temper(random : in TinyMT_64) return U64 with inline is x : U64; begin x := random.status(0) + random.status(1); x := x xor Shift_Right(random.status(0), TINYMT64_SH8); x := x xor (if (x and 1)=1 then random.tmat else 0); return x; end tinymt64_temper; begin tinymt64_next_state(G); return tinymt64_temper(G); end Generate; end PRNG_Zoo.MT;
Holt59/Ada-SDL
Ada
2,957
ads
-------------------------------------------- -- -- -- PACKAGE GAME - PARTIE ADA -- -- -- -- GAME-DISPLAY-DRAW.ADS -- -- -- -- Gestion du dessin sur surface -- -- -- -- Créateur : CAPELLE Mikaël -- -- Adresse : [email protected] -- -- -- -- Dernière modification : 14 / 06 / 2011 -- -- -- -------------------------------------------- with Game.Gtype, Game; use Game.Gtype, Game; package Game.Display.Draw is -- Pour utiliser Put_Pixel et Get_Pixel, la surface S doit être bloqué (lock) -- Transforme le Pixel contenue à la position (X,Y) de la surface S procedure Put_Pixel (Surf : in out Surface; X,Y : in Coord; Col : in Color); -- Récupère la couleur du Pixel se trouvant à la position (X,Y) de la -- surface S function Get_Pixel (Surf : in Surface; X,Y : in Coord) return Color; -- Une surface doit être bloqué avant tout dessin dessus -- Bloque (Lock) ou Debloque (Unlock) la surface S procedure Lock_Surface (Surf : in Surface); procedure Unlock_Surface (Surf : in Surface); -- Dessine un cercle procedure Cercle(Surf : in out Surface; -- Surface sur laquelle le cercle sera dessiné Centre : in Rect; -- Position du centre du cercle Col : in Color; -- Couleur du cercle Rayon : in Positive; -- Rayon du cercle Epaisseur : in Positive := 1; -- Epaisseur du cercle (bord) Lock : in Boolean := True); -- Surface à bloquer avant le dessin ? -- Dessine un disque procedure Disque(Surf : in out Surface; -- Surface sur laquelle le disque sera dessiné Centre : in Rect; -- Position du centre du disque Col : in Color; -- Couleur du disque Rayon : in Positive; -- Rayon du disque Lock : in Boolean := True); -- Surface à bloquer avant le dessin ? -- Trace un segmen procedure Segment(Surf : in out Surface; -- Surface sur laquelle le segment sera tracé X1,Y1 : in Integer; -- Position du point de départ X2,Y2 : in Integer; -- Position du point d'arrivée Col : in Color; -- Couleur du segment Lock : in Boolean := True); -- Surface à bloquer avant le tracé ? end Game.Display.Draw;
diffblue/cbmc
Ada
16
ads
procedure User;
reznikmm/matreshka
Ada
4,909
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- XML Processor -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2013, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision: 3559 $ $Date: 2012-12-07 13:08:31 +0200 (Пт., 07 дек. 2012) $ ------------------------------------------------------------------------------ with Ada.Containers.Vectors; with League.Strings; with League.String_Vectors; with XML.SAX.Content_Handlers; with XML.SAX.Attributes; with XSD_To_Ada.Mappings; package XSD_To_Ada.Mappings_XML is type Mapping_XML is new XSD_To_Ada.Mappings.Mapping and XML.SAX.Content_Handlers.SAX_Content_Handler with private; private -- package Mapping_Vectors is new Ada.Containers.Vectors -- (Index_Type => Positive, -- Element_Type => League.Strings.Universal_String -- "=" => ICTS.Forex."="); type Mapping_XML is new XSD_To_Ada.Mappings.Mapping and XML.SAX.Content_Handlers.SAX_Content_Handler with record Last_Text : League.Strings.Universal_String; end record; overriding procedure Start_Element (Self : in out Mapping_XML; Namespace_URI : League.Strings.Universal_String; Local_Name : League.Strings.Universal_String; Qualified_Name : League.Strings.Universal_String; Attributes : XML.SAX.Attributes.SAX_Attributes; Success : in out Boolean); overriding function Error_String (Self : Mapping_XML) return League.Strings.Universal_String; overriding procedure End_Element (Self : in out Mapping_XML; Namespace_URI : League.Strings.Universal_String; Local_Name : League.Strings.Universal_String; Qualified_Name : League.Strings.Universal_String; Success : in out Boolean); end XSD_To_Ada.Mappings_XML;
optikos/oasis
Ada
5,598
ads
-- Copyright (c) 2019 Maxim Reznik <[email protected]> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Program.Lexical_Elements; with Program.Elements.Expressions; with Program.Elements.Array_Aggregates; with Program.Elements.Enumeration_Representation_Clauses; with Program.Element_Visitors; package Program.Nodes.Enumeration_Representation_Clauses is pragma Preelaborate; type Enumeration_Representation_Clause is new Program.Nodes.Node and Program.Elements.Enumeration_Representation_Clauses .Enumeration_Representation_Clause and Program.Elements.Enumeration_Representation_Clauses .Enumeration_Representation_Clause_Text with private; function Create (For_Token : not null Program.Lexical_Elements .Lexical_Element_Access; Name : not null Program.Elements.Expressions.Expression_Access; Use_Token : not null Program.Lexical_Elements .Lexical_Element_Access; Expression : not null Program.Elements.Array_Aggregates .Array_Aggregate_Access; Semicolon_Token : not null Program.Lexical_Elements .Lexical_Element_Access) return Enumeration_Representation_Clause; type Implicit_Enumeration_Representation_Clause is new Program.Nodes.Node and Program.Elements.Enumeration_Representation_Clauses .Enumeration_Representation_Clause with private; function Create (Name : not null Program.Elements.Expressions .Expression_Access; Expression : not null Program.Elements.Array_Aggregates .Array_Aggregate_Access; Is_Part_Of_Implicit : Boolean := False; Is_Part_Of_Inherited : Boolean := False; Is_Part_Of_Instance : Boolean := False) return Implicit_Enumeration_Representation_Clause with Pre => Is_Part_Of_Implicit or Is_Part_Of_Inherited or Is_Part_Of_Instance; private type Base_Enumeration_Representation_Clause is abstract new Program.Nodes.Node and Program.Elements.Enumeration_Representation_Clauses .Enumeration_Representation_Clause with record Name : not null Program.Elements.Expressions.Expression_Access; Expression : not null Program.Elements.Array_Aggregates .Array_Aggregate_Access; end record; procedure Initialize (Self : aliased in out Base_Enumeration_Representation_Clause'Class); overriding procedure Visit (Self : not null access Base_Enumeration_Representation_Clause; Visitor : in out Program.Element_Visitors.Element_Visitor'Class); overriding function Name (Self : Base_Enumeration_Representation_Clause) return not null Program.Elements.Expressions.Expression_Access; overriding function Expression (Self : Base_Enumeration_Representation_Clause) return not null Program.Elements.Array_Aggregates.Array_Aggregate_Access; overriding function Is_Enumeration_Representation_Clause_Element (Self : Base_Enumeration_Representation_Clause) return Boolean; overriding function Is_Representation_Clause_Element (Self : Base_Enumeration_Representation_Clause) return Boolean; overriding function Is_Clause_Element (Self : Base_Enumeration_Representation_Clause) return Boolean; type Enumeration_Representation_Clause is new Base_Enumeration_Representation_Clause and Program.Elements.Enumeration_Representation_Clauses .Enumeration_Representation_Clause_Text with record For_Token : not null Program.Lexical_Elements .Lexical_Element_Access; Use_Token : not null Program.Lexical_Elements .Lexical_Element_Access; Semicolon_Token : not null Program.Lexical_Elements .Lexical_Element_Access; end record; overriding function To_Enumeration_Representation_Clause_Text (Self : aliased in out Enumeration_Representation_Clause) return Program.Elements.Enumeration_Representation_Clauses .Enumeration_Representation_Clause_Text_Access; overriding function For_Token (Self : Enumeration_Representation_Clause) return not null Program.Lexical_Elements.Lexical_Element_Access; overriding function Use_Token (Self : Enumeration_Representation_Clause) return not null Program.Lexical_Elements.Lexical_Element_Access; overriding function Semicolon_Token (Self : Enumeration_Representation_Clause) return not null Program.Lexical_Elements.Lexical_Element_Access; type Implicit_Enumeration_Representation_Clause is new Base_Enumeration_Representation_Clause with record Is_Part_Of_Implicit : Boolean; Is_Part_Of_Inherited : Boolean; Is_Part_Of_Instance : Boolean; end record; overriding function To_Enumeration_Representation_Clause_Text (Self : aliased in out Implicit_Enumeration_Representation_Clause) return Program.Elements.Enumeration_Representation_Clauses .Enumeration_Representation_Clause_Text_Access; overriding function Is_Part_Of_Implicit (Self : Implicit_Enumeration_Representation_Clause) return Boolean; overriding function Is_Part_Of_Inherited (Self : Implicit_Enumeration_Representation_Clause) return Boolean; overriding function Is_Part_Of_Instance (Self : Implicit_Enumeration_Representation_Clause) return Boolean; end Program.Nodes.Enumeration_Representation_Clauses;
sparre/Command-Line-Parser-Generator
Ada
2,019
adb
with Ada.Strings.Fixed, Ada.Strings.Unbounded.Equal_Case_Insensitive, Ada.Strings.Unbounded.Hash_Case_Insensitive; package body An_Application.Command_Line_Parser.Argument is function "+" (Item : in String) return Ada.Strings.Unbounded.Unbounded_String renames Ada.Strings.Unbounded.To_Unbounded_String; overriding function "=" (Left, Right : in Instance) return Boolean is use Ada.Strings.Unbounded; begin return Equal_Keys (Left, Right) and Left.Value = Right.Value; end "="; function Compose (Key : in String; Value : in String) return Instance is begin return (Key => +Key, Value => +Value); end Compose; function Equal_Keys (Left, Right : in Instance) return Boolean is use Ada.Strings.Unbounded; begin return Equal_Case_Insensitive (Left.Key, Right.Key); end Equal_Keys; function Image (Item : in Instance) return String is use Ada.Strings.Unbounded; begin return "--" & To_String (Item.Key) & "=" & To_String (Item.Value); end Image; function Key_Hash (Item : in Instance) return Ada.Containers.Hash_Type is begin return Ada.Strings.Unbounded.Hash_Case_Insensitive (Item.Key); end Key_Hash; function Value (Item : in String) return Instance is use Ada.Strings.Fixed; Key_Value_Separator : Natural; begin if Head (Item, 2) = "--" then Key_Value_Separator := Index (Item, "="); if Key_Value_Separator = 0 then return (Key => +Item (Item'First + 2 .. Item'Last), Value => +"True"); else return (Key => +Item (Item'First + 2 .. Key_Value_Separator - 1), Value => +Item (Key_Value_Separator + 1 .. Item'Last)); end if; else raise Constraint_Error with "Incorrect argument format. Expected: --<key>=<value>"; end if; end Value; end An_Application.Command_Line_Parser.Argument;
AdaCore/gpr
Ada
1,078
adb
with p1_3; use p1_3; with p2_2; use p2_2; package body p1_2 is function p1_2_0 (Item : Integer) return Integer is Result : Long_Long_Integer; begin if Item < 0 then return -Item; end if; Result := Long_Long_Integer (p1_3_0 (Item - 1)) + Long_Long_Integer (p2_2_0 (Item - 2)); return Integer (Result rem Long_Long_Integer (Integer'Last)); end p1_2_0; function p1_2_1 (Item : Integer) return Integer is Result : Long_Long_Integer; begin if Item < 0 then return -Item; end if; Result := Long_Long_Integer (p1_3_1 (Item - 1)) + Long_Long_Integer (p2_2_1 (Item - 2)); return Integer (Result rem Long_Long_Integer (Integer'Last)); end p1_2_1; function p1_2_2 (Item : Integer) return Integer is Result : Long_Long_Integer; begin if Item < 0 then return -Item; end if; Result := Long_Long_Integer (p1_3_2 (Item - 1)) + Long_Long_Integer (p2_2_2 (Item - 2)); return Integer (Result rem Long_Long_Integer (Integer'Last)); end p1_2_2; end p1_2;
reznikmm/matreshka
Ada
3,679
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Attributes; package ODF.DOM.Svg_Path_Attributes is pragma Preelaborate; type ODF_Svg_Path_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Svg_Path_Attribute_Access is access all ODF_Svg_Path_Attribute'Class with Storage_Size => 0; end ODF.DOM.Svg_Path_Attributes;
onox/orka
Ada
1,111
ads
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2022 onox <[email protected]> -- -- 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 Orka.Numerics.Singles.Tensors.GPU; with Generic_Test_Tensors_Vectors; with Test_Fixtures_GPU_Tensors; package Test_Tensors_GPU_Singles_Vectors is new Generic_Test_Tensors_Vectors ("GPU - Singles", True, Test_Fixtures_GPU_Tensors.Test_Fixture, Orka.Numerics.Singles.Tensors, Orka.Numerics.Singles.Tensors.GPU.GPU_Tensor, Orka.Numerics.Singles.Tensors.GPU.Reset_Random, Orka.Numerics.Singles.Tensors.GPU.Initialize_Shaders);
zhmu/ananas
Ada
6,246
adb
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- S Y S T E M . P A C K _ 0 5 -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2022, 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. -- -- -- ------------------------------------------------------------------------------ with System.Storage_Elements; with System.Unsigned_Types; package body System.Pack_05 is subtype Bit_Order is System.Bit_Order; Reverse_Bit_Order : constant Bit_Order := Bit_Order'Val (1 - Bit_Order'Pos (System.Default_Bit_Order)); subtype Ofs is System.Storage_Elements.Storage_Offset; subtype Uns is System.Unsigned_Types.Unsigned; subtype N07 is System.Unsigned_Types.Unsigned range 0 .. 7; use type System.Storage_Elements.Storage_Offset; use type System.Unsigned_Types.Unsigned; type Cluster is record E0, E1, E2, E3, E4, E5, E6, E7 : Bits_05; end record; for Cluster use record E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1; E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1; E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1; E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1; E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1; E5 at 0 range 5 * Bits .. 5 * Bits + Bits - 1; E6 at 0 range 6 * Bits .. 6 * Bits + Bits - 1; E7 at 0 range 7 * Bits .. 7 * Bits + Bits - 1; end record; for Cluster'Size use Bits * 8; for Cluster'Alignment use Integer'Min (Standard'Maximum_Alignment, 1 + 1 * Boolean'Pos (Bits mod 2 = 0) + 2 * Boolean'Pos (Bits mod 4 = 0)); -- Use maximum possible alignment, given the bit field size, since this -- will result in the most efficient code possible for the field. type Cluster_Ref is access Cluster; type Rev_Cluster is new Cluster with Bit_Order => Reverse_Bit_Order, Scalar_Storage_Order => Reverse_Bit_Order; type Rev_Cluster_Ref is access Rev_Cluster; ------------ -- Get_05 -- ------------ function Get_05 (Arr : System.Address; N : Natural; Rev_SSO : Boolean) return Bits_05 is A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8); C : Cluster_Ref with Address => A'Address, Import; RC : Rev_Cluster_Ref with Address => A'Address, Import; begin if Rev_SSO then case N07 (Uns (N) mod 8) is when 0 => return RC.E0; when 1 => return RC.E1; when 2 => return RC.E2; when 3 => return RC.E3; when 4 => return RC.E4; when 5 => return RC.E5; when 6 => return RC.E6; when 7 => return RC.E7; end case; else case N07 (Uns (N) mod 8) is when 0 => return C.E0; when 1 => return C.E1; when 2 => return C.E2; when 3 => return C.E3; when 4 => return C.E4; when 5 => return C.E5; when 6 => return C.E6; when 7 => return C.E7; end case; end if; end Get_05; ------------ -- Set_05 -- ------------ procedure Set_05 (Arr : System.Address; N : Natural; E : Bits_05; Rev_SSO : Boolean) is A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8); C : Cluster_Ref with Address => A'Address, Import; RC : Rev_Cluster_Ref with Address => A'Address, Import; begin if Rev_SSO then case N07 (Uns (N) mod 8) is when 0 => RC.E0 := E; when 1 => RC.E1 := E; when 2 => RC.E2 := E; when 3 => RC.E3 := E; when 4 => RC.E4 := E; when 5 => RC.E5 := E; when 6 => RC.E6 := E; when 7 => RC.E7 := E; end case; else case N07 (Uns (N) mod 8) is when 0 => C.E0 := E; when 1 => C.E1 := E; when 2 => C.E2 := E; when 3 => C.E3 := E; when 4 => C.E4 := E; when 5 => C.E5 := E; when 6 => C.E6 := E; when 7 => C.E7 := E; end case; end if; end Set_05; end System.Pack_05;
zhmu/ananas
Ada
2,680
adb
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- A D A . E X C E P T I O N S . T R A C E B A C K -- -- -- -- B o d y -- -- -- -- Copyright (C) 1999-2022, 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. -- -- -- ------------------------------------------------------------------------------ package body Ada.Exceptions.Traceback is ---------------- -- Tracebacks -- ---------------- function Tracebacks (E : Exception_Occurrence) return Tracebacks_Array is begin return Tracebacks_Array (E.Tracebacks (1 .. E.Num_Tracebacks)); end Tracebacks; end Ada.Exceptions.Traceback;
zhmu/ananas
Ada
202
ads
generic type Bound_T is private; package Inline18_Gen1 is type T is private; function Complete return T with Inline_Always; private type T is array (0 .. 1) of Bound_T; end Inline18_Gen1;
reznikmm/matreshka
Ada
4,730
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Visitors; with ODF.DOM.Chart_Data_Point_Elements; package Matreshka.ODF_Chart.Data_Point_Elements is type Chart_Data_Point_Element_Node is new Matreshka.ODF_Chart.Abstract_Chart_Element_Node and ODF.DOM.Chart_Data_Point_Elements.ODF_Chart_Data_Point with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Chart_Data_Point_Element_Node; overriding function Get_Local_Name (Self : not null access constant Chart_Data_Point_Element_Node) return League.Strings.Universal_String; overriding procedure Enter_Node (Self : not null access Chart_Data_Point_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control); overriding procedure Leave_Node (Self : not null access Chart_Data_Point_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control); overriding procedure Visit_Node (Self : not null access Chart_Data_Point_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control); end Matreshka.ODF_Chart.Data_Point_Elements;
Fabien-Chouteau/shoot-n-loot
Ada
5,278
adb
-- Shoot'n'loot -- Copyright (c) 2020 Fabien Chouteau with HAL; use HAL; with Levels; with Player; with Render; with Monsters; with Chests; with Score_Display; with Sound; with PyGamer.Controls; use PyGamer; with GESTE_Config; use GESTE_Config; with GESTE; with GESTE.Tile_Bank; with GESTE.Grid; with Game_Assets; with Game_Assets.Tileset; with Game_Assets.Tileset_Collisions; with Game_Assets.title_screen; package body Game is Tile_Bank : aliased GESTE.Tile_Bank.Instance (Game_Assets.Tileset.Tiles'Access, Game_Assets.Tileset_Collisions.Tiles'Access, Game_Assets.Palette'Access); Gameover_Grid : aliased GESTE.Grid.Instance (Game_Assets.title_screen.Gameover.Data'Access, Tile_Bank'Access); Victory_Grid : aliased GESTE.Grid.Instance (Game_Assets.title_screen.Victory.Data'Access, Tile_Bank'Access); Back_Grid : aliased GESTE.Grid.Instance (Game_Assets.title_screen.Back.Data'Access, Tile_Bank'Access); procedure Game_Over; procedure Victory (Time_In_Game : Time.Time_Ms); --------------- -- Game_Over -- --------------- procedure Game_Over is Period : constant Time.Time_Ms := 1000 / 60; Next_Release : Time.Time_Ms; begin Sound.Play_Gameover; Gameover_Grid.Move ((0, 0)); GESTE.Add (Gameover_Grid'Access, 10); Render.Render_All (Render.Background_Color); Next_Release := Time.Clock + Period; loop Controls.Scan; if (for some Button in Controls.Buttons => Controls.Falling (Button)) then GESTE.Remove_All; return; end if; Sound.Tick; Time.Delay_Until (Next_Release); Next_Release := Next_Release + Period; end loop; end Game_Over; ------------- -- Victory -- ------------- procedure Victory (Time_In_Game : Time.Time_Ms) is Period : constant Time.Time_Ms := 1000 / 60; Next_Release : Time.Time_Ms; begin Sound.Play_Victory; GESTE.Remove_All; Back_Grid.Move ((0, 0)); GESTE.Add (Back_Grid'Access, 1); Victory_Grid.Move ((0, 0)); GESTE.Add (Victory_Grid'Access, 2); Score_Display.Init ((10 * Tile_Size, 12 * Tile_Size)); Score_Display.Update (Time_In_Game); Render.Scroll_New_Scene (Render.Background_Color); Next_Release := Time.Clock + Period; loop Controls.Scan; if (for some Button in Controls.Buttons => Controls.Falling (Button)) then return; end if; Sound.Tick; Time.Delay_Until (Next_Release); Next_Release := Next_Release + Period; end loop; end Victory; --------------- -- Game_Loop -- --------------- function Game_Loop (Time_In_Game : in out PyGamer.Time.Time_Ms) return Boolean is use type Levels.Level_Id; Current_Level : Levels.Level_Id := Levels.Lvl_0; Period : constant Time.Time_Ms := 1000 / 60; Next_Release : Time.Time_Ms; Frame_Count : UInt32 := 0; Exit_Open : Boolean := False; begin Time_In_Game := 0; Levels.Enter (Current_Level); Score_Display.Update (Time_In_Game); Render.Scroll_New_Scene (Render.Background_Color); Next_Release := Time.Clock + Period; loop -- Check game-over if not Player.Is_Alive then Game_Over; return False; end if; -- Open exit and check victory if not Exit_Open and then Chests.All_Open and then Monsters.All_Killed then Exit_Open := True; Levels.Open_Exit; end if; if Exit_Open then if Levels.Test_Exit (Player.Position) then Sound.Play_Exit_Taken; if Current_Level = Levels.Level_Id'Last then Victory (Time_In_Game); return True; end if; Current_Level := Levels.Level_Id'Succ (Current_Level); Levels.Enter (Current_Level); Exit_Open := False; Score_Display.Update (Time_In_Game); Render.Scroll_New_Scene (Render.Background_Color); Next_Release := Time.Clock + Period; end if; end if; Controls.Scan; if Controls.Falling (Controls.A) then Player.Jump; end if; if Controls.Falling (Controls.B) then Player.Fire; end if; if Controls.Pressed (Controls.Left) then Player.Move_Left; end if; if Controls.Pressed (Controls.Right) then Player.Move_Right; end if; Player.Update; Monsters.Update; Chests.Check_Chest_Found (Player.Position); Chests.Update; Score_Display.Update (Time_In_Game); Render.Render_Dirty (Render.Background_Color); Frame_Count := Frame_Count + 1; Sound.Tick; Time.Delay_Until (Next_Release); Next_Release := Next_Release + Period; Time_In_Game := Time_In_Game + Period; end loop; end Game_Loop; end Game;
reznikmm/matreshka
Ada
4,559
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Text.Note_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Text_Note_Attribute_Node is begin return Self : Text_Note_Attribute_Node do Matreshka.ODF_Text.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Text_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Text_Note_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Note_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Text_URI, Matreshka.ODF_String_Constants.Note_Attribute, Text_Note_Attribute_Node'Tag); end Matreshka.ODF_Text.Note_Attributes;
francesco-bongiovanni/ewok-kernel
Ada
1,201
ads
-- -- Copyright 2018 The wookey project team <[email protected]> -- - Ryad Benadjila -- - Arnauld Michelizza -- - Mathieu Renard -- - Philippe Thierry -- - Philippe Trebuchet -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- package debug with spark_mode => off is type t_level is (DEBUG, INFO, WARNING, ALERT); COLOR_NORMAL : constant string := ASCII.ESC & "[37;40m"; COLOR_ALERT : constant string := ASCII.ESC & "[37;41m"; COLOR_KERNEL : constant string := ASCII.ESC & "[37;44m"; procedure log (s : string; nl : boolean := true); procedure log (level : t_level; s : string); procedure panic (s : string); end debug;
onox/orka
Ada
18,278
adb
with Ada.Exceptions; with Ada.Real_Time; with Ada.Text_IO; with AWT.Clipboard; with AWT.Drag_And_Drop; with AWT.Inputs.Gamepads; with AWT.Monitors; with AWT.Windows; with Orka.Contexts.AWT; with Orka.Debug; with Orka.Strings; with Orka.Resources.Locations.Directories; with Package_Test; procedure Example is use Ada.Text_IO; Index : Positive := 1; Monitor_Events, Last_Monitor_Events : Positive := 1; Border_Size : constant := 50; Should_Be_Visible : Boolean := True; Visible_Index : Positive := 1; Print_Axes_And_Triggers : constant Boolean := False; subtype Normalized is AWT.Inputs.Gamepads.Normalized; Color : AWT.Inputs.Gamepads.RGB_Color := (others => 0.0); Brightness : Normalized := 0.0; type Extra_Info_Kind is (Info_Motion, Info_Battery, Info_LED); Extra_Info : Extra_Info_Kind := Extra_Info_Kind'First; Visible_Index_Count : constant := 100; type Test_Listener is new AWT.Monitors.Monitor_Event_Listener with null record; overriding procedure On_Connect (Object : Test_Listener; Monitor : AWT.Monitors.Monitor_Ptr); overriding procedure On_Disconnect (Object : Test_Listener; Monitor : AWT.Monitors.Monitor_Ptr); overriding procedure On_Connect (Object : Test_Listener; Monitor : AWT.Monitors.Monitor_Ptr) is begin Put_Line ("connected:"); Monitor.Log_Information; Monitor_Events := Monitor_Events + 1; end On_Connect; overriding procedure On_Disconnect (Object : Test_Listener; Monitor : AWT.Monitors.Monitor_Ptr) is begin Put_Line ("disconnected:"); Monitor.Log_Information; Monitor_Events := Monitor_Events + 1; end On_Disconnect; Unused_Monitor_Listener : Test_Listener; type Print_Gamepad_Listener is new AWT.Inputs.Gamepads.Gamepad_Event_Listener with null record; overriding procedure On_Connect (Object : Print_Gamepad_Listener; Gamepad : AWT.Inputs.Gamepads.Gamepad_Ptr); overriding procedure On_Disconnect (Object : Print_Gamepad_Listener; Gamepad : AWT.Inputs.Gamepads.Gamepad_Ptr); overriding procedure On_Connect (Object : Print_Gamepad_Listener; Gamepad : AWT.Inputs.Gamepads.Gamepad_Ptr) is begin Gamepad.Log_Information; end On_Connect; overriding procedure On_Disconnect (Object : Print_Gamepad_Listener; Gamepad : AWT.Inputs.Gamepads.Gamepad_Ptr) is begin Gamepad.Log_Information; end On_Disconnect; Unused_Print_Gamepad_Listener : Print_Gamepad_Listener; Effect_1 : constant AWT.Inputs.Gamepads.Effect := AWT.Inputs.Gamepads.Rumble_Effect (0.15, 0.0, 0.7, 1.0); Effect_2 : constant AWT.Inputs.Gamepads.Effect := AWT.Inputs.Gamepads.Periodic_Effect (8.0, 0.0, 0.8, 3.0, 2.0); Location_Data : constant Orka.Resources.Locations.Location_Ptr := (Orka.Resources.Locations.Directories.Create_Location ("./")); use all type AWT.Inputs.Gamepads.Connection_Kind; begin Put_Line ("Initializing..."); AWT.Initialize; Put_Line ("Initialized"); for Monitor of AWT.Monitors.Monitors loop Monitor.Log_Information; end loop; if Location_Data.Exists ("gamecontrollerdb.txt") then AWT.Inputs.Gamepads.Set_Mappings (Orka.Resources.Convert (Location_Data.Read_Data ("gamecontrollerdb.txt").Get)); Put_Line ("Mappings added"); end if; AWT.Inputs.Gamepads.Initialize; AWT.Inputs.Gamepads.Poll (DT => 0.0); for Gamepad of AWT.Inputs.Gamepads.Gamepads loop Gamepad.Log_Information; end loop; declare Next_Cursor : AWT.Inputs.Cursors.Pointer_Cursor := AWT.Inputs.Cursors.Pointer_Cursor'First; use Ada.Real_Time; Interval : constant Duration := To_Duration (Microseconds (16_667)); Flip_Size : Boolean := False; Context : constant Orka.Contexts.Surface_Context'Class := Orka.Contexts.AWT.Create_Context (Version => (4, 2), Flags => (Debug | Robust => True, others => False)); Window : Package_Test.Test_Window := Package_Test.Create_Window (Context, 600, 400, Visible => True, Transparent => True, Title => "init test"); AWT_Window : AWT.Windows.Window'Class renames AWT.Windows.Window'Class (Window); task Render_Task is entry Start_Rendering; end Render_Task; task body Render_Task is begin Put_Line ("Render task waiting to get started..."); accept Start_Rendering; Put_Line ("Render task started"); Context.Make_Current (Window); Put_Line ("Window made current on context"); Orka.Debug.Set_Log_Messages (Enable => True); Put_Line ("Context version: " & Orka.Contexts.Image (Context.Version)); Window.Post_Initialize; Put_Line ("Rendering..."); while not Window.Should_Close loop delay until Clock + Microseconds (15000); Window.Render; end loop; Put_Line ("Rendering done"); Context.Make_Not_Current; Put_Line ("Render task, context made not current"); exception when E : others => Put_Line ("Error render task: " & Ada.Exceptions.Exception_Information (E)); Context.Make_Not_Current; raise; end Render_Task; task Poll_Joysticks; task body Poll_Joysticks is Poll_Interval : constant Time_Span := Milliseconds (4); Next_Time : Time := Clock + Poll_Interval; begin Put_Line ("Polling joysticks..."); loop exit when Window.Should_Close; AWT.Inputs.Gamepads.Poll (DT => 0.0); delay until Next_Time; Next_Time := Next_Time + Poll_Interval; end loop; Put_Line ("Polling done"); exception when E : others => Put_Line ("Error joystick task: " & Ada.Exceptions.Exception_Information (E)); raise; end Poll_Joysticks; begin Context.Make_Not_Current; Put_Line ("Context made not current in main task"); Render_Task.Start_Rendering; Put_Line ("Render task started by main task"); Window.Set_Margin (Border_Size); Put_Line ("Starting event loop..."); while not Window.Should_Close loop AWT.Process_Events (Interval); Index := Index + 1; select Window.Drag_And_Drop_Signal.Wait; declare Result : constant String := AWT.Drag_And_Drop.Get; begin Put_Line ("value: '" & Orka.Strings.Strip_Line_Term (Result) & "'"); AWT.Drag_And_Drop.Finish (AWT.Inputs.Copy); end; else null; end select; if not Should_Be_Visible then Put_Line (Positive'Image (Visible_Index + Visible_Index_Count) & Index'Image); if Index > Visible_Index + Visible_Index_Count then Should_Be_Visible := True; AWT_Window.Set_Title ("visible! " & Visible_Index'Image); AWT_Window.Set_Visible (True); Put_Line ("window visible"); end if; end if; if Monitor_Events /= Last_Monitor_Events then Put_Line ("Monitor count: " & Natural'Image (AWT.Monitors.Monitors'Length)); Last_Monitor_Events := Monitor_Events; end if; declare Pointer : constant AWT.Inputs.Pointer_State := AWT_Window.State; -- use all type AWT.Inputs.Button_State; -- use all type AWT.Inputs.Dimension; use all type AWT.Inputs.Pointer_Button; use all type AWT.Inputs.Pointer_Mode; use type AWT.Inputs.Cursors.Pointer_Cursor; begin -- if False then -- Put_Line ("focused: " & Pointer.Focused'Image); -- Put_Line ("scrolling: " & Pointer.Scrolling'Image); -- Put_Line ("buttons:"); -- Put_Line (" left: " & Pointer.Buttons (Left)'Image); -- Put_Line (" middle: " & Pointer.Buttons (Middle)'Image); -- Put_Line (" right: " & Pointer.Buttons (Right)'Image); -- Put_Line ("mode: " & Pointer.Mode'Image); -- Put_Line ("position: " & Pointer.Position (X)'Image & Pointer.Position (Y)'Image); -- Put_Line ("relative: " & Pointer.Relative (X)'Image & Pointer.Relative (Y)'Image); -- Put_Line ("scroll: " & Pointer.Scroll (X)'Image & Pointer.Scroll (Y)'Image); -- end if; if Pointer.Pressed (Left) then Next_Cursor := (if Next_Cursor = AWT.Inputs.Cursors.Pointer_Cursor'Last then AWT.Inputs.Cursors.Pointer_Cursor'First else AWT.Inputs.Cursors.Pointer_Cursor'Succ (Next_Cursor)); AWT_Window.Set_Pointer_Cursor (Next_Cursor); end if; if Pointer.Pressed (Right) and Pointer.Mode /= Locked then AWT_Window.Set_Pointer_Mode (Locked); elsif Pointer.Released (Right) and Pointer.Mode = Locked then AWT_Window.Set_Pointer_Mode (Visible); end if; end; declare Keyboard : constant AWT.Inputs.Keyboard_State := AWT_Window.State; -- use type AWT.Inputs.Keyboard_Modifiers; use all type AWT.Inputs.Button_State; use all type AWT.Inputs.Keyboard_Button; begin if Keyboard.Pressed (Key_Escape) then Window.Close; end if; if Keyboard.Modifiers.Ctrl and Keyboard.Pressed (Key_C) then declare Value : constant String := "foobar" & Index'Image; begin AWT.Clipboard.Set (Value); Put_Line ("Set clipboard: '" & Value & "'"); end; end if; if Keyboard.Modifiers.Ctrl and Keyboard.Pressed (Key_V) then Put_Line ("Get clipboard: '" & AWT.Clipboard.Get & "'"); end if; -- Put_Line ("focused: " & Keyboard.Focused'Image); -- Put_Line ("repeat:"); -- Put_Line (" rate: " & Keyboard.Repeat_Rate'Image); -- Put_Line (" delay: " & Keyboard.Repeat_Delay'Image); -- if False and Keyboard.Modifiers /= Last_Keyboard.Modifiers then -- Put_Line ("Shift: " & Keyboard.Modifiers.Shift'Image); -- Put_Line ("Caps_Lock: " & Keyboard.Modifiers.Caps_Lock'Image); -- Put_Line ("Ctrl: " & Keyboard.Modifiers.Ctrl'Image); -- Put_Line ("Alt: " & Keyboard.Modifiers.Alt'Image); -- Put_Line ("Num_Lock: " & Keyboard.Modifiers.Num_Lock'Image); -- Put_Line ("Logo: " & Keyboard.Modifiers.Logo'Image); -- end if; declare use all type AWT.Windows.Size_Mode; begin if Keyboard.Modifiers.Ctrl and Keyboard.Pressed (Key_F) then if AWT_Window.State.Mode = Fullscreen then AWT_Window.Set_Size_Mode (Default); else AWT_Window.Set_Size_Mode (Fullscreen); end if; end if; if Keyboard.Modifiers.Ctrl and Keyboard.Pressed (Key_M) then if AWT_Window.State.Mode = Maximized then AWT_Window.Set_Size_Mode (Default); else AWT_Window.Set_Size_Mode (Maximized); end if; end if; if Keyboard.Modifiers.Ctrl and Keyboard.Pressed (Key_S) then Flip_Size := not Flip_Size; if Flip_Size then AWT_Window.Set_Size (1280, 720); else AWT_Window.Set_Size (600, 400); end if; end if; if Keyboard.Modifiers.Ctrl and Keyboard.Pressed (Key_H) then Should_Be_Visible := False; Visible_Index := Index; AWT_Window.Set_Visible (False); Put_Line ("window hidden"); end if; end; declare Gamepads : constant AWT.Inputs.Gamepads.Gamepad_Array := AWT.Inputs.Gamepads.Gamepads; Title : AWT.SU.Unbounded_String; begin if Gamepads'Length > 0 then declare Gamepad : AWT.Inputs.Gamepads.Gamepad_Ptr renames Gamepads (1); State : constant AWT.Inputs.Gamepads.Gamepad_State := Gamepad.State; Motion : constant AWT.Inputs.Gamepads.Motion_State := Gamepad.State; Battery : constant AWT.Inputs.Gamepads.Battery_State := Gamepad.State; LED : constant AWT.Inputs.Gamepads.LED_State := Gamepad.State; use all type AWT.Inputs.Gamepads.Gamepad_Button; use all type AWT.Inputs.Gamepads.Gamepad_Trigger; use all type AWT.Inputs.Gamepads.Color_Kind; use type Normalized; Show_Extra_Info : constant Boolean := State.Buttons (Center_Right) /= Pressed; begin AWT.SU.Append (Title, "serial: " & Gamepad.Serial_Number & " connected? " & Gamepad.Connection'Image & " (" & Natural'Image (Gamepads'Length) & " gamepads) "); if State.Pressed (Shoulder_Right) then Gamepad.Play_Effect (Effect_1); elsif State.Released (Shoulder_Right) then Gamepad.Cancel_Effect (Effect_1); end if; if State.Pressed (Shoulder_Left) then Gamepad.Play_Effect (Effect_2); elsif State.Released (Shoulder_Left) then Gamepad.Cancel_Effect (Effect_2); end if; if State.Pressed (Center_Right) then Extra_Info := (if Extra_Info = Extra_Info_Kind'Last then Extra_Info_Kind'First else Extra_Info_Kind'Succ (Extra_Info)); end if; -- Toggle LED red when pressing button B if State.Pressed (Action_Right) then Color (Red) := 1.0 - Color (Red); end if; -- Toggle LED green when pressing button Y if State.Pressed (Action_Up) then Color (Green) := 1.0 - Color (Green); end if; -- Toggle LED blue when pressing button A if State.Pressed (Action_Down) then Color (Blue) := 1.0 - Color (Blue); end if; -- Set brightness with left trigger while holding button X if State.Buttons (Action_Left) = Pressed then Brightness := Normalized (State.Triggers (Trigger_Left)); end if; Gamepad.Set_LED (Brightness, Color); for Button in State.Buttons'Range loop if State.Pressed (Button) then -- pragma Assert (State.Buttons (Button) = Pressed); Put_Line ("pressed " & Button'Image); end if; if State.Released (Button) then -- pragma Assert (State.Buttons (Button) = Released); Put_Line ("released " & Button'Image); end if; if State.Buttons (Button) = Pressed then AWT.SU.Append (Title, " " & Button'Image); end if; end loop; if Show_Extra_Info then if Extra_Info = Info_Motion and Motion.Is_Present then AWT.SU.Append (Title, "motion:"); for Axis in Motion.Axes'Range loop AWT.SU.Append (Title, " " & Motion.Axes (Axis)'Image); end loop; end if; if Extra_Info = Info_Battery and Battery.Is_Present then AWT.SU.Append (Title, "battery: " & Battery.Capacity'Image & " (" & Battery.Status'Image & ")"); end if; if Extra_Info = Info_LED and LED.Is_Present then AWT.SU.Append (Title, "L: " & LED.Brightness'Image & " color: " & LED.Color (Red)'Image & LED.Color (Green)'Image & LED.Color (Blue)'Image); end if; end if; if Print_Axes_And_Triggers then for Axis in State.Axes'Range loop Put (Axis'Image & ": " & State.Axes (Axis)'Image & " "); end loop; for Trigger in State.Triggers'Range loop Put (Trigger'Image & ": " & State.Triggers (Trigger)'Image & " "); end loop; New_Line; end if; end; end if; if Gamepads'Length > 0 then AWT_Window.Set_Title (AWT.SU.To_String (Title)); else AWT_Window.Set_Title ("No gamepads"); end if; end; end; end loop; Put_Line ("Exited event loop"); exception when E : others => Put_Line ("Error in main task: " & Ada.Exceptions.Exception_Information (E)); raise; end; end Example;
reznikmm/matreshka
Ada
3,734
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Attributes; package ODF.DOM.Draw_Caption_Escape_Attributes is pragma Preelaborate; type ODF_Draw_Caption_Escape_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Draw_Caption_Escape_Attribute_Access is access all ODF_Draw_Caption_Escape_Attribute'Class with Storage_Size => 0; end ODF.DOM.Draw_Caption_Escape_Attributes;
bhayward93/Ada-Traffic-Light-Sim
Ada
341
adb
with HWIF;use HWIF; --with Ada.Text_IO; use Ada.Text_IO; function OppositeDirection(dir : in Direction) return Direction is begin if dir = North then return South; elsif dir = South then return North; elsif dir = East then return West; elsif dir = West then return East; end if; end OppositeDirection;
zrmyers/VulkanAda
Ada
6,855
ads
with Interfaces.C; use Interfaces.C; with Interfaces.C.Extensions; package stdint_h is pragma Preelaborate; pragma Pure; --* -- * This file has no copyright assigned and is placed in the Public Domain. -- * This file is part of the mingw-w64 runtime package. -- * No warranty is given; refer to the file DISCLAIMER.PD within this package. -- -- ISO C9x 7.18 Integer types <stdint.h> -- * Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794) -- * -- * THIS SOFTWARE IS NOT COPYRIGHTED -- * -- * Contributor: Danny Smith <[email protected]> -- * -- * This source code is offered for use in the public domain. You may -- * use, modify or distribute it freely. -- * -- * This code is distributed in the hope that it will be useful but -- * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY -- * DISCLAIMED. This includes but is not limited to warranties of -- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- * -- * Date: 2000-12-02 -- -- 7.18.1.1 Exact-width integer types subtype int8_t is signed_char; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:35 subtype uint8_t is unsigned_char; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:36 subtype int16_t is short; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:37 subtype uint16_t is unsigned_short; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:38 subtype int32_t is int; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:39 subtype uint32_t is unsigned; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:40 subtype int64_t is Long_Long_Integer; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:41 subtype uint64_t is Extensions.unsigned_long_long; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:42 -- 7.18.1.2 Minimum-width integer types subtype int_least8_t is signed_char; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:45 subtype uint_least8_t is unsigned_char; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:46 subtype int_least16_t is short; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:47 subtype uint_least16_t is unsigned_short; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:48 subtype int_least32_t is int; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:49 subtype uint_least32_t is unsigned; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:50 subtype int_least64_t is Long_Long_Integer; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:51 subtype uint_least64_t is Extensions.unsigned_long_long; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:52 -- 7.18.1.3 Fastest minimum-width integer types -- * Not actually guaranteed to be fastest for all purposes -- * Here we use the exact-width types for 8 and 16-bit ints. -- subtype int_fast8_t is signed_char; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:58 subtype uint_fast8_t is unsigned_char; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:59 subtype int_fast16_t is short; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:60 subtype uint_fast16_t is unsigned_short; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:61 subtype int_fast32_t is int; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:62 subtype uint_fast32_t is unsigned; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:63 subtype int_fast64_t is Long_Long_Integer; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:64 subtype uint_fast64_t is Extensions.unsigned_long_long; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:65 -- 7.18.1.5 Greatest-width integer types subtype intmax_t is Long_Long_Integer; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:68 subtype uintmax_t is Extensions.unsigned_long_long; -- C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/stdint.h:69 -- 7.18.2 Limits of specified-width integer types -- 7.18.2.1 Limits of exact-width integer types -- 7.18.2.2 Limits of minimum-width integer types -- 7.18.2.3 Limits of fastest minimum-width integer types -- 7.18.2.4 Limits of integer types capable of holding -- object pointers -- 7.18.2.5 Limits of greatest-width integer types -- 7.18.3 Limits of other integer types -- * wint_t is unsigned short for compatibility with MS runtime -- -- 7.18.4 Macros for integer constants -- 7.18.4.1 Macros for minimum-width integer constants -- Accoding to Douglas Gwyn <[email protected]>: -- "This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC -- 9899:1999 as initially published, the expansion was required -- to be an integer constant of precisely matching type, which -- is impossible to accomplish for the shorter types on most -- platforms, because C99 provides no standard way to designate -- an integer constant with width less than that of type int. -- TC1 changed this to require just an integer constant -- *expression* with *promoted* type." -- The trick used here is from Clive D W Feather. -- -- The 'trick' doesn't work in C89 for long long because, without -- suffix, (val) will be evaluated as int, not intmax_t -- 7.18.4.2 Macros for greatest-width integer constants end stdint_h;
reznikmm/matreshka
Ada
9,025
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2010, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ pragma Style_Checks ("-t"); -- GNAT: Disable check for token separation rules, because format of the -- tables is not compatible with them. private package Matreshka.Internals.Regexps.Compiler.Parser.Tables is pragma Preelaborate; type Goto_Entry is record Nonterm : Integer; Newstate : Integer; end record; type Shift_Reduce_Entry is record T : Integer; Act : Integer; end record; YY_Default : constant := -1; YY_First_Shift_Entry : constant := 0; YY_Accept_Code : constant := -3001; YY_Error_Code : constant := -3000; YY_Goto_Matrix : constant array (-1 .. 21) of Goto_Entry := (( -1, -1), ( -6, 10), ( -5, 3), ( -4, 2), ( -3, 1), ( -2, 14), ( -6, 10), ( -5, 16), ( -6, 10), ( -5, 3), ( -4, 2), ( -3, 24), ( -6, 10), ( -5, 3), ( -4, 2), ( -3, 25), ( -7, 28), ( -6, 10), ( -5, 3), ( -4, 31), ( -7, 42), ( -6, 10), ( -5, 16)); YY_Goto_Offset : constant array (0 .. 60) of Integer := ( 0, 5, 5, 7, 7, 11, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22); YY_Rule_Length : constant array (0 .. 35) of Integer := ( 2, 1, 3, 1, 2, 1, 2, 2, 2, 2, 2, 2, 6, 6, 5, 5, 5, 5, 4, 4, 3, 3, 1, 1, 3, 3, 1, 1, 1, 3, 4, 4, 2, 4, 4, 0); YY_Get_LHS_Rule : constant array (0 .. 35) of Integer := ( -1, -2, -3, -3, -4, -4, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -6, -6, -7, -7, -7, -7, -7); YY_Shift_Reduce_Matrix : constant array (-1 .. 166) of Shift_Reduce_Entry := (( -1, -1), ( 2, 7), ( 3, 6), ( 11, 13), ( 20, 4), ( 21, 5), ( 23, 8), ( 24, 9), ( 27, 11), ( 28, 12), ( -1, -3000), ( 4, 15), ( -1, -1), ( 2, 7), ( 3, 6), ( 11, 13), ( 20, 4), ( 21, 5), ( 23, 8), ( 24, 9), ( 27, 11), ( 28, 12), ( -1, -3), ( 5, 17), ( 6, 18), ( 7, 19), ( 8, 20), ( 9, 21), ( 10, 22), ( 15, 23), ( -1, -5), ( 2, 7), ( 3, 6), ( 11, 13), ( 20, 4), ( 21, 5), ( 23, 8), ( 24, 9), ( 27, 11), ( 28, 12), ( -1, -3000), ( 2, 7), ( 3, 6), ( 11, 13), ( 20, 4), ( 21, 5), ( 23, 8), ( 24, 9), ( 27, 11), ( 28, 12), ( -1, -3000), ( -1, -22), ( -1, -23), ( 26, 26), ( -1, -3000), ( 26, 27), ( -1, -3000), ( -1, -26), ( -1, -27), ( -1, -28), ( 13, 29), ( -1, -35), ( 0, -3001), ( -1, -3000), ( 2, 7), ( 3, 6), ( 11, 13), ( 20, 4), ( 21, 5), ( 23, 8), ( 24, 9), ( 27, 11), ( 28, 12), ( -1, -3000), ( 5, 17), ( 6, 18), ( 7, 19), ( 8, 20), ( 9, 21), ( 10, 22), ( 15, 23), ( -1, -4), ( -1, -6), ( -1, -7), ( -1, -8), ( -1, -9), ( -1, -10), ( -1, -11), ( 18, 33), ( 19, 32), ( -1, -3000), ( 4, 15), ( 22, 34), ( -1, -3000), ( 4, 15), ( 22, 35), ( -1, -3000), ( 25, 36), ( -1, -3000), ( 25, 37), ( -1, -3000), ( 2, 39), ( 12, 38), ( 23, 40), ( 24, 41), ( -1, -3000), ( -1, -35), ( -1, -3000), ( 2, 7), ( 3, 6), ( 11, 13), ( 20, 4), ( 21, 5), ( 23, 8), ( 24, 9), ( 27, 11), ( 28, 12), ( -1, -2), ( 16, 44), ( 17, 45), ( 18, 43), ( -1, -3000), ( 19, 46), ( -1, -3000), ( -1, -20), ( -1, -21), ( -1, -24), ( -1, -25), ( -1, -29), ( 14, 47), ( -1, -32), ( 26, 48), ( -1, -3000), ( 26, 49), ( -1, -3000), ( 2, 39), ( 12, 50), ( 23, 40), ( 24, 41), ( -1, -3000), ( 16, 52), ( 17, 53), ( 19, 51), ( -1, -3000), ( -1, -18), ( -1, -19), ( 16, 54), ( 17, 55), ( -1, -3000), ( 2, 56), ( -1, -3000), ( 25, 57), ( -1, -3000), ( 25, 58), ( -1, -3000), ( -1, -30), ( 16, 59), ( 17, 60), ( -1, -3000), ( -1, -16), ( -1, -17), ( -1, -14), ( -1, -15), ( -1, -31), ( -1, -33), ( -1, -34), ( -1, -12), ( -1, -13)); YY_Shift_Reduce_Offset : constant array (0 .. 60) of Integer := ( 0, 10, 12, 22, 30, 40, 50, 51, 52, 54, 56, 57, 58, 59, 61, 63, 73, 81, 82, 83, 84, 85, 86, 87, 90, 93, 96, 98, 100, 105, 106, 107, 117, 121, 123, 124, 125, 126, 127, 128, 130, 132, 134, 139, 143, 144, 145, 148, 150, 152, 154, 155, 158, 159, 160, 161, 162, 163, 164, 165, 166); end Matreshka.Internals.Regexps.Compiler.Parser.Tables;
stcarrez/ada-wiki
Ada
954
ads
----------------------------------------------------------------------- -- Util-texts -- Various Text Utilities -- Copyright (C) 2001, 2002, 2003, 2009, 2010 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- package Util.Texts is pragma Pure; end Util.Texts;
sungyeon/drake
Ada
11,561
adb
with Ada.Containers.Linked_Lists; package body Ada.Containers.Naked_Doubly_Linked_Lists is function Next (Position : not null Node_Access) return Node_Access is begin return Position.Next; end Next; function Previous (Position : not null Node_Access) return Node_Access is begin return Position.Previous; end Previous; procedure Iterate ( First : Node_Access; Process : not null access procedure (Position : not null Node_Access)) is Position : Node_Access := First; begin while Position /= null loop Process (Position); Position := Position.Next; end loop; end Iterate; procedure Reverse_Iterate ( Last : Node_Access; Process : not null access procedure (Position : not null Node_Access)) is procedure Reverse_Iterate_Body is new Linked_Lists.Reverse_Iterate (Node, Node_Access); pragma Inline_Always (Reverse_Iterate_Body); begin Reverse_Iterate_Body (Last, Process => Process); end Reverse_Iterate; function Find ( First : Node_Access; Params : System.Address; Equivalent : not null access function ( Right : not null Node_Access; Params : System.Address) return Boolean) return Node_Access is I : Node_Access := First; begin while I /= null loop if Equivalent (I, Params) then return I; end if; I := I.Next; end loop; return null; end Find; function Reverse_Find ( Last : Node_Access; Params : System.Address; Equivalent : not null access function ( Right : not null Node_Access; Params : System.Address) return Boolean) return Node_Access is function Reverse_Find_Body is new Linked_Lists.Reverse_Find (Node, Node_Access); pragma Inline_Always (Reverse_Find_Body); begin return Reverse_Find_Body (Last, Params, Equivalent => Equivalent); end Reverse_Find; function Is_Before (Before, After : Node_Access) return Boolean is AN : Node_Access; BN : Node_Access; AP : Node_Access; BP : Node_Access; begin if After = Before then return False; else AN := After; BN := Before; AP := After.Previous; BP := Before.Previous; loop if BP = null or else AP = BN then return True; elsif AP = null or else BP = AN then return False; end if; AN := AN.Next; BN := BN.Next; if AN = null or else BN = AP then return True; elsif BN = null or else AN = BP then return False; end if; AP := AP.Previous; BP := BP.Previous; end loop; end if; end Is_Before; function Equivalent ( Left_Last, Right_Last : Node_Access; Equivalent : not null access function ( Left, Right : not null Node_Access) return Boolean) return Boolean is function Equivalent_Body is new Linked_Lists.Equivalent (Node, Node_Access); pragma Inline_Always (Equivalent_Body); begin return Equivalent_Body (Left_Last, Right_Last, Equivalent => Equivalent); end Equivalent; procedure Free ( First : in out Node_Access; Last : in out Node_Access; Length : in out Count_Type; Free : not null access procedure (Object : in out Node_Access)) is procedure Free_Body is new Linked_Lists.Free (Node, Node_Access); pragma Inline_Always (Free_Body); begin Free_Body (First, Last, Length, Free => Free); end Free; procedure Insert ( First : in out Node_Access; Last : in out Node_Access; Length : in out Count_Type; Before : Node_Access; New_Item : not null Node_Access) is begin if Before /= null then New_Item.Previous := Before.Previous; Before.Previous := New_Item; else New_Item.Previous := Last; Last := New_Item; end if; New_Item.Next := Before; if First = Before then First := New_Item; else New_Item.Previous.Next := New_Item; end if; Length := Length + 1; end Insert; procedure Remove ( First : in out Node_Access; Last : in out Node_Access; Length : in out Count_Type; Position : not null Node_Access; Next : Node_Access) is pragma Assert (Next = Position.Next); Previous : constant Node_Access := Position.Previous; begin if Previous /= null then pragma Assert (First /= Position); Previous.Next := Next; else pragma Assert (First = Position); First := Next; end if; if Next /= null then pragma Assert (Last /= Position); Next.Previous := Previous; else pragma Assert (Last = Position); Last := Previous; end if; Length := Length - 1; end Remove; procedure Swap_Links ( First : in out Node_Access; Last : in out Node_Access; I, J : not null Node_Access) is begin if I /= J then declare I_Previous : constant Node_Access := I.Previous; I_Next : constant Node_Access := I.Next; J_Previous : constant Node_Access := J.Previous; J_Next : constant Node_Access := J.Next; begin if I_Previous = J then pragma Assert (J_Next = I); I.Next := J; J.Previous := I; else I.Next := J_Next; J.Previous := I_Previous; if I_Previous /= null then I_Previous.Next := J; else pragma Assert (I = First); First := J; end if; if J_Next /= null then J_Next.Previous := I; else pragma Assert (J = Last); Last := I; end if; end if; if J_Previous = I then pragma Assert (I_Next = J); J.Next := I; I.Previous := J; else J.Next := I_Next; I.Previous := J_Previous; if J_Previous /= null then J_Previous.Next := I; else pragma Assert (J = First); First := I; end if; if I_Next /= null then I_Next.Previous := J; else pragma Assert (I = Last); Last := J; end if; end if; end; end if; end Swap_Links; procedure Splice ( Target_First : in out Node_Access; Target_Last : in out Node_Access; Length : in out Count_Type; Before : Node_Access; Source_First : in out Node_Access; Source_Last : in out Node_Access; Source_Length : in out Count_Type) is Previous : Node_Access; begin if Source_Last /= null then if Before /= null then Previous := Before.Previous; Before.Previous := Source_Last; Source_Last.Next := Before; else Previous := Target_Last; Target_Last := Source_Last; pragma Assert (Source_Last.Next = null); end if; Source_First.Previous := Previous; if Previous /= null then Previous.Next := Source_First; else pragma Assert (Target_First = null); Target_First := Source_First; end if; Length := Length + Source_Length; Source_First := null; Source_Last := null; Source_Length := 0; end if; end Splice; procedure Split ( Target_First : out Node_Access; Target_Last : out Node_Access; Length : out Count_Type; Source_First : in out Node_Access; Source_Last : in out Node_Access; Source_Length : in out Count_Type; Count : Count_Type) is Before : Node_Access; begin if Count = 0 then Target_First := null; Target_Last := null; Length := 0; elsif Count = Source_Length then Target_First := Source_First; Target_Last := Source_Last; Length := Source_Length; Source_First := null; Source_Last := null; Source_Length := 0; else Before := Source_First; for I in 1 .. Count loop Before := Before.Next; end loop; Target_First := Source_First; Target_Last := Before.Previous; Source_First := Before; Target_Last.Next := null; Source_First.Previous := null; Length := Count; Source_Length := Source_Length - Count; end if; end Split; procedure Copy ( Target_First : out Node_Access; Target_Last : out Node_Access; Length : out Count_Type; Source_Last : Node_Access; Copy : not null access procedure ( Target : out Node_Access; Source : not null Node_Access)) is procedure Copy_Body is new Linked_Lists.Copy (Node, Node_Access); pragma Inline_Always (Copy_Body); begin Copy_Body (Target_First, Target_Last, Length, Source_Last, Copy => Copy); end Copy; procedure Reverse_Elements ( Target_First : in out Node_Access; Target_Last : in out Node_Access; Length : in out Count_Type) is procedure Reverse_Elements_Body is new Linked_Lists.Reverse_Elements (Node, Node_Access); pragma Inline_Always (Reverse_Elements_Body); begin Reverse_Elements_Body (Target_First, Target_Last, Length); end Reverse_Elements; function Is_Sorted ( Last : Node_Access; LT : not null access function ( Left, Right : not null Node_Access) return Boolean) return Boolean is function Is_Sorted_Body is new Linked_Lists.Is_Sorted (Node, Node_Access); pragma Inline_Always (Is_Sorted_Body); begin return Is_Sorted_Body (Last, LT => LT); end Is_Sorted; procedure Merge ( Target_First : in out Node_Access; Target_Last : in out Node_Access; Length : in out Count_Type; Source_First : in out Node_Access; Source_Last : in out Node_Access; Source_Length : in out Count_Type; LT : not null access function ( Left, Right : not null Node_Access) return Boolean) is procedure Merge_Body is new Linked_Lists.Merge (Node, Node_Access); pragma Inline_Always (Merge_Body); begin Merge_Body ( Target_First, Target_Last, Length, Source_First, Source_Last, Source_Length, LT => LT); end Merge; procedure Merge_Sort ( Target_First : in out Node_Access; Target_Last : in out Node_Access; Length : in out Count_Type; LT : not null access function ( Left, Right : not null Node_Access) return Boolean) is procedure Merge_Sort_Body is new Linked_Lists.Merge_Sort (Node, Node_Access); -- no inline, Merge_Sort uses recursive calling begin Merge_Sort_Body (Target_First, Target_Last, Length, LT => LT); end Merge_Sort; end Ada.Containers.Naked_Doubly_Linked_Lists;
LionelDraghi/smk
Ada
1,408
ads
-- ----------------------------------------------------------------------------- -- smk, the smart make (http://lionel.draghi.free.fr/smk/) -- © 2018, 2019 Lionel Draghi <[email protected]> -- SPDX-License-Identifier: APSL-2.0 -- ----------------------------------------------------------------------------- -- 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 Smk.Files.File_Lists; procedure Smk.Files.Put (File_List : File_Lists.Map; Prefix : String := ""; Print_Sources : Boolean := False; Print_Targets : Boolean := False; Print_Unused : Boolean := False); -- Print files matching one of the boolean, in a one per line way. -- If Settings.Filter_System_Files, then ignore -- /lib /usr /etc /opt etc. files
reznikmm/matreshka
Ada
3,965
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with ODF.DOM.Db_Thousand_Attributes; package Matreshka.ODF_Db.Thousand_Attributes is type Db_Thousand_Attribute_Node is new Matreshka.ODF_Db.Abstract_Db_Attribute_Node and ODF.DOM.Db_Thousand_Attributes.ODF_Db_Thousand_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Db_Thousand_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Db_Thousand_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Db.Thousand_Attributes;
tum-ei-rcs/StratoX
Ada
16,411
adb
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS -- -- -- -- S Y S T E M . T A S K I N G . R E S T R I C T E D . S T A G E S -- -- -- -- B o d y -- -- -- -- Copyright (C) 1999-2014, 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. 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/>. -- -- -- -- GNARL was developed by the GNARL team at Florida State University. -- -- Extensive contributions were provided by Ada Core Technologies, Inc. -- -- -- ------------------------------------------------------------------------------ -- This is a simplified version of the System.Tasking.Stages package, for use -- with the ravenscar/HI-E profile. -- This package represents the high level tasking interface used by the -- compiler to expand Ada 95 tasking constructs into simpler run time calls. pragma Style_Checks (All_Checks); -- Turn off subprogram alpha order check, since we group soft link bodies and -- also separate off subprograms for restricted GNARLI. pragma Polling (Off); -- Turn off polling, we do not want ATC polling to take place during -- tasking operations. It causes infinite loops and other problems. with System.Task_Primitives.Operations; -- used for Enter_Task -- Wakeup -- Get_Priority -- Set_Priority -- Sleep with System.Secondary_Stack; -- used for SS_Init -- Default_Secondary_Stack_Size with System.Storage_Elements; -- used for Storage_Array package body System.Tasking.Restricted.Stages is use System.Secondary_Stack; use System.Task_Primitives.Operations; use System.Task_Info; Tasks_Activation_Chain : Task_Id; -- Chain of all the tasks to activate, when the sequential elaboration -- policy is used ----------------------- -- Local Subprograms -- ----------------------- procedure Activate_Tasks (Chain : Task_Id); -- Activate the list of tasks started by Chain procedure Create_Restricted_Task (Priority : Integer; Stack_Address : System.Address; Size : System.Parameters.Size_Type; Task_Info : System.Task_Info.Task_Info_Type; CPU : Integer; State : Task_Procedure_Access; Discriminants : System.Address; Created_Task : Task_Id); -- Code shared between Create_Restricted_Task (the concurrent version) and -- Create_Restricted_Task_Sequential. See comment of the former in the -- specification of this package. procedure Task_Wrapper (Self_ID : Task_Id); -- This is the procedure that is called by the GNULL from the new context -- when a task is created. It waits for activation and then calls the task -- body procedure. When the task body procedure completes, it terminates -- the task. ------------------ -- Task_Wrapper -- ------------------ -- The task wrapper is a procedure that is called first for each task -- task body, and which in turn calls the compiler-generated task body -- procedure. The wrapper's main job is to do initialization for the task. -- The variable ID in the task wrapper is used to implement the Self -- function on targets where there is a fast way to find the stack -- base of the current thread, since it should be at a fixed offset -- from the stack base. procedure Task_Wrapper (Self_ID : Task_Id) is use type System.Storage_Elements.Storage_Offset; Sec_Stack_Size : constant Storage_Elements.Storage_Offset := Self_ID.Common.Compiler_Data.Pri_Stack_Info.Size * SSE.Storage_Offset (Parameters.Sec_Stack_Percentage) / 100; Secondary_Stack : aliased Storage_Elements.Storage_Array (1 .. Sec_Stack_Size); for Secondary_Stack'Alignment use Standard'Maximum_Alignment; -- This is the secondary stack data. Note that it is critical that this -- have maximum alignment, since any kind of data can be allocated here. TH : Termination_Handler := null; begin Self_ID.Common.Compiler_Data.Sec_Stack_Addr := Secondary_Stack'Address; SS_Init (Secondary_Stack'Address, Integer (Sec_Stack_Size)); -- Initialize low-level TCB components, that cannot be initialized by -- the creator. Enter_Task (Self_ID); -- Call the task body procedure Self_ID.Common.Task_Entry_Point (Self_ID.Common.Task_Arg); -- Look for a fall-back handler. There is a single task termination -- procedure for all the tasks in the partition. -- This package is part of the restricted run time which supports -- neither task hierarchies (No_Task_Hierarchy) nor specific task -- termination handlers (No_Specific_Termination_Handlers). -- Raise the priority to prevent race conditions when using -- System.Tasking.Fall_Back_Handler. Set_Priority (Self_ID, Any_Priority'Last); TH := System.Tasking.Fall_Back_Handler; -- Restore original priority after retrieving shared data Set_Priority (Self_ID, Self_ID.Common.Base_Priority); -- Execute the task termination handler if we found it if TH /= null then TH.all (Self_ID); end if; -- We used to raise a Program_Error here to signal the task termination -- event in order to avoid silent task death. It has been removed -- because the Ada.Task_Termination functionality serves the same -- purpose in a more flexible (and standard) way. In addition, this -- exception triggered a second execution of the termination handler -- (if any was installed). We simply ensure that the task does not -- execute any more. Sleep (Self_ID, Terminated); end Task_Wrapper; ----------------------- -- Restricted GNARLI -- ----------------------- ----------------------------------- -- Activate_All_Tasks_Sequential -- ----------------------------------- procedure Activate_All_Tasks_Sequential is begin pragma Assert (Partition_Elaboration_Policy = 'S'); Activate_Tasks (Tasks_Activation_Chain); Tasks_Activation_Chain := Null_Task; end Activate_All_Tasks_Sequential; ------------------------------- -- Activate_Restricted_Tasks -- ------------------------------- procedure Activate_Restricted_Tasks (Chain_Access : Activation_Chain_Access) is begin if Partition_Elaboration_Policy = 'S' then -- In sequential elaboration policy, the chain must be empty. This -- procedure can be called if the unit has been compiled without -- partition elaboration policy, but the partition has a sequential -- elaboration policy. pragma Assert (Chain_Access.T_ID = Null_Task); null; else Activate_Tasks (Chain_Access.T_ID); Chain_Access.T_ID := Null_Task; end if; end Activate_Restricted_Tasks; -------------------- -- Activate_Tasks -- -------------------- procedure Activate_Tasks (Chain : Task_Id) is Self_ID : constant Task_Id := Task_Primitives.Operations.Self; C : Task_Id; Next_C : Task_Id; Success : Boolean; begin -- Raise the priority to prevent activated tasks from racing ahead -- before we finish activating the chain. Set_Priority (Self_ID, System.Any_Priority'Last); -- Activate all the tasks in the chain -- Creation of the thread of control was deferred until activation. -- So create it now. -- Note that since all created tasks will be blocked trying to get our -- (environment task) lock, there is no need to lock C here. C := Chain; while C /= Null_Task loop Next_C := C.Common.Activation_Link; C.Common.Activation_Link := null; Task_Primitives.Operations.Create_Task (T => C, Wrapper => Task_Wrapper'Address, Stack_Size => Parameters.Size_Type (C.Common.Compiler_Data.Pri_Stack_Info.Size), Priority => C.Common.Base_Priority, Base_CPU => C.Common.Base_CPU, Succeeded => Success); if Success then C.Common.State := Runnable; else raise Program_Error; end if; C := Next_C; end loop; Self_ID.Common.State := Runnable; -- Restore the original priority Set_Priority (Self_ID, Self_ID.Common.Base_Priority); end Activate_Tasks; ------------------------------------ -- Complete_Restricted_Activation -- ------------------------------------ procedure Complete_Restricted_Activation is begin -- Nothing to be done null; end Complete_Restricted_Activation; ------------------------------ -- Complete_Restricted_Task -- ------------------------------ procedure Complete_Restricted_Task is begin -- Mark the task as terminated. Do not suspend the task now -- because we need to allow for the task termination procedure -- to execute (if needed) in the Task_Wrapper. Task_Primitives.Operations.Self.Common.State := Terminated; end Complete_Restricted_Task; ---------------------------- -- Create_Restricted_Task -- ---------------------------- procedure Create_Restricted_Task (Priority : Integer; Stack_Address : System.Address; Size : System.Parameters.Size_Type; Task_Info : System.Task_Info.Task_Info_Type; CPU : Integer; State : Task_Procedure_Access; Discriminants : System.Address; Created_Task : Task_Id) is Base_Priority : System.Any_Priority; Base_CPU : System.Multiprocessors.CPU_Range; Success : Boolean; begin Base_Priority := (if Priority = Unspecified_Priority then System.Default_Priority else System.Any_Priority (Priority)); -- Legal values of CPU are the special Unspecified_CPU value which is -- inserted by the compiler for tasks without CPU aspect, and those in -- the range of CPU_Range but no greater than Number_Of_CPUs. Otherwise -- the task is defined to have failed, and it becomes a completed task -- (RM D.16(14/3)). if CPU /= Unspecified_CPU and then (CPU < Integer (System.Multiprocessors.CPU_Range'First) or else CPU > Integer (System.Multiprocessors.Number_Of_CPUs)) then raise Tasking_Error with "CPU not in range"; -- Normal CPU affinity else -- When the application code says nothing about the task affinity -- (task without CPU aspect) then the compiler inserts the -- Unspecified_CPU value which indicates to the run-time library that -- the task will activate and execute on the same processor as its -- activating task if the activating task is assigned a processor -- (RM D.16(14/3)). Base_CPU := (if CPU = Unspecified_CPU then Self.Common.Base_CPU else System.Multiprocessors.CPU_Range (CPU)); end if; -- No need to lock Self_ID here, since only environment task is running Initialize_ATCB (State, Discriminants, Base_Priority, Base_CPU, Task_Info, Stack_Address, Size, Created_Task, Success); if not Success then raise Program_Error; end if; Created_Task.Entry_Call.Self := Created_Task; end Create_Restricted_Task; procedure Create_Restricted_Task (Priority : Integer; Stack_Address : System.Address; Size : System.Parameters.Size_Type; Task_Info : System.Task_Info.Task_Info_Type; CPU : Integer; State : Task_Procedure_Access; Discriminants : System.Address; Elaborated : Access_Boolean; Chain : in out Activation_Chain; Task_Image : String; Created_Task : Task_Id) is begin if Partition_Elaboration_Policy = 'S' then -- A unit may have been compiled without partition elaboration -- policy, and in this case the compiler will emit calls for the -- default policy (concurrent). But if the partition policy is -- sequential, activation must be deferred. Create_Restricted_Task_Sequential (Priority, Stack_Address, Size, Task_Info, CPU, State, Discriminants, Elaborated, Task_Image, Created_Task); else Create_Restricted_Task (Priority, Stack_Address, Size, Task_Info, CPU, State, Discriminants, Created_Task); -- Append this task to the activation chain Created_Task.Common.Activation_Link := Chain.T_ID; Chain.T_ID := Created_Task; end if; end Create_Restricted_Task; --------------------------------------- -- Create_Restricted_Task_Sequential -- --------------------------------------- procedure Create_Restricted_Task_Sequential (Priority : Integer; Stack_Address : System.Address; Size : System.Parameters.Size_Type; Task_Info : System.Task_Info.Task_Info_Type; CPU : Integer; State : Task_Procedure_Access; Discriminants : System.Address; Elaborated : Access_Boolean; Task_Image : String; Created_Task : Task_Id) is pragma Unreferenced (Task_Image, Elaborated); begin Create_Restricted_Task (Priority, Stack_Address, Size, Task_Info, CPU, State, Discriminants, Created_Task); -- Append this task to the activation chain Created_Task.Common.Activation_Link := Tasks_Activation_Chain; Tasks_Activation_Chain := Created_Task; end Create_Restricted_Task_Sequential; --------------------------- -- Finalize_Global_Tasks -- --------------------------- -- Dummy version since this procedure is not used in true ravenscar mode procedure Finalize_Global_Tasks is begin raise Program_Error; end Finalize_Global_Tasks; --------------------------- -- Restricted_Terminated -- --------------------------- function Restricted_Terminated (T : Task_Id) return Boolean is begin return T.Common.State = Terminated; end Restricted_Terminated; begin Tasking.Initialize; end System.Tasking.Restricted.Stages;
annexi-strayline/ASAP-Unicode
Ada
3,445
ads
------------------------------------------------------------------------------ -- -- -- Unicode Utilities -- -- -- -- Case Folding Utilities -- -- -- -- ------------------------------------------------------------------------ -- -- -- -- Copyright (C) 2019, ANNEXI-STRAYLINE Trans-Human Ltd. -- -- All rights reserved. -- -- -- -- Original Contributors: -- -- * Richard Wai (ANNEXI-STRAYLINE) -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- -- -- * Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -- -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ package Unicode.Case_Folding with Pure is end;
ytomino/web-ada
Ada
6,524
adb
with Ada.Calendar; with Ada.Characters.Latin_1; with Ada.Command_Line; with Ada.Directories; with Ada.Streams.Stream_IO; with Ada.Text_IO.Text_Streams; with Web.HTML; with Web.Lock_Files; with Web.Producers; with Web.RSS; pragma Unreferenced (Web.RSS); procedure test_web is use type Ada.Calendar.Time; Verbose : Boolean := False; HT : Character renames Ada.Characters.Latin_1.HT; Template_Source : constant String := "template.html"; Template_Cache : constant String := Ada.Directories.Compose ( Ada.Directories.Containing_Directory (Ada.Command_Line.Command_Name), "template-cache.dat"); Lock_Name : constant String := Ada.Directories.Compose ( Ada.Directories.Containing_Directory (Ada.Command_Line.Command_Name), "lockfile"); Output_Name : constant String := Ada.Directories.Compose ( Ada.Directories.Containing_Directory (Ada.Command_Line.Command_Name), "out"); procedure Check_Line (F : in Ada.Text_IO.File_Type; S : in String) is Line : constant String := Ada.Text_IO.Get_Line (F); begin if Verbose then Ada.Text_IO.Put_Line (Line); end if; pragma Assert (Line = S); end Check_Line; procedure Try_Produce (By_Iterator : Boolean) is Lock : Web.Lock_Files.Lock_Type := Web.Lock_Files.Lock (Lock_Name); Output_File : Ada.Text_IO.File_Type; Output : Ada.Text_IO.Text_Streams.Stream_Access; Template_Source_File : Ada.Streams.Stream_IO.File_Type; Template_Cache_File : Ada.Streams.Stream_IO.File_Type; Is_Cache : Boolean; begin Ada.Text_IO.Create (Output_File, Name => Output_Name); Output := Ada.Text_IO.Text_Streams.Stream (Output_File); Web.Header_Content_Type (Output, Web.Text_HTML); Web.Header_Break (Output); Ada.Streams.Stream_IO.Open ( Template_Source_File, Ada.Streams.Stream_IO.In_File, Name => Template_Source); declare procedure Handler ( Output : not null access Ada.Streams.Root_Stream_Type'Class; Tag : in String; Contents : in Web.Producers.Template) is begin if Tag = "title" then Web.HTML.Write_In_HTML (Output, Web.HTML.HTML, "<<sample>>"); elsif Tag = "generator" then Web.HTML.Write_Begin_Attribute (Output, "content"); if By_Iterator then Web.HTML.Write_In_Attribute (Output, Web.HTML.HTML, "by iterator"); else -- by closure Web.HTML.Write_In_Attribute (Output, Web.HTML.HTML, "by closure"); end if; Web.HTML.Write_End_Attribute (Output); elsif Tag = "href" then String'Write (Output, "href="""); Web.HTML.Write_In_Attribute ( Output, Web.HTML.HTML, "http://www.google.co.jp/search?q=1%2B1"); Character'Write (Output, '"'); elsif Tag = "is_cache" then if Is_Cache then if By_Iterator then for I in Web.Producers.Produce (Output, Contents, "true") loop raise Web.Producers.Data_Error; end loop; else -- by closure Web.Producers.Produce (Output, Contents, "true"); end if; else if By_Iterator then for I in Web.Producers.Produce (Output, Contents, "false") loop raise Web.Producers.Data_Error; end loop; else -- by closure Web.Producers.Produce (Output, Contents, "false"); end if; end if; else raise Web.Producers.Data_Error; end if; end Handler; Template : Web.Producers.Template := Web.Producers.Read ( Ada.Streams.Stream_IO.Stream (Template_Source_File), Ada.Streams.Stream_Element_Count ( Ada.Streams.Stream_IO.Size (Template_Source_File)), Parsing => False); -- suppress parsing now begin if Ada.Directories.Exists (Template_Cache) and then Ada.Directories.Modification_Time (Template_Cache) > Ada.Directories.Modification_Time (Template_Source) then Is_Cache := True; -- read parsed-structure from cache file Ada.Streams.Stream_IO.Open (Template_Cache_File, Ada.Streams.Stream_IO.In_File, Name => Template_Cache); Web.Producers.Read_Parsed_Information ( Ada.Streams.Stream_IO.Stream (Template_Cache_File), Template); Ada.Streams.Stream_IO.Close (Template_Cache_File); else Is_Cache := False; Web.Producers.Parse (Template); -- save parsed-structure to cache file Ada.Streams.Stream_IO.Create ( Template_Cache_File, Ada.Streams.Stream_IO.Out_File, Name => Template_Cache); Web.Producers.Write_Parsed_Information ( Ada.Streams.Stream_IO.Stream (Template_Cache_File), Template); Ada.Streams.Stream_IO.Close (Template_Cache_File); end if; if By_Iterator then for I in Web.Producers.Produce (Output, Template) loop Handler (Output, Web.Producers.Tag (I), Web.Producers.Contents (I)); end loop; else -- by closure Web.Producers.Produce (Output, Template, Handler => Handler'Access); end if; end; Ada.Streams.Stream_IO.Close (Template_Source_File); Ada.Text_IO.Close (Output_File); -- check the content Ada.Text_IO.Open (Output_File, Ada.Text_IO.In_File, Name => Output_Name); Check_Line (Output_File, "content-type: text/html"); Check_Line (Output_File, ""); Check_Line (Output_File, "<html>"); Check_Line (Output_File, "<head>"); Check_Line (Output_File, HT & "<title>&lt;&lt;sample&gt;&gt;</title>"); if By_Iterator then Check_Line ( Output_File, HT & "<meta name=""GENERATOR"" content=""by iterator"" />"); else Check_Line ( Output_File, HT & "<meta name=""GENERATOR"" content=""by closure"" />"); end if; Check_Line (Output_File, "</head>"); Check_Line (Output_File, "<body>"); Check_Line ( Output_File, HT & "<a href=""http://www.google.co.jp/search?q=1%2B1"" >1 + 1 = ?" & "</a><br/>"); if Is_Cache then Check_Line (Output_File, HT & "this is cache."); else Check_Line (Output_File, HT & "this is parsed template."); end if; Check_Line (Output_File, "</body>"); Check_Line (Output_File, "</html>"); pragma Assert (Ada.Text_IO.End_Of_File (Output_File)); Ada.Text_IO.Close (Output_File); end Try_Produce; begin for I in 1 .. Ada.Command_Line.Argument_Count loop if Ada.Command_Line.Argument (I) = "-v" then Verbose := True; end if; end loop; for By_Iterator in Boolean loop for Cached in Boolean loop if not Cached and then Ada.Directories.Exists (Template_Cache) then Ada.Directories.Delete_File (Template_Cache); end if; Try_Produce (By_Iterator); end loop; end loop; pragma Assert (not Ada.Directories.Exists (Lock_Name)); -- finish Ada.Text_IO.Put_Line (Ada.Text_IO.Standard_Error.all, "ok"); end test_web;
zhmu/ananas
Ada
117,109
adb
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E M _ D I S P -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2022, 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 Aspects; use Aspects; with Atree; use Atree; with Debug; use Debug; with Elists; use Elists; with Einfo; use Einfo; with Einfo.Entities; use Einfo.Entities; with Einfo.Utils; use Einfo.Utils; with Exp_Disp; use Exp_Disp; with Exp_Util; use Exp_Util; with Exp_Ch6; use Exp_Ch6; with Exp_Ch7; use Exp_Ch7; with Exp_Tss; use Exp_Tss; with Errout; use Errout; with Freeze; use Freeze; with Lib.Xref; use Lib.Xref; with Namet; use Namet; with Nlists; use Nlists; with Nmake; use Nmake; with Opt; use Opt; with Output; use Output; with Restrict; use Restrict; with Rident; use Rident; with Sem; use Sem; with Sem_Aux; use Sem_Aux; with Sem_Ch6; use Sem_Ch6; with Sem_Ch8; use Sem_Ch8; with Sem_Eval; use Sem_Eval; with Sem_Type; use Sem_Type; with Sem_Util; use Sem_Util; with Snames; use Snames; with Sinfo; use Sinfo; with Sinfo.Nodes; use Sinfo.Nodes; with Sinfo.Utils; use Sinfo.Utils; with Tbuild; use Tbuild; with Uintp; use Uintp; with Warnsw; use Warnsw; package body Sem_Disp is ----------------------- -- Local Subprograms -- ----------------------- procedure Add_Dispatching_Operation (Tagged_Type : Entity_Id; New_Op : Entity_Id); -- Add New_Op in the list of primitive operations of Tagged_Type function Check_Controlling_Type (T : Entity_Id; Subp : Entity_Id) return Entity_Id; -- T is the tagged type of a formal parameter or the result of Subp. -- If the subprogram has a controlling parameter or result that matches -- the type, then returns the tagged type of that parameter or result -- (returning the designated tagged type in the case of an access -- parameter); otherwise returns empty. function Find_Hidden_Overridden_Primitive (S : Entity_Id) return Entity_Id; -- [Ada 2012:AI-0125] Find an inherited hidden primitive of the dispatching -- type of S that has the same name of S, a type-conformant profile, an -- original corresponding operation O that is a primitive of a visible -- ancestor of the dispatching type of S and O is visible at the point of -- of declaration of S. If the entity is found the Alias of S is set to the -- original corresponding operation S and its Overridden_Operation is set -- to the found entity; otherwise return Empty. -- -- This routine does not search for non-hidden primitives since they are -- covered by the normal Ada 2005 rules. function Is_Inherited_Public_Operation (Op : Entity_Id) return Boolean; -- Check whether a primitive operation is inherited from an operation -- declared in the visible part of its package. ------------------------------- -- Add_Dispatching_Operation -- ------------------------------- procedure Add_Dispatching_Operation (Tagged_Type : Entity_Id; New_Op : Entity_Id) is List : constant Elist_Id := Primitive_Operations (Tagged_Type); begin -- The dispatching operation may already be on the list, if it is the -- wrapper for an inherited function of a null extension (see Exp_Ch3 -- for the construction of function wrappers). The list of primitive -- operations must not contain duplicates. -- The Default_Initial_Condition and invariant procedures are not added -- to the list of primitives even when they are generated for a tagged -- type. These routines must not be targets of dispatching calls and -- therefore must not appear in the dispatch table because they already -- utilize class-wide-precondition semantics to handle inheritance and -- overriding. if Is_Suitable_Primitive (New_Op) then Append_Unique_Elmt (New_Op, List); end if; end Add_Dispatching_Operation; -------------------------- -- Covered_Interface_Op -- -------------------------- function Covered_Interface_Op (Prim : Entity_Id) return Entity_Id is Tagged_Type : constant Entity_Id := Find_Dispatching_Type (Prim); Elmt : Elmt_Id; E : Entity_Id; begin pragma Assert (Is_Dispatching_Operation (Prim)); -- Although this is a dispatching primitive we must check if its -- dispatching type is available because it may be the primitive -- of a private type not defined as tagged in its partial view. if Present (Tagged_Type) and then Has_Interfaces (Tagged_Type) then -- If the tagged type is frozen then the internal entities associated -- with interfaces are available in the list of primitives of the -- tagged type and can be used to speed up this search. if Is_Frozen (Tagged_Type) then Elmt := First_Elmt (Primitive_Operations (Tagged_Type)); while Present (Elmt) loop E := Node (Elmt); if Present (Interface_Alias (E)) and then Alias (E) = Prim then return Interface_Alias (E); end if; Next_Elmt (Elmt); end loop; -- Otherwise we must collect all the interface primitives and check -- if the Prim overrides (implements) some interface primitive. else declare Ifaces_List : Elist_Id; Iface_Elmt : Elmt_Id; Iface : Entity_Id; Iface_Prim : Entity_Id; begin Collect_Interfaces (Tagged_Type, Ifaces_List); Iface_Elmt := First_Elmt (Ifaces_List); while Present (Iface_Elmt) loop Iface := Node (Iface_Elmt); Elmt := First_Elmt (Primitive_Operations (Iface)); while Present (Elmt) loop Iface_Prim := Node (Elmt); if Chars (Iface_Prim) = Chars (Prim) and then Is_Interface_Conformant (Tagged_Type, Iface_Prim, Prim) then return Iface_Prim; end if; Next_Elmt (Elmt); end loop; Next_Elmt (Iface_Elmt); end loop; end; end if; end if; return Empty; end Covered_Interface_Op; ---------------------------------- -- Covered_Interface_Primitives -- ---------------------------------- function Covered_Interface_Primitives (Prim : Entity_Id) return Elist_Id is Tagged_Type : constant Entity_Id := Find_Dispatching_Type (Prim); Elmt : Elmt_Id; E : Entity_Id; Result : Elist_Id := No_Elist; begin pragma Assert (Is_Dispatching_Operation (Prim)); -- Although this is a dispatching primitive we must check if its -- dispatching type is available because it may be the primitive -- of a private type not defined as tagged in its partial view. if Present (Tagged_Type) and then Has_Interfaces (Tagged_Type) then -- If the tagged type is frozen then the internal entities associated -- with interfaces are available in the list of primitives of the -- tagged type and can be used to speed up this search. if Is_Frozen (Tagged_Type) then Elmt := First_Elmt (Primitive_Operations (Tagged_Type)); while Present (Elmt) loop E := Node (Elmt); if Present (Interface_Alias (E)) and then Alias (E) = Prim then if No (Result) then Result := New_Elmt_List; end if; Append_Elmt (Interface_Alias (E), Result); end if; Next_Elmt (Elmt); end loop; -- Otherwise we must collect all the interface primitives and check -- whether the Prim overrides (implements) some interface primitive. else declare Ifaces_List : Elist_Id; Iface_Elmt : Elmt_Id; Iface : Entity_Id; Iface_Prim : Entity_Id; begin Collect_Interfaces (Tagged_Type, Ifaces_List); Iface_Elmt := First_Elmt (Ifaces_List); while Present (Iface_Elmt) loop Iface := Node (Iface_Elmt); Elmt := First_Elmt (Primitive_Operations (Iface)); while Present (Elmt) loop Iface_Prim := Node (Elmt); if Chars (Iface_Prim) = Chars (Prim) and then Is_Interface_Conformant (Tagged_Type, Iface_Prim, Prim) then if No (Result) then Result := New_Elmt_List; end if; Append_Elmt (Iface_Prim, Result); end if; Next_Elmt (Elmt); end loop; Next_Elmt (Iface_Elmt); end loop; end; end if; end if; return Result; end Covered_Interface_Primitives; ------------------------------- -- Check_Controlling_Formals -- ------------------------------- procedure Check_Controlling_Formals (Typ : Entity_Id; Subp : Entity_Id) is Formal : Entity_Id; Ctrl_Type : Entity_Id; begin Formal := First_Formal (Subp); while Present (Formal) loop Ctrl_Type := Check_Controlling_Type (Etype (Formal), Subp); if Present (Ctrl_Type) then -- Obtain the full type in case we are looking at an incomplete -- view. if Ekind (Ctrl_Type) = E_Incomplete_Type and then Present (Full_View (Ctrl_Type)) then Ctrl_Type := Full_View (Ctrl_Type); end if; -- When controlling type is concurrent and declared within a -- generic or inside an instance use corresponding record type. if Is_Concurrent_Type (Ctrl_Type) and then Present (Corresponding_Record_Type (Ctrl_Type)) then Ctrl_Type := Corresponding_Record_Type (Ctrl_Type); end if; if Ctrl_Type = Typ then Set_Is_Controlling_Formal (Formal); -- Ada 2005 (AI-231): Anonymous access types that are used in -- controlling parameters exclude null because it is necessary -- to read the tag to dispatch, and null has no tag. if Ekind (Etype (Formal)) = E_Anonymous_Access_Type then Set_Can_Never_Be_Null (Etype (Formal)); Set_Is_Known_Non_Null (Etype (Formal)); end if; -- Check that the parameter's nominal subtype statically -- matches the first subtype. if Ekind (Etype (Formal)) = E_Anonymous_Access_Type then if not Subtypes_Statically_Match (Typ, Designated_Type (Etype (Formal))) then Error_Msg_N ("parameter subtype does not match controlling type", Formal); end if; -- Within a predicate function, the formal may be a subtype -- of a tagged type, given that the predicate is expressed -- in terms of the subtype. elsif not Subtypes_Statically_Match (Typ, Etype (Formal)) and then not Is_Predicate_Function (Subp) then Error_Msg_N ("parameter subtype does not match controlling type", Formal); end if; if Present (Default_Value (Formal)) then -- In Ada 2005, access parameters can have defaults if Ekind (Etype (Formal)) = E_Anonymous_Access_Type and then Ada_Version < Ada_2005 then Error_Msg_N ("default not allowed for controlling access parameter", Default_Value (Formal)); elsif not Is_Tag_Indeterminate (Default_Value (Formal)) then Error_Msg_N ("default expression must be a tag indeterminate" & " function call", Default_Value (Formal)); end if; end if; elsif Comes_From_Source (Subp) then Error_Msg_N ("operation can be dispatching in only one type", Subp); end if; end if; Next_Formal (Formal); end loop; if Ekind (Subp) in E_Function | E_Generic_Function then Ctrl_Type := Check_Controlling_Type (Etype (Subp), Subp); if Present (Ctrl_Type) then if Ctrl_Type = Typ then Set_Has_Controlling_Result (Subp); -- Check that result subtype statically matches first subtype -- (Ada 2005): Subp may have a controlling access result. if Subtypes_Statically_Match (Typ, Etype (Subp)) or else (Ekind (Etype (Subp)) = E_Anonymous_Access_Type and then Subtypes_Statically_Match (Typ, Designated_Type (Etype (Subp)))) then null; else Error_Msg_N ("result subtype does not match controlling type", Subp); end if; elsif Comes_From_Source (Subp) then Error_Msg_N ("operation can be dispatching in only one type", Subp); end if; end if; end if; end Check_Controlling_Formals; ---------------------------- -- Check_Controlling_Type -- ---------------------------- function Check_Controlling_Type (T : Entity_Id; Subp : Entity_Id) return Entity_Id is Tagged_Type : Entity_Id := Empty; begin if Is_Tagged_Type (T) then if Is_First_Subtype (T) then Tagged_Type := T; else Tagged_Type := Base_Type (T); end if; -- If the type is incomplete, it may have been declared without a -- Tagged indication, but the full view may be tagged, in which case -- that is the controlling type of the subprogram. This is one of the -- approx. 579 places in the language where a lookahead would help. elsif Ekind (T) = E_Incomplete_Type and then Present (Full_View (T)) and then Is_Tagged_Type (Full_View (T)) then Set_Is_Tagged_Type (T); Tagged_Type := Full_View (T); elsif Ekind (T) = E_Anonymous_Access_Type and then Is_Tagged_Type (Designated_Type (T)) then if Ekind (Designated_Type (T)) /= E_Incomplete_Type then if Is_First_Subtype (Designated_Type (T)) then Tagged_Type := Designated_Type (T); else Tagged_Type := Base_Type (Designated_Type (T)); end if; -- Ada 2005: an incomplete type can be tagged. An operation with an -- access parameter of the type is dispatching. elsif Scope (Designated_Type (T)) = Current_Scope then Tagged_Type := Designated_Type (T); -- Ada 2005 (AI-50217) elsif From_Limited_With (Designated_Type (T)) and then Has_Non_Limited_View (Designated_Type (T)) and then Scope (Designated_Type (T)) = Scope (Subp) then if Is_First_Subtype (Non_Limited_View (Designated_Type (T))) then Tagged_Type := Non_Limited_View (Designated_Type (T)); else Tagged_Type := Base_Type (Non_Limited_View (Designated_Type (T))); end if; end if; end if; if No (Tagged_Type) or else Is_Class_Wide_Type (Tagged_Type) then return Empty; -- In the special case of a protected subprogram of a tagged protected -- type that has a formal of a tagged type (or access formal whose type -- designates a tagged type), such a formal is not controlling unless -- it's of the protected type's corresponding record type. The latter -- can occur for the special wrapper subprograms created for protected -- subprograms. Such subprograms may occur in the same scope where some -- formal's tagged type is declared, and we don't want formals of that -- tagged type being marked as controlling, for one thing because they -- aren't controlling from the language point of view, but also because -- this can cause errors for access formals when conformance is checked -- between the spec and body of the protected subprogram (null-exclusion -- status of the formals may be set differently, which is the case that -- led to adding this check). elsif Is_Subprogram (Subp) and then Present (Protected_Subprogram (Subp)) and then Ekind (Scope (Protected_Subprogram (Subp))) = E_Protected_Type and then Base_Type (Tagged_Type) /= Corresponding_Record_Type (Scope (Protected_Subprogram (Subp))) then return Empty; -- The dispatching type and the primitive operation must be defined in -- the same scope, except in the case of internal operations and formal -- abstract subprograms. elsif ((Scope (Subp) = Scope (Tagged_Type) or else Is_Internal (Subp)) and then (not Is_Generic_Type (Tagged_Type) or else not Comes_From_Source (Subp))) or else (Is_Formal_Subprogram (Subp) and then Is_Abstract_Subprogram (Subp)) or else (Nkind (Parent (Parent (Subp))) = N_Subprogram_Renaming_Declaration and then Present (Corresponding_Formal_Spec (Parent (Parent (Subp)))) and then Is_Abstract_Subprogram (Subp)) then return Tagged_Type; else return Empty; end if; end Check_Controlling_Type; ---------------------------- -- Check_Dispatching_Call -- ---------------------------- procedure Check_Dispatching_Call (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Actual : Node_Id; Formal : Entity_Id; Control : Node_Id := Empty; Func : Entity_Id; Subp_Entity : Entity_Id; Indeterm_Ancestor_Call : Boolean := False; Indeterm_Ctrl_Type : Entity_Id := Empty; -- init to avoid warning Static_Tag : Node_Id := Empty; -- If a controlling formal has a statically tagged actual, the tag of -- this actual is to be used for any tag-indeterminate actual. procedure Check_Direct_Call; -- In the case when the controlling actual is a class-wide type whose -- root type's completion is a task or protected type, the call is in -- fact direct. This routine detects the above case and modifies the -- call accordingly. procedure Check_Dispatching_Context (Call : Node_Id); -- If the call is tag-indeterminate and the entity being called is -- abstract, verify that the context is a call that will eventually -- provide a tag for dispatching, or has provided one already. ----------------------- -- Check_Direct_Call -- ----------------------- procedure Check_Direct_Call is Typ : Entity_Id := Etype (Control); begin -- Predefined primitives do not receive wrappers since they are built -- from scratch for the corresponding record of synchronized types. -- Equality is in general predefined, but is excluded from the check -- when it is user-defined. if Is_Predefined_Dispatching_Operation (Subp_Entity) and then not Is_User_Defined_Equality (Subp_Entity) then return; end if; if Is_Class_Wide_Type (Typ) then Typ := Root_Type (Typ); end if; if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then Typ := Full_View (Typ); end if; if Is_Concurrent_Type (Typ) and then Present (Corresponding_Record_Type (Typ)) then Typ := Corresponding_Record_Type (Typ); -- The concurrent record's list of primitives should contain a -- wrapper for the entity of the call, retrieve it. declare Prim : Entity_Id; Prim_Elmt : Elmt_Id; Wrapper_Found : Boolean := False; begin Prim_Elmt := First_Elmt (Primitive_Operations (Typ)); while Present (Prim_Elmt) loop Prim := Node (Prim_Elmt); if Is_Primitive_Wrapper (Prim) and then Wrapped_Entity (Prim) = Subp_Entity then Wrapper_Found := True; exit; end if; Next_Elmt (Prim_Elmt); end loop; -- A primitive declared between two views should have a -- corresponding wrapper. pragma Assert (Wrapper_Found); -- Modify the call by setting the proper entity Set_Entity (Name (N), Prim); end; end if; end Check_Direct_Call; ------------------------------- -- Check_Dispatching_Context -- ------------------------------- procedure Check_Dispatching_Context (Call : Node_Id) is Subp : constant Entity_Id := Entity (Name (Call)); procedure Abstract_Context_Error; -- Error for abstract call dispatching on result is not dispatching function Has_Controlling_Current_Instance_Actual_In_DIC (Call : Node_Id) return Boolean; -- Return True if the subprogram call Call has a controlling actual -- given directly by a current instance referenced within a DIC -- aspect. ---------------------------- -- Abstract_Context_Error -- ---------------------------- procedure Abstract_Context_Error is begin if Ekind (Subp) = E_Function then Error_Msg_N ("call to abstract function must be dispatching", N); -- This error can occur for a procedure in the case of a call to -- an abstract formal procedure with a statically tagged operand. else Error_Msg_N ("call to abstract procedure must be dispatching", N); end if; end Abstract_Context_Error; ---------------------------------------- -- Has_Current_Instance_Actual_In_DIC -- ---------------------------------------- function Has_Controlling_Current_Instance_Actual_In_DIC (Call : Node_Id) return Boolean is A : Node_Id; F : Entity_Id; begin F := First_Formal (Subp_Entity); A := First_Actual (Call); while Present (F) loop -- Return True if the actual denotes a current instance (which -- will be represented by an in-mode formal of the enclosing -- DIC_Procedure) passed to a controlling formal. We don't have -- to worry about controlling access formals here, because its -- illegal to apply Access (etc.) attributes to a current -- instance within an aspect (by AI12-0068). if Is_Controlling_Formal (F) and then Nkind (A) = N_Identifier and then Ekind (Entity (A)) = E_In_Parameter and then Is_Subprogram (Scope (Entity (A))) and then Is_DIC_Procedure (Scope (Entity (A))) then return True; end if; Next_Formal (F); Next_Actual (A); end loop; return False; end Has_Controlling_Current_Instance_Actual_In_DIC; -- Local variables Scop : constant Entity_Id := Current_Scope_No_Loops; Typ : constant Entity_Id := Etype (Subp); Par : Node_Id; -- Start of processing for Check_Dispatching_Context begin -- Skip checking context of dispatching calls during preanalysis of -- class-wide conditions since at that stage the expression is not -- installed yet on its definite context. if Inside_Class_Condition_Preanalysis then return; end if; -- If the called subprogram is a private overriding, replace it -- with its alias, which has the correct body. Verify that the -- two subprograms have the same controlling type (this is not the -- case for an inherited subprogram that has become abstract). if Is_Abstract_Subprogram (Subp) and then No (Controlling_Argument (Call)) then if Present (Alias (Subp)) and then not Is_Abstract_Subprogram (Alias (Subp)) and then No (DTC_Entity (Subp)) and then Find_Dispatching_Type (Subp) = Find_Dispatching_Type (Alias (Subp)) then -- Private overriding of inherited abstract operation, call is -- legal. Set_Entity (Name (N), Alias (Subp)); return; -- If this is a pre/postcondition for an abstract subprogram, -- it may call another abstract function that is a primitive -- of an abstract type. The call is nondispatching but will be -- legal in overridings of the operation. However, if the call -- is tag-indeterminate we want to continue with with the error -- checking below, as this case is illegal even for abstract -- subprograms (see AI12-0170). -- Similarly, as per AI12-0412, a nonabstract subprogram may -- have a class-wide pre/postcondition that includes a call to -- an abstract primitive of the subprogram's controlling type. -- Certain operations (nondispatching calls, 'Access, use as -- a generic actual) applied to such a nonabstract subprogram -- are illegal in the case where the type is abstract (see -- RM 6.1.1(18.2/5)). elsif Is_Subprogram (Scop) and then not Is_Tag_Indeterminate (N) and then In_Pre_Post_Condition (Call, Class_Wide_Only => True) -- The tagged type associated with the called subprogram must be -- the same as that of the subprogram with a class-wide aspect. and then Is_Dispatching_Operation (Scop) and then Find_Dispatching_Type (Subp) = Find_Dispatching_Type (Scop) then null; -- Similarly to the dispensation for postconditions, a call to -- an abstract function within a Default_Initial_Condition aspect -- can be legal when passed a current instance of the type. Such -- a call will be effectively mapped to a call to a primitive of -- a descendant type (see AI12-0397, as well as AI12-0170), so -- doesn't need to be dispatching. We test for being within a DIC -- procedure, since that's where the call will be analyzed. elsif Is_Subprogram (Scop) and then Is_DIC_Procedure (Scop) and then Has_Controlling_Current_Instance_Actual_In_DIC (Call) then null; elsif Ekind (Current_Scope) = E_Function and then Nkind (Unit_Declaration_Node (Scop)) = N_Generic_Subprogram_Declaration then null; else -- We need to determine whether the context of the call -- provides a tag to make the call dispatching. This requires -- the call to be the actual in an enclosing call, and that -- actual must be controlling. If the call is an operand of -- equality, the other operand must not be abstract. if not Is_Tagged_Type (Typ) and then not (Ekind (Typ) = E_Anonymous_Access_Type and then Is_Tagged_Type (Designated_Type (Typ))) then Abstract_Context_Error; return; end if; Par := Parent (Call); if Nkind (Par) = N_Parameter_Association then Par := Parent (Par); end if; if Nkind (Par) = N_Qualified_Expression or else Nkind (Par) = N_Unchecked_Type_Conversion then Par := Parent (Par); end if; if Nkind (Par) in N_Subprogram_Call and then Is_Entity_Name (Name (Par)) then declare Enc_Subp : constant Entity_Id := Entity (Name (Par)); A : Node_Id; F : Entity_Id; Control : Entity_Id; Ret_Type : Entity_Id; begin -- Find controlling formal that can provide tag for the -- tag-indeterminate actual. The corresponding actual -- must be the corresponding class-wide type. F := First_Formal (Enc_Subp); A := First_Actual (Par); -- Find controlling type of call. Dereference if function -- returns an access type. Ret_Type := Etype (Call); if Is_Access_Type (Etype (Call)) then Ret_Type := Designated_Type (Ret_Type); end if; while Present (F) loop Control := Etype (A); if Is_Access_Type (Control) then Control := Designated_Type (Control); end if; if Is_Controlling_Formal (F) and then not (Call = A or else Parent (Call) = A) and then Control = Class_Wide_Type (Ret_Type) then return; end if; Next_Formal (F); Next_Actual (A); end loop; if Nkind (Par) = N_Function_Call and then Is_Tag_Indeterminate (Par) then -- The parent may be an actual of an enclosing call Check_Dispatching_Context (Par); return; else Error_Msg_N ("call to abstract function must be dispatching", Call); return; end if; end; -- For equality operators, one of the operands must be -- statically or dynamically tagged. elsif Nkind (Par) in N_Op_Eq | N_Op_Ne then if N = Right_Opnd (Par) and then Is_Tag_Indeterminate (Left_Opnd (Par)) then Abstract_Context_Error; elsif N = Left_Opnd (Par) and then Is_Tag_Indeterminate (Right_Opnd (Par)) then Abstract_Context_Error; end if; return; -- The left-hand side of an assignment provides the tag elsif Nkind (Par) = N_Assignment_Statement then return; else Abstract_Context_Error; end if; end if; end if; end Check_Dispatching_Context; -- Start of processing for Check_Dispatching_Call begin -- Find a controlling argument, if any if Present (Parameter_Associations (N)) then Subp_Entity := Entity (Name (N)); Actual := First_Actual (N); Formal := First_Formal (Subp_Entity); while Present (Actual) loop Control := Find_Controlling_Arg (Actual); exit when Present (Control); -- Check for the case where the actual is a tag-indeterminate call -- whose result type is different than the tagged type associated -- with the containing call, but is an ancestor of the type. if Is_Controlling_Formal (Formal) and then Is_Tag_Indeterminate (Actual) and then Base_Type (Etype (Actual)) /= Base_Type (Etype (Formal)) and then Is_Ancestor (Etype (Actual), Etype (Formal)) then Indeterm_Ancestor_Call := True; Indeterm_Ctrl_Type := Etype (Formal); -- If the formal is controlling but the actual is not, the type -- of the actual is statically known, and may be used as the -- controlling tag for some other tag-indeterminate actual. elsif Is_Controlling_Formal (Formal) and then Is_Entity_Name (Actual) and then Is_Tagged_Type (Etype (Actual)) then Static_Tag := Actual; end if; Next_Actual (Actual); Next_Formal (Formal); end loop; -- If the call doesn't have a controlling actual but does have an -- indeterminate actual that requires dispatching treatment, then an -- object is needed that will serve as the controlling argument for -- a dispatching call on the indeterminate actual. This can occur -- in the unusual situation of a default actual given by a tag- -- indeterminate call and where the type of the call is an ancestor -- of the type associated with a containing call to an inherited -- operation (see AI-239). -- Rather than create an object of the tagged type, which would -- be problematic for various reasons (default initialization, -- discriminants), the tag of the containing call's associated -- tagged type is directly used to control the dispatching. if No (Control) and then Indeterm_Ancestor_Call and then No (Static_Tag) then Control := Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Indeterm_Ctrl_Type, Loc), Attribute_Name => Name_Tag); Analyze (Control); end if; if Present (Control) then -- Verify that no controlling arguments are statically tagged if Debug_Flag_E then Write_Str ("Found Dispatching call"); Write_Int (Int (N)); Write_Eol; end if; Actual := First_Actual (N); while Present (Actual) loop if Actual /= Control then if not Is_Controlling_Actual (Actual) then null; -- Can be anything elsif Is_Dynamically_Tagged (Actual) then null; -- Valid parameter elsif Is_Tag_Indeterminate (Actual) then -- The tag is inherited from the enclosing call (the node -- we are currently analyzing). Explicitly expand the -- actual, since the previous call to Expand (from -- Resolve_Call) had no way of knowing about the -- required dispatching. Propagate_Tag (Control, Actual); else Error_Msg_N ("controlling argument is not dynamically tagged", Actual); return; end if; end if; Next_Actual (Actual); end loop; -- Mark call as a dispatching call Set_Controlling_Argument (N, Control); Check_Restriction (No_Dispatching_Calls, N); -- The dispatching call may need to be converted into a direct -- call in certain cases. Check_Direct_Call; -- If there is a statically tagged actual and a tag-indeterminate -- call to a function of the ancestor (such as that provided by a -- default), then treat this as a dispatching call and propagate -- the tag to the tag-indeterminate call(s). elsif Present (Static_Tag) and then Indeterm_Ancestor_Call then Control := Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Etype (Static_Tag), Loc), Attribute_Name => Name_Tag); Analyze (Control); Actual := First_Actual (N); Formal := First_Formal (Subp_Entity); while Present (Actual) loop if Is_Tag_Indeterminate (Actual) and then Is_Controlling_Formal (Formal) then Propagate_Tag (Control, Actual); end if; Next_Actual (Actual); Next_Formal (Formal); end loop; Check_Dispatching_Context (N); elsif Nkind (N) /= N_Function_Call then -- The call is not dispatching, so check that there aren't any -- tag-indeterminate abstract calls left among its actuals. Actual := First_Actual (N); while Present (Actual) loop if Is_Tag_Indeterminate (Actual) then -- Function call case if Nkind (Original_Node (Actual)) = N_Function_Call then Func := Entity (Name (Original_Node (Actual))); -- If the actual is an attribute then it can't be abstract -- (the only current case of a tag-indeterminate attribute -- is the stream Input attribute). elsif Nkind (Original_Node (Actual)) = N_Attribute_Reference then Func := Empty; -- Ditto if it is an explicit dereference elsif Nkind (Original_Node (Actual)) = N_Explicit_Dereference then Func := Empty; -- Only other possibility is a qualified expression whose -- constituent expression is itself a call. else Func := Entity (Name (Original_Node (Expression (Original_Node (Actual))))); end if; if Present (Func) and then Is_Abstract_Subprogram (Func) then Error_Msg_N ("call to abstract function must be dispatching", Actual); end if; end if; Next_Actual (Actual); end loop; Check_Dispatching_Context (N); elsif Nkind (Parent (N)) in N_Subexpr then Check_Dispatching_Context (N); elsif Nkind (Parent (N)) = N_Assignment_Statement and then Is_Class_Wide_Type (Etype (Name (Parent (N)))) then return; elsif Is_Abstract_Subprogram (Subp_Entity) then Check_Dispatching_Context (N); return; end if; -- If this is a nondispatching call to a nonabstract subprogram -- and the subprogram has any Pre'Class or Post'Class aspects with -- nonstatic values, then report an error. This is specified by -- RM 6.1.1(18.2/5) (by AI12-0412). -- Skip reporting this error on helpers and indirect-call wrappers -- built to support class-wide preconditions. if No (Control) and then not Is_Abstract_Subprogram (Subp_Entity) and then Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post (Subp_Entity) and then not (Is_Subprogram (Current_Scope) and then Present (Class_Preconditions_Subprogram (Current_Scope))) then Error_Msg_N ("nondispatching call to nonabstract subprogram of " & "abstract type with nonstatic class-wide " & "pre/postconditions", N); end if; else -- If dispatching on result, the enclosing call, if any, will -- determine the controlling argument. Otherwise this is the -- primitive operation of the root type. Check_Dispatching_Context (N); end if; end Check_Dispatching_Call; --------------------------------- -- Check_Dispatching_Operation -- --------------------------------- procedure Check_Dispatching_Operation (Subp, Old_Subp : Entity_Id) is function Is_Access_To_Subprogram_Wrapper (E : Entity_Id) return Boolean; -- Return True if E is an access to subprogram wrapper procedure Warn_On_Late_Primitive_After_Private_Extension (Typ : Entity_Id; Prim : Entity_Id); -- Prim is a dispatching primitive of the tagged type Typ. Warn on Prim -- if it is a public primitive defined after some private extension of -- the tagged type. ------------------------------------- -- Is_Access_To_Subprogram_Wrapper -- ------------------------------------- function Is_Access_To_Subprogram_Wrapper (E : Entity_Id) return Boolean is Decl_N : constant Node_Id := Unit_Declaration_Node (E); Par_N : constant Node_Id := Parent (List_Containing (Decl_N)); begin -- Access to subprogram wrappers are declared in the freezing actions return Nkind (Par_N) = N_Freeze_Entity and then Ekind (Entity (Par_N)) = E_Access_Subprogram_Type; end Is_Access_To_Subprogram_Wrapper; ---------------------------------------------------- -- Warn_On_Late_Primitive_After_Private_Extension -- ---------------------------------------------------- procedure Warn_On_Late_Primitive_After_Private_Extension (Typ : Entity_Id; Prim : Entity_Id) is E : Entity_Id; begin if Warn_On_Late_Primitives and then Comes_From_Source (Prim) and then Has_Private_Extension (Typ) and then Is_Package_Or_Generic_Package (Current_Scope) and then not In_Private_Part (Current_Scope) then E := Next_Entity (Typ); while E /= Prim loop if Ekind (E) = E_Record_Type_With_Private and then Etype (E) = Typ then Error_Msg_Name_1 := Chars (Typ); Error_Msg_Name_2 := Chars (E); Error_Msg_Sloc := Sloc (E); Error_Msg_N ("?j?primitive of type % defined after private extension " & "% #?", Prim); Error_Msg_Name_1 := Chars (Prim); Error_Msg_Name_2 := Chars (E); Error_Msg_N ("\spec of % should appear before declaration of type %!", Prim); exit; end if; Next_Entity (E); end loop; end if; end Warn_On_Late_Primitive_After_Private_Extension; -- Local variables Body_Is_Last_Primitive : Boolean := False; Has_Dispatching_Parent : Boolean := False; Ovr_Subp : Entity_Id := Empty; Tagged_Type : Entity_Id; -- Start of processing for Check_Dispatching_Operation begin if Ekind (Subp) not in E_Function | E_Procedure then return; -- The Default_Initial_Condition procedure is not a primitive subprogram -- even if it relates to a tagged type. This routine is not meant to be -- inherited or overridden. elsif Is_DIC_Procedure (Subp) then return; -- The "partial" and "full" type invariant procedures are not primitive -- subprograms even if they relate to a tagged type. These routines are -- not meant to be inherited or overridden. elsif Is_Invariant_Procedure (Subp) or else Is_Partial_Invariant_Procedure (Subp) then return; -- Wrappers of access to subprograms are not primitive subprograms. elsif Is_Wrapper (Subp) and then Is_Access_To_Subprogram_Wrapper (Subp) then return; end if; Set_Is_Dispatching_Operation (Subp, False); Tagged_Type := Find_Dispatching_Type (Subp); -- Ada 2005 (AI-345): Use the corresponding record (if available). -- Required because primitives of concurrent types are attached -- to the corresponding record (not to the concurrent type). if Ada_Version >= Ada_2005 and then Present (Tagged_Type) and then Is_Concurrent_Type (Tagged_Type) and then Present (Corresponding_Record_Type (Tagged_Type)) then Tagged_Type := Corresponding_Record_Type (Tagged_Type); end if; -- (AI-345): The task body procedure is not a primitive of the tagged -- type if Present (Tagged_Type) and then Is_Concurrent_Record_Type (Tagged_Type) and then Present (Corresponding_Concurrent_Type (Tagged_Type)) and then Is_Task_Type (Corresponding_Concurrent_Type (Tagged_Type)) and then Subp = Get_Task_Body_Procedure (Corresponding_Concurrent_Type (Tagged_Type)) then return; end if; -- If Subp is derived from a dispatching operation then it should -- always be treated as dispatching. In this case various checks -- below will be bypassed. Makes sure that late declarations for -- inherited private subprograms are treated as dispatching, even -- if the associated tagged type is already frozen. Has_Dispatching_Parent := Present (Alias (Subp)) and then Is_Dispatching_Operation (Alias (Subp)); if No (Tagged_Type) then -- Ada 2005 (AI-251): Check that Subp is not a primitive associated -- with an abstract interface type unless the interface acts as a -- parent type in a derivation. If the interface type is a formal -- type then the operation is not primitive and therefore legal. declare E : Entity_Id; Typ : Entity_Id; begin E := First_Entity (Subp); while Present (E) loop -- For an access parameter, check designated type if Ekind (Etype (E)) = E_Anonymous_Access_Type then Typ := Designated_Type (Etype (E)); else Typ := Etype (E); end if; if Comes_From_Source (Subp) and then Is_Interface (Typ) and then not Is_Class_Wide_Type (Typ) and then not Is_Derived_Type (Typ) and then not Is_Generic_Type (Typ) and then not In_Instance then Error_Msg_N ("??declaration of& is too late!", Subp); Error_Msg_NE -- CODEFIX?? ("\??spec should appear immediately after declaration of " & "& !", Subp, Typ); exit; end if; Next_Entity (E); end loop; -- In case of functions check also the result type if Ekind (Subp) = E_Function then if Is_Access_Type (Etype (Subp)) then Typ := Designated_Type (Etype (Subp)); else Typ := Etype (Subp); end if; -- The following should be better commented, especially since -- we just added several new conditions here ??? if Comes_From_Source (Subp) and then Is_Interface (Typ) and then not Is_Class_Wide_Type (Typ) and then not Is_Derived_Type (Typ) and then not Is_Generic_Type (Typ) and then not In_Instance then Error_Msg_N ("??declaration of& is too late!", Subp); Error_Msg_NE ("\??spec should appear immediately after declaration of " & "& !", Subp, Typ); end if; end if; end; return; -- The subprograms build internally after the freezing point (such as -- init procs, interface thunks, type support subprograms, and Offset -- to top functions for accessing interface components in variable -- size tagged types) are not primitives. elsif Is_Frozen (Tagged_Type) and then not Comes_From_Source (Subp) and then not Has_Dispatching_Parent then -- Complete decoration of internally built subprograms that override -- a dispatching primitive. These entities correspond with the -- following cases: -- 1. Ada 2005 (AI-391): Wrapper functions built by the expander -- to override functions of nonabstract null extensions. These -- primitives were added to the list of primitives of the tagged -- type by Make_Controlling_Function_Wrappers. However, attribute -- Is_Dispatching_Operation must be set to true. -- 2. Ada 2005 (AI-251): Wrapper procedures of null interface -- primitives. -- 3. Subprograms associated with stream attributes (built by -- New_Stream_Subprogram) or with the Put_Image attribute. -- 4. Wrappers built for inherited operations with inherited class- -- wide conditions, where the conditions include calls to other -- overridden primitives. The wrappers include checks on these -- modified conditions. (AI12-113). -- 5. Declarations built for subprograms without separate specs that -- are eligible for inlining in GNATprove (inside -- Sem_Ch6.Analyze_Subprogram_Body_Helper). if Present (Old_Subp) and then Present (Overridden_Operation (Subp)) and then Is_Dispatching_Operation (Old_Subp) then pragma Assert ((Ekind (Subp) = E_Function and then Is_Dispatching_Operation (Old_Subp) and then Is_Null_Extension (Base_Type (Etype (Subp)))) or else (Ekind (Subp) = E_Procedure and then Is_Dispatching_Operation (Old_Subp) and then Present (Alias (Old_Subp)) and then Is_Null_Interface_Primitive (Ultimate_Alias (Old_Subp))) or else Get_TSS_Name (Subp) = TSS_Stream_Read or else Get_TSS_Name (Subp) = TSS_Stream_Write or else Get_TSS_Name (Subp) = TSS_Put_Image or else (Is_Wrapper (Subp) and then Present (LSP_Subprogram (Subp))) or else GNATprove_Mode); Check_Controlling_Formals (Tagged_Type, Subp); Override_Dispatching_Operation (Tagged_Type, Old_Subp, Subp); Set_Is_Dispatching_Operation (Subp); end if; return; -- The operation may be a child unit, whose scope is the defining -- package, but which is not a primitive operation of the type. elsif Is_Child_Unit (Subp) then return; -- If the subprogram is not defined in a package spec, the only case -- where it can be a dispatching op is when it overrides an operation -- before the freezing point of the type. elsif ((not Is_Package_Or_Generic_Package (Scope (Subp))) or else In_Package_Body (Scope (Subp))) and then not Has_Dispatching_Parent then if not Comes_From_Source (Subp) or else (Present (Old_Subp) and then not Is_Frozen (Tagged_Type)) then null; -- If the type is already frozen, the overriding is not allowed -- except when Old_Subp is not a dispatching operation (which can -- occur when Old_Subp was inherited by an untagged type). However, -- a body with no previous spec freezes the type *after* its -- declaration, and therefore is a legal overriding (unless the type -- has already been frozen). Only the first such body is legal. elsif Present (Old_Subp) and then Is_Dispatching_Operation (Old_Subp) then if Comes_From_Source (Subp) and then (Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Body or else Nkind (Unit_Declaration_Node (Subp)) in N_Body_Stub) then declare Subp_Body : constant Node_Id := Unit_Declaration_Node (Subp); Decl_Item : Node_Id; begin -- ??? The checks here for whether the type has been frozen -- prior to the new body are not complete. It's not simple -- to check frozenness at this point since the body has -- already caused the type to be prematurely frozen in -- Analyze_Declarations, but we're forced to recheck this -- here because of the odd rule interpretation that allows -- the overriding if the type wasn't frozen prior to the -- body. The freezing action should probably be delayed -- until after the spec is seen, but that's a tricky -- change to the delicate freezing code. -- Look at each declaration following the type up until the -- new subprogram body. If any of the declarations is a body -- then the type has been frozen already so the overriding -- primitive is illegal. Decl_Item := Next (Parent (Tagged_Type)); while Present (Decl_Item) and then (Decl_Item /= Subp_Body) loop if Comes_From_Source (Decl_Item) and then (Nkind (Decl_Item) in N_Proper_Body or else Nkind (Decl_Item) in N_Body_Stub) then Error_Msg_N ("overriding of& is too late!", Subp); Error_Msg_N ("\spec should appear immediately after the type!", Subp); exit; end if; Next (Decl_Item); end loop; -- If the subprogram doesn't follow in the list of -- declarations including the type then the type has -- definitely been frozen already and the body is illegal. if No (Decl_Item) then Error_Msg_N ("overriding of& is too late!", Subp); Error_Msg_N ("\spec should appear immediately after the type!", Subp); elsif Is_Frozen (Subp) then -- The subprogram body declares a primitive operation. -- If the subprogram is already frozen, we must update -- its dispatching information explicitly here. The -- information is taken from the overridden subprogram. -- We must also generate a cross-reference entry because -- references to other primitives were already created -- when type was frozen. Body_Is_Last_Primitive := True; if Present (DTC_Entity (Old_Subp)) then Set_DTC_Entity (Subp, DTC_Entity (Old_Subp)); Set_DT_Position_Value (Subp, DT_Position (Old_Subp)); if not Restriction_Active (No_Dispatching_Calls) then if Building_Static_DT (Tagged_Type) then -- If the static dispatch table has not been -- built then there is nothing else to do now; -- otherwise we notify that we cannot build the -- static dispatch table. if Has_Dispatch_Table (Tagged_Type) then Error_Msg_N ("overriding of& is too late for building " & " static dispatch tables!", Subp); Error_Msg_N ("\spec should appear immediately after " & "the type!", Subp); end if; -- No code required to register primitives in VM -- targets elsif not Tagged_Type_Expansion then null; else Insert_Actions_After (Subp_Body, Register_Primitive (Sloc (Subp_Body), Prim => Subp)); end if; -- Indicate that this is an overriding operation, -- and replace the overridden entry in the list of -- primitive operations, which is used for xref -- generation subsequently. Generate_Reference (Tagged_Type, Subp, 'P', False); Override_Dispatching_Operation (Tagged_Type, Old_Subp, Subp); Set_Is_Dispatching_Operation (Subp); -- Inherit decoration of controlling formals and -- controlling result. if Ekind (Old_Subp) = E_Function and then Has_Controlling_Result (Old_Subp) then Set_Has_Controlling_Result (Subp); end if; if Present (First_Formal (Old_Subp)) then declare Old_Formal : Entity_Id; Formal : Entity_Id; begin Formal := First_Formal (Subp); Old_Formal := First_Formal (Old_Subp); while Present (Old_Formal) loop Set_Is_Controlling_Formal (Formal, Is_Controlling_Formal (Old_Formal)); Next_Formal (Formal); Next_Formal (Old_Formal); end loop; end; end if; end if; Check_Inherited_Conditions (Tagged_Type, Late_Overriding => True); end if; end if; end; else Error_Msg_N ("overriding of& is too late!", Subp); Error_Msg_N ("\subprogram spec should appear immediately after the type!", Subp); end if; -- If the type is not frozen yet and we are not in the overriding -- case it looks suspiciously like an attempt to define a primitive -- operation, which requires the declaration to be in a package spec -- (3.2.3(6)). Only report cases where the type and subprogram are -- in the same declaration list (by checking the enclosing parent -- declarations), to avoid spurious warnings on subprograms in -- instance bodies when the type is declared in the instance spec -- but hasn't been frozen by the instance body. elsif not Is_Frozen (Tagged_Type) and then In_Same_List (Parent (Tagged_Type), Parent (Parent (Subp))) then Error_Msg_N ("??not dispatching (must be defined in a package spec)", Subp); return; -- When the type is frozen, it is legitimate to define a new -- non-primitive operation. else return; end if; -- Now, we are sure that the scope is a package spec. If the subprogram -- is declared after the freezing point of the type that's an error elsif Is_Frozen (Tagged_Type) and then not Has_Dispatching_Parent then Error_Msg_N ("this primitive operation is declared too late", Subp); Error_Msg_NE ("??no primitive operations for& after this line", Freeze_Node (Tagged_Type), Tagged_Type); return; end if; Check_Controlling_Formals (Tagged_Type, Subp); Ovr_Subp := Old_Subp; -- [Ada 2012:AI-0125]: Search for inherited hidden primitive that may be -- overridden by Subp. This only applies to source subprograms, and -- their declaration must carry an explicit overriding indicator. if No (Ovr_Subp) and then Ada_Version >= Ada_2012 and then Comes_From_Source (Subp) and then Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Declaration then Ovr_Subp := Find_Hidden_Overridden_Primitive (Subp); -- Verify that the proper overriding indicator has been supplied. if Present (Ovr_Subp) and then not Must_Override (Specification (Unit_Declaration_Node (Subp))) then Error_Msg_NE ("missing overriding indicator for&", Subp, Subp); end if; end if; -- Now it should be a correct primitive operation, put it in the list if Present (Ovr_Subp) then -- If the type has interfaces we complete this check after we set -- attribute Is_Dispatching_Operation. Check_Subtype_Conformant (Subp, Ovr_Subp); -- A primitive operation with the name of a primitive controlled -- operation does not override a non-visible overriding controlled -- operation, i.e. one declared in a private part when the full -- view of a type is controlled. Conversely, it will override a -- visible operation that may be declared in a partial view when -- the full view is controlled. if Chars (Subp) in Name_Initialize | Name_Adjust | Name_Finalize and then Is_Controlled (Tagged_Type) and then not Is_Visibly_Controlled (Tagged_Type) and then not Is_Inherited_Public_Operation (Ovr_Subp) then Set_Overridden_Operation (Subp, Empty); -- If the subprogram specification carries an overriding -- indicator, no need for the warning: it is either redundant, -- or else an error will be reported. if Nkind (Parent (Subp)) = N_Procedure_Specification and then (Must_Override (Parent (Subp)) or else Must_Not_Override (Parent (Subp))) then null; -- Here we need the warning else Error_Msg_NE ("operation does not override inherited&??", Subp, Subp); end if; else Override_Dispatching_Operation (Tagged_Type, Ovr_Subp, Subp); -- Ada 2005 (AI-251): In case of late overriding of a primitive -- that covers abstract interface subprograms we must register it -- in all the secondary dispatch tables associated with abstract -- interfaces. We do this now only if not building static tables, -- nor when the expander is inactive (we avoid trying to register -- primitives in semantics-only mode, since the type may not have -- an associated dispatch table). Otherwise the patch code is -- emitted after those tables are built, to prevent access before -- elaboration in gigi. if Body_Is_Last_Primitive and then Expander_Active then declare Subp_Body : constant Node_Id := Unit_Declaration_Node (Subp); Elmt : Elmt_Id; Prim : Node_Id; begin Elmt := First_Elmt (Primitive_Operations (Tagged_Type)); while Present (Elmt) loop Prim := Node (Elmt); -- No code required to register primitives in VM targets if Present (Alias (Prim)) and then Present (Interface_Alias (Prim)) and then Alias (Prim) = Subp and then not Building_Static_DT (Tagged_Type) and then Tagged_Type_Expansion then Insert_Actions_After (Subp_Body, Register_Primitive (Sloc (Subp_Body), Prim => Prim)); end if; Next_Elmt (Elmt); end loop; -- Redisplay the contents of the updated dispatch table if Debug_Flag_ZZ then Write_Str ("Late overriding: "); Write_DT (Tagged_Type); end if; end; end if; end if; -- If no old subprogram, then we add this as a dispatching operation, -- but we avoid doing this if an error was posted, to prevent annoying -- cascaded errors. elsif not Error_Posted (Subp) then Add_Dispatching_Operation (Tagged_Type, Subp); end if; Set_Is_Dispatching_Operation (Subp, True); -- Ada 2005 (AI-251): If the type implements interfaces we must check -- subtype conformance against all the interfaces covered by this -- primitive. if Present (Ovr_Subp) and then Has_Interfaces (Tagged_Type) then declare Ifaces_List : Elist_Id; Iface_Elmt : Elmt_Id; Iface_Prim_Elmt : Elmt_Id; Iface_Prim : Entity_Id; Ret_Typ : Entity_Id; begin Collect_Interfaces (Tagged_Type, Ifaces_List); Iface_Elmt := First_Elmt (Ifaces_List); while Present (Iface_Elmt) loop if not Is_Ancestor (Node (Iface_Elmt), Tagged_Type) then Iface_Prim_Elmt := First_Elmt (Primitive_Operations (Node (Iface_Elmt))); while Present (Iface_Prim_Elmt) loop Iface_Prim := Node (Iface_Prim_Elmt); if Is_Interface_Conformant (Tagged_Type, Iface_Prim, Subp) then -- Handle procedures, functions whose return type -- matches, or functions not returning interfaces if Ekind (Subp) = E_Procedure or else Etype (Iface_Prim) = Etype (Subp) or else not Is_Interface (Etype (Iface_Prim)) then Check_Subtype_Conformant (New_Id => Subp, Old_Id => Iface_Prim, Err_Loc => Subp, Skip_Controlling_Formals => True); -- Handle functions returning interfaces elsif Implements_Interface (Etype (Subp), Etype (Iface_Prim)) then -- Temporarily force both entities to return the -- same type. Required because Subtype_Conformant -- does not handle this case. Ret_Typ := Etype (Iface_Prim); Set_Etype (Iface_Prim, Etype (Subp)); Check_Subtype_Conformant (New_Id => Subp, Old_Id => Iface_Prim, Err_Loc => Subp, Skip_Controlling_Formals => True); Set_Etype (Iface_Prim, Ret_Typ); end if; end if; Next_Elmt (Iface_Prim_Elmt); end loop; end if; Next_Elmt (Iface_Elmt); end loop; end; end if; if not Body_Is_Last_Primitive then Set_DT_Position_Value (Subp, No_Uint); elsif Has_Controlled_Component (Tagged_Type) and then Chars (Subp) in Name_Initialize | Name_Adjust | Name_Finalize | Name_Finalize_Address then declare F_Node : constant Node_Id := Freeze_Node (Tagged_Type); Decl : Node_Id; Old_P : Entity_Id; Old_Bod : Node_Id; Old_Spec : Entity_Id; C_Names : constant array (1 .. 4) of Name_Id := (Name_Initialize, Name_Adjust, Name_Finalize, Name_Finalize_Address); D_Names : constant array (1 .. 4) of TSS_Name_Type := (TSS_Deep_Initialize, TSS_Deep_Adjust, TSS_Deep_Finalize, TSS_Finalize_Address); begin -- Remove previous controlled function which was constructed and -- analyzed when the type was frozen. This requires removing the -- body of the redefined primitive, as well as its specification -- if needed (there is no spec created for Deep_Initialize, see -- exp_ch3.adb). We must also dismantle the exception information -- that may have been generated for it when front end zero-cost -- tables are enabled. for J in D_Names'Range loop Old_P := TSS (Tagged_Type, D_Names (J)); if Present (Old_P) and then Chars (Subp) = C_Names (J) then Old_Bod := Unit_Declaration_Node (Old_P); Remove (Old_Bod); Set_Is_Eliminated (Old_P); Set_Scope (Old_P, Scope (Current_Scope)); if Nkind (Old_Bod) = N_Subprogram_Body and then Present (Corresponding_Spec (Old_Bod)) then Old_Spec := Corresponding_Spec (Old_Bod); Set_Has_Completion (Old_Spec, False); end if; end if; end loop; Build_Late_Proc (Tagged_Type, Chars (Subp)); -- The new operation is added to the actions of the freeze node -- for the type, but this node has already been analyzed, so we -- must retrieve and analyze explicitly the new body. if Present (F_Node) and then Present (Actions (F_Node)) then Decl := Last (Actions (F_Node)); Analyze (Decl); end if; end; end if; -- AI12-0279: If the Yield aspect is specified for a dispatching -- subprogram that inherits the aspect, the specified value shall -- be confirming. if Is_Dispatching_Operation (Subp) and then Is_Primitive_Wrapper (Subp) and then Present (Wrapped_Entity (Subp)) and then Comes_From_Source (Wrapped_Entity (Subp)) and then Present (Overridden_Operation (Subp)) and then Has_Yield_Aspect (Overridden_Operation (Subp)) /= Has_Yield_Aspect (Wrapped_Entity (Subp)) then declare W_Ent : constant Entity_Id := Wrapped_Entity (Subp); W_Decl : constant Node_Id := Parent (W_Ent); Asp : Node_Id; begin if Present (Aspect_Specifications (W_Decl)) then Asp := First (Aspect_Specifications (W_Decl)); while Present (Asp) loop if Chars (Identifier (Asp)) = Name_Yield then Error_Msg_Name_1 := Name_Yield; Error_Msg_N ("specification of inherited aspect% can only confirm " & "parent value", Asp); end if; Next (Asp); end loop; end if; Set_Has_Yield_Aspect (Wrapped_Entity (Subp)); end; end if; -- For similarity with record extensions, in Ada 9X the language should -- have disallowed adding visible operations to a tagged type after -- deriving a private extension from it. Report a warning if this -- primitive is defined after a private extension of Tagged_Type. Warn_On_Late_Primitive_After_Private_Extension (Tagged_Type, Subp); end Check_Dispatching_Operation; ------------------------------------------ -- Check_Operation_From_Incomplete_Type -- ------------------------------------------ procedure Check_Operation_From_Incomplete_Type (Subp : Entity_Id; Typ : Entity_Id) is Full : constant Entity_Id := Full_View (Typ); Parent_Typ : constant Entity_Id := Etype (Full); Old_Prim : constant Elist_Id := Primitive_Operations (Parent_Typ); New_Prim : constant Elist_Id := Primitive_Operations (Full); Op1, Op2 : Elmt_Id; Prev : Elmt_Id := No_Elmt; function Derives_From (Parent_Subp : Entity_Id) return Boolean; -- Check that Subp has profile of an operation derived from Parent_Subp. -- Subp must have a parameter or result type that is Typ or an access -- parameter or access result type that designates Typ. ------------------ -- Derives_From -- ------------------ function Derives_From (Parent_Subp : Entity_Id) return Boolean is F1, F2 : Entity_Id; begin if Chars (Parent_Subp) /= Chars (Subp) then return False; end if; -- Check that the type of controlling formals is derived from the -- parent subprogram's controlling formal type (or designated type -- if the formal type is an anonymous access type). F1 := First_Formal (Parent_Subp); F2 := First_Formal (Subp); while Present (F1) and then Present (F2) loop if Ekind (Etype (F1)) = E_Anonymous_Access_Type then if Ekind (Etype (F2)) /= E_Anonymous_Access_Type then return False; elsif Designated_Type (Etype (F1)) = Parent_Typ and then Designated_Type (Etype (F2)) /= Full then return False; end if; elsif Ekind (Etype (F2)) = E_Anonymous_Access_Type then return False; elsif Etype (F1) = Parent_Typ and then Etype (F2) /= Full then return False; end if; Next_Formal (F1); Next_Formal (F2); end loop; -- Check that a controlling result type is derived from the parent -- subprogram's result type (or designated type if the result type -- is an anonymous access type). if Ekind (Parent_Subp) = E_Function then if Ekind (Subp) /= E_Function then return False; elsif Ekind (Etype (Parent_Subp)) = E_Anonymous_Access_Type then if Ekind (Etype (Subp)) /= E_Anonymous_Access_Type then return False; elsif Designated_Type (Etype (Parent_Subp)) = Parent_Typ and then Designated_Type (Etype (Subp)) /= Full then return False; end if; elsif Ekind (Etype (Subp)) = E_Anonymous_Access_Type then return False; elsif Etype (Parent_Subp) = Parent_Typ and then Etype (Subp) /= Full then return False; end if; elsif Ekind (Subp) = E_Function then return False; end if; return No (F1) and then No (F2); end Derives_From; -- Start of processing for Check_Operation_From_Incomplete_Type begin -- The operation may override an inherited one, or may be a new one -- altogether. The inherited operation will have been hidden by the -- current one at the point of the type derivation, so it does not -- appear in the list of primitive operations of the type. We have to -- find the proper place of insertion in the list of primitive opera- -- tions by iterating over the list for the parent type. Op1 := First_Elmt (Old_Prim); Op2 := First_Elmt (New_Prim); while Present (Op1) and then Present (Op2) loop if Derives_From (Node (Op1)) then if No (Prev) then -- Avoid adding it to the list of primitives if already there if Node (Op2) /= Subp then Prepend_Elmt (Subp, New_Prim); end if; else Insert_Elmt_After (Subp, Prev); end if; return; end if; Prev := Op2; Next_Elmt (Op1); Next_Elmt (Op2); end loop; -- Operation is a new primitive Append_Elmt (Subp, New_Prim); end Check_Operation_From_Incomplete_Type; --------------------------------------- -- Check_Operation_From_Private_View -- --------------------------------------- procedure Check_Operation_From_Private_View (Subp, Old_Subp : Entity_Id) is Tagged_Type : Entity_Id; begin if Is_Dispatching_Operation (Alias (Subp)) then Set_Scope (Subp, Current_Scope); Tagged_Type := Find_Dispatching_Type (Subp); -- Add Old_Subp to primitive operations if not already present if Present (Tagged_Type) and then Is_Tagged_Type (Tagged_Type) then Add_Dispatching_Operation (Tagged_Type, Old_Subp); -- If Old_Subp isn't already marked as dispatching then this is -- the case of an operation of an untagged private type fulfilled -- by a tagged type that overrides an inherited dispatching -- operation, so we set the necessary dispatching attributes here. if not Is_Dispatching_Operation (Old_Subp) then -- If the untagged type has no discriminants, and the full -- view is constrained, there will be a spurious mismatch of -- subtypes on the controlling arguments, because the tagged -- type is the internal base type introduced in the derivation. -- Use the original type to verify conformance, rather than the -- base type. if not Comes_From_Source (Tagged_Type) and then Has_Discriminants (Tagged_Type) then declare Formal : Entity_Id; begin Formal := First_Formal (Old_Subp); while Present (Formal) loop if Tagged_Type = Base_Type (Etype (Formal)) then Tagged_Type := Etype (Formal); end if; Next_Formal (Formal); end loop; end; if Tagged_Type = Base_Type (Etype (Old_Subp)) then Tagged_Type := Etype (Old_Subp); end if; end if; Check_Controlling_Formals (Tagged_Type, Old_Subp); Set_Is_Dispatching_Operation (Old_Subp, True); Set_DT_Position_Value (Old_Subp, No_Uint); end if; -- If the old subprogram is an explicit renaming of some other -- entity, it is not overridden by the inherited subprogram. -- Otherwise, update its alias and other attributes. if Present (Alias (Old_Subp)) and then Nkind (Unit_Declaration_Node (Old_Subp)) /= N_Subprogram_Renaming_Declaration then Set_Alias (Old_Subp, Alias (Subp)); -- The derived subprogram should inherit the abstractness of -- the parent subprogram (except in the case of a function -- returning the type). This sets the abstractness properly -- for cases where a private extension may have inherited an -- abstract operation, but the full type is derived from a -- descendant type and inherits a nonabstract version. if Etype (Subp) /= Tagged_Type then Set_Is_Abstract_Subprogram (Old_Subp, Is_Abstract_Subprogram (Alias (Subp))); end if; end if; end if; end if; end Check_Operation_From_Private_View; -------------------------- -- Find_Controlling_Arg -- -------------------------- function Find_Controlling_Arg (N : Node_Id) return Node_Id is Orig_Node : constant Node_Id := Original_Node (N); Typ : Entity_Id; begin if Nkind (Orig_Node) = N_Qualified_Expression then return Find_Controlling_Arg (Expression (Orig_Node)); end if; -- Dispatching on result case. If expansion is disabled, the node still -- has the structure of a function call. However, if the function name -- is an operator and the call was given in infix form, the original -- node has no controlling result and we must examine the current node. if Nkind (N) = N_Function_Call and then Present (Controlling_Argument (N)) and then Has_Controlling_Result (Entity (Name (N))) then return Controlling_Argument (N); -- If expansion is enabled, the call may have been transformed into -- an indirect call, and we need to recover the original node. elsif Nkind (Orig_Node) = N_Function_Call and then Present (Controlling_Argument (Orig_Node)) and then Has_Controlling_Result (Entity (Name (Orig_Node))) then return Controlling_Argument (Orig_Node); -- Type conversions are dynamically tagged if the target type, or its -- designated type, are classwide. An interface conversion expands into -- a dereference, so test must be performed on the original node. elsif Nkind (Orig_Node) = N_Type_Conversion and then Nkind (N) = N_Explicit_Dereference and then Is_Controlling_Actual (N) then declare Target_Type : constant Entity_Id := Entity (Subtype_Mark (Orig_Node)); begin if Is_Class_Wide_Type (Target_Type) then return N; elsif Is_Access_Type (Target_Type) and then Is_Class_Wide_Type (Designated_Type (Target_Type)) then return N; else return Empty; end if; end; -- Normal case elsif Is_Controlling_Actual (N) or else (Nkind (Parent (N)) = N_Qualified_Expression and then Is_Controlling_Actual (Parent (N))) then Typ := Etype (N); if Is_Access_Type (Typ) then -- In the case of an Access attribute, use the type of the prefix, -- since in the case of an actual for an access parameter, the -- attribute's type may be of a specific designated type, even -- though the prefix type is class-wide. if Nkind (N) = N_Attribute_Reference then Typ := Etype (Prefix (N)); -- An allocator is dispatching if the type of qualified expression -- is class_wide, in which case this is the controlling type. elsif Nkind (Orig_Node) = N_Allocator and then Nkind (Expression (Orig_Node)) = N_Qualified_Expression then Typ := Etype (Expression (Orig_Node)); else Typ := Designated_Type (Typ); end if; end if; if Is_Class_Wide_Type (Typ) or else (Nkind (Parent (N)) = N_Qualified_Expression and then Is_Access_Type (Etype (N)) and then Is_Class_Wide_Type (Designated_Type (Etype (N)))) then return N; end if; end if; return Empty; end Find_Controlling_Arg; --------------------------- -- Find_Dispatching_Type -- --------------------------- function Find_Dispatching_Type (Subp : Entity_Id) return Entity_Id is A_Formal : Entity_Id; Formal : Entity_Id; Ctrl_Type : Entity_Id; begin if Ekind (Subp) in E_Function | E_Procedure and then Present (DTC_Entity (Subp)) then return Scope (DTC_Entity (Subp)); -- For subprograms internally generated by derivations of tagged types -- use the alias subprogram as a reference to locate the dispatching -- type of Subp. elsif not Comes_From_Source (Subp) and then Present (Alias (Subp)) and then Is_Dispatching_Operation (Alias (Subp)) then if Ekind (Alias (Subp)) = E_Function and then Has_Controlling_Result (Alias (Subp)) then return Check_Controlling_Type (Etype (Subp), Subp); else Formal := First_Formal (Subp); A_Formal := First_Formal (Alias (Subp)); while Present (A_Formal) loop if Is_Controlling_Formal (A_Formal) then return Check_Controlling_Type (Etype (Formal), Subp); end if; Next_Formal (Formal); Next_Formal (A_Formal); end loop; pragma Assert (False); return Empty; end if; -- General case else Formal := First_Formal (Subp); while Present (Formal) loop Ctrl_Type := Check_Controlling_Type (Etype (Formal), Subp); if Present (Ctrl_Type) then return Ctrl_Type; end if; Next_Formal (Formal); end loop; -- The subprogram may also be dispatching on result if Present (Etype (Subp)) then return Check_Controlling_Type (Etype (Subp), Subp); end if; end if; pragma Assert (not Is_Dispatching_Operation (Subp)); return Empty; end Find_Dispatching_Type; -------------------------------------- -- Find_Hidden_Overridden_Primitive -- -------------------------------------- function Find_Hidden_Overridden_Primitive (S : Entity_Id) return Entity_Id is Tag_Typ : constant Entity_Id := Find_Dispatching_Type (S); Elmt : Elmt_Id; Orig_Prim : Entity_Id; Prim : Entity_Id; Vis_List : Elist_Id; begin -- This Ada 2012 rule applies only for type extensions or private -- extensions, where the parent type is not in a parent unit, and -- where an operation is never declared but still inherited. if No (Tag_Typ) or else not Is_Record_Type (Tag_Typ) or else Etype (Tag_Typ) = Tag_Typ or else In_Open_Scopes (Scope (Etype (Tag_Typ))) then return Empty; end if; -- Collect the list of visible ancestor of the tagged type Vis_List := Visible_Ancestors (Tag_Typ); Elmt := First_Elmt (Primitive_Operations (Tag_Typ)); while Present (Elmt) loop Prim := Node (Elmt); -- Find an inherited hidden dispatching primitive with the name of S -- and a type-conformant profile. if Present (Alias (Prim)) and then Is_Hidden (Alias (Prim)) and then Find_Dispatching_Type (Alias (Prim)) /= Tag_Typ and then Primitive_Names_Match (S, Prim) and then Type_Conformant (S, Prim) then declare Vis_Ancestor : Elmt_Id; Elmt : Elmt_Id; begin -- The original corresponding operation of Prim must be an -- operation of a visible ancestor of the dispatching type S, -- and the original corresponding operation of S2 must be -- visible. Orig_Prim := Original_Corresponding_Operation (Prim); if Orig_Prim /= Prim and then Is_Immediately_Visible (Orig_Prim) then Vis_Ancestor := First_Elmt (Vis_List); while Present (Vis_Ancestor) loop Elmt := First_Elmt (Primitive_Operations (Node (Vis_Ancestor))); while Present (Elmt) loop if Node (Elmt) = Orig_Prim then Set_Overridden_Operation (S, Prim); Set_Is_Ada_2022_Only (S, Is_Ada_2022_Only (Prim)); Set_Alias (Prim, Orig_Prim); return Prim; end if; Next_Elmt (Elmt); end loop; Next_Elmt (Vis_Ancestor); end loop; end if; end; end if; Next_Elmt (Elmt); end loop; return Empty; end Find_Hidden_Overridden_Primitive; --------------------------------------- -- Find_Primitive_Covering_Interface -- --------------------------------------- function Find_Primitive_Covering_Interface (Tagged_Type : Entity_Id; Iface_Prim : Entity_Id) return Entity_Id is E : Entity_Id; El : Elmt_Id; begin pragma Assert (Is_Interface (Find_Dispatching_Type (Iface_Prim)) or else (Present (Alias (Iface_Prim)) and then Is_Interface (Find_Dispatching_Type (Ultimate_Alias (Iface_Prim))))); -- Search in the homonym chain. Done to speed up locating visible -- entities and required to catch primitives associated with the partial -- view of private types when processing the corresponding full view. E := Current_Entity (Iface_Prim); while Present (E) loop if Is_Subprogram (E) and then Is_Dispatching_Operation (E) and then Is_Interface_Conformant (Tagged_Type, Iface_Prim, E) then return E; end if; E := Homonym (E); end loop; -- Search in the list of primitives of the type. Required to locate -- the covering primitive if the covering primitive is not visible -- (for example, non-visible inherited primitive of private type). El := First_Elmt (Primitive_Operations (Tagged_Type)); while Present (El) loop E := Node (El); -- Keep separate the management of internal entities that link -- primitives with interface primitives from tagged type primitives. if No (Interface_Alias (E)) then if Present (Alias (E)) then -- This interface primitive has not been covered yet if Alias (E) = Iface_Prim then return E; -- The covering primitive was inherited elsif Overridden_Operation (Ultimate_Alias (E)) = Iface_Prim then return E; end if; end if; -- Check if E covers the interface primitive (includes case in -- which E is an inherited private primitive). if Is_Interface_Conformant (Tagged_Type, Iface_Prim, E) then return E; end if; -- Use the internal entity that links the interface primitive with -- the covering primitive to locate the entity. elsif Interface_Alias (E) = Iface_Prim then return Alias (E); end if; Next_Elmt (El); end loop; -- Not found return Empty; end Find_Primitive_Covering_Interface; --------------------------- -- Inheritance_Utilities -- --------------------------- package body Inheritance_Utilities is --------------------------- -- Inherited_Subprograms -- --------------------------- function Inherited_Subprograms (S : Entity_Id; No_Interfaces : Boolean := False; Interfaces_Only : Boolean := False; One_Only : Boolean := False) return Subprogram_List is Result : Subprogram_List (1 .. 6000); -- 6000 here is intended to be infinity. We could use an expandable -- table, but it would be awfully heavy, and there is no way that we -- could reasonably exceed this value. N : Nat := 0; -- Number of entries in Result Parent_Op : Entity_Id; -- Traverses the Overridden_Operation chain procedure Store_IS (E : Entity_Id); -- Stores E in Result if not already stored -------------- -- Store_IS -- -------------- procedure Store_IS (E : Entity_Id) is begin for J in 1 .. N loop if E = Result (J) then return; end if; end loop; N := N + 1; Result (N) := E; end Store_IS; -- Start of processing for Inherited_Subprograms begin pragma Assert (not (No_Interfaces and Interfaces_Only)); -- When used from backends, visibility can be handled differently -- resulting in no dispatching type being found. if Present (S) and then Is_Dispatching_Operation (S) and then Present (Find_DT (S)) then -- Deal with direct inheritance if not Interfaces_Only then Parent_Op := S; loop Parent_Op := Overridden_Operation (Parent_Op); exit when No (Parent_Op) or else (No_Interfaces and then Is_Interface (Find_DT (Parent_Op))); if Is_Subprogram_Or_Generic_Subprogram (Parent_Op) then Store_IS (Parent_Op); if One_Only then goto Done; end if; end if; end loop; end if; -- Now deal with interfaces if not No_Interfaces then declare Tag_Typ : Entity_Id; Prim : Entity_Id; Elmt : Elmt_Id; begin Tag_Typ := Find_DT (S); -- In the presence of limited views there may be no visible -- dispatching type. Primitives will be inherited when non- -- limited view is frozen. if No (Tag_Typ) then return Result (1 .. 0); -- Prevent cascaded errors elsif Is_Concurrent_Type (Tag_Typ) and then No (Corresponding_Record_Type (Tag_Typ)) and then Serious_Errors_Detected > 0 then return Result (1 .. 0); end if; if Is_Concurrent_Type (Tag_Typ) then Tag_Typ := Corresponding_Record_Type (Tag_Typ); end if; if Present (Tag_Typ) and then Is_Private_Type (Tag_Typ) and then Present (Full_View (Tag_Typ)) then Tag_Typ := Full_View (Tag_Typ); end if; -- Search primitive operations of dispatching type if Present (Tag_Typ) and then Present (Primitive_Operations (Tag_Typ)) then Elmt := First_Elmt (Primitive_Operations (Tag_Typ)); while Present (Elmt) loop Prim := Node (Elmt); -- The following test eliminates some odd cases in -- which Ekind (Prim) is Void, to be investigated -- further ??? if not Is_Subprogram_Or_Generic_Subprogram (Prim) then null; -- For [generic] subprogram, look at interface -- alias. elsif Present (Interface_Alias (Prim)) and then Alias (Prim) = S then -- We have found a primitive covered by S Store_IS (Interface_Alias (Prim)); if One_Only then goto Done; end if; end if; Next_Elmt (Elmt); end loop; end if; end; end if; end if; <<Done>> return Result (1 .. N); end Inherited_Subprograms; ------------------------------ -- Is_Overriding_Subprogram -- ------------------------------ function Is_Overriding_Subprogram (E : Entity_Id) return Boolean is Inherited : constant Subprogram_List := Inherited_Subprograms (E, One_Only => True); begin return Inherited'Length > 0; end Is_Overriding_Subprogram; end Inheritance_Utilities; -------------------------------- -- Inheritance_Utilities_Inst -- -------------------------------- package Inheritance_Utilities_Inst is new Inheritance_Utilities (Find_Dispatching_Type); --------------------------- -- Inherited_Subprograms -- --------------------------- function Inherited_Subprograms (S : Entity_Id; No_Interfaces : Boolean := False; Interfaces_Only : Boolean := False; One_Only : Boolean := False) return Subprogram_List renames Inheritance_Utilities_Inst.Inherited_Subprograms; --------------------------- -- Is_Dynamically_Tagged -- --------------------------- function Is_Dynamically_Tagged (N : Node_Id) return Boolean is begin if Nkind (N) = N_Error then return False; elsif Present (Find_Controlling_Arg (N)) then return True; -- Special cases: entities, and calls that dispatch on result elsif Is_Entity_Name (N) then return Is_Class_Wide_Type (Etype (N)); elsif Nkind (N) = N_Function_Call and then Is_Class_Wide_Type (Etype (N)) then return True; -- Otherwise check whether call has controlling argument else return False; end if; end Is_Dynamically_Tagged; --------------------------------- -- Is_Null_Interface_Primitive -- --------------------------------- function Is_Null_Interface_Primitive (E : Entity_Id) return Boolean is begin return Comes_From_Source (E) and then Is_Dispatching_Operation (E) and then Ekind (E) = E_Procedure and then Null_Present (Parent (E)) and then Is_Interface (Find_Dispatching_Type (E)); end Is_Null_Interface_Primitive; ----------------------------------- -- Is_Inherited_Public_Operation -- ----------------------------------- function Is_Inherited_Public_Operation (Op : Entity_Id) return Boolean is Pack_Decl : Node_Id; Prim : Entity_Id := Op; Scop : Entity_Id := Prim; begin -- Locate the ultimate non-hidden alias entity while Present (Alias (Prim)) and then not Is_Hidden (Alias (Prim)) loop pragma Assert (Alias (Prim) /= Prim); Prim := Alias (Prim); Scop := Scope (Prim); end loop; if Comes_From_Source (Prim) and then Ekind (Scop) = E_Package then Pack_Decl := Unit_Declaration_Node (Scop); return Nkind (Pack_Decl) = N_Package_Declaration and then List_Containing (Unit_Declaration_Node (Prim)) = Visible_Declarations (Specification (Pack_Decl)); else return False; end if; end Is_Inherited_Public_Operation; ------------------------------ -- Is_Overriding_Subprogram -- ------------------------------ function Is_Overriding_Subprogram (E : Entity_Id) return Boolean renames Inheritance_Utilities_Inst.Is_Overriding_Subprogram; -------------------------- -- Is_Tag_Indeterminate -- -------------------------- function Is_Tag_Indeterminate (N : Node_Id) return Boolean is Nam : Entity_Id; Actual : Node_Id; Orig_Node : constant Node_Id := Original_Node (N); begin if Nkind (Orig_Node) = N_Function_Call and then Is_Entity_Name (Name (Orig_Node)) then Nam := Entity (Name (Orig_Node)); if not Has_Controlling_Result (Nam) then return False; -- The function may have a controlling result, but if the return type -- is not visibly tagged, then this is not tag-indeterminate. elsif Is_Access_Type (Etype (Nam)) and then not Is_Tagged_Type (Designated_Type (Etype (Nam))) then return False; -- An explicit dereference means that the call has already been -- expanded and there is no tag to propagate. elsif Nkind (N) = N_Explicit_Dereference then return False; -- If there are no actuals, the call is tag-indeterminate elsif No (Parameter_Associations (Orig_Node)) then return True; else Actual := First_Actual (Orig_Node); while Present (Actual) loop if Is_Controlling_Actual (Actual) and then not Is_Tag_Indeterminate (Actual) then -- One operand is dispatching return False; end if; Next_Actual (Actual); end loop; return True; end if; elsif Nkind (Orig_Node) = N_Qualified_Expression then return Is_Tag_Indeterminate (Expression (Orig_Node)); -- Case of a call to the Input attribute (possibly rewritten), which is -- always tag-indeterminate except when its prefix is a Class attribute. elsif Nkind (Orig_Node) = N_Attribute_Reference and then Get_Attribute_Id (Attribute_Name (Orig_Node)) = Attribute_Input and then Nkind (Prefix (Orig_Node)) /= N_Attribute_Reference then return True; -- In Ada 2005, a function that returns an anonymous access type can be -- dispatching, and the dereference of a call to such a function can -- also be tag-indeterminate if the call itself is. elsif Nkind (Orig_Node) = N_Explicit_Dereference and then Ada_Version >= Ada_2005 then return Is_Tag_Indeterminate (Prefix (Orig_Node)); else return False; end if; end Is_Tag_Indeterminate; ------------------------------------ -- Override_Dispatching_Operation -- ------------------------------------ procedure Override_Dispatching_Operation (Tagged_Type : Entity_Id; Prev_Op : Entity_Id; New_Op : Entity_Id) is Elmt : Elmt_Id; Prim : Node_Id; begin -- If there is no previous operation to override, the type declaration -- was malformed, and an error must have been emitted already. Elmt := First_Elmt (Primitive_Operations (Tagged_Type)); while Present (Elmt) and then Node (Elmt) /= Prev_Op loop Next_Elmt (Elmt); end loop; if No (Elmt) then return; end if; -- The location of entities that come from source in the list of -- primitives of the tagged type must follow their order of occurrence -- in the sources to fulfill the C++ ABI. If the overridden entity is a -- primitive of an interface that is not implemented by the parents of -- this tagged type (that is, it is an alias of an interface primitive -- generated by Derive_Interface_Progenitors), then we must append the -- new entity at the end of the list of primitives. if Present (Alias (Prev_Op)) and then Etype (Tagged_Type) /= Tagged_Type and then Is_Interface (Find_Dispatching_Type (Alias (Prev_Op))) and then not Is_Ancestor (Find_Dispatching_Type (Alias (Prev_Op)), Tagged_Type, Use_Full_View => True) and then not Implements_Interface (Etype (Tagged_Type), Find_Dispatching_Type (Alias (Prev_Op))) then Remove_Elmt (Primitive_Operations (Tagged_Type), Elmt); Add_Dispatching_Operation (Tagged_Type, New_Op); -- The new primitive replaces the overridden entity. Required to ensure -- that overriding primitive is assigned the same dispatch table slot. else Replace_Elmt (Elmt, New_Op); end if; if Ada_Version >= Ada_2005 and then Has_Interfaces (Tagged_Type) then -- Ada 2005 (AI-251): Update the attribute alias of all the aliased -- entities of the overridden primitive to reference New_Op, and -- also propagate the proper value of Is_Abstract_Subprogram. Verify -- that the new operation is subtype conformant with the interface -- operations that it implements (for operations inherited from the -- parent itself, this check is made when building the derived type). -- Note: This code is executed with internally generated wrappers of -- functions with controlling result and late overridings. Elmt := First_Elmt (Primitive_Operations (Tagged_Type)); while Present (Elmt) loop Prim := Node (Elmt); if Prim = New_Op then null; -- Note: The check on Is_Subprogram protects the frontend against -- reading attributes in entities that are not yet fully decorated elsif Is_Subprogram (Prim) and then Present (Interface_Alias (Prim)) and then Alias (Prim) = Prev_Op then Set_Alias (Prim, New_Op); -- No further decoration needed yet for internally generated -- wrappers of controlling functions since (at this stage) -- they are not yet decorated. if not Is_Wrapper (New_Op) then Check_Subtype_Conformant (New_Op, Prim); Set_Is_Abstract_Subprogram (Prim, Is_Abstract_Subprogram (New_Op)); -- Ensure that this entity will be expanded to fill the -- corresponding entry in its dispatch table. if not Is_Abstract_Subprogram (Prim) then Set_Has_Delayed_Freeze (Prim); end if; end if; end if; Next_Elmt (Elmt); end loop; end if; if (not Is_Package_Or_Generic_Package (Current_Scope)) or else not In_Private_Part (Current_Scope) then -- Not a private primitive null; else pragma Assert (Is_Inherited_Operation (Prev_Op)); -- Make the overriding operation into an alias of the implicit one. -- In this fashion a call from outside ends up calling the new body -- even if non-dispatching, and a call from inside calls the over- -- riding operation because it hides the implicit one. To indicate -- that the body of Prev_Op is never called, set its dispatch table -- entity to Empty. If the overridden operation has a dispatching -- result, so does the overriding one. Set_Alias (Prev_Op, New_Op); Set_DTC_Entity (Prev_Op, Empty); Set_Has_Controlling_Result (New_Op, Has_Controlling_Result (Prev_Op)); Set_Is_Ada_2022_Only (New_Op, Is_Ada_2022_Only (Prev_Op)); end if; end Override_Dispatching_Operation; ------------------- -- Propagate_Tag -- ------------------- procedure Propagate_Tag (Control : Node_Id; Actual : Node_Id) is Call_Node : Node_Id; Arg : Node_Id; begin if Nkind (Actual) = N_Function_Call then Call_Node := Actual; elsif Nkind (Actual) = N_Identifier and then Nkind (Original_Node (Actual)) = N_Function_Call then -- Call rewritten as object declaration when stack-checking is -- enabled. Propagate tag to expression in declaration, which is -- original call. Call_Node := Expression (Parent (Entity (Actual))); -- Ada 2005: If this is a dereference of a call to a function with a -- dispatching access-result, the tag is propagated when the dereference -- itself is expanded (see exp_ch6.adb) and there is nothing else to do. elsif Nkind (Actual) = N_Explicit_Dereference and then Nkind (Original_Node (Prefix (Actual))) = N_Function_Call then return; -- When expansion is suppressed, an unexpanded call to 'Input can occur, -- and in that case we can simply return. elsif Nkind (Actual) = N_Attribute_Reference then pragma Assert (Attribute_Name (Actual) = Name_Input); return; -- Only other possibilities are parenthesized or qualified expression, -- or an expander-generated unchecked conversion of a function call to -- a stream Input attribute. else Call_Node := Expression (Actual); end if; -- No action needed if the call has been already expanded if Is_Expanded_Dispatching_Call (Call_Node) then return; end if; -- Do not set the Controlling_Argument if already set. This happens in -- the special case of _Input (see Exp_Attr, case Input). if No (Controlling_Argument (Call_Node)) then Set_Controlling_Argument (Call_Node, Control); end if; Arg := First_Actual (Call_Node); while Present (Arg) loop if Is_Tag_Indeterminate (Arg) then Propagate_Tag (Control, Arg); end if; Next_Actual (Arg); end loop; -- Add class-wide precondition check if the target of this dispatching -- call has or inherits class-wide preconditions. Install_Class_Preconditions_Check (Call_Node); -- Expansion of dispatching calls is suppressed on VM targets, because -- the VM back-ends directly handle the generation of dispatching calls -- and would have to undo any expansion to an indirect call. if Tagged_Type_Expansion then declare Call_Typ : constant Entity_Id := Etype (Call_Node); begin Expand_Dispatching_Call (Call_Node); -- If the controlling argument is an interface type and the type -- of Call_Node differs then we must add an implicit conversion to -- force displacement of the pointer to the object to reference -- the secondary dispatch table of the interface. if Is_Interface (Etype (Control)) and then Etype (Control) /= Call_Typ then -- Cannot use Convert_To because the previous call to -- Expand_Dispatching_Call leaves decorated the Call_Node -- with the type of Control. Rewrite (Call_Node, Make_Type_Conversion (Sloc (Call_Node), Subtype_Mark => New_Occurrence_Of (Etype (Control), Sloc (Call_Node)), Expression => Relocate_Node (Call_Node))); Set_Etype (Call_Node, Etype (Control)); Set_Analyzed (Call_Node); Expand_Interface_Conversion (Call_Node); end if; end; -- Expansion of a dispatching call results in an indirect call, which in -- turn causes current values to be killed (see Resolve_Call), so on VM -- targets we do the call here to ensure consistent warnings between VM -- and non-VM targets. else Kill_Current_Values; end if; end Propagate_Tag; end Sem_Disp;
reznikmm/matreshka
Ada
4,255
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ limited with AMF.UML.Models; package AMF.Standard_Profile_L3.Metamodels is pragma Preelaborate; type Standard_Profile_L3_Metamodel is limited interface; type Standard_Profile_L3_Metamodel_Access is access all Standard_Profile_L3_Metamodel'Class; for Standard_Profile_L3_Metamodel_Access'Storage_Size use 0; not overriding function Get_Base_Model (Self : not null access constant Standard_Profile_L3_Metamodel) return AMF.UML.Models.UML_Model_Access is abstract; -- Getter of Metamodel::base_Model. -- not overriding procedure Set_Base_Model (Self : not null access Standard_Profile_L3_Metamodel; To : AMF.UML.Models.UML_Model_Access) is abstract; -- Setter of Metamodel::base_Model. -- end AMF.Standard_Profile_L3.Metamodels;
persan/protobuf-ada
Ada
31,511
adb
pragma Ada_2012; with Interfaces; with Ada.Unchecked_Conversion; with Google.Protobuf.Message; with Google.Protobuf.IO.Invalid_Protocol_Buffer_Exception; with Ada.Containers.Indefinite_Vectors; package body Google.Protobuf.IO.Coded_Input_Stream is ----------------------- -- Decode_Zig_Zag_32 -- ----------------------- function Decode_Zig_Zag_32 (Value : in PB_UInt32) return PB_UInt32 is Value_To_Unsigned_32 : constant Interfaces.Unsigned_32 := Interfaces.Unsigned_32 (Value); use type Interfaces.Unsigned_32; begin return PB_UInt32 (Interfaces.Shift_Right (Value_To_Unsigned_32, 1) xor - (Value_To_Unsigned_32 and 1)); end Decode_Zig_Zag_32; ----------------------- -- Decode_Zig_Zag_64 -- ----------------------- function Decode_Zig_Zag_64 (Value : in PB_UInt64) return PB_UInt64 is Value_To_Unsigned_64 : constant Interfaces.Unsigned_64 := Interfaces.Unsigned_64 (Value); use type Interfaces.Unsigned_64; begin return PB_UInt64 (Interfaces.Shift_Right (Value_To_Unsigned_64, 1) xor - (Value_To_Unsigned_64 and 1)); end Decode_Zig_Zag_64; ------------------ -- Read_Boolean -- ------------------ function Read_Boolean (This : in out Coded_Input_Stream.Instance) return PB_Bool is function BOOLEAN_TO_PB_Bool is new Ada.Unchecked_Conversion (Source => Boolean, Target => PB_Bool); use type PB_Byte; begin return BOOLEAN_TO_PB_Bool (This.Read_Raw_Byte /= 0); end Read_Boolean; ----------------- -- Read_Double -- ----------------- function Read_Double (This : in out Coded_Input_Stream.Instance) return PB_Double is function PB_UInt64_To_PB_Double is new Ada.Unchecked_Conversion (Source => PB_UInt64, Target => PB_Double); begin return PB_UInt64_To_PB_Double (This.Read_Raw_Little_Endian_64); end Read_Double; ---------------------- -- Read_Enumeration -- ---------------------- function Read_Enumeration (This : in out Coded_Input_Stream.Instance) return PB_Int32 is function PB_UInt32_To_PB_Int32 is new Ada.Unchecked_Conversion (Source => PB_UInt32, Target => PB_Int32); begin return PB_UInt32_To_PB_Int32 (This.Read_Raw_Varint_32); end Read_Enumeration; ------------------- -- Read_Fixed_32 -- ------------------- function Read_Fixed_32 (This : in out Coded_Input_Stream.Instance) return PB_UInt32 is begin return This.Read_Raw_Little_Endian_32; end Read_Fixed_32; ------------------- -- Read_Fixed_64 -- ------------------- function Read_Fixed_64 (This : in out Coded_Input_Stream.Instance) return PB_UInt64 is begin return This.Read_Raw_Little_Endian_64; end Read_Fixed_64; ---------------- -- Read_Float -- ---------------- function Read_Float (This : in out Coded_Input_Stream.Instance) return PB_Float is function PB_UInt32_To_PB_Float is new Ada.Unchecked_Conversion (Source => PB_UInt32, Target => PB_Float); begin return PB_UInt32_To_PB_Float (This.Read_Raw_Little_Endian_32); end Read_Float; --------------------- -- Read_Integer_32 -- --------------------- function Read_Integer_32 (This : in out Coded_Input_Stream.Instance) return PB_Int32 is function PB_UInt32_To_PB_Int32 is new Ada.Unchecked_Conversion (Source => PB_UInt32, Target => PB_Int32); begin return PB_UInt32_To_PB_Int32 (This.Read_Raw_Varint_32); end Read_Integer_32; --------------------- -- Read_Integer_64 -- --------------------- function Read_Integer_64 (This : in out Coded_Input_Stream.Instance) return PB_Int64 is function PB_UInt64_To_PB_Int64 is new Ada.Unchecked_Conversion (Source => PB_UInt64, Target => PB_Int64); begin return PB_UInt64_To_PB_Int64 (This.Read_Raw_Varint_64); end Read_Integer_64; ------------------------------- -- Read_Raw_Little_Endian_32 -- ------------------------------- function Read_Raw_Little_Endian_32 (This : in out Coded_Input_Stream.Instance) return PB_UInt32 is Value : PB_UInt32; Byte_1 : constant PB_Byte := This.Read_Raw_Byte; Byte_2 : constant PB_Byte := This.Read_Raw_Byte; Byte_3 : constant PB_Byte := This.Read_Raw_Byte; Byte_4 : constant PB_Byte := This.Read_Raw_Byte; use type PB_UInt32; begin if Big_Endian then -- If we are on a big endian system like PowerPC, do something here --raise Big_Endian_Not_Implemented; Value := Pb_Uint32 (Byte_1); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint32 (Byte_2); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint32 (Byte_3); Value := Shift_Left (Value, 8); Value := Value or PB_UInt32 (Byte_4); else Value := Pb_Uint32 (Byte_4); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint32 (Byte_3); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint32 (Byte_2); Value := Shift_Left (Value, 8); Value := Value or PB_UInt32 (Byte_1); end if; return Value; end Read_Raw_Little_Endian_32; ------------------------------- -- Read_Raw_Little_Endian_64 -- ------------------------------- function Read_Raw_Little_Endian_64 (This : in out Coded_Input_Stream.Instance) return PB_UInt64 is Value : PB_UInt64; Byte_1 : constant PB_Byte := This.Read_Raw_Byte; Byte_2 : constant PB_Byte := This.Read_Raw_Byte; Byte_3 : constant PB_Byte := This.Read_Raw_Byte; Byte_4 : constant PB_Byte := This.Read_Raw_Byte; Byte_5 : constant PB_Byte := This.Read_Raw_Byte; Byte_6 : constant PB_Byte := This.Read_Raw_Byte; Byte_7 : constant PB_Byte := This.Read_Raw_Byte; Byte_8 : constant PB_Byte := This.Read_Raw_Byte; use type PB_UInt64; begin if Big_Endian then -- If we are on a big endian system like PowerPC, do something here --raise Big_Endian_Not_Implemented; Value := Pb_Uint64 (Byte_1); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_2); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_3); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_4); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_5); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_6); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_7); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_8); else Value := Pb_Uint64 (Byte_8); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_7); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_6); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_5); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_4); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_3); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_2); Value := Shift_Left (Value, 8); Value := Value or Pb_Uint64 (Byte_1); end if; return Value; end Read_Raw_Little_Endian_64; ------------------------ -- Read_Raw_Varint_32 -- ------------------------ function Read_Raw_Varint_32 (This : in out Coded_Input_Stream.Instance) return PB_UInt32 is Result : PB_UInt32 := 0; Temp : PB_Byte := This.Read_Raw_Byte; Byte_MSB_Set : constant := 16#80#; use type PB_Byte; use type PB_UInt32; begin -- MSB not set, which means that varint consist of only one byte. See Base 128 Varints: -- https://developers.google.com/protocol-buffers/docs/encoding if Temp < Byte_MSB_Set then return PB_UInt32 (Temp); end if; Result := PB_UInt32 (Temp and 16#7F#); -- (TMP and 16#7F#) == set MSB to 0 Temp := This.Read_Raw_Byte; if Temp < Byte_MSB_Set then Result := Result or Shift_Left (PB_UInt32 (Temp), 7); else Result := Result or Shift_Left (PB_UInt32 (Temp and 16#7F#), 7); Temp := This.Read_Raw_Byte; if Temp < Byte_MSB_Set then Result := Result or Shift_Left (PB_UInt32 (Temp), 14); else Result := Result or Shift_Left (PB_UInt32 (Temp and 16#7F#), 14); Temp := This.Read_Raw_Byte; if Temp < Byte_MSB_Set then Result := Result or Shift_Left (PB_UInt32 (Temp), 21); else Result := Result or Shift_Left (PB_UInt32 (Temp and 16#7F#), 21); Temp := This.Read_Raw_Byte; Result := Result or Shift_Left (PB_UInt32 (Temp), 28); -- Tests if last byte has MSB set in which case the varint is -- malformed, since it cannot be represented by a 32-bit type. if Temp >= Byte_MSB_Set then -- Discard upper 32-bits for I in 1 .. 5 loop Temp := This.Read_Raw_Byte; if Temp < Byte_MSB_Set then return Result; end if; end loop; Invalid_Protocol_Buffer_Exception.Malformed_Varint; end if; end if; end if; end if; return Result; end Read_Raw_Varint_32; ------------------------ -- Read_Raw_Varint_64 -- ------------------------ function Read_Raw_Varint_64 (This : in out Coded_Input_Stream.Instance) return PB_UInt64 is Shift : Natural := 0; Result : PB_UInt64 := 0; Tmp : PB_Byte; Byte_MSB_Set : constant := 16#80#; use type PB_Byte; use type PB_UInt64; begin while Shift < 64 loop Tmp := This.Read_Raw_Byte; Result := Result or Shift_Left (PB_UInt64 (Tmp and 16#7F#), Shift); if (Tmp and Byte_MSB_Set) = 0 then return Result; end if; Shift := Shift + 7; end loop; Invalid_Protocol_Buffer_Exception.Malformed_Varint; return Result; end Read_Raw_Varint_64; -------------------------- -- Read_Signed_Fixed_32 -- -------------------------- function Read_Signed_Fixed_32 (This : in out Coded_Input_Stream.Instance) return PB_Int32 is function PB_UInt32_To_PB_Int32 is new Ada.Unchecked_Conversion (Source => PB_UInt32, Target => PB_Int32); begin return PB_UInt32_To_PB_Int32 (This.Read_Raw_Little_Endian_32); end Read_Signed_Fixed_32; -------------------------- -- Read_Signed_Fixed_64 -- -------------------------- function Read_Signed_Fixed_64 (This : in out Coded_Input_Stream.Instance) return PB_Int64 is function PB_UInt64_To_PB_Int64 is new Ada.Unchecked_Conversion (Source => PB_UInt64, Target => PB_Int64); begin return PB_UInt64_To_PB_Int64 (This.Read_Raw_Little_Endian_64); end Read_Signed_Fixed_64; ---------------------------- -- Read_Signed_Integer_32 -- ---------------------------- function Read_Signed_Integer_32 (This : in out Coded_Input_Stream.Instance) return PB_Int32 is function PB_UInt32_To_PB_Int32 is new Ada.Unchecked_Conversion (Source => PB_UInt32, Target => PB_Int32); begin return PB_UInt32_To_PB_Int32 (Decode_Zig_Zag_32 (This.Read_Raw_Varint_32)); end Read_Signed_Integer_32; ---------------------------- -- Read_Signed_Integer_64 -- ---------------------------- function Read_Signed_Integer_64 (This : in out Coded_Input_Stream.Instance) return PB_Int64 is function PB_UInt64_To_PB_Int64 is new Ada.Unchecked_Conversion (Source => PB_UInt64, Target => PB_Int64); begin return PB_UInt64_To_PB_Int64 (Decode_Zig_Zag_64 (This.Read_Raw_Varint_64)); end Read_Signed_Integer_64; ----------------- -- Read_String -- ----------------- function Read_String (This : in out Coded_Input_Stream.Instance) return PB_String_Access is Size : constant Stream_Element_Offset := Stream_Element_Offset (This.Read_Raw_Varint_32); subtype Return_String_Type is PB_String (1 .. Integer (Size)); function Convert is new Ada.Unchecked_Conversion (Stream_Element_Array, Return_String_Type); begin if Size <= (This.Buffer_Size - This.Buffer_Position) and then Size > 0 then -- Fast Path : We already have the bytes in a contiguous buffer, so -- just copy directly from it. declare Result : constant PB_String_Access := new PB_String'(Convert ( This.Buffer (This.Buffer_Position .. This.Buffer_Position + Size - 1))); begin This.Buffer_Position := This.Buffer_Position + Size; return Result; end; else return Result : PB_String_Access do Result := new PB_String'( Convert ( This.Read_Raw_Bytes (Size) (0 .. Size - 1))); end return; end if; end Read_String; -------------- -- Read_Tag -- -------------- function Read_Tag (This : in out Coded_Input_Stream.Instance) return PB_UInt32 is use type PB_UInt32; begin if This.Is_At_End then This.Last_Tag := 0; return 0; end if; This.Last_Tag := This.Read_Raw_Varint_32; if Get_Tag_Field_Number (This.Last_Tag) = 0 then Invalid_Protocol_Buffer_Exception.Invalid_Tag; end if; return This.Last_Tag; end Read_Tag; ------------------------------ -- Read_Unsigned_Integer_32 -- ------------------------------ function Read_Unsigned_Integer_32 (This : in out Coded_Input_Stream.Instance) return PB_UInt32 is begin return This.Read_Raw_Varint_32; end Read_Unsigned_Integer_32; ------------------------------ -- Read_Unsigned_Integer_64 -- ------------------------------ function Read_Unsigned_Integer_64 (This : in out Coded_Input_Stream.Instance) return PB_UInt64 is begin return This.Read_Raw_Varint_64; end Read_Unsigned_Integer_64; ---------------- -- Skip_Field -- ---------------- function Skip_Field (This : in out Coded_Input_Stream.Instance; Tag : in PB_UInt32) return Boolean is Dummy_1 : PB_Int32; Dummy_2 : PB_UInt32; Dummy_3 : PB_UInt64; pragma Unreferenced (Dummy_1, Dummy_2, Dummy_3); begin case Get_Tag_Wire_Type (Tag) is when VARINT => Dummy_1 := This.Read_Integer_32; return True; when FIXED_32 => Dummy_2 := This.Read_Raw_Little_Endian_32; return True; when FIXED_64 => Dummy_3 := This.Read_Raw_Little_Endian_64; return True; when LENGTH_DELIMITED => declare Length : constant PB_UInt32 := This.Read_Raw_Varint_32; begin This.Skip_Raw_Bytes (Stream_Element_Count (Length)); end; return True; when START_GROUP => return True; when END_GROUP => return False; end case; end Skip_Field; ------------------------ -- Check_Last_Tag_Was -- ------------------------ procedure Check_Last_Tag_Was (This : in Coded_Input_Stream.Instance; Tag : in PB_UInt32) is use type PB_UInt32; begin if This.Last_Tag /= Tag then Invalid_Protocol_Buffer_Exception.Invalid_End_Tag; end if; end Check_Last_Tag_Was; ------------------ -- Skip_Message -- ------------------ procedure Skip_Message (This : in out Coded_Input_Stream.Instance) is Tag : PB_UInt32; use type PB_UInt32; begin loop Tag := This.Read_Tag; if Tag = 0 or else (not This.Skip_Field (Tag)) then return; end if; end loop; end Skip_Message; ------------------ -- Read_Message -- ------------------ procedure Read_Message (This : in out Coded_Input_Stream.Instance; Value : in out Google.Protobuf.Message.Instance'Class) is Length : constant PB_UInt32 := This.Read_Raw_Varint_32; use type PB_UInt32; begin if This.Recursion_Depth >= This.Recursion_Limit then Invalid_Protocol_Buffer_Exception.Recursion_Limit_Exceeded; return; end if; declare Old_Limit : constant Ada.Streams.Stream_Element_Count := This.Push_Limit (Stream_Element_Offset (Length)); begin This.Recursion_Depth := This.Recursion_Depth + 1; Value.Merge_Partial_From_Coded_Input_Stream (This); This.Check_Last_Tag_Was (0); This.Recursion_Depth := This.Recursion_Depth - 1; This.Pop_Limit (Old_Limit); end; end Read_Message; -- ========================================================================== -------------------- -- Set_Size_Limit -- -------------------- function Set_Size_Limit (This : in out Coded_Input_Stream.Instance; Limit : in Stream_Element_Count) return Stream_Element_Count is Old_Limit : constant Stream_Element_Count := This.Size_Limit; begin This.Size_Limit := Limit; return Old_Limit; end Set_Size_Limit; ------------------------ -- Reset_Size_Counter -- ------------------------ procedure Reset_Size_Counter (This : in out Coded_Input_Stream.Instance) is begin This.Total_Bytes_Retired := -This.Buffer_Position; end Reset_Size_Counter; ---------------- -- Push_Limit -- ---------------- function Push_Limit (This : in out Coded_Input_Stream.Instance; Byte_Limit : in Stream_Element_Count) return Stream_Element_Count is New_Current_Limit : Stream_Element_Count; Old_Limit : constant Stream_Element_Count := This.Current_Limit; begin New_Current_Limit := Byte_Limit + This.Total_Bytes_Retired + This.Buffer_Position; if Byte_Limit > Old_Limit then Invalid_Protocol_Buffer_Exception.Truncated_Message; end if; This.Current_Limit := New_Current_Limit; This.Recompute_Buffer_Size_After_Limit; return Old_Limit; end Push_Limit; --------------- -- Pop_Limit -- --------------- procedure Pop_Limit (This : in out Coded_Input_Stream.Instance; Old_Limit : in Stream_Element_Count) is begin This.Current_Limit := Old_Limit; This.Recompute_Buffer_Size_After_Limit; end Pop_Limit; --------------------------- -- Get_Bytes_Until_Limit -- --------------------------- function Get_Bytes_Until_Limit (This : in Coded_Input_Stream.Instance) return Stream_Element_Offset is begin if This.Current_Limit = Stream_Element_Count'Last then return -1; end if; declare Current_Absolute_Position : constant Stream_Element_Offset := This.Total_Bytes_Retired + This.Buffer_Position; begin return This.Current_Limit - Current_Absolute_Position; end; end Get_Bytes_Until_Limit; --------------- -- Is_At_End -- --------------- function Is_At_End (This : in out Coded_Input_Stream.Instance) return Boolean is begin return (This.Buffer_Position = This.Buffer_Size) and then (not This.Refill_Buffer (False)); end Is_At_End; -------------------------- -- Get_Total_Bytes_Read -- -------------------------- function Get_Total_Bytes_Read (This : in Coded_Input_Stream.Instance) return Ada.Streams.Stream_Element_Count is begin return This.Total_Bytes_Retired + This.Buffer_Position; end Get_Total_Bytes_Read; ------------------- -- Refill_Buffer -- ------------------- function Refill_Buffer (This : in out Coded_Input_Stream.Instance; Must_Succeed : in Boolean) return Boolean is begin if This.Buffer_Position < This.Buffer_Size then raise Invalid_Protocol_Buffer_Exception.Protocol_Buffer_Exception with "Refill_Buffer called when buffer wasn't empty."; return False; end if; -- Have we hit the Current_Limit? if This.Total_Bytes_Retired + This.Buffer_Size = This.Current_Limit then if Must_Succeed then Invalid_Protocol_Buffer_Exception.Truncated_Message; return False; else return False; end if; end if; This.Total_Bytes_Retired := This.Total_Bytes_Retired + This.Buffer_Size; This.Buffer_Position := 0; declare Last : Stream_Element_Offset; Total_Bytes_Read : Stream_Element_Count; begin This.Input_Stream.Read (This.Buffer, Last); -- Check for end of stream if Last < This.Buffer'First then This.Buffer_Size := 0; if Must_Succeed then Invalid_Protocol_Buffer_Exception.Truncated_Message; return False; else return False; end if; else This.Buffer_Size := Last + 1; This.Recompute_Buffer_Size_After_Limit; Total_Bytes_Read := This.Total_Bytes_Retired + This.Buffer_Size + This.Buffer_Size_After_Limit; if Total_Bytes_Read > This.Size_Limit then Invalid_Protocol_Buffer_Exception.Size_Limit_Exceeded; return False; end if; return True; end if; end; end Refill_Buffer; ------------------- -- Read_Raw_Byte -- ------------------- function Read_Raw_Byte (This : in out Coded_Input_Stream.Instance) return PB_Byte is Dummy : Boolean; pragma Unreferenced (Dummy); -- Move??? function Stream_Element_To_PB_Byte is new Ada.Unchecked_Conversion (Stream_Element, PB_Byte); begin if This.Buffer_Position = This.Buffer_Size then Dummy := This.Refill_Buffer (True); end if; declare Old_Buffer_Position : constant Stream_Element_Offset := This.Buffer_Position; begin This.Buffer_Position := This.Buffer_Position + 1; return Stream_Element_To_PB_Byte (This.Buffer (Old_Buffer_Position)); end; end Read_Raw_Byte; --------------------------------------- -- Recompute_Buffer_Size_After_Limit -- --------------------------------------- procedure Recompute_Buffer_Size_After_Limit (This : in out Coded_Input_Stream.Instance) is begin This.Buffer_Size := This.Buffer_Size + This.Buffer_Size_After_Limit; declare Buffer_End : constant Stream_Element_Count := This.Total_Bytes_Retired + This.Buffer_Size; begin if Buffer_End > This.Current_Limit then This.Buffer_Size_After_Limit := Buffer_End - This.Current_Limit; This.Buffer_Size := This.Buffer_Size - This.Buffer_Size_After_Limit; else This.Buffer_Size_After_Limit := 0; end if; end; end Recompute_Buffer_Size_After_Limit; -------------------- -- Read_Raw_Bytes -- -------------------- function Read_Raw_Bytes (This : in out Coded_Input_Stream.Instance; Size : in Stream_Element_Count) return Stream_Element_Array is Dummy : Boolean; pragma Unreferenced (Dummy); begin -- Are we reading outside the current limit? if This.Total_Bytes_Retired + This.Buffer_Position + Size > This.Current_Limit then -- Skip bytes up to limit This.Skip_Raw_Bytes (This.Current_Limit - This.Total_Bytes_Retired - This.Buffer_Position); -- Fail here Invalid_Protocol_Buffer_Exception.Truncated_Message; return Stream_Element_Array'(0 => <>); end if; if Size <= This.Buffer_Size - This.Buffer_Position then -- All bytes needed are already buffered return Bytes : Stream_Element_Array (0 .. Size - 1) do Bytes := This.Buffer (This.Buffer_Position .. This.Buffer_Position + Size - 1); This.Buffer_Position := This.Buffer_Position + Size; end return; elsif Size < BUFFER_SIZE then -- Reading more bytes than are in the buffer, but not an excessive number -- of bytes. We can safely allocate the resulting array ahead of time. declare Bytes : Stream_Element_Array (0 .. Size - 1); Position : Stream_Element_Offset := This.Buffer_Size - This.Buffer_Position; begin -- First copy what we have. Bytes (0 .. Position - 1) := This.Buffer (This.Buffer_Position .. This.Buffer_Position + Position - 1); This.Buffer_Position := This.Buffer_Size; Dummy := This.Refill_Buffer (True); while Size - Position > This.Buffer_Size loop Bytes (Position .. This.Buffer_Size - 1) := This.Buffer (0 .. This.Buffer_Size - 1); Position := Position + This.Buffer_Size; This.Buffer_Position := This.Buffer_Size; Dummy := This.Refill_Buffer (True); end loop; Bytes (Position .. Size - 1) := This.Buffer (0 .. Size - Position - 1); This.Buffer_Position := Size - Position; return Bytes; end; else -- The size is very large. For security reasons, we can't allocate the -- entire byte array yet. The size comes directly from the input, so a -- maliciously-crafted message could provide a bogus very large size in -- order to trick the app into allocating a lot of memory. We avoid this -- by allocating and reading only a small chunk at a time, so that the -- malicious message must actually *be* extremely large to cause -- problems. Meanwhile, we limit the allowed size of a message elsewhere. -- Remember the buffer markers since we'll have to copy the bytes out of -- it later. -- Consider replacing this code which might be _very_ inefficient! declare subtype Buffer_Type is Stream_Element_Array (0 .. BUFFER_SIZE - 1); package Buffer_Vector is new Ada.Containers.Indefinite_Vectors (Natural, Stream_Element_Array); Chunks : Buffer_Vector.Vector; Original_Buffer_Size : constant Stream_Element_Count := This.Buffer_Size; Original_Buffer_Position : constant Stream_Element_Offset := This.Buffer_Position; Size_Left : Stream_Element_Count := Size - (Original_Buffer_Size - Original_Buffer_Position); begin This.Total_Bytes_Retired := This.Total_Bytes_Retired + This.Buffer_Size; This.Buffer_Position := 0; This.Buffer_Size := 0; while Size_Left > 0 loop declare Chunk : Buffer_Type; Position : Stream_Element_Offset := 0; Read_Size : constant Stream_Element_Count := Stream_Element_Count'Min (Size_Left, BUFFER_SIZE); Last : Stream_Element_Offset; begin while Position < Read_Size loop This.Input_Stream.Read (Chunk (Position .. Read_Size - Position - 1), Last); if This.Buffer'First - 1 = Last then Invalid_Protocol_Buffer_Exception.Truncated_Message; return Stream_Element_Array'(0 => <>); end if; This.Total_Bytes_Retired := This.Total_Bytes_Retired + Last + 1; Position := Last + 1; end loop; Size_Left := Size_Left - Read_Size; Chunks.Append (Chunk (0 .. Read_Size - 1)); end; end loop; -- OK, got everything. Now concatenate it all into one buffer. declare Bytes : Stream_Element_Array (0 .. Size - 1); Position : Stream_Element_Offset := Original_Buffer_Size - Original_Buffer_Position; begin -- Start by copying the leftover bytes from This.Buffer Bytes (0 .. Position - 1) := This.Buffer (Original_Buffer_Position .. Original_Buffer_Position + Position - 1); for E of Chunks loop Bytes (Position .. Position + E'Length - 1) := E; Position := Position + E'Length; end loop; return Bytes; end; end; end if; end Read_Raw_Bytes; -------------------- -- Skip_Raw_Bytes -- -------------------- procedure Skip_Raw_Bytes (This : in out Coded_Input_Stream.Instance; Size : in Stream_Element_Count) is Dummy : Boolean; pragma Unreferenced (Dummy); begin -- Are we reading outside the current limit? if This.Total_Bytes_Retired + This.Buffer_Position + Size > This.Current_Limit then -- Skip bytes up to limit This.Skip_Raw_Bytes (This.Current_Limit - This.Total_Bytes_Retired - This.Buffer_Position); -- Fail here Invalid_Protocol_Buffer_Exception.Truncated_Message; end if; if Size <= This.Buffer_Size - This.Buffer_Position then -- All bytes needed are already buffered This.Buffer_Position := This.Buffer_Position + Size; else -- Skipping more bytes than are in the buffer. First skip what we have. declare Position : Stream_Element_Offset := This.Buffer_Size - This.Buffer_Position; begin This.Buffer_Position := This.Buffer_Size; -- Keep refilling the buffer until we get to the point we wanted to skip -- to. This has the side effect of ensuring the limits are updated -- correctly. Dummy := This.Refill_Buffer (True); while Size - Position > This.Buffer_Size loop Position := Position + This.Buffer_Size; This.Buffer_Position := This.Buffer_Size; Dummy := This.Refill_Buffer (True); end loop; This.Buffer_Position := Size - Position; end; end if; end Skip_Raw_Bytes; end Google.Protobuf.IO.Coded_Input_Stream;
io7m/coreland-spatial_hash
Ada
183
ads
package Test is procedure Assert (Check : in Boolean; Pass_Message : in String := "assertion passed"; Fail_Message : in String := "assertion failed"); end Test;
reznikmm/matreshka
Ada
6,739
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Svg.Title_Elements is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Svg_Title_Element_Node is begin return Self : Svg_Title_Element_Node do Matreshka.ODF_Svg.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Svg_Prefix); end return; end Create; ---------------- -- Enter_Node -- ---------------- overriding procedure Enter_Node (Self : not null access Svg_Title_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Enter_Svg_Title (ODF.DOM.Svg_Title_Elements.ODF_Svg_Title_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Enter_Node (Visitor, Control); end if; end Enter_Node; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Svg_Title_Element_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Title_Element; end Get_Local_Name; ---------------- -- Leave_Node -- ---------------- overriding procedure Leave_Node (Self : not null access Svg_Title_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Leave_Svg_Title (ODF.DOM.Svg_Title_Elements.ODF_Svg_Title_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Leave_Node (Visitor, Control); end if; end Leave_Node; ---------------- -- Visit_Node -- ---------------- overriding procedure Visit_Node (Self : not null access Svg_Title_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then ODF.DOM.Iterators.Abstract_ODF_Iterator'Class (Iterator).Visit_Svg_Title (Visitor, ODF.DOM.Svg_Title_Elements.ODF_Svg_Title_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Visit_Node (Iterator, Visitor, Control); end if; end Visit_Node; begin Matreshka.DOM_Documents.Register_Element (Matreshka.ODF_String_Constants.Svg_URI, Matreshka.ODF_String_Constants.Title_Element, Svg_Title_Element_Node'Tag); end Matreshka.ODF_Svg.Title_Elements;
zhmu/ananas
Ada
2,132
ads
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- V A S T -- -- -- -- S p e c -- -- -- -- Copyright (C) 2020-2022, 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 is the entry point for VAST: Verifier for the Ada Semantic -- Tree. with Types; use Types; package VAST is procedure Check_Tree (GNAT_Root : Node_Id); -- Check the validity of the given Root tree end VAST;
ekoeppen/STM32_Generic_Ada_Drivers
Ada
323
ads
with HAL; generic with package I2C is new HAL.I2C (<>); package Drivers.Si7006 is subtype Temperature_Type is Integer range -10000 .. 10000; subtype Humidity_Type is Natural range 0 .. 100; function Temperature_x100 return Temperature_Type; function Humidity return Humidity_Type; end Drivers.Si7006;
reznikmm/matreshka
Ada
7,001
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Table.Data_Pilot_Table_Elements is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Table_Data_Pilot_Table_Element_Node is begin return Self : Table_Data_Pilot_Table_Element_Node do Matreshka.ODF_Table.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Table_Prefix); end return; end Create; ---------------- -- Enter_Node -- ---------------- overriding procedure Enter_Node (Self : not null access Table_Data_Pilot_Table_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Enter_Table_Data_Pilot_Table (ODF.DOM.Table_Data_Pilot_Table_Elements.ODF_Table_Data_Pilot_Table_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Enter_Node (Visitor, Control); end if; end Enter_Node; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Table_Data_Pilot_Table_Element_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Data_Pilot_Table_Element; end Get_Local_Name; ---------------- -- Leave_Node -- ---------------- overriding procedure Leave_Node (Self : not null access Table_Data_Pilot_Table_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Leave_Table_Data_Pilot_Table (ODF.DOM.Table_Data_Pilot_Table_Elements.ODF_Table_Data_Pilot_Table_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Leave_Node (Visitor, Control); end if; end Leave_Node; ---------------- -- Visit_Node -- ---------------- overriding procedure Visit_Node (Self : not null access Table_Data_Pilot_Table_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then ODF.DOM.Iterators.Abstract_ODF_Iterator'Class (Iterator).Visit_Table_Data_Pilot_Table (Visitor, ODF.DOM.Table_Data_Pilot_Table_Elements.ODF_Table_Data_Pilot_Table_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Visit_Node (Iterator, Visitor, Control); end if; end Visit_Node; begin Matreshka.DOM_Documents.Register_Element (Matreshka.ODF_String_Constants.Table_URI, Matreshka.ODF_String_Constants.Data_Pilot_Table_Element, Table_Data_Pilot_Table_Element_Node'Tag); end Matreshka.ODF_Table.Data_Pilot_Table_Elements;
charlie5/lace
Ada
10,330
adb
with gel.Window.setup, gel.Applet.gui_world, gel.Forge, gel.Sprite, gel.World, gel.Camera, gel.Keyboard, Physics, openGL.Palette, openGL.Model.text, float_Math.Random, lace.Event, lace.Response, lace.Event.utility, Ada.Text_IO, Ada.Exceptions; pragma Unreferenced (gel.Window.setup); procedure launch_Pong -- -- Basic pong game. -- is use gel.Applet, gel.Applet.gui_world, gel.Keyboard, gel.Math, openGL.Palette, Ada.Text_IO; stadium_Width : constant := 30.0; stadium_Height : constant := 20.0; --- Applet -- the_Applet : gel.Applet.gui_world.view := gel.Forge.new_gui_Applet (Named => "Pong", window_Width => 800, window_Height => 600, space_Kind => physics.Box2d); --- Ball -- the_Ball : constant gel.Sprite.view := gel.Forge.new_circle_Sprite (in_World => the_Applet.World, Site => [0.0, 0.0], Mass => 1.0, Bounce => 1.0, Friction => 0.0, Radius => 0.5, Color => White, Texture => openGL.to_Asset ("assets/opengl/texture/Face1.bmp")); --- Players -- type Player is record Paddle : gel.Sprite.view; moving_Up : Boolean := False; moving_Down : Boolean := False; Score : Natural := 0; score_Text : gel.Sprite.view; score_Model : openGL.Model.text.view; end record; type player_Id is range 1 .. 2; type Players is array (player_Id) of Player; the_Players : Players; procedure add_Player (Id : in player_Id; Site : in Vector_2) is the_Player : Player renames the_Players (Id); score_Site : constant Vector_2 := Site + [0.0, stadium_Height / 2.0 + 0.8]; begin the_Player.Paddle := gel.Forge.new_rectangle_Sprite (the_Applet.World, Site => Site, Mass => 0.0, Bounce => 1.0, Friction => 0.0, Width => 0.7, Height => 3.0, Color => Red); the_Player.score_Text := gel.Forge.new_text_Sprite (the_Applet.World, Origin_3D, " 0", the_Applet.Font, Green); the_Player.score_Model := openGL.Model.text.view (the_Player.score_Text.graphics_Model); the_Applet.World.add (the_Player.Paddle); the_Applet.World.add (the_Player.score_Text); the_Player.score_Text.Site_is (Vector_3 (score_Site & 0.0)); end add_Player; --- Walls -- procedure add_Wall (Site : in Vector_2; Width, Height : in Real) is the_Wall : constant gel.Sprite.view := gel.Forge.new_rectangle_Sprite (the_Applet.World, Site => Site, Mass => 0.0, Bounce => 1.0, Friction => 0.0, Width => Width, Height => Height, Color => Blue); begin the_Applet.World.add (the_Wall); end add_Wall; --- Controls -- relaunch_Ball : Boolean := True; Cycle : Natural := 0; --- Events -- type key_press_Response is new lace.Response.item with null record; overriding procedure respond (Self : in out key_press_Response; to_Event : in lace.Event.item'Class) is pragma Unreferenced (Self); the_Event : gel.Keyboard.key_press_Event renames gel.Keyboard.key_press_Event (to_Event); the_Key : constant gel.keyboard.Key := the_Event.modified_Key.Key; begin case the_Key is when up => the_Players (2).moving_Up := True; when down => the_Players (2).moving_Down := True; when a => the_Players (1).moving_Up := True; when z => the_Players (1).moving_Down := True; when SPACE => relaunch_Ball := True; when others => null; end case; end respond; type key_release_Response is new lace.Response.item with null record; overriding procedure respond (Self : in out key_release_Response; to_Event : in lace.Event.item'Class) is pragma Unreferenced (Self); the_Event : gel.Keyboard.key_release_Event renames gel.Keyboard.key_release_Event (to_Event); the_Key : constant gel.keyboard.Key := the_Event.modified_Key.Key; begin case the_Key is when up => the_Players (2).moving_Up := False; when down => the_Players (2).moving_Down := False; when a => the_Players (1).moving_Up := False; when z => the_Players (1).moving_Down := False; when others => null; end case; end respond; the_key_press_Response : aliased key_press_Response; the_key_release_Response : aliased key_release_Response; use lace.Event.Utility; begin the_Applet.Camera.Site_is ([0.0, 0.0, 20.0]); the_Applet.World.Gravity_is ([0.0, 0.0, 0.0]); the_Applet.World.add (the_Ball); --- Add the players. -- declare paddle_X_Offset : constant := stadium_Width / 2.0 - 2.0; begin add_Player (1, Site => [-paddle_X_Offset, 0.0]); add_Player (2, Site => [ paddle_X_Offset, 0.0]); end; --- Build the stadium. -- declare Thickness : constant := 1.0; -- Thickness of the walls. goal_Size : constant := 6.0; side_wall_Height : constant := (stadium_Height - goal_Size) / 2.0; top_wall_Y_Offset : constant := (stadium_Height - Thickness) / 2.0; side_wall_X_Offset : constant := stadium_Width / 2.0; side_wall_Y_Offset : constant := (side_wall_Height + goal_Size) / 2.0; begin add_Wall (Site => [0.0, top_wall_Y_Offset], Width => stadium_Width, Height => Thickness); -- Top add_Wall (Site => [0.0, -top_wall_Y_Offset], Width => stadium_Width, Height => Thickness); -- Bottom add_Wall (Site => [-side_wall_X_Offset, side_wall_Y_Offset], Width => Thickness, Height => side_wall_Height); -- upper Left add_Wall (Site => [-side_wall_X_Offset, -side_wall_Y_Offset], Width => Thickness, Height => side_wall_Height); -- lower Left add_Wall (Site => [ side_wall_X_Offset, side_wall_Y_Offset], Width => Thickness, Height => side_wall_Height); -- upper Right add_Wall (Site => [ side_wall_X_Offset, -side_wall_Y_Offset], Width => Thickness, Height => side_wall_Height); -- lower Right end; -- Connect events. -- connect ( the_Applet.local_Observer, the_Applet.Keyboard.all'Access, the_key_press_Response'unchecked_Access, +gel.Keyboard.key_press_Event'Tag); connect ( the_Applet.local_Observer, the_Applet.Keyboard.all'Access, the_key_release_Response'unchecked_Access, +gel.Keyboard.key_release_Event'Tag); --- Main loop. -- while the_Applet.is_open loop Cycle := Cycle + 1; the_Applet.World.evolve; -- Advance the world. the_Applet.freshen; -- Handle any new events and update the screen. --- Check goal scoring. -- declare procedure award_Goal (Id : in player_Id) is the_Player : Player renames the_Players (Id); new_Score : constant String := Natural'Image (the_Player.Score + 1); begin relaunch_Ball := True; the_Player.Score := the_Player.Score + 1; the_Player.score_Model.Text_is (new_Score); the_Ball.Site_is (Origin_3d); the_Ball.Speed_is ([0.0, 0.0, 0.0]); end award_Goal; goal_X_Boundary : constant := stadium_Width / 2.0 + 1.0; begin if the_Ball.Site (1) > goal_X_Boundary then award_Goal (Id => 1); elsif the_Ball.Site (1) < -goal_X_Boundary then award_Goal (Id => 2); end if; end; if relaunch_Ball then the_Ball.Site_is ([0.0, 0.0, 0.0]); declare the_Force : Vector_3 := [gel.Math.Random.random_Real (50.0, 200.0), gel.Math.Random.random_Real ( 5.0, 20.0), 0.0]; begin if gel.Math.Random.random_Boolean then the_Force := -the_Force; end if; the_Ball.apply_Force (the_Force); end; relaunch_Ball := False; end if; --- Move the paddles. -- for the_Player of the_Players loop declare paddle_Speed : constant Vector_3 := [0.0, 0.2, 0.0]; begin if the_Player.moving_Up then the_Player.Paddle.Site_is (the_Player.Paddle.Site + paddle_Speed); end if; if the_Player.moving_Down then the_Player.Paddle.Site_is (the_Player.Paddle.Site - paddle_Speed); end if; end; end loop; end loop; free (the_Applet); exception when E : others => new_Line; put_Line ("Unhandled exception in main task !"); put_Line (Ada.Exceptions.Exception_Information (E)); new_Line; end launch_Pong;
stcarrez/ada-awa
Ada
1,299
ads
----------------------------------------------------------------------- -- awa-blogs-tests -- Unit tests for blogs module -- Copyright (C) 2011, 2012, 2013 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- 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.Tests; with AWA.Tests; package AWA.Blogs.Modules.Tests is procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite); type Test is new AWA.Tests.Test with null record; -- Test creation of blog by simulating web requests. procedure Test_Create_Blog (T : in out Test); -- Test creating and updating of a blog post procedure Test_Create_Post (T : in out Test); end AWA.Blogs.Modules.Tests;
ekoeppen/STM32_Generic_Ada_Drivers
Ada
1,419
ads
with STM32_SVD.EXTI; package STM32GD.EXTI is pragma Preelaborate; subtype External_Line_Number is Integer range 0 .. 31; type External_Triggers is (Interrupt_Rising_Edge, Interrupt_Falling_Edge, Interrupt_Rising_Falling_Edge, Event_Rising_Edge, Event_Falling_Edge, Event_Rising_Falling_Edge); type EXTI_IRQ_Status is array (0 .. 31) of Boolean; subtype Interrupt_Triggers is External_Triggers range Interrupt_Rising_Edge .. Interrupt_Rising_Falling_Edge; subtype Event_Triggers is External_Triggers range Event_Rising_Edge .. Event_Rising_Falling_Edge; procedure Connect_External_Interrupt (Pin: UInt4; Port_Index: UInt4); procedure Enable_External_Interrupt (Line : External_Line_Number; Trigger : Interrupt_Triggers) with Inline; procedure Disable_External_Interrupt (Line : External_Line_Number) with Inline; procedure Enable_External_Event (Line : External_Line_Number; Trigger : Event_Triggers) with Inline; procedure Disable_External_Event (Line : External_Line_Number) with Inline; procedure Generate_SWI (Line : External_Line_Number) with Inline; function External_Interrupt_Pending (Line : External_Line_Number) return Boolean with Inline; procedure Clear_External_Interrupt (Line : External_Line_Number) with Inline; end STM32GD.EXTI;
sbksba/Concurrence-LI330
Ada
3,164
adb
with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO,Ada.Integer_Text_IO; package body Matrice is -- procedure d'initialisation d'une matrice par saisie des valeurs au clavier -- l'initialisation doit se faire ligne par ligne procedure Initialiser_Une_Matrice(Matrice: in out Une_Matrice_Entiere) is cpt : Natural := 0; begin for I in Matrice'range(1) loop for J in Matrice'range(2) loop Matrice(I,J) := cpt; cpt := cpt+1; end loop; end loop; end Initialiser_Une_Matrice; -- procedure d'affichage d'une matrice procedure Afficher_Une_Matrice(Matrice : in Une_Matrice_Entiere) is begin for i in Matrice'range(1) loop for j in Matrice'range(2) loop put(Matrice(i, j), width => 8); end loop; new_line; end loop; new_line; end Afficher_Une_Matrice; -- fonction d'addition de 2 matrices function "+"(Matrice1, Matrice2 : Une_Matrice_Entiere) return Une_Matrice_Entiere is Matrice_Resultat : Une_Matrice_Entiere(1..Matrice1'length(1),1..Matrice1'length(2)); begin if Matrice1'length(1) /= Matrice2'length(1) or Matrice1'length(2) /= Matrice2'length(2) then raise Taille_Non_Compatible_a; end if; for I in 1..Matrice1'length(1) loop for J in 1..Matrice1'length(2) loop Matrice_Resultat(I, J) := Matrice1(Matrice1'First(1)+I-1,Matrice1'First(2)+J-1) + Matrice2(Matrice2'First(1)+I-1,Matrice2'First(2)+J-1); end loop; end loop; return Matrice_Resultat; end "+"; -- fonction de multiplication d'une matrice par un scalaire function "*"(Matrice : in Une_Matrice_Entiere; Scalaire : Integer) return Une_Matrice_Entiere is Matrice_Resultat : Une_Matrice_Entiere(1..Matrice'Length(1), 1..Matrice'Length(2)); begin for I in 1..Matrice'length(1) loop for J in 1..Matrice'length(2) loop Matrice_Resultat(I, J) := Matrice(Matrice'First(1)+I-1,Matrice'First(2)+J-1) * Scalaire; end loop; end loop; return Matrice_Resultat; end "*"; -- fonction de multiplication d'un scalaire par une matrice function "*"(Scalaire : Integer; Matrice : in Une_Matrice_Entiere) return Une_Matrice_Entiere is begin return Matrice * Scalaire; end "*"; -- fonction de multiplication d'une matrice par une matrice function "*"(Matrice1, Matrice2 : in Une_Matrice_Entiere) return Une_Matrice_Entiere is Matrice_Resultat : Une_Matrice_Entiere(1..Matrice1'Length(1), 1..Matrice2'Length(2)); begin if Matrice1'length(1) /= Matrice2'length(1) or Matrice1'length(2) /= Matrice2'length(2) then raise Taille_Non_Compatible_m; end if; for I in 1..Matrice1'Length(1) loop for J in 1..Matrice2'Length(2) loop Matrice_Resultat(I, J) := 0; for K in 1..Matrice1'Length(2) loop Matrice_Resultat(I, J) := Matrice_Resultat(I, J) + Matrice1(Matrice1'First(1)+I-1,Matrice1'First(2)+K-1) * Matrice2(Matrice2'First(1)+K-1,Matrice2'First(2)+J-1); end loop; end loop; end loop; return Matrice_Resultat; end "*"; end Matrice;
zhmu/ananas
Ada
2,628
adb
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS -- -- -- -- S Y S T E M . I N T E R R U P T _ M A N A G E M E N T -- -- -- -- B o d y -- -- -- -- Copyright (C) 1997-2022, 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 a NO tasking version of this package package body System.Interrupt_Management is ---------------- -- Initialize -- ---------------- procedure Initialize is begin null; end Initialize; end System.Interrupt_Management;
ytomino/gnat4drake
Ada
421
adb
package body GNAT.Calendar.Time_IO is function Image (Date : Ada.Calendar.Time; Picture : Picture_String) return String is begin raise Program_Error; -- unimplemented return Image (Date, Picture); end Image; function Value (Date : String) return Ada.Calendar.Time is begin raise Program_Error; -- unimplemented return Value (Date); end Value; end GNAT.Calendar.Time_IO;
reznikmm/matreshka
Ada
3,719
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Elements; package ODF.DOM.Form_Connection_Resource_Elements is pragma Preelaborate; type ODF_Form_Connection_Resource is limited interface and XML.DOM.Elements.DOM_Element; type ODF_Form_Connection_Resource_Access is access all ODF_Form_Connection_Resource'Class with Storage_Size => 0; end ODF.DOM.Form_Connection_Resource_Elements;
KamilKrol5/concurrent-programming
Ada
600
ads
package constants is MAX_ARGUMENT_VALUE : constant := 500.0; MAX_EMPLOYEES : constant := 2; MAX_CHAIRMEN : constant := 1; MAX_CLIENTS : constant := 1; MAX_TASKLIST_SIZE : constant := 40; MAX_STORAGE_CAPACITY : constant := 40; EMPLOYEE_SLEEP : constant := 1; CHAIRMAN_SLEEP : constant := 0.4; CLIENT_SLEEP : constant := 2; NUMBER_OF_MACHINES : constant := 2; MACHINE_SLEEP : constant := 0.8; IMPATIENT_WAIT : constant := 1.0; IMPATIENT_PROBABILITY: constant := 0.5; end constants;
tj800x/SPARKNaCl
Ada
4,284
adb
with HAL; use HAL; with HiFive1.LEDs; use HiFive1.LEDs; with FE310; with FE310.CLINT; with FE310.Time; use FE310.Time; with Interfaces; use Interfaces; with IO; with SPARKNaCl; use SPARKNaCl; with SPARKNaCl.Sign; use SPARKNaCl.Sign; with SPARKNaCl.Sign.Utils; use SPARKNaCl.Sign.Utils; with SPARKNaCl.Count; with TweetNaCl_API; with RISCV.CSR; use RISCV.CSR; with FE310.Performance_Monitor; use FE310.Performance_Monitor; procedure TSign is subtype U64 is Unsigned_64; M : constant Byte_Seq (0 .. 255) := (0 => 16#55#, others => 16#aa#); SK : Signing_SK; SM1 : Byte_Seq (0 .. 319) := (others => 0); SM2 : Byte_Seq (0 .. 319) := (others => 0); My_SK : constant Bytes_64 := (16#56#, 16#89#, 16#60#, 16#72#, 16#D7#, 16#E1#, 16#B5#, 16#35#, 16#2B#, 16#12#, 16#B6#, 16#FC#, 16#69#, 16#94#, 16#F3#, 16#76#, 16#A7#, 16#5C#, 16#42#, 16#DF#, 16#70#, 16#1E#, 16#AC#, 16#F0#, 16#A0#, 16#EF#, 16#30#, 16#C6#, 16#A1#, 16#D8#, 16#27#, 16#F6#, 16#D6#, 16#40#, 16#DA#, 16#F4#, 16#0B#, 16#0B#, 16#35#, 16#EF#, 16#03#, 16#25#, 16#5B#, 16#EF#, 16#A3#, 16#4E#, 16#31#, 16#D4#, 16#35#, 16#A1#, 16#A2#, 16#E2#, 16#FF#, 16#AA#, 16#EA#, 16#72#, 16#82#, 16#82#, 16#D2#, 16#D0#, 16#93#, 16#6C#, 16#19#, 16#10#); T1, T2 : UInt64; Total_Time : Unsigned_64; CPU_Hz1, CPU_Hz2 : UInt32; procedure Report; procedure Tweet_Sign (SM : out Byte_Seq; M : in Byte_Seq; SK : in Signing_SK); procedure Tweet_Sign (SM : out Byte_Seq; M : in Byte_Seq; SK : in Signing_SK) is SMLen : Unsigned_64; begin TweetNaCl_API.Crypto_Sign (SM, SMLen, M, M'Length, SK); end Tweet_Sign; procedure Report is begin IO.Put ("Total: "); IO.Put (UInt64 (Total_Time)); IO.Put_Line (" cycles"); end Report; begin CPU_Hz1 := FE310.CPU_Frequency; -- The SPI flash clock divider should be as small as possible to increase -- the execution speed of instructions that are not yet in the instruction -- cache. FE310.Set_SPI_Flash_Clock_Divider (2); -- Load the internal oscillator factory calibration to be sure it -- oscillates at a known frequency. FE310.Load_Internal_Oscilator_Calibration; -- Use the HiFive1 16 MHz crystal oscillator which is more acurate than the -- internal oscillator. FE310.Use_Crystal_Oscillator; HiFive1.LEDs.Initialize; CPU_Hz2 := FE310.CPU_Frequency; IO.Put_Line ("CPU Frequency reset was: ", U64 (CPU_Hz1)); IO.Put_Line ("CPU Frequency now is: ", U64 (CPU_Hz2)); Construct (My_SK, SK); FE310.Performance_Monitor.Set_Commit_Events (3, No_Commit_Events); FE310.Performance_Monitor.Set_Commit_Events (4, No_Commit_Events); Turn_On (Red_LED); T1 := FE310.CLINT.Machine_Time; T2 := FE310.CLINT.Machine_Time; IO.Put_Line ("Null timing test:", U64 (T2 - T1)); T1 := Mcycle.Read; Delay_S (1); T2 := Mcycle.Read; IO.Put_Line ("One second test (CYCLE): ", U64 (T2 - T1)); T1 := Minstret.Read; Delay_S (1); T2 := Minstret.Read; IO.Put_Line ("One second test (INSTRET):", U64 (T2 - T1)); T1 := FE310.CLINT.Machine_Time; Delay_S (1); T2 := FE310.CLINT.Machine_Time; IO.Put_Line ("One second test (CLINT): ", U64 (T2 - T1)); IO.Put_Line ("SPARKNaCl.Sign test"); SPARKNaCl.Count.Reset; T1 := Mcycle.Read; SPARKNaCl.Sign.Sign (SM1, M, SK); T2 := Mcycle.Read; Total_Time := Unsigned_64 (T2 - T1); Report; Turn_Off (Red_LED); Turn_On (Green_LED); IO.New_Line; IO.Put_Line ("TweetNaCl.Sign test"); TweetNaCl_API.Reset; T1 := Mcycle.Read; Tweet_Sign (SM2, M, SK); T2 := Mcycle.Read; Total_Time := Unsigned_64 (T2 - T1); Report; Turn_Off (Green_LED); -- Blinky! loop Turn_On (Red_LED); Delay_S (1); Turn_Off (Red_LED); Turn_On (Green_LED); Delay_S (1); Turn_Off (Green_LED); Turn_On (Blue_LED); Delay_S (1); Turn_Off (Blue_LED); end loop; end TSign;
reznikmm/matreshka
Ada
7,160
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Text.Illustration_Index_Source_Elements is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Text_Illustration_Index_Source_Element_Node is begin return Self : Text_Illustration_Index_Source_Element_Node do Matreshka.ODF_Text.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Text_Prefix); end return; end Create; ---------------- -- Enter_Node -- ---------------- overriding procedure Enter_Node (Self : not null access Text_Illustration_Index_Source_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Enter_Text_Illustration_Index_Source (ODF.DOM.Text_Illustration_Index_Source_Elements.ODF_Text_Illustration_Index_Source_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Enter_Node (Visitor, Control); end if; end Enter_Node; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Text_Illustration_Index_Source_Element_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Illustration_Index_Source_Element; end Get_Local_Name; ---------------- -- Leave_Node -- ---------------- overriding procedure Leave_Node (Self : not null access Text_Illustration_Index_Source_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Leave_Text_Illustration_Index_Source (ODF.DOM.Text_Illustration_Index_Source_Elements.ODF_Text_Illustration_Index_Source_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Leave_Node (Visitor, Control); end if; end Leave_Node; ---------------- -- Visit_Node -- ---------------- overriding procedure Visit_Node (Self : not null access Text_Illustration_Index_Source_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then ODF.DOM.Iterators.Abstract_ODF_Iterator'Class (Iterator).Visit_Text_Illustration_Index_Source (Visitor, ODF.DOM.Text_Illustration_Index_Source_Elements.ODF_Text_Illustration_Index_Source_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Visit_Node (Iterator, Visitor, Control); end if; end Visit_Node; begin Matreshka.DOM_Documents.Register_Element (Matreshka.ODF_String_Constants.Text_URI, Matreshka.ODF_String_Constants.Illustration_Index_Source_Element, Text_Illustration_Index_Source_Element_Node'Tag); end Matreshka.ODF_Text.Illustration_Index_Source_Elements;
AdaCore/ada-traits-containers
Ada
3,522
ads
-- -- Copyright (C) 2015-2016, AdaCore -- -- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -- -- The implementation for bounded list of definite elements. -- This implementation does not perform any memory allocation. -- It is compatible with SPARK. -- -- As opposed to some of the other list's storage packages, this package does -- not take a Base_Container formal parameter. This is for compatibility with -- SPARK, where it is not possible to extend a tagged type with new -- discriminants. -- As a result, a bounded list is always non-limited and non-controlled. This -- only works fine for a list of definite elements where no memory allocation -- occurs. pragma Ada_2012; with Conts.Elements.Definite; generic with package Elements is new Conts.Elements.Definite (<>); package Conts.Lists.Storage.Bounded_Definite with SPARK_Mode is pragma Assertion_Policy (Pre => Suppressible, Ghost => Suppressible, Post => Ignore); subtype Stored_Type is Elements.Traits.Stored; package Impl is type Container (Capacity : Count_Type) is abstract tagged private; type Node_Access is new Count_Type; Null_Node_Access : constant Node_Access := 0; procedure Allocate (Self : in out Impl.Container'Class; Element : Stored_Type; N : out Impl.Node_Access); function Get_Element (Self : Impl.Container'Class; N : Impl.Node_Access) return Stored_Type with Inline; function Get_Next (Self : Impl.Container'Class; N : Impl.Node_Access) return Impl.Node_Access with Inline; function Get_Previous (Self : Impl.Container'Class; N : Impl.Node_Access) return Impl.Node_Access with Inline; procedure Set_Previous (Self : in out Impl.Container'Class; N, Prev : Impl.Node_Access) with Inline; procedure Set_Next (Self : in out Impl.Container'Class; N, Next : Impl.Node_Access) with Inline; procedure Set_Element (Self : in out Impl.Container'Class; N : Node_Access; E : Stored_Type) with Inline; function Capacity (Self : Impl.Container'Class) return Count_Type is (Self.Capacity) with Inline; procedure Assign (Nodes : in out Impl.Container'Class; Source : Impl.Container'Class; New_Head : out Impl.Node_Access; Old_Head : Impl.Node_Access; New_Tail : out Impl.Node_Access; Old_Tail : Impl.Node_Access) with Pre => Nodes.Capacity >= Source.Capacity; -- See description in Conts.Lists.Nodes private pragma SPARK_Mode (Off); type Node is record Element : Stored_Type; Previous, Next : Node_Access := Null_Node_Access; end record; type Nodes_Array is array (Count_Type range <>) of Node; type Container (Capacity : Count_Type) is abstract tagged record Free : Integer := 0; -- head of free nodes list -- For a negative value, its absolute value points to the first free -- element Nodes : Nodes_Array (1 .. Capacity); end record; end Impl; use Impl; package Traits is new Conts.Lists.Storage.Traits (Elements => Elements.Traits, Container => Impl.Container, Node_Access => Impl.Node_Access, Null_Access => Impl.Null_Node_Access, Allocate => Allocate); end Conts.Lists.Storage.Bounded_Definite;
reznikmm/matreshka
Ada
3,729
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Attributes; package ODF.DOM.Text_Organizations_Attributes is pragma Preelaborate; type ODF_Text_Organizations_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Text_Organizations_Attribute_Access is access all ODF_Text_Organizations_Attribute'Class with Storage_Size => 0; end ODF.DOM.Text_Organizations_Attributes;
reznikmm/matreshka
Ada
5,328
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ with AMF.Generic_Collections; package AMF.UML.Clear_Variable_Actions.Collections is pragma Preelaborate; package UML_Clear_Variable_Action_Collections is new AMF.Generic_Collections (UML_Clear_Variable_Action, UML_Clear_Variable_Action_Access); type Set_Of_UML_Clear_Variable_Action is new UML_Clear_Variable_Action_Collections.Set with null record; Empty_Set_Of_UML_Clear_Variable_Action : constant Set_Of_UML_Clear_Variable_Action; type Ordered_Set_Of_UML_Clear_Variable_Action is new UML_Clear_Variable_Action_Collections.Ordered_Set with null record; Empty_Ordered_Set_Of_UML_Clear_Variable_Action : constant Ordered_Set_Of_UML_Clear_Variable_Action; type Bag_Of_UML_Clear_Variable_Action is new UML_Clear_Variable_Action_Collections.Bag with null record; Empty_Bag_Of_UML_Clear_Variable_Action : constant Bag_Of_UML_Clear_Variable_Action; type Sequence_Of_UML_Clear_Variable_Action is new UML_Clear_Variable_Action_Collections.Sequence with null record; Empty_Sequence_Of_UML_Clear_Variable_Action : constant Sequence_Of_UML_Clear_Variable_Action; private Empty_Set_Of_UML_Clear_Variable_Action : constant Set_Of_UML_Clear_Variable_Action := (UML_Clear_Variable_Action_Collections.Set with null record); Empty_Ordered_Set_Of_UML_Clear_Variable_Action : constant Ordered_Set_Of_UML_Clear_Variable_Action := (UML_Clear_Variable_Action_Collections.Ordered_Set with null record); Empty_Bag_Of_UML_Clear_Variable_Action : constant Bag_Of_UML_Clear_Variable_Action := (UML_Clear_Variable_Action_Collections.Bag with null record); Empty_Sequence_Of_UML_Clear_Variable_Action : constant Sequence_Of_UML_Clear_Variable_Action := (UML_Clear_Variable_Action_Collections.Sequence with null record); end AMF.UML.Clear_Variable_Actions.Collections;
ohenley/ada-util
Ada
4,384
adb
----------------------------------------------------------------------- -- serialize-io-csv-tests -- Unit tests for CSV parser -- Copyright (C) 2011, 2016 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- 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.Streams.Stream_IO; with Util.Test_Caller; with Util.Streams.Files; with Util.Serialize.Mappers.Tests; with Util.Serialize.IO.JSON.Tests; package body Util.Serialize.IO.CSV.Tests is package Caller is new Util.Test_Caller (Test, "Serialize.IO.CSV"); procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is begin Caller.Add_Test (Suite, "Test Util.Serialize.IO.CSV.Parse (parse Ok)", Test_Parser'Access); Caller.Add_Test (Suite, "Test Util.Serialize.IO.CSV.Write", Test_Output'Access); end Add_Tests; -- ------------------------------ -- Check various (basic) JSON valid strings (no mapper). -- ------------------------------ procedure Test_Parser (T : in out Test) is use Util.Serialize.Mappers.Tests; procedure Check_Parse (Content : in String; Expect : in Integer); Mapping : aliased Util.Serialize.Mappers.Tests.Map_Test_Mapper.Mapper; Vector_Mapper : aliased Util.Serialize.Mappers.Tests.Map_Test_Vector_Mapper.Mapper; procedure Check_Parse (Content : in String; Expect : in Integer) is P : Parser; Value : aliased Map_Test_Vector.Vector; Mapper : Util.Serialize.Mappers.Processing; begin Mapper.Add_Mapping ("", Vector_Mapper'Unchecked_Access); Map_Test_Vector_Mapper.Set_Context (Mapper, Value'Unchecked_Access); P.Parse_String (Content, Mapper); T.Assert (not P.Has_Error, "Parse error for: " & Content); Util.Tests.Assert_Equals (T, 1, Integer (Value.Length), "Invalid result length"); Util.Tests.Assert_Equals (T, Expect, Integer (Value.Element (1).Value), "Invalid value"); end Check_Parse; HDR : constant String := "name,status,value,bool" & ASCII.CR & ASCII.LF; begin Mapping.Add_Mapping ("name", FIELD_NAME); Mapping.Add_Mapping ("value", FIELD_VALUE); Mapping.Add_Mapping ("status", FIELD_BOOL); Mapping.Add_Mapping ("bool", FIELD_BOOL); Vector_Mapper.Set_Mapping (Mapping'Unchecked_Access); Check_Parse (HDR & "joe,false,23,true", 23); Check_Parse (HDR & "billy,false,""12"",true", 12); Check_Parse (HDR & """John Potter"",false,""1234"",true", 1234); Check_Parse (HDR & """John" & ASCII.CR & "Potter"",False,""3234"",True", 3234); Check_Parse (HDR & """John" & ASCII.LF & "Potter"",False,""3234"",True", 3234); end Test_Parser; -- ------------------------------ -- Test the CSV output stream generation. -- ------------------------------ procedure Test_Output (T : in out Test) is File : aliased Util.Streams.Files.File_Stream; Stream : Util.Serialize.IO.CSV.Output_Stream; Expect : constant String := Util.Tests.Get_Path ("regtests/expect/test-stream.csv"); Path : constant String := Util.Tests.Get_Test_Path ("regtests/result/test-stream.csv"); begin File.Create (Mode => Ada.Streams.Stream_IO.Out_File, Name => Path); Stream.Initialize (Output => File'Unchecked_Access, Size => 10000); Util.Serialize.IO.JSON.Tests.Write_Stream (Stream); Stream.Close; Util.Tests.Assert_Equal_Files (T => T, Expect => Expect, Test => Path, Message => "CSV output serialization"); end Test_Output; end Util.Serialize.IO.CSV.Tests;
francesco-bongiovanni/ewok-kernel
Ada
1,137
ads
-- -- Copyright 2018 The wookey project team <[email protected]> -- - Ryad Benadjila -- - Arnauld Michelizza -- - Mathieu Renard -- - Philippe Thierry -- - Philippe Trebuchet -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- with ewok.tasks_shared; with ewok.interrupts; with soc.interrupts; package ewok.isr with spark_mode => off is procedure postpone_isr (intr : in soc.interrupts.t_interrupt; handler : in ewok.interrupts.t_interrupt_handler_access; task_id : in ewok.tasks_shared.t_task_id; frame_a : in t_stack_frame_access); end ewok.isr;
AdaCore/Ada_Drivers_Library
Ada
29,550
ads
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2015-2016, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- MPU9250 I2C device class package with Interfaces; use Interfaces; with HAL; use HAL; with HAL.I2C; use HAL.I2C; with HAL.Time; package MPU9250 is type MPU9250_AD0_Pin_State is (High, Low); -- The MPU9250 has a pin that can be set to high or low level to change -- its I2C address. -- Types and subtypes type MPU9250_Device (Port : HAL.I2C.Any_I2C_Port; I2C_AD0_Pin : MPU9250_AD0_Pin_State; Time : not null HAL.Time.Any_Delays) is private; -- Type reprensnting all the different clock sources of the MPU9250. -- See the MPU9250 register map section 4.4 for more details. type MPU9250_Clock_Source is (Internal_Clk, X_Gyro_Clk, Y_Gyro_Clk, Z_Gyro_Clk, External_32K_Clk, External_19M_Clk, Reserved_Clk, Stop_Clk); for MPU9250_Clock_Source use (Internal_Clk => 16#00#, X_Gyro_Clk => 16#01#, Y_Gyro_Clk => 16#02#, Z_Gyro_Clk => 16#03#, External_32K_Clk => 16#04#, External_19M_Clk => 16#05#, Reserved_Clk => 16#06#, Stop_Clk => 16#07#); for MPU9250_Clock_Source'Size use 3; -- Type representing the allowed full scale ranges -- for MPU9250 gyroscope. type MPU9250_FS_Gyro_Range is (MPU9250_Gyro_FS_250, MPU9250_Gyro_FS_500, MPU9250_Gyro_FS_1000, MPU9250_Gyro_FS_2000); for MPU9250_FS_Gyro_Range use (MPU9250_Gyro_FS_250 => 16#00#, MPU9250_Gyro_FS_500 => 16#01#, MPU9250_Gyro_FS_1000 => 16#02#, MPU9250_Gyro_FS_2000 => 16#03#); for MPU9250_FS_Gyro_Range'Size use 2; -- Type representing the allowed full scale ranges -- for MPU9250 accelerometer. type MPU9250_FS_Accel_Range is (MPU9250_Accel_FS_2, MPU9250_Accel_FS_4, MPU9250_Accel_FS_8, MPU9250_Accel_FS_16); for MPU9250_FS_Accel_Range use (MPU9250_Accel_FS_2 => 16#00#, MPU9250_Accel_FS_4 => 16#01#, MPU9250_Accel_FS_8 => 16#02#, MPU9250_Accel_FS_16 => 16#03#); for MPU9250_FS_Accel_Range'Size use 2; type MPU9250_DLPF_Bandwidth_Mode is (MPU9250_DLPF_BW_256, MPU9250_DLPF_BW_188, MPU9250_DLPF_BW_98, MPU9250_DLPF_BW_42, MPU9250_DLPF_BW_20, MPU9250_DLPF_BW_10, MPU9250_DLPF_BW_5); for MPU9250_DLPF_Bandwidth_Mode use (MPU9250_DLPF_BW_256 => 16#00#, MPU9250_DLPF_BW_188 => 16#01#, MPU9250_DLPF_BW_98 => 16#02#, MPU9250_DLPF_BW_42 => 16#03#, MPU9250_DLPF_BW_20 => 16#04#, MPU9250_DLPF_BW_10 => 16#05#, MPU9250_DLPF_BW_5 => 16#06#); for MPU9250_DLPF_Bandwidth_Mode'Size use 3; -- Use to convert MPU9250 registers in degrees (gyro) and G (acc). MPU9250_DEG_PER_LSB_250 : constant := (2.0 * 250.0) / 65536.0; MPU9250_DEG_PER_LSB_500 : constant := (2.0 * 500.0) / 65536.0; MPU9250_DEG_PER_LSB_1000 : constant := (2.0 * 1000.0) / 65536.0; MPU9250_DEG_PER_LSB_2000 : constant := (2.0 * 2000.0) / 65536.0; MPU9250_G_PER_LSB_2 : constant := (2.0 * 2.0) / 65536.0; MPU9250_G_PER_LSB_4 : constant := (2.0 * 4.0) / 65536.0; MPU9250_G_PER_LSB_8 : constant := (2.0 * 8.0) / 65536.0; MPU9250_G_PER_LSB_16 : constant := (2.0 * 16.0) / 65536.0; -- Procedures and functions -- Initialize the MPU9250 Device via I2C. procedure MPU9250_Init (Device : in out MPU9250_Device); -- Test if the MPU9250 is initialized and connected. function MPU9250_Test (Device : MPU9250_Device) return Boolean; -- Test if we are connected to MPU9250 via I2C. function MPU9250_Test_Connection (Device : MPU9250_Device) return Boolean; type Test_Reporter is access procedure (Msg : String; Has_Succeeded : out Boolean); -- MPU9250 self test. function MPU9250_Self_Test (Device : in out MPU9250_Device; Do_Report : Boolean; Reporter : Test_Reporter) return Boolean; -- Reset the MPU9250 device. -- A small delay of ~50ms may be desirable after triggering a reset. procedure MPU9250_Reset (Device : in out MPU9250_Device); -- Get raw 6-axis motion sensor readings (accel/gyro). -- Retrieves all currently available motion sensor values. procedure MPU9250_Get_Motion_6 (Device : MPU9250_Device; Acc_X : out Integer_16; Acc_Y : out Integer_16; Acc_Z : out Integer_16; Gyro_X : out Integer_16; Gyro_Y : out Integer_16; Gyro_Z : out Integer_16); -- Set clock source setting. -- 3 bits allowed to choose the source. The different -- clock sources are enumerated in the MPU9250 register map. procedure MPU9250_Set_Clock_Source (Device : in out MPU9250_Device; Clock_Source : MPU9250_Clock_Source); -- Set digital low-pass filter configuration. procedure MPU9250_Set_DLPF_Mode (Device : in out MPU9250_Device; DLPF_Mode : MPU9250_DLPF_Bandwidth_Mode); -- Set full-scale gyroscope range. procedure MPU9250_Set_Full_Scale_Gyro_Range (Device : in out MPU9250_Device; FS_Range : MPU9250_FS_Gyro_Range); -- Set full-scale acceler range. procedure MPU9250_Set_Full_Scale_Accel_Range (Device : in out MPU9250_Device; FS_Range : MPU9250_FS_Accel_Range); -- Set I2C bypass enabled status. -- When this bit is equal to 1 and I2C_MST_EN (Register 106 bit[5]) is -- equal to 0, the host application processor -- will be able to directly access the -- auxiliary I2C bus of the MPU-60X0. When this bit is equal to 0, -- the host application processor will not be able to directly -- access the auxiliary I2C bus of the MPU-60X0 regardless of the state -- of I2C_MST_EN (Register 106 bit[5]). procedure MPU9250_Set_I2C_Bypass_Enabled (Device : in out MPU9250_Device; Value : Boolean); -- Set interrupts enabled status. procedure MPU9250_Set_Int_Enabled (Device : in out MPU9250_Device; Value : Boolean); -- Set gyroscope sample rate divider procedure MPU9250_Set_Rate (Device : in out MPU9250_Device; Rate_Div : UInt8); -- Set sleep mode status. procedure MPU9250_Set_Sleep_Enabled (Device : in out MPU9250_Device; Value : Boolean); -- Set temperature sensor enabled status. procedure MPU9250_Set_Temp_Sensor_Enabled (Device : in out MPU9250_Device; Value : Boolean); -- Get temperature sensor enabled status. function MPU9250_Get_Temp_Sensor_Enabled (Device : MPU9250_Device) return Boolean; private type MPU9250_Device (Port : HAL.I2C.Any_I2C_Port; I2C_AD0_Pin : MPU9250_AD0_Pin_State; Time : not null HAL.Time.Any_Delays) is record Is_Init : Boolean := False; Address : UInt10; end record; subtype T_Bit_Pos_8 is Natural range 0 .. 7; subtype T_Bit_Pos_16 is Natural range 0 .. 15; -- Global variables and constants -- MPU9250 Device ID. Use to test if we are connected via I2C MPU9250_DEVICE_ID : constant := 16#71#; -- Address pin low (GND), default for InvenSense evaluation board MPU9250_ADDRESS_AD0_LOW : constant := 16#68#; -- Address pin high (VCC) MPU9250_ADDRESS_AD0_HIGH : constant := 16#69#; MPU9250_STARTUP_TIME_MS : constant := 1_000; -- MPU9250 register adresses and other defines MPU9250_REV_C4_ES : constant := 16#14#; MPU9250_REV_C5_ES : constant := 16#15#; MPU9250_REV_D6_ES : constant := 16#16#; MPU9250_REV_D7_ES : constant := 16#17#; MPU9250_REV_D8_ES : constant := 16#18#; MPU9250_REV_C4 : constant := 16#54#; MPU9250_REV_C5 : constant := 16#55#; MPU9250_REV_D6 : constant := 16#56#; MPU9250_REV_D7 : constant := 16#57#; MPU9250_REV_D8 : constant := 16#58#; MPU9250_REV_D9 : constant := 16#59#; MPU9250_RA_ST_X_GYRO : constant := 16#00#; MPU9250_RA_ST_Y_GYRO : constant := 16#01#; MPU9250_RA_ST_Z_GYRO : constant := 16#02#; MPU9250_RA_ST_X_ACCEL : constant := 16#0D#; MPU9250_RA_ST_Y_ACCEL : constant := 16#0E#; MPU9250_RA_ST_Z_ACCEL : constant := 16#0F#; MPU9250_RA_XG_OFFS_USRH : constant := 16#13#; MPU9250_RA_XG_OFFS_USRL : constant := 16#14#; MPU9250_RA_YG_OFFS_USRH : constant := 16#15#; MPU9250_RA_YG_OFFS_USRL : constant := 16#16#; MPU9250_RA_ZG_OFFS_USRH : constant := 16#17#; MPU9250_RA_ZG_OFFS_USRL : constant := 16#18#; MPU9250_RA_SMPLRT_DIV : constant := 16#19#; MPU9250_RA_CONFIG : constant := 16#1A#; MPU9250_RA_GYRO_CONFIG : constant := 16#1B#; MPU9250_RA_ACCEL_CONFIG : constant := 16#1C#; MPU9250_RA_ACCEL_CONFIG_2 : constant := 16#1D#; MPU9250_RA_LP_ACCEL_ODR : constant := 16#1E#; MPU9250_RA_WOM_THR : constant := 16#1F#; MPU9250_RA_FIFO_EN : constant := 16#23#; MPU9250_RA_I2C_MST_CTRL : constant := 16#24#; MPU9250_RA_I2C_SLV0_ADDR : constant := 16#25#; MPU9250_RA_I2C_SLV0_REG : constant := 16#26#; MPU9250_RA_I2C_SLV0_CTRL : constant := 16#27#; MPU9250_RA_I2C_SLV1_ADDR : constant := 16#28#; MPU9250_RA_I2C_SLV1_REG : constant := 16#29#; MPU9250_RA_I2C_SLV1_CTRL : constant := 16#2A#; MPU9250_RA_I2C_SLV2_ADDR : constant := 16#2B#; MPU9250_RA_I2C_SLV2_REG : constant := 16#2C#; MPU9250_RA_I2C_SLV2_CTRL : constant := 16#2D#; MPU9250_RA_I2C_SLV3_ADDR : constant := 16#2E#; MPU9250_RA_I2C_SLV3_REG : constant := 16#2F#; MPU9250_RA_I2C_SLV3_CTRL : constant := 16#30#; MPU9250_RA_I2C_SLV4_ADDR : constant := 16#31#; MPU9250_RA_I2C_SLV4_REG : constant := 16#32#; MPU9250_RA_I2C_SLV4_DO : constant := 16#33#; MPU9250_RA_I2C_SLV4_CTRL : constant := 16#34#; MPU9250_RA_I2C_SLV4_DI : constant := 16#35#; MPU9250_RA_I2C_MST_STATUS : constant := 16#36#; MPU9250_RA_INT_PIN_CFG : constant := 16#37#; MPU9250_RA_INT_ENABLE : constant := 16#38#; MPU9250_RA_DMP_INT_STATUS : constant := 16#39#; MPU9250_RA_INT_STATUS : constant := 16#3A#; MPU9250_RA_ACCEL_XOUT_H : constant := 16#3B#; MPU9250_RA_ACCEL_XOUT_L : constant := 16#3C#; MPU9250_RA_ACCEL_YOUT_H : constant := 16#3D#; MPU9250_RA_ACCEL_YOUT_L : constant := 16#3E#; MPU9250_RA_ACCEL_ZOUT_H : constant := 16#3F#; MPU9250_RA_ACCEL_ZOUT_L : constant := 16#40#; MPU9250_RA_TEMP_OUT_H : constant := 16#41#; MPU9250_RA_TEMP_OUT_L : constant := 16#42#; MPU9250_RA_GYRO_XOUT_H : constant := 16#43#; MPU9250_RA_GYRO_XOUT_L : constant := 16#44#; MPU9250_RA_GYRO_YOUT_H : constant := 16#45#; MPU9250_RA_GYRO_YOUT_L : constant := 16#46#; MPU9250_RA_GYRO_ZOUT_H : constant := 16#47#; MPU9250_RA_GYRO_ZOUT_L : constant := 16#48#; MPU9250_RA_EXT_SENS_DATA_00 : constant := 16#49#; MPU9250_RA_EXT_SENS_DATA_01 : constant := 16#4A#; MPU9250_RA_EXT_SENS_DATA_02 : constant := 16#4B#; MPU9250_RA_EXT_SENS_DATA_03 : constant := 16#4C#; MPU9250_RA_EXT_SENS_DATA_04 : constant := 16#4D#; MPU9250_RA_EXT_SENS_DATA_05 : constant := 16#4E#; MPU9250_RA_EXT_SENS_DATA_06 : constant := 16#4F#; MPU9250_RA_EXT_SENS_DATA_07 : constant := 16#50#; MPU9250_RA_EXT_SENS_DATA_08 : constant := 16#51#; MPU9250_RA_EXT_SENS_DATA_09 : constant := 16#52#; MPU9250_RA_EXT_SENS_DATA_10 : constant := 16#53#; MPU9250_RA_EXT_SENS_DATA_11 : constant := 16#54#; MPU9250_RA_EXT_SENS_DATA_12 : constant := 16#55#; MPU9250_RA_EXT_SENS_DATA_13 : constant := 16#56#; MPU9250_RA_EXT_SENS_DATA_14 : constant := 16#57#; MPU9250_RA_EXT_SENS_DATA_15 : constant := 16#58#; MPU9250_RA_EXT_SENS_DATA_16 : constant := 16#59#; MPU9250_RA_EXT_SENS_DATA_17 : constant := 16#5A#; MPU9250_RA_EXT_SENS_DATA_18 : constant := 16#5B#; MPU9250_RA_EXT_SENS_DATA_19 : constant := 16#5C#; MPU9250_RA_EXT_SENS_DATA_20 : constant := 16#5D#; MPU9250_RA_EXT_SENS_DATA_21 : constant := 16#5E#; MPU9250_RA_EXT_SENS_DATA_22 : constant := 16#5F#; MPU9250_RA_EXT_SENS_DATA_23 : constant := 16#60#; MPU9250_RA_MOT_DETECT_STATUS : constant := 16#61#; MPU9250_RA_I2C_SLV0_DO : constant := 16#63#; MPU9250_RA_I2C_SLV1_DO : constant := 16#64#; MPU9250_RA_I2C_SLV2_DO : constant := 16#65#; MPU9250_RA_I2C_SLV3_DO : constant := 16#66#; MPU9250_RA_I2C_MST_DELAY_CTRL : constant := 16#67#; MPU9250_RA_SIGNAL_PATH_RESET : constant := 16#68#; MPU9250_RA_MOT_DETECT_CTRL : constant := 16#69#; MPU9250_RA_USER_CTRL : constant := 16#6A#; MPU9250_RA_PWR_MGMT_1 : constant := 16#6B#; MPU9250_RA_PWR_MGMT_2 : constant := 16#6C#; MPU9250_RA_BANK_SEL : constant := 16#6D#; MPU9250_RA_MEM_START_ADDR : constant := 16#6E#; MPU9250_RA_MEM_R_W : constant := 16#6F#; MPU9250_RA_DMP_CFG_1 : constant := 16#70#; MPU9250_RA_DMP_CFG_2 : constant := 16#71#; MPU9250_RA_FIFO_COUNTH : constant := 16#72#; MPU9250_RA_FIFO_COUNTL : constant := 16#73#; MPU9250_RA_FIFO_R_W : constant := 16#74#; MPU9250_RA_WHO_AM_I : constant := 16#75#; MPU9250_RA_XA_OFFSET_H : constant := 16#77#; MPU9250_RA_XA_OFFSET_L : constant := 16#78#; MPU9250_RA_YA_OFFSET_H : constant := 16#7A#; MPU9250_RA_YA_OFFSET_L : constant := 16#7B#; MPU9250_RA_ZA_OFFSET_H : constant := 16#7D#; MPU9250_RA_ZA_OFFSET_L : constant := 16#7E#; MPU9250_TC_PWR_MODE_BIT : constant := 7; MPU9250_TC_OFFSET_BIT : constant := 6; MPU9250_TC_OFFSET_LENGTH : constant := 6; MPU9250_TC_OTP_BNK_VLD_BIT : constant := 0; MPU9250_VDDIO_LEVEL_VLOGIC : constant := 0; MPU9250_VDDIO_LEVEL_VDD : constant := 1; MPU9250_CFG_EXT_SYNC_SET_BIT : constant := 5; MPU9250_CFG_EXT_SYNC_SET_LENGTH : constant := 3; MPU9250_CFG_DLPF_CFG_BIT : constant := 2; MPU9250_CFG_DLPF_CFG_LENGTH : constant := 3; MPU9250_EXT_SYNC_DISABLED : constant := 16#0#; MPU9250_EXT_SYNC_TEMP_OUT_L : constant := 16#1#; MPU9250_EXT_SYNC_GYRO_XOUT_L : constant := 16#2#; MPU9250_EXT_SYNC_GYRO_YOUT_L : constant := 16#3#; MPU9250_EXT_SYNC_GYRO_ZOUT_L : constant := 16#4#; MPU9250_EXT_SYNC_ACCEL_XOUT_L : constant := 16#5#; MPU9250_EXT_SYNC_ACCEL_YOUT_L : constant := 16#6#; MPU9250_EXT_SYNC_ACCEL_ZOUT_L : constant := 16#7#; MPU9250_GCONFIG_XG_ST_BIT : constant := 7; MPU9250_GCONFIG_YG_ST_BIT : constant := 6; MPU9250_GCONFIG_ZG_ST_BIT : constant := 5; MPU9250_GCONFIG_FS_SEL_BIT : constant := 4; MPU9250_GCONFIG_FS_SEL_LENGTH : constant := 2; MPU9250_ACONFIG_XA_ST_BIT : constant := 7; MPU9250_ACONFIG_YA_ST_BIT : constant := 6; MPU9250_ACONFIG_ZA_ST_BIT : constant := 5; MPU9250_ACONFIG_AFS_SEL_BIT : constant := 4; MPU9250_ACONFIG_AFS_SEL_LENGTH : constant := 2; MPU9250_ACONFIG_ACCEL_HPF_BIT : constant := 2; MPU9250_ACONFIG_ACCEL_HPF_LENGTH : constant := 3; MPU9250_DHPF_RESET : constant := 16#00#; MPU9250_DHPF_5 : constant := 16#01#; MPU9250_DHPF_2P5 : constant := 16#02#; MPU9250_DHPF_1P25 : constant := 16#03#; MPU9250_DHPF_0P63 : constant := 16#04#; MPU9250_DHPF_HOLD : constant := 16#07#; MPU9250_TEMP_FIFO_EN_BIT : constant := 7; MPU9250_XG_FIFO_EN_BIT : constant := 6; MPU9250_YG_FIFO_EN_BIT : constant := 5; MPU9250_ZG_FIFO_EN_BIT : constant := 4; MPU9250_ACCEL_FIFO_EN_BIT : constant := 3; MPU9250_SLV2_FIFO_EN_BIT : constant := 2; MPU9250_SLV1_FIFO_EN_BIT : constant := 1; MPU9250_SLV0_FIFO_EN_BIT : constant := 0; MPU9250_MULT_MST_EN_BIT : constant := 7; MPU9250_WAIT_FOR_ES_BIT : constant := 6; MPU9250_SLV_3_FIFO_EN_BIT : constant := 5; MPU9250_I2C_MST_P_NSR_BIT : constant := 4; MPU9250_I2C_MST_CLK_BIT : constant := 3; MPU9250_I2C_MST_CLK_LENGTH : constant := 4; MPU9250_CLOCK_DIV_348 : constant := 16#0#; MPU9250_CLOCK_DIV_333 : constant := 16#1#; MPU9250_CLOCK_DIV_320 : constant := 16#2#; MPU9250_CLOCK_DIV_308 : constant := 16#3#; MPU9250_CLOCK_DIV_296 : constant := 16#4#; MPU9250_CLOCK_DIV_286 : constant := 16#5#; MPU9250_CLOCK_DIV_276 : constant := 16#6#; MPU9250_CLOCK_DIV_267 : constant := 16#7#; MPU9250_CLOCK_DIV_258 : constant := 16#8#; MPU9250_CLOCK_DIV_500 : constant := 16#9#; MPU9250_CLOCK_DIV_471 : constant := 16#A#; MPU9250_CLOCK_DIV_444 : constant := 16#B#; MPU9250_CLOCK_DIV_421 : constant := 16#C#; MPU9250_CLOCK_DIV_400 : constant := 16#D#; MPU9250_CLOCK_DIV_381 : constant := 16#E#; MPU9250_CLOCK_DIV_364 : constant := 16#F#; MPU9250_I2C_SLV_RW_BIT : constant := 7; MPU9250_I2C_SLV_ADDR_BIT : constant := 6; MPU9250_I2C_SLV_ADDR_LENGTH : constant := 7; MPU9250_I2C_SLV_EN_BIT : constant := 7; MPU9250_I2C_SLV_UInt8_SW_BIT : constant := 6; MPU9250_I2C_SLV_REG_DIS_BIT : constant := 5; MPU9250_I2C_SLV_GRP_BIT : constant := 4; MPU9250_I2C_SLV_LEN_BIT : constant := 3; MPU9250_I2C_SLV_LEN_LENGTH : constant := 4; MPU9250_I2C_SLV4_RW_BIT : constant := 7; MPU9250_I2C_SLV4_ADDR_BIT : constant := 6; MPU9250_I2C_SLV4_ADDR_LENGTH : constant := 7; MPU9250_I2C_SLV4_EN_BIT : constant := 7; MPU9250_I2C_SLV4_INT_EN_BIT : constant := 6; MPU9250_I2C_SLV4_REG_DIS_BIT : constant := 5; MPU9250_I2C_SLV4_MST_DLY_BIT : constant := 4; MPU9250_I2C_SLV4_MST_DLY_LENGTH : constant := 5; MPU9250_MST_PASS_THROUGH_BIT : constant := 7; MPU9250_MST_I2C_SLV4_DONE_BIT : constant := 6; MPU9250_MST_I2C_LOST_ARB_BIT : constant := 5; MPU9250_MST_I2C_SLV4_NACK_BIT : constant := 4; MPU9250_MST_I2C_SLV3_NACK_BIT : constant := 3; MPU9250_MST_I2C_SLV2_NACK_BIT : constant := 2; MPU9250_MST_I2C_SLV1_NACK_BIT : constant := 1; MPU9250_MST_I2C_SLV0_NACK_BIT : constant := 0; MPU9250_INTCFG_INT_LEVEL_BIT : constant := 7; MPU9250_INTCFG_INT_OPEN_BIT : constant := 6; MPU9250_INTCFG_LATCH_INT_EN_BIT : constant := 5; MPU9250_INTCFG_INT_RD_CLEAR_BIT : constant := 4; MPU9250_INTCFG_FSYNC_INT_LEVEL_BIT : constant := 3; MPU9250_INTCFG_FSYNC_INT_EN_BIT : constant := 2; MPU9250_INTCFG_I2C_BYPASS_EN_BIT : constant := 1; MPU9250_INTCFG_CLKOUT_EN_BIT : constant := 0; MPU9250_INTMODE_ACTIVEHIGH : constant := 16#00#; MPU9250_INTMODE_ACTIVELOW : constant := 16#01#; MPU9250_INTDRV_PUSHPULL : constant := 16#00#; MPU9250_INTDRV_OPENDRAIN : constant := 16#01#; MPU9250_INTLATCH_50USPULSE : constant := 16#00#; MPU9250_INTLATCH_WAITCLEAR : constant := 16#01#; MPU9250_INTCLEAR_STATUSREAD : constant := 16#00#; MPU9250_INTCLEAR_ANYREAD : constant := 16#01#; MPU9250_INTERRUPT_FF_BIT : constant := 7; MPU9250_INTERRUPT_MOT_BIT : constant := 6; MPU9250_INTERRUPT_ZMOT_BIT : constant := 5; MPU9250_INTERRUPT_FIFO_OFLOW_BIT : constant := 4; MPU9250_INTERRUPT_I2C_MST_INT_BIT : constant := 3; MPU9250_INTERRUPT_PLL_RDY_INT_BIT : constant := 2; MPU9250_INTERRUPT_DMP_INT_BIT : constant := 1; MPU9250_INTERRUPT_DATA_RDY_BIT : constant := 0; MPU9250_DMPINT_5_BIT : constant := 5; MPU9250_DMPINT_4_BIT : constant := 4; MPU9250_DMPINT_3_BIT : constant := 3; MPU9250_DMPINT_2_BIT : constant := 2; MPU9250_DMPINT_1_BIT : constant := 1; MPU9250_DMPINT_0_BIT : constant := 0; MPU9250_MOTION_MOT_XNEG_BIT : constant := 7; MPU9250_MOTION_MOT_XPOS_BIT : constant := 6; MPU9250_MOTION_MOT_YNEG_BIT : constant := 5; MPU9250_MOTION_MOT_YPOS_BIT : constant := 4; MPU9250_MOTION_MOT_ZNEG_BIT : constant := 3; MPU9250_MOTION_MOT_ZPOS_BIT : constant := 2; MPU9250_MOTION_MOT_ZRMOT_BIT : constant := 0; MPU9250_DELAYCTRL_DELAY_ES_SHADOW_BIT : constant := 7; MPU9250_DELAYCTRL_I2C_SLV4_DLY_EN_BIT : constant := 4; MPU9250_DELAYCTRL_I2C_SLV3_DLY_EN_BIT : constant := 3; MPU9250_DELAYCTRL_I2C_SLV2_DLY_EN_BIT : constant := 2; MPU9250_DELAYCTRL_I2C_SLV1_DLY_EN_BIT : constant := 1; MPU9250_DELAYCTRL_I2C_SLV0_DLY_EN_BIT : constant := 0; MPU9250_PATHRESET_GYRO_RESET_BIT : constant := 2; MPU9250_PATHRESET_ACCEL_RESET_BIT : constant := 1; MPU9250_PATHRESET_TEMP_RESET_BIT : constant := 0; MPU9250_DETECT_ACCEL_ON_DELAY_BIT : constant := 5; MPU9250_DETECT_ACCEL_ON_DELAY_LENGTH : constant := 2; MPU9250_DETECT_FF_COUNT_BIT : constant := 3; MPU9250_DETECT_FF_COUNT_LENGTH : constant := 2; MPU9250_DETECT_MOT_COUNT_BIT : constant := 1; MPU9250_DETECT_MOT_COUNT_LENGTH : constant := 2; MPU9250_DETECT_DECREMENT_RESET : constant := 16#0#; MPU9250_DETECT_DECREMENT_1 : constant := 16#1#; MPU9250_DETECT_DECREMENT_2 : constant := 16#2#; MPU9250_DETECT_DECREMENT_4 : constant := 16#3#; MPU9250_USERCTRL_DMP_EN_BIT : constant := 7; MPU9250_USERCTRL_FIFO_EN_BIT : constant := 6; MPU9250_USERCTRL_I2C_MST_EN_BIT : constant := 5; MPU9250_USERCTRL_I2C_IF_DIS_BIT : constant := 4; MPU9250_USERCTRL_DMP_RESET_BIT : constant := 3; MPU9250_USERCTRL_FIFO_RESET_BIT : constant := 2; MPU9250_USERCTRL_I2C_MST_RESET_BIT : constant := 1; MPU9250_USERCTRL_SIG_COND_RESET_BIT : constant := 0; MPU9250_PWR1_DEVICE_RESET_BIT : constant := 7; MPU9250_PWR1_SLEEP_BIT : constant := 6; MPU9250_PWR1_CYCLE_BIT : constant := 5; MPU9250_PWR1_TEMP_DIS_BIT : constant := 3; MPU9250_PWR1_CLKSEL_BIT : constant := 2; MPU9250_PWR1_CLKSEL_LENGTH : constant := 3; MPU9250_CLOCK_INTERNAL : constant := 16#00#; MPU9250_CLOCK_PLL_XGYRO : constant := 16#01#; MPU9250_CLOCK_PLL_YGYRO : constant := 16#02#; MPU9250_CLOCK_PLL_ZGYRO : constant := 16#03#; MPU9250_CLOCK_PLL_EXT32K : constant := 16#04#; MPU9250_CLOCK_PLL_EXT19M : constant := 16#05#; MPU9250_CLOCK_KEEP_RESET : constant := 16#07#; MPU9250_PWR2_LP_WAKE_CTRL_BIT : constant := 7; MPU9250_PWR2_LP_WAKE_CTRL_LENGTH : constant := 2; MPU9250_PWR2_STBY_XA_BIT : constant := 5; MPU9250_PWR2_STBY_YA_BIT : constant := 4; MPU9250_PWR2_STBY_ZA_BIT : constant := 3; MPU9250_PWR2_STBY_XG_BIT : constant := 2; MPU9250_PWR2_STBY_YG_BIT : constant := 1; MPU9250_PWR2_STBY_ZG_BIT : constant := 0; MPU9250_WAKE_FREQ_1P25 : constant := 16#0#; MPU9250_WAKE_FREQ_2P5 : constant := 16#1#; MPU9250_WAKE_FREQ_5 : constant := 16#2#; MPU9250_WAKE_FREQ_10 : constant := 16#3#; MPU9250_BANKSEL_PRFTCH_EN_BIT : constant := 6; MPU9250_BANKSEL_CFG_USER_BANK_BIT : constant := 5; MPU9250_BANKSEL_MEM_SEL_BIT : constant := 4; MPU9250_BANKSEL_MEM_SEL_LENGTH : constant := 5; MPU9250_WHO_AM_I_BIT : constant := 6; MPU9250_WHO_AM_I_LENGTH : constant := 6; MPU9250_DMP_MEMORY_BANKS : constant := 8; MPU9250_DMP_MEMORY_BANK_SIZE : constant := 256; MPU9250_DMP_MEMORY_CHUNK_SIZE : constant := 16; MPU9250_ST_GYRO_LOW : constant := (-14.0); MPU9250_ST_GYRO_HIGH : constant := 14.0; MPU9250_ST_ACCEL_LOW : constant := (-14.0); MPU9250_ST_ACCEL_HIGH : constant := 14.0; -- Element n is 2620 * (1.01 ** n) MPU9250_ST_TB : constant array (0 .. 255) of UInt16 := ( 2620, 2646, 2672, 2699, 2726, 2753, 2781, 2808, 2837, 2865, 2894, 2923, 2952, 2981, 3011, 3041, 3072, 3102, 3133, 3165, 3196, 3228, 3261, 3293, 3326, 3359, 3393, 3427, 3461, 3496, 3531, 3566, 3602, 3638, 3674, 3711, 3748, 3786, 3823, 3862, 3900, 3939, 3979, 4019, 4059, 4099, 4140, 4182, 4224, 4266, 4308, 4352, 4395, 4439, 4483, 4528, 4574, 4619, 4665, 4712, 4759, 4807, 4855, 4903, 4953, 5002, 5052, 5103, 5154, 5205, 5257, 5310, 5363, 5417, 5471, 5525, 5581, 5636, 5693, 5750, 5807, 5865, 5924, 5983, 6043, 6104, 6165, 6226, 6289, 6351, 6415, 6479, 6544, 6609, 6675, 6742, 6810, 6878, 6946, 7016, 7086, 7157, 7229, 7301, 7374, 7448, 7522, 7597, 7673, 7750, 7828, 7906, 7985, 8065, 8145, 8227, 8309, 8392, 8476, 8561, 8647, 8733, 8820, 8909, 8998, 9088, 9178, 9270, 9363, 9457, 9551, 9647, 9743, 9841, 9939, 10038, 10139, 10240, 10343, 10446, 10550, 10656, 10763, 10870, 10979, 11089, 11200, 11312, 11425, 11539, 11654, 11771, 11889, 12008, 12128, 12249, 12371, 12495, 12620, 12746, 12874, 13002, 13132, 13264, 13396, 13530, 13666, 13802, 13940, 14080, 14221, 14363, 14506, 14652, 14798, 14946, 15096, 15247, 15399, 15553, 15709, 15866, 16024, 16184, 16346, 16510, 16675, 16842, 17010, 17180, 17352, 17526, 17701, 17878, 18057, 18237, 18420, 18604, 18790, 18978, 19167, 19359, 19553, 19748, 19946, 20145, 20347, 20550, 20756, 20963, 21173, 21385, 21598, 21814, 22033, 22253, 22475, 22700, 22927, 23156, 23388, 23622, 23858, 24097, 24338, 24581, 24827, 25075, 25326, 25579, 25835, 26093, 26354, 26618, 26884, 27153, 27424, 27699, 27976, 28255, 28538, 28823, 29112, 29403, 29697, 29994, 30294, 30597, 30903, 31212, 31524, 31839, 32157, 32479, 32804, 33132 ); -- Procedures and functions -- Read data to the specified MPU9250 register procedure MPU9250_Read_Register (Device : MPU9250_Device; Reg_Addr : UInt8; Data : in out I2C_Data); -- Read one UInt8 at the specified MPU9250 register procedure MPU9250_Read_UInt8_At_Register (Device : MPU9250_Device; Reg_Addr : UInt8; Data : out UInt8); -- Read one but at the specified MPU9250 register function MPU9250_Read_Bit_At_Register (Device : MPU9250_Device; Reg_Addr : UInt8; Bit_Pos : T_Bit_Pos_8) return Boolean; -- Write data to the specified MPU9250 register procedure MPU9250_Write_Register (Device : MPU9250_Device; Reg_Addr : UInt8; Data : I2C_Data); -- Write one UInt8 at the specified MPU9250 register procedure MPU9250_Write_UInt8_At_Register (Device : MPU9250_Device; Reg_Addr : UInt8; Data : UInt8); -- Write one bit at the specified MPU9250 register procedure MPU9250_Write_Bit_At_Register (Device : MPU9250_Device; Reg_Addr : UInt8; Bit_Pos : T_Bit_Pos_8; Bit_Value : Boolean); -- Write data in the specified register, starting from the -- bit specified in Start_Bit_Pos procedure MPU9250_Write_Bits_At_Register (Device : MPU9250_Device; Reg_Addr : UInt8; Start_Bit_Pos : T_Bit_Pos_8; Data : UInt8; Length : T_Bit_Pos_8); function Fuse_Low_And_High_Register_Parts (High : UInt8; Low : UInt8) return Integer_16; pragma Inline (Fuse_Low_And_High_Register_Parts); end MPU9250;
reznikmm/matreshka
Ada
3,759
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Attributes; package ODF.DOM.Table_Show_Filter_Button_Attributes is pragma Preelaborate; type ODF_Table_Show_Filter_Button_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Table_Show_Filter_Button_Attribute_Access is access all ODF_Table_Show_Filter_Button_Attribute'Class with Storage_Size => 0; end ODF.DOM.Table_Show_Filter_Button_Attributes;
reznikmm/matreshka
Ada
3,985
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with ODF.DOM.Text_Duration_Attributes; package Matreshka.ODF_Text.Duration_Attributes is type Text_Duration_Attribute_Node is new Matreshka.ODF_Text.Abstract_Text_Attribute_Node and ODF.DOM.Text_Duration_Attributes.ODF_Text_Duration_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Text_Duration_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Text_Duration_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Text.Duration_Attributes;
zhmu/ananas
Ada
4,141
adb
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- SYSTEM.MACHINE_STATE_OPERATIONS -- -- -- -- B o d y -- -- (Dummy version) -- -- -- -- Copyright (C) 1999-2022, 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. -- -- -- ------------------------------------------------------------------------------ -- This dummy version of System.Machine_State_Operations is used on targets -- for which zero cost exception handling is not implemented. package body System.Machine_State_Operations is -- Turn off warnings since many unused parameters pragma Warnings (Off); ---------------------------- -- Allocate_Machine_State -- ---------------------------- function Allocate_Machine_State return Machine_State is begin return Machine_State (Null_Address); end Allocate_Machine_State; ---------------- -- Fetch_Code -- ---------------- function Fetch_Code (Loc : Code_Loc) return Code_Loc is begin return Loc; end Fetch_Code; ------------------------ -- Free_Machine_State -- ------------------------ procedure Free_Machine_State (M : in out Machine_State) is begin M := Machine_State (Null_Address); end Free_Machine_State; ------------------ -- Get_Code_Loc -- ------------------ function Get_Code_Loc (M : Machine_State) return Code_Loc is begin return Null_Address; end Get_Code_Loc; -------------------------- -- Machine_State_Length -- -------------------------- function Machine_State_Length return System.Storage_Elements.Storage_Offset is begin return 0; end Machine_State_Length; --------------- -- Pop_Frame -- --------------- procedure Pop_Frame (M : Machine_State) is begin null; end Pop_Frame; ----------------------- -- Set_Machine_State -- ----------------------- procedure Set_Machine_State (M : Machine_State) is begin null; end Set_Machine_State; end System.Machine_State_Operations;
reznikmm/matreshka
Ada
10,658
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with AMF.Internals.Tables.CMOF_Attributes; with AMF.String_Collections.Internals; with AMF.Visitors.CMOF_Iterators; with AMF.Visitors.CMOF_Visitors; package body AMF.Internals.CMOF_Opaque_Expressions is use AMF.Internals.Tables.CMOF_Attributes; ------------------- -- Enter_Element -- ------------------- overriding procedure Enter_Element (Self : not null access constant CMOF_Opaque_Expression_Proxy; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Control : in out AMF.Visitors.Traverse_Control) is begin if Visitor in AMF.Visitors.CMOF_Visitors.CMOF_Visitor'Class then AMF.Visitors.CMOF_Visitors.CMOF_Visitor'Class (Visitor).Enter_Opaque_Expression (AMF.CMOF.Opaque_Expressions.CMOF_Opaque_Expression_Access (Self), Control); end if; end Enter_Element; ------------------- -- Leave_Element -- ------------------- overriding procedure Leave_Element (Self : not null access constant CMOF_Opaque_Expression_Proxy; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Control : in out AMF.Visitors.Traverse_Control) is begin if Visitor in AMF.Visitors.CMOF_Visitors.CMOF_Visitor'Class then AMF.Visitors.CMOF_Visitors.CMOF_Visitor'Class (Visitor).Leave_Opaque_Expression (AMF.CMOF.Opaque_Expressions.CMOF_Opaque_Expression_Access (Self), Control); end if; end Leave_Element; ------------------- -- Visit_Element -- ------------------- overriding procedure Visit_Element (Self : not null access constant CMOF_Opaque_Expression_Proxy; Iterator : in out AMF.Visitors.Abstract_Iterator'Class; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Control : in out AMF.Visitors.Traverse_Control) is begin if Iterator in AMF.Visitors.CMOF_Iterators.CMOF_Iterator'Class then AMF.Visitors.CMOF_Iterators.CMOF_Iterator'Class (Iterator).Visit_Opaque_Expression (Visitor, AMF.CMOF.Opaque_Expressions.CMOF_Opaque_Expression_Access (Self), Control); end if; end Visit_Element; ------------------------ -- All_Owned_Elements -- ------------------------ overriding function All_Owned_Elements (Self : not null access constant CMOF_Opaque_Expression_Proxy) return AMF.CMOF.Elements.Collections.Set_Of_CMOF_Element is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "All_Owned_Elements unimplemented"); raise Program_Error; return All_Owned_Elements (Self); end All_Owned_Elements; ------------------------ -- Get_Qualified_Name -- ------------------------ overriding function Get_Qualified_Name (Self : not null access constant CMOF_Opaque_Expression_Proxy) return Optional_String is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Get_Qualified_Name unimplemented"); raise Program_Error; return Get_Qualified_Name (Self); end Get_Qualified_Name; ----------------------------- -- Is_Distinguishable_From -- ----------------------------- overriding function Is_Distinguishable_From (Self : not null access constant CMOF_Opaque_Expression_Proxy; N : AMF.CMOF.Named_Elements.CMOF_Named_Element_Access; Ns : AMF.CMOF.Namespaces.CMOF_Namespace_Access) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Is_Distinguishable_From unimplemented"); raise Program_Error; return Is_Distinguishable_From (Self, N, Ns); end Is_Distinguishable_From; ------------------- -- Is_Computable -- ------------------- overriding function Is_Computable (Self : not null access constant CMOF_Opaque_Expression_Proxy) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Is_Computable unimplemented"); raise Program_Error; return Is_Computable (Self); end Is_Computable; ------------------- -- Integer_Value -- ------------------- overriding function Integer_Value (Self : not null access constant CMOF_Opaque_Expression_Proxy) return Integer is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Integer_Value unimplemented"); raise Program_Error; return Integer_Value (Self); end Integer_Value; ------------------- -- Boolean_Value -- ------------------- overriding function Boolean_Value (Self : not null access constant CMOF_Opaque_Expression_Proxy) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Boolean_Value unimplemented"); raise Program_Error; return Boolean_Value (Self); end Boolean_Value; ------------------ -- String_Value -- ------------------ overriding function String_Value (Self : not null access constant CMOF_Opaque_Expression_Proxy) return League.Strings.Universal_String is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "String_Value unimplemented"); raise Program_Error; return String_Value (Self); end String_Value; --------------------- -- Unlimited_Value -- --------------------- overriding function Unlimited_Value (Self : not null access constant CMOF_Opaque_Expression_Proxy) return Unlimited_Natural is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Unlimited_Value unimplemented"); raise Program_Error; return Unlimited_Value (Self); end Unlimited_Value; ------------- -- Is_Null -- ------------- overriding function Is_Null (Self : not null access constant CMOF_Opaque_Expression_Proxy) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Is_Null unimplemented"); raise Program_Error; return Is_Null (Self); end Is_Null; -------------- -- Get_Body -- -------------- overriding function Get_Body (Self : not null access constant CMOF_Opaque_Expression_Proxy) return AMF.String_Collections.Sequence_Of_String is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Get_Body unimplemented"); return AMF.String_Collections.Internals.Wrap (Internal_Get_Body (Self.Element)); end Get_Body; ------------------ -- Get_Language -- ------------------ overriding function Get_Language (Self : not null access constant CMOF_Opaque_Expression_Proxy) return AMF.String_Collections.Ordered_Set_Of_String is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Get_Language unimplemented"); return AMF.String_Collections.Internals.Wrap (Internal_Get_Language (Self.Element)); end Get_Language; end AMF.Internals.CMOF_Opaque_Expressions;
sungyeon/drake
Ada
36
adb
../machine-apple-darwin/s-naenva.adb
BrickBot/Bound-T-H8-300
Ada
131,950
adb
-- Bounds (body) -- -- A component of the Bound-T Worst-Case Execution Time Tool. -- ------------------------------------------------------------------------------- -- Copyright (c) 1999 .. 2015 Tidorum Ltd -- All rights reserved. -- -- 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. -- -- This software is provided by the copyright holders and contributors "as is" and -- any express or implied warranties, including, but not limited to, the implied -- warranties of merchantability and fitness for a particular purpose are -- disclaimed. In no event shall the copyright owner or contributors be liable for -- any direct, indirect, incidental, special, exemplary, or consequential damages -- (including, but not limited to, procurement of substitute goods or services; -- loss of use, data, or profits; or business interruption) however caused and -- on any theory of liability, whether in contract, strict liability, or tort -- (including negligence or otherwise) arising in any way out of the use of this -- software, even if advised of the possibility of such damage. -- -- Other modules (files) of this software composition should contain their -- own copyright statements, which may have different copyright and usage -- conditions. The above conditions apply to this file. ------------------------------------------------------------------------------- -- -- $Revision: 1.115 $ -- $Date: 2015/10/24 20:05:46 $ -- -- $Log: bounds.adb,v $ -- Revision 1.115 2015/10/24 20:05:46 niklas -- Moved to free licence. -- -- Revision 1.114 2014/07/01 22:07:49 niklas -- Added some trace output to Bound_Time_And_Space. -- -- Revision 1.113 2013/12/23 21:19:04 niklas -- Provide assertions to SWEET.Resolve_Dynamic_Jumps. -- -- Revision 1.112 2013/12/20 21:20:55 niklas -- Modified Avoid_Arithmetic_Analysis not to report dynamic flow as -- needing arithmetic analysis, if SWEET is included. -- -- Revision 1.111 2013/12/12 22:26:04 niklas -- BT-CH-0262: Corrections to new value-origin analysis. -- -- Revision 1.110 2013/12/08 22:05:57 niklas -- BT-CH-0259: Storing value-origin analysis results in execution bounds. -- -- Revision 1.109 2013-12-01 20:14:33 niklas -- Updated for changes to opt/sweet, for i8051_4b3. -- -- Revision 1.108 2013-02-03 21:06:48 niklas -- BT-CH-0239: SWEET for dynamic flow analysis - step 1. -- -- Revision 1.107 2011-10-18 20:19:49 niklas -- Updated to provide the Subprogram as a parameter to -- Processor.Properties.Entry_Bounds, an update required by -- the ALF export function. -- -- Revision 1.106 2011-08-31 04:23:33 niklas -- BT-CH-0222: Option registry. Option -dump. External help files. -- -- Revision 1.105 2009-11-27 11:28:06 niklas -- BT-CH-0184: Bit-widths, Word_T, failed modular analysis. -- -- Revision 1.104 2009-10-07 19:26:09 niklas -- BT-CH-0183: Cell-sets are a tagged-type class. -- -- Revision 1.103 2009-04-16 19:46:01 niklas -- Expanded "others" Goals in calls of Flow.Origins.Propagate. -- -- Revision 1.102 2008/12/25 08:59:33 niklas -- Removed unused context clauses and local variables. -- -- Revision 1.101 2008/11/09 21:41:57 niklas -- BT-CH-0158: Option "-trace instr". -- -- Revision 1.100 2008/11/02 08:46:52 niklas -- BT-CH-0154: Assertions on mobile variables correctly used. -- -- Revision 1.99 2008/10/19 10:12:05 niklas -- Improved a trace heading in Bound_Execution. -- -- Revision 1.98 2008/09/24 08:38:52 niklas -- BT-CH-0146: Assertions on "loop starts <bound> times". -- BT-CH-0146: Loop-repeat assertions set both lower and upper bound. -- BT-CH-0146: Report locations of contradictory "count" assertions. -- BT-CH-0146: Contradictory "count" assertions imply infeasibility. -- -- Revision 1.97 2008/09/20 12:41:50 niklas -- BT-CH-0145: No error re too few assertion matches if graph is growing. -- -- Revision 1.96 2008/07/28 19:23:45 niklas -- BT-CH-0140: Detect contradictory execution-count bounds. -- -- Revision 1.95 2008/07/23 09:07:15 niklas -- BT-CH-0139: Fix recursion in Programs.Execution.Paths. -- -- Revision 1.94 2008/07/14 19:16:55 niklas -- BT-CH-0135: Assertions on "instructions". -- -- Revision 1.93 2008/04/26 19:19:43 niklas -- BT-CH-0124: Joint loop counters and induction variables. -- -- Revision 1.92 2008/03/05 18:45:30 niklas -- BT-CH-0120: Allow several dynamically conditional edges from a step. -- -- Revision 1.91 2008/02/27 14:58:48 niklas -- BT-CH-0116: Call-specific time and stack assertions. -- -- Revision 1.90 2008/01/31 21:57:44 niklas -- BT-CH-0108: Fixes to BT-CH-0098. -- -- Revision 1.89 2007/12/22 15:23:46 niklas -- BT-CH-0101: Option "-trace graph". -- -- Revision 1.88 2007/12/21 13:32:53 niklas -- Extended Bound_Execution to use (new) Bound_As_Infeasible to define -- some dummy bounds (eg. empty cell-sets) for an infeasible subprogram. -- -- Revision 1.87 2007/12/17 13:54:35 niklas -- BT-CH-0098: Assertions on stack usage and final stack height, etc. -- -- Revision 1.86 2007/11/12 21:37:27 niklas -- BT-CH-0097: Only arithmetic analysis marks boundable edge domain. -- -- Revision 1.85 2007/10/31 12:16:00 niklas -- BT-CH-0095: Arithmetic analysis of "live" dynamic data refs. -- -- Revision 1.84 2007/10/28 09:32:45 niklas -- BT-CH-0092: Arithmetic analysis of dynamic data refs is optional. -- -- Revision 1.83 2007/10/26 12:44:34 niklas -- BT-CH-0091: Reanalyse a boundable edge only if its domain grows. -- -- Revision 1.82 2007/10/11 12:00:22 niklas -- Use Flow.Computation.Show.Report_Unresolved_Flow instead of the -- like-named operation of Flow.Show. This suppresses unnecessary -- error messages for unresolved but infeasible dynamic edges. -- -- Revision 1.81 2007/10/02 20:47:10 niklas -- Added list of basis cells to Trace_Arith output. -- -- Revision 1.80 2007/08/20 07:56:38 niklas -- Removed Add_Inputs_For_Unbounded_Calls (added in rev 1.75) because -- they add unnecessary input cells (cells that are given values in the -- subprogram, although not sufficient to bound the call). -- -- Revision 1.79 2007/08/17 14:44:00 niklas -- BT-CH-0074: Stable and Unstable stacks. -- -- Revision 1.78 2007/08/10 06:55:09 niklas -- Added Trace line as heading to Trace_Context. -- -- Revision 1.77 2007/08/06 09:20:43 niklas -- Added option Trace_Phase. -- -- Revision 1.76 2007/08/03 19:10:48 niklas -- Updated to use Programs.Show. -- -- Revision 1.75 2007/07/09 13:55:12 niklas -- Extended Bound_With_Arithmetic to Add_Inputs_For_Unbounded_Calls -- when it stores the set of input cells in the execution bounds. -- -- Revision 1.74 2007/02/13 20:14:20 Niklas -- BT-CH-0044. -- -- Revision 1.73 2007/01/13 13:51:02 niklas -- BT-CH-0041. -- -- Revision 1.72 2006/11/26 22:07:25 niklas -- BT-CH-0039. -- -- Revision 1.71 2006/11/20 20:20:18 niklas -- BT-CH-0037. -- -- Revision 1.70 2006/10/24 21:41:05 niklas -- BT-CH-0030. -- -- Revision 1.69 2006/10/24 08:44:29 niklas -- BT-CH-0028. -- -- Revision 1.68 2006/09/04 15:07:03 niklas -- Added the option "-trace arith", as Bounds.Opt.Trace_Arith. -- -- Revision 1.67 2006/08/22 13:16:56 niklas -- Extended Finish_Bounds to call Decoder.Stop when decoding was -- suspended for dynamic flow, but no further decoding was necessary. -- This avoids a dangling "Decoding suspended" message. -- Removed the unused Subprogram parameter from Show_IO_Cells, and -- also the first Trace line (uninformative title). -- -- Revision 1.66 2006/05/27 21:56:08 niklas -- Updated for BT-CH-0020. -- -- Revision 1.65 2006/05/26 15:15:34 niklas -- Corrected Bound_With_Arithmetic to use the Call_Off index-shift -- only for Into_Interest, not for Call_Steps. Calls_Steps'Range -- is the same as Unbounded_Calls'Range, no shift there. -- -- Revision 1.64 2005/10/20 19:34:00 niklas -- BT-CH-0016. -- -- Revision 1.63 2005/10/20 11:28:28 niklas -- BT-CH-0015. -- -- Revision 1.62 2005/09/20 10:03:15 niklas -- Changed Bound_Execution.Apply_Assertions to apply loop-assertions -- only to loops that are still feasible and feasibly repeatable and -- not yet bounded. This avoids repeated application of the same -- assertions to the same loop (after flow-graph pruning) and also -- avoids repeated warnings about unreachable or unrepeatable loops. -- -- Revision 1.61 2005/09/17 14:42:04 niklas -- BT-CH-0009. -- -- Revision 1.60 2005/09/14 12:00:38 niklas -- Corrected Bound_With_Arithmetic to deal with the case of an empty -- Basis cell-set, for which no arithmetic analysis is possible or -- useful. -- Extended Bound_Execution to display all the asserted and inherited -- bounds on variable values if Bounds.Opt.Trace_Context is set. -- -- Revision 1.59 2005/09/12 19:02:57 niklas -- BT-CH-0008. -- -- Revision 1.58 2005/09/03 11:50:27 niklas -- BT-CH-0006. -- -- Revision 1.57 2005/07/01 11:06:58 niklas -- Added the exception Flow.False_Path to the exception handlers -- for Calculator.Empty_Flux, since some analysis routines now use -- the former exception to signal infeasibility. In Resolve_Protocol -- removed Empty_Flux since it cannot occur now due to changes in -- Bounds.Calling.Bound_Protocol. -- Corrected the Note regarding iteration in Bound_With_Arithmetic. -- -- Revision 1.56 2005/06/29 13:02:41 niklas -- Added optional (-warn reach) warnings about unreachable -- instructions and calls. -- -- Revision 1.55 2005/06/29 09:37:05 niklas -- Check and report conflicting asserted or computed cell-bounds -- on entry to the subprogram under analysis. -- -- Revision 1.54 2005/06/28 08:36:44 niklas -- Updated for changes in Bounds.Opt. -- Changed Show_IO_Cells to use the same order as in detailed -- output: input cells, basis cells, output cells. -- Removed Exec_Bounds parameter from Analyze_Irreducible_Subprogram -- because the caller (Bound_Executions) does not need it. -- Added procedure Find_Execution_Bounds to find existing (asserted) -- execution bounds and avoid analysis of "stub" flow-graphs. -- -- Revision 1.53 2005/06/14 17:05:48 niklas -- Corrected Bound_With_Arithmetic, in its local procedures -- Resolve_Data, Resolve_Edge_Cond, Resolve_Protocol and -- Resolve_Flow, to constrain the flux into the relevant step -- by all applicable assertions and by the Range_Pre elements -- in the step's effect. This is done by applying the function -- Assertion_Constrained to the flux from Calculator.Flux_To_Steps. -- -- Revision 1.52 2005/05/09 15:34:48 niklas -- Added value-origin analysis. -- -- Revision 1.51 2005/04/18 10:51:29 niklas -- Added call of Flow.Computation.Show.Report_Unresolved_Data. -- -- Revision 1.50 2005/04/18 09:31:16 niklas -- Added call to Flow.Show.Report_Unresolved_Flow. -- -- Revision 1.49 2005/02/23 09:05:14 niklas -- BT-CH-0005. -- -- Revision 1.48 2005/02/20 15:15:35 niklas -- BT-CH-0004. -- -- Revision 1.47 2005/02/16 21:11:40 niklas -- BT-CH-0002. -- -- Revision 1.46 2004/05/02 06:04:53 niklas -- First Tidorum version. -- Added support for optional time analysis and optional space analysis, in -- particular in Avoid_Arithmetic_Analysis. -- Added support for variables that are held in different cells depending -- on code address (Storage.Location). -- Tolerating irreducible subprograms with Analyze_Irreducible_Subprogram. -- Added constant propagation using Flow.Const in Launch_And_Propagate, but -- so far only on the universal level (no call path dependency) and after -- all dynamic flow is resolved. -- Using dynamism resolution operations from Flow.Dynamic. -- Added support for dynamic flow edges (new form of dynamic flow). -- Extended Nesting_Bounded and Assertion_Constrained to include Range_Pre -- constraints. -- Updated for changes in the Programs family. In particular, extended and -- improved the stack usage analysis, separating Bound_Local_Stack_Height, -- Bound_Take_Off_Height and Bound_Total_Stack_Usage. -- Added support for assertions on subprogram input parameters. -- Taking Cell_T stuff from Storage, not from Arithmetic. -- Using Output.Trace for trace output. -- Bound_Jumps_And_Execution (Subprogram_Set_T) now places a locus nesting -- mark for the subprogram to be analyzed. -- Added several Calculator.Comment calls. -- -- Revision 1.45 2003/03/11 08:31:34 holsti -- Using execution-bounds types from Programs.Execution. -- Added calculator comments for loop-counter checks. -- -- Revision 1.44 2003/02/27 14:37:15 holsti -- Some warnings are conditional on Opt.Warn_Unresolved_Data. -- -- Revision 1.43 2002/11/30 10:47:13 holsti -- Changed Bound_Jumps_And_Execution (for subprogram sets) to delay -- bounding of any caller of a "resolved" subprogram, even if the caller -- has unresolved dynamic flow. This fixes NC_0147. -- Moved Report_Recursion_Cycle to the package level for readability. -- -- Revision 1.42 2002/11/29 11:02:37 holsti -- Using Programs.Sort instead of local code. -- -- Revision 1.41 2002/03/21 09:13:49 saarinen -- Fixed NC_116. -- -- Revision 1.40 2001/12/14 10:49:49 saarinen -- Call dependent analysis limited by option 'max_dependency_depth'. -- -- Revision 1.39 2001/12/10 13:00:07 holsti -- When a call provides no new context, its execution bounds refer -- to the existing (not fully bounded) execution bounds. -- -- Bound_Asserted_Calls has Program parameter because some operations -- in Programs now require it for indexing of execution bound objects. -- -- Calculator.Comments added in Resolve_Flow and Resolve_Data. -- -- Revision 1.38 2001/11/19 10:57:08 saarinen -- Modified for Bound-T/ERC32: -- Removed Compute_Node_Times. -- -- Revision 1.37 2001/06/23 11:44:37 holsti -- Call_Count assertion applied for all calls (NC_135). -- -- Revision 1.36 2001/05/20 13:36:43 holsti -- Finishes flow-graphs with Decoder.Finish (NC_117). -- Computes node execution times with Decoder.Power, Flow.Work, -- and Processor.Time_To_Finish (NC_120, NC_121, NC_122, NC_128). -- -- Revision 1.35 2001/04/14 17:17:12 holsti -- Warn here about unresolved dynamic accesses. -- Warning re asserted bounds overriding computed bounds changed. -- -- Revision 1.34 2001/03/21 20:18:22 holsti -- Output with Locus_T. Some reorganization, too. -- -- Revision 1.33 2001/03/16 09:37:06 ville -- Effort function provided by Flows package used -- -- Revision 1.32 2001/03/15 20:48:32 holsti -- Exit bounding-loop when a resolved subprogram is called. -- -- Revision 1.31 2001/03/15 07:32:41 holsti -- Loop approximation restricted to Basis cells. -- -- Revision 1.30 2001/03/10 22:39:02 holsti -- Option Show_Cell_Sets (-trace io) added. Notes modified. -- -- Revision 1.29 2001/03/10 00:54:10 holsti -- Extensive changes to handle effects of calls (input and ouptut cells) -- and to reduce the size of the basis cell-set. -- Adaptations to the new dynamic parameter-mapping for calls. -- Adaptations to compute and store input and output cell-sets -- and initial bounds for execution bounds. -- NC_098 corrected at least partially. -- -- Revision 1.28 2001/02/19 15:16:50 holsti -- Avoid arithmetic analysis, if possible or required. -- -- Revision 1.27 2001/02/19 09:44:44 holsti -- Adapted to changes in Programs.Execution_Bounds_Ref. -- Execution bounds are never attached to a call, but always to -- a call-path (null for universal bounds) and stored with the -- subprogram. -- All derived execution bounds are stored, whether complete or not. -- Some editorial changes in output formats. -- -- Revision 1.26 2001/02/14 06:49:17 holsti -- Option to trace counters added. -- -- Revision 1.25 2001/01/19 08:54:47 saarinen -- Call to Flux_To_Step modied according to changes in calculator. -- Omega is not used for analysis for subprograms without loops, -- call or dynamics. -- -- Revision 1.24 2001/01/13 11:11:31 holsti -- Adapted to changes in Calculator of this date. -- -- Revision 1.23 2001/01/07 22:18:43 holsti -- Live-cell analysis added. -- Comments on calculation-steps added. -- Trace of param framing and values added (Show_Parameters). -- Deleted "to-be" remarks in favour of non-conformances. -- -- Revision 1.22 2001/01/04 09:57:48 saarinen -- Fixed NC_074. -- -- Revision 1.21 2000/12/28 19:05:14 holsti -- Medium-important improvements as follows. -- General description updated. -- Editorial improvements in comments and formatting. -- Bound_Call uses both Min and Max of asserted call-count (NC_030). -- Call_Level parameters moved to suit their "in" mode. -- Check_Step sets Const_Step in a simpler way. -- Unused parameters of Bound_Loops (Graph, Root_Flux) removed. -- Bound_Loops clarified with new local variables and subprograms. -- Bound_Call_With_Context clarified with new local subprograms. -- Bound_Call_With_Context displays Call_Level in note. -- Bound_Call_With_Context checks that callee is static. -- Resolve_Dynamic_Flow uses Arithmetic.Void_Bound for empty flux. -- Resolve_Dynamic_Data uses Arithmetic.Void_Bound for empty flux. -- Use Loop_Cell_Set_T and Loop_Flux_T from Calculator (NC_040). -- Use Programs.Some_Calls and Flow.Unresolved_Flow. -- -- Revision 1.20 2000/12/28 14:05:37 saarinen -- Fixed NC_046: Negative loop-bounds cause Constraint Error. -- Fixed NC_051: Loop termination on counter equal to limit. -- Does not call audition_for_counter with non-counter cells. -- -- Revision 1.19 2000/12/21 14:37:53 sihvo -- Minor changes in layout etc. -- -- Revision 1.18 2000/12/05 15:48:01 holsti -- Adapted to new names of Decoder framing functions. -- The term "loop neck" replaces the overloaded "loop entry". -- Decoder.Stack_Height_Cell replaces deleted Arithmetic function. -- Absence of stack-height cell tolerated (then no stack bounds). -- -- Revision 1.17 2000/11/29 14:58:51 holsti -- Using Decoder.Duration instead of Processor.To_Time. -- -- Revision 1.16 2000/11/29 13:50:24 saarinen -- Cleaned procedure Update_Var_Cell_Set. -- -- Revision 1.15 2000/11/24 12:06:00 sihvo -- Added stack height analysis. -- -- Revision 1.14 2000/11/24 10:13:08 saarinen -- Calls to Flux_To_Steps modified. -- Variable cells in subprograms are updated. -- -- Revision 1.13 2000/11/22 22:42:13 holsti -- Added function Time to compute the time of one node, using -- the new function Processor.Effort (Step_Info_T). -- -- Renamed Bound_Node_Times to Compute_Node_Times, and changed -- it to use an Assertion_Map_T instead of an Assertion_Set_T, -- in preparation for the use of a "property map". -- -- Moved the two calls of Compute_Node_Times into one call in -- Bound_Jumps_And_Execution (for one subprogram), so that the -- assertion map is available for use as a parameter. -- -- Report_Recursion_Cycle modified for new Programs functions, -- robustness, layout, comments. -- -- Minor commenting and layout improvements. -- -- Revision 1.12 2000/11/14 10:39:32 sihvo -- Added recursion reporting. -- -- Revision 1.11 2000/11/09 14:48:17 saarinen -- Fixed call dependent bounding. -- Handles empty fluxes. -- NC_020 fixed. -- -- Revision 1.10 2000/10/26 10:01:23 saarinen -- Fixed call-dependent bounding. -- -- Revision 1.9 2000/10/19 11:17:08 saarinen -- Using parameters for call-specific bounding. -- Resolving indirect data accesses. -- Delaying bounding of subprograms with dynamic-resolved callees. -- -- Revision 1.8 2000/10/17 11:35:31 langback -- Changed Bounds_Calls so that it works correctly with the return type -- of Assertion.Call_Count -- -- Revision 1.7 2000/10/06 14:10:47 saarinen -- Modified loop bounding. -- -- Revision 1.6 2000/09/20 18:54:43 saarinen -- Added function Bound_Node_Times. -- -- Revision 1.5 2000/08/18 18:19:30 holsti -- Bound_Jumps_And_Execution includes To_Bound in sorting. -- Programs.Output used to trace analysis. -- -- Revision 1.4 2000/08/04 14:47:50 saarinen -- Corrected some typos. -- -- Revision 1.3 2000/07/25 03:13:59 holsti -- First implementation (incomplete). -- -- Revision 1.2 2000/07/12 12:24:31 holsti -- Normalised indentation. -- with Arithmetic; with Arithmetic.Opt; with Bounds.Calling; with Bounds.Looping; with Bounds.Opt; with Bounds.Recursing; with Bounds.Stacking; with Bounds.Timing; with Calculator; with Decoder; with Flow; with Flow.Computation; with Flow.Computation.Show; with Flow.Const; with Flow.Life; with Flow.Origins; with Flow.Origins.For_Flow; with Flow.Origins.Overall_Invariants; with Flow.Pruning; with Flow.Pruning.Opt; with Flow.Show; with Loops; with Loops.Show; with Loops.Slim; with Output; with Processor; with Processor.Properties; with Programs.Execution; with Programs.Show; with Programs.Sort; with Storage.Bounds.Show; with Storage.List_Cell_Sets; with SWEET; with Symbols; package body Bounds is -- -- This package contains a number of operations with similar and -- complex functionality, which may be difficult to understand and -- organise in the reader's mind. The following summary of the calling -- sequences and activities may help. -- -- There are two public operations: Bound_Executions bounds a set of -- subprograms, and Bound_Execution bounds one subprogram in a given -- calling context. -- -- When Bound_Executions is first used, the full set of subprograms has -- perhaps not yet been discovered, if some subprograms contain unresolved -- dynamic jumps. -- Bound_Executions works bottom-up in the (currently known) call-graph -- and computes execution bounds for subprograms that do not have open -- (unresolved) dynamic jumps. If it encounters a subprogram with such -- jumps, it uses the data-flow analysis to resolve the jumps and extend -- the control-flow graph of the subprogram, and terminates there; the -- caller is expected to trace out the extended control-flow graph as far -- as it can, update the call-graph using the new flow-graph, and -- continue the analysis by again calling Bound_Executions, for the set -- of subprograms that were not yet bounded (thus including the one for -- which the control-flow graph was extended). -- -- When the data-flow analysis of a subprogram does not produce -- execution bounds without knowledge about parameter values, the -- subprogram is left without (generic) execution bounds, and is -- considered "call-dependent". Later, when some caller subprogram is -- bounded, the calling context is used to sharpen a new data-flow -- analysis of the call-dependent subprogram, to give call-specific -- execution bounds. This explains why Bound_Execution is self-recursive -- via the procedure Bounds.Calling.Bound_Call_With_Context. -- -- The algorithm in Bound_Executions is summarised as follows, including -- all the operations called from this package but only the most important -- operations called from other packages: -- -- Bound_Executions (set of subprograms): -- -- for each subprogram in bottom-up calling order: -- -- Bound_Execution (one subprogram): -- -- Programs.Execution.Bound_Initial_Values to record -- the context- and assertion-derived bounds on the -- values of cells on entry to the subprogram; -- -- Programs.Execution.Bound_Call_Inputs to record the -- the context- and assertion-derived bounds on the -- inputs to calls to lower-level subprograms; -- -- loop while the computation model improves but -- dynamic edges are not resolved: -- -- Flow.Origins.Propagate provides cell-value origins -- for target-specific uses, for example to chain -- single-word instructions thru carry bits into -- multi-word arithmetic operations. -- -- Flow.Const.Propagate propagates constant values around -- the flow-graph to refine the computation model and -- perhaps prune infeasible parts of the graph; -- -- Flow.Origins.Propagate propagates value copies around -- the flow-graph, here used to resolve boundable -- jumps, especially jumps to the return address; -- -- Assertions.Identify_Loops_And_Calls to map the user's -- assertions to the subprogram's structure; -- -- Bounds.Looping.Bound_Asserted_Starts to bound the loops -- for which the user has asserted loop-start bounds; -- -- Bounds.Looping.Bound_Asserted_Repeats to bound the loops -- for which the user has asserted loop-repeat bounds; -- -- Bounds.Calling.Bound_Asserted_Calls to bound the calls -- for which the user has asserted a worst-case time; -- -- Abstract Execution using SWEET to resolve boundable jumps, -- if the SWEET option is included and options are set -- to use it for resolving dynamic jumps; -- -- Avoid_Arithmetic_Analysis to see if arithmetic -- analysis is still required; -- -- if arithmetic analysis is still required and enabled: -- -- Bound_With_Arithmetic (see below) -- -- exit loop when the computation model is stable -- or dynamic edges were resolved -- -- else: -- -- Bound_Without_Arithmetic (see below) -- -- exit loop -- -- end loop -- -- -- Bound_With_Arithmetic: -- -- Flow.Life.Propagate identifies the "live" assignments; -- -- Loops.Approximate_Loops and -- Calculator.Pool_To_Steps for data-flow analysis; -- -- for all steps with dynamic data references: -- Arithmetic.Bound_References to resolve them; -- -- for all edges with dynamic data references: -- Arithmetic.Reference_Bounded to resolve them; -- -- for all calls with a dynamic calling protocol: -- Bounds.Calling.Bound_Protocol to resolve it, using -- the arithmetic flux into the call. -- -- if no new dynamic data references were resolved: -- -- for each dynamic edge in the flow-graph: -- Flow.Apply to resolve the edge; -- -- if no extension of flow-graph: -- -- Flow.Remove_All_Dynamic_Edges; -- -- for each unbounded, feasible loop: -- Nesting_Bounded for assertions on "into" flux; -- Nesting_Bounded for assertions on repeat-edge flux; -- Bounds.Looping.Bound_Loop -- -- for each unbounded, feasible call: -- Nesting_Bounded for assertions on "into" flux; -- Bounds.Calling.Bound_Call -- -- if stack bounds desired: -- Bounds.Stacking.Bound_Local_Stack_Height -- Bounds.Stacking.Bound_Take_Off_Height -- -- -- Bound_Without_Arithmetic: -- -- for all calls with dynamic calling protocol: -- Bounds.Calling.Bound_Protocol to resolve it, -- using all assertions applicable to this call. -- -- for each unbounded, feasible call: -- Bounds.Calling.Bound_Call to bound the callee, -- using all assertions applicable to this call. -- -- This completes the call-sequence summary. use type Programs.Call_Path_T; function Fully_Bounded (Item : Programs.Execution.Bounds_Ref) return Boolean -- -- Whether the bounds are fully bounded with respect to the -- desired execution measures as defined in Bounds.Opt. -- renames Programs.Execution.Bounded; function Nesting_Bounded_Flux ( Step : Flow.Step_T; Flux : Calculator.Flux_T; Living : Flow.Life.Living_T; Luups : Loops.Loop_List_T; Asserts : Assertions.Assertion_Map_T) return Calculator.Flux_T -- -- The given Flux that enters the given Step, range-constrained with all -- Asserted cell-bounds for all Luups that contain the Step (including -- the assertions for the Step itself, if it is a loop-head), plus -- any Range_Pre assignment constraints in the effect of the Step -- itself, under the given Living computation model. -- is Point : constant Processor.Code_Address_T := Flow.Prime_Address (Step); -- The code address of the step, for mapping variables to cells. Node : constant Flow.Node_T := Flow.Node_Containing (Step, Flow.Life.Graph (Living)); -- The node that contains the given step. Loop_Bounds : constant Storage.Bounds.Cell_Interval_List_T := Assertions.Loop_Nest_Values ( Luups => Loops.Containing_Loops (Luups, Node), Point => Point, Asserts => Asserts); -- The asserted variable (cell) bounds for those Luups that -- contain this Node, mapped to cells at this Point. Result : Calculator.Flux_T := Flux; -- The result, initialised to the given (raw) flux. begin -- Apply assertions from loops: if Loop_Bounds'Length > 0 then -- Some assertions given for containing loops. Calculator.Comment ( Text =>"Using assertions from containing loops", Calc => Calculator.Owner_Of (Flux)); Result := Calculator.Range_Bounded_Flux ( Flux => Result, Bounds => Loop_Bounds); end if; -- Apply Range_Pre constraints in the effect of the step: Result := Calculator.Range_Bounded_Flux ( Flux => Result, Pre => Flow.Life.Live_Effect (Step, Living)); return Result; end Nesting_Bounded_Flux; function Nesting_Bounded_Pool ( Step : Flow.Step_T; Pool : Calculator.Pool_T; Living : Flow.Life.Living_T; Luups : Loops.Loop_List_T; Asserts : Assertions.Assertion_Map_T) return Calculator.Pool_T -- -- The given Pool that enters the given Step, constrained with all -- Asserted cell-bounds for all Luups that contain the Step (including -- the assertions for the Step itself, if it is a loop-head), plus -- any Range_Pre assignment constraints in the effect of the Step -- itself, under the given Living computation model. -- is Point : constant Processor.Code_Address_T := Flow.Prime_Address (Step); -- The code address of the step, for mapping variables to cells. Node : constant Flow.Node_T := Flow.Node_Containing (Step, Flow.Life.Graph (Living)); -- The node that contains the given step. Loop_Bounds : constant Storage.Bounds.Cell_Interval_List_T := Assertions.Loop_Nest_Values ( Luups => Loops.Containing_Loops (Luups, Node), Point => Point, Asserts => Asserts); -- The asserted variable (cell) bounds for those Luups that -- contain this Node, mapped to cells at this Point. Result : Calculator.Pool_T := Pool; -- The result, initialised to the given (raw) pool. begin -- Apply assertions from loops: if Loop_Bounds'Length > 0 then -- Some assertions given for containing loops. Calculator.Comment ( Text => "Using assertions from containing loop.", Calc => Calculator.Owner_Of (Pool)); Result := Calculator.Bounded_Pool ( Pool => Result, Bounds => Loop_Bounds); end if; -- Apply Range_Pre constraints in the effect of the step: Result := Calculator.Bounded_Pool ( Pool => Result, Pre => Flow.Life.Live_Effect (Step, Living)); return Result; end Nesting_Bounded_Pool; -- -- Auxiliary functions for gaining subprogram data: -- procedure Avoid_Arithmetic_Analysis ( Exec_Bounds : in Programs.Execution.Bounds_Ref; Choice : in Arithmetic.Opt.Choice_T; Chosen : out Boolean) -- -- Decides whether it is necessary to apply arithmetic analysis -- for bounding this subprogram further. -- -- If arithmetic analysis is not enabled for this subprogram (by -- option or assertion), but the subprogram contains some feature -- that would require such analysis, these features are reported -- as errors. -- -- If arithmetic analysis is not needed for this subprogran, but -- is enforced (by option or assertion), a note is issued. -- -- We assume that we have already applied all assertions on -- execution time, stack usage, loop bounds, zero execution -- count (infeasibility), and variable values on this subprogram, -- its loops, and its calls. Moreover, we assume that less costly -- forms of analysis (constant propagation, value-origin analysis) -- have been applied, too, so that the only "unbounded" parts left -- are those that need arithmetic analysis. -- -- For time-bounds, arithmetic analysis is needed if the subprogram -- is not yet time-bounded (by an assertion or because it inherits -- time-bounds from a shallower context) and one or more of the -- following occur in the subprogram (as feasible): -- -- > An unresolved boundable jump or call. (Note that this can -- occur only in a context-free, universal analysis.) -- -- > An unbounded but finite (non-eternal) loop. (Also means that -- the flow-graph is reducible.) -- -- > A call where the execution time Depends on context and -- TBA the present (caller) subprogram provides some relevant -- context (contains origins of input cells for the call). -- -- For stack-bounds, arithmetic analysis is needed if the subprogram -- is not yet stack-bounded (by an assertion or because it inherits -- stack-bounds from a shallower context) and if one or more of the -- following occur in the subprogram (as feasible); these conditions -- are checked separately for each stack that is not yet bounded: -- -- > An unresolved boundable jump or call. (Note that this can -- occur only in a context-free, universal analysis.) -- -- > A call where the stack usage Depends on context and -- TBA the present (caller) subprogram provides some relevant -- context (contains origins of input cells for the call). -- -- > TBA: A call with an unbounded take-off height where the callee -- is not stack-vague. -- -- The presence of dynamic calling protocols in the calls from the -- subprogram is not, in itself, a reason for arithmetic analysis. -- -- The presence of unresolved dynamic memory references in the -- subprogram is not, in itself, a reason for arithmetic analysis. -- is use Arithmetic.Opt; use Programs.Execution; use type Flow.Edge_Resolution_T; use type Storage.Cell_T; Unresolved_Flow : constant Boolean := Unstable_Dynamic_Edges (Exec_Bounds)'Length > 0; -- -- Dynamic flow requires arithmetic analysis to be resolved -- for any sort of analysis. Loose_Loops : constant Boolean := Opt.Bound_Time and then Unbounded_Loops ( Within => Exec_Bounds, Eternal => False)'Length > 0; -- -- Any loop that is not yet bounded, but is finite and thus -- potentially boundable by anaysis, requires arithmetic -- analysis if the execution time should be bounded. Stack_Mods : constant Boolean := Opt.Bound_Stack and then Unbounded_Stack_Steps (Exec_Bounds)'Length > 0; -- -- Any step that modifies the stack pointer requires arithmetic -- analysis, if the stack usage should be bounded and has not -- already been bounded (by constant propagation). Input_Dep_Calls : constant Boolean := Input_Dependent_Calls (Exec_Bounds)'Length > 0; -- -- Some (unbounded) calls may benefit from context-dependent -- analysis that provides bounds on inputs (parameters). Needed : constant Boolean := Unresolved_Flow or Loose_Loops or Stack_Mods or Input_Dep_Calls; -- -- Whether arithmetic analysis is needed. procedure Why (What : in String) -- -- Explain why arithmetic analysis needed. -- is What_Needs : constant String := What & " arithmetic analysis."; begin if Choice = Disabled then Output.Error (What_Needs); else Output.Trace (What_Needs); end if; end Why; begin -- Avoid_Arithmetic_Analysis if Needed and (Choice = Disabled or Opt.Trace_Arith) then -- Report why arithmetic analysis is required: if Unresolved_Flow and not SWEET.Included then Why ("Dynamic flow needs"); end if; if Loose_Loops then Why ("Loops need"); end if; if Stack_Mods then Why ("Stack usage needs"); end if; if Input_Dep_Calls then Why ("Calls need"); end if; end if; if not Needed then if Choice = Enforced then Output.Note ("Arithmetic analysis is enforced."); else Output.Note ("Arithmetic analysis is not needed."); end if; end if; Chosen := Choice = Enforced or (Choice = Automatic and Needed); end Avoid_Arithmetic_Analysis; procedure Show_IO_Cells ( Basis : in Storage.Cell_Set_T; Inputs : in Storage.Cell_Set_T; Outputs : in Storage.Cell_Set_T) -- -- Displays the sets of basis cells, input cells, and output -- to be used for bounding the subprogram on the current -- call path (assumed to be defined as the current output locus). -- is begin Output.Trace (Text => "Input cells" & Output.Field_Separator & Storage.Image (Inputs)); Output.Trace (Text => "Basis cells" & Output.Field_Separator & Storage.Image (Basis)); Output.Trace (Text => "Output cells" & Output.Field_Separator & Storage.Image (Outputs)); end Show_IO_Cells; procedure Set_IO_Cells ( Inputs : in Storage.Cell_Set_T; Outputs : in Storage.Cell_Set_T; Basis : in Storage.Cell_Set_T; Within : in Programs.Execution.Bounds_Ref) -- -- Stores the sets of input and output cells as well as the -- calculation-basis set Within the given execution bounds, and -- optionally displays the cell sets. -- is begin Programs.Execution.Set_Input_Cells ( To => Inputs, Within => Within); Programs.Execution.Set_Output_Cells ( To => Outputs, Within => Within); Programs.Execution.Set_Basis_Cells ( To => Basis, Within => Within); if Opt.Trace_Cell_Sets then Show_IO_Cells ( Basis => Basis, Inputs => Inputs, Outputs => Outputs); end if; end Set_IO_Cells; procedure Mark_Unreachable ( Step : in Flow.Step_T; Model : in Flow.Computation.Model_Handle_T; Kind : in String := "instruction") -- -- Marks the Step as unreachable (infeasible) under the -- given Model and prunes the Model. -- is begin if Flow.Pruning.Opt.Warn_Unreachable then Output.Warning ("Unreachable " & Kind); end if; Flow.Computation.Mark_Infeasible (Step, Model.all); Flow.Computation.Prune (Model.all); end Mark_Unreachable; procedure Trace_Nubs ( Kind : in String; Nubs : in Flow.Step_List_T; Program : in Programs.Program_T) -- -- Shows that the Nubs need arithmetic analysis. -- is Source : Symbols.Symbol_Table_T := Programs.Symbol_Table (Program); -- For output locus. begin for N in Nubs'Range loop Output.Trace ( Locus => Flow.Show.Locus (Step => Nubs(N), Source => Source), Text => Kind & " nub in step" & Flow.Step_Index_T'Image (Flow.Index (Nubs(N)))); end loop; end Trace_Nubs; function Opt_Steps_With_Dynamic_Effect ( Living : Flow.Life.Living_T) return Flow.Step_List_T -- -- The feasible steps that have effects that contain "live" -- assignments with value expressions or condition expressions -- that contain dynamic data references that shall be subjected -- to arithmetic analysis. -- is use Arithmetic.Opt; begin case Ref_Choice is when None => return Flow.No_Steps; when Relevant => return Flow.Life.Steps_With_Dynamic_Effect (Living); when All_Item => return Flow.Computation.Steps_With_Dynamic_Effect ( Under => Flow.Life.Model (Living).all); end case; end Opt_Steps_With_Dynamic_Effect; function Opt_Edges_With_Dynamic_Condition ( Model : Flow.Computation.Model_Ref) return Flow.Step_Edge_List_T -- -- The step-edges that have preconditions that contain dynamic data -- references that shall be subjected to arithmetic analysis. -- is use Arithmetic.Opt; begin case Ref_Choice is when None => return Flow.No_Step_Edges; when Relevant | All_Item => return Flow.Computation.Edges_With_Dynamic_Condition (Model); end case; end Opt_Edges_With_Dynamic_Condition; procedure Bound_With_Arithmetic ( Subprogram : in Programs.Subprogram_T; Call_Path : in Programs.Call_Path_T; Initial : in Storage.Bounds.Cell_Interval_List_T; Asserted : in Storage.Bounds.Var_Interval_List_T; Inherit_Inv : in Storage.Cell_Set_T; Asserts : in Assertions.Assertion_Set_T; Assert_Map : in Assertions.Assertion_Map_T; Bounds_Set : in Programs.Execution.Bounds_Set_T; Exec_Bounds : in Programs.Execution.Bounds_Ref) -- -- Bounds the memory accesses and the execution of a subprogram -- using arithmetic analysis of the effects of its instructions. -- -- It is assumed that all bounds that can be derived without -- arithmetic analysis are already entered in the execution -- bounds on entry; this includes asserted loop-bounds and -- asserted worst-case times for specific calls as well as -- bounds derived by other automatic analyses such as constant -- propagation. Only the remaining unresolved or unbounded parts -- of the subprogram are analysed here. -- -- Input parameters: -- -- Subprogram -- The subprogram to be subjected to arithmetic analysis. -- Call_Path -- A call path ending at the subprogram (for context-dependent -- analysis) or null (for universal analysis). If the call-path -- is not null, the Callee of the last element is Subprogram. -- Initial -- Initial bounds for some cells, valid on entry to the -- Subprogram, expressed in the subprogram's own frame (the -- callee frame when considering the last element on the -- Call_Path). -- Asserted -- Asserted bounds for some variables, valid throughout the -- execution of the Subprogram. -- Inherit_Inv -- Inherited set of invariant cells. -- Asserts -- Set of user-given assertions. -- Assert_Map -- Assertion map for the Subprogram and the Asserts set. -- Bounds_Set -- Set of execution bounds computer earlier. -- Exec_Bounds -- Execution bounds under construction for the Subprogram in -- this context. -- -- Output parameters: -- -- Subprogram -- The flow-graph may be extended with new loose edges, if -- the analysis was able to resolve some dynamic edges. -- Exec_Bounds -- Execution bounds for the Subprogram in this context, updated -- with new input/output/basis cell-sets from liveness analysis -- and new bounds from arithmetic analysis. -- Bounds_Set -- Set of execution bounds perhaps updated with context-specific -- bounds for the calls from the Subprogram to lower-level -- subprograms. -- -- The overall result can be classified as follows: -- -- New flow, when Dynamic_Flow (Exec_Bounds) = Growing -- -- The control-flow graph for Subprogram was extended by bounding -- dynamic edges. No attempt was made to bound loops or calls. -- The new flow should be traced to complete the flow-graph and -- then Bound_Execution should be called again. The present -- Exec_Bounds are out of date and should be discarded. -- -- New computation, when Computation_Changed (Exec_Bounds) -- -- The computation model in Exec_Bounds was updated / improved by -- bounding dynamic data references in "live" assignments or -- by bounding dynamic calling protocols in "live" calls to update -- the effect of the call-step. Dead assignments are retained -- unchanged (because they may "come alive" when more dynamic data -- references are resolved to cells). No attempt was made to bound -- loops or calls. Bound_With_Arithmetic should be called again, -- after constant propagation is applied to the new model. -- -- Finished (neither of the above) -- -- The computation model and flow-graph appear stable. An attempt -- was made to bound loops and calls; the results if any are in -- Exec_Bounds. -- is use type Storage.Cell_Set_T; use type Storage.Bounds.Cell_Interval_List_T; use type Flow.Step_List_T; -- Principles Of Operation -- -- There may be several boundable (dynamic) aspects in the -- subprogram and its callees that might become partly or fully -- bounded by arithmetic analysis. The first question is to -- decide in which order these aspects are tackled; the problem -- is that the analysis of one aspect may be hindered by the -- unboundedness of another aspect. For example, while a dynamic -- memory reference is unbounded it may have a wide alias-range; -- if the reference is the target of an assignment, the aliasing -- effect may hide the value of a loop-counter cell and thus -- hinder the bounding of a loop. -- -- No fixed order may be the best in all cases, and there may be -- a trade-off between orders that give a fast analysis and orders -- that give accurate bounds. -- -- To get the most accurate bounds we may have to resort to -- iteration in which each dynamic feature is repeatedly analysed -- in different data contexts that are more and more constrained -- by the analysis of the other dynamic features. However, the -- iteration loop is external to Bound_With_Arithmetic because -- each iteration round begins with a constant-propagation phase. -- -- At present, the following order is applied in each round of -- iteration. This order favours precision over speed: -- -- 1. Refine the computation model by trying to bound the -- dynamic data references and dynamic calling protocols. -- When a dynamic calling protocol is bounded, the effect -- of the call is also refined. -- -- If the computation model changes, the next steps are skipped -- and a new iteration round starts (with constant propagation). -- If the computation model is stable we go on to step 2: -- -- 2. Try to bound dynamic control-flow edges (if any). -- -- If som dynamic edge is successfully bounded and the control-flow -- graph grows, the iteration (on the original flow-graph) is stopped -- and we return to tracing the new flow to complete the flow-graph. -- -- Otherwise (dynamic flow fully resolved or cannot be resolved -- further) we go on to steps 3 and 4: -- -- 3. Bound the loops and calls. -- -- 4. Bound the stack heights and stack usage. -- -- A future redesign of the arithmetic analysis to use slicing -- instead of Pool_To_Steps will have to reconsider the order; -- perhaps a flow order would be better than an order based on -- the type of the dynamic feature. -- -- -- The present analysis uses Calculator.Pool_To_Steps in a global -- way which means that we first collect a list of all the steps -- that contain some boundable features, use Pool_To_Steps to -- find the data flux into each of these steps, and then analyse -- these fluxes in the order described above. -- Get subprogram data: Program : constant Programs.Program_T := Programs.Execution.Program (Exec_Bounds); -- The program under analysis. Graph : Flow.Graph_T := Programs.Flow_Graph (Subprogram); -- The flow-graph of this subprogram. Model : constant Flow.Computation.Model_Handle_T := Programs.Execution.Computation (Exec_Bounds); -- The given (input) computation model. Feasible_Loops : constant Loops.Loop_List_T := Flow.Computation.Loops_Of (Model.all); -- The feasible loop-structure of this subprogram. -- Some or all of these loops may already have bounds. -- Get assertion data: Asserted_Inv : constant Storage.Cell_Set_T := Assertions.Subprogram_Invariants (Subprogram, Asserts); -- Subprogram-specific assertions on cell invariance. Local_Inv : constant Storage.Cell_Set_T := Storage.Mixed.Union (Inherit_Inv, Asserted_Inv); -- All invariant cells (inherited + specifically asserted). -- Get the unbounded features: Dyn_Edges : constant Flow.Dynamic_Edge_List_T := Flow.Computation.Unstable_Dynamic_Edges (Model.all); -- -- The edges with dynamically computed target address (indexed -- jumps) that are feasible under the given Model and have not -- been resolved into Growing or Stable states by earlier analyses -- of this Graph (in its present state). We will try to resolve -- these edges with arithmetic analysis. Unbounded_Calls : constant Programs.Call_List_T := Programs.Execution.Input_Dependent_Calls (Exec_Bounds); -- -- Those calls from this subprogram, to other subprograms, where -- the callee has some unbounded but desired aspects that may -- benefit from context-specific analysis (giving input parameter -- bounds) and where the call is feasible under the computation model. Take_Off_Calls : constant Programs.Call_List_T := Programs.Execution.Calls_With_Unbounded_Take_Off (Exec_Bounds); -- The calls from this subprogram, to other subprograms, where -- the take-off stack-height (in this subprogram) is not yet bounded -- and the total stack usage is not yet bounded. Dyn_Cond_Edges : constant Flow.Step_Edge_List_T := Opt_Edges_With_Dynamic_Condition (Model.all); -- -- The step-edges with preconditions that contain some unresolved -- dynamic data references, or a null list if arithmetic analysis -- is not applied to resolve such references. Living : Flow.Life.Living_T := Flow.Life.Live_Computation ( Model => Model, Calls => Programs.Execution.Call_Bounds (Exec_Bounds), Heights => Programs.Execution.Loose_Stack_Heights (Exec_Bounds), Finals => Programs.Execution.Loose_Final_Stack_Heights (Exec_Bounds), Asserts => Asserts, For_Time => Opt.Bound_Time, For_Space => Opt.Bound_Stack, For_Data => Arithmetic.Opt.Ref_Choice); -- -- The result of liveness analysis of the given Model, showing -- which assignments are "live" in the Model, that is, which -- assignments influence interesting cells and expressions. -- Also shows the input, basis, and output cells. -- -- This may be redundant work, if the liveness is not affected by -- the call-dependent analysis or the (call-dependent) analysis -- of the callees. Inputs : constant Calculator.Cell_Set_T := Calculator.Copy (Flow.Life.Inputs (Living)); -- The Inputs may not contain all input cells for (unbounded) -- calls, because Flow.Life considers such cells relevant only if -- they are assigned in this subprogram or are outputs from calls -- in this subprogram. We will add them TBC, but later on, because we -- hope to bound some of these unbounded calls and this can reduce -- the input-cell set. Basis : constant Calculator.Cell_Set_T := Calculator.Copy (Flow.Life.Basis (Living)); Outputs : constant Calculator.Cell_Set_T:= Calculator.Copy (Flow.Life.Outputs (Living)); -- Gather the "interesting" steps: Jump_Steps : constant Flow.Step_List_T (Dyn_Edges'Range) := Flow.Sources (Dyn_Edges); -- The source-steps of the dynamic edges. -- If a step is the source of more than one dynamic edge, the -- step occurs as many times in this list. Call_Steps : constant Flow.Step_List_T (Unbounded_Calls'Range) := Programs.Steps (Unbounded_Calls); -- The steps that contain the unbounded calls. Stack_Steps : constant Flow.Step_List_T := Programs.Execution.Unbounded_Stack_Steps (Exec_Bounds); -- The steps that change some stack pointer, in case the -- total stack usage has not already been bounded and space -- analysis is requested. Also all final (return) steps, if -- some final stack height is not yet known. Take_Off_Steps : constant Flow.Step_List_T (Take_Off_Calls'Range) := Programs.Steps (Take_Off_Calls); -- The steps that contain the calls with unbounded take-off height, -- for stacks where the total usage is not yet bounded. Effect_Steps : constant Flow.Step_List_T := Opt_Steps_With_Dynamic_Effect (Living); -- The steps that have effects that contain dynamic data references, -- perhaps selected depending on where they occur, or a null list -- if arithmetic analysis is not applied to resolve such references. Cond_Steps : constant Flow.Step_List_T := Flow.Sources (Edges => Dyn_Cond_Edges, Unique => True); -- The source-steps of the edges that have preconditions that -- contain dynamic data references, with each source-step listed -- only once even if it is the source of several such edges. Interest : constant Flow.Step_List_T := Jump_Steps & Call_Steps & Stack_Steps & Take_Off_Steps & Effect_Steps & Cond_Steps; -- -- The set of "interesting" steps contains those steps of the -- (original) flow-graph. Loop-head steps are not included because -- they are handled separately. Jump_First : constant Positive := Interest'First; -- Interest(Jump_First) is the first of the Jump_Steps. Call_First : constant Positive := Jump_First + Jump_Steps'Length; -- Interest(Call_First) is the first of the Call_Steps. Stack_First : constant Positive := Call_First + Call_Steps'Length; -- Interest(Stack_First) is the first of the Stack_Steps. Take_Off_First : constant Positive := Stack_First + Stack_Steps'Length; -- Interest(Take_Off_First) is the first of the Take_Off_Steps. Effect_First : constant Positive := Take_Off_First + Take_Off_Steps'Length; -- Interest(Effect_First) is the first of the Effect_Steps. Cond_First : constant Positive := Effect_First + Effect_Steps'Length; -- Interest(Cond_First) is the first of the Cond_Steps. Jump_Off : constant Integer := Jump_First - Jump_Steps'First; -- Jump_Steps(J) corresponds to Interest(J + Jump_Off). Call_Off : constant Integer := Call_First - Call_Steps'First; -- Call_Steps(C) corresponds to Interest(C + Call_Off). Stack_Off : constant Integer := Stack_First - Stack_Steps'First; -- Stack_Steps(S) corresponds to Interest(S + Stack_Off). Take_Off_Off : constant Integer := Take_Off_First - Take_Off_Steps'First; -- Take_Off_Steps(T) corresponds to Interest(T + Take_Off_Off). Effect_Off : constant Integer := Effect_First - Effect_Steps'First; -- Effect_Steps(E) corresponds to Interest(E + Effect_Off). Cond_Off : constant Integer := Cond_First - Cond_Steps'First; -- Cond_Steps(C) corresponds to Interest(C + Cond_Off). -- Arithmetic analysis stuff: Calc : Calculator.Calc_Handle_T; -- The calculator we use (and start, and stop). Root_Pool : Calculator.Pool_T; -- The root data-pool into the subprogram as the combination of -- the given Initial parameter bounds and the Asserted bounds. Exit_Pool : Calculator.Pool_T; -- The exit data-pool of the subprogram. Summary : Calculator.Loop_Summary_List_T (Feasible_Loops'Range); -- The summary effect of each loop body (flux on the repeat -- edges, set of invariant cells). Loop_Init : Calculator.Pool_List_T (Feasible_Loops'Range); -- The initializing data-pool into each loop, without the assertions. Loop_Repeat : Calculator.Flux_List_T (Feasible_Loops'Range); -- The repeat flux of each loop, without the assertions but with -- knowledge of the range of Loop_Init and Summary.Repeat, ie. the -- improved repeat flux from Calculator.Pool_To_Steps. Into_Interest : Calculator.Pool_List_T (Interest'Range); -- The data-pool into each interesting step. function Assertion_Constrained_Flux ( Flux : Calculator.Flux_T; Step : Flow.Step_T) return Calculator.Flux_T -- -- Constrains the flux by the Asserted bounds, by all the -- assertions on the nested loops that contain the step, and -- by any Range_Pre assignment constraints in the step itself. -- is begin return Nesting_Bounded_Flux ( Step => Step, Flux => Calculator.Range_Bounded_Flux ( Flux => Flux, Bounds => Storage.Bounds.Cell_Intervals ( From => Asserted, Point => Flow.Prime_Address (Step))), Living => Living, Luups => Feasible_Loops, Asserts => Assert_Map); end Assertion_Constrained_Flux; function Assertion_Constrained_Pool ( Pool : Calculator.Pool_T; Step : Flow.Step_T) return Calculator.Pool_T -- -- Constrains the Pool by the assertion-pool, by all the -- assertions on the nested loops that contain the step, and -- by any Range_Pre assignment constraints in the step itself. -- is begin return Nesting_Bounded_Pool ( Step => Step, Pool => Calculator.Bounded_Pool ( Pool => Pool, Bounds => Storage.Bounds.Cell_Intervals ( From => Asserted, Point => Flow.Prime_Address (Step))), Living => Living, Luups => Feasible_Loops, Asserts => Assert_Map); end Assertion_Constrained_Pool; procedure Resolve_Data ( Step : in Flow.Step_T; Pool : in Calculator.Pool_T) -- -- Tries to resolve the dynamic data references in the effect of -- the given Step using, as bounds, the calculated data-Pool into -- the Step. -- -- A dynamic data reference is analysed here if the reference -- occurs in an assignment where -- -- > the assignment is "live", or -- -- > the target is a dynamic data reference. -- -- TBM in the last case to consider only assignments where the -- target may alias with some live/desired cells, including inputs -- to calls. -- -- However, under the option "-arith_ref all" we analyse all -- dynamic data references. -- is use type Arithmetic.Effect_Ref; use type Arithmetic.Expr_Kind_T; use type Arithmetic.Opt.Ref_Choice_T; All_Refs : constant Boolean := Arithmetic.Opt.Ref_Choice = Arithmetic.Opt.All_Item; -- Whether all dynamic refs should be analysed. Step_Mark : Output.Nest_Mark_T; -- For the output locus of the step. Effect : Arithmetic.Effect_T := Flow.Computation.Effect (Step, Model.all); -- The given effect of the Step, under the given model. -- Contains both live and dead assignments. Refs_Bounded : Boolean := False; -- Whether some of the dynamic references in Effect were bounded. One_Ref_Bounded : Boolean; -- Whether one or more dynamic references in the current assignment -- in Effect was bounded. Valid_Pool : Calculator.Pool_T; -- The given Pool constrained with assertions and with -- the Range_Pre assignment constraints in the effect -- of the Step. begin Step_Mark := Output.Nest ( Flow.Show.Locus (Step, Programs.Symbol_Table (Program))); Calculator.Comment ( Text => "Resolving data in step" & Flow.Step_Index_T'Image (Flow.Index (Step)) & " at " & Flow.Image (Flow.Tag (Step)), Calc => Calc); Valid_Pool := Assertion_Constrained_Pool (Pool, Step); -- Try to bound the references in "live" assignments: for E in Effect'Range loop if All_Refs or else ( Effect(E).Target.Kind = Arithmetic.Ref or Flow.Life.Is_Live ( Item => E, Effect => Effect, Step => Step, Living => Living)) then -- Effect(E) is a "live" assignment or has a dynamic -- reference as the target, or we shall analyse all -- dynamic references. Arithmetic.Bound_References ( Within => Effect(E), Bounds => Valid_Pool, Bounded => One_Ref_Bounded); Refs_Bounded := Refs_Bounded or One_Ref_Bounded; end if; end loop; -- Was something bounded? if Refs_Bounded then -- The effect was resolved / refined. if Opt.Trace_Data_Resolution then Output.Trace ( "Effect resolved to " & Arithmetic.Image (Effect)); end if; Flow.Computation.Set_Effect ( Step => Step, To => new Arithmetic.Effect_T'(Effect), Under => Model.all); end if; Output.Unnest (Step_Mark); exception when Flow.False_Path | Calculator.Null_Set_Error => -- Cannot reach this Step in this Model. Output.Note ( "Step #" & Flow.Step_Index_T'Image (Flow.Index (Step)) & " is infeasible (for data refs)."); Mark_Unreachable (Step, Model); Output.Unnest (Step_Mark); when others => Output.Fault ( Location => "Bounds.Bound_With_Arithmetic.Resolve_Data", Text => "Exception propagated."); Output.Unnest (Step_Mark); raise; end Resolve_Data; procedure Resolve_Edge_Cond ( Step : in Flow.Step_T; Pool : in Calculator.Pool_T) -- -- Tries to resolve the dynamic data references in the preconditions -- of edges leaving the given Step using, as bounds, the calculated -- data-Pool into the Step transformed by the effect of the step. -- -- The given Pool parameter is the data-pool into the Step. The effect -- of the Step is here applied to Pool to give the pool (bounds) for -- the edges from the Step. In principle, the precondition of each edge -- also bounds the dynamic references in the precondition itself; -- for example, the precondition could have the form "v = 5 and -- Memory[v] > 22", resolving to "v = 5 and Memory[5] > 22". This -- principle is not used yet. -- is use type Arithmetic.Condition_T; use type Flow.Step_T; Step_Mark : Output.Nest_Mark_T; -- For the output locus of the step. Cond_Pool : Calculator.Pool_T; -- The data-pool after the Step, into the edge preconditions, -- and constrained by all assertions. Edge : Flow.Step_Edge_T; -- One of the Dyn_Cond_Edges. Old_Cond : Arithmetic.Condition_T; -- The given (old) precondition of the Edge. New_Cond : Arithmetic.Condition_T; -- The new precondition, or perhaps the old one unchanged. begin Step_Mark := Output.Nest ( Flow.Show.Locus (Step, Programs.Symbol_Table (Program))); Calculator.Comment ( Text => "Computing flux after step" & Flow.Step_Index_T'Image (Flow.Index (Step)) & " at " & Flow.Image (Flow.Tag (Step)), Calc => Calc); Cond_Pool := Calculator.Pool_After_Effect ( Pool => Assertion_Constrained_Pool (Pool, Step), Effect => Flow.Computation.Effect (Step, Model.all)); -- -- The above computation applies the Range_Pre assignment -- constraints twice, once in Assertion_Constrained_Pool and once -- in Pool_After_Effect. TBM if this becomes a problem. for D in Dyn_Cond_Edges'Range loop Edge := Dyn_Cond_Edges(D); if Flow.Source (Edge) = Step then -- This is an Edge from the Step, with some dynamic -- data references in its precondition. Old_Cond := Flow.Computation.Condition (Edge, Model.all); Calculator.Comment ( Text => "Resolving data in precondition of edge" & Flow.Step_Edge_Index_T'Image (Flow.Index (Edge)), Calc => Calc); New_Cond := Arithmetic.Reference_Bounded ( Expr => Old_Cond, Bounds => Cond_Pool); if New_Cond /= Old_Cond then -- The precondition was resolved / refined. Flow.Computation.Set_Condition ( On => Edge, To => New_Cond, Under => Model.all); if Opt.Trace_Data_Resolution then Output.Trace ( "Edge condition resolved from " & Arithmetic.Image (Old_Cond) & " to " & Arithmetic.Image (New_Cond)); end if; end if; end if; end loop; Output.Unnest (Step_Mark); exception when Flow.False_Path | Calculator.Null_Set_Error => -- Cannot reach this Step in this Model. Output.Note ( "Step #" & Flow.Step_Index_T'Image (Flow.Index (Step)) & " is infeasible (for data refs in conds)."); Mark_Unreachable (Step, Model); Output.Unnest (Step_Mark); when others => Output.Fault ( Location => "Bounds.Bound_With_Arithmetic.Resolve_Edge_Cond", Text => "Exception propagated."); Output.Unnest (Step_Mark); raise; end Resolve_Edge_Cond; procedure Resolve_Protocol ( Call : in Programs.Call_T; Step : in Flow.Step_T; Pool : in Calculator.Pool_T) -- -- Tries to resolve (bound) the calling protocol in the given -- Call by using as bounds the calculated data-Pool into the -- call-Step. Does nothing if the protocol is already Static. -- is Valid_Pool : Calculator.Pool_T; -- The given Pool constrained with assertions and with -- the Range_Pre assignment constraints in the effect of -- the Step. Bounded : Boolean; -- Whether the protocol was bounded. begin if not Flow.Computation.Calling_Protocol_Is_Static (Call, Model.all) then -- The calling protocol is dynamic. Calculator.Comment ( Text => "Resolving protocol in call " & Programs.Image (Call) & " at " & Flow.Image (Flow.Tag (Step)), Calc => Calc); Valid_Pool := Assertion_Constrained_Pool (Pool, Step); -- Try to bound the protocol: Bounds.Calling.Bound_Protocol ( Call => Call, Data => Valid_Pool, Model => Model.all, Bounded => Bounded); -- -- May propagate Flow.False_Path. -- if Bounded then: -- The protocol was refined or constrained in some way. -- This may change the effect of the call may change, so -- we have a (possibly) new computation model. -- This is seen as Computation_Changed (Exec_Bounds). end if; exception when Flow.False_Path => -- Cannot reach this Call in this Model. Output.Note ( Locus => Programs.Locus (Call), Text => "Call in step #" & Flow.Step_Index_T'Image (Flow.Index (Step)) & " is infeasible (for protocol)."); Mark_Unreachable (Step, Model, "call"); end Resolve_Protocol; procedure Resolve_Flow ( Edge : in out Flow.Boundable_Edge_T'Class; Pool : in Calculator.Pool_T) -- -- Tries to resolve the given dynamic Edge using, as bounds, the -- calculated data-Pool into the source-step of the Edge. -- is Source : constant Flow.Step_T := Flow.Source (Edge); -- The source step of Edge. Step_Mark : Output.Nest_Mark_T; -- For the output locus of the Source step. Valid_Pool : Calculator.Pool_T; -- The given Pool constrained with assertions and with -- the Range_Pre assignment constraints in the effect of -- the Source step. begin Step_Mark := Output.Nest ( Flow.Show.Locus ( Step => Source, Source => Programs.Symbol_Table (Program))); Calculator.Comment ( Text => "Resolving dynamic edge from step" & Flow.Step_Index_T'Image (Flow.Index (Source)) & " at " & Flow.Image (Flow.Tag (Source)), Calc => Calc); Valid_Pool := Assertion_Constrained_Pool (Pool, Source); Flow.Mark_Domain (Edge); Flow.Apply ( Bounds => Valid_Pool, Upon => Edge, Graph => Graph); -- -- The results are possible new edges in the Graph and -- a possible change in state of the Dyn_Edge, to be -- checked later with Flow.Computation.Dynamic_Flow or -- Programs.Execution.Dynamic_Flow. Output.Unnest (Step_Mark); exception when Flow.False_Path | Calculator.Null_Set_Error => Output.Note ( "Step #" & Flow.Step_Index_T'Image (Flow.Index (Source)) & " is infeasible (as source of dynamic edges)."); Mark_Unreachable (Step => Source, Model => Model); Output.Unnest (Step_Mark); when others => Output.Fault ( Location => "Bounds.Bound_With_Arithmetic.Resolve_Flow", Text => "Exception propagated."); Output.Unnest (Step_Mark); raise; end Resolve_Flow; procedure Bound_Loop ( Luup : in Loops.Loop_T; Init : in Calculator.Pool_T; Invariant : in Calculator.Cell_Set_T; Repeat : in Calculator.Flux_T) -- -- Bounds the Luup using the Initializing data-pool into the Luup, -- the Invariant cells of the Luup, the Repeat flux of the Luup, -- and assertions. -- -- Luup -- A feasible, unbounded loop. -- Init -- The data-pool into the Luup from outside the loop (initialisation -- pool). -- Invariant -- The cells that are invariant in the Luup. -- Repeat -- The (improved) repeat-flux of the Luup. -- is Loop_Mark : Output.Nest_Mark_T; -- Marks the default Output locus for the Luup. Head_Step : Flow.Step_T; -- The head step of the loop. Into_Loop : Calculator.Pool_T; -- The Init pool constrained with the assertion pool and the -- assertions on outer loops and the loop itself. Repeat_Loop : Calculator.Flux_T; -- The Repeat flux constrained with the assertion pool and the -- assertions on outer loops and the Luup itself. begin Loop_Mark := Output.Nest ( Loops.Show.Locus ( Luup => Luup, Within => Graph, Source => Programs.Symbol_Table (Program))); Head_Step := Loops.Head_Step (Luup); Calculator.Comment ( Text => "Bounding loop" & Loops.Loop_Index_T'Image (Loops.Loop_Index (Luup)), Calc => Calc); Calculator.Comment ( Text => "Assertion-constrain Into", Calc => Calc); Into_Loop := Assertion_Constrained_Pool ( Pool => Init, Step => Head_Step); Calculator.Comment ( Text => "Assertion-constrain Repeat", Calc => Calc); Repeat_Loop := Assertion_Constrained_Flux ( Flux => Repeat, Step => Head_Step); Bounds.Looping.Bound_Loop ( Luup => Luup, Initial => Into_Loop, Repeat => Repeat_Loop, Repeat_Inv => Invariant, Inherit_Inv => Local_Inv, Exec_Bounds => Exec_Bounds); Output.Unnest (Loop_Mark); end Bound_Loop; procedure Bound_Call ( Call : in Programs.Call_T; Step : in Flow.Step_T; Pool : in Calculator.Pool_T) -- -- Bounds the Call using the Pool into the call-Step and assertions. -- is Into_Call : Calculator.Pool_T; -- The pool into the Call, constrained with the assertion -- pool and the assertions on loops that contain the call step. Call_Mark : Output.Nest_Mark_T; -- Marks the default Output locus for the Call. begin Call_Mark := Output.Nest (Programs.Locus (Call_Path & Call)); Calculator.Comment ( Text => "Assertion-constrain Into for " & Programs.Image (Call), Calc => Calc); Into_Call := Assertion_Constrained_Pool (Pool, Step); Bounds.Calling.Bound_Call ( Call => Call, Caller_Bounds => Exec_Bounds, Data => Into_Call, Inherit_Inv => Local_Inv, Asserts => Asserts, Assert_Map => Assert_Map, Bounds_Set => Bounds_Set); Output.Unnest (Call_Mark); end Bound_Call; function Unbounded_Loops return Natural -- -- The number of unbounded Feasible_Loops. -- is Num : Natural := 0; begin for L in Feasible_Loops'Range loop if not Programs.Execution.Bounded ( Luup => Feasible_Loops(L), Within => Exec_Bounds) then Num := Num + 1; end if; end loop; return Num; end Unbounded_Loops; procedure Bound_Time_And_Space -- -- Tries to bound all unbounded loops and Unbounded_Calls, assuming that -- dynamic flow and data-access has been stably resolved (or failed to -- be resolved). Then tries to bound local stack height and total stack -- usage. -- -- As a side effect, some parts of the computation model may be marked -- infeasible (unreachable) and the model may then be pruned. This is -- not reported in any output parameter. -- is Into_Stack_Steps : Calculator.Pool_List_T (Stack_Steps'Range); -- The pool into each step that changes the stack pointer. Into_Take_Off : Calculator.Pool_List_T (Take_Off_Steps'Range); -- The pool into each call-step that has an unbounded take-off. begin -- Bound the loops if time-bounds are desired: if Opt.Bound_Time then for L in Feasible_Loops'Range loop if not Programs.Execution.Bounded ( Luup => Feasible_Loops(L), Within => Exec_Bounds) then Bound_Loop ( Luup => Feasible_Loops(L), Init => Loop_Init(L), Invariant => Summary(L).Invariant, Repeat => Loop_Repeat(L)); end if; end loop; end if; -- Bound the calls: for C in Unbounded_Calls'Range loop Bound_Call ( Call => Unbounded_Calls(C), Step => Call_Steps(C), Pool => Into_Interest(C + Call_Off)); end loop; -- Bound the stack usage if desired: if Opt.Bound_Stack then for S in Stack_Steps'Range loop Into_Stack_Steps(S) := Into_Interest(S + Stack_Off); end loop; for T in Take_Off_Steps'Range loop Into_Take_Off(T) := Into_Interest(T + Take_Off_Off); end loop; Bounds.Stacking.Bound_Local_Stack_Height ( Stack_Steps => Stack_Steps, Into_Stack_Steps => Into_Stack_Steps, Exec_Bounds => Exec_Bounds); Bounds.Stacking.Bound_Take_Off_Height ( Calls => Take_Off_Calls, Into_Calls => Into_Take_Off, Exec_Bounds => Exec_Bounds); end if; end Bound_Time_And_Space; begin -- Bound_With_Arithmetic if Opt.Trace_Arith then Output.Trace ( "Arithmetic analysis starts for" & Natural'Image (Interest'Length) & " nubs," & Natural'Image (Unbounded_Loops) & " unbounded loops, and" & Flow.Step_Index_T'Image (Flow.Max_Step (Graph)) & " steps."); Output.Trace ( "Initial bounds" & Output.Field_Separator & Storage.Bounds.Image (Initial)); Output.Trace ( "Asserted bounds" & Output.Field_Separator & Storage.Bounds.Image (Asserted)); Output.Trace ( "Inherited invariant cells" & Output.Field_Separator & Storage.Image (Inherit_Inv)); end if; -- First show the "interesting" steps if desired: if Opt.Trace_Nubs then Trace_Nubs ("Jump" , Jump_Steps , Program); Trace_Nubs ("Call" , Call_Steps , Program); Trace_Nubs ("Stack" , Stack_Steps , Program); Trace_Nubs ("Take_Off", Take_Off_Steps, Program); Trace_Nubs ("Effect" , Effect_Steps , Program); Trace_Nubs ("Cond" , Cond_Steps , Program); end if; -- Then analyse: if Opt.Trace_Arith then Output.Trace ( "Arithmetic basis contains" & Natural'Image (Flow.Life.Basis_Size (Living)) & " storage cells" & Output.Field_Separator & Calculator.Image (Basis)); end if; if Flow.Life.Basis_Size (Living) = 0 then -- No arithmetic cells seem relevant to the unbounded -- parts of this subprogram. We have no arithmetic to -- analyse. Output.Warning ("No relevant arithmetic to be analysed."); -- These bounds are as good as they get, for this context. Set_IO_Cells ( Inputs => Inputs, Outputs => Outputs, Basis => Basis, Within => Exec_Bounds); -- No change to flow-graph or computation model, so -- we are finished. else -- Some arithmetic cells seem relevant to the unbounded -- parts of this subprogram. -- Start a calculator for the arithmetic analysis: Calc := Calculator.Start (Comment_Text => Programs.Name (Subprogram) & ", on path " & Programs.Image (Call_Path)); -- Define the root data-pool into the subprogram: Root_Pool := Calculator.Bounded_Pool ( Cells => Basis, Bounds => Initial and Storage.Bounds.Cell_Intervals ( From => Asserted, Point => Programs.Entry_Address (Subprogram)), Calc => Calc); -- Approximate the loops using a context-free classification -- of cells into loop-invariants and loop-variants, for -- each loop: Loops.Slim.Approximate_Loops ( Living => Living, Loops => Feasible_Loops, Inherit_Inv => Local_Inv, Asserts => Assert_Map, Basis => Basis, Calc => Calc, Summaries => Summary); if Opt.Trace_Arith then Output.Trace ("Arithmetic loop-approximation done."); end if; -- Calculate all the fluxes that arrive at the interesting steps, -- and also the initial loop values for each unbounded loop: -- Note that the decoding process is required to place dynamic -- accesses and subprogram calls in steps so that the value of -- the dynamic indices, or the parameter values of the call, can -- be read from the flux that arrives at the step before executing -- the effect of the step. -- -- An exception are the dynamic data accesses in edge preconditions. -- These depend on the flux after the step, including the effect of -- the step. This modification is implemented in Resolve_Edge_Cond. -- -- For the loop-heads, the values of interest here are the -- initial values of the counter-candidates and invariants, -- which can be read from the flux that arrives at the head -- step (not including repeat edges). Calculator.Pool_To_Steps ( Nodes => (1 => Flow.Entry_Node (Graph)), Edges => Flow.Computation.Feasible ( Edges => Loops.Forward_Edges ( Within => Graph, Avoiding => Programs.Loops_Of (Subprogram)), Under => Model.all), Living => Living, Root => Root_Pool, Luups => Feasible_Loops, Summaries => Summary, Steps => Interest, Into_Luups => Loop_Init, Repeats => Loop_Repeat, Into_Steps => Into_Interest, Exit_Pool => Exit_Pool); if Opt.Trace_Arith then Output.Trace ("Arithmetic flow propagated to steps."); end if; -- Try to resolve the dynamic data accesses (step 1): case Arithmetic.Opt.Ref_Choice is when Arithmetic.Opt.None => if Opt.Trace_Arith then Output.Trace ( "Arithmetic not applied to dynamic data refs or edge conds."); end if; when Arithmetic.Opt.Relevant | Arithmetic.Opt.All_Item => for E in Effect_Steps'Range loop Resolve_Data ( Step => Effect_Steps(E), Pool => Into_Interest(E + Effect_Off)); end loop; if Opt.Trace_Arith then Output.Trace ("Arithmetic applied to dynamic data refs."); end if; for C in Cond_Steps'Range loop Resolve_Edge_Cond ( Step => Cond_Steps(C), Pool => Into_Interest(C + Cond_Off)); end loop; if Opt.Trace_Arith then Output.Trace ("Arithmetic applied to dynamic edge conds."); end if; end case; -- Try to resolve the dynamic calling protocols: for C in Unbounded_Calls'Range loop Resolve_Protocol ( Call => Unbounded_Calls(C), Step => Call_Steps(C), Pool => Into_Interest(C + Call_Off)); end loop; if Opt.Trace_Arith then Output.Trace ("Arithmetic applied to dynamic protocols."); end if; if Flow.Computation.Changed (Model.all) then -- Some data references in the computation model were -- successfully bounded and changed, or some parts of the -- subprogram were found to be unreachable (infeasible), -- so we abandon this arithmetic analysis and start over -- with the new computation model. Output.Note ("Arithmetic analysis changed computation model."); else -- The computation model appears stable for this flow-graph. -- Try to resolve the dynamic flow (step 2): for J in Jump_Steps'Range loop Resolve_Flow ( Edge => Dyn_Edges(J).all, Pool => Into_Interest(J + Jump_Off)); end loop; if Opt.Trace_Arith then Output.Trace ("Arithmetic applied to dynamic jumps."); end if; -- Is the flow graph still growing? case Flow.Computation.Dynamic_Flow (Model.all) is when Flow.Growing => -- Some dynamic edge(s) were resolved and the flow-graph is -- still growing. It is not useful to try to bound loops or -- calls yet, since the flow-graph will be changed and so will -- the computed data flow. null; when Flow.Unresolved | Flow.Stable => -- All dynamic edges resolved stably, or left unresolved. -- The flow-graph is as complete as we can make it. -- The real work of bounding time and space: Bound_Time_And_Space; -- -- This may find that some loops or calls are unreachable -- (infeasible), which could be a reason for a new iteration -- of the analysis. However, we stop here. -- These bounds are as good as they get, for this context. Set_IO_Cells ( Inputs => Inputs, Outputs => Outputs, Basis => Basis, Within => Exec_Bounds); end case; end if; -- This concludes the data-flow calculations for this iteration. -- If the flow-graph was extended when dynamic jumps were resolved, -- or the arithmetic effects were updated when dynamic data accesses -- were resolved, this subprogram will be reanalysed using a new -- calculator instance on the new flow-graph and/or new computation -- model. -- -- If the bounding of some loop failed, even after resolving data -- accesses, the bounding will be attempted again in the context -- of a more specific call-path. -- -- If the bounding of some call-specific callee failed, even after -- resolving data accesses, the bounding of this subprogram also -- becomes call-specific and will be attempted again in the context -- of calls from higher levels. if Opt.Trace_Arith then Output.Trace ("Arithmetic analysis done."); end if; Calculator.Stop (Calc); end if; -- We no longer need the Living object: Flow.Life.Discard (Living); end Bound_With_Arithmetic; procedure Bound_Without_Arithmetic ( Subprogram : in Programs.Subprogram_T; Call_Path : in Programs.Call_Path_T; Inherit_Inv : in Storage.Cell_Set_T; Asserts : in Assertions.Assertion_Set_T; Assert_Map : in Assertions.Assertion_Map_T; Bounds_Set : in Programs.Execution.Bounds_Set_T; Exec_Bounds : in Programs.Execution.Bounds_Ref) -- -- Bound a subprogram without arithmetic analysis. -- This essentially means setting the input and output -- cell-sets. -- is Model : constant Flow.Computation.Model_Handle_T := Programs.Execution.Computation (Exec_Bounds); -- The given (input) computation model. Unbounded_Calls : constant Programs.Call_List_T := Programs.Execution.Context_Dependent_Calls (Exec_Bounds); -- -- Those calls from this subprogram, to other subprograms, where -- the callee has some unbounded but desired aspects that may -- benefit from context-specific analysis and where the call is -- feasible under the computation model. -- TBA unbounded call protocols. Call : Programs.Call_T; -- One of the Unbounded_Calls. Call_Mark : Output.Nest_Mark_T; -- Locus for the Call. begin if Opt.Trace_Phase then Output.Trace ("Phase avoids arithmetic analysis."); end if; -- TBA unbounded protocols. for U in Unbounded_Calls'Range loop Call := Unbounded_Calls(U); Call_Mark := Output.Nest (Programs.Locus (Call_Path & Call)); Calling.Bound_Call ( Call => Call, Caller_Bounds => Exec_Bounds, Data => Assertions.Local_Call_Values (Call, Assert_Map), Inherit_Inv => Inherit_Inv, Asserts => Asserts, Assert_Map => Assert_Map, Bounds_Set => Bounds_Set); Output.Unnest (Call_Mark); end loop; Set_IO_Cells ( Inputs => Programs.Execution.Inputs_For_Unbounded_Calls (Exec_Bounds), Outputs => Flow.Computation.Cells_Defined (By => Model.all), Basis => Storage.List_Cell_Sets.Empty, Within => Exec_Bounds); -- The cells needed as inputs for bounding lower-level calls -- are probably not assigned in this subprogram, since this -- would require arithmetic analysis of this subprogram. -- Instead, values for these cells are (will be) passed across -- this subprogram in cell-bounds. end Bound_Without_Arithmetic; procedure Bound_As_Infeasible ( Exec_Bounds : in Programs.Execution.Bounds_Ref) -- -- Provide some (dummy) execution bounds for a subprogram that has -- been found to be infeasible (to have no feasible execution path) -- in the present context. -- -- The main purpose is to avoid irrelevant alarms from functions -- that access some attributes of the execution bounds and (without -- this operation) would find that undefined attributes. -- is use Storage.List_Cell_Sets; begin Set_IO_Cells ( Inputs => Empty, Outputs => Empty, Basis => Empty, Within => Exec_Bounds); end Bound_As_Infeasible; procedure Finish_Bounds ( Exec_Bounds : in Programs.Execution.Bounds_Ref; Assert_Map : in Assertions.Assertion_Map_T; Bounds_Set : in Programs.Execution.Bounds_Set_T; Flow_Frozen : out Boolean) -- -- Finishes the analysis of the Execution Bounds of a subprogram, -- where the subprogram is possibly still under construction by -- resolving dynamic control-flow constructs. There are two cases: -- -- > If the subprogram's flow-graph is still growing, because some -- dynamic edges were resolved by recent analysis giving and using -- these Execution Bounds, the bounds are discarded (because they -- will not apply to the extended flow-graph) and Flow_Frozen is -- returned as False. -- -- > If the subprogram's flow-graph is now stable, or could not be -- resolved further by the analysis giving and using these -- Execution Bounds, Flow_Frozen is returned as True and several -- finishing actions are applied to these bounds: -- -- o Report the end of decoding for this subprogram. -- o Remove all dynamic edges and report the unresolved ones. -- o Report unresolved data references (optional). -- o Invoke Decoder.Finish for universal execution bounds. -- o Evaluate the time-state and compute the stack usage. -- o Use value-origin analysis to find invariant cells etc. -- o Store these Execution Bounds in the Bounds_Set. -- -- Exec_Bounds -- The execution bounds to be finished and stored, if the -- flow-graph is stable, or discarded otherwise. -- Assert_Map -- The assertion map for these Execution Bounds. -- May be No_Map in some cases, for example when there is -- no feasible execution path in the subprogram. -- Bounds_Set -- The Execution Bounds are stored here, if Flow_Frozen. -- Flow_Frozen -- Shows if the flow-graph of this subprogram is completed, -- and whether the Execution Bounds were stored in Bounds_Set. -- is use Programs, Programs.Execution; use type Assertions.Assertion_Map_T; Graph : Flow.Graph_T := Flow_Graph (Exec_Bounds); -- The flow-graph of this subprogram. Feasible : Boolean; -- Whether the subprogram is feasible (has a feasible execution -- path) under these Exec_Bounds. begin -- Some ad-hoc internal checks: if Assert_Map /= Assertions.No_Map and then Assertions.Subprogram (Assert_Map) /= Subprogram (Exec_Bounds) then -- Oops. Output.Fault ( Location => "Bounds.Finish_Bounds", Text => "Subprograms differ for bounds and map"); -- The rest will be a mess. end if; case Dynamic_Flow (Exec_Bounds) is when Flow.Growing => -- Some dynamic edges were resolved into new real edges. -- The flow-graph is still growing; all execution bounds -- computed so far are incomplete and insufficient for the -- extended flow-graph. Therefore the bounds are not yet -- stored in the Bounds_Set. Output.Note ( "Dynamic flow not yet stable in bounds #" & Bounds_Index_T'Image (Index (Exec_Bounds))); Flow_Frozen := False; -- TBA discard Exec_Bounds as useless. when Flow.Unresolved | Flow.Stable => -- All dynamic flow is resolved as far as possible. -- This means, among other things, that the call-tree is -- now stable (but may be incomplete) and the execution -- bounds are valid for this context, although perhaps not -- fully bounded. -- Report and handle remaining unresolved dynamic flow and data: if Flow.Some_Dynamic_Edges (Graph) then -- The decoding was suspended to handle dynamic flow -- but is now finished, either with a stable resolution -- or with some unresolved dynamic flow. Decoder.Stop ( Program => Program (Exec_Bounds), Subprogram => Subprogram (Exec_Bounds), Graph => Graph, Suspended => False); end if; Flow.Computation.Show.Report_Unresolved_Flow ( Model => Computation (Exec_Bounds).all, Source => Symbol_Table (Exec_Bounds)); Flow.Remove_All_Dynamic_Edges (Graph); if Opt.Warn_Unresolved_Data then Flow.Computation.Show.Report_Unresolved_Data ( Model => Computation (Exec_Bounds).all, Source => Symbol_Table (Exec_Bounds)); end if; Feasible := Is_Feasible (Exec_Bounds); -- Perhaps "finish" and trace the flow-graph: if Level (Exec_Bounds) = Universal then -- The flow-graph has been completed on the universal level. -- We can let the Decoder apply any finishing touches it -- deems suitable: if Feasible then Decoder.Finish ( Program => Program (Exec_Bounds), Subprogram => Subprogram (Exec_Bounds), Graph => Graph, Assert_Map => Assert_Map); end if; -- Moreover, we may want to show the graph in detail: if Opt.Trace_Graphs then Flow.Show.Trace_Graph ( Graph => Graph, Source => Symbol_Table (Exec_Bounds)); end if; if Opt.Trace_Instructions then Programs.Show.Trace_Instructions_And_Branches ( Subprogram => Subprogram (Exec_Bounds)); end if; end if; Flow_Frozen := True; if Opt.Bound_Time then Timing.Evaluate_Time_State (Exec_Bounds); end if; if Opt.Bound_Stack then Stacking.Compute_Stack_Usage (Exec_Bounds); end if; -- Apply value-origin analysis to find obviously invariant -- cells etc. if not Feasible then Output.Note ("Infeasible subprogram, skip value-origin analysis."); else Programs.Execution.Bound_Value_Origins (Exec_Bounds); if Programs.Execution.Value_Origins_Defined (Exec_Bounds) then Programs.Execution.Remove_From_Output ( Cells => Flow.Origins.Overall_Invariants ( Map => Programs.Execution.Value_Origins (Exec_Bounds)), Within => Exec_Bounds); -- TBC do not apply Decoder Additional actions on value-origin map -- TBA update Subprogram_Effect -- TBA update Loop_Effect else Output.Note ("No value-origins for invariance analysis."); end if; end if; -- The execution bounds are stored with the subprogram, -- whether fully bounded or not: Store_Bounds ( Bounds => Exec_Bounds, Within => Bounds_Set); end case; end Finish_Bounds; procedure Report_Conflicting_Bounds ( Intervals : in Storage.Bounds.Cell_Interval_List_T; Message : in String; Conflict : in out Boolean) -- -- Checks the Intervals for void (empty) bounds on some cell, and -- reports them as Warnings under the Message heading. If some -- voids are found, sets Conflict to True. -- is begin for I in Intervals'Range loop if Storage.Bounds.Void (Intervals(I).Interval) then Conflict := True; Output.Warning ( Message & Output.Field_Separator & Storage.Bounds.Image (Intervals(I))); end if; end loop; end Report_Conflicting_Bounds; procedure Bound_Execution ( Exec_Bounds : in Programs.Execution.Bounds_Ref; Params : in Storage.Bounds.Cell_Interval_List_T; Inherit_Inv : in Storage.Cell_Set_T; Asserts : in Assertions.Assertion_Set_T; Bounds_Set : in Programs.Execution.Bounds_Set_T; Flow_Frozen : out Boolean) is use type Assertions.Assertion_Map_T; use type Flow.Edge_Resolution_T; use type Storage.Bounds.Cell_Interval_List_T; use type Storage.Bounds.Var_Interval_List_T; Subprogram : constant Programs.Subprogram_T := Programs.Execution.Subprogram (Exec_Bounds); -- The subprogram to be analysed. Entry_Address : constant Processor.Code_Address_T := Programs.Entry_Address (Subprogram); -- The code address of the subprogram entry point. Call_Path : constant Programs.Call_Path_T := Programs.Execution.Call_Path (Exec_Bounds); -- The context for the analysis. -- Collect asserted and inherited bounds on cells: Assumed_Initials : constant Storage.Bounds.Cell_Interval_List_T := Programs.Unstable_Stack_Heights_Zero (Programs.Program (Subprogram)); -- The initial local stack height for any Unstable stack is -- assumed (axiomatically) to be zero. Global_Bounds : constant Storage.Bounds.Var_Interval_List_T := Assertions.Global_Values (Asserts); -- Globally asserted bounds on cells, valid throughout -- the subprogram. Sub_Bounds : constant Storage.Bounds.Var_Interval_List_T := Assertions.Subprogram_Values (Subprogram, Asserts); -- Subprogram-specific asserted bounds on cells, valid -- throughout the subprogram. Global_Inputs : constant Storage.Bounds.Cell_Interval_List_T := Storage.Bounds.Cell_Intervals (Global_Bounds, Entry_Address); -- Globally asserted bounds as they apply to cells on entry. Sub_Inputs : constant Storage.Bounds.Cell_Interval_List_T := Storage.Bounds.Cell_Intervals (Sub_Bounds, Entry_Address); -- Whole-subprogram asserted bounds as they apply to cells on entry. Dec_Bounds : constant Storage.Bounds.Cell_Interval_List_T := Processor.Properties.Entry_Bounds ( Subprogram => Subprogram, Sub_Info => Programs.Processor_Info (Subprogram)); -- Bounds that the decoder knows hold on entry. -- This defines the initial local stack height for Stable stacks. Input_Bounds : constant Storage.Bounds.Cell_Interval_List_T := Assertions.Subprogram_Inputs (Subprogram, Asserts); -- Subprogram-specific bounds that hold on entry, for any -- call, and can apply to parameters or global input cells. Generic_Bounds : constant Storage.Bounds.Cell_Interval_List_T := Assumed_Initials and Global_Inputs and Sub_Inputs and Dec_Bounds and Input_Bounds; -- -- The generic (not call-path dependent) cell-bounds on -- entry to the subprogram. Initial_Bounds : constant Storage.Bounds.Cell_Interval_List_T := Params and Generic_Bounds; -- -- All initial cell-bounds on entry to the subprogram, -- including the call-path dependent parameter bounds. -- Other locals: Bounds_Void : Boolean := False; -- Whether some input bounds / assertions conflict, giving -- a void value interval for some cells. Model : Flow.Computation.Model_Handle_T; -- The computation model used and updated. Assert_Map : Assertions.Assertion_Map_T; -- The assertions mapped to this subprogram. -- May be null, when the subprogram is found to be infeasible -- before assertions are mapped onto it. Valid_Map : Boolean; -- Whether the Assert_Map is valid, in terms of actual match -- tallies conforming to expected populations, etc. Arithmetic_Chosen : Boolean; -- Whether arithmetic analysis is chosen, either because it is -- required by the structure of the subprogram and shortcomings -- in the bounds from lower levels and from assertions, or -- because it is enforced by option or assertion. procedure Check_Feasibility -- -- Checks if the execution-count bounds are still (possibly) -- feasible, and marks the exec-bounds as infeasible otherwise. -- is begin if not Programs.Execution.Flow_Bounds_Feasible (Exec_Bounds) then Output.Warning ( "Contradictory assertions make execution infeasible."); Programs.Execution.Mark_Infeasible (Exec_Bounds); end if; end Check_Feasibility; procedure Apply_Instruction_Count_Assertions -- -- Applies the assertions on the number of repetitions of -- specific instructions. This may make some parts of the -- underlying flow-graph infeasible. -- is begin Programs.Execution.Bound_Node_Counts ( By => Assertions.Instruction_Counts ( Subprogram => Subprogram, Model => Model, Asserts => Asserts), Within => Exec_Bounds); Check_Feasibility; Programs.Execution.Prune_Flow (Exec_Bounds); end Apply_Instruction_Count_Assertions; procedure Apply_Assertions -- -- Locates and uses the assertions on this subprogram to bound -- as much as possible. -- is begin Assertions.Identify_Assertions ( Model => Model, Assertion_Set => Asserts, Assertion_Map => Assert_Map); -- -- The assertion mapping can depend on the call-path -- through different dynamic memory accesses (uses/defines -- characteristics) and TBA path-specific assertions. -- TBA: include Model parameter to show feasible parts and -- sharpen uses/defines for dynamic references. Programs.Execution.Bound_Assertions ( Map => Assert_Map, Within => Exec_Bounds); -- Use the asserted loop-start bounds (on potentially all loops): Bounds.Looping.Bound_Asserted_Starts ( Luups => Loops.All_Loops (Programs.Loops_Of (Subprogram)), Asserts => Assert_Map, Exec_Bounds => Exec_Bounds); -- Use the asserted repetition bounds on loops (only for loops -- that are feasible, feasibly repeatable, and not yet bounded): Bounds.Looping.Bound_Asserted_Repeats ( Luups => Programs.Execution.Unbounded_Loops ( Within => Exec_Bounds, Eternal => True), Asserts => Assert_Map, Exec_Bounds => Exec_Bounds); -- Use the asserted bounds and other assertions on calls: Bounds.Calling.Bound_Asserted_Calls ( Calls => Flow.Computation.Calls_From (Model.all), Assert_Map => Assert_Map, Caller_Bounds => Exec_Bounds, Bounds_Set => Bounds_Set); Check_Feasibility; end Apply_Assertions; procedure Mark_Abnormal_Calls -- -- If a call within the given Exec_Bounds has execution bounds -- under which the callee is infeasible, this procedure marks -- the call as infeasible in the computation model of the caller. -- Likewise, if a call within the given Exec_Bounds has execution -- bounds under which the callee never returns to the caller, this -- procedure marks the call as "non-returning" in the computation -- model. -- -- Both actions can change the (in)feasibility of some parts of -- the flow-graph. The flow-graph is then pruned. -- is Calls : constant Programs.Execution.Call_Bounds_List_T := Programs.Execution.Call_Bounds (Exec_Bounds); -- All calls and their possibly context-dependent execution -- bounds. Includes only calls that are (still) considered -- feasible under these Exec_Bounds; some of them may be -- marked as infeasible below. Call : Programs.Execution.Call_Bounds_T; -- One of the Calls. begin for C in Calls'Range loop Call := Calls(C); if not Programs.Execution.Is_Feasible (Call.Bounds) then -- The callee has no feasible execution path, thus -- the call must be considered infeasible. if Flow.Pruning.Opt.Warn_Unreachable then Output.Warning ( Locus => Programs.Locus (Call_Path & Call.Call), Text => "Callee has no feasible execution path."); end if; Flow.Computation.Mark_Infeasible ( Step => Programs.Step (Call.Call), Under => Model.all); elsif not Programs.Execution.Returns (Call.Bounds) then -- A call that does not return. Flow.Computation.Mark_No_Return ( From => Call.Call, To => Model.all); end if; end loop; Flow.Computation.Prune (Model.all); end Mark_Abnormal_Calls; type Phase_T is ( Value_Origins_For_Target, Constant_Propagation, Value_Origins_For_Flow, Applying_Assertions, Abstract_Execution, Arithmetic_Analysis); -- -- The successive phases of analysis that we apply. -- -- Value_Origins_For_Target -- Value-origin analysis for target-specific uses, for -- example to chain narrow operations into wider ones. -- This may modify the arithmetic effects and conditions, -- and introdude new cells, for example register pairs. -- -- Constant_Propagation -- Constant propagation for refining arithmetic expressions, -- resolving dynamic memory references and dynamic jumps, -- finding some infeasible paths, and bounding stack heights. -- -- Value_Origins_For_Flow -- Value-origin analysis for resolving boundable edges. -- This is useful for some targets, for example to -- separate between ordinary calls and tail-calls. -- -- Applying_Assertions -- Identifying and applying assertions on call and loop -- repetition bounds, including loop-start bounds. -- -- Abstract_Execution -- Abstract execution of the subprogram and its callees, to -- resolve boundable edges, and perhaps other things TBA. -- This is an optional phase that uses the SWEET analyser -- from Mälardalen University. -- -- Arithmetic_Analysis -- Arithmetic analysis for loop bounds and for resolving -- all other dynamic objects. -- -- The result of a phase can be: -- -- > Growth of the flow-graph (if dynamic edges were resolved). -- We then return from Bound_Execution and let the Decoder -- continue to trace out the flow-graph. -- -- > Changes to the computation model. We then recompute the -- effects of calls and start over from the first phase. -- -- > None of the above. We can go on to the next phase. Phase : Phase_T := Phase_T'First; -- The current phase of analysis. Restarts : Natural := 0; -- The number of times we have restarted an earlier phase -- because a later phase has updated the computation model. begin -- Bound_Execution -- Check the contextual bounds: Report_Conflicting_Bounds ( Intervals => Generic_Bounds, Message => "Conflicting assertions on entry", Conflict => Bounds_Void); Report_Conflicting_Bounds ( Intervals => Initial_Bounds, Message => "Conflicting assertions or context on entry", Conflict => Bounds_Void); if Bounds_Void or Opt.Trace_Context then -- Show the input bounds in detail. Output.Trace ("Input bounds from context and assertions:"); Output.Heading ("Assumed initial stack heights:"); Storage.Bounds.Show.Show (Assumed_Initials); Output.Heading ("Global assertions:"); Storage.Bounds.Show.Show (Global_Inputs); Output.Heading ("Subprogram entry assertions:"); Storage.Bounds.Show.Show (Input_Bounds); Output.Heading ("Subprogram general assertions at entry:"); Storage.Bounds.Show.Show (Sub_Inputs); Output.Heading ("Call assertions and computed bounds:"); Storage.Bounds.Show.Show (Params); Output.Heading ("Target-dependent implicit bounds:"); Storage.Bounds.Show.Show (Dec_Bounds); -- TBA skip this subprogram/context, marking it "infeasible"? end if; -- Define the contextual bounds on cell values: Programs.Execution.Bound_Initial_Values ( To => Initial_Bounds, Within => Exec_Bounds); Programs.Execution.Bound_Call_Inputs ( To => Global_Bounds and Sub_Bounds, From => Exec_Bounds); -- Possible asserted bounds in instruction execution counts: Apply_Instruction_Count_Assertions; -- Possible asserted bounds on stacks: Bounds.Stacking.Apply_Assertions (Asserts, Exec_Bounds); -- Iterate through the analysis phases: Model := Programs.Execution.Computation (Exec_Bounds); Iteration : loop -- Iterative improvement of the computation model and -- the bounds on loops and calls. -- At this point the computation model is know to be "clean", -- that is, the effects of calls are consistent with the -- other parts of the model. if not Programs.Execution.Is_Feasible (Exec_Bounds) then Output.Warning ("All execution paths are infeasible."); Bound_As_Infeasible (Exec_Bounds); exit Iteration; end if; -- Perform this phase: if Opt.Trace_Phase then Output.Trace ("Phase " & Phase_T'Image (Phase)); end if; case Phase is when Value_Origins_For_Target => -- Possibly refine or extend the arithmetic model by using -- cell-value origins in a target-specific way: if Decoder.Value_Origins_Applicable ( To => Exec_Bounds, Along => Call_Path) then Programs.Execution.Bound_Value_Origins (Exec_Bounds); if Programs.Execution.Value_Origins_Defined (Exec_Bounds) then Decoder.Apply_Value_Origins ( Origins => Programs.Execution.Value_Origins (Exec_Bounds), Bounds => Exec_Bounds); -- -- TBC replace "Bounds" parameter with computation model? -- This may change the computation model, in which -- case we should clean it up and try again. else Output.Note ("No value-origins for target-specific analysis."); end if; end if; when Constant_Propagation => -- Refine the arithmetic model by propagating constant values -- around the control-flow graph, prune infeasible flow, try -- to resolve boundable (dynamic) things, and try to find stack -- bounds if constant: Flow.Const.Propagate ( Subprogram => Subprogram, Asserted => Global_Bounds and Sub_Bounds, Bounds => Exec_Bounds); when Value_Origins_For_Flow => -- Apply value-origin analysis to bound some boundable things -- (those that depend on values of specific cells on entry, -- for example on the return-address register on the SPARC): Programs.Execution.Bound_Value_Origins (Exec_Bounds); if Programs.Execution.Value_Origins_Defined (Exec_Bounds) then Flow.Origins.For_Flow.Resolve_Boundable_Edges ( Map => Programs.Execution.Value_Origins (Exec_Bounds)); else Output.Note ("No value-origins for resolving boundable edges."); end if; when Applying_Assertions => -- Locate the assertions for this subprogram and try to use -- them to bound loops and calls: Apply_Assertions; if not Programs.Execution.Is_Feasible (Exec_Bounds) then -- Some execution-count assertions on loops or calls -- make execution infeasible, or are contradictory. Output.Warning ("All execution paths are infeasible."); Bound_As_Infeasible (Exec_Bounds); exit Iteration; end if; when Abstract_Execution => if SWEET.Included then -- We may use the SWEET tool. if Programs.Execution.Dynamic_Flow (Exec_Bounds) = Flow.Unresolved then -- There are some dynamic edges, not yet stably resolved, -- and the SWEET analyser is available. So we use it. SWEET.Resolve_Dynamic_Jumps ( Subprogram => Subprogram, Bounds => Exec_Bounds, Num_Bounds => Programs.Execution.Number_Of_Bounds ( Within => Bounds_Set), Asserts => Asserts); end if; elsif Opt.Trace_Phase then Output.Trace (Phase_T'Image (Phase) & " not available."); end if; when Arithmetic_Analysis => -- Arithmetic analysis tries to bound all remaining boundable -- things. -- Can we avoid arithmetic analysis? Avoid_Arithmetic_Analysis ( Exec_Bounds => Exec_Bounds, Choice => Programs.Arithmetic_Analysis (Subprogram), Chosen => Arithmetic_Chosen); if not Arithmetic_Chosen then Bound_Without_Arithmetic ( Subprogram => Subprogram, Call_Path => Call_Path, Inherit_Inv => Inherit_Inv, Asserts => Asserts, Assert_Map => Assert_Map, Bounds_Set => Bounds_Set, Exec_Bounds => Exec_Bounds); exit Iteration; -- Bound_Without_Arithmetic cannot change the model -- in a way that would need iteration. -- TBC after addition of call-bounding without arithmetic. elsif not Programs.Reducible (Subprogram) then -- We cannot apply arithmetic analysis to -- an irreducible flow-graph. Output.Error ( "Irreducible flow-graph prevents arithmetic analysis."); Bound_Without_Arithmetic ( Subprogram => Subprogram, Call_Path => Call_Path, Inherit_Inv => Inherit_Inv, Asserts => Asserts, Assert_Map => Assert_Map, Bounds_Set => Bounds_Set, Exec_Bounds => Exec_Bounds); -- -- This will appear to succeed, but the bounds will not be -- considered "fully bounded" because the subprogram is -- not reducible. exit Iteration; -- Bound_Without_Arithmetic cannot change the model -- in a way that would need iteration. -- TBC after addition of call-bounding without arithmetic. elsif Call_Path'Length > Opt.Max_Dependency_Depth then Output.Error (Text => "Maximum call-dependent analysis depth reached."); Bound_Without_Arithmetic ( Subprogram => Subprogram, Call_Path => Call_Path, Inherit_Inv => Inherit_Inv, Asserts => Asserts, Assert_Map => Assert_Map, Bounds_Set => Bounds_Set, Exec_Bounds => Exec_Bounds); exit Iteration; -- Bound_Without_Arithmetic cannot change the model -- in a way that would need iteration. -- TBC after addition of call-bounding without arithmetic. else -- We can and must analyse the arithmetic. Bound_With_Arithmetic ( Subprogram => Subprogram, Call_Path => Call_Path, Initial => Initial_Bounds, Asserted => Global_Bounds and Sub_Bounds, Inherit_Inv => Inherit_Inv, Asserts => Asserts, Assert_Map => Assert_Map, Bounds_Set => Bounds_Set, Exec_Bounds => Exec_Bounds); end if; end case; -- Some calls may now be revealed as infeasible or non-returning: Mark_Abnormal_Calls; -- Check the result of this phase: if not Programs.Execution.Is_Feasible (Exec_Bounds) then -- Some abnormal calls made the whole subprogram infeasible. Output.Warning ("All execution paths are infeasible."); Bound_As_Infeasible (Exec_Bounds); exit Iteration; elsif Flow.Computation.Dynamic_Flow (Model.all) = Flow.Growing then -- If dynamic edges were resolved, the flow-graph is growing -- and these Exec_Bounds are out of date. if Opt.Trace_Phase then Output.Trace ("Resuming decoding because the flow-graph grew."); end if; exit Iteration; elsif Programs.Execution.Computation_Changed (Exec_Bounds) and Restarts < Opt.Max_Restarts then -- The computation model was updated, so we must also update -- the effects of calls etc. and then restart the analysis. if Opt.Trace_Phase then Output.Trace ("Repeating phases for changed computation model."); end if; Programs.Execution.Note_Updated_Computation (Exec_Bounds); Programs.Execution.Mark_Computation_Clean (Exec_Bounds); Restarts := Restarts + 1; Phase := Constant_Propagation; -- The phase Value_Origins_For_Target is not repeated TBC. else -- We will go on to the next Phase if there is one. if Programs.Execution.Computation_Changed (Exec_Bounds) then -- The computation model was updated but this has already -- happened so many times that we are bored with it. We -- leave it possibly inconsistent. Output.Error ( "Computation model did not converge in" & Natural'Image (Restarts) & " iterations and may be unsafe."); end if; if Phase < Phase_T'Last then -- We can go on to the next phase. Phase := Phase_T'Succ (Phase); else -- Last phase was satisfactory, to borrow Nero Wolfe. exit Iteration; end if; end if; end loop Iteration; -- That's (nearly) all folks! Finish_Bounds ( Exec_Bounds => Exec_Bounds, Assert_Map => Assert_Map, Bounds_Set => Bounds_Set, Flow_Frozen => Flow_Frozen); -- Check that the assertions were mapped properly: if Assert_Map = Assertions.No_Map then Output.Note ("No assertion map."); elsif Flow_Frozen then Assertions.Verify_Map ( Map => Assert_Map, Valid => Valid_Map); end if; end Bound_Execution; procedure Find_Execution_Bounds ( Subprogram : in Programs.Subprogram_T; Asserts : in Assertions.Assertion_Set_T; Bounds_Set : in out Programs.Execution.Bounds_Set_T; Flow_Frozen : out Boolean) -- -- Finds bounds on the execution of the given Subprogram either -- in the Bounds_Set (if already bounded) or by analysis otherwise. -- In the latter case, adds the new bounds to the Bounds_Set. -- -- The Flow_Frozen parameter shows whether the control-flow graph is -- completed (all dynamic control-flow resolved as far as we can). -- is use type Flow.Edge_Resolution_T; use type Programs.Execution.Bounds_Ref; Exec_Bounds : Programs.Execution.Bounds_Ref := Programs.Execution.Bounds_For ( Subprogram => Subprogram, Within => Bounds_Set, Along => Programs.Null_Call_Path); -- The execution bounds, initialised to the existing bounds if any. begin if Exec_Bounds = Programs.Execution.No_Bounds then -- No existing bounds, find them by analysis. Output.Note ("No execution bounds known yet."); -- Finish the arithmetic effects in the flow-graph, -- if the decoding left them somehow incomplete: Decoder.Finish_Arithmetic ( Subprogram => Subprogram, Graph => Programs.Flow_Graph (Subprogram), Call_Bounds => Programs.Execution.Bounds_For_Calls ( From => Subprogram, Within => Bounds_Set)); -- Create the execution bounds object: Programs.Execution.Initialize_Universal_Bounds ( Subprogram => Subprogram, Within => Bounds_Set, Bounds => Exec_Bounds); -- Analyse to find execution bounds: Bound_Execution ( Exec_Bounds => Exec_Bounds, Params => Storage.Bounds.Empty, Inherit_Inv => Storage.List_Cell_Sets.Empty, Asserts => Asserts, Bounds_Set => Bounds_Set, Flow_Frozen => Flow_Frozen); else -- Some execution bounds already known (from assertions), -- and are sufficiently bounded so that we do not need -- to analyse the subprogram. Output.Note ("Execution bounds already known."); Flow_Frozen := Programs.Execution.Dynamic_Flow (Exec_Bounds) = Flow.Stable; end if; end Find_Execution_Bounds; procedure Bound_Executions ( To_Bound : in out Programs.Subprogram_Set_T; Asserts : in Assertions.Assertion_Set_T; Bounds_Set : in out Programs.Execution.Bounds_Set_T; Growing : out Programs.Subprogram_Set_T) is Program : constant Programs.Program_T := Programs.Execution.Program (Bounds_Set); -- The target program in which this analysis occurs. All_Calls : constant Programs.Call_List_T := Programs.Calls_Between ( Subprograms => To_Bound, Program => Program); -- All calls between the subprograms to be bounded. -- These calls will define the bottom-up order. Subs : Programs.Subprogram_List_T := Programs.Sort.Bottom_Up ( Elements => Programs.To_List (To_Bound), Pairs => All_Calls); -- The subprograms in bottom-up calling order. Subprogram_Mark : Output.Nest_Mark_T; -- Marks the default output locus for the current subprogram. Frozen : Boolean; -- Whether the control-flow graph of the current subprogram is -- completed (all dynamic control flow resolved as far as we can). begin -- Bound_Executions -- Optional tracing of analysis: if Opt.Trace_Subprograms then Output.Trace ("Subprograms to be bounded:"); Programs.Show.Show (To_Bound); Output.Trace ("All calls between the subprograms:"); Programs.Show.Show (All_Calls); Output.Trace ("Subprograms in bottom-up order:"); Programs.Show.Show (Subs); end if; -- Start from an empty set of growing subprograms: Programs.Erase (Growing); -- Check for recursion: if Subs'Length < Programs.Cardinality (To_Bound) then -- There is a recursion cycle, which includes the -- To_Bound subprograms that are missing from Subs. Bounds.Recursing.Report_Cycle ( Recursive => To_Bound, Non_Recursive => Subs); raise Recursion; end if; -- Bound the subprograms in order: Bounding_Loop: for S in Subs'Range loop Subprogram_Mark := Output.Nest (Programs.Locus (Subs(S))); if Programs.Some_Calls (From => Subs(S), Into => Growing) then -- This subprogram cannot yet be fully bounded, because it calls -- some subprogram in Growing, for which additional callees can -- still be found. Output.Note ("Calls some growing subprogram, bounding delayed"); -- Moreover, some of the higher-level subprograms -- in Subs(S+1 ..) may call this one, which means that -- _their_ arithmetic analysis must be delayed. It is -- simpler to stop here, and start over from the bottom. Output.Unnest (Subprogram_Mark); exit Bounding_Loop; else -- The subprogram can be analysed. However, in some cases -- the Bounds_Set may already hold execution bounds for -- the subprogram. Currently this happens only if the -- bounds were asserted. Find_Execution_Bounds ( Subprogram => Subs(S), Asserts => Asserts, Bounds_Set => Bounds_Set, Flow_Frozen => Frozen); if Frozen then -- All dynamic control-flow is resolved, execution bounds -- perhaps derived. Programs.Remove (From => To_Bound, Removing => Subs(S)); -- If the execution bounds are complete (fully bounded), they -- are universal (call-independent) bounds, which completes -- the bounding for this subprogram. -- If the execution bounds are incomplete, the analysis -- will be continued in a call- or path-specific way, for -- each call of this subprogram. -- Whether the bounds are complete or not, they are stored -- with the subprogram for later use (if complete) or display. -- (Storage is implicit, since all the operations that create -- execution bounds also store them.) else -- Some dynamic control-flow remains, the control-flow graph -- is still growing and re-analysis is needed. Programs.Add (To => Growing, Adding => Subs(S)); end if; end if; Output.Unnest (Subprogram_Mark); end loop Bounding_Loop; end Bound_Executions; end Bounds;
reznikmm/matreshka
Ada
7,816
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Web Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012-2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with League.Text_Codecs; with XML.SAX.Input_Sources.Streams.Element_Arrays; with XML.SAX.Simple_Readers; with Web_Services.SOAP.Constants; with Web_Services.SOAP.Message_Decoders; with Web_Services.SOAP.Message_Encoders; with Web_Services.SOAP.Modules.Registry; package body Web_Services.SOAP.Clients is UTF8_Coder : constant League.Text_Codecs.Text_Codec := League.Text_Codecs.Codec (League.Strings.To_Universal_String ("utf-8")); procedure Read_Payload (Response_Data : League.Stream_Element_Vectors.Stream_Element_Vector; Response : out Web_Services.SOAP.Payloads.SOAP_Payload_Access); -- Extract Payload from Response_Data ---------- -- Call -- ---------- procedure Call (Self : in out SOAP_Client; Request : Web_Services.SOAP.Payloads.SOAP_Payload_Access; Response : out Web_Services.SOAP.Payloads.SOAP_Payload_Access; User : League.Strings.Universal_String := League.Strings.Empty_Universal_String; Password : League.Strings.Universal_String := League.Strings.Empty_Universal_String; Action : League.Strings.Universal_String := League.Strings.Empty_Universal_String) is Input : Web_Services.SOAP.Messages.SOAP_Message_Access := new Web_Services.SOAP.Messages.SOAP_Message; begin Input.Action := Action; Input.Payload := Request; Web_Services.SOAP.Modules.Registry.Execute_Send_Request (Input.all, User, Password); Self.Call (Input, Response); Web_Services.SOAP.Messages.Free (Input); end Call; ---------- -- Call -- ---------- procedure Call (Self : in out SOAP_Client; Input : Web_Services.SOAP.Messages.SOAP_Message_Access; Response : out Web_Services.SOAP.Payloads.SOAP_Payload_Access) is use type League.Strings.Universal_String; Encoder : Web_Services.SOAP.Message_Encoders.SOAP_Message_Encoder; Raw : constant League.Stream_Element_Vectors.Stream_Element_Vector := Encoder.Encode (Input.all); Content_Type : League.Stream_Element_Vectors.Stream_Element_Vector := League.Stream_Element_Vectors.To_Stream_Element_Vector (Constants.Application_SOAP_XML_Array); Response_Data : League.Stream_Element_Vectors.Stream_Element_Vector; begin if not Input.Action.Is_Empty then Content_Type.Append (UTF8_Coder.Encode ("; action=" & Input.Action)); end if; Self.Transport.Post_Request (Content_Type => Content_Type, Request_Data => Raw, Response_Data => Response_Data); if Response_Data.Is_Empty then return; end if; Read_Payload (Response_Data, Response); end Call; ------------------- -- Next_Response -- ------------------- not overriding procedure Next_Response (Self : in out SOAP_Client; Response : out Web_Services.SOAP.Payloads.SOAP_Payload_Access) is Response_Data : League.Stream_Element_Vectors.Stream_Element_Vector; begin Self.Transport.Next_Response (Response_Data); if Response_Data.Is_Empty then return; end if; Read_Payload (Response_Data, Response); end Next_Response; ------------------ -- Read_Payload -- ------------------ procedure Read_Payload (Response_Data : League.Stream_Element_Vectors.Stream_Element_Vector; Response : out Web_Services.SOAP.Payloads.SOAP_Payload_Access) is Output : Web_Services.SOAP.Messages.SOAP_Message_Access; Source : aliased XML.SAX.Input_Sources.Streams.Element_Arrays. Stream_Element_Array_Input_Source; Decoder : aliased Web_Services.SOAP.Message_Decoders.SOAP_Message_Decoder; Reader : aliased XML.SAX.Simple_Readers.Simple_Reader; begin -- Parse request data. Source.Set_Stream_Element_Array (Response_Data.To_Stream_Element_Array); Reader.Set_Content_Handler (Decoder'Unchecked_Access); Reader.Set_Error_Handler (Decoder'Unchecked_Access); Reader.Set_Lexical_Handler (Decoder'Unchecked_Access); Reader.Parse (Source'Access); if Decoder.Success then -- Request was decoded successfully. Output := Decoder.Message; Response := Output.Payload; Output.Payload := null; Web_Services.SOAP.Messages.Free (Output); end if; end Read_Payload; end Web_Services.SOAP.Clients;
reznikmm/matreshka
Ada
3,714
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- 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. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Attributes; package ODF.DOM.Text_Style_Name_Attributes is pragma Preelaborate; type ODF_Text_Style_Name_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Text_Style_Name_Attribute_Access is access all ODF_Text_Style_Name_Attribute'Class with Storage_Size => 0; end ODF.DOM.Text_Style_Name_Attributes;
sungyeon/drake
Ada
4,107
ads
pragma License (Unrestricted); with Ada.Strings.Maps; package Ada.Strings.Wide_Wide_Maps is pragma Preelaborate; -- Representation for a set of Wide_Wide_Character values: -- modified -- type Wide_Wide_Character_Set is private; subtype Wide_Wide_Character_Set is Maps.Character_Set; -- modified -- Null_Set : constant Wide_Wide_Character_Set; function Null_Set return Wide_Wide_Character_Set renames Maps.Null_Set; -- type Wide_Wide_Character_Range is record -- Low : Wide_Wide_Character; -- High : Wide_Wide_Character; -- end record; subtype Wide_Wide_Character_Range is Maps.Wide_Wide_Character_Range; -- Represents Wide_Wide_Character range Low..High -- type Wide_Wide_Character_Ranges is -- array (Positive range <>) of Wide_Wide_Character_Range; subtype Wide_Wide_Character_Ranges is Maps.Wide_Wide_Character_Ranges; function To_Set (Ranges : Wide_Wide_Character_Ranges) return Wide_Wide_Character_Set renames Maps.Overloaded_To_Set; function To_Set (Span : Wide_Wide_Character_Range) return Wide_Wide_Character_Set renames Maps.Overloaded_To_Set; function To_Ranges (Set : Wide_Wide_Character_Set) return Wide_Wide_Character_Ranges renames Maps.Overloaded_To_Ranges; function "=" (Left, Right : Wide_Wide_Character_Set) return Boolean renames Maps."="; function "not" (Right : Wide_Wide_Character_Set) return Wide_Wide_Character_Set renames Maps."not"; function "and" (Left, Right : Wide_Wide_Character_Set) return Wide_Wide_Character_Set renames Maps."and"; function "or" (Left, Right : Wide_Wide_Character_Set) return Wide_Wide_Character_Set renames Maps."or"; function "xor" (Left, Right : Wide_Wide_Character_Set) return Wide_Wide_Character_Set renames Maps."xor"; function "-" (Left, Right : Wide_Wide_Character_Set) return Wide_Wide_Character_Set renames Maps."-"; function Is_In ( Element : Wide_Wide_Character; Set : Wide_Wide_Character_Set) return Boolean renames Maps.Overloaded_Is_In; function Is_Subset ( Elements : Wide_Wide_Character_Set; Set : Wide_Wide_Character_Set) return Boolean renames Maps.Is_Subset; function "<=" ( Left : Wide_Wide_Character_Set; Right : Wide_Wide_Character_Set) return Boolean renames Maps.Is_Subset; -- Alternative representation for a set of Wide_Wide_Character values: subtype Wide_Wide_Character_Sequence is Wide_Wide_String; function To_Set (Sequence : Wide_Wide_Character_Sequence) return Wide_Wide_Character_Set renames Maps.Overloaded_To_Set; function To_Set (Singleton : Wide_Wide_Character) return Wide_Wide_Character_Set renames Maps.Overloaded_To_Set; function To_Sequence (Set : Wide_Wide_Character_Set) return Wide_Wide_Character_Sequence renames Maps.Overloaded_To_Sequence; -- Representation for a Wide_Wide_Character to -- Wide_Wide_Character mapping: -- modified -- type Wide_Wide_Character_Mapping is private; subtype Wide_Wide_Character_Mapping is Maps.Character_Mapping; function Value ( Map : Wide_Wide_Character_Mapping; Element : Wide_Wide_Character) return Wide_Wide_Character renames Maps.Overloaded_Value; -- modified -- Identity : constant Wide_Wide_Character_Mapping; function Identity return Wide_Wide_Character_Mapping renames Maps.Identity; function To_Mapping (From, To : Wide_Wide_Character_Sequence) return Wide_Wide_Character_Mapping renames Maps.Overloaded_To_Mapping; function To_Domain (Map : Wide_Wide_Character_Mapping) return Wide_Wide_Character_Sequence renames Maps.Overloaded_To_Domain; function To_Range (Map : Wide_Wide_Character_Mapping) return Wide_Wide_Character_Sequence renames Maps.Overloaded_To_Range; type Wide_Wide_Character_Mapping_Function is access function (From : Wide_Wide_Character) return Wide_Wide_Character; end Ada.Strings.Wide_Wide_Maps;
zhmu/ananas
Ada
778
adb
with GNAT.Heap_Sort_G; function sort1 (S : String) return String is Result : String (1 .. S'Length) := S; Temp : Character; procedure Move (From : Natural; To : Natural) is begin if From = 0 then Result (To) := Temp; elsif To = 0 then Temp := Result (From); else Result (To) := Result (From); end if; end Move; function Lt (Op1, Op2 : Natural) return Boolean is begin if Op1 = 0 then return Temp < Result (Op2); elsif Op2 = 0 then return Result (Op1) < Temp; else return Result (Op1) < Result (Op2); end if; end Lt; package SP is new GNAT.Heap_Sort_G (Move, Lt); begin SP.Sort (S'Length); return Result; end;
pdaxrom/Kino2
Ada
5,343
ads
------------------------------------------------------------------------------ -- -- -- GNAT ncurses Binding -- -- -- -- Terminal_Interface.Curses.Forms.Field_Types.User -- -- -- -- S P E C -- -- -- ------------------------------------------------------------------------------ -- Copyright (c) 1998 Free Software Foundation, Inc. -- -- -- -- 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, distribute with modifications, 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 ABOVE 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. -- -- -- -- Except as contained in this notice, the name(s) of the above copyright -- -- holders shall not be used in advertising or otherwise to promote the -- -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------ -- Author: Juergen Pfeifer, 1996 -- Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en -- Version Control: -- $Revision: 1.10 $ -- Binding Version 01.00 ------------------------------------------------------------------------------ with Interfaces.C; package Terminal_Interface.Curses.Forms.Field_Types.User is pragma Preelaborate (Terminal_Interface.Curses.Forms.Field_Types.User); use type Interfaces.C.int; subtype C_Int is Interfaces.C.int; type User_Defined_Field_Type is abstract new Field_Type with null record; -- This is the root of the mechanism we use to create field types in -- Ada95. You should your own type derive from this one and implement -- the Field_Check and Character_Check functions for your own type. type User_Defined_Field_Type_Access is access all User_Defined_Field_Type'Class; function Field_Check (Fld : Field; Typ : User_Defined_Field_Type) return Boolean is abstract; -- If True is returned, the field is considered valid, otherwise it is -- invalid. function Character_Check (Ch : Character; Typ : User_Defined_Field_Type) return Boolean is abstract; -- If True is returned, the character is considered as valid for the -- field, otherwise as invalid. procedure Set_Field_Type (Fld : in Field; Typ : in User_Defined_Field_Type); -- This should work for all types derived from User_Defined_Field_Type. -- No need to reimplement it for your derived type. -- +---------------------------------------------------------------------- -- | Private Part. -- | Used by the Choice child package. private use type Interfaces.C.int; function C_Generic_Type return C_Field_Type; function Generic_Field_Check (Fld : Field; Usr : System.Address) return C_Int; pragma Convention (C, Generic_Field_Check); -- This is the generic Field_Check_Function for the low-level fieldtype -- representing all the User_Defined_Field_Type derivates. It routes -- the call to the Field_Check implementation for the type. function Generic_Char_Check (Ch : C_Int; Usr : System.Address) return C_Int; pragma Convention (C, Generic_Char_Check); -- This is the generic Char_Check_Function for the low-level fieldtype -- representing all the User_Defined_Field_Type derivates. It routes -- the call to the Character_Check implementation for the type. end Terminal_Interface.Curses.Forms.Field_Types.User;
stcarrez/atlas
Ada
6,664
adb
----------------------------------------------------------------------- -- atlas-reviews-beans -- Beans for module reviews -- Copyright (C) 2014, 2015 Stephane.Carrez -- Written by Stephane.Carrez ([email protected]) -- -- 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 ADO.Sessions; with ADO.Queries; with ADO.Utils; with ADO.Datasets; with AWA.Services.Contexts; package body Atlas.Reviews.Beans is package ASC renames AWA.Services.Contexts; -- ------------------------------ -- Get the value identified by the name. -- ------------------------------ overriding function Get_Value (From : in Review_Bean; Name : in String) return Util.Beans.Objects.Object is begin if From.Is_Null then return Util.Beans.Objects.Null_Object; else return Atlas.Reviews.Models.Review_Bean (From).Get_Value (Name); end if; end Get_Value; -- ------------------------------ -- Set the value identified by the name. -- ------------------------------ overriding procedure Set_Value (From : in out Review_Bean; Name : in String; Value : in Util.Beans.Objects.Object) is begin if Name = "title" then From.Set_Title (Util.Beans.Objects.To_String (Value)); elsif Name = "site" then From.Set_Site (Util.Beans.Objects.To_String (Value)); elsif Name = "text" then From.Set_Text (Util.Beans.Objects.To_String (Value)); elsif Name = "id" and not Util.Beans.Objects.Is_Empty (Value) then declare Ctx : constant ASC.Service_Context_Access := AWA.Services.Contexts.Current; DB : ADO.Sessions.Session := AWA.Services.Contexts.Get_Session (Ctx); Id : constant ADO.Identifier := ADO.Utils.To_Identifier (Value); Found : Boolean; begin From.Load (DB, Id, Found); end; end if; end Set_Value; overriding procedure Save (Bean : in out Review_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is pragma Unreferenced (Outcome); begin Bean.Module.Save (Bean); end Save; overriding procedure Delete (Bean : in out Review_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is pragma Unreferenced (Outcome); begin Bean.Module.Delete (Bean); end Delete; overriding procedure Load (Bean : in out Review_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is pragma Unreferenced (Outcome, Bean); begin null; end Load; -- ------------------------------ -- Create the Review_Bean bean instance. -- ------------------------------ function Create_Review_Bean (Module : in Atlas.Reviews.Modules.Review_Module_Access) return Util.Beans.Basic.Readonly_Bean_Access is Object : constant Review_Bean_Access := new Review_Bean; begin Object.Module := Module; return Object.all'Access; end Create_Review_Bean; -- ------------------------------ -- Get the value identified by the name. -- ------------------------------ overriding function Get_Value (From : in Review_List_Bean; Name : in String) return Util.Beans.Objects.Object is begin if Name = "page" then return Util.Beans.Objects.To_Object (From.Page); elsif Name = "page_size" then return Util.Beans.Objects.To_Object (From.Page_Size); elsif Name = "count" then return Util.Beans.Objects.To_Object (From.Count); elsif Name = "reviews" then return Util.Beans.Objects.To_Object (Value => From.Reviews_Bean, Storage => Util.Beans.Objects.STATIC); else return From.Reviews.Get_Value (Name); end if; end Get_Value; -- ------------------------------ -- Set the value identified by the name. -- ------------------------------ overriding procedure Set_Value (From : in out Review_List_Bean; Name : in String; Value : in Util.Beans.Objects.Object) is begin if Name = "page" and not Util.Beans.Objects.Is_Empty (Value) then From.Page := Util.Beans.Objects.To_Integer (Value); elsif Name = "page_size" and not Util.Beans.Objects.Is_Empty (Value) then From.Page_Size := Util.Beans.Objects.To_Integer (Value); end if; end Set_Value; overriding procedure Load (Into : in out Review_List_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is pragma Unreferenced (Outcome); Session : ADO.Sessions.Session := Into.Module.Get_Session; Query : ADO.Queries.Context; Count_Query : ADO.Queries.Context; First : constant Natural := (Into.Page - 1) * Into.Page_Size; Last : constant Positive := First + Into.Page_Size; begin Query.Set_Query (Atlas.Reviews.Models.Query_List); Count_Query.Set_Count_Query (Atlas.Reviews.Models.Query_List); Query.Bind_Param (Name => "first", Value => First); Query.Bind_Param (Name => "last", Value => Last); Atlas.Reviews.Models.List (Into.Reviews, Session, Query); Into.Count := ADO.Datasets.Get_Count (Session, Count_Query); end Load; -- ------------------------------ -- Create the Review_List_Bean bean instance. -- ------------------------------ function Create_Review_List_Bean (Module : in Atlas.Reviews.Modules.Review_Module_Access) return Util.Beans.Basic.Readonly_Bean_Access is Object : constant Review_List_Bean_Access := new Review_List_Bean; begin Object.Module := Module; Object.Reviews_Bean := Object.Reviews'Access; Object.Page_Size := 20; Object.Page := 1; Object.Count := 0; return Object.all'Access; end Create_Review_List_Bean; end Atlas.Reviews.Beans;
GLADORG/glad-cli
Ada
4,359
adb
with Ada.Text_IO; with Ada.Directories; with Ada.Command_Line; with Templates_Parser; with CLIC.TTY; with Filesystem; with Commands; package body Blueprint is package IO renames Ada.Text_IO; package TT renames CLIC.TTY; package FS renames Filesystem; use Ada.Directories; Errors : Boolean := false; function Get_Blueprint_Folder return String is Executable_Location : String := FS.Get_Executable_Path; Root : String := Containing_Directory(Containing_Directory (Executable_Location)); Blueprint_Folder : String := Compose (Root, "blueprints"); begin return Blueprint_Folder; end Get_Blueprint_Folder; procedure Process_File (Target : String; Search_Item : in Directory_Entry_Type; Todo: Action) is Source_File : String := Full_Name (Directory_Entry => Search_Item); Processed_Content : String := Templates_Parser.Parse (Source_File, Commands.Translations); File_Handle : IO.File_Type; begin IO.Put_Line (TT.Emph ("Create") & " " & Target); if Exists(Target) then Errors := true; IO.Put_Line (TT.Error ("A file allready exists at ") & " " & TT.Bold (Target) & " " & TT.Warn("Ignored")); else if Todo = Write then IO.Create (File_Handle, IO.Out_File, Target); IO.Put (File_Handle, Processed_Content); IO.Close (File_Handle); end if; end if; end Process_File; procedure Iterate(Blueprint_Folder: String; Path: String; Todo: Action) is Filter : constant Filter_Type := ( Ordinary_File => True, Special_File => False, Directory => True ); procedure Item (Search_Item : in Directory_Entry_Type) is Name : String := Simple_Name (Directory_Entry => Search_Item); Processed_Name : String := Templates_Parser.Translate (Name, Commands.Translations); Blueprint_Folder : String := Full_Name (Directory_Entry => Search_Item); Target : String := Compose (Path, Processed_Name); begin if Filesystem.Is_Valid_File (Name) then case Todo is when Write => if Kind (Directory_Entry => Search_Item) = Directory then IO.Put_Line(TT.Emph ("Create") & " " & Target); if Exists(Target) then if Kind (Directory_Entry => Search_Item) = ORDINARY_FILE then IO.Put_Line (TT.Error ("A file allready exists at ") & " " & TT.Bold (Target) & " " & TT.Warn ("Ignored")); Errors := True; else Iterate (Blueprint_Folder, Target, Todo); end if; else Create_Directory (Target); Iterate (Blueprint_Folder, Target, Todo); end if; else Process_File (Target, Search_Item, Todo); end if; when Delete => if Kind (Directory_Entry => Search_Item) = Directory then if Exists(Target) then Iterate (Blueprint_Folder, Target, Todo); if FS.Count_Files(Target) = 0 then IO.Put_Line(TT.Emph ("Delete") & " " & Target); Delete_Tree(Target); end if; end if; elsif Kind (Directory_Entry => Search_Item) = ORDINARY_FILE then IO.Put_Line(TT.Emph ("Delete") & " " & Target); Delete_File (Target); end if; when DryRun => if Kind (Directory_Entry => Search_Item) = Directory then IO.Put_Line(TT.Emph ("Create") & " " & Target); if Exists(Target) then if Kind (Directory_Entry => Search_Item) = ORDINARY_FILE then IO.Put_Line (TT.Error ("A file allready exists at ") & " " & TT.Bold (Target) & " " & TT.Warn ("Ignored")); Errors := True; else Iterate (Blueprint_Folder, Target, Todo); end if; else Iterate (Blueprint_Folder, Target, Todo); end if; else Process_File (Target, Search_Item, Todo); end if; end case; end if; end Item; begin Search (Directory => Blueprint_Folder, Pattern => "", Filter => Filter, Process => Item'Access); end Iterate; end Blueprint;