repo_name
stringlengths
9
74
language
stringclasses
1 value
length_bytes
int64
11
9.34M
extension
stringclasses
2 values
content
stringlengths
11
9.34M
persan/A-gst
Ada
10,840
ads
pragma Ada_2005; pragma Style_Checks (Off); pragma Warnings (Off); with Interfaces.C; use Interfaces.C; with GLIB; -- with GStreamer.GST_Low_Level.glibconfig_h; with glib; with glib.Values; with System; with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstelement_h; with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h; with System; with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstsegment_h; limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstcaps_h; limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstbuffer_h; limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstevent_h; with glib; with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h; package GStreamer.GST_Low_Level.gstreamer_0_10_gst_rtp_gstbasertppayload_h is -- unsupported macro: GST_TYPE_BASE_RTP_PAYLOAD (gst_basertppayload_get_type()) -- arg-macro: function GST_BASE_RTP_PAYLOAD (obj) -- return G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_RTP_PAYLOAD,GstBaseRTPPayload); -- arg-macro: function GST_BASE_RTP_PAYLOAD_CLASS (klass) -- return G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_RTP_PAYLOAD,GstBaseRTPPayloadClass); -- arg-macro: function GST_BASE_RTP_PAYLOAD_GET_CLASS (obj) -- return G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BASE_RTP_PAYLOAD, GstBaseRTPPayloadClass); -- arg-macro: function GST_IS_BASE_RTP_PAYLOAD (obj) -- return G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_RTP_PAYLOAD); -- arg-macro: function GST_IS_BASE_RTP_PAYLOAD_CLASS (klass) -- return G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_RTP_PAYLOAD); -- arg-macro: function GST_BASE_RTP_PAYLOAD_CAST (obj) -- return (GstBaseRTPPayload*)(obj); -- arg-macro: function GST_BASE_RTP_PAYLOAD_SINKPAD (payload) -- return GST_BASE_RTP_PAYLOAD (payload).sinkpad; -- arg-macro: function GST_BASE_RTP_PAYLOAD_SRCPAD (payload) -- return GST_BASE_RTP_PAYLOAD (payload).srcpad; -- arg-macro: function GST_BASE_RTP_PAYLOAD_PT (payload) -- return GST_BASE_RTP_PAYLOAD (payload).pt; -- arg-macro: function GST_BASE_RTP_PAYLOAD_MTU (payload) -- return GST_BASE_RTP_PAYLOAD (payload).mtu; -- GStreamer -- * Copyright (C) <2005> Wim Taymans <[email protected]> -- * -- * This library is free software; you can redistribute it and/or -- * modify it under the terms of the GNU Library General Public -- * License as published by the Free Software Foundation; either -- * version 2 of the License, or (at your option) any later version. -- * -- * This library is distributed in the hope that it will be useful, -- * but WITHOUT ANY WARRANTY; without even the implied warranty of -- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- * Library General Public License for more details. -- * -- * You should have received a copy of the GNU Library General Public -- * License along with this library; if not, write to the -- * Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- * Boston, MA 02111-1307, USA. -- type GstBaseRTPPayload; type anon_416; type anon_417 is record ptime : aliased GLIB.guint64; -- gst/rtp/gstbasertppayload.h:116 ptime_multiple : aliased GLIB.guint64; -- gst/rtp/gstbasertppayload.h:117 end record; pragma Convention (C_Pass_By_Copy, anon_417); type u_GstBaseRTPPayload_u_gst_reserved_array is array (0 .. 1) of System.Address; type anon_416 (discr : unsigned := 0) is record case discr is when 0 => ABI : aliased anon_417; -- gst/rtp/gstbasertppayload.h:118 when others => u_gst_reserved : u_GstBaseRTPPayload_u_gst_reserved_array; -- gst/rtp/gstbasertppayload.h:119 end case; end record; pragma Convention (C_Pass_By_Copy, anon_416); pragma Unchecked_Union (anon_416);--subtype GstBaseRTPPayload is u_GstBaseRTPPayload; -- gst/rtp/gstbasertppayload.h:42 -- skipped empty struct u_GstBaseRTPPayloadPrivate -- skipped empty struct GstBaseRTPPayloadPrivate type GstBaseRTPPayloadClass; type u_GstBaseRTPPayloadClass_u_gst_reserved_array is array (0 .. 1) of System.Address; --subtype GstBaseRTPPayloadClass is u_GstBaseRTPPayloadClass; -- gst/rtp/gstbasertppayload.h:44 --* -- * GST_BASE_RTP_PAYLOAD_SINKPAD: -- * @payload: a #GstBaseRTPPayload -- * -- * Get access to the sinkpad of @payload. -- --* -- * GST_BASE_RTP_PAYLOAD_SRCPAD: -- * @payload: a #GstBaseRTPPayload -- * -- * Get access to the srcpad of @payload. -- --* -- * GST_BASE_RTP_PAYLOAD_PT: -- * @payload: a #GstBaseRTPPayload -- * -- * Get access to the configured payload type of @payload. -- --* -- * GST_BASE_RTP_PAYLOAD_MTU: -- * @payload: a #GstBaseRTPPayload -- * -- * Get access to the configured MTU of @payload. -- type GstBaseRTPPayload is record element : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstelement_h.GstElement; -- gst/rtp/gstbasertppayload.h:78 sinkpad : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstPad; -- gst/rtp/gstbasertppayload.h:81 srcpad : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstPad; -- gst/rtp/gstbasertppayload.h:82 seq_rand : System.Address; -- gst/rtp/gstbasertppayload.h:85 ssrc_rand : System.Address; -- gst/rtp/gstbasertppayload.h:86 ts_rand : System.Address; -- gst/rtp/gstbasertppayload.h:87 ts_base : aliased GLIB.guint32; -- gst/rtp/gstbasertppayload.h:89 seqnum_base : aliased GLIB.guint16; -- gst/rtp/gstbasertppayload.h:90 media : access GLIB.gchar; -- gst/rtp/gstbasertppayload.h:92 encoding_name : access GLIB.gchar; -- gst/rtp/gstbasertppayload.h:93 dynamic : aliased GLIB.gboolean; -- gst/rtp/gstbasertppayload.h:94 clock_rate : aliased GLIB.guint32; -- gst/rtp/gstbasertppayload.h:95 ts_offset : aliased GLIB.gint32; -- gst/rtp/gstbasertppayload.h:97 timestamp : aliased GLIB.guint32; -- gst/rtp/gstbasertppayload.h:98 seqnum_offset : aliased GLIB.gint16; -- gst/rtp/gstbasertppayload.h:99 seqnum : aliased GLIB.guint16; -- gst/rtp/gstbasertppayload.h:100 max_ptime : aliased GLIB.gint64; -- gst/rtp/gstbasertppayload.h:101 pt : aliased GLIB.guint; -- gst/rtp/gstbasertppayload.h:102 ssrc : aliased GLIB.guint; -- gst/rtp/gstbasertppayload.h:103 current_ssrc : aliased GLIB.guint; -- gst/rtp/gstbasertppayload.h:104 mtu : aliased GLIB.guint; -- gst/rtp/gstbasertppayload.h:105 segment : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstsegment_h.GstSegment; -- gst/rtp/gstbasertppayload.h:107 min_ptime : aliased GLIB.guint64; -- gst/rtp/gstbasertppayload.h:109 priv : System.Address; -- gst/rtp/gstbasertppayload.h:112 abidata : aliased anon_416; -- gst/rtp/gstbasertppayload.h:120 end record; pragma Convention (C_Pass_By_Copy, GstBaseRTPPayload); -- gst/rtp/gstbasertppayload.h:76 --< private > -- FIXME 0.11: none of these GRands are used anymore, remove them --< private > -- in ns -- in ns --* -- * GstBaseRTPPayloadClass: -- * @parent_class: the parent class -- * @set_caps: configure the payloader -- * @handle_buffer: process data -- * @handle_event: custom event handling -- * @get_caps: get desired caps -- * -- * Base class for audio RTP payloader. -- type GstBaseRTPPayloadClass is record parent_class : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstelement_h.GstElementClass; -- gst/rtp/gstbasertppayload.h:135 set_caps : access function (arg1 : access GstBaseRTPPayload; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstcaps_h.GstCaps) return GLIB.gboolean; -- gst/rtp/gstbasertppayload.h:138 handle_buffer : access function (arg1 : access GstBaseRTPPayload; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstbuffer_h.GstBuffer) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstFlowReturn; -- gst/rtp/gstbasertppayload.h:142 handle_event : access function (arg1 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstPad; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstevent_h.GstEvent) return GLIB.gboolean; -- gst/rtp/gstbasertppayload.h:143 get_caps : access function (arg1 : access GstBaseRTPPayload; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstPad) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstcaps_h.GstCaps; -- gst/rtp/gstbasertppayload.h:144 u_gst_reserved : u_GstBaseRTPPayloadClass_u_gst_reserved_array; -- gst/rtp/gstbasertppayload.h:147 end record; pragma Convention (C_Pass_By_Copy, GstBaseRTPPayloadClass); -- gst/rtp/gstbasertppayload.h:133 -- receive caps on the sink pad, configure the payloader. -- handle a buffer, perform 0 or more gst_basertppayload_push() on -- * the RTP buffers. This function takes ownership of the buffer. --< private > function gst_basertppayload_get_type return GLIB.GType; -- gst/rtp/gstbasertppayload.h:150 pragma Import (C, gst_basertppayload_get_type, "gst_basertppayload_get_type"); procedure gst_basertppayload_set_options (payload : access GstBaseRTPPayload; media : access GLIB.gchar; dynamic : GLIB.gboolean; encoding_name : access GLIB.gchar; clock_rate : GLIB.guint32); -- gst/rtp/gstbasertppayload.h:152 pragma Import (C, gst_basertppayload_set_options, "gst_basertppayload_set_options"); function gst_basertppayload_set_outcaps (payload : access GstBaseRTPPayload; fieldname : access GLIB.gchar -- , ... ) return GLIB.gboolean; -- gst/rtp/gstbasertppayload.h:158 pragma Import (C, gst_basertppayload_set_outcaps, "gst_basertppayload_set_outcaps"); function gst_basertppayload_is_filled (payload : access GstBaseRTPPayload; size : GLIB.guint; duration : GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstclock_h.GstClockTime) return GLIB.gboolean; -- gst/rtp/gstbasertppayload.h:161 pragma Import (C, gst_basertppayload_is_filled, "gst_basertppayload_is_filled"); function gst_basertppayload_push (payload : access GstBaseRTPPayload; buffer : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstbuffer_h.GstBuffer) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstFlowReturn; -- gst/rtp/gstbasertppayload.h:164 pragma Import (C, gst_basertppayload_push, "gst_basertppayload_push"); function gst_basertppayload_push_list (payload : access GstBaseRTPPayload; list : System.Address) return GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstpad_h.GstFlowReturn; -- gst/rtp/gstbasertppayload.h:167 pragma Import (C, gst_basertppayload_push_list, "gst_basertppayload_push_list"); end GStreamer.GST_Low_Level.gstreamer_0_10_gst_rtp_gstbasertppayload_h;
faelys/natools
Ada
6,754
adb
------------------------------------------------------------------------------ -- Copyright (c) 2015, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ with Ada.Calendar.Arithmetic; package body Natools.Time_Keys is function Extract_Sub_Second (Key : String) return Duration; -- Read the end of Buffer and compute the Sub_Second part ------------------------------ -- Local Helper Subprograms -- ------------------------------ function Extract_Sub_Second (Key : String) return Duration is Sub_Second : Duration := 0.0; begin for I in reverse Key'First + 7 .. Key'Last loop Sub_Second := (Sub_Second + Duration (Value (Key (I)))) / 32; Sub_Second := (Sub_Second + Duration'Small) / 2; end loop; return Sub_Second; end Extract_Sub_Second; ----------------------- -- Publoic Interface -- ----------------------- function To_Key (Time : Ada.Calendar.Time; Max_Sub_Second_Digits : in Natural := 120) return String is Year : Ada.Calendar.Year_Number; Month : Ada.Calendar.Month_Number; Day : Ada.Calendar.Day_Number; Hour : Ada.Calendar.Formatting.Hour_Number; Minute : Ada.Calendar.Formatting.Minute_Number; Second : Ada.Calendar.Formatting.Second_Number; Sub_Second : Ada.Calendar.Formatting.Second_Duration; Leap_Second : Boolean; begin Ada.Calendar.Formatting.Split (Time, Year, Month, Day, Hour, Minute, Second, Sub_Second, Leap_Second); return To_Key (Year, Month, Day, Hour, Minute, Second, Sub_Second, Leap_Second, Max_Sub_Second_Digits); end To_Key; function To_Key (Year : Ada.Calendar.Year_Number; Month : Ada.Calendar.Month_Number; Day : Ada.Calendar.Day_Number; Hour : Ada.Calendar.Formatting.Hour_Number := 0; Minute : Ada.Calendar.Formatting.Minute_Number := 0; Second : Ada.Calendar.Formatting.Second_Number := 0; Sub_Second : Ada.Calendar.Formatting.Second_Duration := 0.0; Leap_Second : Boolean := False; Max_Sub_Second_Digits : Natural := 120) return String is procedure Increment_Buffer; Buffer : String (1 .. 7 + Max_Sub_Second_Digits); Last : Positive; procedure Increment_Buffer is begin while Last > 7 and then Buffer (Last) = '~' loop Last := Last - 1; end loop; if Last > 7 then Buffer (Last) := Image (Value (Buffer (Last)) + 1); return; end if; if Second <= 58 then Buffer (7) := I_Image (Second + 1); Last := 7; elsif Minute <= 58 then Buffer (6) := I_Image (Minute + 1); Last := 6; elsif Hour <= 22 then Buffer (5) := I_Image (Hour + 1); Last := 5; else Buffer (1 .. 4) := To_Key (Ada.Calendar.Arithmetic."+" (Ada.Calendar.Formatting.Time_Of (Year, Month, Day), 1)); Last := 4; end if; end Increment_Buffer; N : Natural; D, Base : Duration; begin Buffer (1) := I_Image (Year / 64); Buffer (2) := I_Image (Year mod 64); Buffer (3) := I_Image (Month); Buffer (4) := I_Image (Day); Buffer (5) := I_Image (Hour); Buffer (6) := I_Image (Minute); if Leap_Second then pragma Assert (Second = 59); Buffer (7) := I_Image (60); else Buffer (7) := I_Image (Second); end if; if Sub_Second = 0.0 then if Second = 0 then if Minute = 0 then if Hour = 0 then return Buffer (1 .. 4); else return Buffer (1 .. 5); end if; else return Buffer (1 .. 6); end if; else return Buffer (1 .. 7); end if; end if; Last := 7; D := Sub_Second * 64; Base := 1.0; loop Last := Last + 1; Base := Base / 64.0; N := Natural (D); if Last = Buffer'Last or Base = 0.0 then if N < 64 then Buffer (Last) := I_Image (N); else Last := Last - 1; Increment_Buffer; end if; exit; end if; if Duration (N) > D then N := N - 1; pragma Assert (Duration (N) <= D); end if; D := (D - Duration (N)) * 64; Buffer (Last) := I_Image (N); exit when D = 0.0; end loop; return Buffer (1 .. Last); end To_Key; function To_Time (Key : String) return Ada.Calendar.Time is Leap_Second : constant Boolean := Key'First + 6 in Key'Range and then Key (Key'First + 6) = 'x'; begin return Ada.Calendar.Formatting.Time_Of (Year => I_Value (Key (Key'First)) * 64 + I_Value (Key (Key'First + 1)), Month => I_Value (Key (Key'First + 2)), Day => I_Value (Key (Key'First + 3)), Hour => (if Key'First + 4 in Key'Range then I_Value (Key (Key'First + 4)) else 0), Minute => (if Key'First + 5 in Key'Range then I_Value (Key (Key'First + 5)) else 0), Second => (if Key'First + 6 in Key'Range then (if Leap_Second then 59 else I_Value (Key (Key'First + 6))) else 0), Sub_Second => Extract_Sub_Second (Key), Leap_Second => Leap_Second); end To_Time; end Natools.Time_Keys;
DrenfongWong/tkm-rpc
Ada
1,958
adb
with Tkmrpc.Servers.Ike; with Tkmrpc.Results; with Tkmrpc.Request.Ike.Esa_Create_No_Pfs.Convert; with Tkmrpc.Response.Ike.Esa_Create_No_Pfs.Convert; package body Tkmrpc.Operation_Handlers.Ike.Esa_Create_No_Pfs is ------------------------------------------------------------------------- procedure Handle (Req : Request.Data_Type; Res : out Response.Data_Type) is Specific_Req : Request.Ike.Esa_Create_No_Pfs.Request_Type; Specific_Res : Response.Ike.Esa_Create_No_Pfs.Response_Type; begin Specific_Res := Response.Ike.Esa_Create_No_Pfs.Null_Response; Specific_Req := Request.Ike.Esa_Create_No_Pfs.Convert.From_Request (S => Req); if Specific_Req.Data.Esa_Id'Valid and Specific_Req.Data.Isa_Id'Valid and Specific_Req.Data.Sp_Id'Valid and Specific_Req.Data.Ea_Id'Valid and Specific_Req.Data.Nc_Loc_Id'Valid and Specific_Req.Data.Nonce_Rem.Size'Valid and Specific_Req.Data.Initiator'Valid and Specific_Req.Data.Esp_Spi_Loc'Valid and Specific_Req.Data.Esp_Spi_Rem'Valid then Servers.Ike.Esa_Create_No_Pfs (Result => Specific_Res.Header.Result, Esa_Id => Specific_Req.Data.Esa_Id, Isa_Id => Specific_Req.Data.Isa_Id, Sp_Id => Specific_Req.Data.Sp_Id, Ea_Id => Specific_Req.Data.Ea_Id, Nc_Loc_Id => Specific_Req.Data.Nc_Loc_Id, Nonce_Rem => Specific_Req.Data.Nonce_Rem, Initiator => Specific_Req.Data.Initiator, Esp_Spi_Loc => Specific_Req.Data.Esp_Spi_Loc, Esp_Spi_Rem => Specific_Req.Data.Esp_Spi_Rem); Res := Response.Ike.Esa_Create_No_Pfs.Convert.To_Response (S => Specific_Res); else Res.Header.Result := Results.Invalid_Parameter; end if; end Handle; end Tkmrpc.Operation_Handlers.Ike.Esa_Create_No_Pfs;
rveenker/sdlada
Ada
4,694
adb
-------------------------------------------------------------------------------------------------------------------- -- Copyright (c) 2013-2020, Luke A. Guest -- -- This software is provided 'as-is', without any express or implied -- warranty. In no event will the authors be held liable for any damages -- arising from the use of this software. -- -- Permission is granted to anyone to use this software for any purpose, -- including commercial applications, and to alter it and redistribute it -- freely, subject to the following restrictions: -- -- 1. The origin of this software must not be misrepresented; you must not -- claim that you wrote the original software. If you use this software -- in a product, an acknowledgment in the product documentation would be -- appreciated but is not required. -- -- 2. Altered source versions must be plainly marked as such, and must not be -- misrepresented as being the original software. -- -- 3. This notice may not be removed or altered from any source -- distribution. -------------------------------------------------------------------------------------------------------------------- with SDL.Error; package body SDL.RWops.Streams is use type Interfaces.C.unsigned_long; function Open (Op : in RWops) return RWops_Stream is begin return (Ada.Streams.Root_Stream_Type with Context => Op); end Open; procedure Open (Op : in RWops; Stream : out RWops_Stream) is begin Stream.Context := Op; end Open; overriding procedure Read (Stream : in out RWops_Stream; Item : out Ada.Streams.Stream_Element_Array; Last : out Ada.Streams.Stream_Element_Offset) is Objects_Read : Interfaces.C.unsigned_long := 0; function SDL_Read (Context : in RWops_Pointer; Ptr : in System.Address; Size : in C.unsigned_long; Max_Num : in C.unsigned_long ) return C.unsigned_long; pragma Import (C, SDL_Read, "read_wrap"); begin -- Re-implemented c-macro: -- #define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n) -- Read : access function -- (context : RWops_Pointer; -- ptr : System.Address; -- size : Interfaces.C.unsigned_long; -- maxnum : Interfaces.C.unsigned_long) return Interfaces.C.unsigned_long; Objects_Read := SDL_Read (Context => RWops_Pointer (Stream.Context), Ptr => Item'Address, Size => C.unsigned_long (Item'Length), Max_Num => 1); if Objects_Read = 0 then raise RWops_Error with SDL.Error.Get; end if; Last := Ada.Streams.Stream_Element_Offset (Objects_Read); end Read; overriding procedure Write (Stream : in out RWops_Stream; Item : Ada.Streams.Stream_Element_Array) is Objects_Written : Interfaces.C.unsigned_long := 0; function SDL_Write (Context : in RWops_Pointer; Ptr : in System.Address; Size : in C.unsigned_long; Num : in C.unsigned_long ) return C.unsigned_long; pragma Import (C, SDL_Write, "write_wrap"); begin -- Re-implemented c-macro: -- #define SDL_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n) -- Write : access function -- (Context : RWops_Pointer; -- Ptr : System.Address; -- Size : Interfaces.C.unsigned_long; -- Num : Interfaces.C.unsigned_long) return Interfaces.C.unsigned_long; Objects_Written := SDL_Write (Context => RWops_Pointer (Stream.Context), Ptr => Item'Address, Size => C.unsigned_long (Item'Length), Num => 1); if Objects_Written = 0 then raise RWops_Error with SDL.Error.Get; end if; end Write; procedure Close (Stream : in out RWops_Stream) is use type C.int; Res : C.int := 0; function SDL_Close (Context : in RWops_Pointer) return C.int; pragma Import (C, SDL_Close, "close_wrap"); begin -- Re-implemented c-macro: -- #define SDL_RWclose(ctx) (ctx)->close(ctx) -- Close : access function -- (Context : RWops_Pointer) return Interfaces.C.int; Res := SDL_Close (Context => RWops_Pointer (Stream.Context)); if Res /= 0 then raise RWops_Error with SDL.Error.Get; end if; end Close; end SDL.RWops.Streams;
tum-ei-rcs/StratoX
Ada
2,615
ads
-- This spec has been automatically generated from STM32F429x.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; with HAL; with System; package STM32_SVD.RNG is pragma Preelaborate; --------------- -- Registers -- --------------- ----------------- -- CR_Register -- ----------------- -- control register type CR_Register is record -- unspecified Reserved_0_1 : HAL.UInt2 := 16#0#; -- Random number generator enable RNGEN : Boolean := False; -- Interrupt enable IE : Boolean := False; -- unspecified Reserved_4_31 : HAL.UInt28 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR_Register use record Reserved_0_1 at 0 range 0 .. 1; RNGEN at 0 range 2 .. 2; IE at 0 range 3 .. 3; Reserved_4_31 at 0 range 4 .. 31; end record; ----------------- -- SR_Register -- ----------------- -- status register type SR_Register is record -- Read-only. Data ready DRDY : Boolean := False; -- Read-only. Clock error current status CECS : Boolean := False; -- Read-only. Seed error current status SECS : Boolean := False; -- unspecified Reserved_3_4 : HAL.UInt2 := 16#0#; -- Clock error interrupt status CEIS : Boolean := False; -- Seed error interrupt status SEIS : Boolean := False; -- unspecified Reserved_7_31 : HAL.UInt25 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SR_Register use record DRDY at 0 range 0 .. 0; CECS at 0 range 1 .. 1; SECS at 0 range 2 .. 2; Reserved_3_4 at 0 range 3 .. 4; CEIS at 0 range 5 .. 5; SEIS at 0 range 6 .. 6; Reserved_7_31 at 0 range 7 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Random number generator type RNG_Peripheral is record -- control register CR : CR_Register; -- status register SR : SR_Register; -- data register DR : HAL.Word; end record with Volatile; for RNG_Peripheral use record CR at 0 range 0 .. 31; SR at 4 range 0 .. 31; DR at 8 range 0 .. 31; end record; -- Random number generator RNG_Periph : aliased RNG_Peripheral with Import, Address => RNG_Base; end STM32_SVD.RNG;
charlie5/lace
Ada
2,091
ads
with physics.Object, lace.Any; package physics.Joint -- -- Provides an interface for physics joints. -- is type Item is limited interface and lace.Any.limited_item; type View is access all Item'Class; type Degree_of_freedom is range 1 .. 6; procedure destruct (Self : in out Item) is abstract; function Object_A (Self : in Item) return physics.Object.view is abstract; function Object_B (Self : in Item) return physics.Object.view is abstract; function Frame_A (Self : in Item) return Matrix_4x4 is abstract; function Frame_B (Self : in Item) return Matrix_4x4 is abstract; procedure Frame_A_is (Self : in out Item; Now : in Matrix_4x4) is abstract; procedure Frame_B_is (Self : in out Item; Now : in Matrix_4x4) is abstract; function is_Limited (Self : in Item; DoF : Degree_of_freedom) return Boolean is abstract; procedure Velocity_is (Self : in out Item; Now : in Real; DoF : in Degree_of_freedom) is abstract; -- -- Sets the spatial or angular velocity for the specified DoF. function Extent (Self : in Item; DoF : Degree_of_freedom) return Real is abstract; -- -- Returns the current distance or angle (for a spatial or angular DoF, respectively). procedure desired_Extent_is (Self : in out Item; Now : in Real; DoF : in Degree_of_freedom) is abstract; -- -- Sets the desired spacial or angular extent for a given degree of freedom (DoF). function reaction_Force (Self : in Item) return Vector_3 is abstract; function reaction_Torque (Self : in Item) return Real is abstract; procedure user_Data_is (Self : in out Item; Now : access lace.Any.limited_item'Class) is abstract; function user_Data (Self : in Item) return access lace.Any.limited_item'Class is abstract; end physics.Joint;
RREE/build-avr-ada-toolchain
Ada
1,344
ads
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- A D A . U N C H E C K E D _ C O N V E R S I O N -- -- -- -- S p e c -- -- -- -- This specification is derived from the Ada Reference Manual for use with -- -- GNAT. In accordance with the copyright of that document, you can freely -- -- copy and modify this specification, provided that if you redistribute a -- -- modified version, any changes that you have made are clearly indicated. -- -- -- ------------------------------------------------------------------------------ generic type Source (<>) is limited private; type Target (<>) is limited private; function Ada.Unchecked_Conversion (S : Source) return Target; pragma Pure (Unchecked_Conversion); pragma Import (Intrinsic, Unchecked_Conversion);
flyx/OpenGLAda
Ada
6,453
ads
-- part of OpenGLAda, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "COPYING" with GL.Objects.Textures.With_1D_Loader; with GL.Objects.Textures.With_2D_Loader; with GL.Objects.Textures.With_3D_Loader; package GL.Objects.Textures.Targets is pragma Preelaborate; ----------------------------------------------------------------------------- -- Texture Target Specializations -- ----------------------------------------------------------------------------- package Texture_1D_Target is new With_1D_Loader (Texture_Target); package Texture_2D_Target is new With_2D_Loader (Texture_Target); package Texture_3D_Target is new With_3D_Loader (Texture_Target); package Texture_1D_Proxy_Target is new With_1D_Loader (Texture_Proxy); package Texture_2D_Proxy_Target is new With_2D_Loader (Texture_Proxy); package Texture_3D_Proxy_Target is new With_3D_Loader (Texture_Proxy); type Texture_Cube_Map_Target (<>) is new Texture_3D_Target.Target with private; package Cube_Map_Side_Target is new With_2D_Loader (Texture_Proxy); type Texture_Buffer_Target (<>) is new Texture_Target with private; function Buffer_Offset (Object : Texture_Buffer_Target; Level : Mipmap_Level) return Size; function Buffer_Size (Object : Texture_Buffer_Target; Level : Mipmap_Level) return Size; ----------------------------------------------------------------------------- -- Texture Target Instances -- ----------------------------------------------------------------------------- Texture_1D : aliased constant Texture_1D_Target.Fillable_Target; Texture_2D : aliased constant Texture_2D_Target.Fillable_Target; Texture_3D : aliased constant Texture_3D_Target.Fillable_Target; Texture_1D_Proxy : aliased constant Texture_1D_Proxy_Target.Target; Texture_2D_Proxy : aliased constant Texture_2D_Proxy_Target.Target; Texture_3D_Proxy : aliased constant Texture_3D_Proxy_Target.Target; Texture_Cube_Map : aliased constant Texture_Cube_Map_Target; Texture_Cube_Map_Positive_X : aliased constant Cube_Map_Side_Target.Fillable_Target; Texture_Cube_Map_Negative_X : aliased constant Cube_Map_Side_Target.Fillable_Target; Texture_Cube_Map_Positive_Y : aliased constant Cube_Map_Side_Target.Fillable_Target; Texture_Cube_Map_Negative_Y : aliased constant Cube_Map_Side_Target.Fillable_Target; Texture_Cube_Map_Positive_Z : aliased constant Cube_Map_Side_Target.Fillable_Target; Texture_Cube_Map_Negative_Z : aliased constant Cube_Map_Side_Target.Fillable_Target; Texture_Cube_Map_Proxy : aliased constant Texture_2D_Proxy_Target.Target; Texture_Buffer : aliased constant Texture_Buffer_Target; function Target_From_Kind (Kind : Low_Level.Enums.Texture_Kind) return not null access constant Texture_Proxy'Class; private type Texture_Cube_Map_Target is new Texture_3D_Target.Target with null record; type Texture_Buffer_Target is new Texture_Target with null record; Texture_1D : aliased constant Texture_1D_Target.Fillable_Target := Texture_1D_Target.Fillable_Target' (Texture_Target'(Kind => Low_Level.Enums.Texture_1D) with null record); Texture_2D : aliased constant Texture_2D_Target.Fillable_Target := Texture_2D_Target.Fillable_Target' (Texture_Target'(Kind => Low_Level.Enums.Texture_2D) with null record); Texture_3D : aliased constant Texture_3D_Target.Fillable_Target := Texture_3D_Target.Fillable_Target' (Texture_Target'(Kind => Low_Level.Enums.Texture_3D) with null record); Texture_1D_Proxy : aliased constant Texture_1D_Proxy_Target.Target := Texture_1D_Proxy_Target.Target' (Texture_Proxy'(Kind => Low_Level.Enums.Proxy_Texture_1D) with null record); Texture_2D_Proxy : aliased constant Texture_2D_Proxy_Target.Target := Texture_2D_Proxy_Target.Target' (Texture_Proxy'(Kind => Low_Level.Enums.Proxy_Texture_2D) with null record); Texture_3D_Proxy : aliased constant Texture_3D_Proxy_Target.Target := Texture_3D_Proxy_Target.Target' (Texture_Proxy'(Kind => Low_Level.Enums.Proxy_Texture_3D) with null record); Texture_Cube_Map : aliased constant Texture_Cube_Map_Target := Texture_Cube_Map_Target' (Texture_Target'(Kind => Low_Level.Enums.Texture_Cube_Map) with null record); Texture_Cube_Map_Positive_X : aliased constant Cube_Map_Side_Target.Fillable_Target := Cube_Map_Side_Target.Fillable_Target' (Texture_Proxy'(Kind => Low_Level.Enums.Texture_Cube_Map_Positive_X) with null record); Texture_Cube_Map_Negative_X : aliased constant Cube_Map_Side_Target.Fillable_Target := Cube_Map_Side_Target.Fillable_Target' (Texture_Proxy'(Kind => Low_Level.Enums.Texture_Cube_Map_Negative_X) with null record); Texture_Cube_Map_Positive_Y : aliased constant Cube_Map_Side_Target.Fillable_Target := Cube_Map_Side_Target.Fillable_Target' (Texture_Proxy'(Kind => Low_Level.Enums.Texture_Cube_Map_Positive_Y) with null record); Texture_Cube_Map_Negative_Y : aliased constant Cube_Map_Side_Target.Fillable_Target := Cube_Map_Side_Target.Fillable_Target' (Texture_Proxy'(Kind => Low_Level.Enums.Texture_Cube_Map_Negative_Y) with null record); Texture_Cube_Map_Positive_Z : aliased constant Cube_Map_Side_Target.Fillable_Target := Cube_Map_Side_Target.Fillable_Target' (Texture_Proxy'(Kind => Low_Level.Enums.Texture_Cube_Map_Positive_Z) with null record); Texture_Cube_Map_Negative_Z : aliased constant Cube_Map_Side_Target.Fillable_Target := Cube_Map_Side_Target.Fillable_Target' (Texture_Proxy'(Kind => Low_Level.Enums.Texture_Cube_Map_Negative_Z) with null record); Texture_Cube_Map_Proxy : aliased constant Texture_2D_Proxy_Target.Target := Texture_2D_Proxy_Target.Target' (Texture_Proxy'(Kind => Low_Level.Enums.Proxy_Texture_Cube_Map) with null record); Texture_Buffer : aliased constant Texture_Buffer_Target := Texture_Buffer_Target' (Texture_Target'(Kind => Low_Level.Enums.Texture_Buffer) with null record); end GL.Objects.Textures.Targets;
zhmu/ananas
Ada
563
adb
-- { dg-do run } procedure Access_Test is type T1 is tagged null record; procedure Proc_1 (P : access T1'Class) is type Ref is access T1'Class; X : Ref := new T1'Class'(P.all); -- Should always work (no exception) begin null; end; procedure Proc_2 is type T2 is new T1 with null record; X2 : aliased T2; begin Proc_1 (X2'access); declare type T3 is new T1 with null record; X3 : aliased T3; begin Proc_1 (X3'access); end; end; begin Proc_2; end;
reznikmm/matreshka
Ada
4,067
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.Chart_Data_Label_Symbol_Attributes; package Matreshka.ODF_Chart.Data_Label_Symbol_Attributes is type Chart_Data_Label_Symbol_Attribute_Node is new Matreshka.ODF_Chart.Abstract_Chart_Attribute_Node and ODF.DOM.Chart_Data_Label_Symbol_Attributes.ODF_Chart_Data_Label_Symbol_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Chart_Data_Label_Symbol_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Chart_Data_Label_Symbol_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Chart.Data_Label_Symbol_Attributes;
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_Smil.Fill_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Smil_Fill_Attribute_Node is begin return Self : Smil_Fill_Attribute_Node do Matreshka.ODF_Smil.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Smil_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Smil_Fill_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Fill_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Smil_URI, Matreshka.ODF_String_Constants.Fill_Attribute, Smil_Fill_Attribute_Node'Tag); end Matreshka.ODF_Smil.Fill_Attributes;
zrmyers/VulkanAda
Ada
6,885
ads
-------------------------------------------------------------------------------- -- MIT License -- -- Copyright (c) 2020 Zane Myers -- -- 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 Vulkan.Math.GenDMatrix; with Vulkan.Math.Dvec4; use Vulkan.Math.GenDMatrix; use Vulkan.Math.Dvec4; -------------------------------------------------------------------------------- --< @group Vulkan Math Basic Types -------------------------------------------------------------------------------- --< @summary --< This package provides a single precision floating point matrix with 2 rows --< and 4 columns. -------------------------------------------------------------------------------- package Vulkan.Math.Dmat3x4 is pragma Preelaborate; pragma Pure; --< A 2x3 matrix of single-precision floating point numbers. subtype Vkm_Dmat3x4 is Vkm_Dmat( last_row_index => 2, last_column_index => 3); ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dmat3x4 type. --< --< @description --< Construct a 2x3 matrix with each component set to zero. --< --< @return --< A 2x3 matrix. ---------------------------------------------------------------------------- function Make_Dmat3x4 return Vkm_Dmat3x4 is (GDM.Make_GenMatrix(cN => 3, rN => 2)) with Inline; ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dmat3x4 type. --< --< @description --< Construct a 2x3 matrix with each component set to a different value. --< --< | value1 value3 value5 value7 | --< | value2 value4 value6 value8 | --< --< @param value1 --< The first value to set for the matrix. --< --< @param value2 --< The second value to set for the matrix. --< --< @param value3 --< The third value to set for the matrix. --< --< @param value4 --< The fourth value to set for the matrix. --< --< @param value5 --< The fifth value to set for the matrix. --< --< @param value6 --< The sixth value to set for the matrix. --< --< @param value7 --< The seventh value to set for the matrix. --< --< @param value8 --< The eighth value to set for the matrix. --< --< @param value9 --< The ninth value to set for the matrix. --< --< @param value10 --< The tenth value to set for the matrix. --< --< @param value11 --< The eleventh value to set for the matrix. --< --< @return --< A 3x4 matrix. ---------------------------------------------------------------------------- function Make_Dmat3x4 ( value1, value2 , value3 , value4 , value5, value6 , value7 , value8 , value9, value10, value11, value12 : in Vkm_Double) return Vkm_Dmat3x4 is (GDM.Make_GenMatrix( cN => 3, rN => 2, c0r0_val => value1, c0r1_val => value5, c0r2_val => value9, c1r0_val => value2, c1r1_val => value6, c1r2_val => value10, c2r0_val => value3, c2r1_val => value7, c2r2_val => value11, c3r0_val => value4, c3r1_val => value8, c3r2_val => value12)) with Inline; ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dmat3x4 type. --< --< @description --< Construct a 3x4 matrix with each row set to the value of a 4 dimmensional --< vector. --< --< | value1.x value1.y value1.z value1.w | --< | value2.x value2.y value2.z value2.w | --< --< @param value1 --< The first value to set for the matrix. --< --< @param value2 --< The second value to set for the matrix. --< --< @return --< A 3x4 matrix. ---------------------------------------------------------------------------- function Make_Dmat3x4 ( value1, value2, value3: in Vkm_Dvec4) return Vkm_Dmat3x4 is (GDM.Make_GenMatrix( cN => 3, rN => 2, c0r0_val => value1.x, c0r1_val => value2.x, c0r2_val => value3.x, c1r0_val => value1.y, c1r1_val => value2.y, c1r2_val => value3.y, c2r0_val => value1.z, c2r1_val => value2.z, c2r2_val => value3.z, c3r0_val => value1.w, c3r1_val => value2.w, c3r2_val => value3.w)) with Inline; ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dmat3x4 type. --< --< @description --< Construct a 2x3 matrix using values from an existing matrix. --< --< If the provided matrix has dimmensions that are not the same as this --< matrix, the corresponding element in the 4x4 identity matrix is used for --< out of bounds accesses. --< --< @param value1 --< The submatrix to extract values from. --< --< @return --< A 3x4 matrix. ---------------------------------------------------------------------------- function Make_Dmat3x4 ( value1 : in Vkm_Dmat) return Vkm_Dmat3x4 is (GDM.Make_GenMatrix( cN => 3, rN => 2, c0r0_val => value1.c0r0, c0r1_val => value1.c0r1, c0r2_val => value1.c0r2, c1r0_val => value1.c1r0, c1r1_val => value1.c1r1, c1r2_val => value1.c1r2, c2r0_val => value1.c2r0, c2r1_val => value1.c2r1, c2r2_val => value1.c2r2, c3r0_val => value1.c3r0, c3r1_val => value1.c3r1, c3r2_val => value1.c3r2)) with Inline; end Vulkan.Math.Dmat3x4;
reznikmm/matreshka
Ada
3,699
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_Opacity_Attributes is pragma Preelaborate; type ODF_Draw_Opacity_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Draw_Opacity_Attribute_Access is access all ODF_Draw_Opacity_Attribute'Class with Storage_Size => 0; end ODF.DOM.Draw_Opacity_Attributes;
reznikmm/matreshka
Ada
7,150
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. ------------------------------------------------------------------------------ -- RadialGradient is a kind of gradient that fills a graphical element by -- smoothly changing color values in a circle. ------------------------------------------------------------------------------ with AMF.DG.Gradients; package AMF.DG.Radial_Gradients is pragma Preelaborate; type DG_Radial_Gradient is limited interface and AMF.DG.Gradients.DG_Gradient; type DG_Radial_Gradient_Access is access all DG_Radial_Gradient'Class; for DG_Radial_Gradient_Access'Storage_Size use 0; not overriding function Get_Center_X (Self : not null access constant DG_Radial_Gradient) return AMF.Real is abstract; -- Getter of RadialGradient::centerX. -- -- a real number (>=0 and >=1) representing a ratio of the graphical -- element's width that is the x center point of the gradient. not overriding procedure Set_Center_X (Self : not null access DG_Radial_Gradient; To : AMF.Real) is abstract; -- Setter of RadialGradient::centerX. -- -- a real number (>=0 and >=1) representing a ratio of the graphical -- element's width that is the x center point of the gradient. not overriding function Get_Center_Y (Self : not null access constant DG_Radial_Gradient) return AMF.Real is abstract; -- Getter of RadialGradient::centerY. -- -- a real number (>=0 and >=1) representing a ratio of the graphical -- element's width that is the y center point of the gradient. not overriding procedure Set_Center_Y (Self : not null access DG_Radial_Gradient; To : AMF.Real) is abstract; -- Setter of RadialGradient::centerY. -- -- a real number (>=0 and >=1) representing a ratio of the graphical -- element's width that is the y center point of the gradient. not overriding function Get_Radius (Self : not null access constant DG_Radial_Gradient) return AMF.Real is abstract; -- Getter of RadialGradient::radius. -- -- a real number (>=0 and >=1) representing a ratio of the graphical -- element's size that is the radius of the gradient. not overriding procedure Set_Radius (Self : not null access DG_Radial_Gradient; To : AMF.Real) is abstract; -- Setter of RadialGradient::radius. -- -- a real number (>=0 and >=1) representing a ratio of the graphical -- element's size that is the radius of the gradient. not overriding function Get_Focus_X (Self : not null access constant DG_Radial_Gradient) return AMF.Real is abstract; -- Getter of RadialGradient::focusX. -- -- a real number (>=0 and >=1) representing a ratio of the graphical -- element's width that is the x focus point of the gradient. not overriding procedure Set_Focus_X (Self : not null access DG_Radial_Gradient; To : AMF.Real) is abstract; -- Setter of RadialGradient::focusX. -- -- a real number (>=0 and >=1) representing a ratio of the graphical -- element's width that is the x focus point of the gradient. not overriding function Get_Focus_Y (Self : not null access constant DG_Radial_Gradient) return AMF.Real is abstract; -- Getter of RadialGradient::focusY. -- -- a real number (>=0 and >=1) representing a ratio of the graphical -- element's width that is the y focus point of the gradient. not overriding procedure Set_Focus_Y (Self : not null access DG_Radial_Gradient; To : AMF.Real) is abstract; -- Setter of RadialGradient::focusY. -- -- a real number (>=0 and >=1) representing a ratio of the graphical -- element's width that is the y focus point of the gradient. end AMF.DG.Radial_Gradients;
Fabien-Chouteau/Ada_Drivers_Library
Ada
4,344
ads
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2016, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ with nRF51.Device; with nRF51.GPIO; package MicroBit is -- http://tech.microbit.org/hardware/edgeconnector_ds/ MB_P0 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P03; -- 0 pad on edge connector MB_P1 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P02; -- 1 pad on edge connector MB_P2 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P01; -- 2 pad on edge connector MB_P3 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P04; -- Display column 1 MB_P4 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P05; -- Display column 2 MB_P5 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P17; -- Button A MB_P6 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P12; -- Display column 9 MB_P7 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P11; -- Display column 8 MB_P8 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P18; MB_P9 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P10; -- Display column 7 MB_P10 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P06; -- Display column 3 MB_P11 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P26; -- Button B MB_P12 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P20; MB_P13 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P23; -- SCK MB_P14 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P22; -- MISO MB_P15 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P21; -- MOSI MB_P16 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P16; MB_P19 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P00; -- SCL MB_P20 : nRF51.GPIO.GPIO_Point renames nRF51.Device.P30; -- SDA MB_SCK : nRF51.GPIO.GPIO_Point renames MB_P13; MB_MISO : nRF51.GPIO.GPIO_Point renames MB_P14; MB_MOSI : nRF51.GPIO.GPIO_Point renames MB_P15; MB_SCL : nRF51.GPIO.GPIO_Point renames MB_P19; MB_SDA : nRF51.GPIO.GPIO_Point renames MB_P20; MB_UART_TX : nRF51.GPIO.GPIO_Point renames nRF51.Device.P24; MB_UART_RX : nRF51.GPIO.GPIO_Point renames nRF51.Device.P25; end MicroBit;
micahwelf/FLTK-Ada
Ada
7,322
adb
with Interfaces.C, System; use type Interfaces.C.int, System.Address; package body FLTK.Images is function new_fl_image (W, H, D : in Interfaces.C.int) return System.Address; pragma Import (C, new_fl_image, "new_fl_image"); pragma Inline (new_fl_image); procedure free_fl_image (I : in System.Address); pragma Import (C, free_fl_image, "free_fl_image"); pragma Inline (free_fl_image); function fl_image_get_rgb_scaling return Interfaces.C.int; pragma Import (C, fl_image_get_rgb_scaling, "fl_image_get_rgb_scaling"); pragma Inline (fl_image_get_rgb_scaling); procedure fl_image_set_rgb_scaling (T : in Interfaces.C.int); pragma Import (C, fl_image_set_rgb_scaling, "fl_image_set_rgb_scaling"); pragma Inline (fl_image_set_rgb_scaling); function fl_image_copy (I : in System.Address; W, H : in Interfaces.C.int) return System.Address; pragma Import (C, fl_image_copy, "fl_image_copy"); pragma Inline (fl_image_copy); function fl_image_copy2 (I : in System.Address) return System.Address; pragma Import (C, fl_image_copy2, "fl_image_copy2"); pragma Inline (fl_image_copy2); procedure fl_image_color_average (I : in System.Address; C : in Interfaces.C.int; B : in Interfaces.C.C_float); pragma Import (C, fl_image_color_average, "fl_image_color_average"); pragma Inline (fl_image_color_average); procedure fl_image_desaturate (I : in System.Address); pragma Import (C, fl_image_desaturate, "fl_image_desaturate"); pragma Inline (fl_image_desaturate); procedure fl_image_inactive (I : in System.Address); pragma Import (C, fl_image_inactive, "fl_image_inactive"); pragma Inline (fl_image_inactive); function fl_image_w (I : in System.Address) return Interfaces.C.int; pragma Import (C, fl_image_w, "fl_image_w"); pragma Inline (fl_image_w); function fl_image_h (I : in System.Address) return Interfaces.C.int; pragma Import (C, fl_image_h, "fl_image_h"); pragma Inline (fl_image_h); function fl_image_d (I : in System.Address) return Interfaces.C.int; pragma Import (C, fl_image_d, "fl_image_d"); pragma Inline (fl_image_d); procedure fl_image_draw (I : in System.Address; X, Y : in Interfaces.C.int); pragma Import (C, fl_image_draw, "fl_image_draw"); pragma Inline (fl_image_draw); procedure fl_image_draw2 (I : in System.Address; X, Y, W, H, CX, CY : in Interfaces.C.int); pragma Import (C, fl_image_draw2, "fl_image_draw2"); pragma Inline (fl_image_draw2); procedure fl_image_draw_empty (I : in System.Address; X, Y : in Interfaces.C.int); pragma Import (C, fl_image_draw_empty, "fl_image_draw_empty"); pragma Inline (fl_image_draw_empty); overriding procedure Finalize (This : in out Image) is begin if This.Void_Ptr /= System.Null_Address and then This in Image'Class then free_fl_image (This.Void_Ptr); This.Void_Ptr := System.Null_Address; end if; end Finalize; package body Forge is function Create (Width, Height, Depth : in Natural) return Image is begin return This : Image do This.Void_Ptr := new_fl_image (Interfaces.C.int (Width), Interfaces.C.int (Height), Interfaces.C.int (Depth)); case fl_image_fail (This.Void_Ptr) is when 1 => raise No_Image_Error; when 2 => raise File_Access_Error; when 3 => raise Format_Error; when others => null; end case; end return; end Create; end Forge; function Get_Copy_Algorithm return Scaling_Kind is begin return Scaling_Kind'Val (fl_image_get_rgb_scaling); end Get_Copy_Algorithm; procedure Set_Copy_Algorithm (To : in Scaling_Kind) is begin fl_image_set_rgb_scaling (Scaling_Kind'Pos (To)); end Set_Copy_Algorithm; function Copy (This : in Image; Width, Height : in Natural) return Image'Class is begin return Copied : Image do Copied.Void_Ptr := fl_image_copy (This.Void_Ptr, Interfaces.C.int (Width), Interfaces.C.int (Height)); end return; end Copy; function Copy (This : in Image) return Image'Class is begin return Copied : Image do Copied.Void_Ptr := fl_image_copy2 (This.Void_Ptr); end return; end Copy; procedure Color_Average (This : in out Image; Col : in Color; Amount : in Blend) is begin fl_image_color_average (This.Void_Ptr, Interfaces.C.int (Col), Interfaces.C.C_float (Amount)); end Color_Average; procedure Desaturate (This : in out Image) is begin fl_image_desaturate (This.Void_Ptr); end Desaturate; procedure Inactive (This : in out Image) is begin fl_image_inactive (This.Void_Ptr); end Inactive; function Is_Empty (This : in Image) return Boolean is begin return fl_image_fail (This.Void_Ptr) /= 0; end Is_Empty; function Get_W (This : in Image) return Natural is begin return Natural (fl_image_w (This.Void_Ptr)); end Get_W; function Get_H (This : in Image) return Natural is begin return Natural (fl_image_h (This.Void_Ptr)); end Get_H; function Get_D (This : in Image) return Natural is begin return Natural (fl_image_d (This.Void_Ptr)); end Get_D; procedure Draw (This : in Image; X, Y : in Integer) is begin fl_image_draw (This.Void_Ptr, Interfaces.C.int (X), Interfaces.C.int (Y)); end Draw; procedure Draw (This : in Image; X, Y, W, H : in Integer; CX, CY : in Integer := 0) is begin fl_image_draw2 (This.Void_Ptr, Interfaces.C.int (X), Interfaces.C.int (Y), Interfaces.C.int (W), Interfaces.C.int (H), Interfaces.C.int (CX), Interfaces.C.int (CY)); end Draw; procedure Draw_Empty (This : in Image; X, Y : in Integer) is begin fl_image_draw_empty (This.Void_Ptr, Interfaces.C.int (X), Interfaces.C.int (Y)); end Draw_Empty; end FLTK.Images;
stcarrez/dynamo
Ada
3,971
adb
----------------------------------------------------------------------- -- gen-commands-docs -- Extract and generate documentation for the project -- Copyright (C) 2012, 2015, 2017, 2018, 2021 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 GNAT.Command_Line; with Ada.Text_IO; with Ada.Directories; with Gen.Artifacts.Docs; package body Gen.Commands.Docs is use GNAT.Command_Line; -- ------------------------------ -- Execute the command with the arguments. -- ------------------------------ overriding procedure Execute (Cmd : in out Command; Name : in String; Args : in Argument_List'Class; Generator : in out Gen.Generator.Handler) is pragma Unreferenced (Cmd, Name, Args); Doc : Gen.Artifacts.Docs.Artifact; Arg1 : constant String := Get_Argument; Arg2 : constant String := Get_Argument; Footer : Boolean := True; Fmt : Gen.Artifacts.Docs.Doc_Format := Gen.Artifacts.Docs.DOC_WIKI_GOOGLE; begin if Ada.Directories.Exists ("dynamo.xml") then Generator.Read_Project ("dynamo.xml", False); end if; if Arg1'Length = 0 then Generator.Error ("Missing target directory"); return; elsif Arg1 (Arg1'First) /= '-' then if Arg2'Length /= 0 then Generator.Error ("Invalid markup option " & Arg1); return; end if; -- Setup the target directory where the distribution is created. Generator.Set_Result_Directory (Arg1); else if Arg1 = "-markdown" then Fmt := Gen.Artifacts.Docs.DOC_MARKDOWN; elsif Arg1 = "-google" then Fmt := Gen.Artifacts.Docs.DOC_WIKI_GOOGLE; elsif Arg1 = "-pandoc" then Fmt := Gen.Artifacts.Docs.DOC_MARKDOWN; Footer := False; else Generator.Error ("Invalid markup option " & Arg1); return; end if; if Arg2'Length = 0 then Generator.Error ("Missing target directory"); return; end if; Generator.Set_Result_Directory (Arg2); end if; Doc.Set_Format (Fmt, Footer); Doc.Read_Links (Generator.Get_Project_Property ("links", "links.txt")); Doc.Generate (Generator); end Execute; -- ------------------------------ -- Write the help associated with the command. -- ------------------------------ overriding procedure Help (Cmd : in out Command; Name : in String; Generator : in out Gen.Generator.Handler) is pragma Unreferenced (Cmd, Name, Generator); use Ada.Text_IO; begin Put_Line ("build-doc: Extract and generate the project documentation"); Put_Line ("Usage: build-doc [-markdown|-google|-pandoc] target-dir"); New_Line; Put_Line (" Extract the documentation from the project source files and generate the"); Put_Line (" project documentation. The following files are scanned:"); Put_Line (" - Ada specifications (src/*.ads)"); Put_Line (" - XML configuration files (config/*.xml)"); Put_Line (" - XML database model files (db/*.xml)"); end Help; end Gen.Commands.Docs;
reznikmm/matreshka
Ada
3,593
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 XML.DOM.Elements; package ODF.DOM.Elements.Text.P is type ODF_Text_P is new XML.DOM.Elements.DOM_Element with private; private type ODF_Text_P is new XML.DOM.Elements.DOM_Element with null record; end ODF.DOM.Elements.Text.P;
reznikmm/matreshka
Ada
6,457
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012-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$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ with AMF.Elements; with AMF.OCL; with AMF.UML; with Matreshka.Internals.Strings; package AMF.Internals.Tables.OCL_Types is pragma Preelaborate; type Element_Kinds is (E_None, E_OCL_Any_Type, E_OCL_Association_Class_Call_Exp, E_OCL_Bag_Type, E_OCL_Boolean_Literal_Exp, E_OCL_Collection_Item, E_OCL_Collection_Literal_Exp, E_OCL_Collection_Range, E_OCL_Collection_Type, E_OCL_Enum_Literal_Exp, E_OCL_Expression_In_Ocl, E_OCL_If_Exp, E_OCL_Integer_Literal_Exp, E_OCL_Invalid_Literal_Exp, E_OCL_Invalid_Type, E_OCL_Iterate_Exp, E_OCL_Iterator_Exp, E_OCL_Let_Exp, E_OCL_Message_Exp, E_OCL_Message_Type, E_OCL_Null_Literal_Exp, E_OCL_Operation_Call_Exp, E_OCL_Ordered_Set_Type, E_OCL_Property_Call_Exp, E_OCL_Real_Literal_Exp, E_OCL_Sequence_Type, E_OCL_Set_Type, E_OCL_State_Exp, E_OCL_String_Literal_Exp, E_OCL_Template_Parameter_Type, E_OCL_Tuple_Literal_Exp, E_OCL_Tuple_Literal_Part, E_OCL_Tuple_Type, E_OCL_Type_Exp, E_OCL_Unlimited_Natural_Literal_Exp, E_OCL_Unspecified_Value_Exp, E_OCL_Variable, E_OCL_Variable_Exp, E_OCL_Void_Type); type Member_Kinds is (M_None, M_Boolean, M_Collection_Kind, M_Collection_Of_Element, M_Collection_Of_String, M_Element, M_Integer, M_Real, M_String, M_Unlimited_Natural, M_Visibility_Kind, M_Visibility_Kind_Holder); type Member_Record (Kind : Member_Kinds := M_None) is record case Kind is when M_None => null; when M_Boolean => Boolean_Value : Boolean; when M_Collection_Kind => Collection_Kind_Value : AMF.OCL.OCL_Collection_Kind; when M_Collection_Of_Element => Collection : AMF.Internals.AMF_Collection_Of_Element; when M_Collection_Of_String => String_Collection : AMF.Internals.AMF_Collection_Of_String; when M_Element => Link : AMF.Internals.AMF_Link; when M_Integer => Integer_Value : Integer; when M_Real => Real_Value : AMF.Real; when M_String => String_Value : Matreshka.Internals.Strings.Shared_String_Access; when M_Unlimited_Natural => Unlimited_Natural_Value : AMF.Unlimited_Natural; when M_Visibility_Kind => Visibility_Kind_Value : AMF.UML.UML_Visibility_Kind; when M_Visibility_Kind_Holder => Visibility_Kind_Holder : AMF.UML.Optional_UML_Visibility_Kind; end case; end record; type Member_Array is array (Natural range 0 .. 18) of Member_Record; type Element_Record is record Kind : Element_Kinds := E_None; Extent : AMF.Internals.AMF_Extent; Proxy : AMF.Elements.Element_Access; Member : Member_Array; end record; end AMF.Internals.Tables.OCL_Types;
KipodAfterFree/KAF-2019-FireHog
Ada
8,145
adb
------------------------------------------------------------------------------ -- -- -- GNAT ncurses Binding Samples -- -- -- -- Sample.Keyboard_Handler -- -- -- -- B O D Y -- -- -- ------------------------------------------------------------------------------ -- 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 <[email protected]> 1996 -- Version Control -- $Revision: 1.5 $ -- Binding Version 00.93 ------------------------------------------------------------------------------ with Ada.Strings; use Ada.Strings; with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants; with Ada.Characters.Latin_1; use Ada.Characters.Latin_1; with Ada.Characters.Handling; use Ada.Characters.Handling; with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels; with Terminal_Interface.Curses.Forms; use Terminal_Interface.Curses.Forms; with Terminal_Interface.Curses.Forms.Field_Types.Enumeration; use Terminal_Interface.Curses.Forms.Field_Types.Enumeration; with Sample.Header_Handler; use Sample.Header_Handler; with Sample.Form_Demo.Aux; use Sample.Form_Demo.Aux; with Sample.Manifest; use Sample.Manifest; with Sample.Form_Demo.Handler; -- This package contains a centralized keyboard handler used throughout -- this example. The handler establishes a timeout mechanism that provides -- periodical updates of the common header lines used in this example. -- package body Sample.Keyboard_Handler is In_Command : Boolean := False; function Get_Key (Win : Window := Standard_Window) return Real_Key_Code is K : Real_Key_Code; function Command return Real_Key_Code; function Command return Real_Key_Code is function My_Driver (F : Form; C : Key_Code; P : Panel) return Boolean; package Fh is new Sample.Form_Demo.Handler (My_Driver); type Label_Array is array (Label_Number) of String (1 .. 8); Labels : Label_Array; FA : Field_Array_Access := new Field_Array' (Make (0, 0, "Command:"), Make (Top => 0, Left => 9, Width => Columns - 11), Null_Field); K : Real_Key_Code := Key_None; N : Natural := 0; function My_Driver (F : Form; C : Key_Code; P : Panel) return Boolean is Ch : Character; begin if C in User_Key_Code'Range and then C = QUIT then if Driver (F, F_Validate_Field) = Form_Ok then K := Key_None; return True; end if; elsif C in Normal_Key_Code'Range then Ch := Character'Val (C); if (Ch = LF or else Ch = CR) then if Driver (F, F_Validate_Field) = Form_Ok then declare Buffer : String (1 .. Positive (Columns - 11)); Cmdc : String (1 .. 8); begin Get_Buffer (Fld => FA (2), Str => Buffer); Trim (Buffer, Left); if Buffer (1) /= ' ' then Cmdc := To_Upper (Buffer (Cmdc'Range)); for I in Labels'Range loop if Cmdc = Labels (I) then K := Function_Key_Code (Function_Key_Number (I)); exit; end if; end loop; end if; return True; end; end if; end if; end if; return False; end My_Driver; begin In_Command := True; for I in Label_Number'Range loop Get_Soft_Label_Key (I, Labels (I)); Trim (Labels (I), Left); Translate (Labels (I), Upper_Case_Map); if Labels (I) (1) /= ' ' then N := N + 1; end if; end loop; if N > 0 then -- some labels were really set declare Enum_Info : Enumeration_Info (N); Enum_Field : Enumeration_Field; J : Positive := Enum_Info.Names'First; Frm : Form := Create (FA); begin for I in Label_Number'Range loop if Labels (I) (1) /= ' ' then Enum_Info.Names (J) := new String'(Labels (I)); J := J + 1; end if; end loop; Enum_Field := Create (Enum_Info, True); Set_Field_Type (FA (2), Enum_Field); Set_Background (FA (2), Normal_Video); Fh.Drive_Me (Frm, Lines - 3, 0); Delete (Frm); Update_Panels; Update_Screen; end; end if; Free (FA, True); In_Command := False; return K; end Command; begin Set_Timeout_Mode (Win, Delayed, 30000); loop K := Get_Keystroke (Win); if K = Key_None then -- a timeout occured Update_Header_Window; elsif K = 3 and then not In_Command then -- CTRL-C K := Command; exit when K /= Key_None; else exit; end if; end loop; return K; end Get_Key; procedure Init_Keyboard_Handler is begin null; end Init_Keyboard_Handler; end Sample.Keyboard_Handler;
zhmu/ananas
Ada
151,483
adb
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E M _ C A S E -- -- -- -- B o d y -- -- -- -- Copyright (C) 1996-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 Elists; use Elists; with Errout; use Errout; with Namet; use Namet; with Nlists; use Nlists; with Nmake; use Nmake; with Opt; use Opt; with Sem; use Sem; with Sem_Aux; use Sem_Aux; with Sem_Eval; use Sem_Eval; with Sem_Res; use Sem_Res; with Sem_Util; use Sem_Util; with Sem_Type; use Sem_Type; with Snames; use Snames; with Stand; use Stand; with Sinfo; use Sinfo; with Sinfo.Nodes; use Sinfo.Nodes; with Sinfo.Utils; use Sinfo.Utils; with Stringt; use Stringt; with Table; with Tbuild; use Tbuild; with Uintp; use Uintp; with Ada.Unchecked_Deallocation; with GNAT.Heap_Sort_G; with GNAT.Sets; package body Sem_Case is type Choice_Bounds is record Lo : Node_Id; Hi : Node_Id; Node : Node_Id; end record; -- Represent one choice bounds entry with Lo and Hi values, Node points -- to the choice node itself. type Choice_Table_Type is array (Nat range <>) of Choice_Bounds; -- Table type used to sort the choices present in a case statement or -- record variant. The actual entries are stored in 1 .. Last, but we -- have a 0 entry for use in sorting. ----------------------- -- Local Subprograms -- ----------------------- procedure Check_Choice_Set (Choice_Table : in out Choice_Table_Type; Bounds_Type : Entity_Id; Subtyp : Entity_Id; Others_Present : Boolean; Case_Node : Node_Id); -- This is the procedure which verifies that a set of case alternatives -- or record variant choices has no duplicates, and covers the range -- specified by Bounds_Type. Choice_Table contains the discrete choices -- to check. These must start at position 1. -- -- Furthermore Choice_Table (0) must exist. This element is used by -- the sorting algorithm as a temporary. Others_Present is a flag -- indicating whether or not an Others choice is present. Finally -- Msg_Sloc gives the source location of the construct containing the -- choices in the Choice_Table. -- -- Bounds_Type is the type whose range must be covered by the alternatives -- -- Subtyp is the subtype of the expression. If its bounds are nonstatic -- the alternatives must cover its base type. function Choice_Image (Value : Uint; Ctype : Entity_Id) return Name_Id; -- Given a Pos value of enumeration type Ctype, returns the name -- ID of an appropriate string to be used in error message output. function Has_Static_Discriminant_Constraint (Subtyp : Entity_Id) return Boolean; -- Returns True if the given subtype is subject to a discriminant -- constraint and at least one of the constraint values is nonstatic. package Composite_Case_Ops is function Box_Value_Required (Subtyp : Entity_Id) return Boolean; -- If result is True, then the only allowed value (in a choice -- aggregate) for a component of this (sub)type is a box. This rule -- means that such a component can be ignored in case alternative -- selection. This in turn implies that it is ok if the component -- type doesn't meet the usual restrictions, such as not being an -- access/task/protected type, since nobody is going to look -- at it. function Choice_Count (Alternatives : List_Id) return Nat; -- The sum of the number of choices for each alternative in the given -- list. function Normalized_Case_Expr_Type (Case_Statement : Node_Id) return Entity_Id; -- Usually returns the Etype of the selector expression of the -- case statement. However, in the case of a constrained composite -- subtype with a nonstatic constraint, returns the unconstrained -- base type. function Scalar_Part_Count (Subtyp : Entity_Id) return Nat; -- Given the composite type Subtyp of a case selector, returns the -- number of scalar parts in an object of this type. This is the -- dimensionality of the associated Cartesian product space. package Array_Case_Ops is function Array_Choice_Length (Choice : Node_Id) return Nat; -- Given a choice expression of an array type, returns its length. function Unconstrained_Array_Effective_Length (Array_Type : Entity_Id; Case_Statement : Node_Id) return Nat; -- If the nominal subtype of the case selector is unconstrained, -- then use the length of the longest choice of the case statement. -- Components beyond that index value will not influence the case -- selection decision. function Unconstrained_Array_Scalar_Part_Count (Array_Type : Entity_Id; Case_Statement : Node_Id) return Nat; -- Same as Scalar_Part_Count except that the value used for the -- "length" of the array subtype being cased on is determined by -- calling Unconstrained_Array_Effective_Length. end Array_Case_Ops; generic Case_Statement : Node_Id; package Choice_Analysis is use Array_Case_Ops; type Alternative_Id is new Int range 1 .. List_Length (Alternatives (Case_Statement)); type Choice_Id is new Int range 1 .. Choice_Count (Alternatives (Case_Statement)); Case_Expr_Type : constant Entity_Id := Normalized_Case_Expr_Type (Case_Statement); Unconstrained_Array_Case : constant Boolean := Is_Array_Type (Case_Expr_Type) and then not Is_Constrained (Case_Expr_Type); -- If Unconstrained_Array_Case is True, choice lengths may differ: -- when "Aaa" | "Bb" | "C" | "" => -- -- Strictly speaking, the name "Unconstrained_Array_Case" is -- slightly imprecise; a subtype with a nonstatic constraint is -- also treated as unconstrained (see Normalize_Case_Expr_Type). type Part_Id is new Int range 1 .. (if Unconstrained_Array_Case then Unconstrained_Array_Scalar_Part_Count (Case_Expr_Type, Case_Statement) else Scalar_Part_Count (Case_Expr_Type)); type Discrete_Range_Info is record Low, High : Uint; end record; type Composite_Range_Info is array (Part_Id) of Discrete_Range_Info; type Choice_Range_Info (Is_Others : Boolean := False) is record case Is_Others is when False => Ranges : Composite_Range_Info; when True => null; end case; end record; type Choices_Range_Info is array (Choice_Id) of Choice_Range_Info; package Value_Sets is type Value_Set is private; -- A set of points in the Cartesian product space defined -- by the composite type of the case selector. -- Implemented as an access type. type Set_Comparison is (Disjoint, Equal, Contains, Contained_By, Overlaps); function Compare (S1, S2 : Value_Set) return Set_Comparison; -- If either argument (or both) is empty, result is Disjoint. -- Otherwise, result is Equal if the two sets are equal. Empty : constant Value_Set; function Matching_Values (Info : Composite_Range_Info) return Value_Set; -- The Cartesian product of the given array of ranges -- (excluding any values outside the Cartesian product of the -- component ranges). procedure Union (Target : in out Value_Set; Source : Value_Set); -- Add elements of Source into Target procedure Remove (Target : in out Value_Set; Source : Value_Set); -- Remove elements of Source from Target function Complement_Is_Empty (Set : Value_Set) return Boolean; -- Return True iff the set is "maximal", in the sense that it -- includes every value in the Cartesian product of the -- component ranges. procedure Free_Value_Sets; -- Reclaim storage associated with implementation of this package. private type Value_Set is new Natural; -- An index for a table that will be declared in the package body. Empty : constant Value_Set := 0; end Value_Sets; type Single_Choice_Info (Is_Others : Boolean := False) is record Alternative : Alternative_Id; case Is_Others is when False => Matches : Value_Sets.Value_Set; when True => null; end case; end record; type Choices_Info is array (Choice_Id) of Single_Choice_Info; function Analysis return Choices_Info; -- Parse the case choices in order to determine the set of -- matching values associated with each choice. type Bound_Values is array (Positive range <>) of Node_Id; end Choice_Analysis; end Composite_Case_Ops; procedure Expand_Others_Choice (Case_Table : Choice_Table_Type; Others_Choice : Node_Id; Choice_Type : Entity_Id); -- The case table is the table generated by a call to Check_Choices -- (with just 1 .. Last_Choice entries present). Others_Choice is a -- pointer to the N_Others_Choice node (this routine is only called if -- an others choice is present), and Choice_Type is the discrete type -- of the bounds. The effect of this call is to analyze the cases and -- determine the set of values covered by others. This choice list is -- set in the Others_Discrete_Choices field of the N_Others_Choice node. ---------------------- -- Check_Choice_Set -- ---------------------- procedure Check_Choice_Set (Choice_Table : in out Choice_Table_Type; Bounds_Type : Entity_Id; Subtyp : Entity_Id; Others_Present : Boolean; Case_Node : Node_Id) is Predicate_Error : Boolean := False; -- Flag to prevent cascaded errors when a static predicate is known to -- be violated by one choice. Num_Choices : constant Nat := Choice_Table'Last; procedure Check_Against_Predicate (Pred : in out Node_Id; Choice : Choice_Bounds; Prev_Lo : in out Uint; Prev_Hi : in out Uint; Error : in out Boolean); -- Determine whether a choice covers legal values as defined by a static -- predicate set. Pred is a static predicate range. Choice is the choice -- to be examined. Prev_Lo and Prev_Hi are the bounds of the previous -- choice that covered a predicate set. Error denotes whether the check -- found an illegal intersection. procedure Check_Duplicates; -- Check for duplicate choices, and call Dup_Choice if there are any -- such errors. Note that predicates are irrelevant here. procedure Dup_Choice (Lo, Hi : Uint; C : Node_Id); -- Post message "duplication of choice value(s) bla bla at xx". Message -- is posted at location C. Caller sets Error_Msg_Sloc for xx. procedure Explain_Non_Static_Bound; -- Called when we find a nonstatic bound, requiring the base type to -- be covered. Provides where possible a helpful explanation of why the -- bounds are nonstatic, since this is not always obvious. function Lt_Choice (C1, C2 : Natural) return Boolean; -- Comparison routine for comparing Choice_Table entries. Use the lower -- bound of each Choice as the key. procedure Missing_Choice (Value1 : Node_Id; Value2 : Node_Id); procedure Missing_Choice (Value1 : Node_Id; Value2 : Uint); procedure Missing_Choice (Value1 : Uint; Value2 : Node_Id); procedure Missing_Choice (Value1 : Uint; Value2 : Uint); -- Issue an error message indicating that there are missing choices, -- followed by the image of the missing choices themselves which lie -- between Value1 and Value2 inclusive. procedure Missing_Choices (Pred : Node_Id; Prev_Hi : Uint); -- Emit an error message for each non-covered static predicate set. -- Prev_Hi denotes the upper bound of the last choice covering a set. procedure Move_Choice (From : Natural; To : Natural); -- Move routine for sorting the Choice_Table package Sorting is new GNAT.Heap_Sort_G (Move_Choice, Lt_Choice); ----------------------------- -- Check_Against_Predicate -- ----------------------------- procedure Check_Against_Predicate (Pred : in out Node_Id; Choice : Choice_Bounds; Prev_Lo : in out Uint; Prev_Hi : in out Uint; Error : in out Boolean) is procedure Illegal_Range (Loc : Source_Ptr; Lo : Uint; Hi : Uint); -- Emit an error message regarding a choice that clashes with the -- legal static predicate sets. Loc is the location of the choice -- that introduced the illegal range. Lo .. Hi is the range. function Inside_Range (Lo : Uint; Hi : Uint; Val : Uint) return Boolean; -- Determine whether position Val within a discrete type is within -- the range Lo .. Hi inclusive. ------------------- -- Illegal_Range -- ------------------- procedure Illegal_Range (Loc : Source_Ptr; Lo : Uint; Hi : Uint) is begin Error_Msg_Name_1 := Chars (Bounds_Type); -- Single value if Lo = Hi then if Is_Integer_Type (Bounds_Type) then Error_Msg_Uint_1 := Lo; Error_Msg ("static predicate on % excludes value ^!", Loc); else Error_Msg_Name_2 := Choice_Image (Lo, Bounds_Type); Error_Msg ("static predicate on % excludes value %!", Loc); end if; -- Range else if Is_Integer_Type (Bounds_Type) then Error_Msg_Uint_1 := Lo; Error_Msg_Uint_2 := Hi; Error_Msg ("static predicate on % excludes range ^ .. ^!", Loc); else Error_Msg_Name_2 := Choice_Image (Lo, Bounds_Type); Error_Msg_Name_3 := Choice_Image (Hi, Bounds_Type); Error_Msg ("static predicate on % excludes range % .. %!", Loc); end if; end if; end Illegal_Range; ------------------ -- Inside_Range -- ------------------ function Inside_Range (Lo : Uint; Hi : Uint; Val : Uint) return Boolean is begin return Lo <= Val and then Val <= Hi; end Inside_Range; -- Local variables Choice_Hi : constant Uint := Expr_Value (Choice.Hi); Choice_Lo : constant Uint := Expr_Value (Choice.Lo); Loc : Source_Ptr; LocN : Node_Id; Next_Hi : Uint; Next_Lo : Uint; Pred_Hi : Uint; Pred_Lo : Uint; -- Start of processing for Check_Against_Predicate begin -- Find the proper error message location if Present (Choice.Node) then LocN := Choice.Node; else LocN := Case_Node; end if; Loc := Sloc (LocN); if Present (Pred) then Pred_Lo := Expr_Value (Low_Bound (Pred)); Pred_Hi := Expr_Value (High_Bound (Pred)); -- Previous choices managed to satisfy all static predicate sets else Illegal_Range (Loc, Choice_Lo, Choice_Hi); Error := True; return; end if; -- Step 1: Ignore duplicate choices, other than to set the flag, -- because these were already detected by Check_Duplicates. if Inside_Range (Choice_Lo, Choice_Hi, Prev_Lo) or else Inside_Range (Choice_Lo, Choice_Hi, Prev_Hi) then Error := True; -- Step 2: Detect full coverage -- Choice_Lo Choice_Hi -- +============+ -- Pred_Lo Pred_Hi elsif Choice_Lo = Pred_Lo and then Choice_Hi = Pred_Hi then Prev_Lo := Choice_Lo; Prev_Hi := Choice_Hi; Next (Pred); -- Step 3: Detect all cases where a choice mentions values that are -- not part of the static predicate sets. -- Choice_Lo Choice_Hi Pred_Lo Pred_Hi -- +-----------+ . . . . . +=========+ -- ^ illegal ^ elsif Choice_Lo < Pred_Lo and then Choice_Hi < Pred_Lo then Illegal_Range (Loc, Choice_Lo, Choice_Hi); Error := True; -- Choice_Lo Pred_Lo Choice_Hi Pred_Hi -- +-----------+=========+===========+ -- ^ illegal ^ elsif Choice_Lo < Pred_Lo and then Inside_Range (Pred_Lo, Pred_Hi, Choice_Hi) then Illegal_Range (Loc, Choice_Lo, Pred_Lo - 1); Error := True; -- Pred_Lo Pred_Hi Choice_Lo Choice_Hi -- +=========+ . . . . +-----------+ -- ^ illegal ^ elsif Pred_Lo < Choice_Lo and then Pred_Hi < Choice_Lo then if Others_Present then -- Current predicate set is covered by others clause. null; else Missing_Choice (Pred_Lo, Pred_Hi); Error := True; end if; -- There may be several static predicate sets between the current -- one and the choice. Inspect the next static predicate set. Next (Pred); Check_Against_Predicate (Pred => Pred, Choice => Choice, Prev_Lo => Prev_Lo, Prev_Hi => Prev_Hi, Error => Error); -- Pred_Lo Choice_Lo Pred_Hi Choice_Hi -- +=========+===========+-----------+ -- ^ illegal ^ elsif Pred_Hi < Choice_Hi and then Inside_Range (Pred_Lo, Pred_Hi, Choice_Lo) then Next (Pred); -- The choice may fall in a static predicate set. If this is the -- case, avoid mentioning legal values in the error message. if Present (Pred) then Next_Lo := Expr_Value (Low_Bound (Pred)); Next_Hi := Expr_Value (High_Bound (Pred)); -- The next static predicate set is to the right of the choice if Choice_Hi < Next_Lo and then Choice_Hi < Next_Hi then Illegal_Range (Loc, Pred_Hi + 1, Choice_Hi); else Illegal_Range (Loc, Pred_Hi + 1, Next_Lo - 1); end if; else Illegal_Range (Loc, Pred_Hi + 1, Choice_Hi); end if; Error := True; -- Choice_Lo Pred_Lo Pred_Hi Choice_Hi -- +-----------+=========+-----------+ -- ^ illegal ^ ^ illegal ^ -- Emit an error on the low gap, disregard the upper gap elsif Choice_Lo < Pred_Lo and then Pred_Hi < Choice_Hi then Illegal_Range (Loc, Choice_Lo, Pred_Lo - 1); Error := True; -- Step 4: Detect all cases of partial or missing coverage -- Pred_Lo Choice_Lo Choice_Hi Pred_Hi -- +=========+==========+===========+ -- ^ gap ^ ^ gap ^ else -- An "others" choice covers all gaps if Others_Present then Prev_Lo := Choice_Lo; Prev_Hi := Choice_Hi; -- Check whether predicate set is fully covered by choice if Pred_Hi = Choice_Hi then Next (Pred); end if; -- Choice_Lo Choice_Hi Pred_Hi -- +===========+===========+ -- Pred_Lo ^ gap ^ -- The upper gap may be covered by a subsequent choice elsif Pred_Lo = Choice_Lo then Prev_Lo := Choice_Lo; Prev_Hi := Choice_Hi; -- Pred_Lo Prev_Hi Choice_Lo Choice_Hi Pred_Hi -- +===========+=========+===========+===========+ -- ^ covered ^ ^ gap ^ else pragma Assert (Pred_Lo < Choice_Lo); -- A previous choice covered the gap up to the current choice if Prev_Hi = Choice_Lo - 1 then Prev_Lo := Choice_Lo; Prev_Hi := Choice_Hi; if Choice_Hi = Pred_Hi then Next (Pred); end if; -- The previous choice did not intersect with the current -- static predicate set. elsif Prev_Hi < Pred_Lo then Missing_Choice (Pred_Lo, Choice_Lo - 1); Error := True; -- The previous choice covered part of the static predicate set -- but there is a gap after Prev_Hi. else Missing_Choice (Prev_Hi + 1, Choice_Lo - 1); Error := True; end if; end if; end if; end Check_Against_Predicate; ---------------------- -- Check_Duplicates -- ---------------------- procedure Check_Duplicates is Choice : Node_Id; Choice_Hi : Uint; Choice_Lo : Uint; Prev_Choice : Node_Id := Empty; Prev_Hi : Uint; begin Prev_Hi := Expr_Value (Choice_Table (1).Hi); for Outer_Index in 2 .. Num_Choices loop Choice_Lo := Expr_Value (Choice_Table (Outer_Index).Lo); Choice_Hi := Expr_Value (Choice_Table (Outer_Index).Hi); -- Choices overlap; this is an error if Choice_Lo <= Prev_Hi then Choice := Choice_Table (Outer_Index).Node; -- Find first previous choice that overlaps for Inner_Index in 1 .. Outer_Index - 1 loop if Choice_Lo <= Expr_Value (Choice_Table (Inner_Index).Hi) then Prev_Choice := Choice_Table (Inner_Index).Node; exit; end if; end loop; pragma Assert (Present (Prev_Choice)); if Sloc (Prev_Choice) <= Sloc (Choice) then Error_Msg_Sloc := Sloc (Prev_Choice); Dup_Choice (Choice_Lo, UI_Min (Choice_Hi, Prev_Hi), Choice); else Error_Msg_Sloc := Sloc (Choice); Dup_Choice (Choice_Lo, UI_Min (Choice_Hi, Prev_Hi), Prev_Choice); end if; end if; if Choice_Hi > Prev_Hi then Prev_Hi := Choice_Hi; end if; end loop; end Check_Duplicates; ---------------- -- Dup_Choice -- ---------------- procedure Dup_Choice (Lo, Hi : Uint; C : Node_Id) is begin -- In some situations, we call this with a null range, and obviously -- we don't want to complain in this case. if Lo > Hi then return; end if; -- Case of only one value that is duplicated if Lo = Hi then -- Integer type if Is_Integer_Type (Bounds_Type) then -- We have an integer value, Lo, but if the given choice -- placement is a constant with that value, then use the -- name of that constant instead in the message: if Nkind (C) = N_Identifier and then Compile_Time_Known_Value (C) and then Expr_Value (C) = Lo then Error_Msg_N ("duplication of choice value: &#!", Original_Node (C)); -- Not that special case, so just output the integer value else Error_Msg_Uint_1 := Lo; Error_Msg_N ("duplication of choice value: ^#!", Original_Node (C)); end if; -- Enumeration type else Error_Msg_Name_1 := Choice_Image (Lo, Bounds_Type); Error_Msg_N ("duplication of choice value: %#!", Original_Node (C)); end if; -- More than one choice value, so print range of values else -- Integer type if Is_Integer_Type (Bounds_Type) then -- Similar to the above, if C is a range of known values which -- match Lo and Hi, then use the names. We have to go to the -- original nodes, since the values will have been rewritten -- to their integer values. if Nkind (C) = N_Range and then Nkind (Original_Node (Low_Bound (C))) = N_Identifier and then Nkind (Original_Node (High_Bound (C))) = N_Identifier and then Compile_Time_Known_Value (Low_Bound (C)) and then Compile_Time_Known_Value (High_Bound (C)) and then Expr_Value (Low_Bound (C)) = Lo and then Expr_Value (High_Bound (C)) = Hi then Error_Msg_Node_2 := Original_Node (High_Bound (C)); Error_Msg_N ("duplication of choice values: & .. &#!", Original_Node (Low_Bound (C))); -- Not that special case, output integer values else Error_Msg_Uint_1 := Lo; Error_Msg_Uint_2 := Hi; Error_Msg_N ("duplication of choice values: ^ .. ^#!", Original_Node (C)); end if; -- Enumeration type else Error_Msg_Name_1 := Choice_Image (Lo, Bounds_Type); Error_Msg_Name_2 := Choice_Image (Hi, Bounds_Type); Error_Msg_N ("duplication of choice values: % .. %#!", Original_Node (C)); end if; end if; end Dup_Choice; ------------------------------ -- Explain_Non_Static_Bound -- ------------------------------ procedure Explain_Non_Static_Bound is Expr : Node_Id; begin if Nkind (Case_Node) = N_Variant_Part then Expr := Name (Case_Node); else Expr := Expression (Case_Node); end if; if Bounds_Type /= Subtyp then -- If the case is a variant part, the expression is given by the -- discriminant itself, and the bounds are the culprits. if Nkind (Case_Node) = N_Variant_Part then Error_Msg_NE ("bounds of & are not static, " & "alternatives must cover base type!", Expr, Expr); -- If this is a case statement, the expression may be nonstatic -- or else the subtype may be at fault. elsif Is_Entity_Name (Expr) then Error_Msg_NE ("bounds of & are not static, " & "alternatives must cover base type!", Expr, Expr); else Error_Msg_N ("subtype of expression is not static, " & "alternatives must cover base type!", Expr); end if; -- Otherwise the expression is not static, even if the bounds of the -- type are, or else there are missing alternatives. If both, the -- additional information may be redundant but harmless. Examine -- whether original node is an entity, because it may have been -- constant-folded to a literal if value is known. elsif not Is_Entity_Name (Original_Node (Expr)) then Error_Msg_N ("subtype of expression is not static, " & "alternatives must cover base type!", Expr); end if; end Explain_Non_Static_Bound; --------------- -- Lt_Choice -- --------------- function Lt_Choice (C1, C2 : Natural) return Boolean is begin return Expr_Value (Choice_Table (Nat (C1)).Lo) < Expr_Value (Choice_Table (Nat (C2)).Lo); end Lt_Choice; -------------------- -- Missing_Choice -- -------------------- procedure Missing_Choice (Value1 : Node_Id; Value2 : Node_Id) is begin Missing_Choice (Expr_Value (Value1), Expr_Value (Value2)); end Missing_Choice; procedure Missing_Choice (Value1 : Node_Id; Value2 : Uint) is begin Missing_Choice (Expr_Value (Value1), Value2); end Missing_Choice; procedure Missing_Choice (Value1 : Uint; Value2 : Node_Id) is begin Missing_Choice (Value1, Expr_Value (Value2)); end Missing_Choice; -------------------- -- Missing_Choice -- -------------------- procedure Missing_Choice (Value1 : Uint; Value2 : Uint) is begin -- AI05-0188 : within an instance the non-others choices do not have -- to belong to the actual subtype. if Ada_Version >= Ada_2012 and then In_Instance then return; -- In some situations, we call this with a null range, and obviously -- we don't want to complain in this case. elsif Value1 > Value2 then return; -- If predicate is already known to be violated, do not check for -- coverage error, to prevent cascaded messages. elsif Predicate_Error then return; end if; -- Case of only one value that is missing if Value1 = Value2 then if Is_Integer_Type (Bounds_Type) then Error_Msg_Uint_1 := Value1; Error_Msg_N ("missing case value: ^!", Case_Node); else Error_Msg_Name_1 := Choice_Image (Value1, Bounds_Type); Error_Msg_N ("missing case value: %!", Case_Node); end if; -- More than one choice value, so print range of values else if Is_Integer_Type (Bounds_Type) then Error_Msg_Uint_1 := Value1; Error_Msg_Uint_2 := Value2; Error_Msg_N ("missing case values: ^ .. ^!", Case_Node); else Error_Msg_Name_1 := Choice_Image (Value1, Bounds_Type); Error_Msg_Name_2 := Choice_Image (Value2, Bounds_Type); Error_Msg_N ("missing case values: % .. %!", Case_Node); end if; end if; end Missing_Choice; --------------------- -- Missing_Choices -- --------------------- procedure Missing_Choices (Pred : Node_Id; Prev_Hi : Uint) is Hi : Uint; Lo : Uint; Set : Node_Id; begin Set := Pred; while Present (Set) loop Lo := Expr_Value (Low_Bound (Set)); Hi := Expr_Value (High_Bound (Set)); -- A choice covered part of a static predicate set if Lo <= Prev_Hi and then Prev_Hi < Hi then Missing_Choice (Prev_Hi + 1, Hi); else Missing_Choice (Lo, Hi); end if; Next (Set); end loop; end Missing_Choices; ----------------- -- Move_Choice -- ----------------- procedure Move_Choice (From : Natural; To : Natural) is begin Choice_Table (Nat (To)) := Choice_Table (Nat (From)); end Move_Choice; -- Local variables Bounds_Hi : constant Node_Id := Type_High_Bound (Bounds_Type); Bounds_Lo : constant Node_Id := Type_Low_Bound (Bounds_Type); Has_Predicate : constant Boolean := Is_OK_Static_Subtype (Bounds_Type) and then Has_Static_Predicate (Bounds_Type); Choice_Hi : Uint; Choice_Lo : Uint; Pred : Node_Id; Prev_Lo : Uint; Prev_Hi : Uint; -- Start of processing for Check_Choice_Set begin -- If the case is part of a predicate aspect specification, do not -- recheck it against itself. if Present (Parent (Case_Node)) and then Nkind (Parent (Case_Node)) = N_Aspect_Specification then return; end if; -- Choice_Table must start at 0 which is an unused location used by the -- sorting algorithm. However the first valid position for a discrete -- choice is 1. pragma Assert (Choice_Table'First = 0); -- The choices do not cover the base range. Emit an error if "others" is -- not available and return as there is no need for further processing. if Num_Choices = 0 then if not Others_Present then Missing_Choice (Bounds_Lo, Bounds_Hi); end if; return; end if; Sorting.Sort (Positive (Choice_Table'Last)); -- First check for duplicates. This involved the choices; predicates, if -- any, are irrelevant. Check_Duplicates; -- Then check for overlaps -- If the subtype has a static predicate, the predicate defines subsets -- of legal values and requires finer-grained analysis. -- Note that in GNAT the predicate is considered static if the predicate -- expression is static, independently of whether the aspect mentions -- Static explicitly. if Has_Predicate then Pred := First (Static_Discrete_Predicate (Bounds_Type)); -- Make initial value smaller than 'First of type, so that first -- range comparison succeeds. This applies both to integer types -- and to enumeration types. Prev_Lo := Expr_Value (Type_Low_Bound (Bounds_Type)) - 1; Prev_Hi := Prev_Lo; declare Error : Boolean := False; begin for Index in 1 .. Num_Choices loop Check_Against_Predicate (Pred => Pred, Choice => Choice_Table (Index), Prev_Lo => Prev_Lo, Prev_Hi => Prev_Hi, Error => Error); -- The analysis detected an illegal intersection between a -- choice and a static predicate set. Do not examine other -- choices unless all errors are requested. if Error then Predicate_Error := True; if not All_Errors_Mode then return; end if; end if; end loop; end; if Predicate_Error then return; end if; -- The choices may legally cover some of the static predicate sets, -- but not all. Emit an error for each non-covered set. if not Others_Present then Missing_Choices (Pred, Prev_Hi); end if; -- Default analysis else Choice_Lo := Expr_Value (Choice_Table (1).Lo); Choice_Hi := Expr_Value (Choice_Table (1).Hi); Prev_Hi := Choice_Hi; if not Others_Present and then Expr_Value (Bounds_Lo) < Choice_Lo then Missing_Choice (Bounds_Lo, Choice_Lo - 1); -- If values are missing outside of the subtype, add explanation. -- No additional message if only one value is missing. if Expr_Value (Bounds_Lo) < Choice_Lo - 1 then Explain_Non_Static_Bound; end if; end if; for Index in 2 .. Num_Choices loop Choice_Lo := Expr_Value (Choice_Table (Index).Lo); Choice_Hi := Expr_Value (Choice_Table (Index).Hi); if Choice_Lo > Prev_Hi + 1 and then not Others_Present then Missing_Choice (Prev_Hi + 1, Choice_Lo - 1); end if; if Choice_Hi > Prev_Hi then Prev_Hi := Choice_Hi; end if; end loop; if not Others_Present and then Expr_Value (Bounds_Hi) > Prev_Hi then Missing_Choice (Prev_Hi + 1, Bounds_Hi); if Expr_Value (Bounds_Hi) > Prev_Hi + 1 then Explain_Non_Static_Bound; end if; end if; end if; end Check_Choice_Set; ------------------ -- Choice_Image -- ------------------ function Choice_Image (Value : Uint; Ctype : Entity_Id) return Name_Id is Rtp : constant Entity_Id := Root_Type (Ctype); Lit : Entity_Id; C : Int; begin -- For character, or wide [wide] character. If 7-bit ASCII graphic -- range, then build and return appropriate character literal name if Is_Standard_Character_Type (Ctype) then C := UI_To_Int (Value); if C in 16#20# .. 16#7E# then Set_Character_Literal_Name (Char_Code (UI_To_Int (Value))); return Name_Find; end if; -- For user defined enumeration type, find enum/char literal else Lit := First_Literal (Rtp); for J in 1 .. UI_To_Int (Value) loop Next_Literal (Lit); end loop; -- If enumeration literal, just return its value if Nkind (Lit) = N_Defining_Identifier then return Chars (Lit); -- For character literal, get the name and use it if it is -- for a 7-bit ASCII graphic character in 16#20#..16#7E#. else Get_Decoded_Name_String (Chars (Lit)); if Name_Len = 3 and then Name_Buffer (2) in Character'Val (16#20#) .. Character'Val (16#7E#) then return Chars (Lit); end if; end if; end if; -- If we fall through, we have a character literal which is not in -- the 7-bit ASCII graphic set. For such cases, we construct the -- name "type'val(nnn)" where type is the choice type, and nnn is -- the pos value passed as an argument to Choice_Image. Get_Name_String (Chars (First_Subtype (Ctype))); Add_Str_To_Name_Buffer ("'val("); UI_Image (Value); Add_Str_To_Name_Buffer (UI_Image_Buffer (1 .. UI_Image_Length)); Add_Char_To_Name_Buffer (')'); return Name_Find; end Choice_Image; package body Composite_Case_Ops is function Static_Array_Length (Subtyp : Entity_Id) return Nat; -- Given a one-dimensional constrained array subtype with -- statically known bounds, return its length. ------------------------- -- Static_Array_Length -- ------------------------- function Static_Array_Length (Subtyp : Entity_Id) return Nat is pragma Assert (Is_Constrained (Subtyp)); pragma Assert (Number_Dimensions (Subtyp) = 1); Index : constant Node_Id := First_Index (Subtyp); pragma Assert (Is_OK_Static_Range (Index)); Lo : constant Uint := Expr_Value (Low_Bound (Index)); Hi : constant Uint := Expr_Value (High_Bound (Index)); Len : constant Uint := UI_Max (0, (Hi - Lo) + 1); begin return UI_To_Int (Len); end Static_Array_Length; ------------------------ -- Box_Value_Required -- ------------------------ function Box_Value_Required (Subtyp : Entity_Id) return Boolean is -- Some of these restrictions will be relaxed eventually, but best -- to initially err in the direction of being too restrictive. begin if Has_Predicates (Subtyp) then return True; elsif Is_Discrete_Type (Subtyp) then if not Is_Static_Subtype (Subtyp) then return True; elsif Is_Enumeration_Type (Subtyp) and then Has_Enumeration_Rep_Clause (Subtyp) -- Maybe enumeration rep clauses can be ignored here? then return True; end if; elsif Is_Array_Type (Subtyp) then if Number_Dimensions (Subtyp) /= 1 then return True; elsif not Is_Constrained (Subtyp) then if not Is_Static_Subtype (Etype (First_Index (Subtyp))) then return True; end if; elsif not Is_OK_Static_Range (First_Index (Subtyp)) then return True; end if; elsif Is_Record_Type (Subtyp) then if Has_Discriminants (Subtyp) and then Is_Constrained (Subtyp) and then not Has_Static_Discriminant_Constraint (Subtyp) then -- Perhaps treat differently the case where Subtyp is the -- subtype of the top-level selector expression, as opposed -- to the subtype of some subcomponent thereof. return True; end if; else -- Return True for any type that is not a discrete type, -- a record type, or an array type. return True; end if; return False; end Box_Value_Required; ------------------ -- Choice_Count -- ------------------ function Choice_Count (Alternatives : List_Id) return Nat is Result : Nat := 0; Alt : Node_Id := First (Alternatives); begin while Present (Alt) loop Result := Result + List_Length (Discrete_Choices (Alt)); Next (Alt); end loop; return Result; end Choice_Count; ------------------------------- -- Normalized_Case_Expr_Type -- ------------------------------- function Normalized_Case_Expr_Type (Case_Statement : Node_Id) return Entity_Id is Unnormalized : constant Entity_Id := Etype (Expression (Case_Statement)); Is_Dynamically_Constrained_Array : constant Boolean := Is_Array_Type (Unnormalized) and then Is_Constrained (Unnormalized) and then not Has_Static_Array_Bounds (Unnormalized); Is_Dynamically_Constrained_Record : constant Boolean := Is_Record_Type (Unnormalized) and then Has_Discriminants (Unnormalized) and then Is_Constrained (Unnormalized) and then not Has_Static_Discriminant_Constraint (Unnormalized); begin if Is_Dynamically_Constrained_Array or Is_Dynamically_Constrained_Record then return Base_Type (Unnormalized); else return Unnormalized; end if; end Normalized_Case_Expr_Type; ----------------------- -- Scalar_Part_Count -- ----------------------- function Scalar_Part_Count (Subtyp : Entity_Id) return Nat is begin if Box_Value_Required (Subtyp) then return 0; -- component does not participate in case selection elsif Is_Scalar_Type (Subtyp) then return 1; elsif Is_Array_Type (Subtyp) then return Static_Array_Length (Subtyp) * Scalar_Part_Count (Component_Type (Subtyp)); elsif Is_Record_Type (Subtyp) then declare Result : Nat := 0; Comp : Entity_Id := First_Component_Or_Discriminant (Base_Type (Subtyp)); begin while Present (Comp) loop Result := Result + Scalar_Part_Count (Etype (Comp)); Next_Component_Or_Discriminant (Comp); end loop; return Result; end; else pragma Assert (Serious_Errors_Detected > 0); return 0; end if; end Scalar_Part_Count; package body Array_Case_Ops is ------------------------- -- Array_Choice_Length -- ------------------------- function Array_Choice_Length (Choice : Node_Id) return Nat is begin case Nkind (Choice) is when N_String_Literal => return String_Length (Strval (Choice)); when N_Aggregate => declare Bounds : constant Node_Id := Aggregate_Bounds (Choice); pragma Assert (Is_OK_Static_Range (Bounds)); Lo : constant Uint := Expr_Value (Low_Bound (Bounds)); Hi : constant Uint := Expr_Value (High_Bound (Bounds)); Len : constant Uint := (Hi - Lo) + 1; begin return UI_To_Int (Len); end; when N_Has_Entity => if Present (Entity (Choice)) and then Ekind (Entity (Choice)) = E_Constant then return Array_Choice_Length (Expression (Parent (Entity (Choice)))); end if; when N_Others_Choice => return 0; when others => null; end case; if Nkind (Original_Node (Choice)) in N_String_Literal | N_Aggregate then return Array_Choice_Length (Original_Node (Choice)); end if; Error_Msg_N ("Unsupported case choice", Choice); return 0; end Array_Choice_Length; ------------------------------------------ -- Unconstrained_Array_Effective_Length -- ------------------------------------------ function Unconstrained_Array_Effective_Length (Array_Type : Entity_Id; Case_Statement : Node_Id) return Nat is pragma Assert (Is_Array_Type (Array_Type)); -- Array_Type is otherwise unreferenced for now. Result : Nat := 0; Alt : Node_Id := First (Alternatives (Case_Statement)); begin while Present (Alt) loop declare Choice : Node_Id := First (Discrete_Choices (Alt)); begin while Present (Choice) loop Result := Nat'Max (Result, Array_Choice_Length (Choice)); Next (Choice); end loop; end; Next (Alt); end loop; return Result; end Unconstrained_Array_Effective_Length; ------------------------------------------- -- Unconstrained_Array_Scalar_Part_Count -- ------------------------------------------- function Unconstrained_Array_Scalar_Part_Count (Array_Type : Entity_Id; Case_Statement : Node_Id) return Nat is begin -- Add one for the length, which is treated like a discriminant return 1 + (Unconstrained_Array_Effective_Length (Array_Type => Array_Type, Case_Statement => Case_Statement) * Scalar_Part_Count (Component_Type (Array_Type))); end Unconstrained_Array_Scalar_Part_Count; end Array_Case_Ops; package body Choice_Analysis is function Component_Bounds_Info return Composite_Range_Info; -- Returns the (statically known) bounds for each component. -- The selector expression value (or any other value of the type -- of the selector expression) can be thought of as a point in the -- Cartesian product of these sets. function Parse_Choice (Choice : Node_Id; Alt : Node_Id) return Choice_Range_Info; -- Extract Choice_Range_Info from a Choice node --------------------------- -- Component_Bounds_Info -- --------------------------- function Component_Bounds_Info return Composite_Range_Info is Result : Composite_Range_Info; Next : Part_Id := 1; Done : Boolean := False; procedure Update_Result (Info : Discrete_Range_Info); -- Initialize first remaining uninitialized element of Result. -- Also set Next and Done. ------------------- -- Update_Result -- ------------------- procedure Update_Result (Info : Discrete_Range_Info) is begin Result (Next) := Info; if Next /= Part_Id'Last then Next := Next + 1; else pragma Assert (not Done); Done := True; end if; end Update_Result; procedure Traverse_Discrete_Parts (Subtyp : Entity_Id); -- Traverse the given subtype, looking for discrete parts. -- For an array subtype of length N, the element subtype -- is traversed N times. For a record subtype, traverse -- each component's subtype (once). When a discrete part is -- found, call Update_Result. ----------------------------- -- Traverse_Discrete_Parts -- ----------------------------- procedure Traverse_Discrete_Parts (Subtyp : Entity_Id) is begin if Box_Value_Required (Subtyp) then return; end if; if Is_Discrete_Type (Subtyp) then Update_Result ((Low => Expr_Value (Type_Low_Bound (Subtyp)), High => Expr_Value (Type_High_Bound (Subtyp)))); elsif Is_Array_Type (Subtyp) then declare Len : Nat; begin if Is_Constrained (Subtyp) then Len := Static_Array_Length (Subtyp); else -- Length will be treated like a discriminant; -- We could compute High more precisely as -- 1 + Index_Subtype'Last - Index_Subtype'First -- (we currently require that those bounds be -- static, so this is an option), but only downside of -- overshooting is if somebody wants to omit a -- "when others" choice and exhaustively cover all -- possibilities explicitly. Update_Result ((Low => Uint_0, High => Uint_2 ** Uint_32)); Len := Unconstrained_Array_Effective_Length (Array_Type => Subtyp, Case_Statement => Case_Statement); end if; for I in 1 .. Len loop Traverse_Discrete_Parts (Component_Type (Subtyp)); end loop; end; elsif Is_Record_Type (Subtyp) then if Has_Static_Discriminant_Constraint (Subtyp) then -- The component range for a constrained discriminant -- is a single value. declare Dc_Elmt : Elmt_Id := First_Elmt (Discriminant_Constraint (Subtyp)); Dc_Value : Uint; begin while Present (Dc_Elmt) loop Dc_Value := Expr_Value (Node (Dc_Elmt)); Update_Result ((Low => Dc_Value, High => Dc_Value)); Next_Elmt (Dc_Elmt); end loop; end; -- Generate ranges for nondiscriminant components. declare Comp : Entity_Id := First_Component (Base_Type (Subtyp)); begin while Present (Comp) loop Traverse_Discrete_Parts (Etype (Comp)); Next_Component (Comp); end loop; end; else -- Generate ranges for all components declare Comp : Entity_Id := First_Component_Or_Discriminant (Base_Type (Subtyp)); begin while Present (Comp) loop Traverse_Discrete_Parts (Etype (Comp)); Next_Component_Or_Discriminant (Comp); end loop; end; end if; else Error_Msg_N ("case selector type having a non-discrete non-record" & " non-array subcomponent type not implemented", Expression (Case_Statement)); end if; end Traverse_Discrete_Parts; begin Traverse_Discrete_Parts (Case_Expr_Type); pragma Assert (Done or else Serious_Errors_Detected > 0); return Result; end Component_Bounds_Info; Component_Bounds : constant Composite_Range_Info := Component_Bounds_Info; package Case_Bindings is procedure Note_Binding (Comp_Assoc : Node_Id; Choice : Node_Id; Alt : Node_Id); -- Note_Binding is called once for each component association -- that defines a binding (using either "A => B is X" or -- "A => <X>" syntax); procedure Check_Bindings; -- After all calls to Note_Binding, check that bindings are -- ok (e.g., check consistency among different choices of -- one alternative). end Case_Bindings; procedure Refresh_Binding_Info (Aggr : Node_Id); -- The parser records binding-related info in the tree. -- The choice nodes that we see here might not be (will never be?) -- the original nodes that were produced by the parser. The info -- recorded by the parser is missing in that case, so this -- procedure recovers it. -- -- There are bugs here. In some cases involving nested aggregates, -- the path back to the parser-created nodes is lost. In particular, -- we may fail to detect an illegal case like -- when (F1 | F2 => (Aa => Natural, Bb => Natural is X)) => -- This should be rejected because it is binding X to both the -- F1.Bb and to the F2.Bb subcomponents of the case selector. -- It would be nice if the not-specific-to-pattern-matching -- aggregate-processing code could remain unaware of the existence -- of this binding-related info but perhaps that isn't possible. -------------------------- -- Refresh_Binding_Info -- -------------------------- procedure Refresh_Binding_Info (Aggr : Node_Id) is Orig_Aggr : constant Node_Id := Original_Node (Aggr); Orig_Comp : Node_Id := First (Component_Associations (Orig_Aggr)); begin if Aggr = Orig_Aggr then return; end if; while Present (Orig_Comp) loop if Nkind (Orig_Comp) = N_Component_Association and then Binding_Chars (Orig_Comp) /= No_Name then if List_Length (Choices (Orig_Comp)) /= 1 then -- Conceivably this could be checked during parsing, -- but checking is easier here. Error_Msg_N ("binding shared by multiple components", Orig_Comp); return; end if; declare Orig_Name : constant Name_Id := Chars (First (Choices (Orig_Comp))); Comp : Node_Id := First (Component_Associations (Aggr)); Matching_Comp : Node_Id := Empty; begin while Present (Comp) loop if Chars (First (Choices (Comp))) = Orig_Name then pragma Assert (not Present (Matching_Comp)); Matching_Comp := Comp; end if; Next (Comp); end loop; pragma Assert (Present (Matching_Comp)); Set_Binding_Chars (Matching_Comp, Binding_Chars (Orig_Comp)); end; end if; Next (Orig_Comp); end loop; end Refresh_Binding_Info; ------------------ -- Parse_Choice -- ------------------ function Parse_Choice (Choice : Node_Id; Alt : Node_Id) return Choice_Range_Info is Result : Choice_Range_Info (Is_Others => False); Ranges : Composite_Range_Info renames Result.Ranges; Next_Part : Part_Id'Base range 1 .. Part_Id'Last + 1 := 1; procedure Traverse_Choice (Expr : Node_Id); -- Traverse a legal choice expression, looking for -- values/ranges of discrete parts. Call Update_Result -- for each. procedure Update_Result (Discrete_Range : Discrete_Range_Info); -- Initialize first remaining uninitialized element of Ranges. -- Also set Next_Part. procedure Update_Result_For_Full_Coverage (Comp_Type : Entity_Id); -- For each scalar part of the given component type, call -- Update_Result with the full range for that scalar part. -- This is used for both box components in aggregates and -- for any inactive-variant components that do not appear in -- a given aggregate. ------------------- -- Update_Result -- ------------------- procedure Update_Result (Discrete_Range : Discrete_Range_Info) is begin Ranges (Next_Part) := Discrete_Range; Next_Part := Next_Part + 1; end Update_Result; ------------------------------------- -- Update_Result_For_Full_Coverage -- ------------------------------------- procedure Update_Result_For_Full_Coverage (Comp_Type : Entity_Id) is begin for Counter in 1 .. Scalar_Part_Count (Comp_Type) loop Update_Result (Component_Bounds (Next_Part)); end loop; end Update_Result_For_Full_Coverage; --------------------- -- Traverse_Choice -- --------------------- procedure Traverse_Choice (Expr : Node_Id) is begin if Nkind (Expr) = N_Qualified_Expression then Traverse_Choice (Expression (Expr)); elsif Nkind (Expr) = N_Type_Conversion and then not Comes_From_Source (Expr) then if Expr /= Original_Node (Expr) then Traverse_Choice (Original_Node (Expr)); else Traverse_Choice (Expression (Expr)); end if; elsif Nkind (Expr) = N_Aggregate then if Is_Record_Type (Etype (Expr)) then Refresh_Binding_Info (Aggr => Expr); declare Comp_Assoc : Node_Id := First (Component_Associations (Expr)); -- Aggregate has been normalized (components in -- order, only one component per choice, etc.). Comp_From_Type : Node_Id := First_Component_Or_Discriminant (Base_Type (Etype (Expr))); Saved_Next_Part : constant Part_Id := Next_Part; begin while Present (Comp_Assoc) loop pragma Assert (List_Length (Choices (Comp_Assoc)) = 1); declare Comp : constant Node_Id := Entity (First (Choices (Comp_Assoc))); Comp_Seen : Boolean := False; begin loop if Original_Record_Component (Comp) = Original_Record_Component (Comp_From_Type) then Comp_Seen := True; else -- We have an aggregate of a type that -- has a variant part (or has a -- subcomponent type that has a variant -- part) and we have to deal with a -- component that is present in the type -- but not in the aggregate (because the -- component is in an inactive variant). -- Update_Result_For_Full_Coverage (Comp_Type => Etype (Comp_From_Type)); end if; Comp_From_Type := Next_Component_Or_Discriminant (Comp_From_Type); exit when Comp_Seen; end loop; end; declare Comp_Type : constant Entity_Id := Etype (First (Choices (Comp_Assoc))); begin if Box_Value_Required (Comp_Type) then -- This component is not allowed to -- influence which alternative is -- chosen; case choice must be box. -- -- For example, component might be -- of a real type or of an access type -- or of a non-static discrete subtype. if not Box_Present (Comp_Assoc) then Error_Msg_N ("Non-box case choice component value" & " of unsupported type/subtype", Expression (Comp_Assoc)); end if; elsif Box_Present (Comp_Assoc) then -- Box matches all values Update_Result_For_Full_Coverage (Etype (First (Choices (Comp_Assoc)))); else Traverse_Choice (Expression (Comp_Assoc)); end if; end; if Binding_Chars (Comp_Assoc) /= No_Name then Case_Bindings.Note_Binding (Comp_Assoc => Comp_Assoc, Choice => Choice, Alt => Alt); end if; Next (Comp_Assoc); end loop; while Present (Comp_From_Type) loop -- Deal with any trailing inactive-variant -- components. -- -- See earlier commment about calling -- Update_Result_For_Full_Coverage for such -- components. Update_Result_For_Full_Coverage (Comp_Type => Etype (Comp_From_Type)); Comp_From_Type := Next_Component_Or_Discriminant (Comp_From_Type); end loop; declare Expr_Type : Entity_Id := Etype (Expr); begin if Has_Discriminants (Expr_Type) then -- Avoid nonstatic choice expr types, -- for which Scalar_Part_Count returns 0. Expr_Type := Base_Type (Expr_Type); end if; pragma Assert (Nat (Next_Part - Saved_Next_Part) = Scalar_Part_Count (Expr_Type)); end; end; elsif Is_Array_Type (Etype (Expr)) then if Is_Non_Empty_List (Component_Associations (Expr)) then Error_Msg_N ("non-positional array aggregate as/within case " & "choice not implemented", Expr); end if; if not Unconstrained_Array_Case and then List_Length (Expressions (Expr)) /= Nat (Part_Id'Last) then Error_Msg_Uint_1 := UI_From_Int (List_Length (Expressions (Expr))); Error_Msg_Uint_2 := UI_From_Int (Int (Part_Id'Last)); Error_Msg_N ("array aggregate length ^ does not match length " & "of statically constrained case selector ^", Expr); return; end if; declare Subexpr : Node_Id := First (Expressions (Expr)); begin while Present (Subexpr) loop Traverse_Choice (Subexpr); Next (Subexpr); end loop; end; else raise Program_Error; end if; elsif Nkind (Expr) = N_String_Literal then if not Is_Array_Type (Etype (Expr)) then Error_Msg_N ("User-defined string literal not allowed as/within" & "case choice", Expr); else declare Char_Type : constant Entity_Id := Root_Type (Component_Type (Etype (Expr))); -- If the component type is not a standard character -- type then this string lit should have already been -- transformed into an aggregate in -- Resolve_String_Literal. -- pragma Assert (Is_Standard_Character_Type (Char_Type)); Str : constant String_Id := Strval (Expr); Strlen : constant Nat := String_Length (Str); Char_Val : Uint; begin if not Unconstrained_Array_Case and then Strlen /= Nat (Part_Id'Last) then Error_Msg_Uint_1 := UI_From_Int (Strlen); Error_Msg_Uint_2 := UI_From_Int (Int (Part_Id'Last)); Error_Msg_N ("String literal length ^ does not match length" & " of statically constrained case selector ^", Expr); return; end if; for Idx in 1 .. Strlen loop Char_Val := UI_From_CC (Get_String_Char (Str, Idx)); Update_Result ((Low | High => Char_Val)); end loop; end; end if; elsif Is_Discrete_Type (Etype (Expr)) then if Nkind (Expr) in N_Has_Entity and then Present (Entity (Expr)) and then Is_Type (Entity (Expr)) then declare Low : constant Node_Id := Type_Low_Bound (Entity (Expr)); High : constant Node_Id := Type_High_Bound (Entity (Expr)); begin Update_Result ((Low => Expr_Value (Low), High => Expr_Value (High))); end; else pragma Assert (Compile_Time_Known_Value (Expr)); Update_Result ((Low | High => Expr_Value (Expr))); end if; elsif Nkind (Expr) in N_Has_Entity and then Present (Entity (Expr)) and then Ekind (Entity (Expr)) = E_Constant then Traverse_Choice (Expression (Parent (Entity (Expr)))); elsif Nkind (Original_Node (Expr)) in N_Aggregate | N_String_Literal then Traverse_Choice (Original_Node (Expr)); else Error_Msg_N ("non-aggregate case choice (or subexpression thereof)" & " that is not of a discrete type not implemented", Expr); end if; end Traverse_Choice; -- Start of processing for Parse_Choice begin if Nkind (Choice) = N_Others_Choice then return (Is_Others => True); end if; if Unconstrained_Array_Case then -- Treat length like a discriminant Update_Result ((Low | High => UI_From_Int (Array_Choice_Length (Choice)))); end if; Traverse_Choice (Choice); if Unconstrained_Array_Case then -- This is somewhat tricky. Suppose we are casing on String, -- the longest choice in the case statement is length 10, and -- the choice we are looking at now is of length 6. We fill -- in the trailing 4 slots here. while Next_Part <= Part_Id'Last loop Update_Result_For_Full_Coverage (Comp_Type => Component_Type (Case_Expr_Type)); end loop; end if; -- Avoid returning uninitialized garbage in error case if Next_Part /= Part_Id'Last + 1 then pragma Assert (Serious_Errors_Detected > 0); Result.Ranges := (others => (Low => Uint_1, High => Uint_0)); end if; return Result; end Parse_Choice; package body Case_Bindings is type Binding is record Comp_Assoc : Node_Id; Choice : Node_Id; Alt : Node_Id; end record; type Binding_Index is new Natural; package Case_Bindings_Table is new Table.Table (Table_Component_Type => Binding, Table_Index_Type => Binding_Index, Table_Low_Bound => 1, Table_Initial => 16, Table_Increment => 64, Table_Name => "Composite_Case_Ops.Case_Bindings"); ------------------ -- Note_Binding -- ------------------ procedure Note_Binding (Comp_Assoc : Node_Id; Choice : Node_Id; Alt : Node_Id) is begin Case_Bindings_Table.Append ((Comp_Assoc => Comp_Assoc, Choice => Choice, Alt => Alt)); end Note_Binding; -------------------- -- Check_Bindings -- -------------------- procedure Check_Bindings is use Case_Bindings_Table; function Binding_Subtype (Idx : Binding_Index; Tab : Table_Type) return Entity_Id is (Etype (Nlists.First (Choices (Tab (Idx).Comp_Assoc)))); procedure Declare_Binding_Objects (Alt_Start : Binding_Index; Alt : Node_Id; First_Choice_Bindings : Natural; Tab : Table_Type); -- Declare the binding objects for a given alternative ------------------------------ -- Declare_Binding_Objects -- ------------------------------ procedure Declare_Binding_Objects (Alt_Start : Binding_Index; Alt : Node_Id; First_Choice_Bindings : Natural; Tab : Table_Type) is Loc : constant Source_Ptr := Sloc (Alt); Declarations : constant List_Id := New_List; Decl : Node_Id; Obj_Type : Entity_Id; Def_Id : Entity_Id; begin for FC_Idx in Alt_Start .. Alt_Start + Binding_Index (First_Choice_Bindings - 1) loop Obj_Type := Binding_Subtype (FC_Idx, Tab); Def_Id := Make_Defining_Identifier (Loc, Binding_Chars (Tab (FC_Idx).Comp_Assoc)); -- Either make a copy or rename the original. At a -- minimum, we do not want a copy if it would need -- finalization. Copies may also introduce problems -- if default init can have side effects (although we -- could suppress such default initialization). -- We have to make a copy in any cases where -- Unrestricted_Access doesn't work. -- -- This is where the copy-or-rename decision is made. -- In many cases either way would work and so we have -- some flexibility here. if not Is_By_Copy_Type (Obj_Type) then -- Generate -- type Ref -- is access constant Obj_Type; -- Ptr : Ref := <some bogus value>; -- Obj : Obj_Type renames Ptr.all; -- -- Initialization of Ptr will be generated later -- during expansion. declare Ptr_Type : constant Entity_Id := Make_Temporary (Loc, 'P'); Ptr_Type_Def : constant Node_Id := Make_Access_To_Object_Definition (Loc, All_Present => True, Subtype_Indication => New_Occurrence_Of (Obj_Type, Loc)); Ptr_Type_Decl : constant Node_Id := Make_Full_Type_Declaration (Loc, Ptr_Type, Type_Definition => Ptr_Type_Def); Ptr_Obj : constant Entity_Id := Make_Temporary (Loc, 'T'); -- We will generate initialization code for this -- object later (during expansion) but in the -- meantime we don't want the dereference that -- is generated a few lines below here to be -- transformed into a Raise_C_E. To prevent this, -- we provide a bogus initial value here; this -- initial value will be removed later during -- expansion. Ptr_Obj_Decl : constant Node_Id := Make_Object_Declaration (Loc, Ptr_Obj, Object_Definition => New_Occurrence_Of (Ptr_Type, Loc), Expression => Unchecked_Convert_To (Ptr_Type, Make_Integer_Literal (Loc, 5432))); begin Mutate_Ekind (Ptr_Type, E_Access_Type); -- in effect, Storage_Size => 0 Set_No_Pool_Assigned (Ptr_Type); Set_Is_Access_Constant (Ptr_Type); -- We could set Ptr_Type'Alignment here if that -- ever turns out to be needed for renaming a -- misaligned subcomponent. Mutate_Ekind (Ptr_Obj, E_Variable); Set_Etype (Ptr_Obj, Ptr_Type); Decl := Make_Object_Renaming_Declaration (Loc, Def_Id, Subtype_Mark => New_Occurrence_Of (Obj_Type, Loc), Name => Make_Explicit_Dereference (Loc, New_Occurrence_Of (Ptr_Obj, Loc))); Append_To (Declarations, Ptr_Type_Decl); Append_To (Declarations, Ptr_Obj_Decl); end; else Decl := Make_Object_Declaration (Sloc => Loc, Defining_Identifier => Def_Id, Object_Definition => New_Occurrence_Of (Obj_Type, Loc)); end if; Append_To (Declarations, Decl); end loop; declare Old_Statements : constant List_Id := Statements (Alt); New_Statements : constant List_Id := New_List; Block_Statement : constant Node_Id := Make_Block_Statement (Sloc => Loc, Declarations => Declarations, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Old_Statements), Has_Created_Identifier => True); begin Append_To (New_Statements, Block_Statement); Set_Statements (Alt, New_Statements); end; end Declare_Binding_Objects; begin if Last = 0 then -- no bindings to check return; end if; declare Tab : Table_Type renames Case_Bindings_Table.Table (1 .. Last); function Same_Id (Idx1, Idx2 : Binding_Index) return Boolean is ( Binding_Chars (Tab (Idx1).Comp_Assoc) = Binding_Chars (Tab (Idx2).Comp_Assoc)); begin -- Verify that elements with given choice or alt value -- are contiguous, and that elements with equal -- choice values have same alt value. for Idx1 in 2 .. Tab'Last loop if Tab (Idx1 - 1).Choice /= Tab (Idx1).Choice then pragma Assert (for all Idx2 in Idx1 + 1 .. Tab'Last => Tab (Idx2).Choice /= Tab (Idx1 - 1).Choice); else pragma Assert (Tab (Idx1 - 1).Alt = Tab (Idx1).Alt); end if; if Tab (Idx1 - 1).Alt /= Tab (Idx1).Alt then pragma Assert (for all Idx2 in Idx1 + 1 .. Tab'Last => Tab (Idx2).Alt /= Tab (Idx1 - 1).Alt); end if; end loop; -- Check for user errors: -- 1) Two choices for a given alternative shall define the -- same set of names. Can't have -- when (<X>, 0) | (0, <Y>) => -- 2) A choice shall not define a name twice. Can't have -- when (A => <X>, B => <X>, C => 0) => -- 3) Two definitions of a name within one alternative -- shall have statically matching component subtypes. -- Can't have -- type R is record Int : Integer; -- Nat : Natural; end record; -- case R'(...) is -- when (<X>, 1) | (1, <X>) => -- 4) A given binding shall match only one value. -- Can't have -- (Fld1 | Fld2 => (Fld => <X>)) -- For now, this is enforced *very* conservatively -- with respect to arrays - a binding cannot match -- any part of an array. This is temporary. for Idx1 in Tab'Range loop if Idx1 = 1 or else Tab (Idx1 - 1).Alt /= Tab (Idx1).Alt then -- Process one alternative declare Alt_Start : constant Binding_Index := Idx1; Alt : constant Node_Id := Tab (Alt_Start).Alt; First_Choice : constant Node_Id := Nlists.First (Discrete_Choices (Alt)); First_Choice_Bindings : Natural := 0; begin -- Check for duplicates within one choice, -- and for choices with no bindings. if First_Choice /= Tab (Alt_Start).Choice then Error_Msg_N ("binding(s) missing for choice", First_Choice); return; end if; declare Current_Choice : Node_Id := First_Choice; Choice_Start : Binding_Index := Alt_Start; begin for Idx2 in Alt_Start .. Tab'Last loop exit when Tab (Idx2).Alt /= Alt; if Tab (Idx2).Choice = Current_Choice then for Idx3 in Choice_Start .. Idx2 - 1 loop if Same_Id (Idx2, Idx3) then Error_Msg_N ("duplicate binding in choice", Current_Choice); return; end if; end loop; else Next (Current_Choice); pragma Assert (Present (Current_Choice)); Choice_Start := Idx2; if Tab (Idx2).Choice /= Current_Choice then Error_Msg_N ("binding(s) missing for choice", Current_Choice); return; end if; end if; end loop; -- If we made it through all the bindings -- for this alternative but didn't make it -- to the last choice, then bindings are -- missing for all remaining choices. -- We only complain about the first one. if Present (Next (Current_Choice)) then Error_Msg_N ("binding(s) missing for choice", Next (Current_Choice)); return; end if; end; -- Count bindings for first choice of alternative for FC_Idx in Alt_Start .. Tab'Last loop exit when Tab (FC_Idx).Choice /= First_Choice; First_Choice_Bindings := First_Choice_Bindings + 1; end loop; declare Current_Choice : Node_Id := First_Choice; Current_Choice_Bindings : Natural := 0; begin for Idx2 in Alt_Start .. Tab'Last loop exit when Tab (Idx2).Alt /= Alt; -- If starting a new choice if Tab (Idx2).Choice /= Current_Choice then -- Check count for choice just finished if Current_Choice_Bindings /= First_Choice_Bindings then Error_Msg_N ("subsequent choice has different" & " number of bindings than first" & " choice", Current_Choice); end if; Current_Choice := Tab (Idx2).Choice; Current_Choice_Bindings := 1; -- Remember that Alt has both one or more -- bindings and two or more choices; we'll -- need to know this during expansion. Set_Multidefined_Bindings (Alt, True); else Current_Choice_Bindings := Current_Choice_Bindings + 1; end if; -- Check that first choice has binding with -- matching name; check subtype consistency. declare Found : Boolean := False; begin for FC_Idx in Alt_Start .. Alt_Start + Binding_Index (First_Choice_Bindings - 1) loop if Same_Id (Idx2, FC_Idx) then if not Subtypes_Statically_Match (Binding_Subtype (Idx2, Tab), Binding_Subtype (FC_Idx, Tab)) then Error_Msg_N ("subtype of binding in " & "subsequent choice does not " & "match that in first choice", Tab (Idx2).Comp_Assoc); end if; Found := True; exit; end if; end loop; if not Found then Error_Msg_N ("binding defined in subsequent " & "choice not defined in first " & "choice", Current_Choice); end if; end; -- Check for illegal repeated binding -- via an enclosing aggregate, as in -- (F1 | F2 => (F3 => Natural is X, -- F4 => Natural)) -- where the inner aggregate would be ok. declare Rover : Node_Id := Tab (Idx2).Comp_Assoc; begin while Rover /= Tab (Idx2).Choice loop Rover := (if Is_List_Member (Rover) then Parent (List_Containing (Rover)) else Parent (Rover)); pragma Assert (Present (Rover)); if Nkind (Rover) = N_Component_Association and then List_Length (Choices (Rover)) > 1 then Error_Msg_N ("binding shared by multiple " & "enclosing components", Tab (Idx2).Comp_Assoc); end if; end loop; end; end loop; end; -- Construct the (unanalyzed) declarations for -- the current alternative. Then analyze them. if First_Choice_Bindings > 0 then Declare_Binding_Objects (Alt_Start => Alt_Start, Alt => Alt, First_Choice_Bindings => First_Choice_Bindings, Tab => Tab); end if; end; end if; end loop; end; end Check_Bindings; end Case_Bindings; function Choice_Bounds_Info return Choices_Range_Info; -- Returns mapping from any given Choice_Id value to that choice's -- component-to-range map. ------------------------ -- Choice_Bounds_Info -- ------------------------ function Choice_Bounds_Info return Choices_Range_Info is Result : Choices_Range_Info; Alt : Node_Id := First (Alternatives (Case_Statement)); C_Id : Choice_Id := 1; begin while Present (Alt) loop declare Choice : Node_Id := First (Discrete_Choices (Alt)); begin while Present (Choice) loop Result (C_Id) := Parse_Choice (Choice, Alt => Alt); Next (Choice); if C_Id /= Choice_Id'Last then C_Id := C_Id + 1; end if; end loop; end; Next (Alt); end loop; pragma Assert (C_Id = Choice_Id'Last); -- No more calls to Note_Binding, so time for checks. Case_Bindings.Check_Bindings; return Result; end Choice_Bounds_Info; Choices_Bounds : constant Choices_Range_Info := Choice_Bounds_Info; package body Value_Sets is use GNAT; function Hash (Key : Uint) return Bucket_Range_Type is (Bucket_Range_Type (UI_To_Int (Key mod (Uint_2 ** Uint_31)))); package Uint_Sets is new GNAT.Sets.Membership_Sets (Uint, "=", Hash); type Representative_Values_Array is array (Part_Id) of Uint_Sets.Membership_Set; function Representative_Values_Init return Representative_Values_Array; -- Select the representative values for each Part_Id value. -- This function is called exactly once, immediately after it -- is declared. -------------------------------- -- Representative_Values_Init -- -------------------------------- function Representative_Values_Init return Representative_Values_Array is -- For each range of each choice (as well as the range for the -- component subtype, which is handled in the first loop), -- insert the low bound of the range and the successor of -- the high bound into the corresponding R_V element. -- -- The idea we are trying to capture here is somewhat tricky. -- Given an arbitrary point P1 in the Cartesian product -- of the Component_Bounds sets, we want to be able -- to map that to a point P2 in the (smaller) Cartesian product -- of the Representative_Values sets that has the property -- that for every choice of the case statement, P1 matches -- the choice if and only if P2 also matches. Given that, -- we can implement the overlapping/containment/etc. rules -- safely by just looking at (using brute force enumeration) -- the (smaller) Cartesian product of the R_V sets. -- We are never going to actually perform this point-to-point -- mapping - just the fact that it exists is enough to ensure -- we can safely look at just the R_V sets. -- -- The desired mapping can be implemented by mapping a point -- P1 to a point P2 by reducing each of P1's coordinates down -- to the largest element of the corresponding R_V set that is -- less than or equal to the original coordinate value (such -- an element Y will always exist because the R_V set for a -- given component always includes the low bound of the -- component subtype). It then suffices to show that every -- choice in the case statement yields the same Boolean result -- for P1 as for P2. -- -- Suppose the contrary. Then there is some particular -- coordinate position X (i.e., a Part_Id value) and some -- choice C where exactly one of P1(X) and P2(X) belongs to -- the (contiguous) range associated with C(X); call that -- range L .. H. We know that P2(X) <= P1(X) because the -- mapping never increases coordinate values. Consider three -- cases: P1(X) lies within the L .. H range, or it is greater -- than H, or it is lower than L. -- The third case is impossible because reducing a value that -- is less than L can only produce another such value, -- violating the "exactly one" assumption. The second -- case is impossible because L belongs to the corresponding -- R_V set, so P2(X) >= L and both values belong to the -- range, again violating the "exactly one" assumption. -- Finally, the third case is impossible because H+1 belongs -- to the corresponding R_V set, so P2(X) > H, so neither -- value belongs to the range, again violating the "exactly -- one" assumption. So our initial supposition was wrong. QED. use Uint_Sets; Result : constant Representative_Values_Array := (others => Uint_Sets.Create (Initial_Size => 32)); procedure Insert_Representative (Value : Uint; P : Part_Id); -- Insert the given Value into the representative values set -- for the given component if it belongs to the component's -- subtype. Otherwise, do nothing. --------------------------- -- Insert_Representative -- --------------------------- procedure Insert_Representative (Value : Uint; P : Part_Id) is begin if Value >= Component_Bounds (P).Low and Value <= Component_Bounds (P).High then Insert (Result (P), Value); end if; end Insert_Representative; begin for P in Part_Id loop Insert_Representative (Component_Bounds (P).Low, P); end loop; for C of Choices_Bounds loop if not C.Is_Others then for P in Part_Id loop if C.Ranges (P).Low <= C.Ranges (P).High then Insert_Representative (C.Ranges (P).Low, P); Insert_Representative (C.Ranges (P).High + 1, P); end if; end loop; end if; end loop; return Result; end Representative_Values_Init; Representative_Values : constant Representative_Values_Array := Representative_Values_Init; -- We want to avoid looking at every point in the Cartesian -- product of all component values. Instead we select, for each -- component, a set of representative values and then look only -- at the Cartesian product of those sets. A single value can -- safely represent a larger enclosing interval if every choice -- for that component either completely includes or completely -- excludes the interval. The elements of this array will be -- populated by a call to Initialize_Representative_Values and -- will remain constant after that. type Value_Index_Base is new Natural; function Value_Index_Count return Value_Index_Base; -- Returns the product of the sizes of the Representative_Values -- sets (i.e., the size of the Cartesian product of the sets). -- May return zero if one of the sets is empty. -- This function is called exactly once, immediately after it -- is declared. ----------------------- -- Value_Index_Count -- ----------------------- function Value_Index_Count return Value_Index_Base is Result : Value_Index_Base := 1; begin for Set of Representative_Values loop Result := Result * Value_Index_Base (Uint_Sets.Size (Set)); end loop; return Result; exception when Constraint_Error => Error_Msg_N ("Capacity exceeded in compiling case statement with" & " composite selector type", Case_Statement); raise; end Value_Index_Count; Max_Value_Index : constant Value_Index_Base := Value_Index_Count; subtype Value_Index is Value_Index_Base range 1 .. Max_Value_Index; type Value_Index_Set is array (Value_Index) of Boolean; package Value_Index_Set_Table is new Table.Table (Table_Component_Type => Value_Index_Set, Table_Index_Type => Value_Set, Table_Low_Bound => 1, Table_Initial => 16, Table_Increment => 100, Table_Name => "Composite_Case_Ops.Value_Sets"); -- A nonzero Value_Set value is an index into this table. function Indexed (Index : Value_Set) return Value_Index_Set is (Value_Index_Set_Table.Table.all (Index)); function Allocate_Table_Element (Initial_Value : Value_Index_Set) return Value_Set; -- Allocate and initialize a new table element; return its index. ---------------------------- -- Allocate_Table_Element -- ---------------------------- function Allocate_Table_Element (Initial_Value : Value_Index_Set) return Value_Set is use Value_Index_Set_Table; begin Append (Initial_Value); return Last; end Allocate_Table_Element; procedure Assign_Table_Element (Index : Value_Set; Value : Value_Index_Set); -- Assign specified value to specified table element. -------------------------- -- Assign_Table_Element -- -------------------------- procedure Assign_Table_Element (Index : Value_Set; Value : Value_Index_Set) is begin Value_Index_Set_Table.Table.all (Index) := Value; end Assign_Table_Element; ------------- -- Compare -- ------------- function Compare (S1, S2 : Value_Set) return Set_Comparison is begin if S1 = Empty or S2 = Empty then return Disjoint; elsif Indexed (S1) = Indexed (S2) then return Equal; else declare Intersection : constant Value_Index_Set := Indexed (S1) and Indexed (S2); begin if (for all Flag of Intersection => not Flag) then return Disjoint; elsif Intersection = Indexed (S1) then return Contained_By; elsif Intersection = Indexed (S2) then return Contains; else return Overlaps; end if; end; end if; end Compare; ------------------------- -- Complement_Is_Empty -- ------------------------- function Complement_Is_Empty (Set : Value_Set) return Boolean is (Set /= Empty and then (for all Flag of Indexed (Set) => Flag)); --------------------- -- Free_Value_Sets -- --------------------- procedure Free_Value_Sets is begin Value_Index_Set_Table.Free; end Free_Value_Sets; ----------- -- Union -- ----------- procedure Union (Target : in out Value_Set; Source : Value_Set) is begin if Source /= Empty then if Target = Empty then Target := Allocate_Table_Element (Indexed (Source)); else Assign_Table_Element (Target, Indexed (Target) or Indexed (Source)); end if; end if; end Union; ------------ -- Remove -- ------------ procedure Remove (Target : in out Value_Set; Source : Value_Set) is begin if Source /= Empty and Target /= Empty then Assign_Table_Element (Target, Indexed (Target) and not Indexed (Source)); if (for all V of Indexed (Target) => not V) then Target := Empty; end if; end if; end Remove; --------------------- -- Matching_Values -- --------------------- function Matching_Values (Info : Composite_Range_Info) return Value_Set is Matches : Value_Index_Set; Next_Index : Value_Index := 1; Done : Boolean := False; Point : array (Part_Id) of Uint; procedure Test_Point_For_Match; -- Point identifies a point in the Cartesian product of the -- representative value sets. Record whether that Point -- belongs to the product-of-ranges specified by Info. -------------------------- -- Test_Point_For_Match -- -------------------------- procedure Test_Point_For_Match is function In_Range (Val : Uint; Rang : Discrete_Range_Info) return Boolean is ((Rang.Low <= Val) and then (Val <= Rang.High)); begin pragma Assert (not Done); Matches (Next_Index) := (for all P in Part_Id => In_Range (Point (P), Info (P))); if Next_Index = Matches'Last then Done := True; else Next_Index := Next_Index + 1; end if; end Test_Point_For_Match; procedure Test_Points (P : Part_Id); -- Iterate over the Cartesian product of the representative -- value sets, calling Test_Point_For_Match for each point. ----------------- -- Test_Points -- ----------------- procedure Test_Points (P : Part_Id) is use Uint_Sets; Iter : Iterator := Iterate (Representative_Values (P)); begin -- We could traverse here in sorted order, as opposed to -- whatever order the set iterator gives us. -- No need for that as long as every iteration over -- a given representative values set yields the same order. -- Not sorting is more efficient, but it makes it harder to -- interpret a Value_Index_Set bit vector when debugging. while Has_Next (Iter) loop Next (Iter, Point (P)); -- If we have finished building up a Point value, then -- test it for matching. Otherwise, recurse to continue -- building up a point value. if P = Part_Id'Last then Test_Point_For_Match; else Test_Points (P + 1); end if; end loop; end Test_Points; begin Test_Points (1); if (for all Flag of Matches => not Flag) then return Empty; end if; return Allocate_Table_Element (Matches); end Matching_Values; end Value_Sets; -------------- -- Analysis -- -------------- function Analysis return Choices_Info is Result : Choices_Info; Alt : Node_Id := First (Alternatives (Case_Statement)); A_Id : Alternative_Id := 1; C_Id : Choice_Id := 1; begin while Present (Alt) loop declare Choice : Node_Id := First (Discrete_Choices (Alt)); begin while Present (Choice) loop if Nkind (Choice) = N_Others_Choice then pragma Assert (Choices_Bounds (C_Id).Is_Others); Result (C_Id) := (Alternative => A_Id, Is_Others => True); else Result (C_Id) := (Alternative => A_Id, Is_Others => False, Matches => Value_Sets.Matching_Values (Choices_Bounds (C_Id).Ranges)); end if; Next (Choice); if C_Id /= Choice_Id'Last then C_Id := C_Id + 1; end if; end loop; end; Next (Alt); if A_Id /= Alternative_Id'Last then A_Id := A_Id + 1; end if; end loop; pragma Assert (A_Id = Alternative_Id'Last); pragma Assert (C_Id = Choice_Id'Last); return Result; end Analysis; end Choice_Analysis; end Composite_Case_Ops; -------------------------- -- Expand_Others_Choice -- -------------------------- procedure Expand_Others_Choice (Case_Table : Choice_Table_Type; Others_Choice : Node_Id; Choice_Type : Entity_Id) is Loc : constant Source_Ptr := Sloc (Others_Choice); Choice_List : constant List_Id := New_List; Choice : Node_Id; Exp_Lo : Node_Id; Exp_Hi : Node_Id; Hi : Uint; Lo : Uint; Previous_Hi : Uint; function Build_Choice (Value1, Value2 : Uint) return Node_Id; -- Builds a node representing the missing choices given by Value1 and -- Value2. A N_Range node is built if there is more than one literal -- value missing. Otherwise a single N_Integer_Literal, N_Identifier -- or N_Character_Literal is built depending on what Choice_Type is. function Lit_Of (Value : Uint) return Node_Id; -- Returns the Node_Id for the enumeration literal corresponding to the -- position given by Value within the enumeration type Choice_Type. The -- returned value has its Is_Static_Expression flag set to true. ------------------ -- Build_Choice -- ------------------ function Build_Choice (Value1, Value2 : Uint) return Node_Id is Lit_Node : Node_Id; Lo, Hi : Node_Id; begin -- If there is only one choice value missing between Value1 and -- Value2, build an integer or enumeration literal to represent it. if Value1 = Value2 then if Is_Integer_Type (Choice_Type) then Lit_Node := Make_Integer_Literal (Loc, Value1); Set_Etype (Lit_Node, Choice_Type); Set_Is_Static_Expression (Lit_Node); else Lit_Node := Lit_Of (Value1); end if; -- Otherwise is more that one choice value that is missing between -- Value1 and Value2, therefore build a N_Range node of either -- integer or enumeration literals. else if Is_Integer_Type (Choice_Type) then Lo := Make_Integer_Literal (Loc, Value1); Set_Etype (Lo, Choice_Type); Set_Is_Static_Expression (Lo); Hi := Make_Integer_Literal (Loc, Value2); Set_Etype (Hi, Choice_Type); Set_Is_Static_Expression (Hi); Lit_Node := Make_Range (Loc, Low_Bound => Lo, High_Bound => Hi); else Lit_Node := Make_Range (Loc, Low_Bound => Lit_Of (Value1), High_Bound => Lit_Of (Value2)); end if; end if; return Lit_Node; end Build_Choice; ------------ -- Lit_Of -- ------------ function Lit_Of (Value : Uint) return Node_Id is Lit : Entity_Id; begin -- In the case where the literal is of type Character, there needs -- to be some special handling since there is no explicit chain -- of literals to search. Instead, a N_Character_Literal node -- is created with the appropriate Char_Code and Chars fields. if Is_Standard_Character_Type (Choice_Type) then Set_Character_Literal_Name (Char_Code (UI_To_Int (Value))); Lit := Make_Character_Literal (Loc, Chars => Name_Find, Char_Literal_Value => Value); Set_Etype (Lit, Choice_Type); Set_Is_Static_Expression (Lit, True); return Lit; -- Otherwise, iterate through the literals list of Choice_Type -- "Value" number of times until the desired literal is reached -- and then return an occurrence of it. else Lit := First_Literal (Choice_Type); for J in 1 .. UI_To_Int (Value) loop Next_Literal (Lit); end loop; return New_Occurrence_Of (Lit, Loc); end if; end Lit_Of; -- Start of processing for Expand_Others_Choice begin if Case_Table'Last = 0 then -- Special case: only an others case is present. The others case -- covers the full range of the type. if Is_OK_Static_Subtype (Choice_Type) then Choice := New_Occurrence_Of (Choice_Type, Loc); else Choice := New_Occurrence_Of (Base_Type (Choice_Type), Loc); end if; Set_Others_Discrete_Choices (Others_Choice, New_List (Choice)); return; end if; -- Establish the bound values for the choice depending upon whether the -- type of the case statement is static or not. if Is_OK_Static_Subtype (Choice_Type) then Exp_Lo := Type_Low_Bound (Choice_Type); Exp_Hi := Type_High_Bound (Choice_Type); else Exp_Lo := Type_Low_Bound (Base_Type (Choice_Type)); Exp_Hi := Type_High_Bound (Base_Type (Choice_Type)); end if; Lo := Expr_Value (Case_Table (1).Lo); Hi := Expr_Value (Case_Table (1).Hi); Previous_Hi := Expr_Value (Case_Table (1).Hi); -- Build the node for any missing choices that are smaller than any -- explicit choices given in the case. if Expr_Value (Exp_Lo) < Lo then Append (Build_Choice (Expr_Value (Exp_Lo), Lo - 1), Choice_List); end if; -- Build the nodes representing any missing choices that lie between -- the explicit ones given in the case. for J in 2 .. Case_Table'Last loop Lo := Expr_Value (Case_Table (J).Lo); Hi := Expr_Value (Case_Table (J).Hi); if Lo /= (Previous_Hi + 1) then Append_To (Choice_List, Build_Choice (Previous_Hi + 1, Lo - 1)); end if; Previous_Hi := Hi; end loop; -- Build the node for any missing choices that are greater than any -- explicit choices given in the case. if Expr_Value (Exp_Hi) > Hi then Append (Build_Choice (Hi + 1, Expr_Value (Exp_Hi)), Choice_List); end if; Set_Others_Discrete_Choices (Others_Choice, Choice_List); -- Warn on null others list if warning option set if Warn_On_Redundant_Constructs and then Comes_From_Source (Others_Choice) and then Is_Empty_List (Choice_List) then Error_Msg_N ("?r?OTHERS choice is redundant", Others_Choice); Error_Msg_N ("\?r?previous choices cover all values", Others_Choice); end if; end Expand_Others_Choice; ----------- -- No_OP -- ----------- procedure No_OP (C : Node_Id) is begin if Nkind (C) = N_Range and then Warn_On_Redundant_Constructs then Error_Msg_N ("choice is an empty range?r?", C); end if; end No_OP; ----------------------------- -- Generic_Analyze_Choices -- ----------------------------- package body Generic_Analyze_Choices is -- The following type is used to gather the entries for the choice -- table, so that we can then allocate the right length. type Link; type Link_Ptr is access all Link; type Link is record Val : Choice_Bounds; Nxt : Link_Ptr; end record; --------------------- -- Analyze_Choices -- --------------------- procedure Analyze_Choices (Alternatives : List_Id; Subtyp : Entity_Id) is Choice_Type : constant Entity_Id := Base_Type (Subtyp); -- The actual type against which the discrete choices are resolved. -- Note that this type is always the base type not the subtype of the -- ruling expression, index or discriminant. Expected_Type : Entity_Id; -- The expected type of each choice. Equal to Choice_Type, except if -- the expression is universal, in which case the choices can be of -- any integer type. Alt : Node_Id; -- A case statement alternative or a variant in a record type -- declaration. Choice : Node_Id; Kind : Node_Kind; -- The node kind of the current Choice begin -- Set Expected type (= choice type except for universal integer, -- where we accept any integer type as a choice). if Choice_Type = Universal_Integer then Expected_Type := Any_Integer; else Expected_Type := Choice_Type; end if; -- Now loop through the case alternatives or record variants Alt := First (Alternatives); while Present (Alt) loop -- If pragma, just analyze it if Nkind (Alt) = N_Pragma then Analyze (Alt); -- Otherwise we have an alternative. In most cases the semantic -- processing leaves the list of choices unchanged -- Check each choice against its base type else Choice := First (Discrete_Choices (Alt)); while Present (Choice) loop Analyze (Choice); Kind := Nkind (Choice); -- Choice is a Range if Kind = N_Range or else (Kind = N_Attribute_Reference and then Attribute_Name (Choice) = Name_Range) then Resolve (Choice, Expected_Type); -- Choice is a subtype name, nothing further to do now elsif Is_Entity_Name (Choice) and then Is_Type (Entity (Choice)) then null; -- Choice is a subtype indication elsif Kind = N_Subtype_Indication then Resolve_Discrete_Subtype_Indication (Choice, Expected_Type); -- Others choice, no analysis needed elsif Kind = N_Others_Choice then null; -- Only other possibility is an expression else Resolve (Choice, Expected_Type); end if; -- Move to next choice Next (Choice); end loop; Process_Associated_Node (Alt); end if; Next (Alt); end loop; end Analyze_Choices; end Generic_Analyze_Choices; --------------------------- -- Generic_Check_Choices -- --------------------------- package body Generic_Check_Choices is -- The following type is used to gather the entries for the choice -- table, so that we can then allocate the right length. type Link; type Link_Ptr is access all Link; type Link is record Val : Choice_Bounds; Nxt : Link_Ptr; end record; procedure Free is new Ada.Unchecked_Deallocation (Link, Link_Ptr); ------------------- -- Check_Choices -- ------------------- procedure Check_Choices (N : Node_Id; Alternatives : List_Id; Subtyp : Entity_Id; Others_Present : out Boolean) is E : Entity_Id; Raises_CE : Boolean; -- Set True if one of the bounds of a choice raises CE Enode : Node_Id; -- This is where we post error messages for bounds out of range Choice_List : Link_Ptr := null; -- Gather list of choices Num_Choices : Nat := 0; -- Number of entries in Choice_List Choice_Type : constant Entity_Id := Base_Type (Subtyp); -- The actual type against which the discrete choices are resolved. -- Note that this type is always the base type not the subtype of the -- ruling expression, index or discriminant. Bounds_Type : Entity_Id; -- The type from which are derived the bounds of the values covered -- by the discrete choices (see 3.8.1 (4)). If a discrete choice -- specifies a value outside of these bounds we have an error. Bounds_Lo : Uint; Bounds_Hi : Uint; -- The actual bounds of the above type Expected_Type : Entity_Id; -- The expected type of each choice. Equal to Choice_Type, except if -- the expression is universal, in which case the choices can be of -- any integer type. Alt : Node_Id; -- A case statement alternative or a variant in a record type -- declaration. Choice : Node_Id; Kind : Node_Kind; -- The node kind of the current Choice Others_Choice : Node_Id := Empty; -- Remember others choice if it is present (empty otherwise) procedure Check (Choice : Node_Id; Lo, Hi : Node_Id); -- Checks the validity of the bounds of a choice. When the bounds -- are static and no error occurred the bounds are collected for -- later entry into the choices table so that they can be sorted -- later on. procedure Check_Case_Pattern_Choices; -- Check choices validity for the Ada extension case where the -- selecting expression is not of a discrete type and so the -- choices are patterns. procedure Check_Composite_Case_Selector; -- Check that the (non-discrete) type of the expression being -- cased on is suitable. procedure Handle_Static_Predicate (Typ : Entity_Id; Lo : Node_Id; Hi : Node_Id); -- If the type of the alternative has predicates, we must examine -- each subset of the predicate rather than the bounds of the type -- itself. This is relevant when the choice is a subtype mark or a -- subtype indication. ----------- -- Check -- ----------- procedure Check (Choice : Node_Id; Lo, Hi : Node_Id) is Lo_Val : Uint; Hi_Val : Uint; begin -- First check if an error was already detected on either bounds if Etype (Lo) = Any_Type or else Etype (Hi) = Any_Type then return; -- Do not insert non static choices in the table to be sorted elsif not Is_OK_Static_Expression (Lo) or else not Is_OK_Static_Expression (Hi) then Process_Non_Static_Choice (Choice); return; -- Ignore range which raise constraint error elsif Raises_Constraint_Error (Lo) or else Raises_Constraint_Error (Hi) then Raises_CE := True; return; -- AI05-0188 : Within an instance the non-others choices do not -- have to belong to the actual subtype. elsif Ada_Version >= Ada_2012 and then In_Instance then return; -- Otherwise we have an OK static choice else Lo_Val := Expr_Value (Lo); Hi_Val := Expr_Value (Hi); -- Do not insert null ranges in the choices table if Lo_Val > Hi_Val then Process_Empty_Choice (Choice); return; end if; end if; -- Check for low bound out of range if Lo_Val < Bounds_Lo then -- If the choice is an entity name, then it is a type, and we -- want to post the message on the reference to this entity. -- Otherwise post it on the lower bound of the range. if Is_Entity_Name (Choice) then Enode := Choice; else Enode := Lo; end if; -- Specialize message for integer/enum type if Is_Integer_Type (Bounds_Type) then Error_Msg_Uint_1 := Bounds_Lo; Error_Msg_N ("minimum allowed choice value is^", Enode); else Error_Msg_Name_1 := Choice_Image (Bounds_Lo, Bounds_Type); Error_Msg_N ("minimum allowed choice value is%", Enode); end if; end if; -- Check for high bound out of range if Hi_Val > Bounds_Hi then -- If the choice is an entity name, then it is a type, and we -- want to post the message on the reference to this entity. -- Otherwise post it on the upper bound of the range. if Is_Entity_Name (Choice) then Enode := Choice; else Enode := Hi; end if; -- Specialize message for integer/enum type if Is_Integer_Type (Bounds_Type) then Error_Msg_Uint_1 := Bounds_Hi; Error_Msg_N ("maximum allowed choice value is^", Enode); else Error_Msg_Name_1 := Choice_Image (Bounds_Hi, Bounds_Type); Error_Msg_N ("maximum allowed choice value is%", Enode); end if; end if; -- Collect bounds in the list -- Note: we still store the bounds, even if they are out of range, -- since this may prevent unnecessary cascaded errors for values -- that are covered by such an excessive range. Choice_List := new Link'(Val => (Lo, Hi, Choice), Nxt => Choice_List); Num_Choices := Num_Choices + 1; end Check; -------------------------------- -- Check_Case_Pattern_Choices -- -------------------------------- procedure Check_Case_Pattern_Choices is -- ??? Need to Free/Finalize value sets allocated here. package Ops is new Composite_Case_Ops.Choice_Analysis (Case_Statement => N); use Ops; use Ops.Value_Sets; Empty : Value_Set renames Value_Sets.Empty; -- Cope with hiding due to multiple use clauses Info : constant Choices_Info := Analysis; Others_Seen : Boolean := False; begin declare Matches : array (Alternative_Id) of Value_Sets.Value_Set := (others => Empty); Flag_Overlapping_Within_One_Alternative : constant Boolean := False; -- We may want to flag overlapping (perhaps with only a -- warning) if the pattern binds an identifier, as in -- when (Positive, <X>) | (Integer, <X>) => Covered : Value_Set := Empty; -- The union of all alternatives seen so far begin for Choice of Info loop if Choice.Is_Others then Others_Seen := True; else if Flag_Overlapping_Within_One_Alternative and then (Compare (Matches (Choice.Alternative), Choice.Matches) /= Disjoint) then Error_Msg_N ("bad overlapping within one alternative", N); end if; Union (Target => Matches (Choice.Alternative), Source => Choice.Matches); end if; end loop; for A1 in Alternative_Id loop for A2 in Alternative_Id range A1 + 1 .. Alternative_Id'Last loop case Compare (Matches (A1), Matches (A2)) is when Disjoint | Contained_By => null; -- OK when Overlaps => declare Uncovered_1, Uncovered_2 : Value_Set := Empty; begin Union (Uncovered_1, Matches (A1)); Remove (Uncovered_1, Covered); Union (Uncovered_2, Matches (A2)); Remove (Uncovered_2, Covered); -- Recheck for overlap after removing choices -- covered by earlier alternatives. case Compare (Uncovered_1, Uncovered_2) is when Disjoint | Contained_By => null; when Contains | Overlaps | Equal => Error_Msg_N ("bad alternative overlapping", N); end case; end; when Equal => Error_Msg_N ("alternatives match same values", N); when Contains => Error_Msg_N ("alternatives in wrong order", N); end case; end loop; Union (Target => Covered, Source => Matches (A1)); end loop; if (not Others_Seen) and then not Complement_Is_Empty (Covered) then Error_Msg_N ("not all values are covered", N); end if; end; Ops.Value_Sets.Free_Value_Sets; end Check_Case_Pattern_Choices; ----------------------------------- -- Check_Composite_Case_Selector -- ----------------------------------- procedure Check_Composite_Case_Selector is begin if not Is_Composite_Type (Subtyp) then Error_Msg_N ("case selector type must be discrete or composite", N); elsif Is_Limited_Type (Subtyp) then Error_Msg_N ("case selector type must not be limited", N); elsif Is_Class_Wide_Type (Subtyp) then Error_Msg_N ("case selector type must not be class-wide", N); elsif Needs_Finalization (Subtyp) and then Is_Newly_Constructed (Expression (N), Context_Requires_NC => False) then -- We could allow this case as long as there are no bindings. -- -- If there are bindings, then allowing this case will get -- messy because the selector expression will be finalized -- before the statements of the selected alternative are -- executed (unless we add an INOX-specific change to the -- accessibility rules to prevent this earlier-than-wanted -- finalization, but adding new INOX-specific accessibility -- complexity is probably not the direction we want to go). -- This early selector finalization would be ok if we made -- copies in this case (so that the bindings would not yield -- a view of a finalized object), but then we'd have to deal -- with finalizing those copies (which would necessarily -- include defining their accessibility level). So it gets -- messy either way. Error_Msg_N ("case selector must not require finalization", N); end if; end Check_Composite_Case_Selector; ----------------------------- -- Handle_Static_Predicate -- ----------------------------- procedure Handle_Static_Predicate (Typ : Entity_Id; Lo : Node_Id; Hi : Node_Id) is P : Node_Id; C : Node_Id; begin -- Loop through entries in predicate list, checking each entry. -- Note that if the list is empty, corresponding to a False -- predicate, then no choices are checked. If the choice comes -- from a subtype indication, the given range may have bounds -- that narrow the predicate choices themselves, so we must -- consider only those entries within the range of the given -- subtype indication.. P := First (Static_Discrete_Predicate (Typ)); while Present (P) loop -- Check that part of the predicate choice is included in the -- given bounds. if Expr_Value (High_Bound (P)) >= Expr_Value (Lo) and then Expr_Value (Low_Bound (P)) <= Expr_Value (Hi) then C := New_Copy (P); Set_Sloc (C, Sloc (Choice)); Set_Original_Node (C, Choice); if Expr_Value (Low_Bound (C)) < Expr_Value (Lo) then Set_Low_Bound (C, Lo); end if; if Expr_Value (High_Bound (C)) > Expr_Value (Hi) then Set_High_Bound (C, Hi); end if; Check (C, Low_Bound (C), High_Bound (C)); end if; Next (P); end loop; Set_Has_SP_Choice (Alt); end Handle_Static_Predicate; -- Start of processing for Check_Choices begin Raises_CE := False; Others_Present := False; -- If Subtyp is not a discrete type or there was some other error, -- then don't try any semantic checking on the choices since we have -- a complete mess. if not Is_Discrete_Type (Subtyp) or else Subtyp = Any_Type then -- Hold on, maybe it isn't a complete mess after all. if Extensions_Allowed and then Subtyp /= Any_Type then Check_Composite_Case_Selector; Check_Case_Pattern_Choices; end if; return; end if; -- If Subtyp is not a static subtype Ada 95 requires then we use the -- bounds of its base type to determine the values covered by the -- discrete choices. -- In Ada 2012, if the subtype has a nonstatic predicate the full -- range of the base type must be covered as well. if Is_OK_Static_Subtype (Subtyp) then if not Has_Predicates (Subtyp) or else Has_Static_Predicate (Subtyp) then Bounds_Type := Subtyp; else Bounds_Type := Choice_Type; end if; else Bounds_Type := Choice_Type; end if; -- Obtain static bounds of type, unless this is a generic formal -- discrete type for which all choices will be nonstatic. if not Is_Generic_Type (Root_Type (Bounds_Type)) or else Ekind (Bounds_Type) /= E_Enumeration_Type then Bounds_Lo := Expr_Value (Type_Low_Bound (Bounds_Type)); Bounds_Hi := Expr_Value (Type_High_Bound (Bounds_Type)); end if; if Choice_Type = Universal_Integer then Expected_Type := Any_Integer; else Expected_Type := Choice_Type; end if; -- Now loop through the case alternatives or record variants Alt := First (Alternatives); while Present (Alt) loop -- If pragma, just analyze it if Nkind (Alt) = N_Pragma then Analyze (Alt); -- Otherwise we have an alternative. In most cases the semantic -- processing leaves the list of choices unchanged -- Check each choice against its base type else Choice := First (Discrete_Choices (Alt)); while Present (Choice) loop Kind := Nkind (Choice); -- Choice is a Range if Kind = N_Range or else (Kind = N_Attribute_Reference and then Attribute_Name (Choice) = Name_Range) then Check (Choice, Low_Bound (Choice), High_Bound (Choice)); -- Choice is a subtype name elsif Is_Entity_Name (Choice) and then Is_Type (Entity (Choice)) then -- Check for inappropriate type if not Covers (Expected_Type, Etype (Choice)) then Wrong_Type (Choice, Choice_Type); -- Type is OK, so check further else E := Entity (Choice); -- Case of predicated subtype if Has_Predicates (E) then -- Use of nonstatic predicate is an error if not Is_Discrete_Type (E) or else not Has_Static_Predicate (E) or else Has_Dynamic_Predicate_Aspect (E) then Bad_Predicated_Subtype_Use ("cannot use subtype& with non-static " & "predicate as case alternative", Choice, E, Suggest_Static => True); -- Static predicate case. The bounds are those of -- the given subtype. else Handle_Static_Predicate (E, Type_Low_Bound (E), Type_High_Bound (E)); end if; -- Not predicated subtype case elsif not Is_OK_Static_Subtype (E) then Process_Non_Static_Choice (Choice); else Check (Choice, Type_Low_Bound (E), Type_High_Bound (E)); end if; end if; -- Choice is a subtype indication elsif Kind = N_Subtype_Indication then Resolve_Discrete_Subtype_Indication (Choice, Expected_Type); if Etype (Choice) /= Any_Type then declare C : constant Node_Id := Constraint (Choice); R : constant Node_Id := Range_Expression (C); L : constant Node_Id := Low_Bound (R); H : constant Node_Id := High_Bound (R); begin E := Entity (Subtype_Mark (Choice)); if not Is_OK_Static_Subtype (E) then Process_Non_Static_Choice (Choice); else if Is_OK_Static_Expression (L) and then Is_OK_Static_Expression (H) then if Expr_Value (L) > Expr_Value (H) then Process_Empty_Choice (Choice); else if Is_Out_Of_Range (L, E) then Apply_Compile_Time_Constraint_Error (L, "static value out of range", CE_Range_Check_Failed); end if; if Is_Out_Of_Range (H, E) then Apply_Compile_Time_Constraint_Error (H, "static value out of range", CE_Range_Check_Failed); end if; end if; end if; -- Check applicable predicate values within the -- bounds of the given range. if Has_Static_Predicate (E) then Handle_Static_Predicate (E, L, H); else Check (Choice, L, H); end if; end if; end; end if; -- The others choice is only allowed for the last -- alternative and as its only choice. elsif Kind = N_Others_Choice then if not (Choice = First (Discrete_Choices (Alt)) and then Choice = Last (Discrete_Choices (Alt)) and then Alt = Last (Alternatives)) then Error_Msg_N ("the choice OTHERS must appear alone and last", Choice); return; end if; Others_Present := True; Others_Choice := Choice; -- Only other possibility is an expression else Check (Choice, Choice, Choice); end if; -- Move to next choice Next (Choice); end loop; Process_Associated_Node (Alt); end if; Next (Alt); end loop; -- Now we can create the Choice_Table, since we know how long -- it needs to be so we can allocate exactly the right length. declare Choice_Table : Choice_Table_Type (0 .. Num_Choices); begin -- Now copy the items we collected in the linked list into this -- newly allocated table (leave entry 0 unused for sorting). declare T : Link_Ptr; begin for J in 1 .. Num_Choices loop T := Choice_List; Choice_List := T.Nxt; Choice_Table (J) := T.Val; Free (T); end loop; end; Check_Choice_Set (Choice_Table, Bounds_Type, Subtyp, Others_Present or else (Choice_Type = Universal_Integer), N); -- If no others choice we are all done, otherwise we have one more -- step, which is to set the Others_Discrete_Choices field of the -- others choice (to contain all otherwise unspecified choices). -- Skip this if CE is known to be raised. if Others_Present and not Raises_CE then Expand_Others_Choice (Case_Table => Choice_Table, Others_Choice => Others_Choice, Choice_Type => Bounds_Type); end if; end; end Check_Choices; end Generic_Check_Choices; ----------------------------------------- -- Has_Static_Discriminant_Constraint -- ----------------------------------------- function Has_Static_Discriminant_Constraint (Subtyp : Entity_Id) return Boolean is begin if Has_Discriminants (Subtyp) and then Is_Constrained (Subtyp) then declare DC_Elmt : Elmt_Id := First_Elmt (Discriminant_Constraint (Subtyp)); begin while Present (DC_Elmt) loop if not All_Composite_Constraints_Static (Node (DC_Elmt)) then return False; end if; Next_Elmt (DC_Elmt); end loop; return True; end; end if; return False; end Has_Static_Discriminant_Constraint; ---------------------------- -- Is_Case_Choice_Pattern -- ---------------------------- function Is_Case_Choice_Pattern (Expr : Node_Id) return Boolean is E : Node_Id := Expr; begin if not Extensions_Allowed then return False; end if; loop case Nkind (E) is when N_Case_Statement_Alternative | N_Case_Expression_Alternative => -- We could return False if selecting expression is discrete, -- but this doesn't seem to be worth the bother. return True; when N_Empty | N_Statement_Other_Than_Procedure_Call | N_Procedure_Call_Statement | N_Declaration => return False; when others => E := Parent (E); end case; end loop; end Is_Case_Choice_Pattern; end Sem_Case;
AdaCore/Ada_Drivers_Library
Ada
11,929
ads
-- This spec has been automatically generated from STM32F46_79x.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package STM32_SVD.DCMI is pragma Preelaborate; --------------- -- Registers -- --------------- subtype CR_FCRC_Field is HAL.UInt2; subtype CR_EDM_Field is HAL.UInt2; -- control register 1 type CR_Register is record -- Capture enable CAPTURE : Boolean := False; -- Capture mode CM : Boolean := False; -- Crop feature CROP : Boolean := False; -- JPEG format JPEG : Boolean := False; -- Embedded synchronization select ESS : Boolean := False; -- Pixel clock polarity PCKPOL : Boolean := False; -- Horizontal synchronization polarity HSPOL : Boolean := False; -- Vertical synchronization polarity VSPOL : Boolean := False; -- Frame capture rate control FCRC : CR_FCRC_Field := 16#0#; -- Extended data mode EDM : CR_EDM_Field := 16#0#; -- unspecified Reserved_12_13 : HAL.UInt2 := 16#0#; -- DCMI enable ENABLE : Boolean := False; -- unspecified Reserved_15_31 : HAL.UInt17 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR_Register use record CAPTURE at 0 range 0 .. 0; CM at 0 range 1 .. 1; CROP at 0 range 2 .. 2; JPEG at 0 range 3 .. 3; ESS at 0 range 4 .. 4; PCKPOL at 0 range 5 .. 5; HSPOL at 0 range 6 .. 6; VSPOL at 0 range 7 .. 7; FCRC at 0 range 8 .. 9; EDM at 0 range 10 .. 11; Reserved_12_13 at 0 range 12 .. 13; ENABLE at 0 range 14 .. 14; Reserved_15_31 at 0 range 15 .. 31; end record; -- status register type SR_Register is record -- Read-only. HSYNC HSYNC : Boolean; -- Read-only. VSYNC VSYNC : Boolean; -- Read-only. FIFO not empty FNE : Boolean; -- unspecified Reserved_3_31 : HAL.UInt29; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SR_Register use record HSYNC at 0 range 0 .. 0; VSYNC at 0 range 1 .. 1; FNE at 0 range 2 .. 2; Reserved_3_31 at 0 range 3 .. 31; end record; -- raw interrupt status register type RIS_Register is record -- Read-only. Capture complete raw interrupt status FRAME_RIS : Boolean; -- Read-only. Overrun raw interrupt status OVR_RIS : Boolean; -- Read-only. Synchronization error raw interrupt status ERR_RIS : Boolean; -- Read-only. VSYNC raw interrupt status VSYNC_RIS : Boolean; -- Read-only. Line raw interrupt status LINE_RIS : Boolean; -- unspecified Reserved_5_31 : HAL.UInt27; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for RIS_Register use record FRAME_RIS at 0 range 0 .. 0; OVR_RIS at 0 range 1 .. 1; ERR_RIS at 0 range 2 .. 2; VSYNC_RIS at 0 range 3 .. 3; LINE_RIS at 0 range 4 .. 4; Reserved_5_31 at 0 range 5 .. 31; end record; -- interrupt enable register type IER_Register is record -- Capture complete interrupt enable FRAME_IE : Boolean := False; -- Overrun interrupt enable OVR_IE : Boolean := False; -- Synchronization error interrupt enable ERR_IE : Boolean := False; -- VSYNC interrupt enable VSYNC_IE : Boolean := False; -- Line interrupt enable LINE_IE : Boolean := False; -- unspecified Reserved_5_31 : HAL.UInt27 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for IER_Register use record FRAME_IE at 0 range 0 .. 0; OVR_IE at 0 range 1 .. 1; ERR_IE at 0 range 2 .. 2; VSYNC_IE at 0 range 3 .. 3; LINE_IE at 0 range 4 .. 4; Reserved_5_31 at 0 range 5 .. 31; end record; -- masked interrupt status register type MIS_Register is record -- Read-only. Capture complete masked interrupt status FRAME_MIS : Boolean; -- Read-only. Overrun masked interrupt status OVR_MIS : Boolean; -- Read-only. Synchronization error masked interrupt status ERR_MIS : Boolean; -- Read-only. VSYNC masked interrupt status VSYNC_MIS : Boolean; -- Read-only. Line masked interrupt status LINE_MIS : Boolean; -- unspecified Reserved_5_31 : HAL.UInt27; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MIS_Register use record FRAME_MIS at 0 range 0 .. 0; OVR_MIS at 0 range 1 .. 1; ERR_MIS at 0 range 2 .. 2; VSYNC_MIS at 0 range 3 .. 3; LINE_MIS at 0 range 4 .. 4; Reserved_5_31 at 0 range 5 .. 31; end record; -- interrupt clear register type ICR_Register is record -- Write-only. Capture complete interrupt status clear FRAME_ISC : Boolean := False; -- Write-only. Overrun interrupt status clear OVR_ISC : Boolean := False; -- Write-only. Synchronization error interrupt status clear ERR_ISC : Boolean := False; -- Write-only. Vertical synch interrupt status clear VSYNC_ISC : Boolean := False; -- Write-only. line interrupt status clear LINE_ISC : Boolean := False; -- unspecified Reserved_5_31 : HAL.UInt27 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for ICR_Register use record FRAME_ISC at 0 range 0 .. 0; OVR_ISC at 0 range 1 .. 1; ERR_ISC at 0 range 2 .. 2; VSYNC_ISC at 0 range 3 .. 3; LINE_ISC at 0 range 4 .. 4; Reserved_5_31 at 0 range 5 .. 31; end record; subtype ESCR_FSC_Field is HAL.UInt8; subtype ESCR_LSC_Field is HAL.UInt8; subtype ESCR_LEC_Field is HAL.UInt8; subtype ESCR_FEC_Field is HAL.UInt8; -- embedded synchronization code register type ESCR_Register is record -- Frame start delimiter code FSC : ESCR_FSC_Field := 16#0#; -- Line start delimiter code LSC : ESCR_LSC_Field := 16#0#; -- Line end delimiter code LEC : ESCR_LEC_Field := 16#0#; -- Frame end delimiter code FEC : ESCR_FEC_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for ESCR_Register use record FSC at 0 range 0 .. 7; LSC at 0 range 8 .. 15; LEC at 0 range 16 .. 23; FEC at 0 range 24 .. 31; end record; subtype ESUR_FSU_Field is HAL.UInt8; subtype ESUR_LSU_Field is HAL.UInt8; subtype ESUR_LEU_Field is HAL.UInt8; subtype ESUR_FEU_Field is HAL.UInt8; -- embedded synchronization unmask register type ESUR_Register is record -- Frame start delimiter unmask FSU : ESUR_FSU_Field := 16#0#; -- Line start delimiter unmask LSU : ESUR_LSU_Field := 16#0#; -- Line end delimiter unmask LEU : ESUR_LEU_Field := 16#0#; -- Frame end delimiter unmask FEU : ESUR_FEU_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for ESUR_Register use record FSU at 0 range 0 .. 7; LSU at 0 range 8 .. 15; LEU at 0 range 16 .. 23; FEU at 0 range 24 .. 31; end record; subtype CWSTRT_HOFFCNT_Field is HAL.UInt14; subtype CWSTRT_VST_Field is HAL.UInt13; -- crop window start type CWSTRT_Register is record -- Horizontal offset count HOFFCNT : CWSTRT_HOFFCNT_Field := 16#0#; -- unspecified Reserved_14_15 : HAL.UInt2 := 16#0#; -- Vertical start line count VST : CWSTRT_VST_Field := 16#0#; -- unspecified Reserved_29_31 : HAL.UInt3 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CWSTRT_Register use record HOFFCNT at 0 range 0 .. 13; Reserved_14_15 at 0 range 14 .. 15; VST at 0 range 16 .. 28; Reserved_29_31 at 0 range 29 .. 31; end record; subtype CWSIZE_CAPCNT_Field is HAL.UInt14; subtype CWSIZE_VLINE_Field is HAL.UInt14; -- crop window size type CWSIZE_Register is record -- Capture count CAPCNT : CWSIZE_CAPCNT_Field := 16#0#; -- unspecified Reserved_14_15 : HAL.UInt2 := 16#0#; -- Vertical line count VLINE : CWSIZE_VLINE_Field := 16#0#; -- unspecified Reserved_30_31 : HAL.UInt2 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CWSIZE_Register use record CAPCNT at 0 range 0 .. 13; Reserved_14_15 at 0 range 14 .. 15; VLINE at 0 range 16 .. 29; Reserved_30_31 at 0 range 30 .. 31; end record; -- DR_Byte array element subtype DR_Byte_Element is HAL.UInt8; -- DR_Byte array type DR_Byte_Field_Array is array (0 .. 3) of DR_Byte_Element with Component_Size => 8, Size => 32; -- data register type DR_Register (As_Array : Boolean := False) is record case As_Array is when False => -- Byte as a value Val : HAL.UInt32; when True => -- Byte as an array Arr : DR_Byte_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for DR_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Digital camera interface type DCMI_Peripheral is record -- control register 1 CR : aliased CR_Register; -- status register SR : aliased SR_Register; -- raw interrupt status register RIS : aliased RIS_Register; -- interrupt enable register IER : aliased IER_Register; -- masked interrupt status register MIS : aliased MIS_Register; -- interrupt clear register ICR : aliased ICR_Register; -- embedded synchronization code register ESCR : aliased ESCR_Register; -- embedded synchronization unmask register ESUR : aliased ESUR_Register; -- crop window start CWSTRT : aliased CWSTRT_Register; -- crop window size CWSIZE : aliased CWSIZE_Register; -- data register DR : aliased DR_Register; end record with Volatile; for DCMI_Peripheral use record CR at 16#0# range 0 .. 31; SR at 16#4# range 0 .. 31; RIS at 16#8# range 0 .. 31; IER at 16#C# range 0 .. 31; MIS at 16#10# range 0 .. 31; ICR at 16#14# range 0 .. 31; ESCR at 16#18# range 0 .. 31; ESUR at 16#1C# range 0 .. 31; CWSTRT at 16#20# range 0 .. 31; CWSIZE at 16#24# range 0 .. 31; DR at 16#28# range 0 .. 31; end record; -- Digital camera interface DCMI_Periph : aliased DCMI_Peripheral with Import, Address => System'To_Address (16#50050000#); end STM32_SVD.DCMI;
reznikmm/matreshka
Ada
3,764
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.Style_Snap_To_Layout_Grid_Attributes is pragma Preelaborate; type ODF_Style_Snap_To_Layout_Grid_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Style_Snap_To_Layout_Grid_Attribute_Access is access all ODF_Style_Snap_To_Layout_Grid_Attribute'Class with Storage_Size => 0; end ODF.DOM.Style_Snap_To_Layout_Grid_Attributes;
charlie5/cBound
Ada
1,755
ads
-- This file is generated by SWIG. Please do not modify by hand. -- with Interfaces; with swig; with Interfaces.C; with Interfaces.C.Pointers; package xcb.xcb_glx_get_color_table_reply_t is -- Item -- type Item is record response_type : aliased Interfaces.Unsigned_8; pad0 : aliased Interfaces.Unsigned_8; sequence : aliased Interfaces.Unsigned_16; length : aliased Interfaces.Unsigned_32; pad1 : aliased swig.int8_t_Array (0 .. 7); width : aliased Interfaces.Integer_32; pad2 : aliased swig.int8_t_Array (0 .. 11); end record; -- Item_Array -- type Item_Array is array (Interfaces.C .size_t range <>) of aliased xcb.xcb_glx_get_color_table_reply_t .Item; -- Pointer -- package C_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_glx_get_color_table_reply_t.Item, Element_Array => xcb.xcb_glx_get_color_table_reply_t.Item_Array, Default_Terminator => (others => <>)); subtype Pointer is C_Pointers.Pointer; -- Pointer_Array -- type Pointer_Array is array (Interfaces.C .size_t range <>) of aliased xcb.xcb_glx_get_color_table_reply_t .Pointer; -- Pointer_Pointer -- package C_Pointer_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_glx_get_color_table_reply_t.Pointer, Element_Array => xcb.xcb_glx_get_color_table_reply_t.Pointer_Array, Default_Terminator => null); subtype Pointer_Pointer is C_Pointer_Pointers.Pointer; end xcb.xcb_glx_get_color_table_reply_t;
Letractively/ada-ado
Ada
9,293
ads
----------------------------------------------------------------------- -- Regtests.Comments -- Regtests.Comments ----------------------------------------------------------------------- -- File generated by ada-gen DO NOT MODIFY -- Template used: templates/model/package-spec.xhtml -- Ada Generator: https://ada-gen.googlecode.com/svn/trunk Revision 166 ----------------------------------------------------------------------- -- Copyright (C) 2011 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. ----------------------------------------------------------------------- pragma Warnings (Off, "unit * is not referenced"); with ADO.Sessions; with ADO.Objects; with ADO.Statements; with ADO.SQL; with ADO.Schemas; with Ada.Calendar; with Ada.Containers.Vectors; with Ada.Strings.Unbounded; with Util.Beans.Objects; with Util.Beans.Basic.Lists; with Regtests.Simple.Model; pragma Warnings (On, "unit * is not referenced"); package Regtests.Comments is -- -------------------- -- The Comment table records a user comment associated with a database entity. -- The comment can be associated with any other database record. -- -------------------- -- Create an object key for Comment. function Comment_Key (Id : in ADO.Identifier) return ADO.Objects.Object_Key; -- Create an object key for Comment from a string. -- Raises Constraint_Error if the string cannot be converted into the object key. function Comment_Key (Id : in String) return ADO.Objects.Object_Key; type Comment_Ref is new ADO.Objects.Object_Ref with null record; Null_Comment : constant Comment_Ref; function "=" (Left, Right : Comment_Ref'Class) return Boolean; -- Set the comment identifier procedure Set_Id (Object : in out Comment_Ref; Value : in ADO.Identifier); -- Get the comment identifier function Get_Id (Object : in Comment_Ref) return ADO.Identifier; -- Get the comment version. function Get_Version (Object : in Comment_Ref) return Integer; -- Set the comment publication date. procedure Set_Date (Object : in out Comment_Ref; Value : in Ada.Calendar.Time); -- Get the comment publication date. function Get_Date (Object : in Comment_Ref) return Ada.Calendar.Time; -- Set the comment message. procedure Set_Message (Object : in out Comment_Ref; Value : in Ada.Strings.Unbounded.Unbounded_String); procedure Set_Message (Object : in out Comment_Ref; Value : in String); -- Get the comment message. function Get_Message (Object : in Comment_Ref) return Ada.Strings.Unbounded.Unbounded_String; function Get_Message (Object : in Comment_Ref) return String; -- Set the entity identifier to which this comment is associated. procedure Set_Entity_Id (Object : in out Comment_Ref; Value : in Integer); -- Get the entity identifier to which this comment is associated. function Get_Entity_Id (Object : in Comment_Ref) return Integer; -- Set the user who posted this comment procedure Set_User (Object : in out Comment_Ref; Value : in Regtests.Simple.Model.User_Ref'Class); -- Get the user who posted this comment function Get_User (Object : in Comment_Ref) return Regtests.Simple.Model.User_Ref'Class; -- Set the entity type that correspond to the entity associated with this comment. procedure Set_Entity_Type (Object : in out Comment_Ref; Value : in ADO.Entity_Type); -- Get the entity type that correspond to the entity associated with this comment. function Get_Entity_Type (Object : in Comment_Ref) return ADO.Entity_Type; -- Load the entity identified by 'Id'. -- Raises the NOT_FOUND exception if it does not exist. procedure Load (Object : in out Comment_Ref; Session : in out ADO.Sessions.Session'Class; Id : in ADO.Identifier); -- Load the entity identified by 'Id'. -- Returns True in <b>Found</b> if the object was found and False if it does not exist. procedure Load (Object : in out Comment_Ref; Session : in out ADO.Sessions.Session'Class; Id : in ADO.Identifier; Found : out Boolean); -- Find and load the entity. overriding procedure Find (Object : in out Comment_Ref; Session : in out ADO.Sessions.Session'Class; Query : in ADO.SQL.Query'Class; Found : out Boolean); -- Save the entity. If the entity does not have an identifier, an identifier is allocated -- and it is inserted in the table. Otherwise, only data fields which have been changed -- are updated. overriding procedure Save (Object : in out Comment_Ref; Session : in out ADO.Sessions.Master_Session'Class); -- Delete the entity. overriding procedure Delete (Object : in out Comment_Ref; Session : in out ADO.Sessions.Master_Session'Class); overriding function Get_Value (Item : in Comment_Ref; Name : in String) return Util.Beans.Objects.Object; -- Table definition COMMENT_TABLE : aliased constant ADO.Schemas.Class_Mapping; -- Internal method to allocate the Object_Record instance overriding procedure Allocate (Object : in out Comment_Ref); -- Copy of the object. procedure Copy (Object : in Comment_Ref; Into : in out Comment_Ref); package Comment_Vectors is new Ada.Containers.Vectors (Index_Type => Natural, Element_Type => Comment_Ref, "=" => "="); subtype Comment_Vector is Comment_Vectors.Vector; procedure List (Object : in out Comment_Vector; Session : in out ADO.Sessions.Session'Class; Query : in ADO.SQL.Query'Class); private COMMENT_NAME : aliased constant String := "TEST_COMMENTS"; COL_0_1_NAME : aliased constant String := "ID"; COL_1_1_NAME : aliased constant String := "version"; COL_2_1_NAME : aliased constant String := "DATE"; COL_3_1_NAME : aliased constant String := "MESSAGE"; COL_4_1_NAME : aliased constant String := "ENTITY_ID"; COL_5_1_NAME : aliased constant String := "USER_FK"; COL_6_1_NAME : aliased constant String := "ENTITY__TYPE_FK"; COMMENT_TABLE : aliased constant ADO.Schemas.Class_Mapping := (Count => 7, Table => COMMENT_NAME'Access, Members => ( COL_0_1_NAME'Access, COL_1_1_NAME'Access, COL_2_1_NAME'Access, COL_3_1_NAME'Access, COL_4_1_NAME'Access, COL_5_1_NAME'Access, COL_6_1_NAME'Access ) ); Null_Comment : constant Comment_Ref := Comment_Ref'(ADO.Objects.Object_Ref with others => <>); type Comment_Impl is new ADO.Objects.Object_Record (Key_Type => ADO.Objects.KEY_INTEGER, Of_Class => COMMENT_TABLE'Access) with record Version : Integer; Date : Ada.Calendar.Time; Message : Ada.Strings.Unbounded.Unbounded_String; Entity_Id : Integer; User : Regtests.Simple.Model.User_Ref; Entity_Type : ADO.Entity_Type; end record; type Comment_Access is access all Comment_Impl; overriding procedure Destroy (Object : access Comment_Impl); overriding procedure Find (Object : in out Comment_Impl; Session : in out ADO.Sessions.Session'Class; Query : in ADO.SQL.Query'Class; Found : out Boolean); overriding procedure Load (Object : in out Comment_Impl; Session : in out ADO.Sessions.Session'Class); procedure Load (Object : in out Comment_Impl; Stmt : in out ADO.Statements.Query_Statement'Class; Session : in out ADO.Sessions.Session'Class); overriding procedure Save (Object : in out Comment_Impl; Session : in out ADO.Sessions.Master_Session'Class); procedure Create (Object : in out Comment_Impl; Session : in out ADO.Sessions.Master_Session'Class); overriding procedure Delete (Object : in out Comment_Impl; Session : in out ADO.Sessions.Master_Session'Class); procedure Set_Field (Object : in out Comment_Ref'Class; Impl : out Comment_Access); end Regtests.Comments;
reznikmm/spawn
Ada
740
adb
-- -- Copyright (C) 2018-2019, AdaCore -- -- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -- with Ada.Strings.Fixed; with GNAT.Strings; with Glib.Spawn; separate (Spawn.Environments) procedure Initialize_Default (Default : out Spawn.Environments.Process_Environment) is List : GNAT.Strings.String_List := Glib.Spawn.Get_Environ; begin for Text of List loop declare Separator : constant Natural := Ada.Strings.Fixed.Index (Text.all, "="); begin exit when Separator = 0; Default.Insert (Text (Text'First .. Separator - 1), Text (Separator + 1 .. Text'Last)); GNAT.Strings.Free (Text); end; end loop; end Initialize_Default;
shintakezou/drake
Ada
16,546
adb
with Ada.Exception_Identification.From_Here; with System.Address_To_Named_Access_Conversions; with System.UTF_Conversions.From_8_To_16; with System.UTF_Conversions.From_16_To_8; with C.winnls; with C.winnt; package body System.Native_Text_IO is use Ada.Exception_Identification.From_Here; use type Ada.Streams.Stream_Element_Offset; use type C.signed_int; -- C.windef.WINBOOL use type C.windef.DWORD; use type C.windef.WORD; use type C.winnt.SHORT; use type C.winnt.WCHAR; package LPSTR_Conv is new Address_To_Named_Access_Conversions (C.char, C.winnt.LPSTR); function Processed_Input_Is_Enabled (Handle : Handle_Type) return Boolean; function Processed_Input_Is_Enabled (Handle : Handle_Type) return Boolean is Mode : aliased C.windef.DWORD; begin return C.wincon.GetConsoleMode (Handle, Mode'Access) /= C.windef.FALSE and then (Mode and C.wincon.ENABLE_PROCESSED_INPUT) /= 0; end Processed_Input_Is_Enabled; procedure Read_Buffer_Trailing_From_Terminal ( Handle : Handle_Type; Buffer : in out Buffer_Type; Out_Last : out Integer; -- no error since a leading data is existing Leading : C.winnt.WCHAR); procedure Read_Buffer_Trailing_From_Terminal ( Handle : Handle_Type; Buffer : in out Buffer_Type; Out_Last : out Integer; Leading : C.winnt.WCHAR) is Wide_Buffer : Wide_String (1 .. 2); Wide_Buffer_As_C : C.winnt.WCHAR_array (0 .. 1); for Wide_Buffer_As_C'Address use Wide_Buffer'Address; Wide_Buffer_Length : Natural; Read_Size : aliased C.windef.DWORD; UTF_16_Seq : Natural; Sequence_Status : UTF_Conversions.Sequence_Status_Type; -- ignore begin Wide_Buffer_As_C (0) := Leading; if Wide_Buffer_As_C (0) = C.winnt.WCHAR'Val (0) then Out_Last := 0; -- no data else Wide_Buffer_Length := 1; UTF_Conversions.UTF_16_Sequence ( Wide_Character'Val (C.winnt.WCHAR'Pos (Wide_Buffer_As_C (0))), UTF_16_Seq, Sequence_Status); if UTF_16_Seq = 2 and then C.wincon.ReadConsoleW ( hConsoleInput => Handle, lpBuffer => C.windef.LPVOID (Wide_Buffer_As_C (1)'Address), nNumberOfCharsToRead => 1, lpNumberOfCharsRead => Read_Size'Access, lpReserved => C.windef.LPVOID (Null_Address)) /= C.windef.FALSE and then Read_Size > 0 then Wide_Buffer_Length := Wide_Buffer_Length + Natural (Read_Size); end if; UTF_Conversions.From_16_To_8.Convert ( Wide_Buffer (1 .. Wide_Buffer_Length), Buffer, Out_Last); end if; end Read_Buffer_Trailing_From_Terminal; procedure GetConsoleScreenBufferInfo ( ConsoleOutput : C.winnt.HANDLE; ConsoleScreenBufferInfo : access C.wincon.CONSOLE_SCREEN_BUFFER_INFO); procedure GetConsoleScreenBufferInfo ( ConsoleOutput : C.winnt.HANDLE; ConsoleScreenBufferInfo : access C.wincon.CONSOLE_SCREEN_BUFFER_INFO) is begin if C.wincon.GetConsoleScreenBufferInfo ( ConsoleOutput, ConsoleScreenBufferInfo) = C.windef.FALSE then Raise_Exception (Device_Error'Identity); end if; end GetConsoleScreenBufferInfo; procedure SetConsoleScreenBufferSize_With_Adjusting ( ConsoleOutput : C.winnt.HANDLE; Size : C.wincon.COORD; Current : C.winnt.HANDLE); procedure SetConsoleScreenBufferSize_With_Adjusting ( ConsoleOutput : C.winnt.HANDLE; Size : C.wincon.COORD; Current : C.winnt.HANDLE) is Info, Old_Info : aliased C.wincon.CONSOLE_SCREEN_BUFFER_INFO; Old_Size : C.wincon.COORD; Rect : aliased C.wincon.SMALL_RECT; begin -- resize viewport to smaller than current window GetConsoleScreenBufferInfo (Current, Old_Info'Access); Old_Size.X := Old_Info.srWindow.Right - Old_Info.srWindow.Left + 1; Old_Size.Y := Old_Info.srWindow.Bottom - Old_Info.srWindow.Top + 1; if Size.X < Old_Size.X or else Size.Y < Old_Size.Y then Rect.Left := 0; Rect.Top := 0; Rect.Right := C.winnt.SHORT'Min (Size.X, Old_Size.X) - 1; Rect.Bottom := C.winnt.SHORT'Min (Size.Y, Old_Size.Y) - 1; if C.wincon.SetConsoleWindowInfo (ConsoleOutput, 1, Rect'Access) = C.windef.FALSE then Raise_Exception (Layout_Error'Identity); end if; end if; -- resize screen buffer if C.wincon.SetConsoleScreenBufferSize (ConsoleOutput, Size) = C.windef.FALSE then Raise_Exception (Layout_Error'Identity); -- Size is too large end if; -- maximize viewport GetConsoleScreenBufferInfo (ConsoleOutput, Info'Access); Rect.Left := 0; Rect.Top := 0; Rect.Right := Info.dwMaximumWindowSize.X - 1; Rect.Bottom := Info.dwMaximumWindowSize.Y - 1; if C.wincon.SetConsoleWindowInfo (ConsoleOutput, 1, Rect'Access) = C.windef.FALSE then Raise_Exception (Device_Error'Identity); end if; end SetConsoleScreenBufferSize_With_Adjusting; -- implementation procedure To_UTF_8 ( Buffer : aliased DBCS_Buffer_Type; Last : Natural; Out_Buffer : out Buffer_Type; Out_Last : out Natural) is Wide_Buffer : Wide_String (1 .. 2); Wide_Buffer_As_C : C.winnt.WCHAR_array (0 .. 1); for Wide_Buffer_As_C'Address use Wide_Buffer'Address; Wide_Buffer_Length : C.signed_int; DBCS_Seq : Natural; begin DBCS_Seq := 1 -- leading byte + Boolean'Pos ( C.winnls.IsDBCSLeadByte ( C.windef.BYTE'(Character'Pos (Buffer (1)))) /= C.windef.FALSE); if Last = DBCS_Seq then Wide_Buffer_Length := C.winnls.MultiByteToWideChar ( C.winnls.CP_ACP, 0, LPSTR_Conv.To_Pointer (Buffer (1)'Address), C.signed_int (Last), Wide_Buffer_As_C (0)'Access, 2); UTF_Conversions.From_16_To_8.Convert ( Wide_Buffer (1 .. Natural (Wide_Buffer_Length)), Out_Buffer, Out_Last); else Out_Last := 0; end if; end To_UTF_8; procedure To_DBCS ( Buffer : Buffer_Type; Last : Natural; Out_Buffer : aliased out DBCS_Buffer_Type; Out_Last : out Natural) is Wide_Buffer : Wide_String (1 .. 2); Wide_Buffer_Last : Natural; Wide_Buffer_As_C : C.winnt.WCHAR_array (0 .. 1); for Wide_Buffer_As_C'Address use Wide_Buffer'Address; Out_Length : C.signed_int; begin UTF_Conversions.From_8_To_16.Convert ( Buffer (1 .. Last), Wide_Buffer, Wide_Buffer_Last); Out_Length := C.winnls.WideCharToMultiByte ( C.winnls.CP_ACP, 0, Wide_Buffer_As_C (0)'Access, C.signed_int (Wide_Buffer_Last), LPSTR_Conv.To_Pointer (Out_Buffer (1)'Address), Out_Buffer'Length, null, null); if Out_Length = 0 then Out_Buffer (1) := '?'; Out_Last := 1; else Out_Last := Natural (Out_Length); end if; end To_DBCS; procedure Terminal_Get ( Handle : Handle_Type; Item : Address; Length : Ada.Streams.Stream_Element_Offset; Out_Length : out Ada.Streams.Stream_Element_Offset) is pragma Unreferenced (Length); Buffer : Buffer_Type; for Buffer'Address use Item; Wide_Buffer : C.winnt.WCHAR_array (0 .. 1); Read_Size : aliased C.windef.DWORD; begin if C.wincon.ReadConsole ( hConsoleInput => Handle, lpBuffer => C.windef.LPVOID (Wide_Buffer (0)'Address), nNumberOfCharsToRead => 1, lpNumberOfCharsRead => Read_Size'Access, lpReserved => C.windef.LPVOID (Null_Address)) = C.windef.FALSE then Out_Length := -1; -- error elsif Read_Size = 0 or else ( Wide_Buffer (0) = C.winnt.WCHAR'Val (16#1A#) -- Control+Z and then Processed_Input_Is_Enabled (Handle)) then Out_Length := 0; -- no data else Read_Buffer_Trailing_From_Terminal ( Handle, Buffer, Natural (Out_Length), Wide_Buffer (0)); end if; end Terminal_Get; procedure Terminal_Get_Immediate ( Handle : Handle_Type; Item : Address; Length : Ada.Streams.Stream_Element_Offset; Out_Length : out Ada.Streams.Stream_Element_Offset) is pragma Unreferenced (Length); Buffer : Buffer_Type; for Buffer'Address use Item; Event_Count : aliased C.windef.DWORD; Read_Size : aliased C.windef.DWORD; Event : aliased C.wincon.INPUT_RECORD; begin if C.wincon.GetNumberOfConsoleInputEvents (Handle, Event_Count'Access) = C.windef.FALSE then Out_Length := -1; -- error elsif Event_Count = 0 then Out_Length := 0; -- no data elsif C.wincon.ReadConsoleInput ( hConsoleInput => Handle, lpBuffer => Event'Access, nLength => 1, lpNumberOfEventsRead => Read_Size'Access) = C.windef.FALSE then Out_Length := -1; -- error elsif not ( Read_Size > 0 and then Event.EventType = C.wincon.KEY_EVENT and then Event.Event.KeyEvent.bKeyDown /= C.windef.FALSE) then Out_Length := 0; -- no data else Read_Buffer_Trailing_From_Terminal ( Handle, Buffer, Natural (Out_Length), Event.Event.KeyEvent.uChar.UnicodeChar); end if; end Terminal_Get_Immediate; procedure Terminal_Put ( Handle : Handle_Type; Item : Address; Length : Ada.Streams.Stream_Element_Offset; Out_Length : out Ada.Streams.Stream_Element_Offset) is Buffer : Buffer_Type; for Buffer'Address use Item; Wide_Buffer : Wide_String (1 .. 2); Wide_Buffer_Last : Natural; Written : aliased C.windef.DWORD; begin UTF_Conversions.From_8_To_16.Convert ( Buffer (1 .. Natural (Length)), Wide_Buffer, Wide_Buffer_Last); if C.wincon.WriteConsoleW ( hConsoleOutput => Handle, lpBuffer => C.windef.LPCVOID (Wide_Buffer (1)'Address), nNumberOfCharsToWrite => C.windef.DWORD (Wide_Buffer_Last), lpNumberOfCharsWritten => Written'Access, lpReserved => C.windef.LPVOID (Null_Address)) = C.windef.FALSE then Out_Length := -1; -- error else Out_Length := Ada.Streams.Stream_Element_Offset (Written); end if; end Terminal_Put; procedure Terminal_Size ( Handle : Handle_Type; Line_Length, Page_Length : out Natural) is Info : aliased C.wincon.CONSOLE_SCREEN_BUFFER_INFO; begin GetConsoleScreenBufferInfo (Handle, Info'Access); Line_Length := Natural (Info.dwSize.X); Page_Length := Natural (Info.dwSize.Y); end Terminal_Size; procedure Set_Terminal_Size ( Handle : Handle_Type; Line_Length, Page_Length : Natural) is begin SetConsoleScreenBufferSize_With_Adjusting ( Handle, C.wincon.COORD'( X => C.winnt.SHORT (Line_Length), Y => C.winnt.SHORT (Page_Length)), Handle); end Set_Terminal_Size; procedure Terminal_View ( Handle : Handle_Type; Left, Top : out Positive; Right, Bottom : out Natural) is Info : aliased C.wincon.CONSOLE_SCREEN_BUFFER_INFO; begin GetConsoleScreenBufferInfo (Handle, Info'Access); Left := Positive (Info.srWindow.Left + 1); Top := Positive (Info.srWindow.Top + 1); Right := Natural (Info.srWindow.Right + 1); Bottom := Natural (Info.srWindow.Bottom + 1); end Terminal_View; procedure Terminal_Position ( Handle : Handle_Type; Col, Line : out Positive) is Info : aliased C.wincon.CONSOLE_SCREEN_BUFFER_INFO; begin GetConsoleScreenBufferInfo (Handle, Info'Access); Col := Positive (Info.dwCursorPosition.X + 1); Line := Positive (Info.dwCursorPosition.Y + 1); end Terminal_Position; procedure Set_Terminal_Position ( Handle : Handle_Type; Col, Line : Positive) is begin if C.wincon.SetConsoleCursorPosition ( Handle, C.wincon.COORD'( X => C.winnt.SHORT (Col) - 1, Y => C.winnt.SHORT (Line) - 1)) = C.windef.FALSE then Raise_Exception (Layout_Error'Identity); end if; end Set_Terminal_Position; procedure Set_Terminal_Col ( Handle : Handle_Type; To : Positive) is Col, Line : Positive; begin Terminal_Position (Handle, Col, Line); Set_Terminal_Position (Handle, To, Line); end Set_Terminal_Col; procedure Terminal_Clear ( Handle : Handle_Type) is Info : aliased C.wincon.CONSOLE_SCREEN_BUFFER_INFO; begin GetConsoleScreenBufferInfo ( Handle, Info'Access); declare Clear_Char_Info : constant C.wincon.CHAR_INFO := ( Char => ( Unchecked_Tag => 0, UnicodeChar => C.winnt.WCHAR'Val (16#20#)), Attributes => Info.wAttributes); Buffer : aliased constant array (0 .. Info.dwSize.Y - 1, 0 .. Info.dwSize.X - 1) of aliased C.wincon.CHAR_INFO := (others => (others => Clear_Char_Info)); Region : aliased C.wincon.SMALL_RECT; begin Region.Left := 0; Region.Top := 0; Region.Right := Info.dwSize.X - 1; Region.Bottom := Info.dwSize.Y - 1; if C.wincon.WriteConsoleOutputW ( hConsoleOutput => Handle, lpBuffer => Buffer (0, 0)'Access, dwBufferSize => Info.dwSize, dwBufferCoord => (X => 0, Y => 0), lpWriteRegion => Region'Access) = C.windef.FALSE then Raise_Exception (Device_Error'Identity); end if; end; if C.wincon.SetConsoleCursorPosition (Handle, (X => 0, Y => 0)) = C.windef.FALSE then Raise_Exception (Device_Error'Identity); end if; end Terminal_Clear; procedure Set_Non_Canonical_Mode ( Handle : Handle_Type; Wait : Boolean; Saved_Settings : aliased out Setting) is pragma Unreferenced (Wait); begin -- get and unset line-input mode if C.wincon.GetConsoleMode (Handle, Saved_Settings'Access) = C.windef.FALSE or else C.wincon.SetConsoleMode ( Handle, Saved_Settings and not ( C.wincon.ENABLE_ECHO_INPUT or C.wincon.ENABLE_LINE_INPUT)) = C.windef.FALSE then Raise_Exception (Device_Error'Identity); end if; end Set_Non_Canonical_Mode; procedure Restore ( Handle : Handle_Type; Settings : aliased Setting) is begin if C.wincon.SetConsoleMode (Handle, Settings) = C.windef.FALSE then Raise_Exception (Device_Error'Identity); end if; end Restore; procedure Set_Terminal_Attributes ( Handle : Handle_Type; Attributes : C.windef.WORD) is begin if C.wincon.SetConsoleTextAttribute (Handle, Attributes) = C.windef.FALSE then Raise_Exception (Device_Error'Identity); end if; end Set_Terminal_Attributes; procedure Save_State (Handle : Handle_Type; To_State : out Output_State) is Info : aliased C.wincon.CONSOLE_SCREEN_BUFFER_INFO; begin if C.wincon.GetConsoleScreenBufferInfo (Handle, Info'Access) = C.windef.FALSE then Raise_Exception (Device_Error'Identity); end if; To_State.Position := Info.dwCursorPosition; To_State.Attributes := Info.wAttributes; end Save_State; procedure Reset_State (Handle : Handle_Type; From_State : Output_State) is begin Set_Terminal_Attributes (Handle, From_State.Attributes); Set_Terminal_Position (Handle, Col => Integer (From_State.Position.X + 1), Line => Integer (From_State.Position.Y + 1)); end Reset_State; end System.Native_Text_IO;
stcarrez/mat
Ada
789
ads
package MAT.Expressions.Parser_Tokens is subtype YYSType is MAT.Expressions.yystype; YYLVal, YYVal : YYSType; type Token is (END_OF_INPUT, ERROR, T_NAME, T_INT, T_STRING, T_SELECT, T_WITH, T_AT, T_BY, T_IN, T_NOT, T_OR, T_AND, T_SIZE, T_ADDR, T_FROM, T_BEGIN, T_END, T_TO, T_REALLOCATION, T_ALL, T_UNOT, T_WITHIN, T_USE, T_AFTER, T_BEFORE, T_DIRECT, T_IS, T_MALLOC, T_REALLOC, T_FREE, T_SMARK, T_SALLOC, T_SRELEASE, T_LEAK, T_NO_FREE, T_THREAD, T_RANGE, T_EVENT, T_TIME, T_LT, T_LE, T_GT, T_GE, T_NE, T_EQ, T_HAS, '[', ']', '(', ')', ',', '+', '-'); Syntax_Error : exception; end MAT.Expressions.Parser_Tokens;
reznikmm/matreshka
Ada
4,998
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012-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$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ with AMF.Generic_Collections; package AMF.OCL.Literal_Exps.Collections is pragma Preelaborate; package OCL_Literal_Exp_Collections is new AMF.Generic_Collections (OCL_Literal_Exp, OCL_Literal_Exp_Access); type Set_Of_OCL_Literal_Exp is new OCL_Literal_Exp_Collections.Set with null record; Empty_Set_Of_OCL_Literal_Exp : constant Set_Of_OCL_Literal_Exp; type Ordered_Set_Of_OCL_Literal_Exp is new OCL_Literal_Exp_Collections.Ordered_Set with null record; Empty_Ordered_Set_Of_OCL_Literal_Exp : constant Ordered_Set_Of_OCL_Literal_Exp; type Bag_Of_OCL_Literal_Exp is new OCL_Literal_Exp_Collections.Bag with null record; Empty_Bag_Of_OCL_Literal_Exp : constant Bag_Of_OCL_Literal_Exp; type Sequence_Of_OCL_Literal_Exp is new OCL_Literal_Exp_Collections.Sequence with null record; Empty_Sequence_Of_OCL_Literal_Exp : constant Sequence_Of_OCL_Literal_Exp; private Empty_Set_Of_OCL_Literal_Exp : constant Set_Of_OCL_Literal_Exp := (OCL_Literal_Exp_Collections.Set with null record); Empty_Ordered_Set_Of_OCL_Literal_Exp : constant Ordered_Set_Of_OCL_Literal_Exp := (OCL_Literal_Exp_Collections.Ordered_Set with null record); Empty_Bag_Of_OCL_Literal_Exp : constant Bag_Of_OCL_Literal_Exp := (OCL_Literal_Exp_Collections.Bag with null record); Empty_Sequence_Of_OCL_Literal_Exp : constant Sequence_Of_OCL_Literal_Exp := (OCL_Literal_Exp_Collections.Sequence with null record); end AMF.OCL.Literal_Exps.Collections;
tum-ei-rcs/StratoX
Ada
1,277
ads
-- Institution: Technische Universität München -- Department: Real-Time Computer Systems (RCS) -- Project: StratoX -- Authors: Martin Becker ([email protected]) with Ada.Real_Time; use Ada.Real_Time; with HIL; use HIL; -- @summary -- SPI protocol to CYPRESS FM25v0x series (ferroelectric RAM, non-volatile) generic MEMSIZE_BYTES : Positive; -- FIXME: introduce datatype to constrain to 65kByte, beause we have 16bit addresses. package FM25v0x with SPARK_Mode -- Abstract_State => State is --MEMSIZE_BYTES : constant := Memory_Size; type Address is new Integer range 0 .. MEMSIZE_BYTES - 1; procedure Init; -- initialize the communication to the FRAM procedure Self_Check (Status : out Boolean); -- run a self-check. -- @return true on success -- @req Subsystem/Init/Selfcheck procedure Read_Byte (addr : Address; byte : out HIL.Byte); -- read a single byte -- @req Subsystem/InvalidRequirement procedure Write_Byte (addr : Address; byte : HIL.Byte); -- with Pre => Is_Init; -- write a single byte private Is_Init : Boolean := False;-- with Part_Of => State; FM25v0x_STARTUP_TIME_MS : constant Time := Time_First + Milliseconds (1); -- datasheet: ~400 usec @3.3V end FM25v0x;
AdaCore/libadalang
Ada
101
adb
with Foo; procedure Test is X : Foo.Opt_Type; pragma Test_Statement; begin null; end Test;
optikos/oasis
Ada
9,207
adb
-- Copyright (c) 2019 Maxim Reznik <[email protected]> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- package body Program.Nodes.Procedure_Renaming_Declarations is function Create (Not_Token : Program.Lexical_Elements.Lexical_Element_Access; Overriding_Token : Program.Lexical_Elements.Lexical_Element_Access; Procedure_Token : not null Program.Lexical_Elements .Lexical_Element_Access; Name : not null Program.Elements.Defining_Names .Defining_Name_Access; Left_Bracket_Token : Program.Lexical_Elements.Lexical_Element_Access; Parameters : Program.Elements.Parameter_Specifications .Parameter_Specification_Vector_Access; Right_Bracket_Token : Program.Lexical_Elements.Lexical_Element_Access; Renames_Token : Program.Lexical_Elements.Lexical_Element_Access; Renamed_Procedure : Program.Elements.Expressions.Expression_Access; With_Token : Program.Lexical_Elements.Lexical_Element_Access; Aspects : Program.Elements.Aspect_Specifications .Aspect_Specification_Vector_Access; Semicolon_Token : not null Program.Lexical_Elements .Lexical_Element_Access) return Procedure_Renaming_Declaration is begin return Result : Procedure_Renaming_Declaration := (Not_Token => Not_Token, Overriding_Token => Overriding_Token, Procedure_Token => Procedure_Token, Name => Name, Left_Bracket_Token => Left_Bracket_Token, Parameters => Parameters, Right_Bracket_Token => Right_Bracket_Token, Renames_Token => Renames_Token, Renamed_Procedure => Renamed_Procedure, With_Token => With_Token, Aspects => Aspects, Semicolon_Token => Semicolon_Token, Enclosing_Element => null) do Initialize (Result); end return; end Create; function Create (Name : not null Program.Elements.Defining_Names .Defining_Name_Access; Parameters : Program.Elements.Parameter_Specifications .Parameter_Specification_Vector_Access; Renamed_Procedure : Program.Elements.Expressions.Expression_Access; Aspects : Program.Elements.Aspect_Specifications .Aspect_Specification_Vector_Access; Is_Part_Of_Implicit : Boolean := False; Is_Part_Of_Inherited : Boolean := False; Is_Part_Of_Instance : Boolean := False; Has_Not : Boolean := False; Has_Overriding : Boolean := False) return Implicit_Procedure_Renaming_Declaration is begin return Result : Implicit_Procedure_Renaming_Declaration := (Name => Name, Parameters => Parameters, Renamed_Procedure => Renamed_Procedure, Aspects => Aspects, Is_Part_Of_Implicit => Is_Part_Of_Implicit, Is_Part_Of_Inherited => Is_Part_Of_Inherited, Is_Part_Of_Instance => Is_Part_Of_Instance, Has_Not => Has_Not, Has_Overriding => Has_Overriding, Enclosing_Element => null) do Initialize (Result); end return; end Create; overriding function Name (Self : Base_Procedure_Renaming_Declaration) return not null Program.Elements.Defining_Names.Defining_Name_Access is begin return Self.Name; end Name; overriding function Parameters (Self : Base_Procedure_Renaming_Declaration) return Program.Elements.Parameter_Specifications .Parameter_Specification_Vector_Access is begin return Self.Parameters; end Parameters; overriding function Renamed_Procedure (Self : Base_Procedure_Renaming_Declaration) return Program.Elements.Expressions.Expression_Access is begin return Self.Renamed_Procedure; end Renamed_Procedure; overriding function Aspects (Self : Base_Procedure_Renaming_Declaration) return Program.Elements.Aspect_Specifications .Aspect_Specification_Vector_Access is begin return Self.Aspects; end Aspects; overriding function Not_Token (Self : Procedure_Renaming_Declaration) return Program.Lexical_Elements.Lexical_Element_Access is begin return Self.Not_Token; end Not_Token; overriding function Overriding_Token (Self : Procedure_Renaming_Declaration) return Program.Lexical_Elements.Lexical_Element_Access is begin return Self.Overriding_Token; end Overriding_Token; overriding function Procedure_Token (Self : Procedure_Renaming_Declaration) return not null Program.Lexical_Elements.Lexical_Element_Access is begin return Self.Procedure_Token; end Procedure_Token; overriding function Left_Bracket_Token (Self : Procedure_Renaming_Declaration) return Program.Lexical_Elements.Lexical_Element_Access is begin return Self.Left_Bracket_Token; end Left_Bracket_Token; overriding function Right_Bracket_Token (Self : Procedure_Renaming_Declaration) return Program.Lexical_Elements.Lexical_Element_Access is begin return Self.Right_Bracket_Token; end Right_Bracket_Token; overriding function Renames_Token (Self : Procedure_Renaming_Declaration) return Program.Lexical_Elements.Lexical_Element_Access is begin return Self.Renames_Token; end Renames_Token; overriding function With_Token (Self : Procedure_Renaming_Declaration) return Program.Lexical_Elements.Lexical_Element_Access is begin return Self.With_Token; end With_Token; overriding function Semicolon_Token (Self : Procedure_Renaming_Declaration) return not null Program.Lexical_Elements.Lexical_Element_Access is begin return Self.Semicolon_Token; end Semicolon_Token; overriding function Has_Not (Self : Procedure_Renaming_Declaration) return Boolean is begin return Self.Not_Token.Assigned; end Has_Not; overriding function Has_Overriding (Self : Procedure_Renaming_Declaration) return Boolean is begin return Self.Overriding_Token.Assigned; end Has_Overriding; overriding function Is_Part_Of_Implicit (Self : Implicit_Procedure_Renaming_Declaration) return Boolean is begin return Self.Is_Part_Of_Implicit; end Is_Part_Of_Implicit; overriding function Is_Part_Of_Inherited (Self : Implicit_Procedure_Renaming_Declaration) return Boolean is begin return Self.Is_Part_Of_Inherited; end Is_Part_Of_Inherited; overriding function Is_Part_Of_Instance (Self : Implicit_Procedure_Renaming_Declaration) return Boolean is begin return Self.Is_Part_Of_Instance; end Is_Part_Of_Instance; overriding function Has_Not (Self : Implicit_Procedure_Renaming_Declaration) return Boolean is begin return Self.Has_Not; end Has_Not; overriding function Has_Overriding (Self : Implicit_Procedure_Renaming_Declaration) return Boolean is begin return Self.Has_Overriding; end Has_Overriding; procedure Initialize (Self : aliased in out Base_Procedure_Renaming_Declaration'Class) is begin Set_Enclosing_Element (Self.Name, Self'Unchecked_Access); for Item in Self.Parameters.Each_Element loop Set_Enclosing_Element (Item.Element, Self'Unchecked_Access); end loop; if Self.Renamed_Procedure.Assigned then Set_Enclosing_Element (Self.Renamed_Procedure, Self'Unchecked_Access); end if; for Item in Self.Aspects.Each_Element loop Set_Enclosing_Element (Item.Element, Self'Unchecked_Access); end loop; null; end Initialize; overriding function Is_Procedure_Renaming_Declaration_Element (Self : Base_Procedure_Renaming_Declaration) return Boolean is pragma Unreferenced (Self); begin return True; end Is_Procedure_Renaming_Declaration_Element; overriding function Is_Declaration_Element (Self : Base_Procedure_Renaming_Declaration) return Boolean is pragma Unreferenced (Self); begin return True; end Is_Declaration_Element; overriding procedure Visit (Self : not null access Base_Procedure_Renaming_Declaration; Visitor : in out Program.Element_Visitors.Element_Visitor'Class) is begin Visitor.Procedure_Renaming_Declaration (Self); end Visit; overriding function To_Procedure_Renaming_Declaration_Text (Self : aliased in out Procedure_Renaming_Declaration) return Program.Elements.Procedure_Renaming_Declarations .Procedure_Renaming_Declaration_Text_Access is begin return Self'Unchecked_Access; end To_Procedure_Renaming_Declaration_Text; overriding function To_Procedure_Renaming_Declaration_Text (Self : aliased in out Implicit_Procedure_Renaming_Declaration) return Program.Elements.Procedure_Renaming_Declarations .Procedure_Renaming_Declaration_Text_Access is pragma Unreferenced (Self); begin return null; end To_Procedure_Renaming_Declaration_Text; end Program.Nodes.Procedure_Renaming_Declarations;
ytomino/xml-ada
Ada
4,473
adb
with Ada.IO_Exceptions; with System.Address_To_Access_Conversions; with C.libxml.tree; with C.libxml.xmlIO; package body XML.Streams is use type C.libxml.tree.xmlOutputBufferPtr; use type C.libxml.xmlreader.xmlTextReaderPtr; use type C.libxml.xmlwriter.xmlTextWriterPtr; procedure memcpy (dst, src : System.Address; n : C.size_t) with Import, Convention => Intrinsic, External_Name => "__builtin_memcpy"; -- reader function Read_Handler ( context : C.void_ptr; buffer : access C.char; len : C.signed_int) return C.signed_int with Convention => C; function Read_Handler ( context : C.void_ptr; buffer : access C.char; len : C.signed_int) return C.signed_int is package Conv is new System.Address_To_Access_Conversions (Ada.Streams.Root_Stream_Type'Class); Stream : constant Conv.Object_Pointer := Conv.To_Pointer (System.Address (context)); Item : Ada.Streams.Stream_Element_Array ( 1 .. Ada.Streams.Stream_Element_Offset (len)); for Item'Address use buffer.all'Address; Last : Ada.Streams.Stream_Element_Offset; begin begin Ada.Streams.Read (Stream.all, Item, Last); exception when Ada.IO_Exceptions.End_Error => Last := 0; end; return C.signed_int (Last); end Read_Handler; -- implementation of reader function Create ( Stream : not null access Ada.Streams.Root_Stream_Type'Class; Encoding : Encoding_Type := No_Encoding; URI : String := "") return Reader is package Conv is new System.Address_To_Access_Conversions (Ada.Streams.Root_Stream_Type'Class); begin Check_Version; declare P_Encoding : C.char_const_ptr := null; P_URI : access constant C.char := null; URI_Length : constant C.size_t := URI'Length; C_URI : aliased C.char_array (0 .. URI_Length); -- NUL begin if Encoding /= null then P_Encoding := C.char_const_ptr (Encoding.name); end if; if URI'Length > 0 then memcpy (C_URI'Address, URI'Address, URI_Length); C_URI (URI_Length) := C.char'Val (0); P_URI := C_URI (C_URI'First)'Access; end if; return Result : aliased Reader do declare NC_Result : Non_Controlled_Reader renames Controlled_Readers.Reference (Result).all; begin NC_Result.Raw := C.libxml.xmlreader.xmlReaderForIO ( Read_Handler'Access, null, C.void_ptr (Conv.To_Address (Conv.Object_Pointer (Stream))), P_URI, P_Encoding, 0); if NC_Result.Raw = null then raise Use_Error; end if; Install_Error_Handler (NC_Result); end; end return; end; end Create; -- writer function Write_Handler ( context : C.void_ptr; buffer : access constant C.char; len : C.signed_int) return C.signed_int with Convention => C; function Write_Handler ( context : C.void_ptr; buffer : access constant C.char; len : C.signed_int) return C.signed_int is package Conv is new System.Address_To_Access_Conversions (Ada.Streams.Root_Stream_Type'Class); Stream : constant Conv.Object_Pointer := Conv.To_Pointer (System.Address (context)); Item : Ada.Streams.Stream_Element_Array ( 1 .. Ada.Streams.Stream_Element_Offset (len)); for Item'Address use buffer.all'Address; begin Ada.Streams.Write (Stream.all, Item); return len; end Write_Handler; -- implementation of writer function Create ( Stream : not null access Ada.Streams.Root_Stream_Type'Class; Encoding : Encoding_Type := No_Encoding) return Writer is package Conv is new System.Address_To_Access_Conversions (Ada.Streams.Root_Stream_Type'Class); begin Check_Version; declare Buffer : constant C.libxml.tree.xmlOutputBufferPtr := C.libxml.xmlIO.xmlOutputBufferCreateIO ( Write_Handler'Access, null, C.void_ptr (Conv.To_Address (Conv.Object_Pointer (Stream))), Encoding); begin if Buffer = null then raise Use_Error; end if; return Result : Writer do declare procedure Process (NC_Result : in out Non_Controlled_Writer) is begin NC_Result.Raw := C.libxml.xmlwriter.xmlNewTextWriter (Buffer); if NC_Result.Raw = null then declare Dummy : C.signed_int; begin Dummy := C.libxml.xmlIO.xmlOutputBufferClose (Buffer); end; raise Use_Error; end if; end Process; procedure Do_Create is new Controlled_Writers.Update (Process); begin Do_Create (Result); end; end return; end; end Create; end XML.Streams;
reznikmm/matreshka
Ada
3,600
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.Elements.Generic_Hash; function AMF.DG.Rectangles.Hash is new AMF.Elements.Generic_Hash (DG_Rectangle, DG_Rectangle_Access);
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.Attributes; package ODF.DOM.Meta_Table_Count_Attributes is pragma Preelaborate; type ODF_Meta_Table_Count_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Meta_Table_Count_Attribute_Access is access all ODF_Meta_Table_Count_Attribute'Class with Storage_Size => 0; end ODF.DOM.Meta_Table_Count_Attributes;
jquorning/iNow
Ada
618
ads
pragma License (Restricted); -- -- Copyright (C) 2020 Jesper Quorning All Rights Reserved. -- -- The author disclaims copyright to this source code. In place of -- a legal notice, here is a blessing: -- -- May you do good and not evil. -- May you find forgiveness for yourself and forgive others. -- May you share freely, not taking more than you give. -- package SQL_Database is procedure Open; -- Open database. -- Raise Program_Error on fail. function Is_Valid (File_Name : in String) return Boolean; -- True when File_Name designates valid database. end SQL_Database;
reznikmm/matreshka
Ada
4,640
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_Style.Text_Position_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Style_Text_Position_Attribute_Node is begin return Self : Style_Text_Position_Attribute_Node do Matreshka.ODF_Style.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Style_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Style_Text_Position_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Text_Position_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Style_URI, Matreshka.ODF_String_Constants.Text_Position_Attribute, Style_Text_Position_Attribute_Node'Tag); end Matreshka.ODF_Style.Text_Position_Attributes;
OneWingedShark/Byron
Ada
1,800
adb
Pragma Ada_2012; Pragma Assertion_Policy( Check ); with Ada.Containers.Vectors; Procedure Lexington.Aux.P18(Data : in out Token_Vector_Pkg.Vector) is Use Lexington.Aux.Token_Pkg; -- Converts all tokens of Which_ID to tokens of Target_ID. Procedure Translate( Which_ID, Target_ID : Token_ID ) is Procedure Translate (Position : Token_Vector_Pkg.Cursor) is Package TVP renames Token_Vector_Pkg; This : Token renames TVP.Element( Position ); This_ID : Token_ID renames Token_Pkg.ID(This); This_Value : Wide_Wide_String renames Token_Pkg.Lexeme( This ); begin if This_ID = Which_ID then declare New_Item : Token renames Make_Token(Target_ID, This_Value); begin Data.Replace_Element( Position, New_Item ); end; end if; exception when Constraint_Error => Null; End Translate; Begin Data.Iterate( Translate'Access ); End Translate; Begin -- Translate Operators. Translate( ch_Astrisk, op_Mul ); Translate( ch_Slash, op_Div ); Translate( ch_Plus, op_Add ); Translate( ch_Dash, op_Sub ); Translate( ch_Ampersand, op_Concat ); Translate( ch_Less_Than, op_Less_Than ); Translate( ch_Greater_Than, op_Greater_Than ); Translate( ch_Equal, op_Equal ); -- Translate separators. Translate( ch_Open_Paren, ns_Open_Paren ); Translate( ch_Close_Paren, ns_Close_Paren ); Translate( ch_Comma, ns_Comma ); Translate( ch_Colon, ns_Colon ); Translate( ch_Semicolon, ns_Semicolon ); Translate( ch_Period, ns_Period ); End Lexington.Aux.P18;
jwhitham/x86determiniser
Ada
216
ads
generic type Data ( <> ) is private; with procedure Procedure_To_Be_Measured (D : in Data); package Measure_Time is function Time ( D : Data; Iterations : in Natural) return Natural ; end Measure_Time ;
io7m/coreland-getopt-ada
Ada
211
adb
with Getopt; procedure noarg2 is Option : Integer; begin Option := Getopt.Process (" "); if Option /= Getopt.Option_EOF then raise Program_Error with "expected EOF from Getopt"; end if; end noarg2;
shintakezou/adaplayground
Ada
2,731
ads
with Converters; -- @summary -- Units used in aviation, operations among them and conversion -- factors. -- -- @description -- Measure_Units provides all you can need to play with -- units used in aviation, except that this is a lie because -- this is a test, so you won't find anything really useful -- here. -- package Measure_Units is Meters_per_Nautical_Mile : constant := 1852.0; Meters_per_Foot : constant := 0.3048; Mps_per_Knot : constant := Meters_per_Nautical_Mile/3600.0; type Kn is new Float; -- Knot (NM/h) subtype Kt is Kn; -- kt is used in aviation in place of kn type NM is new Float; -- Nautical Mile (1832 m by definition; it was 1/60 of a degree of -- latitude) type Ft is new Float; -- Foot (0.3048 m) type Climb_Rate is new Float; -- Climb rate is misured in ft/min; negative values are for sink -- rate. type Meter is new Float; -- Standard meter type Mps is new Float; -- m/s function To_Mps (V : Kn) return Mps; -- Convert kn to m/s. function To_Meters (V : NM) return Meter; -- Convert NM to meters. function To_Meters (V : Ft) return Meter; -- Convert ft to meters. function "*" (Speed : Kn; T : Duration) return NM; -- Speed in kn * t gives a distance. -- @param Speed Speed expressed in knots. -- @param T Time in seconds. -- @return NM done in the given time. function "*" (CR : Climb_Rate; T : Duration) return Ft; -- Climb rate (ft/min) * t gives an altitude (distance). -- @param CR Climb rate. -- @param T Time in seconds. -- @return the feet climbed after that time. function "/" (D : Ft; T : Duration) return Climb_Rate; -- Distance in feet / time is a Climb rate -- @param D Diff of altitude in feet. -- @param T Time in seconds. -- @return the climb rate. function To_String is new Converters.To_String (Kn); function To_String is new Converters.To_String (Ft); function To_String is new Converters.To_String (NM); function To_String is new Converters.To_String (Mps); function To_String is new Converters.To_String (Meter); function To_String is new Converters.To_String (Climb_Rate); function "&" is new Converters.Concat (Kn, To_String); function "&" is new Converters.Concat (Ft, To_String); function "&" is new Converters.Concat (NM, To_String); function "&" is new Converters.Concat (Mps, To_String); function "&" is new Converters.Concat (Meter, To_String); function "&" is new Converters.Concat (Climb_Rate, To_String); end Measure_Units;
reznikmm/matreshka
Ada
4,632
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_Chart.Text_Overlap_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Chart_Text_Overlap_Attribute_Node is begin return Self : Chart_Text_Overlap_Attribute_Node do Matreshka.ODF_Chart.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Chart_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Chart_Text_Overlap_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Text_Overlap_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Chart_URI, Matreshka.ODF_String_Constants.Text_Overlap_Attribute, Chart_Text_Overlap_Attribute_Node'Tag); end Matreshka.ODF_Chart.Text_Overlap_Attributes;
reznikmm/matreshka
Ada
4,641
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.String_Value_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Office_String_Value_Attribute_Node is begin return Self : Office_String_Value_Attribute_Node do Matreshka.ODF_Office.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Office_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Office_String_Value_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.String_Value_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Office_URI, Matreshka.ODF_String_Constants.String_Value_Attribute, Office_String_Value_Attribute_Node'Tag); end Matreshka.ODF_Office.String_Value_Attributes;
reznikmm/matreshka
Ada
3,635
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- 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 League.Strings; with Matreshka.Internals.Locales; package Matreshka.CLDR.Collation_Loader is procedure Load_Collation_Data (Language : League.Strings.Universal_String; Locale : not null access Matreshka.Internals.Locales.Locale_Data); end Matreshka.CLDR.Collation_Loader;
pat-rogers/LmcpGen
Ada
5,311
adb
-<include_all_factories>- with Ada.Unchecked_Conversion; with Ada.Text_IO; use Ada.Text_IO; package body AVTAS.LMCP.Factory is ----------------- -- PackMessage -- ----------------- function PackMessage (RootObject : in Avtas.Lmcp.Object.Object_Any; EnableChecksum : in Boolean) return ByteBuffer is -- Allocate space for message, with 15 extra bytes for -- Existence (1 byte), series name (8 bytes), type (4 bytes), version number (2 bytes) MsgSize : constant UInt32 := RootObject.CalculatePackedSize + 15; Buffer : ByteBuffer (HEADER_SIZE + Index (MsgSize) + CHECKSUM_SIZE); begin -- add header values Buffer.Put_Int32 (LMCP_CONTROL_STR); Buffer.Put_UInt32 (MsgSize); -- add root object PutObject (RootObject, Buffer); -- add checksum if enabled Buffer.Put_UInt32 (if EnableChecksum then CalculatedChecksum (Buffer, Buffer.Capacity) else 0); return Buffer; end PackMessage; --------------- -- PutObject -- --------------- procedure PutObject (Object : in Avtas.Lmcp.Object.Object_Any; Buffer : in out ByteBuffer) is begin -- If object is null, pack a 0; otherwise, add root object if Object = null then Buffer.Put_Boolean (False); else Buffer.Put_Boolean (True); Buffer.Put_Int64 (Object.GetSeriesNameAsLong); Buffer.Put_UInt32 (Object.GetLmcpType); Buffer.Put_UInt16 (Object.GetSeriesVersion); Object.Pack (Buffer); end if; end PutObject; --------------- -- GetObject -- --------------- procedure GetObject (Buffer : in out ByteBuffer; Output : out Avtas.Lmcp.Object.Object_Any) is CtrlStr : Int32; MsgSize : UInt32; MsgExists : Boolean; SeriesId : Int64; MsgType : Uint32; Version : Uint16; begin Output := null; -- default if buffer.Capacity < HEADER_SIZE + CHECKSUM_SIZE then Put_Line ("AVTAS.LMCP.Factory.GetObject error: Buffer capacity too small for header and checksum (" & Integer'Image(HEADER_SIZE + CHECKSUM_SIZE) & ")."); raise Program_Error; -- for the moment -- return; end if; Buffer.Get_Int32 (CtrlStr); if CtrlStr /= LMCP_CONTROL_STR then Put_Line ("AVTAS.LMCP.Factory.GetObject error: Not a proper LMCP message."); Put_Line (" Expected: " & LMCP_CONTROL_STR'Image & " Received: " & CtrlStr'Image); raise Program_Error; -- for the moment -- return; end if; Buffer.Get_UInt32 (MsgSize); if Buffer.Capacity < Index (MsgSize) then Put_Line ("AVTAS.LMCP.Factory.GetObject error: Buffer size too small for packed object."); Put_Line (" MsgSize: " & MsgSize'Image & " Capacity: " & Buffer.Capacity'Image); raise Program_Error; -- for the moment -- return; end if; if not Validated (Buffer) then Put_Line ("AVTAS.LMCP.Factory.GetObject error: Checksum invalid."); raise Program_Error; -- for the moment -- return; end if; Buffer.Get_Boolean (MsgExists); if not MsgExists then Put_Line ("AVTAS.LMCP.Factory.GetObject error: Message indicated it was packed as null"); raise Program_Error; -- for the moment -- return; end if; Buffer.Get_Int64 (SeriesId); Buffer.Get_UInt32 (MsgType); Buffer.Get_UInt16 (Version); Output := CreateObject (SeriesId, MsgType, Version); if Output /= null then Output.Unpack (Buffer); else Put_Line ("AVTAS.LMCP.Factory.GetObject error: Buffer does not contain a recognized object type."); end if; end GetObject; ------------------ -- createObject -- ------------------ function createObject(seriesId : in Int64; msgType : in UInt32; version: in UInt16) return avtas.lmcp.object.Object_Any is begin -<global_factory_switch>- end createObject; ------------------------ -- CalculatedChecksum -- ------------------------ function CalculatedChecksum (Buffer : in ByteBuffer; Size : Index) return UInt32 is (Buffer.Checksum (Last => Size - 1)); ------------------- -- GetObjectSize -- ------------------- function GetObjectSize (Buffer : in ByteBuffer) return UInt32 is Result : UInt32; Second_HalfWord_Start : constant Index := 4; -- the buffer array is zero-based begin -- get the second UInt32 value in the buffer Buffer.Get_UInt32 (Result, First => Second_HalfWord_Start); return Result; end getObjectSize; --------------- -- Validated -- --------------- function Validated (Buffer : in ByteBuffer) return Boolean is Stored_Checksum : UInt32; begin if Buffer.High_Water_Mark < HEADER_SIZE + CHECKSUM_SIZE then Put_Line ("AVTAS.LMCP.Factory.Validated: Buffer size < HEADER_SIZE + CHECKSUM_SIZE."); return False; end if; Buffer.Get_UInt32 (Stored_Checksum, First => Buffer.High_Water_Mark - Checksum_Size); return Stored_Checksum = 0 or else Stored_Checksum = CalculatedChecksum (Buffer, Buffer.High_Water_Mark - Checksum_Size); end Validated; end AVTAS.LMCP.Factory;
MinimSecure/unum-sdk
Ada
982
ads
-- Copyright 2015-2019 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 Pack is type Table_Type is array (Natural range <>) of Integer; type Table_Ptr_Type is access all Table_Type; Table : Table_Type := (1 => 10, 2 => 20); Table_Ptr : aliased Table_Ptr_Type := new Table_Type'(3 => 30, 4 => 40); end Pack;
stcarrez/ada-asf
Ada
7,696
adb
----------------------------------------------------------------------- -- asf.beans -- Bean Registration and Factory -- Copyright (C) 2009, 2010, 2011, 2012, 2013, 2015, 2020, 2022 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.Log.Loggers; with Util.Beans.Objects.Maps; package body ASF.Beans is -- The logger Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("ASF.Beans"); -- ------------------------------ -- Register under the name identified by <b>Name</b> the class instance <b>Class</b>. -- ------------------------------ procedure Register_Class (Factory : in out Bean_Factory; Name : in String; Class : in Class_Binding_Access) is begin Log.Info ("Register bean class {0}", Name); Factory.Registry.Include (Name, Class_Binding_Ref.Create (Class)); end Register_Class; -- ------------------------------ -- Register under the name identified by <b>Name</b> a function to create a bean. -- This is a simplified class registration. -- ------------------------------ procedure Register_Class (Factory : in out Bean_Factory; Name : in String; Handler : in Create_Bean_Access) is Class : constant Default_Class_Binding_Access := new Default_Class_Binding; begin Class.Create := Handler; Register_Class (Factory, Name, Class.all'Access); end Register_Class; -- ------------------------------ -- Register the bean identified by <b>Name</b> and associated with the class <b>Class</b>. -- The class must have been registered by using the <b>Register</b> class operation. -- The scope defines the scope of the bean. -- ------------------------------ procedure Register (Factory : in out Bean_Factory; Name : in String; Class : in String; Params : in Parameter_Bean_Ref.Ref; Scope : in Scope_Type := REQUEST_SCOPE) is begin Log.Info ("Register bean '{0}' created by '{1}' in scope {2}", Name, Class, Scope_Type'Image (Scope)); declare Pos : constant Registry_Maps.Cursor := Factory.Registry.Find (Class); Binding : Bean_Binding; begin if not Registry_Maps.Has_Element (Pos) then Log.Error ("Class '{0}' does not exist. Cannot register bean '{1}'", Class, Name); return; end if; Binding.Create := Registry_Maps.Element (Pos); Binding.Scope := Scope; Binding.Params := Params; Factory.Map.Include (Ada.Strings.Unbounded.To_Unbounded_String (Name), Binding); end; end Register; -- ------------------------------ -- Register the bean identified by <b>Name</b> and associated with the class <b>Class</b>. -- The class must have been registered by using the <b>Register</b> class operation. -- The scope defines the scope of the bean. -- ------------------------------ procedure Register (Factory : in out Bean_Factory; Name : in String; Class : in Class_Binding_Access; Params : in Parameter_Bean_Ref.Ref; Scope : in Scope_Type := REQUEST_SCOPE) is Binding : Bean_Binding; begin Log.Info ("Register bean '{0}' in scope {1}", Name, Scope_Type'Image (Scope)); Binding.Create := Class_Binding_Ref.Create (Class); Binding.Scope := Scope; Binding.Params := Params; Factory.Map.Include (Ada.Strings.Unbounded.To_Unbounded_String (Name), Binding); end Register; -- ------------------------------ -- Register all the definitions from a factory to a main factory. -- ------------------------------ procedure Register (Factory : in out Bean_Factory; From : in Bean_Factory) is begin declare Pos : Registry_Maps.Cursor := From.Registry.First; begin while Registry_Maps.Has_Element (Pos) loop Factory.Registry.Include (Key => Registry_Maps.Key (Pos), New_Item => Registry_Maps.Element (Pos)); Registry_Maps.Next (Pos); end loop; end; declare Pos : Bean_Maps.Cursor := Bean_Maps.First (From.Map); begin while Bean_Maps.Has_Element (Pos) loop Factory.Map.Include (Key => Bean_Maps.Key (Pos), New_Item => Bean_Maps.Element (Pos)); Bean_Maps.Next (Pos); end loop; end; end Register; -- ------------------------------ -- Create a bean by using the create operation registered for the name -- ------------------------------ procedure Create (Factory : in Bean_Factory; Name : in Unbounded_String; Context : in EL.Contexts.ELContext'Class; Result : out Util.Beans.Basic.Readonly_Bean_Access; Scope : out Scope_Type) is use type Util.Beans.Basic.Readonly_Bean_Access; Pos : constant Bean_Maps.Cursor := Factory.Map.Find (Name); begin if Bean_Maps.Has_Element (Pos) then declare Binding : constant Bean_Binding := Bean_Maps.Element (Pos); begin Binding.Create.Value.Create (Name, Result); if Result /= null and then not Binding.Params.Is_Null then if Result.all in Util.Beans.Basic.Bean'Class then EL.Beans.Initialize (Util.Beans.Basic.Bean'Class (Result.all), Binding.Params.Value.Params, Context); else Log.Warn ("Bean {0} cannot be set with pre-defined properties as it does " & "not implement the Bean interface", To_String (Name)); end if; end if; Scope := Binding.Scope; end; else Result := null; Scope := ANY_SCOPE; end if; end Create; -- ------------------------------ -- Create a bean by using the registered create function. -- ------------------------------ overriding procedure Create (Factory : in Default_Class_Binding; Name : in Ada.Strings.Unbounded.Unbounded_String; Result : out Util.Beans.Basic.Readonly_Bean_Access) is pragma Unreferenced (Name); begin Result := Factory.Create.all; end Create; -- ------------------------------ -- Create a map bean object that allows to associate name/value pairs in a bean. -- ------------------------------ function Create_Map_Bean return Util.Beans.Basic.Readonly_Bean_Access is begin return new Util.Beans.Objects.Maps.Map_Bean; end Create_Map_Bean; end ASF.Beans;
optikos/oasis
Ada
8,389
ads
-- Copyright (c) 2019 Maxim Reznik <[email protected]> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Program.Lexical_Elements; with Program.Elements.Defining_Identifiers; with Program.Elements.Discrete_Ranges; with Program.Elements.Parameter_Specifications; with Program.Elements.Aspect_Specifications; with Program.Elements.Entry_Declarations; with Program.Element_Visitors; package Program.Nodes.Entry_Declarations is pragma Preelaborate; type Entry_Declaration is new Program.Nodes.Node and Program.Elements.Entry_Declarations.Entry_Declaration and Program.Elements.Entry_Declarations.Entry_Declaration_Text with private; function Create (Not_Token : Program.Lexical_Elements.Lexical_Element_Access; Overriding_Token : Program.Lexical_Elements.Lexical_Element_Access; Entry_Token : not null Program.Lexical_Elements .Lexical_Element_Access; Name : not null Program.Elements.Defining_Identifiers .Defining_Identifier_Access; Left_Bracket_Token : Program.Lexical_Elements.Lexical_Element_Access; Entry_Family_Definition : Program.Elements.Discrete_Ranges .Discrete_Range_Access; Right_Bracket_Token : Program.Lexical_Elements.Lexical_Element_Access; Left_Bracket_Token_2 : Program.Lexical_Elements.Lexical_Element_Access; Parameters : Program.Elements.Parameter_Specifications .Parameter_Specification_Vector_Access; Right_Bracket_Token_2 : Program.Lexical_Elements.Lexical_Element_Access; With_Token : Program.Lexical_Elements.Lexical_Element_Access; Aspects : Program.Elements.Aspect_Specifications .Aspect_Specification_Vector_Access; Semicolon_Token : not null Program.Lexical_Elements .Lexical_Element_Access) return Entry_Declaration; type Implicit_Entry_Declaration is new Program.Nodes.Node and Program.Elements.Entry_Declarations.Entry_Declaration with private; function Create (Name : not null Program.Elements.Defining_Identifiers .Defining_Identifier_Access; Entry_Family_Definition : Program.Elements.Discrete_Ranges .Discrete_Range_Access; Parameters : Program.Elements.Parameter_Specifications .Parameter_Specification_Vector_Access; Aspects : Program.Elements.Aspect_Specifications .Aspect_Specification_Vector_Access; Is_Part_Of_Implicit : Boolean := False; Is_Part_Of_Inherited : Boolean := False; Is_Part_Of_Instance : Boolean := False; Has_Not : Boolean := False; Has_Overriding : Boolean := False) return Implicit_Entry_Declaration with Pre => Is_Part_Of_Implicit or Is_Part_Of_Inherited or Is_Part_Of_Instance; private type Base_Entry_Declaration is abstract new Program.Nodes.Node and Program.Elements.Entry_Declarations.Entry_Declaration with record Name : not null Program.Elements .Defining_Identifiers.Defining_Identifier_Access; Entry_Family_Definition : Program.Elements.Discrete_Ranges .Discrete_Range_Access; Parameters : Program.Elements.Parameter_Specifications .Parameter_Specification_Vector_Access; Aspects : Program.Elements.Aspect_Specifications .Aspect_Specification_Vector_Access; end record; procedure Initialize (Self : aliased in out Base_Entry_Declaration'Class); overriding procedure Visit (Self : not null access Base_Entry_Declaration; Visitor : in out Program.Element_Visitors.Element_Visitor'Class); overriding function Name (Self : Base_Entry_Declaration) return not null Program.Elements.Defining_Identifiers .Defining_Identifier_Access; overriding function Entry_Family_Definition (Self : Base_Entry_Declaration) return Program.Elements.Discrete_Ranges.Discrete_Range_Access; overriding function Parameters (Self : Base_Entry_Declaration) return Program.Elements.Parameter_Specifications .Parameter_Specification_Vector_Access; overriding function Aspects (Self : Base_Entry_Declaration) return Program.Elements.Aspect_Specifications .Aspect_Specification_Vector_Access; overriding function Is_Entry_Declaration_Element (Self : Base_Entry_Declaration) return Boolean; overriding function Is_Declaration_Element (Self : Base_Entry_Declaration) return Boolean; type Entry_Declaration is new Base_Entry_Declaration and Program.Elements.Entry_Declarations.Entry_Declaration_Text with record Not_Token : Program.Lexical_Elements .Lexical_Element_Access; Overriding_Token : Program.Lexical_Elements .Lexical_Element_Access; Entry_Token : not null Program.Lexical_Elements .Lexical_Element_Access; Left_Bracket_Token : Program.Lexical_Elements .Lexical_Element_Access; Right_Bracket_Token : Program.Lexical_Elements .Lexical_Element_Access; Left_Bracket_Token_2 : Program.Lexical_Elements .Lexical_Element_Access; Right_Bracket_Token_2 : Program.Lexical_Elements .Lexical_Element_Access; With_Token : Program.Lexical_Elements .Lexical_Element_Access; Semicolon_Token : not null Program.Lexical_Elements .Lexical_Element_Access; end record; overriding function To_Entry_Declaration_Text (Self : aliased in out Entry_Declaration) return Program.Elements.Entry_Declarations.Entry_Declaration_Text_Access; overriding function Not_Token (Self : Entry_Declaration) return Program.Lexical_Elements.Lexical_Element_Access; overriding function Overriding_Token (Self : Entry_Declaration) return Program.Lexical_Elements.Lexical_Element_Access; overriding function Entry_Token (Self : Entry_Declaration) return not null Program.Lexical_Elements.Lexical_Element_Access; overriding function Left_Bracket_Token (Self : Entry_Declaration) return Program.Lexical_Elements.Lexical_Element_Access; overriding function Right_Bracket_Token (Self : Entry_Declaration) return Program.Lexical_Elements.Lexical_Element_Access; overriding function Left_Bracket_Token_2 (Self : Entry_Declaration) return Program.Lexical_Elements.Lexical_Element_Access; overriding function Right_Bracket_Token_2 (Self : Entry_Declaration) return Program.Lexical_Elements.Lexical_Element_Access; overriding function With_Token (Self : Entry_Declaration) return Program.Lexical_Elements.Lexical_Element_Access; overriding function Semicolon_Token (Self : Entry_Declaration) return not null Program.Lexical_Elements.Lexical_Element_Access; overriding function Has_Not (Self : Entry_Declaration) return Boolean; overriding function Has_Overriding (Self : Entry_Declaration) return Boolean; type Implicit_Entry_Declaration is new Base_Entry_Declaration with record Is_Part_Of_Implicit : Boolean; Is_Part_Of_Inherited : Boolean; Is_Part_Of_Instance : Boolean; Has_Not : Boolean; Has_Overriding : Boolean; end record; overriding function To_Entry_Declaration_Text (Self : aliased in out Implicit_Entry_Declaration) return Program.Elements.Entry_Declarations.Entry_Declaration_Text_Access; overriding function Is_Part_Of_Implicit (Self : Implicit_Entry_Declaration) return Boolean; overriding function Is_Part_Of_Inherited (Self : Implicit_Entry_Declaration) return Boolean; overriding function Is_Part_Of_Instance (Self : Implicit_Entry_Declaration) return Boolean; overriding function Has_Not (Self : Implicit_Entry_Declaration) return Boolean; overriding function Has_Overriding (Self : Implicit_Entry_Declaration) return Boolean; end Program.Nodes.Entry_Declarations;
reznikmm/matreshka
Ada
4,255
adb
------------------------------------------------------------------------------ -- -- -- 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$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Nodes.Elements; package body XML.DOM.Nodes.Elements.Internals is ------------ -- Create -- ------------ function Create (Node : Matreshka.DOM_Nodes.Element_Access) return XML.DOM.Nodes.Elements.DOM_Element is use type Matreshka.DOM_Nodes.Element_Access; begin if Node /= null then Matreshka.DOM_Nodes.Reference (Matreshka.DOM_Nodes.Node_Access (Node)); end if; return (Ada.Finalization.Controlled with Node => Matreshka.DOM_Nodes.Node_Access (Node)); end Create; ---------- -- Wrap -- ---------- function Wrap (Node : Matreshka.DOM_Nodes.Element_Access) return XML.DOM.Nodes.Elements.DOM_Element is begin return (Ada.Finalization.Controlled with Node => Matreshka.DOM_Nodes.Node_Access (Node)); end Wrap; end XML.DOM.Nodes.Elements.Internals;
MinimSecure/unum-sdk
Ada
834
ads
-- Copyright 2017-2019 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/>. with System; package Pck is type Str is new String (1 .. 4); procedure Do_Nothing (A : System.Address); end pck;
PaPablo/cadenas-ada
Ada
849
adb
with Ada.Text_IO, Ada.Text_IO.Unbounded_IO, Ada.Strings.Unbounded; use Ada.Text_IO,Ada.Text_IO.Unbounded_IO,Ada.Strings.Unbounded; procedure cadenas is saludo : String := "Hola mundo!"; saludo_unbounded : Unbounded_String; begin -- Cadenas en Ada -- String: arreglos de caracteres de tamaño fijo -- Bounded_String: cadenas de largo variable, -- pero con una tamaño máximo (no las vamos a usar) -- Unbounded_String: cadenas de largo varible, sin límite. Put_Line(saludo); saludo := "hola Mundo"; saludo_unbounded := To_Unbounded_String("Hola Mundo!"); saludo:= To_String(saludo_unbounded); Put_Line(saludo_unbounded); Put_Line(saludo); -- String -> Unbounded_String => To_Unbounded_String -- Unbounded_String -> String => To_String end cadenas;
gonma95/RealTimeSystem_CarDistrations
Ada
17,342
ads
with Ada.Real_Time; use Ada.Real_Time; with ada.strings.unbounded; use ada.strings.unbounded; with ada.strings.unbounded.text_io; use ada.strings.unbounded.text_io; package devices1 is --------------------------------------------------------------------- ------ Access time for devices --------------------------------------------------------------------- WCET_Distance: constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds(12); WCET_Speed: constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds(7); WCET_HeadPosition: constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds(4); WCET_Steering: constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds(7); WCET_Eyes_Image: constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds(20); WCET_EEG: constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds(18); WCET_Display: constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds(15); WCET_Alarm: constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds(5); WCET_Light: constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds(5); WCET_Automatic_Driving: constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds(5); WCET_Brake: constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds(5); --------------------------------------------------------------------- ------ INPUT devices interface --------------------------------------------------------------------- --------------------------------------------------------------------- ------ ELECTRODES --------------------------------------------------- type Value_Electrode is new natural range 0..10; Number_Electrodes: constant integer := 10; type EEG_Samples_Index is new natural range 1..Number_Electrodes; type EEG_Samples_Type is array (EEG_Samples_Index) of Value_Electrode; procedure Reading_Sensors (L: out EEG_Samples_Type); -- It reads a sample of Electrode Sensors and returns a array of 10 values --------------------------------------------------------------------- ------ EYES --------------------------------------------------------- type Eyes_Samples_Index is (left,right); type Eyes_Samples_Values is new natural range 0..100; type Eyes_Samples_Type is array (Eyes_Samples_Index) of Eyes_Samples_Values; procedure Reading_EyesImage (L: out Eyes_Samples_Type); -- It reads an image of the eyes, analyses the image and returns --- the percentage of aperture (0..100) of every eye (left, right) --------------------------------------------------------------------- ------ HeadPosition ------------------------------------------------- type HeadPosition_Samples_Index is (x,y); type HeadPosition_Samples_Values is new integer range -90..+90; type HeadPosition_Samples_Type is array (HeadPosition_Samples_Index) of HeadPosition_Samples_Values; procedure Reading_HeadPosition (H: out HeadPosition_Samples_Type); -- It reads the head position in axis x,y and returns -- the angle -90..+90 degrees --------------------------------------------------------------------- ------ DISTANCE ----------------------------------------------------- type Distance_Samples_Type is new natural range 0..150; procedure Reading_Distance (L: out Distance_Samples_Type); -- It reads the distance with the previous vehicle: from 0m. to 150m. --------------------------------------------------------------------- ------ SPEED -------------------------------------------------------- type Speed_Samples_Type is new natural range 0..200; procedure Reading_Speed (V: out Speed_Samples_Type); -- It reads the current vehicle speed: from 0m. to 200m. --------------------------------------------------------------------- ------ STEERING WHEEL ----------------------------------------------- type Steering_Samples_Type is new integer range -180..180; procedure Reading_Steering (S: out Steering_Samples_Type); -- It reads the current position of the steering wheel: from -180 to 180 --------------------------------------------------------------------- ------ OUTPUT devices interface --------------------------------------------------------------------- type Values_Pulse_Rate is new float range 20.0..300.0; procedure Display_Pulse_Rate (P: Values_Pulse_Rate); -- It displays the pulse rate P --------------------------------------------------------------------- procedure Display_Electrodes_Sample (R: EEG_Samples_Type); -- It displays the 10 values of the electrodes sample -------------------------------------------------------------------- procedure Display_Eyes_Sample (R: Eyes_Samples_Type); -- It displays the values of eyes aperture (left and right) --------------------------------------------------------------------- procedure Display_Distance (D: Distance_Samples_Type); -- It displays the distance D --------------------------------------------------------------------- procedure Display_Speed (V: Speed_Samples_Type); -- It displays the speed V --------------------------------------------------------------------- procedure Display_Steering (S: Steering_Samples_Type); -- It displays the steering wheel position S -------------------------------------------------------------------- procedure Display_HeadPosition_Sample (H: HeadPosition_Samples_Type); -- It displays the angle of the head position in both axis (x and y) --------------------------------------------------------------------- procedure Display_Cronometro (Origen: Ada.Real_Time.Time; Hora: Ada.Real_Time.Time); -- It displays a chronometer --------------------------------------------------------------------- Type Volume is new integer range 1..5; procedure Beep (v: Volume); -- It beeps with a volume "v" --------------------------------------------------------------------- type Light_States is (On, Off); procedure Light (E: Light_States); -- It turns ON/OFF the light --------------------------------------------------------------------- procedure Activate_Automatic_Driving; -- It activates the automatic driving system --------------------------------------------------------------------- procedure Activate_Brake; -- It activates the brake --------------------------------------------------------------------- ------ SCENARIO --------------------------------------------------------------------- --------------------------------------------------------------------- ------ SPEED -------------------------------------------------------- cantidad_datos_Velocidad: constant := 100; type Indice_Secuencia_Velocidad is mod cantidad_datos_Velocidad; type tipo_Secuencia_Velocidad is array (Indice_Secuencia_Velocidad) of Speed_Samples_Type; Speed_Simulation: tipo_Secuencia_Velocidad := ( -- peligro colision 80,80,80,80,80, -- 1 muestra cada 100ms. 80,80,80,80,80, -- 1s. 80,80,80,80,80, 80,80,80,80,80, -- 2s. 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80, 80,80,80,80,80 ); -- 10s. --------------------------------------------------------------------- ------ DISTANCE ----------------------------------------------------- cantidad_datos_Distancia: constant := 100; type Indice_Secuencia_Distancia is mod cantidad_datos_Distancia; type tipo_Secuencia_Distancia is array (Indice_Secuencia_Distancia) of Distance_Samples_Type; Distance_Simulation: tipo_Secuencia_Distancia := ( -- peligro colision 5,5,5,5,5, -- 1 muestra cada 100ms. 5,5,5,5,5, -- 1s. 5,5,5,5,5, 5,5,5,5,5, -- 2s. 5,5,5,5,5, 5,5,5,5,5, -- 3s. 5,5,5,5,5, 5,5,5,5,5, -- 4s. 5,5,5,5,5, 5,5,5,5,5, -- 5s. 5,5,5,5,5, 5,5,5,5,5, -- 6s. 5,5,5,5,5, 5,5,5,5,5, -- 7s. 5,5,5,5,5, 5,5,5,5,5, -- 8s. 5,5,5,5,5, 5,5,5,5,5, -- 9s. 5,5,5,5,5, 5,5,5,5,5 ); -- 10s. --------------------------------------------------------------------- ------ HEAD POSITION ------------------------------------------------ cantidad_datos_HeadPosition: constant := 100; type Indice_Secuencia_HeadPosition is mod cantidad_datos_HeadPosition; type tipo_Secuencia_HeadPosition is array (Indice_Secuencia_HeadPosition) of HeadPosition_Samples_Type; HeadPosition_Simulation: tipo_Secuencia_HeadPosition := ( -- cabeza inclinada (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), --2s. (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35), (+01,+35),(+01,+35),(+01,+35),(+01,+35),(+01,+35) ); --10s. --------------------------------------------------------------------- ------ STEERING WHEEL ----------------------------------------------- cantidad_datos_Volante: constant := 100; type Indice_Secuencia_Volante is mod cantidad_datos_Volante; type tipo_Secuencia_Volante is array (Indice_Secuencia_Volante) of Steering_Samples_Type; Steering_Simulation: tipo_Secuencia_Volante := ( -- no gira el volante 0, 0, 0, 0, 0, -- 1 muestra cada 100ms. 0, 0, 0, 0, 0, -- 1s. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); -- 10s. --------------------------------------------------------------------- ------ EYESIMAGE ---------------------------------------------------- cantidad_datos_EyesImage: constant := 100; type Indice_Secuencia_EyesImage is mod cantidad_datos_EyesImage; type tipo_Secuencia_EyesImage is array (Indice_Secuencia_EyesImage) of Eyes_Samples_Type; Eyes_Simulation: tipo_Secuencia_EyesImage := ((85,85),(70,70),(85,85),(85,85),(05,05), -- 1 muestra cada 100ms. (05,05),(85,85),(20,20),(85,85),(85,85), --1s. (70,70),(60,60),(60,60),(40,40),(40,40), (40,40),(40,40),(40,40),(40,40),(30,30), --2s. (30,30),(30,30),(40,40),(40,40),(40,40), (50,50),(50,50),(50,50),(50,50),(50,50), --3s. (60,60),(60,60),(50,50),(40,40),(40,40), (50,50),(50,50),(50,50),(50,50),(50,50), --4s. (30,30),(30,30),(40,40),(40,40),(40,40), (50,50),(50,50),(50,50),(50,50),(50,50), --5s. (20,20),(20,20),(20,20),(25,25),(25,25), (20,20),(20,20),(20,20),(15,15),(15,15), --6s. (10,10),(10,10),(10,10),(10,10),(10,40), ( 0, 0),( 0, 0),( 5, 5),( 5, 5),( 5, 5), --7s. ( 0, 0),( 0, 0),( 0, 0),( 0, 0),( 0, 0), ( 0, 0),( 0, 0),( 0, 0),( 0, 0),( 0, 0), --8s. ( 0, 0),( 0, 0),( 0, 0),( 0, 0),( 0, 0), ( 0, 0),( 0, 0),( 0, 0),( 0, 0),( 0, 0), --9s. ( 0, 0),( 0, 0),( 0, 0),( 0, 0),( 0, 0), ( 0, 0),( 0, 0),( 0, 0),( 0, 0),( 0, 0) ); --10s. --------------------------------------------------------------------- ------ EEG ---------------------------------------------------------- cantidad_datos_Sensores: constant := 100; type Indice_Secuencia_Sensores is mod cantidad_datos_Sensores; type tipo_Secuencia_Sensores is array (Indice_Secuencia_Sensores) of EEG_Samples_Type; EEG_Simulation: tipo_Secuencia_Sensores := ((7,7,7,7,7,7,7,7,7,7),(7,7,7,7,7,7,7,7,7,7), -- 1 muestra cada 100ms. (7,7,7,7,7,7,7,7,7,7),(7,7,7,7,7,7,7,7,7,7), (7,7,7,7,7,7,7,7,7,7),(8,8,8,8,8,8,8,8,8,8), (8,8,8,8,8,8,8,8,8,8),(8,8,8,8,8,8,8,8,8,8), (8,8,8,8,8,8,8,8,8,8),(8,8,8,8,8,8,8,8,8,8), --1s. (4,4,4,4,4,4,4,4,4,4),(4,4,4,4,4,4,4,4,4,4), (4,4,4,4,4,4,4,4,4,4),(5,5,5,5,5,5,5,5,5,5), (5,5,5,5,5,5,5,5,5,5),(6,6,6,6,6,6,6,6,6,6), (6,6,6,6,6,6,6,6,6,6),(6,6,6,6,6,6,6,6,6,6), (6,6,6,6,6,6,6,6,6,6),(6,6,6,6,6,6,6,6,6,6), --2s. (1,1,1,1,1,1,1,1,1,1),(1,1,1,1,1,1,1,1,1,1), (1,1,1,1,1,1,1,1,1,1),(2,2,2,2,2,2,2,2,2,2), (2,2,2,2,2,2,2,2,2,2),(2,2,2,2,2,2,2,2,2,2), (2,2,2,2,2,2,2,2,2,2),(3,3,3,3,3,3,3,3,3,3), (3,3,3,3,3,3,3,3,3,3),(3,3,3,3,3,3,3,3,3,3), --3s. (1,1,1,1,1,1,1,1,1,1),(1,1,1,1,1,1,1,1,1,1), (1,1,1,1,1,1,1,1,1,1),(2,2,2,2,2,2,2,2,2,2), (2,2,2,2,2,2,2,2,2,2),(2,2,2,2,2,2,2,2,2,2), (2,2,2,2,2,2,2,2,2,2),(3,3,3,3,3,3,3,3,3,3), (3,3,3,3,3,3,3,3,3,3),(3,3,3,3,3,3,3,3,3,3), --4s. (4,4,4,4,4,4,4,4,4,4),(4,4,4,4,4,4,4,4,4,4), (4,4,4,4,4,4,4,4,4,4),(5,5,5,5,5,5,5,5,5,5), (5,5,5,5,5,5,5,5,5,5),(7,7,7,7,7,7,7,7,7,7), (7,7,7,7,7,7,7,7,7,7),(7,7,7,7,7,7,7,7,7,7), (7,7,7,7,7,7,7,7,7,7),(7,7,7,7,7,7,7,7,7,7), --5s. (7,7,7,7,7,7,7,7,7,7),(7,7,7,7,7,7,7,7,7,7), (7,7,7,7,7,7,7,7,7,7),(7,7,7,7,7,7,7,7,7,7), (7,7,7,7,7,7,7,7,7,7),(8,8,8,8,8,8,8,8,8,8), (8,8,8,8,8,8,8,8,8,8),(8,8,8,8,8,8,8,8,8,8), (8,8,8,8,8,8,8,8,8,8),(8,8,8,8,8,8,8,8,8,8), --6s. (4,4,4,4,4,4,4,4,4,4),(4,4,4,4,4,4,4,4,4,4), (4,4,4,4,4,4,4,4,4,4),(5,5,5,5,5,5,5,5,5,5), (5,5,5,5,5,5,5,5,5,5),(6,6,6,6,6,6,6,6,6,6), (6,6,6,6,6,6,6,6,6,6),(6,6,6,6,6,6,6,6,6,6), (6,6,6,6,6,6,6,6,6,6),(6,6,6,6,6,6,6,6,6,6), --7s. (1,1,1,1,1,1,1,1,1,1),(1,1,1,1,1,1,1,1,1,1), (1,1,1,1,1,1,1,1,1,1),(2,2,2,2,2,2,2,2,2,2), (2,2,2,2,2,2,2,2,2,2),(2,2,2,2,2,2,2,2,2,2), (2,2,2,2,2,2,2,2,2,2),(3,3,3,3,3,3,3,3,3,3), (3,3,3,3,3,3,3,3,3,3),(3,3,3,3,3,3,3,3,3,3), --8s. (1,1,1,1,1,1,1,1,1,1),(1,1,1,1,1,1,1,1,1,1), (1,1,1,1,1,1,1,1,1,1),(2,2,2,2,2,2,2,2,2,2), (2,2,2,2,2,2,2,2,2,2),(2,2,2,2,2,2,2,2,2,2), (2,2,2,2,2,2,2,2,2,2),(3,3,3,3,3,3,3,3,3,3), (3,3,3,3,3,3,3,3,3,3),(3,3,3,3,3,3,3,3,3,3), --9s. (4,4,4,4,4,4,4,4,4,4),(4,4,4,4,4,4,4,4,4,4), (4,4,4,4,4,4,4,4,4,4),(5,5,5,5,5,5,5,5,5,5), (5,5,5,5,5,5,5,5,5,5),(7,7,7,7,7,7,7,7,7,7), (7,7,7,7,7,7,7,7,7,7),(7,7,7,7,7,7,7,7,7,7), (7,7,7,7,7,7,7,7,7,7),(7,7,7,7,7,7,7,7,7,7) ); --10s. end devices1;
pchapin/acrypto
Ada
759
ads
--------------------------------------------------------------------------- -- FILE : aco-crypto-exceptions.ads -- SUBJECT : Specification of a package holding crypto exceptions. -- AUTHOR : (C) Copyright 2010 by Peter Chapin -- -- Please send comments or bug reports to -- -- Peter Chapin <[email protected]> --------------------------------------------------------------------------- package ACO.Crypto.Exceptions is -- Raised by the cipher types if the wrong mode is used. Bad_Cipher_Mode : exception; -- Raised by the cipher types if a bad key size is used. Bad_Key_Length : exception; -- Raised by the block cipher types if the wrong block size is used. Bad_Block_Size : exception; end ACO.Crypto.Exceptions;
reznikmm/matreshka
Ada
4,059
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.Style_Language_Complex_Attributes; package Matreshka.ODF_Style.Language_Complex_Attributes is type Style_Language_Complex_Attribute_Node is new Matreshka.ODF_Style.Abstract_Style_Attribute_Node and ODF.DOM.Style_Language_Complex_Attributes.ODF_Style_Language_Complex_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Style_Language_Complex_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Style_Language_Complex_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Style.Language_Complex_Attributes;
danieagle/ASAP-Modular_Hashing
Ada
19,693
adb
------------------------------------------------------------------------------ -- -- -- Modular Hash Infrastructure -- -- -- -- SHA2 (512) -- -- -- -- - "Reference" Implementation - -- -- -- -- ------------------------------------------------------------------------ -- -- -- -- Copyright (C) 2019, ANNEXI-STRAYLINE Trans-Human Ltd. -- -- All rights reserved. -- -- -- -- Original Contributors: -- -- * Ensi Martini (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 Hex.Modular_Codec; package body Modular_Hashing.SHA512 is package body U_128 is function "+" (Left, Right : Unsigned_128) return Unsigned_128 is Output : Unsigned_128; begin Output.Low := Left.Low + Right.Low; Output.High := Left.High + Right.High; --if 2**64 - Left.Low < Right.Low then -- Output.High := Output.High + 1; --end if; return Output; end "+"; end U_128; ------------------ -- Digest_Chunk -- ------------------ -- This procedure is the internal digest that allows for a 1024-bit block to -- be processed without finishing the hash (padding) -- -- This is the bulk of the SHA512 algorithm, missing only the addition of -- message size with padding, which is handed by the Digest subprogram procedure Digest_Chunk (Engine : in out SHA512_Engine) with Inline is A, B, C, D, E, F, G, H, S0, S1, Ch, Maj, Temp_1, Temp_2: Unsigned_64; Word_Sequence : array (1 .. 80) of Unsigned_64; begin -- Break the chunk into 16 64-bit words, assign to Word_Sequence for I in 1 .. 16 loop -- TODO: Make this into its own loop, there is a pattern with the offsets Word_Sequence(I) := Shift_Left(Value => Unsigned_64 (Engine.Buffer(Stream_Element_Offset((I * 8) - 7))), Amount => 56) + Shift_Left(Value => Unsigned_64 (Engine.Buffer(Stream_Element_Offset((I * 8) - 6))), Amount => 48) + Shift_Left(Value => Unsigned_64 (Engine.Buffer(Stream_Element_Offset((I * 8) - 5))), Amount => 40) + Shift_Left(Value => Unsigned_64 (Engine.Buffer(Stream_Element_Offset((I * 8) - 4))), Amount => 32) + Shift_Left(Value => Unsigned_64 (Engine.Buffer(Stream_Element_Offset((I * 8) - 3))), Amount => 24) + Shift_Left(Value => Unsigned_64 (Engine.Buffer(Stream_Element_Offset((I * 8) - 2))), Amount => 16) + Shift_Left(Value => Unsigned_64 (Engine.Buffer(Stream_Element_Offset((I * 8) - 1))), Amount => 8) + Unsigned_64(Engine.Buffer(Stream_Element_Offset(I * 8))); end loop; -- Create the values for the rest of Word_Sequence for I in 17 .. 80 loop S0 := Rotate_Right (Value => Word_Sequence(I - 15), Amount => 1) xor Rotate_Right (Value => Word_Sequence(I - 15), Amount => 8) xor Shift_Right (Value => Word_Sequence(I - 15), Amount => 7); S1 := Rotate_Right (Value => Word_Sequence(I - 2), Amount => 19) xor Rotate_Right (Value => Word_Sequence(I - 2), Amount => 61) xor Shift_Right (Value => Word_Sequence(I - 2), Amount => 6); Word_Sequence(I) := Word_Sequence(I - 16) + S0 + Word_Sequence(I - 7) + S1; end loop; A := Engine.H0; B := Engine.H1; C := Engine.H2; D := Engine.H3; E := Engine.H4; F := Engine.H5; G := Engine.H6; H := Engine.H7; for I in 1 .. 80 loop S1 := Rotate_Right(Value => E, Amount => 14) xor Rotate_Right(Value => E, Amount => 18) xor Rotate_Right(Value => E, Amount => 41); Ch := (E and F) xor ( (not E) and G ); Temp_1 := H + S1 + Ch + K(I) + Word_Sequence(I); S0 := Rotate_Right(Value => A, Amount => 28) xor Rotate_Right(Value => A, Amount => 34) xor Rotate_Right(Value => A, Amount => 39); Maj := (A and B) xor (A and C) xor (B and C); Temp_2 := S0 + Maj; H := G; G := F; F := E; E := D + Temp_1; D := C; C := B; B := A; A := Temp_1 + Temp_2; end loop; Engine.H0 := Engine.H0 + A; Engine.H1 := Engine.H1 + B; Engine.H2 := Engine.H2 + C; Engine.H3 := Engine.H3 + D; Engine.H4 := Engine.H4 + E; Engine.H5 := Engine.H5 + F; Engine.H6 := Engine.H6 + G; Engine.H7 := Engine.H7 + H; Engine.Last_Element_Index := 0; end Digest_Chunk; --------- -- "<" -- --------- function "<" (Left, Right: SHA512_Hash) return Boolean is begin -- Even though our numbers are split into arrays of Unsigned_32, -- comparison operators can work on each section individually, -- as the lower indices have more significance for I in Message_Digest'Range loop if Left.Digest(I) < Right.Digest(I) then return True; elsif Left.Digest(I) > Right.Digest(I) then return False; end if; end loop; -- The only way we get here is when Left = Right return False; end "<"; --------- -- ">" -- --------- function ">" (Left, Right: SHA512_Hash) return Boolean is begin -- Even though our numbers are split into arrays of Unsigned_32, -- comparison operators can work on each section individually, -- as the lower indices have more significance for I in Message_Digest'Range loop if Left.Digest(I) > Right.Digest(I) then return True; elsif Left.Digest(I) < Right.Digest(I) then return False; end if; end loop; -- The only way we get here is when Left = Right return False; end ">"; --------- -- "=" -- --------- function "=" (Left, Right: SHA512_Hash) return Boolean is begin for I in Message_Digest'Range loop if Left.Digest(I) /= Right.Digest(I) then return False; end if; end loop; return True; end "="; ------------ -- Binary -- ------------ function Binary (Value: SHA512_Hash) return Hash_Binary_Value is I: Positive; Register: Unsigned_64; begin return Output: Hash_Binary_Value (1 .. SHA512_Hash_Bytes) do I := Output'First; for Chunk of reverse Value.Digest loop -- Value.Digest big-endian Register := Chunk; for J in 1 .. 8 loop -- Eight bytes per digest chunk Output(I) := Unsigned_8 (Register and 16#FF#); Register := Shift_Right (Register, 8); I := I + 1; end loop; end loop; end return; end Binary; ----------- -- Write -- ----------- procedure Write (Stream : in out SHA512_Engine; Item : in Stream_Element_Array) is Last_In: Stream_Element_Offset; Temp : U_128.Unsigned_128; begin -- Check for a null range of Item and discard if Item'Length = 0 then return; end if; Last_In := Item'First - 1; -- Finally, we can go ahead and add the message length to the Engine now, -- since there are early-ending code-paths below, and so we can avoid -- duplicating code. The only way this can really go wrong is if the -- entire message is larger than the Message_Size, which SHA512 limits to a -- 128-bit signed integer. Therefore a message of 2^128 bytes will cause -- an invalid hash, due to a wrap-around of the message_size. -- That's a risk we are willing to take. Temp.Low := Stream_Element'Size * Item'Length; Stream.Message_Length := U_128."+"(Stream.Message_Length, Temp); -- Our buffer has a size of 1024 (the size of a "chunk" of processing for -- the SHA-2 algorithm). -- Our write should be automated so that as soon as that buffer is full -- (no matter how much of the Item array is written already), the chunk is -- processed -- In order to take advantage of any processor vector copy features, we -- will explicitly copy Item in chunks that are either the full size of -- Item, 128 elements, or the remaining space in the hash Buffer, whichever -- is largest while Last_In < Item'Last loop declare subtype Buffer_Slice is Stream_Element_Offset range Stream.Last_Element_Index + 1 .. Stream.Buffer'Last; Buffer_Slice_Length: Stream_Element_Offset := Buffer_Slice'Last - Buffer_Slice'First + 1; subtype Item_Slice is Stream_Element_Offset range Last_In + 1 .. Item'Last; Item_Slice_Length: Stream_Element_Offset := Item_Slice'Last - Item_Slice'First + 1; begin if Buffer_Slice_Length > Item_Slice_Length then -- We can fit the rest in the buffer, with space left-over declare -- Set-up a specific slice in the Buffer which can accommodate -- the remaining elements of Item subtype Target_Slice is Stream_Element_Offset range Buffer_Slice'First .. Buffer_Slice'First + (Item_Slice'Last - Item_Slice'First); begin -- Here is the block copy Stream.Buffer(Target_Slice'Range):= Item (Item_Slice'Range); Stream.Last_Element_Index := Target_Slice'Last; end; -- That's it, we've absorbed the entire Item, no need to waste -- time updating Last_In. return; else -- This means the buffer space is either equal to or smaller than -- the remaining Item elements, this means we need process the -- chunk (digest the buffer) no matter what -- First step is to copy in as much of the remaining Item -- elements as possible declare subtype Source_Slice is Stream_Element_Offset range Item_Slice'First .. Item_Slice'First + Buffer_Slice_Length - 1; begin -- Block copy Stream.Buffer(Buffer_Slice'Range) := Item (Source_Slice'Range); Stream.Last_Element_Index := Buffer_Slice'Last; Last_In := Source_Slice'Last; end; -- Now we digest the currently full buffer Digest_Chunk (Stream); end if; end; end loop; end Write; ----------- -- Reset -- ----------- procedure Reset (Engine : in out SHA512_Engine) is begin Engine.Last_Element_Index := 0; Engine.Message_Length.Low := 0; Engine.Message_Length.High := 0; Engine.H0 := H0_Initial; Engine.H1 := H1_Initial; Engine.H2 := H2_Initial; Engine.H3 := H3_Initial; Engine.H4 := H4_Initial; Engine.H5 := H5_Initial; Engine.H6 := H6_Initial; Engine.H7 := H7_Initial; end Reset; ------------ -- Digest -- ------------ function Digest (Engine : in out SHA512_Engine) return Hash'Class is -- The core of the message digest algorithm occurs in-line with stream -- writes through the Digest_Chunk procedure. The role of this function -- is to append the message size and padding, and then execute the final -- Digest_Chunk before returning the digest. -- We work with the data in the Buffer in chunks of 1024 bits -- Once we get to the last section that is < 1024 bits, we append -- the 128 bit length and padding 0's -- In most cases, this 128 bit + padding will all be in the last section -- of the buffer -- We pad up until the 896th bit (112th byte) and then add the length -- However, we must also keep in mind the fringe case where the data ends -- at bit position 896 or later (byte 112 or later) -- In that case, the approach to take is to pad the final chunk, then add -- a new one that is ONLY padding and the 128 bit length Message_Length_Spliced : Stream_Element_Array(1 .. 16); Special_Case_Index : Stream_Element_Offset := 0; begin -- Splitting the 128-bit message length into array of bytes for I in 1 .. 8 loop Message_Length_Spliced(Stream_Element_Offset(I)) := Stream_Element (Unsigned_8(Shift_Right(Value => Engine.Message_Length.High, Amount => 8 * (8 - I)) and 16#ff#)); end loop; for I in 1 .. 8 loop Message_Length_Spliced(Stream_Element_Offset(I + 8)) := Stream_Element (Unsigned_8(Shift_Right(Value => Engine.Message_Length.Low, Amount => 8 * (8 - I)) and 16#ff#)); end loop; -- This is a while loop but we use an exit condition to make sure that it -- executes at least once (for the case of empty hash message) loop if Special_Case_Index /= 0 then if Special_Case_Index = 1 then Engine.Buffer(1) := 2#10000000#; else Engine.Buffer(1) := 2#00000000#; end if; Engine.Buffer(2 .. 112) := (others => 2#00000000#); Engine.Buffer(113 .. 128) := Message_Length_Spliced; Special_Case_Index := 0; -- If there is less than 1024 bits left in the Buffer else -- The case where one chunk will hold Buffer + padding + 64 bits if Engine.Last_Element_Index < 112 then -- Add the correct amount of padding Engine.Buffer(Engine.Last_Element_Index + 1) := 2#10000000#; Engine.Buffer(Engine.Last_Element_Index + 2 .. 112) := (others => 2#00000000#); -- Finish it off with Message_Length Engine.Buffer(113 .. 128) := Message_Length_Spliced; -- The case where one chunk will hold Buffer + padding, and -- another will hold padding + 128 bit message length else -- Put what we can of the padding in the current chunk Engine.Buffer(Engine.Last_Element_Index + 1) := 2#10000000#; Engine.Buffer(Engine.Last_Element_Index + 2 .. 128) := (others => 2#00000000#); -- Save where we left off in the padding for the next chunk Special_Case_Index := 129 - Engine.Last_Element_Index; end if; end if; Digest_Chunk (Engine); exit when Engine.Last_Element_Index = 0 and Special_Case_Index = 0; end loop; return Result: SHA512_Hash do Result.Digest := (1 => Engine.H0, 2 => Engine.H1, 3 => Engine.H2, 4 => Engine.H3, 5 => Engine.H4, 6 => Engine.H5, 7 => Engine.H6, 8 => Engine.H7); Engine.Reset; end return; end Digest; end Modular_Hashing.SHA512;
ekoeppen/STM32_Generic_Ada_Drivers
Ada
13,020
ads
-- This spec has been automatically generated from STM32F103.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with System; package STM32_SVD.AFIO is pragma Preelaborate; --------------- -- Registers -- --------------- subtype EVCR_PIN_Field is STM32_SVD.UInt4; subtype EVCR_PORT_Field is STM32_SVD.UInt3; subtype EVCR_EVOE_Field is STM32_SVD.Bit; -- Event Control Register (AFIO_EVCR) type EVCR_Register is record -- Pin selection PIN : EVCR_PIN_Field := 16#0#; -- Port selection PORT : EVCR_PORT_Field := 16#0#; -- Event Output Enable EVOE : EVCR_EVOE_Field := 16#0#; -- unspecified Reserved_8_31 : STM32_SVD.UInt24 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for EVCR_Register use record PIN at 0 range 0 .. 3; PORT at 0 range 4 .. 6; EVOE at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype MAPR_SPI1_REMAP_Field is STM32_SVD.Bit; subtype MAPR_I2C1_REMAP_Field is STM32_SVD.Bit; subtype MAPR_USART1_REMAP_Field is STM32_SVD.Bit; subtype MAPR_USART2_REMAP_Field is STM32_SVD.Bit; subtype MAPR_USART3_REMAP_Field is STM32_SVD.UInt2; subtype MAPR_TIM1_REMAP_Field is STM32_SVD.UInt2; subtype MAPR_TIM2_REMAP_Field is STM32_SVD.UInt2; subtype MAPR_TIM3_REMAP_Field is STM32_SVD.UInt2; subtype MAPR_TIM4_REMAP_Field is STM32_SVD.Bit; subtype MAPR_CAN_REMAP_Field is STM32_SVD.UInt2; subtype MAPR_PD01_REMAP_Field is STM32_SVD.Bit; subtype MAPR_TIM5CH4_IREMAP_Field is STM32_SVD.Bit; subtype MAPR_ADC1_ETRGINJ_REMAP_Field is STM32_SVD.Bit; subtype MAPR_ADC1_ETRGREG_REMAP_Field is STM32_SVD.Bit; subtype MAPR_ADC2_ETRGINJ_REMAP_Field is STM32_SVD.Bit; subtype MAPR_ADC2_ETRGREG_REMAP_Field is STM32_SVD.Bit; subtype MAPR_SWJ_CFG_Field is STM32_SVD.UInt3; -- AF remap and debug I/O configuration register (AFIO_MAPR) type MAPR_Register is record -- SPI1 remapping SPI1_REMAP : MAPR_SPI1_REMAP_Field := 16#0#; -- I2C1 remapping I2C1_REMAP : MAPR_I2C1_REMAP_Field := 16#0#; -- USART1 remapping USART1_REMAP : MAPR_USART1_REMAP_Field := 16#0#; -- USART2 remapping USART2_REMAP : MAPR_USART2_REMAP_Field := 16#0#; -- USART3 remapping USART3_REMAP : MAPR_USART3_REMAP_Field := 16#0#; -- TIM1 remapping TIM1_REMAP : MAPR_TIM1_REMAP_Field := 16#0#; -- TIM2 remapping TIM2_REMAP : MAPR_TIM2_REMAP_Field := 16#0#; -- TIM3 remapping TIM3_REMAP : MAPR_TIM3_REMAP_Field := 16#0#; -- TIM4 remapping TIM4_REMAP : MAPR_TIM4_REMAP_Field := 16#0#; -- CAN1 remapping CAN_REMAP : MAPR_CAN_REMAP_Field := 16#0#; -- Port D0/Port D1 mapping on OSCIN/OSCOUT PD01_REMAP : MAPR_PD01_REMAP_Field := 16#0#; -- Set and cleared by software TIM5CH4_IREMAP : MAPR_TIM5CH4_IREMAP_Field := 16#0#; -- ADC 1 External trigger injected conversion remapping ADC1_ETRGINJ_REMAP : MAPR_ADC1_ETRGINJ_REMAP_Field := 16#0#; -- ADC 1 external trigger regular conversion remapping ADC1_ETRGREG_REMAP : MAPR_ADC1_ETRGREG_REMAP_Field := 16#0#; -- ADC 2 external trigger injected conversion remapping ADC2_ETRGINJ_REMAP : MAPR_ADC2_ETRGINJ_REMAP_Field := 16#0#; -- ADC 2 external trigger regular conversion remapping ADC2_ETRGREG_REMAP : MAPR_ADC2_ETRGREG_REMAP_Field := 16#0#; -- unspecified Reserved_21_23 : STM32_SVD.UInt3 := 16#0#; -- Write-only. Serial wire JTAG configuration SWJ_CFG : MAPR_SWJ_CFG_Field := 16#0#; -- unspecified Reserved_27_31 : STM32_SVD.UInt5 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MAPR_Register use record SPI1_REMAP at 0 range 0 .. 0; I2C1_REMAP at 0 range 1 .. 1; USART1_REMAP at 0 range 2 .. 2; USART2_REMAP at 0 range 3 .. 3; USART3_REMAP at 0 range 4 .. 5; TIM1_REMAP at 0 range 6 .. 7; TIM2_REMAP at 0 range 8 .. 9; TIM3_REMAP at 0 range 10 .. 11; TIM4_REMAP at 0 range 12 .. 12; CAN_REMAP at 0 range 13 .. 14; PD01_REMAP at 0 range 15 .. 15; TIM5CH4_IREMAP at 0 range 16 .. 16; ADC1_ETRGINJ_REMAP at 0 range 17 .. 17; ADC1_ETRGREG_REMAP at 0 range 18 .. 18; ADC2_ETRGINJ_REMAP at 0 range 19 .. 19; ADC2_ETRGREG_REMAP at 0 range 20 .. 20; Reserved_21_23 at 0 range 21 .. 23; SWJ_CFG at 0 range 24 .. 26; Reserved_27_31 at 0 range 27 .. 31; end record; -- EXTICR1_EXTI array element subtype EXTICR1_EXTI_Element is STM32_SVD.UInt4; -- EXTICR1_EXTI array type EXTICR1_EXTI_Field_Array is array (0 .. 3) of EXTICR1_EXTI_Element with Component_Size => 4, Size => 16; -- Type definition for EXTICR1_EXTI type EXTICR1_EXTI_Field (As_Array : Boolean := False) is record case As_Array is when False => -- EXTI as a value Val : STM32_SVD.UInt16; when True => -- EXTI as an array Arr : EXTICR1_EXTI_Field_Array; end case; end record with Unchecked_Union, Size => 16; for EXTICR1_EXTI_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; -- External interrupt configuration register 1 (AFIO_EXTICR1) type EXTICR1_Register is record -- EXTI0 configuration EXTI : EXTICR1_EXTI_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_16_31 : STM32_SVD.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for EXTICR1_Register use record EXTI at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- EXTICR2_EXTI array element subtype EXTICR2_EXTI_Element is STM32_SVD.UInt4; -- EXTICR2_EXTI array type EXTICR2_EXTI_Field_Array is array (4 .. 7) of EXTICR2_EXTI_Element with Component_Size => 4, Size => 16; -- Type definition for EXTICR2_EXTI type EXTICR2_EXTI_Field (As_Array : Boolean := False) is record case As_Array is when False => -- EXTI as a value Val : STM32_SVD.UInt16; when True => -- EXTI as an array Arr : EXTICR2_EXTI_Field_Array; end case; end record with Unchecked_Union, Size => 16; for EXTICR2_EXTI_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; -- External interrupt configuration register 2 (AFIO_EXTICR2) type EXTICR2_Register is record -- EXTI4 configuration EXTI : EXTICR2_EXTI_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_16_31 : STM32_SVD.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for EXTICR2_Register use record EXTI at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- EXTICR3_EXTI array element subtype EXTICR3_EXTI_Element is STM32_SVD.UInt4; -- EXTICR3_EXTI array type EXTICR3_EXTI_Field_Array is array (8 .. 11) of EXTICR3_EXTI_Element with Component_Size => 4, Size => 16; -- Type definition for EXTICR3_EXTI type EXTICR3_EXTI_Field (As_Array : Boolean := False) is record case As_Array is when False => -- EXTI as a value Val : STM32_SVD.UInt16; when True => -- EXTI as an array Arr : EXTICR3_EXTI_Field_Array; end case; end record with Unchecked_Union, Size => 16; for EXTICR3_EXTI_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; -- External interrupt configuration register 3 (AFIO_EXTICR3) type EXTICR3_Register is record -- EXTI8 configuration EXTI : EXTICR3_EXTI_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_16_31 : STM32_SVD.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for EXTICR3_Register use record EXTI at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- EXTICR4_EXTI array element subtype EXTICR4_EXTI_Element is STM32_SVD.UInt4; -- EXTICR4_EXTI array type EXTICR4_EXTI_Field_Array is array (12 .. 15) of EXTICR4_EXTI_Element with Component_Size => 4, Size => 16; -- Type definition for EXTICR4_EXTI type EXTICR4_EXTI_Field (As_Array : Boolean := False) is record case As_Array is when False => -- EXTI as a value Val : STM32_SVD.UInt16; when True => -- EXTI as an array Arr : EXTICR4_EXTI_Field_Array; end case; end record with Unchecked_Union, Size => 16; for EXTICR4_EXTI_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; -- External interrupt configuration register 4 (AFIO_EXTICR4) type EXTICR4_Register is record -- EXTI12 configuration EXTI : EXTICR4_EXTI_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_16_31 : STM32_SVD.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for EXTICR4_Register use record EXTI at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype MAPR2_TIM9_REMAP_Field is STM32_SVD.Bit; subtype MAPR2_TIM10_REMAP_Field is STM32_SVD.Bit; subtype MAPR2_TIM11_REMAP_Field is STM32_SVD.Bit; subtype MAPR2_TIM13_REMAP_Field is STM32_SVD.Bit; subtype MAPR2_TIM14_REMAP_Field is STM32_SVD.Bit; subtype MAPR2_FSMC_NADV_Field is STM32_SVD.Bit; -- AF remap and debug I/O configuration register type MAPR2_Register is record -- unspecified Reserved_0_4 : STM32_SVD.UInt5 := 16#0#; -- TIM9 remapping TIM9_REMAP : MAPR2_TIM9_REMAP_Field := 16#0#; -- TIM10 remapping TIM10_REMAP : MAPR2_TIM10_REMAP_Field := 16#0#; -- TIM11 remapping TIM11_REMAP : MAPR2_TIM11_REMAP_Field := 16#0#; -- TIM13 remapping TIM13_REMAP : MAPR2_TIM13_REMAP_Field := 16#0#; -- TIM14 remapping TIM14_REMAP : MAPR2_TIM14_REMAP_Field := 16#0#; -- NADV connect/disconnect FSMC_NADV : MAPR2_FSMC_NADV_Field := 16#0#; -- unspecified Reserved_11_31 : STM32_SVD.UInt21 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MAPR2_Register use record Reserved_0_4 at 0 range 0 .. 4; TIM9_REMAP at 0 range 5 .. 5; TIM10_REMAP at 0 range 6 .. 6; TIM11_REMAP at 0 range 7 .. 7; TIM13_REMAP at 0 range 8 .. 8; TIM14_REMAP at 0 range 9 .. 9; FSMC_NADV at 0 range 10 .. 10; Reserved_11_31 at 0 range 11 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Alternate function I/O type AFIO_Peripheral is record -- Event Control Register (AFIO_EVCR) EVCR : aliased EVCR_Register; -- AF remap and debug I/O configuration register (AFIO_MAPR) MAPR : aliased MAPR_Register; -- External interrupt configuration register 1 (AFIO_EXTICR1) EXTICR1 : aliased EXTICR1_Register; -- External interrupt configuration register 2 (AFIO_EXTICR2) EXTICR2 : aliased EXTICR2_Register; -- External interrupt configuration register 3 (AFIO_EXTICR3) EXTICR3 : aliased EXTICR3_Register; -- External interrupt configuration register 4 (AFIO_EXTICR4) EXTICR4 : aliased EXTICR4_Register; -- AF remap and debug I/O configuration register MAPR2 : aliased MAPR2_Register; end record with Volatile; for AFIO_Peripheral use record EVCR at 16#0# range 0 .. 31; MAPR at 16#4# range 0 .. 31; EXTICR1 at 16#8# range 0 .. 31; EXTICR2 at 16#C# range 0 .. 31; EXTICR3 at 16#10# range 0 .. 31; EXTICR4 at 16#14# range 0 .. 31; MAPR2 at 16#1C# range 0 .. 31; end record; -- Alternate function I/O AFIO_Periph : aliased AFIO_Peripheral with Import, Address => System'To_Address (16#40010000#); end STM32_SVD.AFIO;
sungyeon/drake
Ada
610
adb
package body System.Runtime_Context is pragma Suppress (All_Checks); -- I hope it will be zero-initialized... Environment_Task_Local_Storage : aliased Task_Local_Storage; -- implementation function Get_Environment_Task_Local_Storage return not null Task_Local_Storage_Access is begin return Environment_Task_Local_Storage'Access; end Get_Environment_Task_Local_Storage; function Get_Task_Local_Storage return not null Task_Local_Storage_Access is begin return Get_Task_Local_Storage_Hook.all; end Get_Task_Local_Storage; end System.Runtime_Context;
stcarrez/babel
Ada
2,693
ads
----------------------------------------------------------------------- -- babel-streams-files -- Local file stream management -- 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. ----------------------------------------------------------------------- private with Util.Streams.Raw; -- == Local Files Stream == -- The <tt>Babel.Streams.Files</tt> package provides the streams support to read and write -- local files. package Babel.Streams.Files is type Stream_Type is new Babel.Streams.Stream_Type with private; type Stream_Access is access all Stream_Type'Class; -- Open the local file for reading and use the given buffer for the Read operation. procedure Open (Stream : in out Stream_Type; Path : in String; Buffer : in Babel.Files.Buffers.Buffer_Access); -- Create a file and prepare for the Write operation. procedure Create (Stream : in out Stream_Type; Path : in String; Mode : in Util.Systems.Types.mode_t); -- Read the data stream as much as possible and return the result in a buffer. -- The buffer is owned by the stream and need not be released. The same buffer may -- or may not be returned by the next <tt>Read</tt> operation. -- A null buffer is returned when the end of the data stream is reached. overriding procedure Read (Stream : in out Stream_Type; Buffer : out Babel.Files.Buffers.Buffer_Access); -- Write the buffer in the data stream. overriding procedure Write (Stream : in out Stream_Type; Buffer : in Babel.Files.Buffers.Buffer_Access); -- Close the data stream. overriding procedure Close (Stream : in out Stream_Type); -- Prepare to read again the data stream from the beginning. overriding procedure Rewind (Stream : in out Stream_Type); private type Stream_Type is new Babel.Streams.Stream_Type with record File : Util.Streams.Raw.Raw_Stream; Eof : Boolean := False; end record; end Babel.Streams.Files;
charlie5/lace
Ada
4,850
adb
with lace.Text.all_Tokens, ada.Characters.latin_1; package body lace.Text.all_Lines is use lace.Text.all_Tokens, ada.Characters.latin_1; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_2 is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_4 is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_8 is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_16 is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_32 is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_64 is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_128 is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_256 is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_512 is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_1k is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_2k is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_4k is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_8k is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_16k is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_32k is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_64k is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_128k is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_256k is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; function Lines (Self : in Item; Trim : in Boolean := False; max_Lines : in Positive := default_Max) return Text.items_512k is begin return Tokens (Self, LF, Trim, max_Lines); end Lines; end lace.Text.all_Lines;
sungyeon/drake
Ada
833
ads
pragma License (Unrestricted); -- BSD 3-Clause -- translated unit from dSFMT (dSFMT-common.h, dSFMT.c) private generic package Ada.Numerics.dSFMT.Generating is -- SSE2 version pragma Preelaborate; procedure do_recursion ( r : aliased out w128_t; a, b : aliased w128_t; lung : aliased in out w128_t) with Convention => Intrinsic; pragma Inline_Always (do_recursion); procedure convert_c0o1 (w : aliased in out w128_t) with Convention => Intrinsic; procedure convert_o0c1 (w : aliased in out w128_t) with Convention => Intrinsic; procedure convert_o0o1 (w : aliased in out w128_t) with Convention => Intrinsic; pragma Inline_Always (convert_c0o1); pragma Inline_Always (convert_o0c1); pragma Inline_Always (convert_o0o1); end Ada.Numerics.dSFMT.Generating;
zhmu/ananas
Ada
15,214
ads
------------------------------------------------------------------------------ -- -- -- GNAT LIBRARY COMPONENTS -- -- -- -- ADA.CONTAINERS.INDEFINITE_ORDERED_SETS -- -- -- -- S p e c -- -- -- -- Copyright (C) 2004-2022, Free Software Foundation, Inc. -- -- -- -- This specification is derived from the Ada Reference Manual for use with -- -- GNAT. The copyright notice above, and the license provisions that follow -- -- apply solely to the contents of the part following the private keyword. -- -- -- -- 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/>. -- -- -- -- This unit was originally developed by Matthew J Heaney. -- ------------------------------------------------------------------------------ with Ada.Iterator_Interfaces; with Ada.Containers.Helpers; private with Ada.Containers.Red_Black_Trees; private with Ada.Finalization; private with Ada.Streams; private with Ada.Strings.Text_Buffers; generic type Element_Type (<>) is private; with function "<" (Left, Right : Element_Type) return Boolean is <>; with function "=" (Left, Right : Element_Type) return Boolean is <>; package Ada.Containers.Indefinite_Ordered_Sets with SPARK_Mode => Off is pragma Annotate (CodePeer, Skip_Analysis); pragma Preelaborate; pragma Remote_Types; function Equivalent_Elements (Left, Right : Element_Type) return Boolean; type Set is tagged private with Constant_Indexing => Constant_Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type, Aggregate => (Empty => Empty, Add_Unnamed => Include); pragma Preelaborable_Initialization (Set); type Cursor is private; pragma Preelaborable_Initialization (Cursor); Empty_Set : constant Set; function Empty return Set; No_Element : constant Cursor; function Has_Element (Position : Cursor) return Boolean; package Set_Iterator_Interfaces is new Ada.Iterator_Interfaces (Cursor, Has_Element); function "=" (Left, Right : Set) return Boolean; function Equivalent_Sets (Left, Right : Set) return Boolean; function To_Set (New_Item : Element_Type) return Set; function Length (Container : Set) return Count_Type; function Is_Empty (Container : Set) return Boolean; procedure Clear (Container : in out Set); function Element (Position : Cursor) return Element_Type; procedure Replace_Element (Container : in out Set; Position : Cursor; New_Item : Element_Type); procedure Query_Element (Position : Cursor; Process : not null access procedure (Element : Element_Type)); type Constant_Reference_Type (Element : not null access constant Element_Type) is private with Implicit_Dereference => Element; function Constant_Reference (Container : aliased Set; Position : Cursor) return Constant_Reference_Type; pragma Inline (Constant_Reference); procedure Assign (Target : in out Set; Source : Set); function Copy (Source : Set) return Set; procedure Move (Target : in out Set; Source : in out Set); procedure Insert (Container : in out Set; New_Item : Element_Type; Position : out Cursor; Inserted : out Boolean); procedure Insert (Container : in out Set; New_Item : Element_Type); procedure Include (Container : in out Set; New_Item : Element_Type); procedure Replace (Container : in out Set; New_Item : Element_Type); procedure Exclude (Container : in out Set; Item : Element_Type); procedure Delete (Container : in out Set; Item : Element_Type); procedure Delete (Container : in out Set; Position : in out Cursor); procedure Delete_First (Container : in out Set); procedure Delete_Last (Container : in out Set); procedure Union (Target : in out Set; Source : Set); function Union (Left, Right : Set) return Set; function "or" (Left, Right : Set) return Set renames Union; procedure Intersection (Target : in out Set; Source : Set); function Intersection (Left, Right : Set) return Set; function "and" (Left, Right : Set) return Set renames Intersection; procedure Difference (Target : in out Set; Source : Set); function Difference (Left, Right : Set) return Set; function "-" (Left, Right : Set) return Set renames Difference; procedure Symmetric_Difference (Target : in out Set; Source : Set); function Symmetric_Difference (Left, Right : Set) return Set; function "xor" (Left, Right : Set) return Set renames Symmetric_Difference; function Overlap (Left, Right : Set) return Boolean; function Is_Subset (Subset : Set; Of_Set : Set) return Boolean; function First (Container : Set) return Cursor; function First_Element (Container : Set) return Element_Type; function Last (Container : Set) return Cursor; function Last_Element (Container : Set) return Element_Type; function Next (Position : Cursor) return Cursor; procedure Next (Position : in out Cursor); function Previous (Position : Cursor) return Cursor; procedure Previous (Position : in out Cursor); function Find (Container : Set; Item : Element_Type) return Cursor; function Floor (Container : Set; Item : Element_Type) return Cursor; function Ceiling (Container : Set; Item : Element_Type) return Cursor; function Contains (Container : Set; Item : Element_Type) return Boolean; function "<" (Left, Right : Cursor) return Boolean; function ">" (Left, Right : Cursor) return Boolean; function "<" (Left : Cursor; Right : Element_Type) return Boolean; function ">" (Left : Cursor; Right : Element_Type) return Boolean; function "<" (Left : Element_Type; Right : Cursor) return Boolean; function ">" (Left : Element_Type; Right : Cursor) return Boolean; procedure Iterate (Container : Set; Process : not null access procedure (Position : Cursor)); procedure Reverse_Iterate (Container : Set; Process : not null access procedure (Position : Cursor)); function Iterate (Container : Set) return Set_Iterator_Interfaces.Reversible_Iterator'class; function Iterate (Container : Set; Start : Cursor) return Set_Iterator_Interfaces.Reversible_Iterator'class; generic type Key_Type (<>) is private; with function Key (Element : Element_Type) return Key_Type; with function "<" (Left, Right : Key_Type) return Boolean is <>; package Generic_Keys is function Equivalent_Keys (Left, Right : Key_Type) return Boolean; function Key (Position : Cursor) return Key_Type; function Element (Container : Set; Key : Key_Type) return Element_Type; procedure Replace (Container : in out Set; Key : Key_Type; New_Item : Element_Type); procedure Exclude (Container : in out Set; Key : Key_Type); procedure Delete (Container : in out Set; Key : Key_Type); function Find (Container : Set; Key : Key_Type) return Cursor; function Floor (Container : Set; Key : Key_Type) return Cursor; function Ceiling (Container : Set; Key : Key_Type) return Cursor; function Contains (Container : Set; Key : Key_Type) return Boolean; procedure Update_Element_Preserving_Key (Container : in out Set; Position : Cursor; Process : not null access procedure (Element : in out Element_Type)); type Reference_Type (Element : not null access Element_Type) is private with Implicit_Dereference => Element; function Reference_Preserving_Key (Container : aliased in out Set; Position : Cursor) return Reference_Type; function Constant_Reference (Container : aliased Set; Key : Key_Type) return Constant_Reference_Type; function Reference_Preserving_Key (Container : aliased in out Set; Key : Key_Type) return Reference_Type; private type Set_Access is access all Set; for Set_Access'Storage_Size use 0; type Key_Access is access all Key_Type; package Impl is new Helpers.Generic_Implementation; type Reference_Control_Type is new Impl.Reference_Control_Type with record Container : Set_Access; Pos : Cursor; Old_Key : Key_Access; end record; overriding procedure Finalize (Control : in out Reference_Control_Type); pragma Inline (Finalize); type Reference_Type (Element : not null access Element_Type) is record Control : Reference_Control_Type; end record; use Ada.Streams; procedure Write (Stream : not null access Root_Stream_Type'Class; Item : Reference_Type); for Reference_Type'Write use Write; procedure Read (Stream : not null access Root_Stream_Type'Class; Item : out Reference_Type); for Reference_Type'Read use Read; end Generic_Keys; private pragma Inline (Next); pragma Inline (Previous); type Node_Type; type Node_Access is access Node_Type; type Element_Access is access all Element_Type; type Node_Type is limited record Parent : Node_Access; Left : Node_Access; Right : Node_Access; Color : Red_Black_Trees.Color_Type := Red_Black_Trees.Red; Element : Element_Access; end record; package Tree_Types is new Red_Black_Trees.Generic_Tree_Types (Node_Type, Node_Access); type Set is new Ada.Finalization.Controlled with record Tree : Tree_Types.Tree_Type; end record with Put_Image => Put_Image; procedure Put_Image (S : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class; V : Set); overriding procedure Adjust (Container : in out Set); overriding procedure Finalize (Container : in out Set) renames Clear; use Red_Black_Trees; use Tree_Types, Tree_Types.Implementation; use Ada.Finalization; use Ada.Streams; procedure Write (Stream : not null access Root_Stream_Type'Class; Container : Set); for Set'Write use Write; procedure Read (Stream : not null access Root_Stream_Type'Class; Container : out Set); for Set'Read use Read; type Set_Access is access all Set; for Set_Access'Storage_Size use 0; type Cursor is record Container : Set_Access; Node : Node_Access; end record; procedure Write (Stream : not null access Root_Stream_Type'Class; Item : Cursor); for Cursor'Write use Write; procedure Read (Stream : not null access Root_Stream_Type'Class; Item : out Cursor); for Cursor'Read use Read; subtype Reference_Control_Type is Implementation.Reference_Control_Type; -- It is necessary to rename this here, so that the compiler can find it type Constant_Reference_Type (Element : not null access constant Element_Type) is record Control : Reference_Control_Type := raise Program_Error with "uninitialized reference"; -- The RM says, "The default initialization of an object of -- type Constant_Reference_Type or Reference_Type propagates -- Program_Error." end record; procedure Read (Stream : not null access Root_Stream_Type'Class; Item : out Constant_Reference_Type); for Constant_Reference_Type'Read use Read; procedure Write (Stream : not null access Root_Stream_Type'Class; Item : Constant_Reference_Type); for Constant_Reference_Type'Write use Write; -- Three operations are used to optimize in the expansion of "for ... of" -- loops: the Next(Cursor) procedure in the visible part, and the following -- Pseudo_Reference and Get_Element_Access functions. See Sem_Ch5 for -- details. function Pseudo_Reference (Container : aliased Set'Class) return Reference_Control_Type; pragma Inline (Pseudo_Reference); -- Creates an object of type Reference_Control_Type pointing to the -- container, and increments the Lock. Finalization of this object will -- decrement the Lock. function Get_Element_Access (Position : Cursor) return not null Element_Access; -- Returns a pointer to the element designated by Position. Empty_Set : constant Set := (Controlled with others => <>); function Empty return Set is (Empty_Set); No_Element : constant Cursor := Cursor'(null, null); type Iterator is new Limited_Controlled and Set_Iterator_Interfaces.Reversible_Iterator with record Container : Set_Access; Node : Node_Access; end record with Disable_Controlled => not T_Check; overriding procedure Finalize (Object : in out Iterator); overriding function First (Object : Iterator) return Cursor; overriding function Last (Object : Iterator) return Cursor; overriding function Next (Object : Iterator; Position : Cursor) return Cursor; overriding function Previous (Object : Iterator; Position : Cursor) return Cursor; end Ada.Containers.Indefinite_Ordered_Sets;
Componolit/libsparkcrypto
Ada
2,356
adb
------------------------------------------------------------------------------- -- This file is part of libsparkcrypto. -- -- Copyright (C) 2010, Alexander Senier -- Copyright (C) 2010, secunet Security Networks AG -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met: -- -- * Redistributions of source code must retain the above copyright notice, -- this list of conditions and the following disclaimer. -- -- * Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- -- * Neither the name of the nor the names of its contributors may be used -- to endorse or promote products derived from this software without -- specific prior written permission. -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS -- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -- POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------- with System.Machine_Code; package body LSC.Internal.Byteswap64 with SPARK_Mode => Off is function Swap (Value : Types.Word64) return Types.Word64 is Result : Types.Word64; begin System.Machine_Code.Asm ("bswap %0", Inputs => (Types.Word64'Asm_Input ("0", Value)), Outputs => (Types.Word64'Asm_Output ("=r", Result)), Volatile => True); return Result; end Swap; end LSC.Internal.Byteswap64;
msorvig/qt-quick-bindings
Ada
215
adb
with Interfaces.C.Strings; use Interfaces.C.Strings; package body QtQuick is procedure Qt_Main (MainQmlFile : String) is begin Qt_Main_Simple(New_String(MainQmlFile)); end Qt_Main; end QtQuick;
sungyeon/drake
Ada
2,242
ads
pragma License (Unrestricted); -- extended unit, see AI05-0001-1 private with System.Storage_Elements; generic -- type Object is limited private; type Object is private; -- limited type could not have copy-assign version New_Object package System.Initialization is -- This is an implementation of Matthew Heaney's plan in AI05-0001-1. pragma Preelaborate; type Object_Storage is private; -- has size and alignment of type Object -- need separate versions for limited Obj vs. non-limited Obj? -- => yes -- Note: Your application-code should set the alignment -- because Object'Alignment can not be static expression... type Object_Pointer is access all Object; for Object_Pointer'Storage_Size use 0; -- to default-init object function New_Object (Storage : not null access Object_Storage) return Object_Pointer; -- to copy-assign the object function New_Object ( Storage : not null access Object_Storage; Value : Object) return Object_Pointer; -- modified -- Because Object_Storage is not tagged type, -- so it is not assured to pass-by-reference (?) -- procedure Delete_Object (Storage : in out Object_Storage); procedure Delete_Object (Storage : not null access Object_Storage); -- extended -- New and Delete seems like sense of C++, -- but New and Dispose is suitable for sense of Pascal :-) procedure Dispose_Object (Storage : not null access Object_Storage) renames Delete_Object; private use type Storage_Elements.Storage_Offset; type A1 is array (1 .. 1) of Object; pragma Suppress_Initialization (A1); type A2 is array (1 .. 2) of Object; pragma Suppress_Initialization (A2); -- Use A2'Max_Size_In_Storage_Elements - A1'Max_Size_In_Storage_Elements -- because Ada.Finalization.Controlled'Max_Size_In_Storage_Elements -- includes System.Finalization_Masters.Header_Size. type Object_Storage is new Storage_Elements.Storage_Array ( 1 .. Storage_Elements.Storage_Offset'(A2'Max_Size_In_Storage_Elements) - A1'Max_Size_In_Storage_Elements); pragma Suppress_Initialization (Object_Storage); end System.Initialization;
stcarrez/ada-awa
Ada
1,160
ads
----------------------------------------------------------------------- -- jobs-modules-tests -- Unit tests for AWA job module -- Copyright (C) 2012 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.Jobs.Modules.Tests is procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite); type Test is new AWA.Tests.Test with null record; -- Test the job factory. procedure Test_Register (T : in out Test); end AWA.Jobs.Modules.Tests;
charlie5/cBound
Ada
1,690
ads
-- This file is generated by SWIG. Please do not modify by hand. -- with Interfaces; with Interfaces.C; with Interfaces.C.Pointers; package xcb.xcb_glx_get_queryiv_arb_request_t is -- Item -- type Item is record major_opcode : aliased Interfaces.Unsigned_8; minor_opcode : aliased Interfaces.Unsigned_8; length : aliased Interfaces.Unsigned_16; context_tag : aliased xcb.xcb_glx_context_tag_t; target : aliased Interfaces.Unsigned_32; pname : aliased Interfaces.Unsigned_32; end record; -- Item_Array -- type Item_Array is array (Interfaces.C .size_t range <>) of aliased xcb.xcb_glx_get_queryiv_arb_request_t .Item; -- Pointer -- package C_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_glx_get_queryiv_arb_request_t.Item, Element_Array => xcb.xcb_glx_get_queryiv_arb_request_t.Item_Array, Default_Terminator => (others => <>)); subtype Pointer is C_Pointers.Pointer; -- Pointer_Array -- type Pointer_Array is array (Interfaces.C .size_t range <>) of aliased xcb.xcb_glx_get_queryiv_arb_request_t .Pointer; -- Pointer_Pointer -- package C_Pointer_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_glx_get_queryiv_arb_request_t.Pointer, Element_Array => xcb.xcb_glx_get_queryiv_arb_request_t.Pointer_Array, Default_Terminator => null); subtype Pointer_Pointer is C_Pointer_Pointers.Pointer; end xcb.xcb_glx_get_queryiv_arb_request_t;
sebsgit/textproc
Ada
3,341
ads
with opencl; with cl_objects; with PixelArray.Gpu; with ImageRegions; with System; with Ada.Finalization; package GpuComponentLabeling is pragma Elaborate_Body; pragma Assertion_Policy (Pre => Check, Post => Check, Type_Invariant => Check); type Processor is tagged limited private; type Processor_Access is access all Processor; type Pixel_CCL_Data is record label: opencl.cl_uint; min_x, min_y: opencl.cl_int; max_x, max_y: opencl.cl_int; px_count: opencl.cl_uint; end record; for Pixel_CCL_Data'Size use 32 * 6; pragma Convention(Convention => C, Entity => Pixel_CCL_Data); type CCL_Data is array (Natural range <>) of Pixel_CCL_Data; pragma Convention(Convention => C, Entity => CCL_Data); function Create(ctx: cl_objects.Context_Access; width, height: in Positive; cl_code: out opencl.Status) return Processor; function Init_CCL_Data(proc: in out Processor; gpu_image: in out PixelArray.Gpu.GpuImage; events_to_wait: in opencl.Events; cl_code: out opencl.Status) return cl_objects.Event; function Vertical_Pass(proc: in out Processor; events_to_wait: opencl.Events; cl_code: out opencl.Status) return cl_objects.Event; function Merge_Pass(proc: in out Processor; width_div: in Positive; events_to_wait: in opencl.Events; cl_code: out opencl.Status) return cl_objects.Event; function Merge_Pass(proc: in out Processor; events_to_wait: in opencl.Events; cl_code: out opencl.Status) return cl_objects.Event; function Run_CCL(proc: in out Processor; gpu_image: in out PixelArray.Gpu.GpuImage; events_to_wait: in opencl.Events; cl_code: out opencl.Status) return cl_objects.Event; function Get_Width(proc: in Processor) return Natural; function Get_Height(proc: in Processor) return Natural; function Detect_Regions(proc: in out Processor; preprocessed_cpu_image: in PixelArray.ImagePlane; cl_code: out opencl.Status) return ImageRegions.RegionVector.Vector; function Detect_Regions_And_Assign_Labels(proc: in out Processor; preprocessed_cpu_image: in out PixelArray.ImagePlane; cl_code: out opencl.Status) return ImageRegions.RegionVector.Vector; function Detect_Regions_And_Assign_Labels(proc: in out Processor; preprocessed_gpu_image: in out PixelArray.Gpu.GpuImage; target_cpu_image: in out PixelArray.ImagePlane; events_to_wait: in opencl.Events; cl_code: out opencl.Status) return ImageRegions.RegionVector.Vector; -- exposed for testing function Get_CCL_Data(proc: in out Processor; host_buff: in System.Address; events_to_wait: in opencl.Events; cl_code: out opencl.Status) return cl_objects.Event; private type Processor is new Ada.Finalization.Limited_Controlled with record context: cl_objects.Context_Access; width, height: aliased opencl.cl_int := 0; max_ccl_size: opencl.cl_int := 0; ccl_data: cl_objects.Buffer_Access; gpu_queue: cl_objects.Command_Queue_Access; processing_program: cl_objects.Program_Access; initialization_kernel: cl_objects.Kernel_Access; vertical_pass_kernel: cl_objects.Kernel_Access; merge_pass_kernel: cl_objects.Kernel_Access; label_assign_pass_kernel: cl_objects.Kernel_Access; end record; overriding procedure Finalize(This: in out Processor); end GpuComponentLabeling;
AdaCore/libadalang
Ada
363
adb
procedure TestIfc is package Pkg is type A is interface; procedure Foo (Self : A; O : Natural) is null; type B is interface and A; procedure Bar (Self : B) is null; type C is new B with null record; end Pkg; use Pkg; Inst : B'Class := C'(null record); begin Foo (Inst, 12); pragma Test_Statement; end Testifc;
redparavoz/ada-wiki
Ada
7,120
ads
----------------------------------------------------------------------- -- wiki-filters-collectors -- Wiki word and link collectors -- Copyright (C) 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.Containers.Indefinite_Ordered_Maps; -- === Collector Filters === -- The <tt>Wiki.Filters.Collectors</tt> package defines three filters that can be used to -- collect words, links or images contained in a Wiki document. The collector filters are -- inserted in the filter chain and they collect the data as the Wiki text is parsed. -- After the parsing, the collector filters have collected either the words or the links -- and they can be queried by using the <tt>Find</tt> or <tt>Iterate</tt> operations. -- -- The filter is inserted in the filter chain before parsing the Wiki document. -- -- Words : aliased Wiki.Filters.Collectors.Word_Collector_Type; -- ... -- Engine.Add_Filter (Words'Unchecked_Access); -- -- Once the document is parsed, the collector filters contains the data that was collected. -- The <tt>Iterate</tt> procedure can be used to have a procedure called for each value -- collected by the filter. -- -- Words.Iterate (Print'Access); -- package Wiki.Filters.Collectors is pragma Preelaborate; package WString_Maps is new Ada.Containers.Indefinite_Ordered_Maps (Key_Type => Wiki.Strings.WString, Element_Type => Natural, "<" => "<", "=" => "="); subtype Map is WString_Maps.Map; subtype Cursor is WString_Maps.Cursor; -- ------------------------------ -- General purpose collector type -- ------------------------------ type Collector_Type is new Filter_Type with private; type Collector_Type_Access is access all Collector_Type'Class; function Find (Map : in Collector_Type; Item : in Wiki.Strings.WString) return Cursor; function Contains (Map : in Collector_Type; Item : in Wiki.Strings.WString) return Boolean; procedure Iterate (Map : in Collector_Type; Process : not null access procedure (Pos : in Cursor)); -- ------------------------------ -- Word Collector type -- ------------------------------ type Word_Collector_Type is new Collector_Type with private; type Word_Collector_Type_Access is access all Word_Collector_Type'Class; -- Add a text content with the given format to the document. procedure Add_Text (Filter : in out Word_Collector_Type; Document : in out Wiki.Documents.Document; Text : in Wiki.Strings.WString; Format : in Wiki.Format_Map); -- Add a section header with the given level in the document. procedure Add_Header (Filter : in out Word_Collector_Type; Document : in out Wiki.Documents.Document; Header : in Wiki.Strings.WString; Level : in Natural); -- Add a link. procedure Add_Link (Filter : in out Word_Collector_Type; Document : in out Wiki.Documents.Document; Name : in Wiki.Strings.WString; Attributes : in out Wiki.Attributes.Attribute_List); -- Add an image. procedure Add_Image (Filter : in out Word_Collector_Type; Document : in out Wiki.Documents.Document; Name : in Wiki.Strings.WString; Attributes : in out Wiki.Attributes.Attribute_List); -- Add a quote. procedure Add_Quote (Filter : in out Word_Collector_Type; Document : in out Wiki.Documents.Document; Name : in Wiki.Strings.WString; Attributes : in out Wiki.Attributes.Attribute_List); -- Add a text block that is pre-formatted. procedure Add_Preformatted (Filter : in out Word_Collector_Type; Document : in out Wiki.Documents.Document; Text : in Wiki.Strings.WString; Format : in Wiki.Strings.WString); -- ------------------------------ -- Link Collector type -- ------------------------------ type Link_Collector_Type is new Collector_Type with private; type Link_Collector_Type_Access is access all Link_Collector_Type'Class; -- Add a link. overriding procedure Add_Link (Filter : in out Link_Collector_Type; Document : in out Wiki.Documents.Document; Name : in Wiki.Strings.WString; Attributes : in out Wiki.Attributes.Attribute_List); -- Push a HTML node with the given tag to the document. overriding procedure Push_Node (Filter : in out Link_Collector_Type; Document : in out Wiki.Documents.Document; Tag : in Wiki.Html_Tag; Attributes : in out Wiki.Attributes.Attribute_List); -- ------------------------------ -- Image Collector type -- ------------------------------ type Image_Collector_Type is new Collector_Type with private; type Image_Collector_Type_Access is access all Image_Collector_Type'Class; -- Add an image. overriding procedure Add_Image (Filter : in out Image_Collector_Type; Document : in out Wiki.Documents.Document; Name : in Wiki.Strings.WString; Attributes : in out Wiki.Attributes.Attribute_List); private type Collector_Type is new Filter_Type with record Items : WString_Maps.Map; end record; type Word_Collector_Type is new Collector_Type with null record; procedure Collect_Words (Filter : in out Word_Collector_Type; Content : in Wiki.Strings.WString); type Link_Collector_Type is new Collector_Type with null record; procedure Collect_Link (Filter : in out Link_Collector_Type; Attributes : in Wiki.Attributes.Attribute_List; Name : in String); type Image_Collector_Type is new Collector_Type with null record; end Wiki.Filters.Collectors;
reznikmm/matreshka
Ada
3,961
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_Fixed_Attributes; package Matreshka.ODF_Text.Fixed_Attributes is type Text_Fixed_Attribute_Node is new Matreshka.ODF_Text.Abstract_Text_Attribute_Node and ODF.DOM.Text_Fixed_Attributes.ODF_Text_Fixed_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Text_Fixed_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Text_Fixed_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Text.Fixed_Attributes;
AdaCore/training_material
Ada
369
ads
with Messages.List_Types; package Messages.List_Types.Operations is procedure Append (List : in out List_T; Item : Message_T); function Next (List : List_T) return List_T; function Is_Null (List : List_T) return Boolean; function Image (Message : List_T) return String; end Messages.List_Types.Operations;
reznikmm/matreshka
Ada
4,616
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_Style.Line_Break_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Style_Line_Break_Attribute_Node is begin return Self : Style_Line_Break_Attribute_Node do Matreshka.ODF_Style.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Style_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Style_Line_Break_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Line_Break_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Style_URI, Matreshka.ODF_String_Constants.Line_Break_Attribute, Style_Line_Break_Attribute_Node'Tag); end Matreshka.ODF_Style.Line_Break_Attributes;
nerilex/ada-util
Ada
12,310
adb
----------------------------------------------------------------------- -- util-serialize-io -- IO Drivers for serialization -- Copyright (C) 2010, 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 Util.Streams.Files; with Ada.Streams; with Ada.Streams.Stream_IO; with Ada.Exceptions; with Ada.IO_Exceptions; package body Util.Serialize.IO is -- use Util.Log; use type Util.Log.Loggers.Logger_Access; -- The logger' Log : aliased constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Util.Serialize.IO", Util.Log.WARN_LEVEL); procedure Write_Attribute (Stream : in out Output_Stream'Class; Name : in String; Value : in Ada.Strings.Unbounded.Unbounded_String) is begin Stream.Write_Attribute (Name, Ada.Strings.Unbounded.To_String (Value)); end Write_Attribute; procedure Write_Entity (Stream : in out Output_Stream'Class; Name : in String; Value : in Ada.Strings.Unbounded.Unbounded_String) is begin Stream.Write_Entity (Name, Ada.Strings.Unbounded.To_String (Value)); end Write_Entity; -- ------------------------------ -- Read the file and parse it using the JSON parser. -- ------------------------------ procedure Parse (Handler : in out Parser; File : in String) is Stream : aliased Util.Streams.Files.File_Stream; Buffer : Util.Streams.Buffered.Buffered_Stream; begin if Handler.Error_Logger = null then Handler.Error_Logger := Log'Access; end if; Handler.Error_Logger.Info ("Reading file {0}", File); Handler.File := Ada.Strings.Unbounded.To_Unbounded_String (File); Buffer.Initialize (Output => null, Input => Stream'Unchecked_Access, Size => 1024); Stream.Open (Mode => Ada.Streams.Stream_IO.In_File, Name => File); Context_Stack.Clear (Handler.Stack); Parser'Class (Handler).Parse (Buffer); exception when Util.Serialize.Mappers.Field_Fatal_Error => null; when Ada.IO_Exceptions.Name_Error => Parser'Class (Handler).Error ("File '" & File & "' does not exist."); when E : others => Parser'Class (Handler).Error ("Exception " & Ada.Exceptions.Exception_Name (E)); end Parse; -- ------------------------------ -- Parse the content string. -- ------------------------------ procedure Parse_String (Handler : in out Parser; Content : in String) is Stream : aliased Util.Streams.Buffered.Buffered_Stream; begin if Handler.Error_Logger = null then Handler.Error_Logger := Log'Access; end if; Handler.File := Ada.Strings.Unbounded.To_Unbounded_String ("<inline>"); Stream.Initialize (Content => Content); Context_Stack.Clear (Handler.Stack); Parser'Class (Handler).Parse (Stream); exception when Util.Serialize.Mappers.Field_Fatal_Error => null; when E : others => Parser'Class (Handler).Error ("Exception " & Ada.Exceptions.Exception_Name (E)); end Parse_String; -- ------------------------------ -- Returns true if the <b>Parse</b> operation detected at least one error. -- ------------------------------ function Has_Error (Handler : in Parser) return Boolean is begin return Handler.Error_Flag; end Has_Error; -- ------------------------------ -- Set the error logger to report messages while parsing and reading the input file. -- ------------------------------ procedure Set_Logger (Handler : in out Parser; Logger : in Util.Log.Loggers.Logger_Access) is begin Handler.Error_Logger := Logger; end Set_Logger; -- ------------------------------ -- Push the current context when entering in an element. -- ------------------------------ procedure Push (Handler : in out Parser) is use type Util.Serialize.Mappers.Mapper_Access; begin Context_Stack.Push (Handler.Stack); end Push; -- ------------------------------ -- Pop the context and restore the previous context when leaving an element -- ------------------------------ procedure Pop (Handler : in out Parser) is begin Context_Stack.Pop (Handler.Stack); end Pop; function Find_Mapper (Handler : in Parser; Name : in String) return Util.Serialize.Mappers.Mapper_Access is pragma Unreferenced (Handler, Name); begin return null; end Find_Mapper; -- ------------------------------ -- Start a new object associated with the given name. This is called when -- the '{' is reached. The reader must be updated so that the next -- <b>Set_Member</b> procedure will associate the name/value pair on the -- new object. -- ------------------------------ procedure Start_Object (Handler : in out Parser; Name : in String) is use type Util.Serialize.Mappers.Mapper_Access; Current : constant Element_Context_Access := Context_Stack.Current (Handler.Stack); Next : Element_Context_Access; Pos : Positive; begin Log.Debug ("Start object {0}", Name); Context_Stack.Push (Handler.Stack); Next := Context_Stack.Current (Handler.Stack); if Current /= null then Pos := 1; -- Notify we are entering in the given node for each active mapping. for I in Current.Active_Nodes'Range loop declare Node : constant Mappers.Mapper_Access := Current.Active_Nodes (I); Child : Mappers.Mapper_Access; begin exit when Node = null; Child := Node.Find_Mapper (Name => Name); if Child = null and then Node.Is_Wildcard then Child := Node; end if; if Child /= null then Log.Debug ("{0} is matching {1}", Name, Child.Get_Name); Child.Start_Object (Handler, Name); Next.Active_Nodes (Pos) := Child; Pos := Pos + 1; end if; end; end loop; while Pos <= Next.Active_Nodes'Last loop Next.Active_Nodes (Pos) := null; Pos := Pos + 1; end loop; else Next.Active_Nodes (1) := Handler.Mapping_Tree.Find_Mapper (Name); end if; end Start_Object; -- ------------------------------ -- Finish an object associated with the given name. The reader must be -- updated to be associated with the previous object. -- ------------------------------ procedure Finish_Object (Handler : in out Parser; Name : in String) is use type Util.Serialize.Mappers.Mapper_Access; begin Log.Debug ("Finish object {0}", Name); declare Current : constant Element_Context_Access := Context_Stack.Current (Handler.Stack); begin if Current /= null then -- Notify we are leaving the given node for each active mapping. for I in Current.Active_Nodes'Range loop declare Node : constant Mappers.Mapper_Access := Current.Active_Nodes (I); begin exit when Node = null; Node.Finish_Object (Handler, Name); end; end loop; end if; end; Handler.Pop; end Finish_Object; procedure Start_Array (Handler : in out Parser; Name : in String) is pragma Unreferenced (Name); begin Handler.Push; end Start_Array; procedure Finish_Array (Handler : in out Parser; Name : in String) is pragma Unreferenced (Name); begin Handler.Pop; end Finish_Array; -- ----------------------- -- Set the name/value pair on the current object. For each active mapping, -- find whether a rule matches our name and execute it. -- ----------------------- procedure Set_Member (Handler : in out Parser; Name : in String; Value : in Util.Beans.Objects.Object; Attribute : in Boolean := False) is use Util.Serialize.Mappers; Current : constant Element_Context_Access := Context_Stack.Current (Handler.Stack); begin Log.Debug ("Set member {0}", Name); if Current /= null then -- Look each active mapping node. for I in Current.Active_Nodes'Range loop declare Node : constant Mapper_Access := Current.Active_Nodes (I); begin exit when Node = null; Node.Set_Member (Name => Name, Value => Value, Attribute => Attribute, Context => Handler); exception when E : Util.Serialize.Mappers.Field_Error => Parser'Class (Handler).Error (Message => Ada.Exceptions.Exception_Message (E)); when E : Util.Serialize.Mappers.Field_Fatal_Error => Parser'Class (Handler).Error (Message => Ada.Exceptions.Exception_Message (E)); raise; -- For other exception, report an error with the field name and value. when E : others => Parser'Class (Handler).Error (Message => "Cannot set field '" & Name & "' to '" & Util.Beans.Objects.To_String (Value) & "': " & Ada.Exceptions.Exception_Message (E)); raise; end; end loop; end if; end Set_Member; -- ------------------------------ -- Get the current location (file and line) to report an error message. -- ------------------------------ function Get_Location (Handler : in Parser) return String is begin return Ada.Strings.Unbounded.To_String (Handler.File); end Get_Location; -- ------------------------------ -- Report an error while parsing the input stream. The error message will be reported -- on the logger associated with the parser. The parser will be set as in error so that -- the <b>Has_Error</b> function will return True after parsing the whole file. -- ------------------------------ procedure Error (Handler : in out Parser; Message : in String) is begin Handler.Error_Logger.Error ("{0}: {1}", Parser'Class (Handler).Get_Location, Message); Handler.Error_Flag := True; end Error; procedure Add_Mapping (Handler : in out Parser; Path : in String; Mapper : in Util.Serialize.Mappers.Mapper_Access) is begin Handler.Mapping_Tree.Add_Mapping (Path, Mapper); end Add_Mapping; -- ------------------------------ -- Dump the mapping tree on the logger using the INFO log level. -- ------------------------------ procedure Dump (Handler : in Parser'Class; Logger : in Util.Log.Loggers.Logger'Class) is begin Util.Serialize.Mappers.Dump (Handler.Mapping_Tree, Logger, "Mapping "); end Dump; end Util.Serialize.IO;
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.Table_Is_Active_Attributes is pragma Preelaborate; type ODF_Table_Is_Active_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Table_Is_Active_Attribute_Access is access all ODF_Table_Is_Active_Attribute'Class with Storage_Size => 0; end ODF.DOM.Table_Is_Active_Attributes;
stcarrez/ada-ado
Ada
15,307
ads
----------------------------------------------------------------------- -- ado-queries -- Database Queries -- Copyright (C) 2009 - 2022 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.Strings; with Util.Refs; with ADO.SQL; private with ADO.Configs; with Ada.Strings.Unbounded; with Ada.Finalization; -- == Named Queries == -- Ada Database Objects provides a small framework which helps in -- using complex SQL queries in an application by using named queries. -- The benefit of the framework are the following: -- -- * The SQL query result are directly mapped in Ada records, -- * It is easy to change or tune an SQL query without re-building the application, -- * The SQL query can be easily tuned for a given database. -- -- The database query framework uses an XML query file: -- -- * The XML query file defines a mapping that represents the result of SQL queries, -- * The XML mapping is used by Dynamo code generator to generate an Ada record, -- * The XML query file also defines a set of SQL queries, each query being -- identified by a unique name, -- * The XML query file is read by the application to obtain the SQL query -- associated with a query name, -- * The application uses the `List` procedure generated by Dynamo. -- -- === XML Query File === -- The XML query file uses the `query-mapping` root element. It should -- define at most one `class` mapping and several `query` definitions. -- The `class` definition should come first before any `query` definition. -- -- <query-mapping> -- <class>...</class> -- <query>...</query> -- </query-mapping> -- -- === SQL Result Mapping === -- The XML query mapping is very close to the database XML table mapping. -- The difference is that there is no need to specify any table name -- nor any SQL type. The XML query mapping is used to build an Ada -- record that correspond to query results. Unlike the database table mapping, -- the Ada record will not be tagged and its definition will expose all the record -- members directly. -- -- The following XML query mapping: -- -- <query-mapping> -- <class name='Samples.Model.User_Info'> -- <property name="name" type="String"> -- <comment>the user name</comment> -- </property> -- <property name="email" type="String"> -- <comment>the email address</comment> -- </property> -- </class> -- </query-mapping> -- -- will generate the following Ada record and it will instantiate the Ada container `Vectors` -- generic to provide a support for vectors of the record: -- -- package Samples.Model is -- type User_Info is record -- Name : Unbounded_String; -- Email : Unbounded_String; -- end record; -- package User_Info_Vectors is -- new Ada.Containers.Vectors (Index_Type => Natural, -- Element_Type => User_Info, -- "=" => "="); -- subtype User_Info_Vector is User_Info_Vectors.Vector; -- end Samples.Model; -- -- A `List` operation is also generated and can be used to execute an SQL query and have -- the result mapped in the record. -- -- The same query mapping can be used by different queries. -- -- After writing or updating a query mapping, it is necessary to launch the -- Dynamo code generator to generate the corresponding Ada model. -- -- === SQL Queries === -- The XML query file defines a list of SQL queries that the application -- can use. Each query is associated with a unique name. The application -- will use that name to identify the SQL query to execute. For each query, -- the file also describes the SQL query pattern that must be used for -- the query execution. -- -- <query-mapping> -- <query name='user-list' class='Samples.Model.User_Info'> -- <sql driver='mysql'> -- SELECT u.name, u.email FROM user AS u -- </sql> -- <sql driver='sqlite'> -- ... -- </sql> -- <sql-count driver='mysql'> -- SELECT COUNT(*) FROM user AS u -- </sql-count> -- </query> -- </query-mapping> -- -- The query contains basically two SQL patterns. The `sql` element represents -- the main SQL pattern. This is the SQL that is used by the `List` operation. -- In some cases, the result set returned by the query is limited to return only -- a maximum number of rows. This is often use in paginated lists. -- -- The `sql-count` element represents an SQL query to indicate the total number -- of elements if the SQL query was not limited. -- -- The `sql` and `sql-count` XML element can have an optional `driver` attribute. -- When defined, the attribute indicates the database driver name that is specific -- to the query. When empty or not defined, the SQL is not specific to a database driver. -- -- For each query, the Dynamo code generator generates a query definition instance which -- can be used in the Ada code to be able to use the query. Such instance is static and -- readonly and serves as a reference when using the query. For the above query, -- the Dynamo code generator generates: -- -- package Samples.User.Model is -- Query_User_List : constant ADO.Queries.Query_Definition_Access; -- private -- ... -- end Samples.User.Model; -- -- When a new query is added, the Dynamo code generator must be launched to update -- the generated Ada code. -- -- === Using Named Queries === -- In order to use a named query, it is necessary to create a query context instance -- and initialize it. The query context holds the information about the query definition -- as well as the parameters to execute the query. It provides a `Set_Query` and -- `Set_Count_Query` operation that allows to configure the named query to be executed. -- It also provides all the `Bind_Param` and `Add_Param` operations to allow giving the -- query parameters. -- -- with ADO.Sessions; -- with ADO.Queries; -- ... -- Session : ADO.Sessions.Session := Factory.Get_Session; -- Query : ADO.Queries.Context; -- Users : Samples.User.Model.User_Info_Vector; -- ... -- Query.Set_Query (Samples.User.Model.Query_User_List); -- Samples.User.Model.List (Users, Session, Query); -- -- To use the `sql-count` part of the query, you will use the `Set_Count_Query` -- with the same query definition. You will then create a query statement from the -- named query context and run the query. Since the query is expected to contain exactly -- one row, you can use the `Get_Result_Integer` to get the first row and column result. -- For example: -- -- Query.Set_Count_Query (Samples.User.Model.Query_User_List); -- ... -- Stmt : ADO.Statements.Query_Statement -- := Session.Create_Statement (Query); -- ... -- Stmt.Execute; -- ... -- Count : Natural := Stmt.Get_Result_Integer; -- -- You may also use the `ADO.Datasets.Get_Count` operation which simplifies these steps -- in: -- -- Query.Set_Count_Query (Samples.User.Model.Query_User_List); -- ... -- Count : Natural := ADO.Datasets.Get_Count (Session, Query); -- package ADO.Queries is -- Exception raised when a query does not exist or is empty. Query_Error : exception; type Query_Index is new Natural; type File_Index is new Natural; type Query_File is limited private; type Query_File_Access is access all Query_File; type Query_Definition is limited private; type Query_Definition_Access is access all Query_Definition; type Query_Manager is limited new Ada.Finalization.Limited_Controlled with private; type Query_Manager_Access is access all Query_Manager; -- ------------------------------ -- Query Context -- ------------------------------ -- The <b>Context</b> type holds the necessary information to build and execute -- a query whose SQL pattern is defined in an XML query file. type Context is new ADO.SQL.Query with private; -- Clear the query object. overriding procedure Clear (Query : in out Context); -- Set the query definition which identifies the SQL query to execute. -- The query is represented by the <tt>sql</tt> XML entry. procedure Set_Query (Into : in out Context; Query : in Query_Definition_Access); -- Set the query count definition which identifies the SQL query to execute. -- The query count is represented by the <tt>sql-count</tt> XML entry. procedure Set_Count_Query (Into : in out Context; Query : in Query_Definition_Access); -- Set the query to execute as SQL statement. procedure Set_SQL (Into : in out Context; SQL : in String); procedure Set_Query (Into : in out Context; Name : in String); -- Set the limit for the SQL query. procedure Set_Limit (Into : in out Context; First : in Natural; Last : in Natural); -- Get the first row index. function Get_First_Row_Index (From : in Context) return Natural; -- Get the last row index. function Get_Last_Row_Index (From : in Context) return Natural; -- Get the maximum number of rows that the SQL query can return. -- This operation uses the <b>sql-count</b> query. function Get_Max_Row_Count (From : in Context) return Natural; -- Get the SQL query that correspond to the query context. function Get_SQL (From : in Context; Manager : in Query_Manager'Class) return String; function Get_SQL (From : in Query_Definition_Access; Manager : in Query_Manager; Use_Count : in Boolean) return String; type Static_Loader_Access is access function (Name : in String) return access constant String; -- Set a static query loader to load SQL queries. procedure Set_Query_Loader (Manager : in out Query_Manager; Loader : in Static_Loader_Access); private subtype Driver_Index is ADO.Configs.Driver_Index; -- ------------------------------ -- Query Definition -- ------------------------------ -- The <b>Query_Definition</b> holds the SQL query pattern which is defined -- in an XML query file. The query is identified by a name and a given XML -- query file can contain several queries. The Dynamo generator generates -- one instance of <b>Query_Definition</b> for each query defined in the XML -- file. The XML file is loaded during application initialization (or later) -- to get the SQL query pattern. Multi-thread concurrency is achieved by -- the Query_Info_Ref atomic reference. type Query_Definition is limited record -- The query name. Name : Util.Strings.Name_Access; -- The query file in which the query is defined. File : Query_File_Access; -- The next query defined in the query file. Next : Query_Definition_Access; -- The SQL query pattern (initialized when reading the XML query file). -- Query : Query_Info_Ref_Access; Query : Query_Index := 0; end record; -- ------------------------------ -- Query File -- ------------------------------ -- The <b>Query_File</b> describes the SQL queries associated and loaded from -- a given XML query file. The Dynamo generator generates one instance of -- <b>Query_File</b> for each XML query file that it has read. The Path, -- Sha1_Map, Queries and Next are initialized statically by the generator (during -- package elaboration). type Query_File is limited record -- Query relative path name Name : Util.Strings.Name_Access; -- The SHA1 hash of the query map section. Sha1_Map : Util.Strings.Name_Access; -- The first query defined for that file. Queries : Query_Definition_Access; -- The next XML query file registered in the application. Next : Query_File_Access; -- The unique file index. File : File_Index := 0; end record; type Context is new ADO.SQL.Query with record First : Natural := 0; Last : Natural := 0; Last_Index : Natural := 0; Max_Row_Count : Natural := 0; Query_Def : Query_Definition_Access := null; Is_Count : Boolean := False; end record; use Ada.Strings.Unbounded; -- SQL query pattern type Query_Pattern is limited record SQL : Ada.Strings.Unbounded.Unbounded_String; end record; type Query_Pattern_Array is array (Driver_Index) of Query_Pattern; type Query_Info is new Util.Refs.Ref_Entity with record Main_Query : Query_Pattern_Array; Count_Query : Query_Pattern_Array; end record; type Query_Info_Access is access all Query_Info; package Query_Info_Ref is new Util.Refs.References (Query_Info, Query_Info_Access); package Atomic_Query_Info_Ref is new Query_Info_Ref.IR.Atomic; type Query_Info_Ref_Access is access all Atomic_Query_Info_Ref.Atomic_Ref; subtype Query_Index_Table is Query_Index range 1 .. Query_Index'Last; subtype File_Index_Table is File_Index range 1 .. File_Index'Last; type Query_File_Info is limited record -- Query absolute path name (after path resolution). Path : Ada.Strings.Unbounded.Unbounded_String; -- File File : Query_File_Access; -- Stamp when the query file will be checked. Next_Check : Ada.Calendar.Time; -- Stamp identifying the modification date of the query file. Last_Modified : Ada.Calendar.Time; end record; -- Find the query with the given name. -- Returns the query definition that matches the name or null if there is none function Find_Query (File : in Query_File_Info; Name : in String) return Query_Definition_Access; type Query_Table is array (Query_Index_Table range <>) of Query_Info_Ref.Ref; type Query_Table_Access is access all Query_Table; type File_Table is array (File_Index_Table range <>) of Query_File_Info; type File_Table_Access is access all File_Table; type Query_Manager is limited new Ada.Finalization.Limited_Controlled with record Driver : Driver_Index := Driver_Index'First; Queries : Query_Table_Access; Files : File_Table_Access; Loader : Static_Loader_Access; end record; overriding procedure Finalize (Manager : in out Query_Manager); end ADO.Queries;
reznikmm/matreshka
Ada
3,647
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 XML.DOM.Attributes; package ODF.DOM.Attributes.Style.Adjustment is type ODF_Style_Adjustment is new XML.DOM.Attributes.DOM_Attribute with private; private type ODF_Style_Adjustment is new XML.DOM.Attributes.DOM_Attribute with null record; end ODF.DOM.Attributes.Style.Adjustment;
alexcamposruiz/dds-requestreply
Ada
7,080
adb
with Ada.Command_Line; with Ada.Text_IO; use Ada.Text_IO; with DDS.DomainParticipant; with DDS.DomainParticipantFactory; with Primes.PrimeNumberRequester; with Primes_IDL_File.PrimeNumberRequest_TypeSupport; with RTIDDS.Config; procedure Primes.Requester_Main is use Primes_IDL_File; use DDS.DomainParticipant; use all type DDS.ReturnCode_T; Factory : constant DDS.DomainParticipantFactory.Ref_Access := DDS.DomainParticipantFactory.Get_Instance; procedure Requester_Shutdown (Participant : in out DDS.DomainParticipant.Ref_Access; Requester : in out PrimeNumberRequester.Ref_Access; Request : in out PrimeNumberRequest_Access) is begin PrimeNumberRequest_TypeSupport.Delete_Data (Request); PrimeNumberRequester.Delete (Requester); if Participant /= null then Participant.Delete_Contained_Entities; end if; Factory.Delete_Participant (Participant); Factory.Finalize_Instance; end; procedure Requester_Main (N : DDS.long ; Primes_Per_Reply : DDS.long ; Domain_Id : DDS.DomainId_T) is Retcode : DDS.ReturnCode_T; Replies : aliased PrimeNumberReply_Seq.Sequence; Info_Seq : aliased DDS.SampleInfo_Seq.Sequence; Participant : DDS.DomainParticipant.Ref_Access; Requester : PrimeNumberRequester.Ref_Access; Request : PrimeNumberRequest_Access := PrimeNumberRequest_TypeSupport.Create_Data; MAX_WAIT : constant DDS.Duration_T := DDS.To_Duration_T (20.0); In_Progress : Boolean := False; use type PrimeNumberRequester.Ref_Access; use PrimeNumberReply_Seq; use DDS.SampleInfo_Seq; begin -- Create the participant Participant := Factory.Create_Participant (Domain_Id); if Participant = null then Put_Line (Standard_Error, "create_participant error"); Ada.Command_Line.Set_Exit_Status (ADa.Command_Line.Failure); return; end if; -- Create the requester with that participant, and a QoS profile -- defined in USER_QOS_PROFILES.xml -- Requester := PrimeNumberRequester.Create (Participant => Participant, Service_Name => Service_Name, Qos_Library_Name => Qos_Library_Name, Qos_Profile_Name => Qos_Profile_Name); if Requester = null then Put_Line (Standard_Error, "create requester error"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); Requester_Shutdown (Participant, Requester, Request); return; end if; Request := PrimeNumberRequest_TypeSupport.Create_Data; if Request = null then Put_Line (Standard_Error, "Create data error"); ADa.Command_Line.Set_Exit_Status (ADa.Command_Line.Failure); Requester_Shutdown (Participant, Requester, Request); return; end if; Request.N := N; Request.Primes_Per_Reply := Primes_Per_Reply; Retcode := Requester.Send_Request (Request.all); if Retcode /= DDS.RETCODE_OK then Put_Line (Standard_Error, "send_request error:" & Retcode'Img ); Ada.Command_Line.Set_Exit_Status (ADa.Command_Line.Failure); Requester_Shutdown (Participant, Requester, Request); return; end if; Retcode := Requester.Receive_Replies (Replies => Replies'Unrestricted_Access, Sample_Info => Info_Seq'Unrestricted_Access, Min_Reply_Count => 1, Max_Reply_Count => DDS.LENGTH_UNLIMITED, Timeout => MAX_WAIT); In_Progress := True; while In_Progress and then (Retcode = DDS.RETCODE_OK)loop Put_Line ("("); for I in 1 .. Get_Length (Replies'Unrestricted_Access) loop declare Reply : constant PrimeNumberReply_Access := Get_Reference (Replies'Unrestricted_Access, I); Info : constant DDS.SampleInfo_Access := Get_Reference (Info_Seq'Unrestricted_Access, I); begin if (Info.Valid_Data) then for Prime_Number of Reply.Primes loop Put (Prime_Number.all'Img); end loop; end if; if Reply.Status /= REPLY_IN_PROGRESS then In_Progress := False; if Reply.Status = REPLY_ERROR then Put_Line (Standard_Error, "Error in Replier"); elsif Reply.Status = REPLY_COMPLETED then Put_Line ("DONE"); end if; end if; Put_Line (")"); end; end loop; -- Return the loan to the middleware Requester.Return_Loan (Replies, Info_Seq); if In_Progress then Retcode := Requester.Receive_Replies (Replies => Replies'Unrestricted_Access, Sample_Info => Info_Seq'Unrestricted_Access, Min_Reply_Count => 1, Max_Reply_Count => DDS.LENGTH_UNLIMITED, Timeout => MAX_WAIT); end if; end loop; if Retcode /= DDS.RETCODE_OK then if (Retcode = DDS.RETCODE_TIMEOUT) then Put_Line (Standard_Error, "Timed out waiting for prime numbers"); else Put_Line (Standard_Error, "Error receiving replies" & Retcode'Img); end if; end if; Requester_Shutdown (Participant, Requester, Request); end; Domain_Id : DDS.DomainId_T := 0; N : DDS.long; Primes_Per_Reply : DDS.long := 5; begin if Ada.Command_Line.Argument_Count < 1 then Put_Line ("PrimeNumberRequester:"); Put_Line ("Sends a request to calculate the prime numbers <= n"); Put_Line ("Parameters: <n> [<primes_per_reply> = 5] [<domain_id> = 0]"); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); return; end if; N := DDS.Integer'Value (Ada.Command_Line.Argument (1)); if Ada.Command_Line.Argument_Count < 1 then Primes_Per_Reply := DDS.Integer'Value (Ada.Command_Line.Argument (2)); end if; if Ada.Command_Line.Argument_Count < 2 then Domain_Id := DDS.DomainId_T'Value (Ada.Command_Line.Argument (3)); end if; RTIDDS.Config.Logger.Get_Instance.Set_Verbosity (RTIDDS.Config.VERBOSITY_WARNING); -- Uncomment this to turn on additional logging -- RTIDDS.Config.Logger.Get_Instance.Set_Verbosity (RTIDDS.Config.VERBOSITY_ERROR); Put_Line ("PrimeNumberRequester: Sending a request to calculate the " & "prime numbers " & N'Img & " in sequences of " & Primes_Per_Reply'Img & " or less elements." & "(on domain " & Domain_Id'Img & ")" ); Requester_Main (N, Primes_Per_Reply, Domain_Id); end;
AdaCore/gpr
Ada
11,370
adb
-- -- Copyright (C) 2019-2023, AdaCore -- -- SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception -- package body GPR2.Project.Attribute.Set is type Iterator is new Attribute_Iterator.Forward_Iterator with record Name : Optional_Attribute_Id; Index : Attribute_Index.Object; At_Pos : Unit_Index := No_Index; Set : access Set.Map; With_Defaults : Boolean := False; end record; overriding function First (Iter : Iterator) return Cursor; overriding function Next (Iter : Iterator; Position : Cursor) return Cursor; function Is_Matching (Iter : Iterator'Class; Position : Cursor) return Boolean with Pre => Has_Element (Position); -- Returns True if the current Position is matching the Iterator ----------- -- Clear -- ----------- procedure Clear (Self : in out Object) is begin Self.Attributes.Clear; Self.Length := 0; end Clear; ------------------------ -- Constant_Reference -- ------------------------ function Constant_Reference (Self : aliased Object; Position : Cursor) return Constant_Reference_Type is Ref : Set_Attribute.Constant_Reference_Type renames Self.Attributes.Constant_Reference (Position.CM).Constant_Reference (Position.CA); begin return Constant_Reference_Type' (Attribute => Ref.Element.all'Unrestricted_Access, Ref => Ref); end Constant_Reference; -------------- -- Contains -- -------------- function Contains (Self : Object; Name : Attribute_Id; Index : Attribute_Index.Object := Attribute_Index.Undefined; At_Pos : Unit_Index := No_Index) return Boolean is Position : constant Cursor := Self.Find (Name, Index, At_Pos); begin return Has_Element (Position); end Contains; function Contains (Self : Object; Attribute : Project.Attribute.Object) return Boolean is begin return Self.Contains (Attribute.Name.Id.Attr, Attribute.Index, At_Pos_Or (Source_Reference.Value.Object (Attribute.Index), 0)); end Contains; ------------- -- Element -- ------------- function Element (Position : Cursor) return Attribute.Object is begin return Set_Attribute.Element (Position.CA); end Element; function Element (Self : Object; Name : Attribute_Id; Index : Attribute_Index.Object := Attribute_Index.Undefined; At_Pos : Unit_Index := No_Index) return Attribute.Object is Position : constant Cursor := Self.Find (Name, Index, At_Pos); begin if Set_Attribute.Has_Element (Position.CA) then return Element (Position); else return Project.Attribute.Undefined; end if; end Element; ------------ -- Filter -- ------------ function Filter (Self : Object; Name : Optional_Attribute_Id := No_Attribute; Index : Attribute_Index.Object := Attribute_Index.Undefined; At_Pos : Unit_Index := No_Index) return Object is begin if Name = No_Attribute and then not Index.Is_Defined then return Self; end if; declare Result : Object; begin if Name = No_Attribute then for C in Self.Iterate (Name, Index, At_Pos) loop Result.Insert (Element (C)); end loop; return Result; end if; -- If Name is defined we can use fast search for the attributes declare C : constant Set.Cursor := Self.Attributes.Find (Name); begin if not Set.Has_Element (C) then -- Result is empty here return Result; end if; declare Item : constant Set.Constant_Reference_Type := Self.Attributes (C); CI : Set_Attribute.Cursor; begin if not Index.Is_Defined then -- All indexes Result.Attributes.Insert (Name, Item); Result.Length := Item.Length; return Result; end if; -- Specific index only CI := Item.Find (Create (Index, At_Pos)); if Set_Attribute.Has_Element (CI) then Result.Insert (Set_Attribute.Element (CI)); return Result; end if; CI := Item.Find (Create (Attribute_Index.Any, At_Pos)); if Set_Attribute.Has_Element (CI) then Result.Insert (Set_Attribute.Element (CI)); return Result; end if; end; end; return Result; end; end Filter; ---------- -- Find -- ---------- function Find (Self : Object; Name : Attribute_Id; Index : Attribute_Index.Object := Attribute_Index.Undefined; At_Pos : Unit_Index := No_Index) return Cursor is Result : Cursor := (CM => Self.Attributes.Find (Name), CA => Set_Attribute.No_Element); begin if Set.Has_Element (Result.CM) then -- If we have an attribute in the bucket let's check if the index -- is case sensitive or not. Result.CA := Self.Attributes.Constant_Reference (Result.CM).Find (Create (Index, Default_At_Pos => At_Pos)); if not Set_Attribute.Has_Element (Result.CA) then Result.CA := Self.Attributes.Constant_Reference (Result.CM).Find (Create (Attribute_Index.Any, 0)); end if; end if; return Result; end Find; function Find (Self : Object; Attribute : Project.Attribute.Object) return Cursor is begin return Self.Find (Attribute.Name.Id.Attr, Attribute.Index, At_Pos_Or (Source_Reference.Value.Object (Attribute.Index), 0)); end Find; ----------- -- First -- ----------- overriding function First (Iter : Iterator) return Cursor is Position : Cursor := (CM => Iter.Set.First, CA => Set_Attribute.No_Element); begin if Set.Has_Element (Position.CM) then Position.CA := Iter.Set.Constant_Reference (Position.CM).First; end if; if Has_Element (Position) and then not Is_Matching (Iter, Position) then return Next (Iter, Position); else return Position; end if; end First; ----------------- -- Has_Element -- ----------------- function Has_Element (Position : Cursor) return Boolean is begin return Set.Has_Element (Position.CM) and then Set_Attribute.Has_Element (Position.CA); end Has_Element; ------------- -- Include -- ------------- procedure Include (Self : in out Object; Attribute : Project.Attribute.Object) is Position : Set.Cursor; CSA : Set_Attribute.Cursor; Inserted : Boolean; begin Self.Attributes.Insert (Attribute.Name.Id.Attr, Set_Attribute.Empty_Map, Position, Inserted); Self.Attributes (Position).Insert (Attribute.Case_Aware_Index, Attribute, CSA, Inserted); if Inserted then Self.Length := Self.Length + 1; else Self.Attributes (Position) (CSA) := Attribute; end if; end Include; ------------ -- Insert -- ------------ procedure Insert (Self : in out Object; Attribute : Project.Attribute.Object) is Position : Set.Cursor; Inserted : Boolean; begin Self.Attributes.Insert (Attribute.Name.Id.Attr, Set_Attribute.Empty_Map, Position, Inserted); Self.Attributes (Position).Insert (Attribute.Case_Aware_Index, Attribute); Self.Length := Self.Length + 1; end Insert; -------------- -- Is_Empty -- -------------- function Is_Empty (Self : Object) return Boolean is begin return Self.Length = 0; end Is_Empty; ----------------- -- Is_Matching -- ----------------- function Is_Matching (Iter : Iterator'Class; Position : Cursor) return Boolean is begin if Iter.Name = No_Attribute and then Iter.With_Defaults then return True; else declare A : Set_Attribute.Constant_Reference_Type renames Iter.Set.Constant_Reference (Position.CM).Element.Constant_Reference (Position.CA); begin return (Iter.Name = No_Attribute or else A.Name.Id.Attr = Iter.Name) and then (not Iter.Index.Is_Defined or else A.Index = Iter.Index) and then (Iter.With_Defaults or else not A.Is_Default); end; end if; end Is_Matching; ------------- -- Iterate -- ------------- function Iterate (Self : Object; Name : Optional_Attribute_Id := No_Attribute; Index : Attribute_Index.Object := Attribute_Index.Undefined; At_Pos : Unit_Index := No_Index; With_Defaults : Boolean := True) return Attribute_Iterator.Forward_Iterator'Class is begin return It : Iterator do It.Set := Self.Attributes'Unrestricted_Access; It.Name := Name; It.Index := Index; It.At_Pos := At_Pos; It.With_Defaults := With_Defaults; end return; end Iterate; ------------ -- Length -- ------------ function Length (Self : Object) return Containers.Count_Type is begin return Self.Length; end Length; ---------- -- Next -- ---------- overriding function Next (Iter : Iterator; Position : Cursor) return Cursor is procedure Next (Position : in out Cursor) with Post => Position'Old /= Position; -- Move Position to next element ---------- -- Next -- ---------- procedure Next (Position : in out Cursor) is begin Position.CA := Set_Attribute.Next (Position.CA); if not Set_Attribute.Has_Element (Position.CA) then Position.CM := Set.Next (Position.CM); if Set.Has_Element (Position.CM) then Position.CA := Iter.Set.Constant_Reference (Position.CM).First; else Position.CA := Set_Attribute.No_Element; end if; end if; end Next; Result : Cursor := Position; begin loop Next (Result); exit when not Has_Element (Result) or else Is_Matching (Iter, Result); end loop; return Result; end Next; --------------- -- Reference -- --------------- function Reference (Self : aliased in out Object; Position : Cursor) return Reference_Type is Ref : Set_Attribute.Reference_Type renames Self.Attributes.Reference (Position.CM).Reference (Position.CA); begin return Reference_Type' (Attribute => Ref.Element.all'Unrestricted_Access, Ref => Ref); end Reference; end GPR2.Project.Attribute.Set;
caqg/linux-home
Ada
50,830
adb
-- Abstract : -- -- see spec. -- -- Copyright (C) 2018 - 2020 Free Software Foundation, Inc. -- -- This library is free software; you can redistribute it and/or modify it -- under terms of the GNU General Public License as published by the Free -- Software Foundation; either version 3, or (at your option) any later -- version. This library is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- As a special exception under Section 7 of GPL version 3, you are granted -- additional permissions described in the GCC Runtime Library Exception, -- version 3.1, as published by the Free Software Foundation. pragma License (Modified_GPL); with Ada.Containers; with Ada.Exceptions; with Ada_Process_Actions; with System.Assertions; package body WisiToken.Parse.LR.McKenzie_Recover.Ada is use all type Ada_Process_Actions.Token_Enum_ID; -- token names use all type Semantic_Checks.Check_Status_Label; Descriptor : WisiToken.Descriptor renames Ada_Process_Actions.Descriptor; subtype Grammar_Token_ID_Set is WisiToken.Token_ID_Set (Descriptor.First_Terminal .. Descriptor.Last_Nonterminal); subtype Terminal_Token_ID_Set is WisiToken.Token_ID_Set (Descriptor.First_Terminal .. Descriptor.Last_Terminal); -- From ada.wy, all nonterms with a Match_Names check: -- -- nonterm <begin_name_token> <end_name_token> -- |-----------------------------|-------------------------|------------- -- accept_statement IDENTIFIER identifier_opt -- block_statement block_label_opt identifier_opt -- entry_body IDENTIFIER identifier_opt -- loop_statement block_label_opt identifier_opt -- package_body name name_opt -- package_specification name name_opt -- protected_body IDENTIFIER identifier_opt -- protected_type_declaration IDENTIFIER protected_definition -- single_protected_declaration IDENTIFIER protected_definition -- single_task_declaration IDENTIFIER identifier_opt -- subprogram_body subprogram_specification name_opt -- task_body IDENTIFIER identifier_opt -- task_type_declaration IDENTIFIER identifier_opt No_Statements_Nonterm_IDs : constant Grammar_Token_ID_Set := To_Token_ID_Set -- Nonterms that cannot contain a handled_sequence_of_statements -- (transitive). (Descriptor.First_Terminal, Descriptor.Last_Nonterminal, +package_specification_ID & (+protected_type_declaration_ID) & (+single_protected_declaration_ID) & (+single_task_declaration_ID) & (+task_type_declaration_ID)); End_Keyword_IDs : constant Terminal_Token_ID_Set := To_Token_ID_Set (Descriptor.First_Terminal, Descriptor.Last_Terminal, +CASE_ID & (+IF_ID) & (+LOOP_ID) & (+RECORD_ID) & (+RETURN_ID) & (+SELECT_ID)); procedure Handle_Check_Fail (Trace : in out WisiToken.Trace'Class; Lexer : access constant WisiToken.Lexer.Instance'Class; Parser_Label : in Natural; Parse_Table : in WisiToken.Parse.LR.Parse_Table; Terminals : in Base_Token_Arrays.Vector; Tree : in Syntax_Trees.Tree; Local_Config_Heap : in out Config_Heaps.Heap_Type; Config : in Configuration) with Pre => Config.Check_Status.Label /= Ok is procedure Put (Message : in String; Config : in Configuration) is begin Put (Message, Trace, Parser_Label, Terminals, Config); end Put; End_Name_Token : Recover_Token renames Config.Check_Status.End_Name; begin -- There is a top level exception handler in McKenzie_Recover; the -- user has no way to work around an exception. If we are trying to -- fix a particular use case, the trace messages will be enough. case Config.Check_Status.Label is when Ok => raise SAL.Programmer_Error; when Match_Names_Error => -- There are several cases: -- -- 0. User name error. The input looks like: -- -- "<begin_name_token> ... <end_name_token> ;" -- -- where the names do not match, because the user is changing them. -- -- The fix is to ignore the error. See -- test/ada_mode-recover_change_name.adb. -- -- 1. The mismatch indicates one or more missing 'end's. The input -- looks like: -- -- "<correct_begin_name_token> ... <bad_begin_name_token> ... <end_name_token> ;" -- -- where <correct_begin_name_token> matches <end_name_token>, but -- <bad_begin_name_token> does not, and the erroneous reduce has -- matched <bad_begin_name_token> with <end_name_token>. -- -- The fix is to insert one or more 'end ;' before <end_name_token>. -- See test_mckenzie_recover.adb Block_Match_Names_1, Extra_Name_2. -- -- 2. The mismatch indicates a missing block start. The input looks like: -- -- "<bad_begin_name_token> ... begin ... end <end_name_token> ;" -- -- where the matching begin name token has been deleted. -- -- The fix is to insert a matching block start before the 'begin'. -- See test/ada_mode-recover_deleted_procedure_1.adb -- -- -- It is not possible for the mismatch to indicate an extra 'end'; -- that would generate either a Missing_Name_Error, or a syntax -- error. -- -- To distinguish between case 0 and 1, we search the stack for -- <correct_begin_name_token>. If found, it's case 1, otherwise case -- 0 or 2. We cannot distinguish between 0 and 2 (without parsing -- ahead). -- -- If there is more than one missing 'end', a later recover operation -- will fix the others. For example, in test_mckenzie_recover -- Extra_Name_2, we get here on a second semantic check error. -- This case doesn't use Tree, and it can handle some virtual tokens. declare End_Name : constant String := Lexer.Buffer_Text (End_Name_Token.Name); Matching_Name_Index : SAL.Peek_Type := 3; -- start search before <end_name_token> begin Find_Matching_Name (Config, Lexer, End_Name, Matching_Name_Index, Case_Insensitive => True); if Matching_Name_Index = Config.Stack.Depth then -- case 0 or 2. if Ada_Process_Actions.Token_Enum_ID'(-Config.Error_Token.ID) in protected_body_ID | protected_type_declaration_ID | single_protected_declaration_ID | single_task_declaration_ID then -- Not case 2 return; end if; declare New_Config : Configuration := Config; begin -- These solutions must compete with 'ignore check fail', so give them the same cost. New_Config.Cost := New_Config.Cost + Parse_Table.McKenzie_Param.Ignore_Check_Fail; New_Config.Strategy_Counts (Language_Fix) := New_Config.Strategy_Counts (Language_Fix) + 1; New_Config.Error_Token.ID := Invalid_Token_ID; New_Config.Check_Status := (Label => Ok); case Ada_Process_Actions.Token_Enum_ID'(-Config.Error_Token.ID) is when block_statement_ID => Push_Back_Check (New_Config, (+SEMICOLON_ID, +identifier_opt_ID, +END_ID)); Insert (New_Config, +BEGIN_ID); when entry_body_ID => Push_Back_Check (New_Config, (+SEMICOLON_ID, +name_opt_ID, +END_ID, +handled_sequence_of_statements_ID)); Insert (New_Config, +BEGIN_ID); when loop_statement_ID => Push_Back_Check (New_Config, (+SEMICOLON_ID, +identifier_opt_ID, +LOOP_ID, +END_ID)); Insert (New_Config, +LOOP_ID); when package_body_ID => Push_Back_Check (New_Config, (+SEMICOLON_ID, +name_opt_ID, +END_ID)); if New_Config.Stack.Peek (1).Token.ID = +handled_sequence_of_statements_ID then Push_Back_Check (New_Config, (+handled_sequence_of_statements_ID, +BEGIN_ID)); end if; Push_Back_Check (New_Config, (1 => +declarative_part_opt_ID)); Insert (New_Config, (+PACKAGE_ID, +BODY_ID, +IDENTIFIER_ID, +IS_ID)); when package_specification_ID => Push_Back_Check (New_Config, (+name_opt_ID, +END_ID, +declarative_part_opt_ID)); if New_Config.Stack.Peek (1).Token.ID = +PRIVATE_ID then Push_Back_Check (New_Config, (+PRIVATE_ID, +declarative_part_opt_ID)); end if; Insert (New_Config, (+PACKAGE_ID, +IDENTIFIER_ID, +IS_ID)); when subprogram_body_ID => Push_Back_Check (New_Config, (+SEMICOLON_ID, +name_opt_ID, +END_ID, +handled_sequence_of_statements_ID, +BEGIN_ID, +declarative_part_opt_ID)); Insert (New_Config, (+PROCEDURE_ID, +IDENTIFIER_ID, +IS_ID)); when task_body_ID => Push_Back_Check (New_Config, (+SEMICOLON_ID, +name_opt_ID, +END_ID, +handled_sequence_of_statements_ID)); Insert (New_Config, +BEGIN_ID); when others => if Trace_McKenzie > Outline then Put ("Language_Fixes Match_Names_Error 2: unknown error token", Config); end if; return; end case; if Trace_McKenzie > Detail then Put ("Language_Fixes Match_Names_Error 2 " & Image (Config.Error_Token.ID, Descriptor), New_Config); end if; Local_Config_Heap.Add (New_Config); exception when Bad_Config => null; end; else -- Case 1. declare New_Config : Configuration := Config; begin New_Config.Error_Token.ID := Invalid_Token_ID; New_Config.Check_Status := (Label => Ok); New_Config.Strategy_Counts (Language_Fix) := New_Config.Strategy_Counts (Language_Fix) + 1; Push_Back_Check (New_Config, (+SEMICOLON_ID, (case Ada_Process_Actions.Token_Enum_ID'(-Config.Error_Token.ID) is when package_body_ID | package_specification_ID | subprogram_body_ID => +name_opt_ID, when protected_type_declaration_ID | single_protected_declaration_ID => +protected_definition_ID, when others => +identifier_opt_ID))); if New_Config.Stack.Peek.Token.Min_Terminal_Index = Invalid_Token_Index then -- 'end' is on top of stack. We want to set Current_Shared_Token to -- 'end'; we can't if it has an invalid index (which it has if it was -- pushed after a previous fix). -- -- We don't check earlier for Invalid_Indices, because we can handle -- other tokens having invalid indices. return; end if; Push_Back_Check (New_Config, +END_ID); -- We don't insert ';' here, because we may need to insert other -- stuff first; let Minimal_Complete_Actions handle it. Insert (New_Config, +END_ID); Local_Config_Heap.Add (New_Config); if Trace_McKenzie > Detail then Put ("Language_Fixes Match_Names_Error 1 " & Image (Config.Error_Token.ID, Descriptor), New_Config); end if; exception when Bad_Config => null; when E : System.Assertions.Assert_Failure => if Trace_McKenzie > Outline then Trace.Put_Line ("Match_Names_Error 1 " & Standard.Ada.Exceptions.Exception_Message (E) & " " & Image (Config.Error_Token.ID, Descriptor)); end if; end; end if; end; when Missing_Name_Error => -- 0. User name error. The input looks like: -- -- "<begin_name_token> ... <end_name_token> ;" -- -- where <end_name_token> is empty, because the user is changing it. -- -- There are two cases: -- -- 0a. The nonterm can contain a handled_sequence_of_statements; ie a subprogram or named block -- -- 0b. The nonterm cannot contain a handled_sequence_of_statements; -- ie a protected object or type declaration. -- -- The fix is to ignore the error. -- -- 1. missing 'begin' or extra 'end'. The stack looks like: -- -- "<begin_named_token> ... begin handled_sequence_of_statements end <end_name_token> ;" -- -- where the <end_name_token> is empty. See test_mckenzie_recover.adb -- Missing_Name_*, ada_mode-recover_15.adb. -- -- There are two subcases: -- -- 1a. The 'end <end_name_token> ;' is left over from editing, and -- should be deleted. Note that there could be an End_Keyword_IDs -- with that end instead of a name. -- -- 1b. There is a missing 'begin'. -- -- We can distinguish between 1a and 1b by looking for 'exception'; -- if it is present, it is more likely there is a missing 'begin'. -- However, 'exception' is contained by -- 'handled_sequence_of_statements' on the stack, so we have to look -- inside that using the syntax tree. -- -- We cannot distinguish between cases 0 and 1, other than by parsing -- ahead, except in case 0b. So we enqueue two solutions; 'ignore -- error' and either 'insert begin' or 'delete end;'. if not Valid_Tree_Indices (Config.Stack, SAL.Base_Peek_Type (Config.Check_Token_Count)) then -- Invalid tree indices happens when recover enqueues a config that -- contains tokens pushed during recover. The logic below depends on -- valid tree indices. return; end if; if No_Statements_Nonterm_IDs (Config.Error_Token.ID) then -- case 0b. -- test/ada_mode.ads return; end if; if Syntax_Trees.Invalid_Node_Index = Tree.Find_Child (Config.Stack.Peek (4).Tree_Index, +EXCEPTION_ID) then -- 'exception' not found; case 1a - assume extra 'end [keyword] ;'; delete it. declare use Config_Op_Arrays; New_Config : Configuration := Config; Ops : Config_Op_Arrays.Vector renames New_Config.Ops; Stack : Recover_Stacks.Stack renames New_Config.Stack; End_Item : Recover_Stack_Item; -- 'end' keyword; position in stack varies with case Keyword_Item : Recover_Stack_Item; -- keyword after 'end'; may not be present Semicolon_Item : Recover_Stack_Item; -- semicolon after 'end' begin New_Config.Error_Token.ID := Invalid_Token_ID; New_Config.Check_Status := (Label => Ok); -- This is a guess, and sometimes deleting the error keyword is better, so -- give it a cost. New_Config.Cost := New_Config.Cost + 1; New_Config.Strategy_Counts (Language_Fix) := New_Config.Strategy_Counts (Language_Fix) + 1; case To_Token_Enum (Config.Error_Token.ID) is when block_statement_ID | package_body_ID | subprogram_body_ID | task_body_ID => Semicolon_Item := Stack.Peek (1); End_Item := Stack.Peek (3); Push_Back_Check (New_Config, (+SEMICOLON_ID, (if Config.Error_Token.ID in +block_statement_ID | +task_body_ID then +identifier_opt_ID else +name_opt_ID), +END_ID)); if New_Config.Stack.Peek (1).Token.ID = +handled_sequence_of_statements_ID then Undo_Reduce_Check (New_Config, Tree, (+handled_sequence_of_statements_ID, +sequence_of_statements_opt_ID)); end if; when package_specification_ID => Semicolon_Item := Stack.Peek (1); End_Item := Stack.Peek (3); Push_Back_Check (New_Config, (+SEMICOLON_ID, +name_opt_ID, +END_ID)); Undo_Reduce_Check (New_Config, Tree, +declarative_part_opt_ID); when loop_statement_ID => Semicolon_Item := Stack.Peek (1); Keyword_Item := Stack.Peek (3); End_Item := Stack.Peek (4); Push_Back_Check (New_Config, (+SEMICOLON_ID, +identifier_opt_ID, +LOOP_ID, +END_ID)); if New_Config.Stack.Peek (1).Token.ID = +handled_sequence_of_statements_ID then Undo_Reduce_Check (New_Config, Tree, (+handled_sequence_of_statements_ID, +sequence_of_statements_opt_ID)); end if; when others => if Trace_McKenzie > Outline then Put ("Language_Fixes unimplemented nonterm for Missing_Name_Error.", Config); end if; raise Bad_Config; end case; if not Has_Space (Ops, 3) then raise Bad_Config; end if; Append (Ops, (Delete, +END_ID, End_Item.Token.Min_Terminal_Index)); if Keyword_Item.Token.ID /= Invalid_Token_ID then Append (Ops, (Delete, Keyword_Item.Token.ID, Keyword_Item.Token.Min_Terminal_Index)); end if; -- We don't need to delete the identifier|name ; it is missing and therefor empty. Append (Ops, (Delete, +SEMICOLON_ID, Semicolon_Item.Token.Min_Terminal_Index)); New_Config.Current_Shared_Token := Config.Current_Shared_Token; -- After pushed_back SEMICOLON. Local_Config_Heap.Add (New_Config); if Trace_McKenzie > Detail then Put ("Language_Fixes Missing_Name_Error 1a " & Image (Config.Error_Token.ID, Descriptor), New_Config); end if; exception when Bad_Config => null; end; else -- 'exception' found; case 1b - assume missing 'begin'; insert it -- before 'handled_sequence_of_statements' declare New_Config : Configuration := Config; begin New_Config.Error_Token.ID := Invalid_Token_ID; New_Config.Check_Status := (Label => Ok); New_Config.Cost := New_Config.Cost + 1; New_Config.Strategy_Counts (Language_Fix) := New_Config.Strategy_Counts (Language_Fix) + 1; Push_Back_Check (New_Config, (+SEMICOLON_ID, (if Config.Error_Token.ID = +block_statement_ID then +identifier_opt_ID else +name_opt_ID), +END_ID, +handled_sequence_of_statements_ID)); Insert (New_Config, +BEGIN_ID); Local_Config_Heap.Add (New_Config); if Trace_McKenzie > Detail then Put ("Language_Fixes Missing_Name_Error 1b " & Image (Config.Error_Token.ID, Descriptor), New_Config); end if; exception when Bad_Config => null; end; end if; when Extra_Name_Error => -- The input looks like -- -- "<begin_name_token> ... block_label_opt begin ... end <end_name_token> ;" -- -- where the erroneous reduce matches the empty 'block_label_opt' -- with '<end_name_Token>'. -- -- 0. If a matching <begin_name_token> is found, this is not a -- plausible user name error (but we always allow 'ignore error'). If -- it is not found, the user could be adding/deleting names; ignore -- error is appropriate. In either case, enqueue other solutions. -- -- 1. There is at least one missing 'end' before 'begin'. See -- test_mckenzie_recover.adb Extra_Name_1, Extra_Name_2, -- Two_Missing_Ends. The solution is to insert 'end ;' before the -- 'begin'. -- -- 2. There is at least one missing 'end' after 'begin'. See -- test_mckenzie_recover.adb Extra_Name_3, Block_Match_Names_1. The -- solution is to insert 'end ;' before the 'end'. -- -- 3. There is an extra 'begin', before the 'begin'. See -- test/ada_mode-recover_block_name_mismatch.adb -- -- There is no reliable way to distinguish between 1 and 2, so we -- enqueue both solutions. See test/ada_mode-recover_exception_1.adb -- -- If there is more than one missing 'end', a later recover operation -- will fix the others. -- This case can handle Config.Error_Token.Virtual = True, and it doesn't use -- Tree. declare End_Name : constant String := Lexer.Buffer_Text (End_Name_Token.Name); Matching_Name_Index : SAL.Peek_Type := 3; -- start search before <end_name_token> Begin_Count : Integer; begin Find_Matching_Name (Config, Lexer, End_Name, Matching_Name_Index, Other_ID => +BEGIN_ID, Other_Count => Begin_Count, Case_Insensitive => True); if Matching_Name_Index = Config.Stack.Depth then -- No matching name found; ignore error is the only fix. return; end if; if Begin_Count = 1 then -- Case 1 or 2. declare New_Config : Configuration := Config; begin New_Config.Error_Token.ID := Invalid_Token_ID; New_Config.Check_Status := (Label => Ok); New_Config.Strategy_Counts (Language_Fix) := New_Config.Strategy_Counts (Language_Fix) + 1; -- Push_Back the failed reduce tokens. for I in 1 .. New_Config.Check_Token_Count loop Push_Back (New_Config); end loop; Insert (New_Config, +END_ID); -- Let Minimal_Complete_Actions handle (insert ';'). Local_Config_Heap.Add (New_Config); if Trace_McKenzie > Detail then Put ("Language_Fixes Extra_Name_Error 1 " & Image (Config.Error_Token.ID, Descriptor), New_Config); end if; exception when Bad_Config => null; end; -- Case 2 declare New_Config : Configuration := Config; begin New_Config.Error_Token.ID := Invalid_Token_ID; New_Config.Check_Status := (Label => Ok); New_Config.Strategy_Counts (Language_Fix) := New_Config.Strategy_Counts (Language_Fix) + 1; case Ada_Process_Actions.Token_Enum_ID'(-Config.Error_Token.ID) is when block_statement_ID => -- There is almost always an open block of some sort; not worth -- checking. Push_Back_Check (New_Config, (+SEMICOLON_ID, +identifier_opt_ID, +END_ID)); when loop_statement_ID => Push_Back_Check (New_Config, (+SEMICOLON_ID, +identifier_opt_ID, +LOOP_ID, +END_ID)); when others => if Trace_McKenzie > Outline then Put ("Language_Fixes Extra_Name_Error 2: unrecognized Error_Token", Config); end if; raise Bad_Config; end case; -- Let Minimal_Complete_Actions finish insert Insert (New_Config, +END_ID); Local_Config_Heap.Add (New_Config); if Trace_McKenzie > Detail then Put ("Language_Fixes Extra_Name_Error 2 " & Image (Config.Error_Token.ID, Descriptor), New_Config); end if; exception when Bad_Config => null; end; else -- Case 3. Delete the extra begin -- -- If the first begin was inserted by recovery; we actually want to -- delete the second begin. see test/ada_mode-recover_indent_4.adb declare New_Config : Configuration := Config; I : SAL.Peek_Type := 1; First_Begin_I : SAL.Peek_Type; Second_Begin_I : SAL.Peek_Type; begin loop if New_Config.Stack.Peek (I).Token.ID = +BEGIN_ID then Second_Begin_I := I; exit; end if; I := I + 1; end loop; loop I := I + 1; if New_Config.Stack.Peek (I).Token.ID = +BEGIN_ID then First_Begin_I := I; exit; end if; end loop; if New_Config.Stack.Peek (First_Begin_I).Token.Virtual then if New_Config.Stack.Peek (Second_Begin_I).Token.Virtual then -- nothing we can do. return; end if; -- Delete the second begin for I in 1 .. Second_Begin_I loop Push_Back (New_Config); end loop; pragma Assert (New_Config.Stack.Peek.Token.ID = +block_label_opt_ID); if New_Config.Stack.Peek.Token.Byte_Region = Null_Buffer_Region then -- block label is empty Push_Back (New_Config); Delete_Check (Terminals, New_Config, +BEGIN_ID); else Push_Back (New_Config); declare Index : WisiToken.Token_Index := New_Config.Current_Shared_Token; begin Delete_Check (Terminals, New_Config, Index, +IDENTIFIER_ID); Delete_Check (Terminals, New_Config, Index, +COLON_ID); Delete_Check (Terminals, New_Config, Index, +BEGIN_ID); end; end if; if Undo_Reduce_Valid (New_Config.Stack, Tree) then Undo_Reduce_Check (New_Config, Tree, +sequence_of_statements_ID); else Push_Back_Check (New_Config, +sequence_of_statements_ID); end if; Local_Config_Heap.Add (New_Config); if Trace_McKenzie > Detail then Put ("Language_Fixes Extra_Name_Error 3a " & Image (Config.Error_Token.ID, Descriptor), New_Config); end if; else -- Delete the first begin. We assume it is in a subprogram body, so -- we don't need to adjust anything else. for I in 1 .. First_Begin_I loop Push_Back (New_Config); end loop; Delete_Check (Terminals, New_Config, +BEGIN_ID); Local_Config_Heap.Add (New_Config); if Trace_McKenzie > Detail then Put ("Language_Fixes Extra_Name_Error 3b " & Image (Config.Error_Token.ID, Descriptor), New_Config); end if; end if; end; end if; end; end case; exception when Bad_Config => null; when System.Assertions.Assert_Failure => if Trace_McKenzie > Outline then Trace.Put_Line ("Language_Fixes Handle_Check_Fail Assert fail"); end if; end Handle_Check_Fail; procedure Handle_Parse_Error (Trace : in out WisiToken.Trace'Class; Lexer : access constant WisiToken.Lexer.Instance'Class; Parser_Label : in Natural; Parse_Table : in WisiToken.Parse.LR.Parse_Table; Terminals : in Base_Token_Arrays.Vector; Tree : in Syntax_Trees.Tree; Local_Config_Heap : in out Config_Heaps.Heap_Type; Config : in Configuration) with Pre => Config.Check_Status.Label = Ok is use Config_Op_Arrays; use Sorted_Insert_Delete_Arrays, Insert_Delete_Array_Refs; use all type Standard.Ada.Containers.Count_Type; procedure Put (Message : in String; Config : in Configuration) is begin Put (Message, Trace, Parser_Label, Terminals, Config); end Put; begin if Config.Error_Token.ID = +COLON_ID and Config.Stack.Peek.Token.ID = +IDENTIFIER_ID then -- Code looks like: -- -- begin ... <variable_identifier> : [aliased constant] <subtype_indication> ... -- -- compare to "missing begin"/"extra begin" case below. -- -- Assume the user copied a declaration with an initializer, and is -- converting it to a subprogram parameter; see -- ada_mode-recover_02.adb). Delete the ': [aliased constant] -- <subtype_indication>'. -- -- Note that if the user was converting to an assignment, the error -- would be on 'constant', not ':'. if Length (Config.Insert_Delete) > 0 and then Token_Index (Constant_Ref (Config.Insert_Delete, Last_Index (Config.Insert_Delete))) >= Config.Current_Shared_Token then -- Can't delete tokens from here return; end if; declare New_Config : Configuration := Config; Delete_Index : WisiToken.Token_Index := Config.Current_Shared_Token; begin Delete_Check (Terminals, New_Config, Delete_Index, +COLON_ID); if Terminals (Delete_Index).ID = +ALIASED_ID then Delete_Check (Terminals, New_Config, Delete_Index, +ALIASED_ID); end if; if Terminals (Delete_Index).ID = +CONSTANT_ID then Delete_Check (Terminals, New_Config, Delete_Index, +CONSTANT_ID); end if; if Terminals (Delete_Index).ID = +NOT_ID then Delete_Check (Terminals, New_Config, Delete_Index, +NOT_ID); end if; if Terminals (Delete_Index).ID = +NULL_ID then Delete_Check (Terminals, New_Config, Delete_Index, +NULL_ID); end if; if Terminals (Delete_Index).ID = +IDENTIFIER_ID then Delete_Check (Terminals, New_Config, Delete_Index, +IDENTIFIER_ID); -- There might be more to the subtype_indication; we'll let explore sort that out. Local_Config_Heap.Add (New_Config); if Trace_McKenzie > Detail then Put ("Language_Fixes variable decl as param", New_Config); end if; else -- Something else is going on, abandon this return; end if; end; elsif Config.Error_Token.ID = +DOT_ID then -- We've encountered a Selected_Component when we were expecting a -- simple IDENTIFIER or a name. If the name is preceded by 'end', then -- this similar to a semantic check Extra_Name_Error, and the -- solutions are similar. if Config.Stack.Peek.Token.ID = +IDENTIFIER_ID and Config.Stack.Peek (2).Token.ID = +END_ID then -- The input looks like one of: -- -- 1) "<begin_name_token_1> ... <begin_name_token_2> ... begin ... begin ... end <end_name_token_1> ;" -- -- 2) "<begin_name_token_1> ... begin ... declare ... begin ... end <end_name_token_1> ;" -- -- Case 1) is missing 'end <end_name_token_2> ;' between the -- 'begin's, so parsing expects <end_name_token_1> to match the -- second 'begin', which looks like an unnamed block. See -- test_mckenzie_recover Match_Selected_Component_1. 'declare ...' -- may _not_ be present on the second begin. The solution is to -- insert 'end ;' before the second 'begin'. -- -- Case 2) is missing 'end;' after the second 'begin'. See -- test_mckenzie_recover Match_Selected_Component_2. 'declare ...' -- may be absent on the second begin, or a name may be present. The -- solution is to insert 'end;' after the second 'begin' (ie before -- the last 'end'). -- -- Minimal_Complete_Actions does not handle this case well. -- -- Note that it's _not_ possible the user is just editing names; that -- would generate a semantic check fail, not a parse table error, -- since a "." would be permitted. declare Label : constant String := "selected_component 1"; New_Config_1 : Configuration := Config; New_Config_2 : Configuration; begin New_Config_1.Error_Token.ID := Invalid_Token_ID; New_Config_1.Strategy_Counts (Language_Fix) := New_Config_1.Strategy_Counts (Language_Fix) + 1; Push_Back_Check (New_Config_1, (+IDENTIFIER_ID, +END_ID)); if New_Config_1.Stack.Peek (1).Token.ID = +handled_sequence_of_statements_ID then Undo_Reduce_Check (New_Config_1, Tree, (+handled_sequence_of_statements_ID, +sequence_of_statements_opt_ID)); end if; case To_Token_Enum (New_Config_1.Stack.Peek (3).Token.ID) is when block_label_opt_ID => -- no 'declare'; either case 1 or 2 New_Config_2 := New_Config_1; New_Config_2.Strategy_Counts (Language_Fix) := New_Config_2.Strategy_Counts (Language_Fix) + 1; Insert (New_Config_2, +END_ID); -- Let Minimal_Complete_Actions finish insert. Push_Back_Check (New_Config_1, (+handled_sequence_of_statements_ID, +BEGIN_ID, +block_label_opt_ID)); Insert (New_Config_1, +END_ID); -- Let Minimal_Complete_Actions finish insert. Local_Config_Heap.Add (New_Config_1); Local_Config_Heap.Add (New_Config_2); when declarative_part_opt_ID => -- case 2 Insert (New_Config_1, +END_ID); Local_Config_Heap.Add (New_Config_1); when others => if Trace_McKenzie > Outline then Put ("Language_Fixes " & Label & " missing case " & Image (New_Config_1.Stack.Peek (3).Token.ID, Descriptor), Config); Trace.Put_Line ("... new_config stack: " & Image (New_Config_1.Stack, Descriptor)); end if; return; end case; if Trace_McKenzie > Detail then Put ("Language_Fixes " & Label, New_Config_1); if Length (New_Config_2.Ops) > 0 then Put ("Language_Fixes " & Label, New_Config_2); end if; end if; exception when Bad_Config => null; end; end if; elsif Config.Error_Token.ID = +IDENTIFIER_ID and Config.Stack.Peek.Token.ID = +END_ID then -- We've encountered an identifier after 'end' when expecting a -- keyword. See test/ada_mode-recover_26.adb. -- -- If a matching 'begin name' is found on the stack, the input looks like: -- -- 1) "<begin_name_token> ... begin ... <compound_statement_begin> ... end <end_name_token> ;" -- -- There is a missing 'end <compound_statement_id> ;' before the -- 'end'. We can get the ID to insert from Parse_Table -- Minimal_Complete_Actions. -- -- Minimal_Complete_Actions does not handle this case well; it -- ignores the name. declare End_ID_Actions : constant Minimal_Action_Arrays.Vector := Parse_Table.States (Config.Stack.Peek.State).Minimal_Complete_Actions; End_Name : constant String := Lexer.Buffer_Text (Config.Error_Token.Byte_Region); Matching_Name_Index : SAL.Peek_Type := 2; -- start search before 'end' begin Find_Matching_Name (Config, Lexer, End_Name, Matching_Name_Index, Case_Insensitive => True); if Matching_Name_Index < Config.Stack.Depth and then End_ID_Actions.Length = 1 and then End_ID_Actions (End_ID_Actions.First_Index).Verb = Shift then declare Label : constant String := "missing end keyword"; New_Config : Configuration := Config; begin New_Config.Error_Token.ID := Invalid_Token_ID; New_Config.Strategy_Counts (Language_Fix) := New_Config.Strategy_Counts (Language_Fix) + 1; Push_Back_Check (New_Config, +END_ID); -- Inserting the end keyword and semicolon here avoids the costs added by -- Insert_Minimal_Complete_Actions. Insert (New_Config, (+END_ID, End_ID_Actions (End_ID_Actions.First_Index).ID, +SEMICOLON_ID)); Local_Config_Heap.Add (New_Config); if Trace_McKenzie > Detail then Put ("Language_Fixes " & Label, New_Config); end if; exception when Bad_Config => null; end; end if; end; elsif To_Token_Enum (Config.Error_Token.ID) in CONSTANT_ID | IDENTIFIER_ID and Config.Stack.Peek.Token.ID = +COLON_ID then -- Code looks like: -- -- ... <subprogram|package start> begin ... <variable_name> : [constant] <type_name>; -- -- The variable_name looks like a block_label. compare to "variable decl as -- param" case above. -- -- 1) There is a missing 'end;' before the <variable_name>. See -- test/ada_mode-recover_25.adb. Minimal_Complete now handles this -- case, but we enqueue the same solution here at lower cost, so it -- can compete with the solution for case 2.. -- -- 2) There is an extra 'begin' before the <variable_name>. See -- test/ada_mode-recover_27.adb. -- -- FIXME: if there is a sequence_of_statements between the 'begin' -- and the error point, or declarations before the 'begin', this is -- either a copied variable declaration that the user is converting -- to an assignment (solution: delete ': type'), or a subprogram -- begin split in two (solution: insert 'declare' or 'end; procedure -- name'). Need test cases. declare New_Config_1 : Configuration := Config; New_Config_2 : Configuration; begin New_Config_1.Strategy_Counts (Language_Fix) := New_Config_1.Strategy_Counts (Language_Fix) + 1; Push_Back_Check (New_Config_1, (+COLON_ID, +IDENTIFIER_ID)); New_Config_2 := New_Config_1; Insert (New_Config_1, +END_ID); -- Let Minimal_Complete finish insert; that will add cost, so no cost here. Local_Config_Heap.Add (New_Config_1); if Trace_McKenzie > Detail then Put ("Language_Fixes missing begin", New_Config_1); end if; -- Case 2. Push_Back_Check (New_Config_2, +BEGIN_ID); if Undo_Reduce_Valid (New_Config_2.Stack, Tree) then Undo_Reduce_Check (New_Config_2, Tree, +declarative_part_opt_ID); else return; end if; Delete_Check (Terminals, New_Config_2, +BEGIN_ID); -- This is a guess, so add a cost. New_Config_2.Cost := New_Config_2.Cost + 1; Local_Config_Heap.Add (New_Config_2); if Trace_McKenzie > Detail then Put ("Language_Fixes extra begin", New_Config_2); end if; end; elsif Config.Error_Token.ID = +OR_ID and then Config.Stack.Peek.Token.ID = +expression_opt_ID then -- Code looks like: -- -- expr1 and expr2 or expr3 -- -- where 'expr1 and expr2' is in the expression on the stack. Missing -- left paren before expr1. See test/ada_mode-recover_20.adb. -- -- We could check for the presence of 'and' in expression_opt, but -- that requires a syntax tree. If the left paren doesn't help, this -- config will be dropped. declare New_Config : Configuration := Config; begin New_Config.Strategy_Counts (Language_Fix) := New_Config.Strategy_Counts (Language_Fix) + 1; Push_Back_Check (New_Config, +expression_opt_ID); Insert (New_Config, +LEFT_PAREN_ID); -- Minimal_Complete will add the matching right paren. Local_Config_Heap.Add (New_Config); if Trace_McKenzie > Detail then Put ("Language_Fixes and/or", New_Config); end if; end; elsif Config.Error_Token.ID = +TICK_1_ID then -- Editing "Put ('|');" => "Put ('|-');"; need to change ' to ". declare New_Config : Configuration := Config; begin New_Config.Strategy_Counts (Language_Fix) := New_Config.Strategy_Counts (Language_Fix) + 1; declare Index : WisiToken.Token_Index := New_Config.Current_Shared_Token; Start_Line : constant WisiToken.Line_Number_Type := Terminals (Config.Error_Token.Min_Terminal_Index).Line; begin Delete_Check (Terminals, New_Config, Index, +TICK_1_ID); -- increments index loop if Index > Terminals.Last_Index then raise Bad_Config; end if; if Terminals (Index).Line /= Start_Line then raise Bad_Config; end if; exit when Terminals (Index).ID = +TICK_1_ID; Delete (Terminals, New_Config, Index); -- increments index end loop; Delete_Check (Terminals, New_Config, Index, +TICK_1_ID); Insert (New_Config, Index, +STRING_LITERAL_ID); end; Local_Config_Heap.Add (New_Config); if Trace_McKenzie > Detail then Put ("Language_Fixes char_literal to string", New_Config); end if; end; end if; exception when Bad_Config => null; when System.Assertions.Assert_Failure => if Trace_McKenzie > Outline then Trace.Put_Line ("Language_Fixes Handle_Parse_Error assert fail"); end if; end Handle_Parse_Error; ---------- -- Public subprograms procedure Language_Fixes (Trace : in out WisiToken.Trace'Class; Lexer : access constant WisiToken.Lexer.Instance'Class; Parser_Label : in Natural; Parse_Table : in WisiToken.Parse.LR.Parse_Table; Terminals : in Base_Token_Arrays.Vector; Tree : in Syntax_Trees.Tree; Local_Config_Heap : in out Config_Heaps.Heap_Type; Config : in Configuration) is begin if Trace_McKenzie > Extra then Put ("Language_Fixes", Trace, Parser_Label, Terminals, Config); Put_Line (Trace, Parser_Label, "config stack: " & Image (Config.Stack, Descriptor)); end if; case Config.Check_Status.Label is when Ok => Handle_Parse_Error (Trace, Lexer, Parser_Label, Parse_Table, Terminals, Tree, Local_Config_Heap, Config); when others => Handle_Check_Fail (Trace, Lexer, Parser_Label, Parse_Table, Terminals, Tree, Local_Config_Heap, Config); end case; end Language_Fixes; procedure Matching_Begin_Tokens (Tokens : in Token_ID_Array_1_3; Config : in Configuration; Matching_Tokens : out Token_ID_Arrays.Vector; Forbid_Minimal_Complete : out Boolean) is use Ada_Process_Actions; use Token_ID_Arrays; function Matching_Begin_For_End (Next_Index : in Positive) return Token_ID_Arrays.Vector is begin return Result : Token_ID_Arrays.Vector do if Tokens (Next_Index) = Invalid_Token_ID then -- Better to delete 'end' Result := Empty_Vector; else case To_Token_Enum (Tokens (Next_Index)) is when CASE_ID | IF_ID | LOOP_ID | RETURN_ID | SELECT_ID => Result := To_Vector (Tokens (Next_Index)); when IDENTIFIER_ID => if Tokens (Next_Index + 1) /= Invalid_Token_ID and then To_Token_Enum (Tokens (Next_Index + 1)) = DOT_ID then Result := To_Vector ((+PACKAGE_ID, +BODY_ID, +IDENTIFIER_ID, +IS_ID)); -- package body else Result := To_Vector ((+IDENTIFIER_ID, +COLON_ID, +BEGIN_ID)); -- named block begin end if; when SEMICOLON_ID => Result := To_Vector (+BEGIN_ID); when others => null; end case; end if; end return; end Matching_Begin_For_End; begin if Config.Stack.Depth > 0 and then Config.Stack.Peek.Token.ID = +END_ID then Matching_Tokens := Matching_Begin_For_End (1); else case To_Token_Enum (Tokens (1)) is when END_ID => Matching_Tokens := Matching_Begin_For_End (2); when ELSE_ID | ELSIF_ID | THEN_ID => Matching_Tokens := To_Vector (+IF_ID); when EXCEPTION_ID => Matching_Tokens := To_Vector (+BEGIN_ID); -- We don't return LEFT_PAREN for RIGHT_PAREN; better to delete it. when WHEN_ID => Matching_Tokens := To_Vector ((+CASE_ID, +IDENTIFIER_ID, +IS_ID)); when others => null; end case; end if; if Config.Stack.Peek.Token.ID = +END_ID and ((Tokens (1) = +IDENTIFIER_ID and (Tokens (2) /= Invalid_Token_ID and then -Tokens (2) in DOT_ID | SEMICOLON_ID)) or End_Keyword_IDs (Tokens (1))) then Forbid_Minimal_Complete := True; else Forbid_Minimal_Complete := False; end if; end Matching_Begin_Tokens; function String_ID_Set (Descriptor : in WisiToken.Descriptor; String_Literal_ID : in Token_ID) return Token_ID_Set is use Ada_Process_Actions; begin -- Character literal can be part of a string primary, so the nonterms -- are independent of String_Literal_ID. return Result : Token_ID_Set (Descriptor.First_Terminal .. Descriptor.Last_Nonterminal) := (others => False) do Result (String_Literal_ID) := True; Result (+name_ID) := True; Result (+primary_ID) := True; Result (+factor_ID) := True; Result (+term_ID) := True; Result (+term_list_ID) := True; Result (+simple_expression_ID) := True; Result (+relation_ID) := True; Result (+expression_ID) := True; end return; end String_ID_Set; end WisiToken.Parse.LR.McKenzie_Recover.Ada; -- Local Variables: -- ada-case-strict: nil -- End:
sungyeon/drake
Ada
264
adb
procedure Ada.Unchecked_Deallocate_Subpool ( Subpool : in out System.Storage_Pools.Subpools.Subpool_Handle) is pragma Suppress (All_Checks); begin System.Storage_Pools.Subpools.Unchecked_Deallocate_Subpool (Subpool); end Ada.Unchecked_Deallocate_Subpool;
reznikmm/matreshka
Ada
5,963
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- XML Processor -- -- -- -- 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$ ------------------------------------------------------------------------------ with Matreshka.XML_Schema.AST.Objects; with Ada.Containers.Hashed_Maps; with Ada.Unchecked_Deallocation; package body Matreshka.XML_Schema.Named_Maps is ------------ -- Append -- ------------ procedure Append (Self : in out Named_Map; Item : Matreshka.XML_Schema.AST.Object_Access) is use type League.Strings.Universal_String; Key : constant League.Strings.Universal_String := Item.Get_Name & Item.Get_Target_Namespace; begin Self.Map.Insert (Key => Key, New_Item => Item); end Append; ----------------- -- Dereference -- ----------------- procedure Dereference (Self : in out Named_Map_Access) is procedure Free is new Ada.Unchecked_Deallocation (Named_Map'Class, Named_Map_Access); begin if Matreshka.Atomics.Counters.Decrement (Self.Counter) then Free (Self); end if; end Dereference; ---------- -- Item -- ---------- function Item (Self : in out Named_Map; Index : Positive) return Matreshka.XML_Schema.AST.Object_Access is begin if Self.Last_Cursor = 0 or Self.Last_Cursor + 1 /= Index then Self.Cursor := Self.Map.First; Self.Last_Cursor := 1; for J in 2 .. Index loop Object_Maps.Next (Self.Cursor); Self.Last_Cursor := Self.Last_Cursor + 1; end loop; else Object_Maps.Next (Self.Cursor); Self.Last_Cursor := Self.Last_Cursor + 1; end if; return Object_Maps.Element (Self.Cursor); end Item; ------------------ -- Item_By_Name -- ------------------ function Item_By_Name (Self : Named_Map; Name : League.Strings.Universal_String; Namespace : League.Strings.Universal_String) return Matreshka.XML_Schema.AST.Object_Access is use type League.Strings.Universal_String; Key : constant League.Strings.Universal_String := Name & Namespace; Cursor : Object_Maps.Cursor; begin Cursor := Self.Map.Find (Key => Key); if Object_Maps.Has_Element (Position => Cursor) then return Object_Maps.Element (Cursor); else return null; end if; end Item_By_Name; ------------ -- Length -- ------------ function Length (Self : Named_Map) return Natural is begin return Natural (Self.Map.Length); end Length; --------------- -- Reference -- --------------- procedure Reference (Self : Named_Map_Access) is begin Matreshka.Atomics.Counters.Increment (Self.Counter); end Reference; end Matreshka.XML_Schema.Named_Maps;
AdaCore/gpr
Ada
182
ads
package p1_2 is function p1_2_0 (Item : Integer) return Integer; function p1_2_1 (Item : Integer) return Integer; function p1_2_2 (Item : Integer) return Integer; end p1_2;
stcarrez/ada-util
Ada
5,813
adb
----------------------------------------------------------------------- -- util-events-timers-tests -- Unit tests for timers -- Copyright (C) 2017, 2019 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.Test_Caller; package body Util.Events.Timers.Tests is use Util.Tests; use type Ada.Real_Time.Time; package Caller is new Util.Test_Caller (Test, "Events.Timers"); procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is begin Caller.Add_Test (Suite, "Test Util.Events.Timers.Is_Scheduled", Test_Empty_Timer'Access); Caller.Add_Test (Suite, "Test Util.Events.Timers.Process", Test_Timer_Event'Access); Caller.Add_Test (Suite, "Test Util.Events.Timers.Repeat", Test_Repeat_Timer'Access); Caller.Add_Test (Suite, "Test Util.Events.Timers.Repeat+Process", Test_Many_Timers'Access); end Add_Tests; overriding procedure Time_Handler (Sub : in out Test; Event : in out Timer_Ref'Class) is begin Sub.Count := Sub.Count + 1; if Sub.Repeat > 1 then Sub.Repeat := Sub.Repeat - 1; Event.Repeat (Ada.Real_Time.Milliseconds (1)); end if; end Time_Handler; -- ----------------------- -- Test empty timers. -- ----------------------- procedure Test_Empty_Timer (T : in out Test) is M : Timer_List; R : Timer_Ref; Deadline : Ada.Real_Time.Time; begin T.Assert (not R.Is_Scheduled, "Empty timer should not be scheduled"); T.Assert (R.Time_Of_Event = Ada.Real_Time.Time_Last, "Time_Of_Event returned invalid value"); R.Cancel; M.Process (Deadline); T.Assert (Deadline = Ada.Real_Time.Time_Last, "The Process operation returned invalid deadline"); end Test_Empty_Timer; procedure Test_Timer_Event (T : in out Test) is M : Timer_List; R : Timer_Ref; Start : constant Ada.Real_Time.Time := Ada.Real_Time.Clock; Deadline : Ada.Real_Time.Time; Now : Ada.Real_Time.Time; begin for Retry in 1 .. 10 loop M.Set_Timer (T'Unchecked_Access, R, Start + Ada.Real_Time.Milliseconds (10)); M.Process (Deadline); Now := Ada.Real_Time.Clock; exit when Now < Deadline; end loop; T.Assert (Now < Deadline, "The timer deadline is not correct"); delay until Deadline; M.Process (Deadline); Assert_Equals (T, 1, T.Count, "The timer handler was not called"); end Test_Timer_Event; -- ----------------------- -- Test repeating timers. -- ----------------------- procedure Test_Repeat_Timer (T : in out Test) is M : Timer_List; R : Timer_Ref; Start : constant Ada.Real_Time.Time := Ada.Real_Time.Clock; Deadline : Ada.Real_Time.Time; Now : Ada.Real_Time.Time; begin T.Count := 0; T.Repeat := 5; for Retry in 1 .. 10 loop M.Set_Timer (T'Unchecked_Access, R, Start + Ada.Real_Time.Milliseconds (10)); M.Process (Deadline); Now := Ada.Real_Time.Clock; exit when Now < Deadline; end loop; T.Assert (Now < Deadline, "The timer deadline is not correct"); loop delay until Deadline; M.Process (Deadline); exit when Deadline >= Now + Ada.Real_Time.Seconds (1); end loop; Assert_Equals (T, 5, T.Count, "The timer handler was not repeated"); end Test_Repeat_Timer; -- ----------------------- -- Test executing several timers. -- ----------------------- procedure Test_Many_Timers (T : in out Test) is Timer_Count : constant Positive := 30; type Timer_Ref_Array is array (1 .. Timer_Count) of Timer_Ref; type Test_Ref_Array is array (1 .. Timer_Count) of aliased Test; M : Timer_List; Start : constant Ada.Real_Time.Time := Ada.Real_Time.Clock; Deadline : Ada.Real_Time.Time; R : Timer_Ref_Array; D : Test_Ref_Array; Dt : Ada.Real_Time.Time_Span; Count : Natural := 0; begin for I in R'Range loop D (I).Count := 0; D (I).Repeat := 4; if I mod 2 = 0 then Dt := Ada.Real_Time.Milliseconds (40); else Dt := Ada.Real_Time.Milliseconds (20); end if; M.Set_Timer (D (I)'Unchecked_Access, R (I), Start + Dt); end loop; loop M.Process (Deadline); exit when Deadline >= Start + Ada.Real_Time.Seconds (10); Count := Count + 1; delay until Deadline; end loop; -- Depending on the load we can have different values for Count. T.Assert (Count <= 8, "Count of Process"); T.Assert (Count >= 2, "Count of Process"); for I in D'Range loop Util.Tests.Assert_Equals (T, 4, D (I).Count, "Invalid count for timer at " & Natural'Image (I) & " " & Natural'Image (Count)); end loop; end Test_Many_Timers; end Util.Events.Timers.Tests;
burratoo/Acton
Ada
10,919
adb
------------------------------------------------------------------------------------------ -- -- -- ACTON PROCESSOR SUPPORT PACKAGE -- -- -- -- ATMEL.AT91SAM7S.TWI -- -- -- -- Copyright (C) 2014-2021, Patrick Bernardi -- -- -- ------------------------------------------------------------------------------------------ with Ada.Unchecked_Conversion; with System.Address_To_Access_Conversions; with Atmel.AT91SAM7S.AIC; with Atmel.AT91SAM7S.PIO; with Atmel.AT91SAM7S.PMC; with System.Storage_Elements; use System.Storage_Elements; package body Atmel.AT91SAM7S.TWI is package Access_Buffer_Address is new System.Address_To_Access_Conversions (Unsigned_8); use Access_Buffer_Address; procedure Send_Message (To : in TWI_Device_Address; Internal_Address : in TWI_Internal_Address; Address_Size : in Internal_Device_Address_Range; Message : in Address; Message_Length : in Natural) is begin Two_Wire_Interface.Transmit_Data (With_Device => To, Internal_Address => Internal_Address, Address_Size => Address_Size, Data => Message, Data_Length => Message_Length, Direction => Write); Two_Wire_Interface.Wait_For_Transmission; end Send_Message; procedure Receive_Message (From : in TWI_Device_Address; Internal_Address : in TWI_Internal_Address; Address_Size : in Internal_Device_Address_Range; Message : in Address; Message_Length : in Natural) is begin Two_Wire_Interface.Transmit_Data (With_Device => From, Internal_Address => Internal_Address, Address_Size => Address_Size, Data => Message, Data_Length => Message_Length, Direction => Read); Two_Wire_Interface.Wait_For_Transmission; end Receive_Message; procedure Initialise_Interface (Clock_Divider : Clock_Divider_Type; Clock_Low_Divider : Unsigned_8; Clock_High_Divider : Unsigned_8) is begin Two_Wire_Interface.Initialise_Interface (Clock_Divider => Clock_Divider, Clock_Low_Divider => Clock_Low_Divider, Clock_High_Divider => Clock_High_Divider); end Initialise_Interface; protected body Two_Wire_Interface is procedure Initialise_Interface (Clock_Divider : Clock_Divider_Type; Clock_Low_Divider : Unsigned_8; Clock_High_Divider : Unsigned_8) is begin AIC.Interrupt_Disable_Command_Register.Interrupt := (P_TWI => Disable, others => No_Change); Interrupt_Disable_Register := (others => Disable); -- Turn on TWI clocks PMC.Peripheral_Clock_Enable_Register := (P_TWI => Enable, P_PIOA => Enable, others => No_Change); -- Set up pins PIO.Multi_Driver_Enable_Register := (IO_Line_A_TWI_Data => Enable, IO_Line_A_TWI_Clock => Enable, others => No_Change); PIO.PIO_Disable_Register := (IO_Line_A_TWI_Data => Disable, IO_Line_A_TWI_Clock => Disable, others => No_Change); PIO.Peripheral_A_Select_Register := (IO_Line_A_TWI_Data => PIO.Use_Peripheral, IO_Line_A_TWI_Clock => PIO.Use_Peripheral, others => PIO.No_Change); -- Setup TWI Hardware Control_Register := (Start => No, Stop => No, Master_Transfer_Enabled => False, Master_Transfer_Disabled => True, Software_Reset => True); Clock_Waveform_Generator_Register := (Clock_Low_Divider => Clock_Low_Divider, Clock_High_Divider => Clock_High_Divider, Clock_Divider => Clock_Divider); Control_Register := (Start => No, Stop => No, Master_Transfer_Enabled => True, Master_Transfer_Disabled => False, Software_Reset => False); -- Setup Interrupts AIC.Source_Mode_Register (P_TWI) := (Priority_Level => AIC.AIC_Interrupt_Priority'Last, Interrupt_Source => AIC.High_Level_Sensitive); AIC.Interrupt_Enable_Command_Register.Interrupt := (P_TWI => Enable, others => No_Change); Transfer_Completed := True; end Initialise_Interface; procedure Transmit_Data (With_Device : in TWI_Device_Address; Internal_Address : in TWI_Internal_Address; Address_Size : in Internal_Device_Address_Range; Data : in Address; Data_Length : in Natural; Direction : in Communication_Direction) is begin -- Setup the protected object for the transfer Transfer_Completed := False; Buffer := Data; Buffer_Length := Data_Length; -- Setup the TWI hardware for the transfer Master_Mode_Register := (Internal_Device_Address_Size => Address_Size, Master_Read_Direction => Direction, Device_Address => With_Device); if Address_Size > 0 then Internal_Address_Register.Internal_Address := Internal_Address; end if; -- Start the transfer -- Control_Register := -- (Start => Yes, -- Stop => No, -- Master_Transfer_Enabled => True, -- Master_Transfer_Disabled => False, -- Software_Reset => False); case Direction is when Read => Control_Register := (Start => Yes, Stop => No, Master_Transfer_Enabled => False, Master_Transfer_Disabled => False, Software_Reset => False); Interrupt_Enable_Register := (Receive_Holding_Register_Ready => Enable, Not_Acknowledged => Enable, others => No_Change); when Write => Transmit_Holding_Register.Data := To_Pointer (Buffer).all; Buffer := Buffer + 1; Buffer_Length := Buffer_Length - 1; Interrupt_Enable_Register := (Transmit_Holding_Register_Ready => Enable, -- Transmission_Completed => Enable, Not_Acknowledged => Enable, others => No_Change); end case; end Transmit_Data; entry Wait_For_Transmission when Transfer_Completed is begin null; end Wait_For_Transmission; procedure Interface_Handler is ST : constant Status_Register_Type := Status_Register; TWI_Status : constant Status_Register_Type := (ST and Interrupt_Mask_Register); begin if TWI_Status.Receive_Holding_Register_Ready then -- We have recieved a byte if Buffer_Length > 0 then To_Pointer (Buffer).all := Receive_Holding_Register.Data; Buffer := Buffer + 1; Buffer_Length := Buffer_Length - 1; if Buffer_Length = 1 then Control_Register := (Start => No, Stop => Yes, Master_Transfer_Enabled => False, Master_Transfer_Disabled => False, Software_Reset => False); elsif Buffer_Length = 0 then -- Recieve transfer complete Interrupt_Disable_Register := (others => Disable); Transfer_Completed := True; end if; elsif Buffer_Length = 0 then raise Program_Error; end if; elsif TWI_Status.Transmit_Holding_Register_Ready then if Buffer_Length > 0 then if Buffer_Length = 1 then Control_Register := (Start => No, Stop => Yes, Master_Transfer_Enabled => False, Master_Transfer_Disabled => False, Software_Reset => False); -- Interrupt_Disable_Register := -- (Transmit_Holding_Register_Ready => Disable, -- others => No_Change); end if; Transmit_Holding_Register.Data := To_Pointer (Buffer).all; Buffer := Buffer + 1; Buffer_Length := Buffer_Length - 1; else Transfer_Completed := True; Interrupt_Disable_Register := (Transmit_Holding_Register_Ready => Disable, others => No_Change); end if; -- elsif TWI_Status.Transmission_Completed then -- if Buffer_Length > 0 then -- raise Program_Error; -- end if; -- Transfer_Completed := True; -- Interrupt_Disable_Register := (others => Disable); end if; if TWI_Status.Not_Acknowledged then Transfer_Completed := True; Interrupt_Disable_Register := (others => Disable); -- raise Program_Error; end if; end Interface_Handler; end Two_Wire_Interface; function "and" (L, R : Status_Register_Type) return Status_Register_Type is function To_Register is new Ada.Unchecked_Conversion (Source => Status_Register_Type, Target => Register); function To_Status_Type is new Ada.Unchecked_Conversion (Source => Register, Target => Status_Register_Type); begin return To_Status_Type (To_Register (L) and To_Register (R)); end "and"; end Atmel.AT91SAM7S.TWI;
jscparker/math_packages
Ada
17,422
adb
with e_Derivs; with Ada.Numerics.Generic_Elementary_Functions; with Extended_Real; with Extended_Real.Elementary_Functions; with Extended_Real.IO; with Text_IO; use Text_IO; procedure e_deriv_tst_1 is type Real_8 is digits 15; package mth is new Ada.Numerics.Generic_Elementary_Functions (Real_8); use mth; package ext is new Extended_Real (Real_8); use ext; package fnc is new ext.Elementary_Functions (Sqrt, Log, Exp, Arcsin); use fnc; package eio is new ext.IO; -- extented IO use eio; subtype Real is e_Real; Max_Order_Of_Deriv : constant Positive := 40; package dif is new e_Derivs (Max_Order_Of_Deriv, Real, Real_8); use dif; w, Phase : Real := +1.0; Time, t : Real; FullDuration : constant Real := +1.0; No_Of_Steps : constant Integer := 100; DeltaT : Real := FullDuration / (+Real_8(No_Of_Steps)); G, H : Derivatives := (others => +0.0); Deriv0, Deriv1, Deriv2, Deriv3, Deriv4, Deriv5, Deriv6 : Real; Error : Array(Deriv_Index) of Real := (others => +0.0); Max_Error : Real; Three : constant Real := +3.0; begin -- REMEMBER, Functions return REDUCED derivatives. --********************************************************************* -- Test 1. H = Exp_d(Sin_d(t)) --********************************************************************* -- H = f(g(t)) = Exp(Sin(t)) -- d^1 H = Cos(t)*Exp(Sin(t)) -- d^2 H = (-Sin(t) + Cos(t)**2) * Exp(Sin(t)) -- d^3 H = (-Cos(t) -3*Sin(t)*Cos(t) + Cos(t)**3) * Exp(Sin(t)) -- d^4 H = ((-Cos(t) -3*Sin(t)*Cos(t) + Cos(t)**3) * Cos(t) + -- (Sin(t) - 3*Cos(t)**2 + 3*Sin(t)**2 - 3*Sin(t)*Cos(t)**2))*Exp(Sin(t)) Max_Error := Zero; for I in 0..No_Of_Steps loop Time := (+Real_8 (I)) * DeltaT; t := Time; G := Sin_d (t); H := Compose (Exp_d (G(0)), G); -- Exp (Sin (t)) Deriv0 := Exp (Sin (t)); Deriv1 := Cos(t) * Exp(Sin(t)); Deriv2 := (-Sin(t) + Cos(t)**2) * Exp(Sin(t)); Deriv3 := (-Cos(t) - Three*Sin(t)*Cos(t) + Cos(t)**3) * Exp(Sin(t)); Deriv4 := ((-Cos(t) -Three*Sin(t)*Cos(t) + Cos(t)**3) * Cos(t) + (Sin(t) - Three*Cos(t)**2 + Three*Sin(t)**2 - Three*Sin(t)*Cos(t)**2))*Exp(Sin(t)); Un_Reduce (H); Error(0) := Abs (H(0) - Deriv0); Error(1) := Abs (H(1) - Deriv1); Error(2) := Abs (H(2) - Deriv2); Error(3) := Abs (H(3) - Deriv3); Error(4) := Abs (H(4) - Deriv4); for I in 0..4 loop if Error(I) > Max_Error then Max_Error := Error(I); end if; end loop; end loop; new_line; put("Max error, test 1: "); put (e_Real_Image (Max_Error, Aft => 20)); --********************************************************************* -- Test 2. H = Sin_d(t**3) --********************************************************************* -- H = f(g(t)) = Sin(t**3) -- d^1 H = 3*t**2 * Cos(t**3) -- d^2 H = 6*t * Cos(t**3) - 9*t**4 * Sin(t**3) Max_Error := Zero; for I in 0..No_Of_Steps loop Time := (+Real_8 (I)) * DeltaT; G := Time ** 3; H := Compose (Sin_d (G(0)), G); -- Sin (Time**3) Deriv0 := Sin(Time**3); Deriv1 := (+3.0)*Time**2 * COS(Time**3); Deriv2 := (+6.0)*Time*Cos(Time**3) - (+9.0)*Time**4*Sin(Time**3); Un_Reduce (H); Error(0) := Abs (H(0) - Deriv0); Error(1) := Abs (H(1) - Deriv1); Error(2) := Abs (H(2) - Deriv2); for I in 0..2 loop if Error(I) > Max_Error then Max_Error := Error(I); end if; end loop; end loop; new_line; put("Max error, test 2: "); put (e_Real_Image (Max_Error, Aft => 20)); --********************************************************************* -- Test 3. H = Sin_d(t)**5 --********************************************************************* -- H = g(t)**5 = Sin(t)**5 -- d^1 H = 5 * Cos(t) * Sin(t)**4 -- d^2 H = 20 * Cos(t)**2 * Sin(t)**3 - 5 * Sin(t)**5 -- d^3 H = -40 * Cos(t) * Sin(t)**4 + 60 * Cos(t)**3 * Sin(t)**2 -- - 25 * Cos(t) * Sin(t)**4 Max_Error := Zero; for I in 0..No_Of_Steps loop Time := (+Real_8 (I)) * DeltaT; t := Time; H := Sin_d(Time) ** 5; Deriv0 := Sin(t)**5; Deriv1 := (+5.0) * Cos(t) * Sin(t)**4 ; Deriv2 := (+20.0) * Cos(t)**2 * Sin(t)**3 - (+5.0) * Sin(t)**5; Deriv3 := (-40.0) * Cos(t) * Sin(t)**4 + (+60.0) * Cos(t)**3 * Sin(t)**2 - (+25.0) * Cos(t) * Sin(t)**4; Un_Reduce (H); Error(0) := Abs (H(0) - Deriv0); Error(1) := Abs (H(1) - Deriv1); Error(2) := Abs (H(2) - Deriv2); Error(3) := Abs (H(3) - Deriv3); for I in 0..3 loop if Error(I) > Max_Error then Max_Error := Error(I); end if; end loop; end loop; new_line; put("Max error, test 3: "); put (e_Real_Image (Max_Error, Aft => 20)); --********************************************************************* -- Test 4. H = t**4 --********************************************************************* -- H = = t**4 -- d^1 H = 4 * t**3 -- d^2 H = 12 * t**2 -- d^3 H = 24 * t -- d^4 H = 24 -- d^5 H = 0 -- d^6 H = 0 Max_Error := Zero; for I in 0..No_Of_Steps loop Time := (+Real_8 (I)) * DeltaT; t := Time; H := t ** 4; Deriv0 := t ** 4; Deriv1 := (+4.0) * t**3; Deriv2 := (+12.0) * t**2; Deriv3 := (+24.0) * t; Deriv4 := +24.0; Deriv5 := Zero; Deriv6 := Zero; Un_Reduce (H); Error(0) := Abs (H(0) - Deriv0); Error(1) := Abs (H(1) - Deriv1); Error(2) := Abs (H(2) - Deriv2); Error(3) := Abs (H(3) - Deriv3); Error(4) := Abs (H(4) - Deriv4); Error(5) := Abs (H(5) - Deriv5); Error(6) := Abs (H(6) - Deriv6); for I in 0..6 loop if Error(I) > Max_Error then Max_Error := Error(I); end if; end loop; end loop; new_line; put("Max error, test 4: "); put (e_Real_Image (Max_Error, Aft => 20)); --********************************************************************* -- Test 5. H = Sin_d (w * t + phase) --********************************************************************* -- H = Sin (w * t + phase) -- d^1 H = w**1 * Cos (w * t + phase) -- d^2 H = -w**2 * Sin (w * t + phase) -- d^3 H = -w**3 * Cos (w * t + phase) -- d^4 H = w**4 * Sin (w * t + phase) -- d^5 H = w**5 * Cos (w * t + phase) -- d^6 H = -w**6 * Sin (w * t + phase) Max_Error := Zero; w := +0.92345; phase := +0.34567; for I in 0..No_Of_Steps loop Time := (+Real_8 (I)) * DeltaT; t := Time; H := Sin_d (t, w, phase); Deriv0 := Sin (w * t + phase); Deriv1 := w**1 * Cos (w * t + phase); Deriv2 := -w**2 * Sin (w * t + phase); Deriv3 := -w**3 * Cos (w * t + phase); Deriv4 := w**4 * Sin (w * t + phase); Deriv5 := w**5 * Cos (w * t + phase); Deriv6 := -w**6 * Sin (w * t + phase); Un_Reduce (H); Error(0) := Abs (H(0) - Deriv0); Error(1) := Abs (H(1) - Deriv1); Error(2) := Abs (H(2) - Deriv2); Error(3) := Abs (H(3) - Deriv3); Error(4) := Abs (H(4) - Deriv4); Error(5) := Abs (H(5) - Deriv5); Error(6) := Abs (H(6) - Deriv6); for I in 0..6 loop if Error(I) > Max_Error then Max_Error := Error(I); end if; end loop; end loop; new_line; put("Max error, test 5: "); put (e_Real_Image (Max_Error, Aft => 20)); --********************************************************************* -- Test 6. H = Log_d (w * t + phase). -- This also test Reciprocal : Real -> Derivative. --********************************************************************* Max_Error := Zero; w := +0.22345; phase := +0.34567; for I in 0..No_Of_Steps loop Time := (+Real_8 (I)) * DeltaT; t := Time; H := Log_d (t, w, phase); Deriv0 := Log (w * t + phase); Deriv1 := w**1 / (w * t + phase); Deriv2 := -w**2 / (w * t + phase)**2; Deriv3 := (+2.0) * w**3 / (w * t + phase)**3; Deriv4 := (-6.0) * w**4 / (w * t + phase)**4; Deriv5 := (+24.0) * w**5 / (w * t + phase)**5; Deriv6 := (-120.0) * w**6 / (w * t + phase)**6; Un_Reduce (H); Error(0) := Abs (H(0) - Deriv0); Error(1) := Abs (H(1) - Deriv1); Error(2) := Abs (H(2) - Deriv2); Error(3) := Abs (H(3) - Deriv3); Error(4) := Abs (H(4) - Deriv4); Error(5) := Abs (H(5) - Deriv5); Error(6) := Abs (H(6) - Deriv6); for I in 0..6 loop if Error(I) > Max_Error then Max_Error := Error(I); end if; end loop; end loop; new_line; put("Max error, test 6: "); put (e_Real_Image (Max_Error, Aft => 20)); --********************************************************************* -- Test 7. H = Cos_d (w * t + phase) --********************************************************************* Max_Error := Zero; w := +0.92345; phase := +0.34567; for I in 0..No_Of_Steps loop Time := (+Real_8 (I)) * DeltaT; t := Time; H := Cos_d (t, w, phase); Deriv0 := Cos (w * t + phase); Deriv1 := -w**1 * Sin (w * t + phase); Deriv2 := -w**2 * Cos (w * t + phase); Deriv3 := w**3 * Sin (w * t + phase); Deriv4 := w**4 * Cos (w * t + phase); Deriv5 := -w**5 * Sin (w * t + phase); Deriv6 := -w**6 * Cos (w * t + phase); Un_Reduce (H); Error(0) := Abs (H(0) - Deriv0); Error(1) := Abs (H(1) - Deriv1); Error(2) := Abs (H(2) - Deriv2); Error(3) := Abs (H(3) - Deriv3); Error(4) := Abs (H(4) - Deriv4); Error(5) := Abs (H(5) - Deriv5); Error(6) := Abs (H(6) - Deriv6); for I in 0..6 loop if Error(I) > Max_Error then Max_Error := Error(I); end if; end loop; end loop; new_line; put("Max error, test 7: "); put (e_Real_Image (Max_Error, Aft => 20)); --********************************************************************* -- Test 8. H = Sin_d / Cos_d; --********************************************************************* Max_Error := Zero; for I in 0..No_Of_Steps loop Time := (+Real_8 (I)) * DeltaT; t := Time; H := Sin_d (t) / Cos_d (t); Deriv0 := Sin(t) / Cos(t); Deriv1 := (+1.0) / Cos(t)**2; Deriv2 := (+2.0) * Sin(t) / Cos(t)**3; Deriv3 := (+2.0) / Cos(t)**2 + (+6.0) * Sin(t)**2 / Cos(t)**4; Deriv4 := (+4.0) * Sin(t) / Cos(t)**3 + (+12.0) * Sin(t) / Cos (t)**3 + (+24.0) * Sin(t)**3 / Cos(t)**5; Un_Reduce (H); Error(0) := Abs (H(0) - Deriv0); Error(1) := Abs (H(1) - Deriv1); Error(2) := Abs (H(2) - Deriv2); Error(3) := Abs (H(3) - Deriv3); Error(4) := Abs (H(4) - Deriv4); for I in 0..4 loop if Error(I) > Max_Error then Max_Error := Error(I); end if; end loop; end loop; new_line; put("Max error, test 8: "); put (e_Real_Image (Max_Error, Aft => 20)); --********************************************************************* -- Test 9. H = Sqrt_d; --********************************************************************* Max_Error := Zero; DeltaT := One / (+(No_Of_Steps + 1)); for I in 2..No_Of_Steps loop Time := (+Real_8 (I)) * DeltaT; t := Time; H := Sqrt_d (t); Deriv0 := Sqrt(t); Deriv1 := (+0.5) / Sqrt (t); Deriv2 := -(+0.5)*(+0.5)/ ((t) * Sqrt (t)); Deriv3 := (+0.5)*(+0.5)*(+0.5)*(+3.0)/ (t * t * Sqrt (t)); --Deriv4 := -(+0.5)*(+0.5)*(+0.5)*(+0.5)*(+3.0)*(+5.0)/ (t * t * t * Sqrt (t)); Un_Reduce (H); Error(0) := Abs (H(0) - Deriv0); Error(1) := Abs (H(1) - Deriv1); Error(2) := Abs (H(2) - Deriv2); Error(3) := Abs (H(3) - Deriv3); --Error(4) := Abs (H(4) - Deriv4); for I in 0..3 loop if Error(I) > Max_Error then Max_Error := Error(I); end if; end loop; end loop; new_line; put("Max error, test 9: "); put (e_Real_Image (Max_Error, Aft => 20)); --********************************************************************* -- Test 10. H = Arcsin_d; tests Compose and "/". --********************************************************************* Max_Error := Zero; DeltaT := One / (+Real_8(No_Of_Steps + 7)); for I in 1..No_Of_Steps loop Time := (+Real_8 (I)) * DeltaT; t := Time; H := Arcsin_d (t); Deriv0 := Arcsin(t); Deriv1 := One / Sqrt (One - t*t); Deriv2 := t / ((One - t*t) * Sqrt (One - t*t)); Deriv3 := One / ((One - t*t) * Sqrt (One - t*t)) + (+3.0)*t*t / ((One - t*t)*(One - t*t) * Sqrt (One - t*t)); Deriv4 := (+9.0)* t / ((One - t*t)*(One - t*t)*Sqrt (One - t*t)) + (+3.0)*(+5.0)*t*t*t / ((One - t*t)*(One - t*t)*(One - t*t)*Sqrt (One - t*t)); Un_Reduce (H); Error(0) := Abs (H(0) - Deriv0); Error(1) := Abs (H(1) - Deriv1); Error(2) := Abs (H(2) - Deriv2); Error(3) := Abs (H(3) - Deriv3); --Error(4) := Abs (H(4) - Deriv4); for I in 0..3 loop if Error(I) > Max_Error then Max_Error := Error(I); end if; end loop; end loop; new_line; put("Max error, test 10: "); put (e_Real_Image (Max_Error, Aft => 20)); --********************************************************************* -- Test 11. H = Arctan_d; tests Compose and "/". --********************************************************************* Max_Error := Zero; DeltaT := One / (+(No_Of_Steps + 7)); for I in 1..No_Of_Steps loop Time := (+Real_8(I)) * DeltaT; t := Time; H := Arctan_d (t); Deriv0 := Arcsin (t / Sqrt (One + t*t)); Deriv1 := One / (One + t*t); Deriv2 := -(+2.0) * t / ((One + t*t)**2); Deriv3 := -(+2.0) / ((One + t*t)**2) + (+8.0)*t*t / ((One + t*t)**3); Un_Reduce (H); Error(0) := Abs (H(0) - Deriv0); Error(1) := Abs (H(1) - Deriv1); Error(2) := Abs (H(2) - Deriv2); Error(3) := Abs (H(3) - Deriv3); for I in 0..3 loop if Error(I) > Max_Error then Max_Error := Error(I); end if; end loop; end loop; new_line; put("Max error, test 11: "); put (e_Real_Image (Max_Error, Aft => 20)); --********************************************************************* -- Test 12. H = Exp_d (Log_d (t)) -- -- Test the reduced derivs. Un-reduced get too large. --********************************************************************* -- H = f(g(t)) = Exp_d (Log_d (t)) -- d^1 H = One -- d^2 H = Zero Max_Error := Zero; for I in 0..No_Of_Steps loop Time := (+Real_8 (I)) * (+0.5) + (+5.0); t := Time; G := Log_d (t); H := Compose (Exp_d (G(0)), G); -- Exp (Log (t)) Deriv0 := t; Deriv1 := One; Deriv2 := Zero; --Un_Reduce (H); Error(0) := Abs (H(0) - Deriv0); Error(1) := Abs (H(1) - Deriv1); Error(2) := Abs ((+2.0)*H(2) - Deriv2); for I in 3..Max_Order_Of_Deriv loop Error(I) := Abs (H(I)); end loop; for I in 0..Max_Order_Of_Deriv loop if Error(I) > Max_Error then Max_Error := Error(I); end if; end loop; end loop; new_line; put("Max error, test 12: "); put (e_Real_Image (Max_Error, Aft => 20)); --********************************************************************* -- Test 13. H = Sin_d (Arcsin_d (t)) -- -- Test the reduced derivs. Un-reduced get too large. --********************************************************************* -- H = f(g(t)) = Sin_d (Arcsin_d (t)) -- d^1 H = One -- d^2 H = Zero Max_Error := Zero; for I in 0..No_Of_Steps loop Time := (+Real_8 (I + 1)) * DeltaT / (+Real_8 (I + 2)); t := Time; G := Arcsin_d (t); H := Compose (Sin_d (G(0)), G); -- Sin_d (Arcsin_d (t)) Deriv0 := t; Deriv1 := One; Deriv2 := Zero; --Un_Reduce (H); Error(0) := Abs (H(0) - Deriv0); Error(1) := Abs (H(1) - Deriv1); Error(2) := Abs ((+2.0)*H(2) - Deriv2); for I in 3..Max_Order_Of_Deriv loop Error(I) := Abs (H(I)); end loop; for I in 0..Max_Order_Of_Deriv loop if Error(I) > Max_Error then Max_Error := Error(I); end if; end loop; end loop; new_line; put("Max error, test 13: "); put (e_Real_Image (Max_Error, Aft => 20)); end;
reznikmm/matreshka
Ada
3,699
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.Office_Master_Styles_Elements is pragma Preelaborate; type ODF_Office_Master_Styles is limited interface and XML.DOM.Elements.DOM_Element; type ODF_Office_Master_Styles_Access is access all ODF_Office_Master_Styles'Class with Storage_Size => 0; end ODF.DOM.Office_Master_Styles_Elements;
optikos/oasis
Ada
2,852
ads
-- Copyright (c) 2019 Maxim Reznik <[email protected]> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Program.Elements.Declarations; with Program.Lexical_Elements; with Program.Elements.Defining_Names; with Program.Elements.Aspect_Specifications; with Program.Element_Vectors; with Program.Elements.Expressions; package Program.Elements.Package_Declarations is pragma Pure (Program.Elements.Package_Declarations); type Package_Declaration is limited interface and Program.Elements.Declarations.Declaration; type Package_Declaration_Access is access all Package_Declaration'Class with Storage_Size => 0; not overriding function Name (Self : Package_Declaration) return not null Program.Elements.Defining_Names.Defining_Name_Access is abstract; not overriding function Aspects (Self : Package_Declaration) return Program.Elements.Aspect_Specifications .Aspect_Specification_Vector_Access is abstract; not overriding function Visible_Declarations (Self : Package_Declaration) return Program.Element_Vectors.Element_Vector_Access is abstract; not overriding function Private_Declarations (Self : Package_Declaration) return Program.Element_Vectors.Element_Vector_Access is abstract; not overriding function End_Name (Self : Package_Declaration) return Program.Elements.Expressions.Expression_Access is abstract; type Package_Declaration_Text is limited interface; type Package_Declaration_Text_Access is access all Package_Declaration_Text'Class with Storage_Size => 0; not overriding function To_Package_Declaration_Text (Self : aliased in out Package_Declaration) return Package_Declaration_Text_Access is abstract; not overriding function Package_Token (Self : Package_Declaration_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function With_Token (Self : Package_Declaration_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Is_Token (Self : Package_Declaration_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Private_Token (Self : Package_Declaration_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function End_Token (Self : Package_Declaration_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Semicolon_Token (Self : Package_Declaration_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; end Program.Elements.Package_Declarations;
sonneveld/adazmq
Ada
9,685
adb
-- Load-balancing broker -- Clients and workers are shown here in-process with Ada.Command_Line; with Ada.Containers.Indefinite_Doubly_Linked_Lists; with Ada.Real_Time; with Ada.Strings.Unbounded; with Ada.Text_IO; with GNAT.Formatted_String; with ZMQ; with ZHelper; use type GNAT.Formatted_String.Formatted_String; use type Ada.Real_Time.Time_Span; procedure LBBroker is package String_Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists (Element_Type => String, "=" => "="); Nbr_Clients : constant := 10; Nbr_Workers : constant := 3; -- Basic request-reply client using REQ socket -- Because s_send and s_recv can't handle 0MQ binary identities, we -- set a printable text identity to allow routing. task type Client_Task_Type is entry Start (Id : out Ada.Strings.Unbounded.Unbounded_String); end Client_Task_Type; task body Client_Task_Type is Context : ZMQ.Context_Type := ZMQ.New_Context; Client : ZMQ.Socket_Type'Class := Context.New_Socket (ZMQ.ZMQ_REQ); Self_Id : constant String := ZHelper.Set_Id (Client); -- Set a printable identity. begin accept Start (Id : out Ada.Strings.Unbounded.Unbounded_String) do Id := Ada.Strings.Unbounded.To_Unbounded_String (Self_Id); end Start; Client.Connect ("ipc://frontend.ipc"); -- Send request, get reply Client.Send ("HELLO"); declare Reply : constant String := Client.Recv; begin Ada.Text_IO.Put_Line ("Client: " & Reply); end; Client.Close; Context.Term; end Client_Task_Type; -- While this example runs in a single process, that is just to make -- it easier to start and stop the example. Each thread has its own -- context and conceptually acts as a separate process. -- This is the worker task, using a REQ socket to do load-balancing. -- Because s_send and s_recv can't handle 0MQ binary identities, we -- set a printable text identity to allow routing. task type Worker_Task_Type is entry Start (Id : out Ada.Strings.Unbounded.Unbounded_String); end Worker_Task_Type; task body Worker_Task_Type is Context : ZMQ.Context_Type := ZMQ.New_Context; Worker : ZMQ.Socket_Type'Class := Context.New_Socket (ZMQ.ZMQ_REQ); Self_Id : constant String := ZHelper.Set_Id (Worker); -- Set a printable identity. begin accept Start (Id : out Ada.Strings.Unbounded.Unbounded_String) do Id := Ada.Strings.Unbounded.To_Unbounded_String (Self_Id); end Start; Worker.Connect ("ipc://backend.ipc"); -- Tell broker we're ready for work Worker.Send ("READY"); Read_Loop : loop -- Read and save all frames until we get an empty frame -- In this example there is only 1, but there could be more declare Identity : constant String := Worker.Recv; Empty : constant String := Worker.Recv; Request : constant String := Worker.Recv; begin if Empty'Length /= 0 then raise Program_Error; end if; exit Read_Loop when Request = "TERMINATE"; -- Get request, send reply Ada.Text_IO.Put_Line ("Worker: " & Request); Worker.Send (Identity, Send_More => True); Worker.Send ("", Send_More => True); Worker.Send ("OK"); end; end loop Read_Loop; Worker.Close; Context.Term; end Worker_Task_Type; -- This is the main task. It starts the clients and workers, and then -- routes requests between the two layers. Workers signal READY when -- they start; after that we treat them as ready when they reply with -- a response back to a client. The load-balancing data structure is -- just a queue of next available workers. function Main return Ada.Command_Line.Exit_Status is -- Prepare our context and sockets Context : ZMQ.Context_Type := ZMQ.New_Context; Frontend : ZMQ.Socket_Type'Class := Context.New_Socket (ZMQ.ZMQ_ROUTER); Backend : ZMQ.Socket_Type'Class := Context.New_Socket (ZMQ.ZMQ_ROUTER); begin Frontend.Bind ("ipc://frontend.ipc"); Backend.Bind ("ipc://backend.ipc"); declare Client_Tasks : array (1 .. Nbr_Clients) of Client_Task_Type; Worker_Tasks : array (1 .. Nbr_Workers) of Worker_Task_Type; Worker_Ids : String_Lists.List; Client_Reply_Count : Natural := 0; T_Id : Ada.Strings.Unbounded.Unbounded_String; begin for T of Client_Tasks loop T.Start (T_Id); end loop; for T of Worker_Tasks loop T.Start (T_Id); Worker_Ids.Append (Ada.Strings.Unbounded.To_String (T_Id)); end loop; -- Here is the main loop for the least-recently-used queue. It has two -- sockets; a frontend for clients and a backend for workers. It polls -- the backend in all cases, and polls the frontend only when there are -- one or more workers ready. This is a neat way to use 0MQ's own queues -- to hold messages we're not ready to process yet. When we get a client -- reply, we pop the next available worker and send the request to it, -- including the originating client identity. When a worker replies, we -- requeue that worker and forward the reply to the original client -- using the reply envelope. -- Queue of available workers declare Worker_Queue : String_Lists.List; begin Poll_Loop : loop declare Items : ZMQ.Poll_Item_Array_Type := (ZMQ.New_Poll_Item (Backend, Poll_In => True), ZMQ.New_Poll_Item (Frontend, Poll_In => True)); begin -- Poll frontend only if we have available workers if Worker_Queue.Is_Empty then ZMQ.Poll (Items (Items'First .. Items'First)); else ZMQ.Poll (Items); end if; -- Handle worker activity on backend if ZMQ.Is_Readable (Items (Items'First)) then -- Queue worker identity for load-balancing declare Worker_Id : constant String := Backend.Recv; Empty : constant String := Backend.Recv; -- Second frame is empty Client_Id : constant String := Backend.Recv; -- Third frame is READY or else a client reply identity begin Worker_Queue.Append (Worker_Id); if Empty'Length /= 0 then raise Program_Error; end if; -- If client reply, send rest back to frontend if Client_Id /= "READY" then declare Empty : constant String := Backend.Recv; Reply : constant String := Backend.Recv; begin if Empty'Length /= 0 then raise Program_Error; end if; Frontend.Send (Client_Id, Send_More => True); Frontend.Send ("", Send_More => True); Frontend.Send (Reply); Client_Reply_Count := Client_Reply_Count + 1; end; end if; end; end if; -- Here is how we handle a client request: if not Worker_Queue.Is_Empty and then ZMQ.Is_Readable (Items (Items'First + 1)) then -- Now get next client request, route to last-used worker -- Client request is [identity][empty][request] declare Client_Id : constant String := Frontend.Recv; Empty : constant String := Frontend.Recv; Request : constant String := Frontend.Recv; Worker_Id : constant String := Worker_Queue.First_Element; begin if Empty'Length /= 0 then raise Program_Error; end if; Backend.Send (Worker_Id, Send_More => True); Backend.Send ("", Send_More => True); Backend.Send (Client_Id, Send_More => True); Backend.Send ("", Send_More => True); Backend.Send (Request); -- Dequeue and drop the next worker identity Worker_Queue.Delete_First; end; end if; end; exit Poll_Loop when Client_Reply_Count >= Nbr_Clients; -- Exit after N messages end loop Poll_Loop; end; for X of Worker_Ids loop Backend.Send (X, Send_More => True); Backend.Send ("", Send_More => True); Backend.Send ("<none>", Send_More => True); Backend.Send ("", Send_More => True); Backend.Send ("TERMINATE"); end loop; Frontend.Close; Backend.Close; Context.Term; end; return 0; end Main; begin Ada.Command_Line.Set_Exit_Status (Main); end LBBroker;
zrmyers/VulkanAda
Ada
6,291
ads
-------------------------------------------------------------------------------- -- MIT License -- -- Copyright (c) 2020 Zane Myers -- -- 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 Vulkan.Math.GenFMatrix; with Vulkan.Math.Vec4; use Vulkan.Math.GenFMatrix; use Vulkan.Math.Vec4; -------------------------------------------------------------------------------- --< @group Vulkan Math Basic Types -------------------------------------------------------------------------------- --< @summary --< This package provides a single precision floating point matrix with 2 rows --< and 4 columns. -------------------------------------------------------------------------------- package Vulkan.Math.Mat2x4 is pragma Preelaborate; pragma Pure; --< A 2x3 matrix of single-precision floating point numbers. subtype Vkm_Mat2x4 is Vkm_Mat( last_row_index => 1, last_column_index => 3); ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Mat2x4 type. --< --< @description --< Construct a 2x3 matrix with each component set to zero. --< --< @return --< A 2x3 matrix. ---------------------------------------------------------------------------- function Make_Mat2x4 return Vkm_Mat2x4 is (GFM.Make_GenMatrix(cN => 3, rN => 1)) with Inline; ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Mat2x4 type. --< --< @description --< Construct a 2x3 matrix with each component set to a different value. --< --< | value1 value3 value5 value7 | --< | value2 value4 value6 value8 | --< --< @param value1 --< The first value to set for the matrix. --< --< @param value2 --< The second value to set for the matrix. --< --< @param value3 --< The third value to set for the matrix. --< --< @param value4 --< The fourth value to set for the matrix. --< --< @param value5 --< The fifth value to set for the matrix. --< --< @param value6 --< The sixth value to set for the matrix. --< --< @param value7 --< The seventh value to set for the matrix. --< --< @param value8 --< The eighth value to set for the matrix. --< --< @return --< A 2x4 matrix. ---------------------------------------------------------------------------- function Make_Mat2x4 ( value1, value2, value3, value4, value5, value6, value7, value8 : in Vkm_Float) return Vkm_Mat2x4 is (GFM.Make_GenMatrix( cN => 3, rN => 1, c0r0_val => value1, c0r1_val => value5, c1r0_val => value2, c1r1_val => value6, c2r0_val => value3, c2r1_val => value7, c3r0_val => value4, c3r1_val => value8)) with Inline; ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Mat2x4 type. --< --< @description --< Construct a 2x4 matrix with each row set to the value of a 4 dimmensional --< vector. --< --< | value1.x value1.y value1.z value1.w | --< | value2.x value2.y value2.z value2.w | --< --< @param value1 --< The first value to set for the matrix. --< --< @param value2 --< The second value to set for the matrix. --< --< @return --< A 2x4 matrix. ---------------------------------------------------------------------------- function Make_Mat2x4 ( value1, value2 : in Vkm_Vec4) return Vkm_Mat2x4 is (GFM.Make_GenMatrix( cN => 3, rN => 1, c0r0_val => value1.x, c0r1_val => value2.x, c1r0_val => value1.y, c1r1_val => value2.y, c2r0_val => value1.z, c2r1_val => value2.z, c3r0_val => value1.w, c3r1_val => value2.w)) with Inline; ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Mat2x4 type. --< --< @description --< Construct a 2x3 matrix using values from an existing matrix. --< --< If the provided matrix has dimmensions that are not the same as this --< matrix, the corresponding element in the 4x4 identity matrix is used for --< out of bounds accesses. --< --< @param value1 --< The submatrix to extract values from. --< --< @return --< A 2x4 matrix. ---------------------------------------------------------------------------- function Make_Mat2x4 ( value1 : in Vkm_Mat) return Vkm_Mat2x4 is (GFM.Make_GenMatrix( cN => 3, rN => 1, c0r0_val => value1.c0r0, c0r1_val => value1.c0r1, c1r0_val => value1.c1r0, c1r1_val => value1.c1r1, c2r0_val => value1.c2r0, c2r1_val => value1.c2r1, c3r0_val => value1.c3r0, c3r1_val => value1.c3r1)) with Inline; end Vulkan.Math.Mat2x4;
reznikmm/matreshka
Ada
3,694
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_Title_Attributes is pragma Preelaborate; type ODF_Table_Title_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Table_Title_Attribute_Access is access all ODF_Table_Title_Attribute'Class with Storage_Size => 0; end ODF.DOM.Table_Title_Attributes;
AdaCore/gpr
Ada
1,046
adb
with Test_GPR; with Test_Assert; with GPR2.Project.Tree; function Test return Integer is package TGPR renames Test_GPR; package A renames Test_Assert; Tree : GPR2.Project.Tree.Object; begin -- Ensure that a basic project with extends all is loaded correctly TGPR.Load_With_No_Errors (Tree, "./basic/root.gpr"); -- Variable1 definition starts in B, then amended by C, then A TGPR.Assert_Variable (View => Tree.Root_Project, Variable => "A_Variable1", Value => "A extall C with D with ExtB.Var2"); -- Variant of previous test in which C is referenced instead of A. TGPR.Assert_Variable (View => Tree.Root_Project, Variable => "A_Variable2", Value => "A with ExtB.Var2"); -- Variant of previous test in which C is referenced instead of A, but -- variable value is not modified in the extension TGPR.Assert_Variable (View => Tree.Root_Project, Variable => "B_Variable2", Value => "B.Var2"); return A.Report; end Test;
reznikmm/matreshka
Ada
3,635
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$ ------------------------------------------------------------------------------ package Matreshka.Internals.Regexps.Engine.Pike is pragma Preelaborate; function Execute (Program : Engine.Program; String : not null Matreshka.Internals.Strings.Shared_String_Access) return not null Shared_Match_Access; end Matreshka.Internals.Regexps.Engine.Pike;
tum-ei-rcs/StratoX
Ada
2,689
ads
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- A D A . E X C E P T I O N S . L A S T _ C H A N C E _ H A N D L E R -- -- -- -- S p e c -- -- -- -- Copyright (C) 2012-2013, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- -- -- -- -- -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- Last chance handler. Unhandled exceptions are passed to this routine with System; procedure Ada.Exceptions.Last_Chance_Handler (Msg : System.Address; Line : Integer); pragma Export (C, Ada.Exceptions.Last_Chance_Handler, "__gnat_last_chance_handler"); pragma No_Return (Ada.Exceptions.Last_Chance_Handler);
reznikmm/matreshka
Ada
4,025
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.Smil_TargetElement_Attributes; package Matreshka.ODF_Smil.TargetElement_Attributes is type Smil_TargetElement_Attribute_Node is new Matreshka.ODF_Smil.Abstract_Smil_Attribute_Node and ODF.DOM.Smil_TargetElement_Attributes.ODF_Smil_TargetElement_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Smil_TargetElement_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Smil_TargetElement_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Smil.TargetElement_Attributes;
AdaCore/libadalang
Ada
57
ads
package Bar is I : constant Integer := $BAR; end Bar;
jrmarino/zstd-ada
Ada
22,783
adb
-- This file is covered by the Internet Software Consortium (ISC) License -- Reference: ../License.txt with Ada.Directories; with Ada.Direct_IO; package body Zstandard.Functions is package DIR renames Ada.Directories; -------------------- -- Zstd_Version -- -------------------- function Zstd_Version return String is function trim (num : Natural) return String; function trim (num : Natural) return String is numstr : constant String := num'Img; begin return numstr (numstr'First + 1 .. numstr'Last); end trim; dot : constant String := "."; res : Thin.IC.unsigned; ver : Natural; major : Natural; minor : Natural; point : Natural; begin res := Thin.ZSTD_versionNumber; ver := Natural (res); point := ver mod 100; minor := (ver / 100) mod 100; major := (ver / 10000) mod 100; return trim (major) & dot & trim (minor) & dot & trim (point); end Zstd_Version; ------------------ -- convert #1 -- ------------------ function convert (data : Thin.IC.char_array) return String is use type Thin.IC.size_t; result : String (1 .. data'Length); arrow : Thin.IC.size_t := data'First; begin for z in result'Range loop result (z) := Character (data (arrow)); arrow := arrow + 1; end loop; return result; end convert; ------------------ -- convert #2 -- ------------------ function convert (data : String) return Thin.IC.char_array is use type Thin.IC.size_t; reslen : Thin.IC.size_t := Thin.IC.size_t (data'Length); result : Thin.IC.char_array (1 .. reslen); arrow : Thin.IC.size_t := 1; begin for z in data'Range loop result (arrow) := Thin.IC.char (data (z)); arrow := arrow + 1; end loop; return result; end convert; ---------------- -- Compress -- ---------------- function Compress (source_data : String; successful : out Boolean; quality : Compression_Level := Default_Compression) return String is comp_bytes : Thin.IC.size_t; is_error : Thin.IC.unsigned; level : constant Thin.IC.int := Thin.IC.int (quality); src : aliased Thin.IC.char_array := convert (source_data); srcSize : constant Thin.IC.size_t := Thin.IC.size_t (source_data'Length); dstCapacity : constant Thin.IC.size_t := Thin.ZSTD_compressBound (srcSize); dst : aliased Thin.IC.char_array := (1 .. dstCapacity => Thin.IC.nul); dst_pointer : Thin.ICS.chars_ptr := Thin.ICS.To_Chars_Ptr (dst'Unchecked_Access); src_pointer : Thin.ICS.chars_ptr := Thin.ICS.To_Chars_Ptr (src'Unchecked_Access); begin comp_bytes := Thin.ZSTD_compress (dst => dst_pointer, dstCapacity => dstCapacity, src => src_pointer, srcSize => srcSize, compressionLevel => level); is_error := Thin.ZSTD_isError (code => comp_bytes); successful := (Natural (is_error) = 0); if successful then return convert (dst (1 .. comp_bytes)); else return Thin.ICS.Value (Thin.ZSTD_getErrorName (code => comp_bytes)); end if; end Compress; ------------------ -- Decompress -- ------------------ function Decompress (source_data : String; successful : out Boolean) return String is use type Thin.Zstd_uint64; use type Thin.IC.size_t; dcmp_bytes : Thin.IC.size_t; src : aliased Thin.IC.char_array := convert (source_data); srcSize : constant Thin.IC.size_t := Thin.IC.size_t (source_data'Length); src_pointer : Thin.ICS.chars_ptr := Thin.ICS.To_Chars_Ptr (src'Unchecked_Access); full_size : constant Thin.Zstd_uint64 := Thin.ZSTD_getDecompressedSize (src => src_pointer, srcSize => srcSize); begin if full_size = 0 then successful := False; return Warn_orig_size_fail; end if; if full_size > Thin.Zstd_uint64 (Thin.IC.size_t'Last) then successful := False; return Warn_way_too_big; end if; declare dstCapacity : constant Thin.IC.size_t := Thin.IC.size_t (full_size); dst : aliased Thin.IC.char_array := (1 .. dstCapacity => Thin.IC.nul); dst_pointer : Thin.ICS.chars_ptr := Thin.ICS.To_Chars_Ptr (dst'Unchecked_Access); begin dcmp_bytes := Thin.ZSTD_decompress (dst => dst_pointer, dstCapacity => dstCapacity, src => src_pointer, compressedSize => srcSize); successful := (dcmp_bytes = dstCapacity); if successful then return convert (dst); else return Thin.ICS.Value (Thin.ZSTD_getErrorName (code => dcmp_bytes)); end if; end; end Decompress; --------------------- -- File_Contents -- --------------------- function File_Contents (filename : String; filesize : Natural; nominal : out Boolean) return String is subtype File_String is String (1 .. filesize); package File_String_IO is new Ada.Direct_IO (File_String); File : File_String_IO.File_Type; Contents : File_String; begin nominal := False; File_String_IO.Open (File => File, Mode => File_String_IO.In_File, Name => filename); File_String_IO.Read (File => File, Item => Contents); File_String_IO.Close (File); nominal := True; return Contents; exception when others => if File_String_IO.Is_Open (File) then File_String_IO.Close (File); end if; return ""; end File_Contents; ------------------------- -- write_entire_file -- ------------------------- function Write_Entire_File (filename : String; contents : String) return Boolean is new_file_size : constant Natural := contents'Length; subtype File_String is String (1 .. new_file_size); package File_String_IO is new Ada.Direct_IO (File_String); output_Handle : File_String_IO.File_Type; begin File_String_IO.Create (File => output_Handle, Mode => File_String_IO.Out_File, Name => filename); File_String_IO.Write (output_Handle, File_String (contents)); File_String_IO.Close (output_Handle); return True; exception when others => if File_String_IO.Is_Open (output_Handle) then File_String_IO.Close (output_Handle); end if; return False; end Write_Entire_File; --------------------- -- Compress_File -- --------------------- function Compress_File (source_file : String; output_file : String; source_size : out File_Size; output_size : out File_Size; successful : out Boolean; quality : Compression_Level := Default_Compression) return String is begin source_size := 0; output_size := 0; successful := False; if not DIR.Exists (source_file) then return Warn_src_file_DNE; end if; source_size := File_Size (DIR.Size (source_file)); declare good_dump : Boolean; payload : constant String := File_Contents (filename => source_file, filesize => Natural (source_size), nominal => good_dump); begin if not good_dump then return Warn_src_read_fail; end if; declare good_compress : Boolean; compact : constant String := Compress (source_data => payload, successful => good_compress, quality => quality); begin if not good_compress then return Warn_compress_fail & " (" & compact & ")"; end if; if Write_Entire_File (filename => output_file, contents => compact) then output_size := File_Size (compact'Length); successful := True; return ""; else return Warn_dst_write_fail; end if; end; end; end Compress_File; ----------------------- -- Decompress_File -- ----------------------- function Decompress_File (source_file : String; output_file : String; source_size : out File_Size; output_size : out File_Size; successful : out Boolean) return String is begin source_size := 0; output_size := 0; successful := False; if not DIR.Exists (source_file) then return Warn_src_file_DNE; end if; source_size := File_Size (DIR.Size (source_file)); declare good_dump : Boolean; payload : constant String := File_Contents (filename => source_file, filesize => Natural (source_size), nominal => good_dump); begin if not good_dump then return Warn_src_read_fail; end if; declare good_expansion : Boolean; fulldata : constant String := Decompress (source_data => payload, successful => good_expansion); begin if not good_expansion then return Warn_decompress_fail & " (" & fulldata & ")"; end if; if Write_Entire_File (filename => output_file, contents => fulldata) then output_size := File_Size (fulldata'Length); successful := True; return ""; else return Warn_dst_write_fail; end if; end; end; end Decompress_File; ------------------------------------- -- Create_Compression_Dictionary -- ------------------------------------- function Create_Compression_Dictionary (sample : String; quality : Compression_Level := Default_Compression) return Compression_Dictionary is dict : aliased Thin.IC.char_array := convert (sample); dictSize : constant Thin.IC.size_t := Thin.IC.size_t (sample'Length); dict_pointer : Thin.ICS.chars_ptr := Thin.ICS.To_Chars_Ptr (dict'Unchecked_Access); level : constant Thin.IC.int := Thin.IC.int (quality); begin return Thin.ZSTD_createCDict (dict => dict_pointer, dictSize => dictSize, compressionLevel => level); end Create_Compression_Dictionary; ----------------------------------------------- -- Create_Compression_Dictionary_From_File -- ----------------------------------------------- function Create_Compression_Dictionary_From_File (sample_file : String; successful : out Boolean; quality : Compression_Level := Default_Compression) return Compression_Dictionary is sample_file_size : Natural; new_dictionary : Compression_Dictionary; begin successful := False; if not DIR.Exists (sample_file) then return Thin.Null_CDict_pointer; end if; sample_file_size := Natural (DIR.Size (sample_file)); declare use type Thin.ZSTD_CDict_ptr; good_dump : Boolean; payload : constant String := File_Contents (filename => sample_file, filesize => sample_file_size, nominal => good_dump); begin if not good_dump then return Thin.Null_CDict_pointer; end if; new_dictionary := Create_Compression_Dictionary (payload, quality); successful := (new_dictionary /= Thin.Null_CDict_pointer); return new_dictionary; end; end Create_Compression_Dictionary_From_File; -------------------------------------- -- Destroy_Compression_Dictionary -- -------------------------------------- procedure Destroy_Compression_Dictionary (digest : Compression_Dictionary) is res : Thin.IC.size_t; begin res := Thin.ZSTD_freeCDict (CDict => digest); end Destroy_Compression_Dictionary; --------------------------------------- -- Create_Decompression_Dictionary -- --------------------------------------- function Create_Decompression_Dictionary (sample : String) return Decompression_Dictionary is dict : aliased Thin.IC.char_array := convert (sample); dictSize : constant Thin.IC.size_t := Thin.IC.size_t (sample'Length); dict_pointer : Thin.ICS.chars_ptr := Thin.ICS.To_Chars_Ptr (dict'Unchecked_Access); begin return Thin.ZSTD_createDDict (dict => dict_pointer, dictSize => dictSize); end Create_Decompression_Dictionary; ------------------------------------------------- -- Create_Decompression_Dictionary_From_File -- ------------------------------------------------- function Create_Decompression_Dictionary_From_File (sample_file : String; successful : out Boolean) return Decompression_Dictionary is sample_file_size : Natural; new_dictionary : Decompression_Dictionary; begin successful := False; if not DIR.Exists (sample_file) then return Thin.Null_DDict_pointer; end if; sample_file_size := Natural (DIR.Size (sample_file)); declare use type Thin.ZSTD_DDict_ptr; good_dump : Boolean; payload : constant String := File_Contents (filename => sample_file, filesize => sample_file_size, nominal => good_dump); begin if not good_dump then return Thin.Null_DDict_pointer; end if; new_dictionary := Create_Decompression_Dictionary (payload); successful := (new_dictionary /= Thin.Null_DDict_pointer); return new_dictionary; end; end Create_Decompression_Dictionary_From_File; ---------------------------------------- -- Destroy_Decompression_Dictionary -- ---------------------------------------- procedure Destroy_Decompression_Dictionary (digest : Decompression_Dictionary) is res : Thin.IC.size_t; begin res := Thin.ZSTD_freeDDict (ddict => digest); end Destroy_Decompression_Dictionary; ----------------------------- -- Compress (dictionary) -- ----------------------------- function Compress (source_data : String; digest : Compression_Dictionary; successful : out Boolean) return String is comp_bytes : Thin.IC.size_t; is_error : Thin.IC.unsigned; src : aliased Thin.IC.char_array := convert (source_data); srcSize : constant Thin.IC.size_t := Thin.IC.size_t (source_data'Length); dstCapacity : constant Thin.IC.size_t := Thin.ZSTD_compressBound (srcSize); dst : aliased Thin.IC.char_array := (1 .. dstCapacity => Thin.IC.nul); dst_pointer : Thin.ICS.chars_ptr := Thin.ICS.To_Chars_Ptr (dst'Unchecked_Access); src_pointer : Thin.ICS.chars_ptr := Thin.ICS.To_Chars_Ptr (src'Unchecked_Access); cctx : Thin.ZSTD_CCtx_ptr; freeres : Thin.IC.size_t; begin cctx := Thin.ZSTD_createCCtx; comp_bytes := Thin.ZSTD_compress_usingCDict (ctx => cctx, dst => dst_pointer, dstCapacity => dstCapacity, src => src_pointer, srcSize => srcSize, CDict => digest); freeres := Thin.ZSTD_freeCCtx (cctx); is_error := Thin.ZSTD_isError (code => comp_bytes); successful := (Natural (is_error) = 0); if successful then return convert (dst (1 .. comp_bytes)); else return Thin.ICS.Value (Thin.ZSTD_getErrorName (code => comp_bytes)); end if; end Compress; ---------------------------------- -- Compress_File (dictionary) -- ---------------------------------- function Compress_File (source_file : String; output_file : String; digest : Compression_Dictionary; source_size : out File_Size; output_size : out File_Size; successful : out Boolean) return String is begin source_size := 0; output_size := 0; successful := False; if not DIR.Exists (source_file) then return Warn_src_file_DNE; end if; source_size := File_Size (DIR.Size (source_file)); declare good_dump : Boolean; payload : constant String := File_Contents (filename => source_file, filesize => Natural (source_size), nominal => good_dump); begin if not good_dump then return Warn_src_read_fail; end if; declare good_compress : Boolean; compact : constant String := Compress (source_data => payload, digest => digest, successful => good_compress); begin if not good_compress then return Warn_compress_fail & " (" & compact & ")"; end if; if Write_Entire_File (filename => output_file, contents => compact) then output_size := File_Size (compact'Length); successful := True; return ""; else return Warn_dst_write_fail; end if; end; end; end Compress_File; ------------------------------- -- Decompress (dictionary) -- ------------------------------- function Decompress (source_data : String; digest : Decompression_Dictionary; successful : out Boolean) return String is use type Thin.Zstd_uint64; use type Thin.IC.size_t; dcmp_bytes : Thin.IC.size_t; src : aliased Thin.IC.char_array := convert (source_data); srcSize : constant Thin.IC.size_t := Thin.IC.size_t (source_data'Length); src_pointer : Thin.ICS.chars_ptr := Thin.ICS.To_Chars_Ptr (src'Unchecked_Access); full_size : constant Thin.Zstd_uint64 := Thin.ZSTD_getDecompressedSize (src => src_pointer, srcSize => srcSize); dctx : Thin.ZSTD_DCtx_ptr; freeres : Thin.IC.size_t; begin successful := False; if full_size = 0 then return Warn_orig_size_fail; end if; if full_size > Thin.Zstd_uint64 (Thin.IC.size_t'Last) then return Warn_way_too_big; end if; declare dstCapacity : constant Thin.IC.size_t := Thin.IC.size_t (full_size); dst : aliased Thin.IC.char_array := (1 .. dstCapacity => Thin.IC.nul); dst_pointer : Thin.ICS.chars_ptr := Thin.ICS.To_Chars_Ptr (dst'Unchecked_Access); begin dctx := Thin.ZSTD_createDCtx; dcmp_bytes := Thin.ZSTD_decompress_usingDDict (dctx => dctx, dst => dst_pointer, dstCapacity => dstCapacity, src => src_pointer, srcSize => srcSize, ddict => digest); freeres := Thin.ZSTD_freeDCtx (dctx); successful := (dcmp_bytes = dstCapacity); if successful then return convert (dst); else return Thin.ICS.Value (Thin.ZSTD_getErrorName (code => dcmp_bytes)); end if; end; end Decompress; ------------------------------------ -- Decompress_File (dictionary) -- ------------------------------------ function Decompress_File (source_file : String; output_file : String; digest : Decompression_Dictionary; source_size : out File_Size; output_size : out File_Size; successful : out Boolean) return String is begin source_size := 0; output_size := 0; successful := False; if not DIR.Exists (source_file) then return Warn_src_file_DNE; end if; source_size := File_Size (DIR.Size (source_file)); declare good_dump : Boolean; payload : constant String := File_Contents (filename => source_file, filesize => Natural (source_size), nominal => good_dump); begin if not good_dump then return Warn_src_read_fail; end if; declare good_expansion : Boolean; fulldata : constant String := Decompress (source_data => payload, digest => digest, successful => good_expansion); begin if not good_expansion then return Warn_decompress_fail & " (" & fulldata & ")"; end if; if Write_Entire_File (filename => output_file, contents => fulldata) then output_size := File_Size (fulldata'Length); successful := True; return ""; else return Warn_dst_write_fail; end if; end; end; end Decompress_File; end Zstandard.Functions;
stcarrez/ada-awa
Ada
1,656
ads
----------------------------------------------------------------------- -- awa-components-redirect -- ASF Core Components -- Copyright (C) 2011 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 ASF.Components.Core; with ASF.Contexts.Faces; with Util.Beans.Objects; package AWA.Components.Redirect is use ASF.Contexts.Faces; -- ------------------------------ -- Redirect component -- ------------------------------ type UIRedirect is new ASF.Components.Core.UILeaf with null record; type UIRedirect_Access is access all UIRedirect'Class; -- Get the redirection link function Get_Link (UI : in UIRedirect; Context : in Faces_Context'Class) return Util.Beans.Objects.Object; -- If the component is rendered, activate the redirection to the -- specified URI. overriding procedure Encode_Begin (UI : in UIRedirect; Context : in out Faces_Context'Class); end AWA.Components.Redirect;
MinimSecure/unum-sdk
Ada
1,444
adb
-- Copyright 2012-2016 Free Software Foundation, Inc. -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see <http://www.gnu.org/licenses/>. with Ops; use Ops; procedure Ops_Test is begin Dummy (Make (31) + Make (11)); -- BEGIN Dummy (Make (31) - Make (11)); Dummy (Make (31) * Make (11)); Dummy (Make (31) / Make (11)); Dummy (Make (31) mod Make (11)); Dummy (Make (31) rem Make (11)); Dummy (Make (31) ** Make (11)); Dummy (Make (31) < Make (11)); Dummy (Make (31) <= Make (11)); Dummy (Make (31) > Make (11)); Dummy (Make (31) >= Make (11)); Dummy (Make (31) = Make (11)); Dummy (Make (31) and Make (11)); Dummy (Make (31) or Make (11)); Dummy (Make (31) xor Make (11)); Dummy (Make (31) & Make (11)); Dummy (abs (Make (42))); Dummy (not Make (11)); Dummy (+ Make (11)); Dummy (- Make (11)); end Ops_Test;
reznikmm/matreshka
Ada
4,151
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Examples Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2016-2020, 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 Ada.Streams; with League.Strings; with Servlet.Generic_Servlets; with Servlet.HTTP_Requests; with Servlet.HTTP_Responses; with Servlet.HTTP_Servlets; with Servlet.HTTP_Upgrade_Handlers; with Web_Socket.Handlers.AWS_Handlers; with Web_Socket.Listeners; package Servlets.File is type File_Servlet is new Servlet.HTTP_Servlets.HTTP_Servlet with private; private type File_Servlet is new Servlet.HTTP_Servlets.HTTP_Servlet with null record; overriding function Get_Servlet_Info (Self : File_Servlet) return League.Strings.Universal_String; overriding procedure Do_Get (Self : in out File_Servlet; Request : Servlet.HTTP_Requests.HTTP_Servlet_Request'Class; Response : in out Servlet.HTTP_Responses.HTTP_Servlet_Response'Class); overriding function Instantiate (Parameters : not null access Servlet.Generic_Servlets.Instantiation_Parameters'Class) return File_Servlet; end Servlets.File;
charlie5/cBound
Ada
1,544
ads
-- This file is generated by SWIG. Please do not modify by hand. -- with Interfaces; with Interfaces.C; with Interfaces.C.Pointers; package xcb.xcb_poly_line_request_t is -- Item -- type Item is record major_opcode : aliased Interfaces.Unsigned_8; coordinate_mode : aliased Interfaces.Unsigned_8; length : aliased Interfaces.Unsigned_16; drawable : aliased xcb.xcb_drawable_t; gc : aliased xcb.xcb_gcontext_t; end record; -- Item_Array -- type Item_Array is array (Interfaces.C.size_t range <>) of aliased xcb.xcb_poly_line_request_t .Item; -- Pointer -- package C_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_poly_line_request_t.Item, Element_Array => xcb.xcb_poly_line_request_t.Item_Array, Default_Terminator => (others => <>)); subtype Pointer is C_Pointers.Pointer; -- Pointer_Array -- type Pointer_Array is array (Interfaces.C.size_t range <>) of aliased xcb.xcb_poly_line_request_t .Pointer; -- Pointer_Pointer -- package C_Pointer_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_poly_line_request_t.Pointer, Element_Array => xcb.xcb_poly_line_request_t.Pointer_Array, Default_Terminator => null); subtype Pointer_Pointer is C_Pointer_Pointers.Pointer; end xcb.xcb_poly_line_request_t;