repo_name
stringlengths
9
74
language
stringclasses
1 value
length_bytes
int64
11
9.34M
extension
stringclasses
2 values
content
stringlengths
11
9.34M
micahwelf/FLTK-Ada
Ada
10,272
adb
with Interfaces.C.Strings, System; use type Interfaces.C.int, Interfaces.C.Strings.chars_ptr; package body FLTK.Dialogs is procedure dialog_fl_alert (M : in Interfaces.C.char_array); pragma Import (C, dialog_fl_alert, "dialog_fl_alert"); pragma Inline (dialog_fl_alert); -- function dialog_fl_ask -- (M : in Interfaces.C.char_array) -- return Interfaces.C.int; -- pragma Import (C, dialog_fl_ask, "dialog_fl_ask"); -- pragma Inline (dialog_fl_ask); procedure dialog_fl_beep (B : in Interfaces.C.int); pragma Import (C, dialog_fl_beep, "dialog_fl_beep"); pragma Inline (dialog_fl_beep); function dialog_fl_choice (M, A, B, C : in Interfaces.C.char_array) return Interfaces.C.int; pragma Import (C, dialog_fl_choice, "dialog_fl_choice"); pragma Inline (dialog_fl_choice); function dialog_fl_input (M, D : in Interfaces.C.char_array) return Interfaces.C.Strings.chars_ptr; pragma Import (C, dialog_fl_input, "dialog_fl_input"); pragma Inline (dialog_fl_input); procedure dialog_fl_message (M : in Interfaces.C.char_array); pragma Import (C, dialog_fl_message, "dialog_fl_message"); pragma Inline (dialog_fl_message); function dialog_fl_password (M, D : in Interfaces.C.char_array) return Interfaces.C.Strings.chars_ptr; pragma Import (C, dialog_fl_password, "dialog_fl_password"); pragma Inline (dialog_fl_password); function dialog_fl_color_chooser (N : in Interfaces.C.char_array; R, G, B : in out Interfaces.C.double; M : in Interfaces.C.int) return Interfaces.C.int; pragma Import (C, dialog_fl_color_chooser, "dialog_fl_color_chooser"); pragma Inline (dialog_fl_color_chooser); function dialog_fl_color_chooser2 (N : in Interfaces.C.char_array; R, G, B : in out Interfaces.C.unsigned_char; M : in Interfaces.C.int) return Interfaces.C.int; pragma Import (C, dialog_fl_color_chooser2, "dialog_fl_color_chooser2"); pragma Inline (dialog_fl_color_chooser2); function dialog_fl_dir_chooser (M, D : in Interfaces.C.char_array; R : in Interfaces.C.int) return Interfaces.C.Strings.chars_ptr; pragma Import (C, dialog_fl_dir_chooser, "dialog_fl_dir_chooser"); pragma Inline (dialog_fl_dir_chooser); function dialog_fl_file_chooser (M, P, D : in Interfaces.C.char_array; R : in Interfaces.C.int) return Interfaces.C.Strings.chars_ptr; pragma Import (C, dialog_fl_file_chooser, "dialog_fl_file_chooser"); pragma Inline (dialog_fl_file_chooser); function dialog_fl_get_message_hotspot return Interfaces.C.int; pragma Import (C, dialog_fl_get_message_hotspot, "dialog_fl_get_message_hotspot"); pragma Inline (dialog_fl_get_message_hotspot); procedure dialog_fl_set_message_hotspot (V : in Interfaces.C.int); pragma Import (C, dialog_fl_set_message_hotspot, "dialog_fl_set_message_hotspot"); pragma Inline (dialog_fl_set_message_hotspot); procedure dialog_fl_message_font (F, S : in Interfaces.C.int); pragma Import (C, dialog_fl_message_font, "dialog_fl_message_font"); pragma Inline (dialog_fl_message_font); function dialog_fl_message_icon return System.Address; pragma Import (C, dialog_fl_message_icon, "dialog_fl_message_icon"); pragma Inline (dialog_fl_message_icon); procedure dialog_fl_message_title (T : in Interfaces.C.char_array); pragma Import (C, dialog_fl_message_title, "dialog_fl_message_title"); pragma Inline (dialog_fl_message_title); procedure dialog_fl_message_title_default (T : in Interfaces.C.char_array); pragma Import (C, dialog_fl_message_title_default, "dialog_fl_message_title_default"); pragma Inline (dialog_fl_message_title_default); procedure Alert (Message : String) is begin dialog_fl_alert (Interfaces.C.To_C (Message)); end Alert; -- function Ask -- (Message : in String) -- return Boolean is -- begin -- return dialog_fl_ask (Interfaces.C.To_C (Message)) /= 0; -- end Ask; procedure Beep (Kind : in Beep_Kind) is begin dialog_fl_beep (Beep_Kind'Pos (Kind)); end Beep; function Three_Way_Choice (Message, Button1, Button2, Button3 : in String) return Choice is Result : Interfaces.C.int := dialog_fl_choice (Interfaces.C.To_C (Message), Interfaces.C.To_C (Button1), Interfaces.C.To_C (Button2), Interfaces.C.To_C (Button3)); begin return Choice'Val (Result); end Three_Way_Choice; function Text_Input (Message : in String; Default : in String := "") return String is Result : Interfaces.C.Strings.chars_ptr := dialog_fl_input (Interfaces.C.To_C (Message), Interfaces.C.To_C (Default)); begin -- string does not need dealloc if Result = Interfaces.C.Strings.Null_Ptr then return ""; else return Interfaces.C.Strings.Value (Result); end if; end Text_Input; procedure Message_Box (Message : in String) is begin dialog_fl_message (Interfaces.C.To_C (Message)); end Message_Box; function Password (Message : in String; Default : in String := "") return String is Result : Interfaces.C.Strings.chars_ptr := dialog_fl_password (Interfaces.C.To_C (Message), Interfaces.C.To_C (Default)); begin -- string does not need dealloc if Result = Interfaces.C.Strings.Null_Ptr then return ""; else return Interfaces.C.Strings.Value (Result); end if; end Password; function Color_Chooser (Title : in String; R, G, B : in out RGB_Float; Mode : in FLTK.Widgets.Groups.Color_Choosers.Color_Mode := FLTK.Widgets.Groups.Color_Choosers.RGB) return Boolean is C_R : Interfaces.C.double := Interfaces.C.double (R); C_G : Interfaces.C.double := Interfaces.C.double (G); C_B : Interfaces.C.double := Interfaces.C.double (B); M : Interfaces.C.int := FLTK.Widgets.Groups.Color_Choosers.Color_Mode'Pos (Mode); Result : Boolean := dialog_fl_color_chooser (Interfaces.C.To_C (Title), C_R, C_G, C_B, M) /= 0; begin R := RGB_Float (C_R); G := RGB_Float (C_G); B := RGB_Float (C_B); return Result; end Color_Chooser; function Color_Chooser (Title : in String; R, G, B : in out RGB_Int; Mode : in FLTK.Widgets.Groups.Color_Choosers.Color_Mode := FLTK.Widgets.Groups.Color_Choosers.RGB) return Boolean is C_R : Interfaces.C.unsigned_char := Interfaces.C.unsigned_char (R); C_G : Interfaces.C.unsigned_char := Interfaces.C.unsigned_char (G); C_B : Interfaces.C.unsigned_char := Interfaces.C.unsigned_char (B); M : Interfaces.C.int := FLTK.Widgets.Groups.Color_Choosers.Color_Mode'Pos (Mode); Result : Boolean := dialog_fl_color_chooser2 (Interfaces.C.To_C (Title), C_R, C_G, C_B, M) /= 0; begin R := RGB_Int (C_R); G := RGB_Int (C_G); B := RGB_Int (C_B); return Result; end Color_Chooser; function Dir_Chooser (Message, Default : in String; Relative : in Boolean := False) return String is Result : Interfaces.C.Strings.chars_ptr := dialog_fl_dir_chooser (Interfaces.C.To_C (Message), Interfaces.C.To_C (Default), Boolean'Pos (Relative)); begin -- I'm... fairly sure the string does not need dealloc? if Result = Interfaces.C.Strings.Null_Ptr then return ""; else return Interfaces.C.Strings.Value (Result); end if; end Dir_Chooser; function File_Chooser (Message, Filter_Pattern, Default : in String; Relative : in Boolean := False) return String is Result : Interfaces.C.Strings.chars_ptr := dialog_fl_file_chooser (Interfaces.C.To_C (Message), Interfaces.C.To_C (Filter_Pattern), Interfaces.C.To_C (Default), Boolean'Pos (Relative)); begin -- I'm... fairly sure the string does not need dealloc? if Result = Interfaces.C.Strings.Null_Ptr then return ""; else return Interfaces.C.Strings.Value (Result); end if; end File_Chooser; function Get_Hotspot return Boolean is begin return dialog_fl_get_message_hotspot /= 0; end Get_Hotspot; procedure Set_Hotspot (To : in Boolean) is begin dialog_fl_set_message_hotspot (Boolean'Pos (To)); end Set_Hotspot; procedure Set_Message_Font (Font : in Font_Kind; Size : in Font_Size) is begin dialog_fl_message_font (Font_Kind'Pos (Font), Interfaces.C.int (Size)); end Set_Message_Font; function Get_Message_Icon return FLTK.Widgets.Boxes.Box_Reference is begin return (Data => Icon_Box'Access); end Get_Message_Icon; procedure Set_Message_Title (To : in String) is begin dialog_fl_message_title (Interfaces.C.To_C (To)); end Set_Message_Title; procedure Set_Message_Title_Default (To : in String) is begin dialog_fl_message_title_default (Interfaces.C.To_C (To)); end Set_Message_Title_Default; begin Wrapper (Icon_Box).Void_Ptr := dialog_fl_message_icon; Wrapper (Icon_Box).Needs_Dealloc := False; end FLTK.Dialogs;
MinimSecure/unum-sdk
Ada
1,020
adb
-- Copyright 2012-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/>. procedure Foo is type Discriminants_Record (A : Integer; B : Boolean) is record C : Float; end record; -- The following variable is unused on purpose, and might be -- optimized out by the compiler. Z : Discriminants_Record := (A => 1, B => False, C => 2.0); begin null; end Foo;
reznikmm/matreshka
Ada
7,120
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Text.List_Level_Style_Number_Elements is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Text_List_Level_Style_Number_Element_Node is begin return Self : Text_List_Level_Style_Number_Element_Node do Matreshka.ODF_Text.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Text_Prefix); end return; end Create; ---------------- -- Enter_Node -- ---------------- overriding procedure Enter_Node (Self : not null access Text_List_Level_Style_Number_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Enter_Text_List_Level_Style_Number (ODF.DOM.Text_List_Level_Style_Number_Elements.ODF_Text_List_Level_Style_Number_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Enter_Node (Visitor, Control); end if; end Enter_Node; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Text_List_Level_Style_Number_Element_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.List_Level_Style_Number_Element; end Get_Local_Name; ---------------- -- Leave_Node -- ---------------- overriding procedure Leave_Node (Self : not null access Text_List_Level_Style_Number_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Leave_Text_List_Level_Style_Number (ODF.DOM.Text_List_Level_Style_Number_Elements.ODF_Text_List_Level_Style_Number_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Leave_Node (Visitor, Control); end if; end Leave_Node; ---------------- -- Visit_Node -- ---------------- overriding procedure Visit_Node (Self : not null access Text_List_Level_Style_Number_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then ODF.DOM.Iterators.Abstract_ODF_Iterator'Class (Iterator).Visit_Text_List_Level_Style_Number (Visitor, ODF.DOM.Text_List_Level_Style_Number_Elements.ODF_Text_List_Level_Style_Number_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Visit_Node (Iterator, Visitor, Control); end if; end Visit_Node; begin Matreshka.DOM_Documents.Register_Element (Matreshka.ODF_String_Constants.Text_URI, Matreshka.ODF_String_Constants.List_Level_Style_Number_Element, Text_List_Level_Style_Number_Element_Node'Tag); end Matreshka.ODF_Text.List_Level_Style_Number_Elements;
ekoeppen/STM32_Generic_Ada_Drivers
Ada
12,491
ads
pragma Style_Checks (Off); -- This spec has been automatically generated from STM32L0x3.svd pragma Restrictions (No_Elaboration_Code); with System; package STM32_SVD.SPI is pragma Preelaborate; --------------- -- Registers -- --------------- subtype CR1_CPHA_Field is STM32_SVD.Bit; subtype CR1_CPOL_Field is STM32_SVD.Bit; subtype CR1_MSTR_Field is STM32_SVD.Bit; subtype CR1_BR_Field is STM32_SVD.UInt3; subtype CR1_SPE_Field is STM32_SVD.Bit; subtype CR1_LSBFIRST_Field is STM32_SVD.Bit; subtype CR1_SSI_Field is STM32_SVD.Bit; subtype CR1_SSM_Field is STM32_SVD.Bit; subtype CR1_RXONLY_Field is STM32_SVD.Bit; subtype CR1_DFF_Field is STM32_SVD.Bit; subtype CR1_CRCNEXT_Field is STM32_SVD.Bit; subtype CR1_CRCEN_Field is STM32_SVD.Bit; subtype CR1_BIDIOE_Field is STM32_SVD.Bit; subtype CR1_BIDIMODE_Field is STM32_SVD.Bit; -- control register 1 type CR1_Register is record -- Clock phase CPHA : CR1_CPHA_Field := 16#0#; -- Clock polarity CPOL : CR1_CPOL_Field := 16#0#; -- Master selection MSTR : CR1_MSTR_Field := 16#0#; -- Baud rate control BR : CR1_BR_Field := 16#0#; -- SPI enable SPE : CR1_SPE_Field := 16#0#; -- Frame format LSBFIRST : CR1_LSBFIRST_Field := 16#0#; -- Internal slave select SSI : CR1_SSI_Field := 16#0#; -- Software slave management SSM : CR1_SSM_Field := 16#0#; -- Receive only RXONLY : CR1_RXONLY_Field := 16#0#; -- Data frame format DFF : CR1_DFF_Field := 16#0#; -- CRC transfer next CRCNEXT : CR1_CRCNEXT_Field := 16#0#; -- Hardware CRC calculation enable CRCEN : CR1_CRCEN_Field := 16#0#; -- Output enable in bidirectional mode BIDIOE : CR1_BIDIOE_Field := 16#0#; -- Bidirectional data mode enable BIDIMODE : CR1_BIDIMODE_Field := 16#0#; -- unspecified Reserved_16_31 : STM32_SVD.UInt16 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for CR1_Register use record CPHA at 0 range 0 .. 0; CPOL at 0 range 1 .. 1; MSTR at 0 range 2 .. 2; BR at 0 range 3 .. 5; SPE at 0 range 6 .. 6; LSBFIRST at 0 range 7 .. 7; SSI at 0 range 8 .. 8; SSM at 0 range 9 .. 9; RXONLY at 0 range 10 .. 10; DFF at 0 range 11 .. 11; CRCNEXT at 0 range 12 .. 12; CRCEN at 0 range 13 .. 13; BIDIOE at 0 range 14 .. 14; BIDIMODE at 0 range 15 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype CR2_RXDMAEN_Field is STM32_SVD.Bit; subtype CR2_TXDMAEN_Field is STM32_SVD.Bit; subtype CR2_SSOE_Field is STM32_SVD.Bit; subtype CR2_FRF_Field is STM32_SVD.Bit; subtype CR2_ERRIE_Field is STM32_SVD.Bit; subtype CR2_RXNEIE_Field is STM32_SVD.Bit; subtype CR2_TXEIE_Field is STM32_SVD.Bit; -- control register 2 type CR2_Register is record -- Rx buffer DMA enable RXDMAEN : CR2_RXDMAEN_Field := 16#0#; -- Tx buffer DMA enable TXDMAEN : CR2_TXDMAEN_Field := 16#0#; -- SS output enable SSOE : CR2_SSOE_Field := 16#0#; -- unspecified Reserved_3_3 : STM32_SVD.Bit := 16#0#; -- Frame format FRF : CR2_FRF_Field := 16#0#; -- Error interrupt enable ERRIE : CR2_ERRIE_Field := 16#0#; -- RX buffer not empty interrupt enable RXNEIE : CR2_RXNEIE_Field := 16#0#; -- Tx buffer empty interrupt enable TXEIE : CR2_TXEIE_Field := 16#0#; -- unspecified Reserved_8_31 : STM32_SVD.UInt24 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for CR2_Register use record RXDMAEN at 0 range 0 .. 0; TXDMAEN at 0 range 1 .. 1; SSOE at 0 range 2 .. 2; Reserved_3_3 at 0 range 3 .. 3; FRF at 0 range 4 .. 4; ERRIE at 0 range 5 .. 5; RXNEIE at 0 range 6 .. 6; TXEIE at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype SR_RXNE_Field is STM32_SVD.Bit; subtype SR_TXE_Field is STM32_SVD.Bit; subtype SR_CHSIDE_Field is STM32_SVD.Bit; subtype SR_UDR_Field is STM32_SVD.Bit; subtype SR_CRCERR_Field is STM32_SVD.Bit; subtype SR_MODF_Field is STM32_SVD.Bit; subtype SR_OVR_Field is STM32_SVD.Bit; subtype SR_BSY_Field is STM32_SVD.Bit; subtype SR_TIFRFE_Field is STM32_SVD.Bit; -- status register type SR_Register is record -- Read-only. Receive buffer not empty RXNE : SR_RXNE_Field := 16#0#; -- Read-only. Transmit buffer empty TXE : SR_TXE_Field := 16#1#; -- Read-only. Channel side CHSIDE : SR_CHSIDE_Field := 16#0#; -- Read-only. Underrun flag UDR : SR_UDR_Field := 16#0#; -- CRC error flag CRCERR : SR_CRCERR_Field := 16#0#; -- Read-only. Mode fault MODF : SR_MODF_Field := 16#0#; -- Read-only. Overrun flag OVR : SR_OVR_Field := 16#0#; -- Read-only. Busy flag BSY : SR_BSY_Field := 16#0#; -- Read-only. TI frame format error TIFRFE : SR_TIFRFE_Field := 16#0#; -- unspecified Reserved_9_31 : STM32_SVD.UInt23 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for SR_Register use record RXNE at 0 range 0 .. 0; TXE at 0 range 1 .. 1; CHSIDE at 0 range 2 .. 2; UDR at 0 range 3 .. 3; CRCERR at 0 range 4 .. 4; MODF at 0 range 5 .. 5; OVR at 0 range 6 .. 6; BSY at 0 range 7 .. 7; TIFRFE at 0 range 8 .. 8; Reserved_9_31 at 0 range 9 .. 31; end record; subtype DR_DR_Field is STM32_SVD.UInt16; -- data register type DR_Register is record -- Data register DR : DR_DR_Field := 16#0#; -- unspecified Reserved_16_31 : STM32_SVD.UInt16 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for DR_Register use record DR at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype CRCPR_CRCPOLY_Field is STM32_SVD.UInt16; -- CRC polynomial register type CRCPR_Register is record -- CRC polynomial register CRCPOLY : CRCPR_CRCPOLY_Field := 16#7#; -- unspecified Reserved_16_31 : STM32_SVD.UInt16 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for CRCPR_Register use record CRCPOLY at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype RXCRCR_RxCRC_Field is STM32_SVD.UInt16; -- RX CRC register type RXCRCR_Register is record -- Read-only. Rx CRC register RxCRC : RXCRCR_RxCRC_Field; -- unspecified Reserved_16_31 : STM32_SVD.UInt16; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for RXCRCR_Register use record RxCRC at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype TXCRCR_TxCRC_Field is STM32_SVD.UInt16; -- TX CRC register type TXCRCR_Register is record -- Read-only. Tx CRC register TxCRC : TXCRCR_TxCRC_Field; -- unspecified Reserved_16_31 : STM32_SVD.UInt16; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for TXCRCR_Register use record TxCRC at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype I2SCFGR_CHLEN_Field is STM32_SVD.Bit; subtype I2SCFGR_DATLEN_Field is STM32_SVD.UInt2; subtype I2SCFGR_CKPOL_Field is STM32_SVD.Bit; subtype I2SCFGR_I2SSTD_Field is STM32_SVD.UInt2; subtype I2SCFGR_PCMSYNC_Field is STM32_SVD.Bit; subtype I2SCFGR_I2SCFG_Field is STM32_SVD.UInt2; subtype I2SCFGR_I2SE_Field is STM32_SVD.Bit; subtype I2SCFGR_I2SMOD_Field is STM32_SVD.Bit; -- I2S configuration register type I2SCFGR_Register is record -- Channel length (number of bits per audio channel) CHLEN : I2SCFGR_CHLEN_Field := 16#0#; -- Data length to be transferred DATLEN : I2SCFGR_DATLEN_Field := 16#0#; -- Steady state clock polarity CKPOL : I2SCFGR_CKPOL_Field := 16#0#; -- I2S standard selection I2SSTD : I2SCFGR_I2SSTD_Field := 16#0#; -- unspecified Reserved_6_6 : STM32_SVD.Bit := 16#0#; -- PCM frame synchronization PCMSYNC : I2SCFGR_PCMSYNC_Field := 16#0#; -- I2S configuration mode I2SCFG : I2SCFGR_I2SCFG_Field := 16#0#; -- I2S Enable I2SE : I2SCFGR_I2SE_Field := 16#0#; -- I2S mode selection I2SMOD : I2SCFGR_I2SMOD_Field := 16#0#; -- unspecified Reserved_12_31 : STM32_SVD.UInt20 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for I2SCFGR_Register use record CHLEN at 0 range 0 .. 0; DATLEN at 0 range 1 .. 2; CKPOL at 0 range 3 .. 3; I2SSTD at 0 range 4 .. 5; Reserved_6_6 at 0 range 6 .. 6; PCMSYNC at 0 range 7 .. 7; I2SCFG at 0 range 8 .. 9; I2SE at 0 range 10 .. 10; I2SMOD at 0 range 11 .. 11; Reserved_12_31 at 0 range 12 .. 31; end record; subtype I2SPR_I2SDIV_Field is STM32_SVD.Byte; subtype I2SPR_ODD_Field is STM32_SVD.Bit; subtype I2SPR_MCKOE_Field is STM32_SVD.Bit; -- I2S prescaler register type I2SPR_Register is record -- I2S Linear prescaler I2SDIV : I2SPR_I2SDIV_Field := 16#10#; -- Odd factor for the prescaler ODD : I2SPR_ODD_Field := 16#0#; -- Master clock output enable MCKOE : I2SPR_MCKOE_Field := 16#0#; -- unspecified Reserved_10_31 : STM32_SVD.UInt22 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for I2SPR_Register use record I2SDIV at 0 range 0 .. 7; ODD at 0 range 8 .. 8; MCKOE at 0 range 9 .. 9; Reserved_10_31 at 0 range 10 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Serial peripheral interface type SPI_Peripheral is record -- control register 1 CR1 : aliased CR1_Register; -- control register 2 CR2 : aliased CR2_Register; -- status register SR : aliased SR_Register; -- data register DR : aliased DR_Register; -- CRC polynomial register CRCPR : aliased CRCPR_Register; -- RX CRC register RXCRCR : aliased RXCRCR_Register; -- TX CRC register TXCRCR : aliased TXCRCR_Register; -- I2S configuration register I2SCFGR : aliased I2SCFGR_Register; -- I2S prescaler register I2SPR : aliased I2SPR_Register; end record with Volatile; for SPI_Peripheral use record CR1 at 16#0# range 0 .. 31; CR2 at 16#4# range 0 .. 31; SR at 16#8# range 0 .. 31; DR at 16#C# range 0 .. 31; CRCPR at 16#10# range 0 .. 31; RXCRCR at 16#14# range 0 .. 31; TXCRCR at 16#18# range 0 .. 31; I2SCFGR at 16#1C# range 0 .. 31; I2SPR at 16#20# range 0 .. 31; end record; -- Serial peripheral interface SPI1_Periph : aliased SPI_Peripheral with Import, Address => SPI1_Base; -- Serial peripheral interface SPI2_Periph : aliased SPI_Peripheral with Import, Address => SPI2_Base; end STM32_SVD.SPI;
io7m/coreland-opengl-ada
Ada
404
ads
with OpenGL.Types; package OpenGL.View is -- -- Viewport specification. -- -- proc_map : glDepthRange procedure Depth_Range (Near : in OpenGL.Types.Clamped_Double_t; Far : in OpenGL.Types.Clamped_Double_t); -- proc_map : glViewport procedure Viewport (Left : in Natural; Bottom : in Natural; Width : in Positive; Height : in Positive); end OpenGL.View;
reznikmm/matreshka
Ada
6,674
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011, 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 version of package intended to be used on POSIX systems. -- -- This package is conformant to "XDG Base Directory Specification". ------------------------------------------------------------------------------ separate (Matreshka.Internals.Settings.Ini_Managers) package body Paths is use type League.Characters.Universal_Character; HOME : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("HOME"); XDG_CONFIG_HOME : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("XDG_CONFIG_HOME"); XDG_CONFIG_DIRS : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("XDG_CONFIG_DIRS"); ------------------ -- System_Paths -- ------------------ function System_Paths return League.String_Vectors.Universal_String_Vector is Dirs : League.String_Vectors.Universal_String_Vector; Path : League.Strings.Universal_String; Paths : League.String_Vectors.Universal_String_Vector; begin -- Looking for XDG_CONFIG_DIRS environment variable and construct list -- directories from its value. if League.Application.Environment.Contains (XDG_CONFIG_DIRS) then Dirs := League.Application.Environment.Value (XDG_CONFIG_DIRS).Split (':', League.Strings.Skip_Empty); for J in 1 .. Dirs.Length loop Path := Dirs.Element (J); -- Resolve relative paths relativealy home directory. if Path.Element (1) /= '/' then Path := League.Application.Environment.Value (HOME) & '/' & Path; end if; -- Check for trailing path separator and add it when necessary. if Path.Element (Path.Length) /= '/' then Path.Append ('/'); end if; Paths.Append (Path); end loop; end if; -- Use default directory when directories list is not constructed. if Paths.Is_Empty then Paths.Append (League.Strings.To_Universal_String ("/etc/xdg/")); end if; return Paths; end System_Paths; --------------- -- User_Path -- --------------- function User_Path return League.Strings.Universal_String is Path : League.Strings.Universal_String; begin -- First, looking for XDG_CONFIG_HOME environment variable, it overrides -- default path. if League.Application.Environment.Contains (XDG_CONFIG_HOME) then Path := League.Application.Environment.Value (XDG_CONFIG_HOME); end if; -- When XDG_CONFIG_HOME environment variable is not defined, use -- $HOME/.config directory. if Path.Is_Empty then Path := League.Application.Environment.Value (HOME) & '/' & ".config"; -- Otherwise, when XDG_CONFIG_HOME is relative path, construct full -- path as $HOME/$XDG_CONFIG_HOME. elsif Path.Element (1).To_Wide_Wide_Character /= '/' then Path := League.Application.Environment.Value (HOME) & '/' & Path; end if; -- Check for trailing path separator and add it when necessary. if Path.Element (Path.Length) /= '/' then Path.Append ('/'); end if; return Path; end User_Path; end Paths;
zhmu/ananas
Ada
53,841
ads
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- C H E C K S -- -- -- -- S p e c -- -- -- -- Copyright (C) 1992-2022, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- Package containing routines used to deal with run-time checks. These -- routines are used both by the semantics and by the expander. In some -- cases, checks are enabled simply by setting a flag for the back end, -- and in other cases the code for the check is expanded. -- The approach used for range and length checks, in regards to suppressed -- checks, is to attempt to detect at compilation time that a constraint -- error will occur. If this is detected a warning or error is issued and the -- offending expression or statement replaced with a constraint error node. -- This always occurs whether checks are suppressed or not. Dynamic range -- checks are, of course, not inserted if checks are suppressed. with Errout; use Errout; with Namet; use Namet; with Table; with Types; use Types; with Uintp; use Uintp; with Urealp; use Urealp; package Checks is type Bit_Vector is array (Pos range <>) of Boolean; type Dimension_Set (Dimensions : Nat) is record Elements : Bit_Vector (1 .. Dimensions); end record; Empty_Dimension_Set : constant Dimension_Set := (Dimensions => 0, Elements => (others => <>)); procedure Initialize; -- Called for each new main source program, to initialize internal -- variables used in the package body of the Checks unit. function Access_Checks_Suppressed (E : Entity_Id) return Boolean; function Accessibility_Checks_Suppressed (E : Entity_Id) return Boolean; function Alignment_Checks_Suppressed (E : Entity_Id) return Boolean; function Allocation_Checks_Suppressed (E : Entity_Id) return Boolean; function Atomic_Synchronization_Disabled (E : Entity_Id) return Boolean; function Discriminant_Checks_Suppressed (E : Entity_Id) return Boolean; function Division_Checks_Suppressed (E : Entity_Id) return Boolean; function Duplicated_Tag_Checks_Suppressed (E : Entity_Id) return Boolean; function Elaboration_Checks_Suppressed (E : Entity_Id) return Boolean; function Index_Checks_Suppressed (E : Entity_Id) return Boolean; function Length_Checks_Suppressed (E : Entity_Id) return Boolean; function Overflow_Checks_Suppressed (E : Entity_Id) return Boolean; function Predicate_Checks_Suppressed (E : Entity_Id) return Boolean; function Range_Checks_Suppressed (E : Entity_Id) return Boolean; function Storage_Checks_Suppressed (E : Entity_Id) return Boolean; function Tag_Checks_Suppressed (E : Entity_Id) return Boolean; -- These functions check to see if the named check is suppressed, either -- by an active scope suppress setting, or because the check has been -- specifically suppressed for the given entity. If no entity is relevant -- for the current check, then Empty is used as an argument. Note: the -- reason we insist on specifying Empty is to force the caller to think -- about whether there is any relevant entity that should be checked. function Is_Check_Suppressed (E : Entity_Id; C : Check_Id) return Boolean; -- This function is called if Checks_May_Be_Suppressed (E) is True to -- determine whether check C is suppressed either on the entity E or -- as the result of a scope suppress pragma. If Checks_May_Be_Suppressed -- is False, then the status of the check can be determined simply by -- examining Scope_Suppress, so this routine is not called in that case. function Overflow_Check_Mode return Overflow_Mode_Type; -- Returns current overflow checking mode, taking into account whether -- we are inside an assertion expression and the assertion policy. ----------------------------------------- -- Control of Alignment Check Warnings -- ----------------------------------------- -- When we have address clauses, there is an issue of whether the address -- specified is appropriate to the alignment. In the general case where the -- address is dynamic, we generate a check and a possible warning (this -- warning occurs for example if we have a restricted runtime with the -- restriction No_Exception_Propagation). We also issue this warning in -- the case where the address is static, but we don't know the alignment -- at the time we process the address clause. In such a case, we issue the -- warning, but we may be able to find out later (after the back end has -- annotated the actual alignment chosen) that the warning was not needed. -- To deal with deleting these potentially annoying warnings, we save the -- warning information in a table, and then delete the warnings in the -- post compilation validation stage if we can tell that the check would -- never fail (in general the back end will also optimize away the check -- in such cases). -- Table used to record information type Alignment_Warnings_Record is record E : Entity_Id; -- Entity whose alignment possibly warrants a warning A : Uint; -- Compile time known value of address clause for which the alignment -- is to be checked once we know the alignment. P : Node_Id; -- Prefix of address clause when it is of the form X'Address W : Error_Msg_Id; -- Id of warning message we might delete end record; package Alignment_Warnings is new Table.Table ( Table_Component_Type => Alignment_Warnings_Record, Table_Index_Type => Int, Table_Low_Bound => 0, Table_Initial => 10, Table_Increment => 200, Table_Name => "Alignment_Warnings"); procedure Validate_Alignment_Check_Warnings; -- This routine is called after back annotation of type data to delete any -- alignment warnings that turn out to be false alarms, based on knowing -- the actual alignment, and a compile-time known alignment value. ------------------------------------------- -- Procedures to Activate Checking Flags -- ------------------------------------------- procedure Activate_Division_Check (N : Node_Id); pragma Inline (Activate_Division_Check); -- Sets Do_Division_Check flag in node N, and handles possible local raise. -- Always call this routine rather than calling Set_Do_Division_Check to -- set an explicit value of True, to ensure handling the local raise case. procedure Activate_Overflow_Check (N : Node_Id); pragma Inline (Activate_Overflow_Check); -- Sets Do_Overflow_Check flag in node N, and handles possible local raise. -- Always call this routine rather than calling Set_Do_Overflow_Check to -- set an explicit value of True, to ensure handling the local raise case. -- Note that for discrete types, this call has no effect for MOD, REM, and -- unary "+" for which overflow is never possible in any case. -- -- Note: for the discrete-type case, it is legitimate to call this routine -- on an unanalyzed node where the Etype field is not set. However, for the -- floating-point case, Etype must be set (to a floating-point type). -- -- For floating-point, we set the flag if we have automatic overflow checks -- on the target, or if Check_Float_Overflow mode is set. For the floating- -- point case, we ignore all the unary operators ("+", "-", and abs) since -- none of these can result in overflow. If there are no overflow checks on -- the target, and Check_Float_Overflow mode is not set, then the call has -- no effect, since in such cases we want to generate NaN's and infinities. procedure Activate_Range_Check (N : Node_Id); pragma Inline (Activate_Range_Check); -- Sets Do_Range_Check flag in node N, and handles possible local raise. -- Always call this routine rather than calling Set_Do_Range_Check to -- set an explicit value of True, to ensure handling the local raise case. -------------------------------- -- Procedures to Apply Checks -- -------------------------------- -- General note on following checks. These checks are always active if -- Expander_Active and not Inside_A_Generic. They are inactive and have -- no effect Inside_A_Generic. In the case where not Expander_Active -- and not Inside_A_Generic, most of them are inactive, but some of them -- operate anyway since they may generate useful compile time warnings. procedure Apply_Access_Check (N : Node_Id); -- Determines whether an expression node requires a run-time access -- check and if so inserts the appropriate run-time check. procedure Apply_Accessibility_Check (N : Node_Id; Typ : Entity_Id; Insert_Node : Node_Id); -- Given a name N denoting an access parameter, emits a run-time -- accessibility check (if necessary), checking that the level of -- the object denoted by the access parameter is not deeper than the -- level of the type Typ. Program_Error is raised if the check fails. -- Insert_Node indicates the node where the check should be inserted. procedure Apply_Address_Clause_Check (E : Entity_Id; N : Node_Id); -- E is the entity for an object which has an address clause. If checks -- are enabled, then this procedure generates a check that the specified -- address has an alignment consistent with the alignment of the object, -- raising PE if this is not the case. The resulting check (if one is -- generated) is prepended to the Actions list of N_Freeze_Entity node N. -- Note that the check references E'Alignment, so it cannot be emitted -- before N (its freeze node), otherwise this would cause an illegal -- access before elaboration error in gigi. For the case of a clear overlay -- situation, we also check that the size of the overlaying object is not -- larger than the overlaid object. procedure Apply_Arithmetic_Overflow_Check (N : Node_Id); -- Handle overflow checking for an arithmetic operator. Also handles the -- cases of ELIMINATED and MINIMIZED overflow checking mode. If the mode -- is one of the latter two, then this routine can also be called with -- an if or case expression node to make sure that we properly handle -- overflow checking for dependent expressions. This routine handles -- front end vs back end overflow checks (in the front end case it expands -- the necessary check). Note that divide is handled separately using -- Apply_Divide_Checks. Node N may or may not have Do_Overflow_Check. -- In STRICT mode, there is nothing to do if this flag is off, but in -- MINIMIZED/ELIMINATED mode we still have to deal with possible use -- of doing operations in Long_Long_Integer or Bignum mode. procedure Apply_Constraint_Check (N : Node_Id; Typ : Entity_Id; No_Sliding : Boolean := False); -- Top-level procedure, calls all the others depending on the class of -- Typ. Checks that expression N satisfies the constraint of type Typ. -- No_Sliding is only relevant for constrained array types, if set to -- True, it checks that indexes are in range. procedure Apply_Discriminant_Check (N : Node_Id; Typ : Entity_Id; Lhs : Node_Id := Empty); -- Given an expression N of a discriminated type, or of an access type -- whose designated type is a discriminanted type, generates a check to -- ensure that the expression can be converted to the subtype given as -- the second parameter. Lhs is empty except in the case of assignments, -- where the target object may be needed to determine the subtype to -- check against (such as the cases of unconstrained formal parameters -- and unconstrained aliased objects). For the case of unconstrained -- formals, the check is performed only if the corresponding actual is -- constrained, i.e., whether Lhs'Constrained is True. procedure Apply_Divide_Checks (N : Node_Id); -- The node kind is N_Op_Divide, N_Op_Mod, or N_Op_Rem if either of the -- flags Do_Division_Check or Do_Overflow_Check is set, then this routine -- ensures that the appropriate checks are made. Note that overflow can -- occur in the signed case for the case of the largest negative number -- divided by minus one. This procedure only applies to Integer types. procedure Apply_Parameter_Aliasing_Checks (Call : Node_Id; Subp : Entity_Id); -- Given a subprogram call Call, add a check to verify that none of the -- actuals overlap. Subp denotes the subprogram being called. procedure Apply_Parameter_Validity_Checks (Subp : Entity_Id); -- Given a subprogram Subp, add both a pre and post condition pragmas that -- verify the proper initialization of scalars in parameters and function -- results. procedure Apply_Predicate_Check (N : Node_Id; Typ : Entity_Id; Fun : Entity_Id := Empty); -- N is an expression to which a predicate check may need to be applied for -- Typ, if Typ has a predicate function. When N is an actual in a call, Fun -- is the function being called, which is used to generate a better warning -- if the call leads to an infinite recursion. procedure Apply_Type_Conversion_Checks (N : Node_Id); -- N is an N_Type_Conversion node. A type conversion actually involves -- two sorts of checks. The first check is the checks that ensures that -- the operand in the type conversion fits onto the base type of the -- subtype it is being converted to (see RM 4.6 (28)-(50)). The second -- check is there to ensure that once the operand has been converted to -- a value of the target type, this converted value meets the -- constraints imposed by the target subtype (see RM 4.6 (51)). procedure Apply_Universal_Integer_Attribute_Checks (N : Node_Id); -- The argument N is an attribute reference node intended for processing -- by gigi. The attribute is one that returns a universal integer, but -- the attribute reference node is currently typed with the expected -- result type. This routine deals with range and overflow checks needed -- to make sure that the universal result is in range. function Build_Discriminant_Checks (N : Node_Id; T_Typ : Entity_Id) return Node_Id; -- Subsidiary routine for Apply_Discriminant_Check. Builds the expression -- that compares discriminants of the expression with discriminants of the -- type. Also used directly for membership tests (see Exp_Ch4.Expand_N_In). function Convert_From_Bignum (N : Node_Id) return Node_Id; -- Returns result of converting node N from Bignum. The returned value is -- not analyzed, the caller takes responsibility for this. Node N must be -- a subexpression node of type Bignum. The result is Long_Long_Integer. function Convert_To_Bignum (N : Node_Id) return Node_Id; -- Returns result of converting node N to Bignum. The returned value is not -- analyzed, the caller takes responsibility for this. Node N must be a -- subexpression node of a signed integer type or Bignum type (if it is -- already a Bignum, the returned value is Relocate_Node (N)). procedure Determine_Range (N : Node_Id; OK : out Boolean; Lo : out Uint; Hi : out Uint; Assume_Valid : Boolean := False); -- N is a node for a subexpression. If N is of a discrete type with no -- error indications, and no other peculiarities (e.g. missing Etype), -- then OK is True on return, and Lo and Hi are set to a conservative -- estimate of the possible range of values of N. Thus if OK is True on -- return, the value of the subexpression N is known to lie in the range -- Lo .. Hi (inclusive). For enumeration and character literals the values -- returned are the Pos value in the relevant enumeration type. If the -- expression is not of a discrete type, or some kind of error condition -- is detected, then OK is False on exit, and Lo/Hi are set to No_Uint. -- Thus the significance of OK being False on return is that no useful -- information is available on the range of the expression. Assume_Valid -- determines whether the processing is allowed to assume that values are -- in range of their subtypes. If it is set to True, then this assumption -- is valid, if False, then processing is done using base types to allow -- invalid values. procedure Determine_Range_R (N : Node_Id; OK : out Boolean; Lo : out Ureal; Hi : out Ureal; Assume_Valid : Boolean := False); -- Similar to Determine_Range, but for a node N of floating-point type. OK -- is True on return only for IEEE floating-point types and only if we do -- not have to worry about extended precision (i.e. on the x86, we must be -- using -msse2 -mfpmath=sse). At the current time, this is used only in -- GNATprove, though we could consider using it more generally in future. -- For that to happen, the possibility of arguments of infinite or NaN -- value should be taken into account, which is not the case currently. procedure Determine_Range_To_Discrete (N : Node_Id; OK : out Boolean; Lo : out Uint; Hi : out Uint; Fixed_Int : Boolean := False; Assume_Valid : Boolean := False); -- Similar to Determine_Range, but attempts to return a discrete range even -- if N is not of a discrete type by doing a conversion. The Fixed_Int flag -- if set causes any fixed-point values to be treated as though they were -- discrete values (i.e. the underlying integer value is used), in which -- case no conversion is needed. At the current time, this is used only for -- discrete types, for fixed-point types if Fixed_Int is set, and also for -- floating-point types in GNATprove, see Determine_Range_R above. procedure Install_Null_Excluding_Check (N : Node_Id); -- Determines whether an access node requires a run-time access check and -- if so inserts the appropriate run-time check. procedure Install_Primitive_Elaboration_Check (Subp_Body : Node_Id); -- Insert a check to ensure that subprogram body Subp_Body has been -- properly elaborated. The check is installed only when Subp_Body is the -- body of a nonabstract library-level primitive of a tagged type. Further -- restrictions may apply, see the body for details. function Make_Bignum_Block (Loc : Source_Ptr) return Node_Id; -- This function is used by top level overflow checking routines to do a -- mark/release operation on the secondary stack around bignum operations. -- The block created looks like: -- -- declare -- M : Mark_Id := SS_Mark; -- begin -- SS_Release (M); -- end; -- -- The idea is that the caller will insert any needed extra declarations -- after the declaration of M, and any needed statements (in particular -- the bignum operations) before the call to SS_Release, and then do an -- Insert_Action of the whole block (it is returned unanalyzed). The Loc -- parameter is used to supply Sloc values for the constructed tree. procedure Minimize_Eliminate_Overflows (N : Node_Id; Lo : out Uint; Hi : out Uint; Top_Level : Boolean); -- This is the main routine for handling MINIMIZED and ELIMINATED overflow -- processing. On entry N is a node whose result is a signed integer -- subtype. The Do_Overflow_Check flag may or may not be set on N. If the -- node is an arithmetic operation, then a range analysis is carried out, -- and there are three possibilities: -- -- The node is left unchanged (apart from expansion of an exponentiation -- operation). This happens if the routine can determine that the result -- is definitely in range. The Do_Overflow_Check flag is turned off in -- this case. -- -- The node is transformed into an arithmetic operation with a result -- type of Long_Long_Integer. -- -- The node is transformed into a function call that calls an appropriate -- function in the System.Bignums package to compute a Bignum result. -- -- In the first two cases, Lo and Hi are set to the bounds of the possible -- range of results, computed as accurately as possible. In the third case -- Lo and Hi are set to No_Uint (there are some cases where we could get an -- advantage from keeping result ranges for Bignum values, but it could use -- a lot of space and is very unlikely to be valuable). -- -- If the node is not an arithmetic operation, then it is unchanged but -- Lo and Hi are still set (to the bounds of the result subtype if nothing -- better can be determined). -- -- Note: this function is recursive, if called with an arithmetic operator, -- recursive calls are made to process the operands using this procedure. -- So we end up doing things top down. Nothing happens to an arithmetic -- expression until this procedure is called on the top level node and -- then the recursive calls process all the children. We have to do it -- this way. If we try to do it bottom up in natural expansion order, then -- there are two problems. First, where do we stash the bounds, and more -- importantly, semantic processing will be messed up. Consider A+B+C where -- A,B,C are all of type integer, if we processed A+B before doing semantic -- analysis of the addition of this result to C, that addition could end up -- with a Long_Long_Integer left operand and an Integer right operand, and -- we would get a semantic error. -- -- The routine is called in three situations if we are operating in either -- MINIMIZED or ELIMINATED modes. -- -- Overflow processing applied to the top node of an expression tree when -- that node is an arithmetic operator. In this case the result is -- converted to the appropriate result type (there is special processing -- when the parent is a conversion, see body for details). -- -- Overflow processing applied to the operands of a comparison operation. -- In this case, the comparison is done on the result Long_Long_Integer -- or Bignum values, without raising any exceptions. -- -- Overflow processing applied to the left operand of a membership test. -- In this case no exception is raised if a Long_Long_Integer or Bignum -- result is outside the range of the type of that left operand (it is -- just that the result of IN is false in that case). -- -- Note that if Bignum values appear, the caller must take care of doing -- the appropriate mark/release operations on the secondary stack. -- -- Top_Level is used to avoid inefficient unnecessary transitions into the -- Bignum domain. If Top_Level is True, it means that the caller will have -- to convert any Bignum value back to Long_Long_Integer, possibly checking -- that the value is in range. This is the normal case for a top level -- operator in a subexpression. There is no point in going into Bignum mode -- to avoid an overflow just so we can check for overflow the next moment. -- For calls from comparisons and membership tests, and for all recursive -- calls, we do want to transition into the Bignum domain if necessary. -- Note that this setting is only relevant in ELIMINATED mode. ------------------------------------------------------- -- Control and Optimization of Range/Overflow Checks -- ------------------------------------------------------- -- Range checks are controlled by the Do_Range_Check flag. The front end -- is responsible for setting this flag in relevant nodes. Originally the -- back end generated all the corresponding range checks, but later on we -- decided to generate all the range checks in the front end and this is -- the current situation. -- Overflow checks are similarly controlled by the Do_Overflow_Check flag. -- The difference here is that if back end overflow checks are inactive -- (Backend_Overflow_Checks_On_Target set False), then the actual overflow -- checks are generated by the front end, but if back end overflow checks -- are active (Backend_Overflow_Checks_On_Target set True), then the back -- end does generate the checks. -- The following two routines are used to set these flags, they allow -- for the possibility of eliminating checks. Checks can be eliminated -- if an identical check has already been performed. procedure Enable_Overflow_Check (N : Node_Id); -- First this routine determines if an overflow check is needed by doing -- an appropriate range check. If a check is not needed, then the call -- has no effect. If a check is needed then this routine sets the flag -- Do_Overflow_Check in node N to True, unless it can be determined that -- the check is not needed. The only condition under which this is the -- case is if there was an identical check earlier on. procedure Enable_Range_Check (N : Node_Id); -- Set Do_Range_Check flag in node N True, unless it can be determined -- that the check is not needed. The only condition under which this is -- the case is if there was an identical check earlier on. This routine -- is not responsible for doing range analysis to determine whether or -- not such a check is needed -- the caller is expected to do this. The -- one other case in which the request to set the flag is ignored is -- when Kill_Range_Check is set in an N_Unchecked_Conversion node. -- The following routines are used to keep track of processing sequences -- of statements (e.g. the THEN statements of an IF statement). A check -- that appears within such a sequence can eliminate an identical check -- within this sequence of statements. However, after the end of the -- sequence of statements, such a check is no longer of interest, since -- it may not have been executed. procedure Conditional_Statements_Begin; -- This call marks the start of processing of a sequence of statements. -- Every call to this procedure must be followed by a matching call to -- Conditional_Statements_End. procedure Conditional_Statements_End; -- This call removes from consideration all saved checks since the -- corresponding call to Conditional_Statements_Begin. These two -- procedures operate in a stack like manner. -- The mechanism for optimizing checks works by remembering checks -- that have already been made, but certain conditions, for example -- an assignment to a variable involved in a check, may mean that the -- remembered check is no longer valid, in the sense that if the same -- expression appears again, another check is required because the -- value may have changed. -- The following routines are used to note conditions which may render -- some or all of the stored and remembered checks to be invalidated. procedure Kill_Checks (V : Entity_Id); -- This procedure records an assignment or other condition that causes -- the value of the variable to be changed, invalidating any stored -- checks that reference the value. Note that all such checks must -- be discarded, even if they are not in the current statement range. procedure Kill_All_Checks; -- This procedure kills all remembered checks ----------------------------- -- Length and Range Checks -- ----------------------------- -- In the following procedures, there are three arguments which have -- a common meaning as follows: -- Expr The expression to be checked. If a check is required, -- the appropriate flag will be placed on this node. Whether -- this node is further examined depends on the setting of -- the parameter Source_Typ, as described below. -- Target_Typ The target type on which the check is to be based. For -- example, if we have a scalar range check, then the check -- is that we are in range of this type. -- Source_Typ Normally Empty, but can be set to a type, in which case -- this type is used for the check, see below. -- The checks operate in one of two modes: -- If Source_Typ is Empty, then the node Expr is examined, at the very -- least to get the source subtype. In addition for some of the checks, -- the actual form of the node may be examined. For example, a node of -- type Integer whose actual form is an Integer conversion from a type -- with range 0 .. 3 can be determined to have a value in range 0 .. 3. -- If Source_Typ is given, then nothing can be assumed about the Expr, -- and indeed its contents are not examined. In this case the check is -- based on the assumption that Expr can be an arbitrary value of the -- given Source_Typ. -- Currently, the only case in which a Source_Typ is explicitly supplied -- is for the case of Out and In_Out parameters, where, for the conversion -- on return (the Out direction), the types must be reversed. This is -- handled by the caller. procedure Apply_Length_Check (Expr : Node_Id; Target_Typ : Entity_Id; Source_Typ : Entity_Id := Empty); -- This procedure builds a sequence of declarations to do a length check -- that checks if the lengths of the two arrays Target_Typ and source type -- are the same. The resulting actions are inserted at Node using a call -- to Insert_Actions. -- -- For access types, the Directly_Designated_Type is retrieved and -- processing continues as enumerated above, with a guard against null -- values. -- -- Note: calls to Apply_Length_Check currently never supply an explicit -- Source_Typ parameter, but Apply_Length_Check takes this parameter and -- processes it as described above for consistency with the other routines -- in this section. procedure Apply_Length_Check_On_Assignment (Expr : Node_Id; Target_Typ : Entity_Id; Target : Node_Id; Source_Typ : Entity_Id := Empty); -- Similar to Apply_Length_Check, but takes the target of an assignment for -- which the check is to be done. Used to filter out specific cases where -- the check is superfluous. procedure Apply_Static_Length_Check (Expr : Node_Id; Target_Typ : Entity_Id; Source_Typ : Entity_Id := Empty); -- Tries to determine statically whether the two array types source type -- and Target_Typ have the same length. If it can be determined at compile -- time that they do not, then an N_Raise_Constraint_Error node replaces -- Expr, and a warning message is issued. procedure Apply_Range_Check (Expr : Node_Id; Target_Typ : Entity_Id; Source_Typ : Entity_Id := Empty; Insert_Node : Node_Id := Empty); -- For a Node of kind N_Range, constructs a range check action that tests -- first that the range is not null and then that the range is contained in -- the Target_Typ range. -- -- For scalar types, constructs a range check action that first tests that -- the expression is contained in the Target_Typ range. The difference -- between this and Apply_Scalar_Range_Check is that the latter generates -- the actual checking code against the Etype of the expression. -- -- For constrained array types, construct series of range check actions -- to check that each Expr range is properly contained in the range of -- Target_Typ. -- -- For a type conversion to an unconstrained array type, constructs a range -- check action to check that the bounds of the source type are within the -- constraints imposed by the Target_Typ. -- -- For access types, the Directly_Designated_Type is retrieved and -- processing continues as enumerated above, with a guard against null -- values. -- -- The source type is used by type conversions to unconstrained array -- types to retrieve the corresponding bounds. -- Insert_Node indicates the node where the check should be inserted. -- If it is empty, then the check is inserted directly at Expr instead. procedure Apply_Scalar_Range_Check (Expr : Node_Id; Target_Typ : Entity_Id; Source_Typ : Entity_Id := Empty; Fixed_Int : Boolean := False); -- For scalar types, determines whether an expression node should be -- flagged as needing a run-time range check. If the node requires such a -- check, the Do_Range_Check flag is turned on. The Fixed_Int flag if set -- causes any fixed-point values to be treated as though they were discrete -- values (i.e. the underlying integer value is used). type Check_Result is private; -- Type used to return result of Get_Range_Checks call, for later use in -- call to Insert_Range_Checks procedure. function Get_Range_Checks (Expr : Node_Id; Target_Typ : Entity_Id; Source_Typ : Entity_Id := Empty; Warn_Node : Node_Id := Empty) return Check_Result; -- Like Apply_Range_Check, except it does not modify anything. Instead -- it returns an encapsulated result of the check operations for later -- use in a call to Insert_Range_Checks. If Warn_Node is non-empty, its -- Sloc is used, in the static case, for the generated warning or error. -- Additionally, it is used rather than Expr (or Low/High_Bound of Expr) -- in constructing the check. procedure Append_Range_Checks (Checks : Check_Result; Stmts : List_Id; Suppress_Typ : Entity_Id; Static_Sloc : Source_Ptr); -- Called to append range checks as returned by a call to Get_Range_Checks. -- Stmts is a list to which either the dynamic check is appended or the -- raise Constraint_Error statement is appended (for static checks). -- Suppress_Typ is the type to check to determine if checks are suppressed. -- Static_Sloc is the Sloc at which the raise CE node points. procedure Insert_Range_Checks (Checks : Check_Result; Node : Node_Id; Suppress_Typ : Entity_Id; Static_Sloc : Source_Ptr; Do_Before : Boolean := False); -- Called to insert range checks as returned by a call to Get_Range_Checks. -- Node is the node after which either the dynamic check is inserted or -- the raise Constraint_Error statement is inserted (for static checks). -- Suppress_Typ is the type to check to determine if checks are suppressed. -- Static_Sloc is the Sloc at which the raise CE node points. Normally the -- checks are inserted after Node; if Do_Before is True, they are before. ----------------------- -- Expander Routines -- ----------------------- -- In most cases, the processing for range checks done by semantic analysis -- only results in setting the Do_Range_Check flag, rather than actually -- generating checks. The following routines must be called later on in the -- expansion process upon seeing the Do_Range_Check flag; they generate the -- actual checks and reset the flag. The remaining cases where range checks -- are still directly generated during semantic analysis occur as part of -- the processing of constraints in (sub)type and object declarations. procedure Generate_Range_Check (N : Node_Id; Target_Type : Entity_Id; Reason : RT_Exception_Code); -- This procedure is called to actually generate and insert a range check. -- A check is generated to ensure that the value of N lies within the range -- of the target type. Note that the base type of N may be different from -- the base type of the target type. This happens in the conversion case. -- The Reason parameter is the exception code to be used for the exception -- if raised. -- -- Note: if the expander is not active, or if we are in GNATprove mode, -- then we do not generate explicit range checks. Instead we just turn the -- Do_Range_Check flag on, since in these cases that's what we want to see -- in the tree (GNATprove in particular depends on this flag being set). If -- we generate the actual range checks, then we make sure the flag is off -- afterward, since the code we generate takes complete care of the checks. -- -- Historical note: We used to just pass on the Do_Range_Check flag to the -- back end to generate the check, but now in code-generation mode we never -- have this flag set, since the front end takes care of the check. The -- normal processing flow now is that the analyzer typically turns on the -- Do_Range_Check flag, and if it is set, this routine is called, which -- turns the flag off in code-generation mode. procedure Generate_Index_Checks (N : Node_Id; Checks_Generated : out Dimension_Set); -- This procedure is called to generate index checks on the subscripts for -- the indexed component node N. Each subscript expression is examined, and -- if the Do_Range_Check flag is set, an appropriate index check is -- generated and the flag is reset. -- The out-mode parameter Checks_Generated indicates the dimensions for -- which checks were generated. Checks_Generated.Dimensions must match -- the number of dimensions of the array type. -- Similarly, we set the flag Do_Discriminant_Check in the semantic -- analysis to indicate that a discriminant check is required for selected -- component of a discriminated type. The following routine is called from -- the expander to actually generate the call. procedure Generate_Discriminant_Check (N : Node_Id); -- N is a selected component for which a discriminant check is required to -- make sure that the discriminants have appropriate values for the -- selection. This is done by calling the appropriate discriminant checking -- routine for the selector. ----------------------- -- Validity Checking -- ----------------------- -- In (RM 13.9.1(9-11)) we have the following rules on invalid values -- If the representation of a scalar object does not represent value of -- the object's subtype (perhaps because the object was not initialized), -- the object is said to have an invalid representation. It is a bounded -- error to evaluate the value of such an object. If the error is -- detected, either Constraint_Error or Program_Error is raised. -- Otherwise, execution continues using the invalid representation. The -- rules of the language outside this subclause assume that all objects -- have valid representations. The semantics of operations on invalid -- representations are as follows: -- -- 10 If the representation of the object represents a value of the -- object's type, the value of the type is used. -- -- 11 If the representation of the object does not represent a value -- of the object's type, the semantics of operations on such -- representations is implementation-defined, but does not by -- itself lead to erroneous or unpredictable execution, or to -- other objects becoming abnormal. -- We quote the rules in full here since they are quite delicate. Most -- of the time, we can just compute away with wrong values, and get a -- possibly wrong result, which is well within the range of allowed -- implementation defined behavior. The two tricky cases are subscripted -- array assignments, where we don't want to do wild stores, and case -- statements where we don't want to do wild jumps. -- In GNAT, we control validity checking with a switch -gnatV that can take -- three parameters, n/d/f for None/Default/Full. These modes have the -- following meanings: -- None (no validity checking) -- In this mode, there is no specific checking for invalid values -- and the code generator assumes that all stored values are always -- within the bounds of the object subtype. The consequences are as -- follows: -- For case statements, an out of range invalid value will cause -- Constraint_Error to be raised, or an arbitrary one of the case -- alternatives will be executed. Wild jumps cannot result even -- in this mode, since we always do a range check -- For subscripted array assignments, wild stores will result in -- the expected manner when addresses are calculated using values -- of subscripts that are out of range. -- It could perhaps be argued that this mode is still conformant with -- the letter of the RM, since implementation defined is a rather -- broad category, but certainly it is not in the spirit of the -- RM requirement, since wild stores certainly seem to be a case of -- erroneous behavior. -- Default (default standard RM-compatible validity checking) -- In this mode, which is the default, minimal validity checking is -- performed to ensure no erroneous behavior as follows: -- For case statements, an out of range invalid value will cause -- Constraint_Error to be raised. -- For subscripted array assignments, invalid out of range -- subscript values will cause Constraint_Error to be raised. -- Full (Full validity checking) -- In this mode, the protections guaranteed by the standard mode are -- in place, and the following additional checks are made: -- For every assignment, the right side is checked for validity -- For every call, IN and IN OUT parameters are checked for validity -- For every subscripted array reference, both for stores and loads, -- all subscripts are checked for validity. -- These checks are not required by the RM, but will in practice -- improve the detection of uninitialized variables, particularly -- if used in conjunction with pragma Normalize_Scalars. -- In the above description, we talk about performing validity checks, -- but we don't actually generate a check in a case where the compiler -- can be sure that the value is valid. Note that this assurance must -- be achieved without assuming that any uninitialized value lies within -- the range of its type. The following are cases in which values are -- known to be valid. The flag Is_Known_Valid is used to keep track of -- some of these cases. -- If all possible stored values are valid, then any uninitialized -- value must be valid. -- Literals, including enumeration literals, are clearly always valid -- Constants are always assumed valid, with a validity check being -- performed on the initializing value where necessary to ensure that -- this is the case. -- For variables, the status is set to known valid if there is an -- initializing expression. Again a check is made on the initializing -- value if necessary to ensure that this assumption is valid. The -- status can change as a result of local assignments to a variable. -- If a known valid value is unconditionally assigned, then we mark -- the left side as known valid. If a value is assigned that is not -- known to be valid, then we mark the left side as invalid. This -- kind of processing does NOT apply to non-local variables since we -- are not following the flow graph (more properly the flow of actual -- processing only corresponds to the flow graph for local assignments). -- For non-local variables, we preserve the current setting, i.e. a -- validity check is performed when assigning to a known valid global. -- Note: no validity checking is required if range checks are suppressed -- regardless of the setting of the validity checking mode. -- The following procedures are used in handling validity checking procedure Apply_Subscript_Validity_Checks (Expr : Node_Id; No_Check_Needed : Dimension_Set := Empty_Dimension_Set); -- Expr is the node for an indexed component. If validity checking and -- range checking are enabled, each subscript for this indexed component -- whose dimension does not belong to the No_Check_Needed set is checked -- for validity. No_Check_Needed.Dimensions must match the number of -- dimensions of the array type or be zero. procedure Check_Valid_Lvalue_Subscripts (Expr : Node_Id); -- Expr is a lvalue, i.e. an expression representing the target of an -- assignment. This procedure checks for this expression involving an -- assignment to an array value. We have to be sure that all the subscripts -- in such a case are valid, since according to the rules in (RM -- 13.9.1(9-11)) such assignments are not permitted to result in erroneous -- behavior in the case of invalid subscript values. procedure Ensure_Valid (Expr : Node_Id; Holes_OK : Boolean := False; Related_Id : Entity_Id := Empty; Is_Low_Bound : Boolean := False; Is_High_Bound : Boolean := False); -- Ensure that Expr represents a valid value of its type. If this type -- is not a scalar type, then the call has no effect, since validity -- is only an issue for scalar types. The effect of this call is to -- check if the value is known valid, if so, nothing needs to be done. -- If this is not known, then either Expr is set to be range checked, -- or specific checking code is inserted so that an exception is raised -- if the value is not valid. -- -- The optional argument Holes_OK indicates whether it is necessary to -- worry about enumeration types with non-standard representations leading -- to "holes" in the range of possible representations. If Holes_OK is -- True, then such values are assumed valid (this is used when the caller -- will make a separate check for this case anyway). If Holes_OK is False, -- then this case is checked, and code is inserted to ensure that Expr is -- valid, raising Constraint_Error if the value is not valid. -- -- Related_Id denotes the entity of the context where Expr appears. Flags -- Is_Low_Bound and Is_High_Bound specify whether the expression to check -- is the low or the high bound of a range. These three optional arguments -- signal Remove_Side_Effects to create an external symbol of the form -- Chars (Related_Id)_FIRST/_LAST. For suggested use of these parameters -- see the warning in the body of Sem_Ch3.Process_Range_Expr_In_Decl. function Expr_Known_Valid (Expr : Node_Id) return Boolean; -- This function tests it the value of Expr is known to be valid in the -- sense of RM 13.9.1(9-11). In the case of GNAT, it is only discrete types -- which are a concern, since for non-discrete types we simply continue -- computation with invalid values, which does not lead to erroneous -- behavior. Thus Expr_Known_Valid always returns True if the type of Expr -- is non-discrete. For discrete types the value returned is True only if -- it can be determined that the value is Valid. Otherwise False is -- returned. procedure Insert_Valid_Check (Expr : Node_Id; Related_Id : Entity_Id := Empty; Is_Low_Bound : Boolean := False; Is_High_Bound : Boolean := False); -- Inserts code that will check for the value of Expr being valid, in the -- sense of the 'Valid attribute returning True. Constraint_Error will be -- raised if the value is not valid. -- -- Related_Id denotes the entity of the context where Expr appears. Flags -- Is_Low_Bound and Is_High_Bound specify whether the expression to check -- is the low or the high bound of a range. These three optional arguments -- signal Remove_Side_Effects to create an external symbol of the form -- Chars (Related_Id)_FIRST/_LAST. For suggested use of these parameters -- see the warning in the body of Sem_Ch3.Process_Range_Expr_In_Decl. procedure Null_Exclusion_Static_Checks (N : Node_Id; Comp : Node_Id := Empty; Array_Comp : Boolean := False); -- Ada 2005 (AI-231): Test for and warn on null-excluding objects or -- components that will raise an exception due to initialization by null. -- -- When a value for Comp is supplied (as in the case of an uninitialized -- null-excluding component within a composite object), a reported warning -- will indicate the offending component instead of the object itself. -- Array_Comp being True indicates an array object with null-excluding -- components, and any reported warning will indicate that. procedure Remove_Checks (Expr : Node_Id); -- Remove all checks from Expr except those that are only executed -- conditionally (on the right side of And Then/Or Else. This call -- removes only embedded checks (Do_Range_Check, Do_Overflow_Check). procedure Validity_Check_Range (N : Node_Id; Related_Id : Entity_Id := Empty); -- If N is an N_Range node, then Ensure_Valid is called on its bounds, if -- validity checking of operands is enabled. Related_Id denotes the entity -- of the context where N appears. ----------------------------- -- Handling of Check Names -- ----------------------------- -- The following table contains Name_Id's for recognized checks. The first -- entries (corresponding to the values of the subtype Predefined_Check_Id) -- contain the Name_Id values for the checks that are predefined, including -- All_Checks (see Types). Remaining entries are those that are introduced -- by pragma Check_Names. package Check_Names is new Table.Table ( Table_Component_Type => Name_Id, Table_Index_Type => Check_Id, Table_Low_Bound => 1, Table_Initial => 30, Table_Increment => 200, Table_Name => "Name_Check_Names"); function Get_Check_Id (N : Name_Id) return Check_Id; -- Function to search above table for matching name. If found returns the -- corresponding Check_Id value in the range 1 .. Check_Name.Last. If not -- found returns No_Check_Id. private type Check_Result is array (Positive range 1 .. 2) of Node_Id; -- There are two cases for the result returned by Range_Check: -- -- For the static case the result is one or two nodes that should cause -- a Constraint_Error. Typically these will include Expr itself or the -- direct descendants of Expr, such as Low/High_Bound (Expr)). It is the -- responsibility of the caller to rewrite and substitute the nodes with -- N_Raise_Constraint_Error nodes. -- -- For the non-static case a single N_Raise_Constraint_Error node with a -- non-empty Condition field is returned. -- -- Unused entries in Check_Result, if any, are simply set to Empty For -- external clients, the required processing on this result is achieved -- using the Insert_Range_Checks routine. pragma Inline (Apply_Length_Check); pragma Inline (Apply_Range_Check); pragma Inline (Apply_Static_Length_Check); end Checks;
google-code/ada-security
Ada
7,096
adb
----------------------------------------------------------------------- -- security-openid - Tests for OpenID -- Copyright (C) 2009, 2010, 2011, 2012, 2013 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Strings.Unbounded; with Util.Http.Mockups; with Util.Http.Clients.Mockups; with Util.Test_Caller; with Ada.Text_IO; package body Security.Auth.Tests is use Util.Tests; package Caller is new Util.Test_Caller (Test, "Security.Openid"); procedure Check_Discovery (T : in out Test; Name : in String; URI : in String); procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is begin Caller.Add_Test (Suite, "Test Security.OpenID.Discover", Test_Discovery'Access); Caller.Add_Test (Suite, "Test Security.OpenID.Verify_Signature", Test_Verify_Signature'Access); end Add_Tests; overriding function Get_Parameter (Params : in Test_Parameters; Name : in String) return String is begin if Params.Params.Contains (Name) then return Params.Params.Element (Name); else return ""; end if; end Get_Parameter; procedure Set_Parameter (Params : in out Test_Parameters; Name : in String; Value : in String) is begin Params.Params.Include (Name, Value); end Set_Parameter; procedure Setup (M : in out Manager; Name : in String) is Params : Test_Parameters; begin Params.Set_Parameter ("auth.provider.google", "openid"); Params.Set_Parameter ("auth.provider.openid", "openid"); Params.Set_Parameter ("openid.realm", "http://localhost/verify"); Params.Set_Parameter ("openid.callback_url", "http://localhost/openId"); M.Initialize (Params, Name); end Setup; procedure Check_Discovery (T : in out Test; Name : in String; URI : in String) is pragma Unreferenced (URI, T); M : Manager; Dir : constant String := "regtests/files/discover/"; Path : constant String := Util.Tests.Get_Path (Dir); Result : End_Point; begin Setup (M, "openid"); Util.Http.Clients.Mockups.Register; Util.Http.Clients.Mockups.Set_File (Path & Name & ".xrds"); M.Discover (Name => Name, Result => Result); Ada.Text_IO.Put_Line ("Result: " & To_String (Result)); end Check_Discovery; -- ------------------------------ -- Test Yadis discovery using static files -- ------------------------------ procedure Test_Discovery (T : in out Test) is begin Check_Discovery (T, "google", "https://www.google.com/accounts/o8/ud"); Check_Discovery (T, "yahoo", "https://open.login.yahooapis.com/openid/op/auth"); Check_Discovery (T, "claimid", ""); Check_Discovery (T, "livejournal", ""); Check_Discovery (T, "myopenid", ""); Check_Discovery (T, "myspace", ""); Check_Discovery (T, "orange", ""); Check_Discovery (T, "verisign", ""); Check_Discovery (T, "steamcommunity", ""); end Test_Discovery; -- ------------------------------ -- Test the OpenID verify signature process -- ------------------------------ procedure Test_Verify_Signature (T : in out Test) is Assoc : Association; Req : Test_Parameters; M : Manager; Result : Authentication; begin Setup (M, "openid"); -- M.Return_To := To_Unbounded_String ("http://localhost/openId"); -- Below is a part of the authentication process on Google OpenId. -- In theory, you cannot use the following information to authenticate again... Assoc.Session_Type := To_Unbounded_String ("no-encryption"); Assoc.Assoc_Type := To_Unbounded_String ("HMAC-SHA1"); Assoc.Assoc_Handle := To_Unbounded_String ("AOQobUdTfNDRSgJLi_0mQQnCCstOsefQadOiW9LNSp4JFO815iHCHsRk"); Assoc.Mac_Key := To_Unbounded_String ("NGFpR6vWfe7O8YIhhnXQMjL0goI="); Req.Set_Parameter ("openid.ns", "http://specs.openid.net/auth/2.0"); Req.Set_Parameter ("openid.mode", "id_res"); Req.Set_Parameter ("openid.op_endpoint", "https://www.google.com/accounts/o8/ud"); Req.Set_Parameter ("openid.response_nonce", "2011-04-26T20:08:22ZJ_neiVqR0e1wZw"); Req.Set_Parameter ("openid.return_to", "http://localhost/openId"); Req.Set_Parameter ("openid.assoc_handle", "AOQobUdTfNDRSgJLi_0mQQnCCstOsefQadOiW9LNSp4JFO815iHCHsRk"); Req.Set_Parameter ("openid.signed", "op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle,ns.ext1,ext1.mode,ext1.type.firstname,ext1.value.firstname,ext1.type.email,ext1.value.email,ext1.type.language,ext1.value.language,ext1.type.lastname,ext1.value.lastname"); Req.Set_Parameter ("openid.sig", "pV8cmScjrmgKvFn2F6Wxh/qBiIE="); Req.Set_Parameter ("openid.identity", "https://www.google.com/accounts/o8/id?id=AItOawm4O6C695XlWrS7MUWC-_V_R2zC-Ol993E"); Req.Set_Parameter ("openid.claimed_id", "https://www.google.com/accounts/o8/id?id=AItOawm4O6C695XlWrS7MUWC-_V_R2zC-Ol993E"); Req.Set_Parameter ("openid.ns.ext1", "http://openid.net/srv/ax/1.0"); Req.Set_Parameter ("openid.ext1.mode", "fetch_response"); Req.Set_Parameter ("openid.ext1.type.firstname", "http://axschema.org/namePerson/first"); Req.Set_Parameter ("openid.ext1.value.firstname", "Stephane"); Req.Set_Parameter ("openid.ext1.type.email", "http://axschema.org/contact/email"); Req.Set_Parameter ("openid.ext1.value.email", "[email protected]"); Req.Set_Parameter ("openid.ext1.type.language", "http://axschema.org/pref/language"); Req.Set_Parameter ("openid.ext1.value.language", "fr"); Req.Set_Parameter ("openid.ext1.type.lastname", "http://axschema.org/namePerson/last"); Req.Set_Parameter ("openid.ext1.value.lastname", "Carrez"); M.Verify (Assoc, Req, Result); -- If the verification is succeeds, the signature is correct, we should be authenticated. T.Assert (Get_Status (Result) = AUTHENTICATED, "Authentication status is not authenticated"); Assert_Equals (T, "[email protected]", Get_Email (Result), "Invalid email"); end Test_Verify_Signature; end Security.Auth.Tests;
zhmu/ananas
Ada
288
adb
-- { dg-do compile } procedure Derived_Type4 is type Root (D : Positive) is record S : String (1 .. D); end record; subtype Short is Positive range 1 .. 10; type Derived (N : Short := 1) is new Root (D => N); Obj : Derived; begin Obj := (N => 5, S => "Hello"); end;
Fabien-Chouteau/Ada_Drivers_Library
Ada
5,254
ads
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2016-2018, 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 HAL.GPIO; package nRF51.GPIO is subtype GPIO_Pin_Index is Natural range 0 .. 31; type Pin_IO_Modes is (Mode_In, Mode_Out); type Pin_Resistors is (Pull_Up, Pull_Down, No_Pull); type Pin_Drive is (Drive_S0S1, Drive_H0S1, Drive_S0H1, Drive_H0H1, Drive_D0S1, Drive_D0H1, Drive_S0D1, Drive_H0D1); type Pin_Sense_Mode is (Sense_Disabled, Sense_For_High_Level, Sense_For_Low_Level); type Pin_Input_Buffer_Mode is (Input_Buffer_Connect, Input_Buffer_Disconnect); type GPIO_Configuration is record Mode : Pin_IO_Modes; Resistors : Pin_Resistors; Input_Buffer : Pin_Input_Buffer_Mode := Input_Buffer_Disconnect; Drive : Pin_Drive := Drive_S0S1; Sense : Pin_Sense_Mode := Sense_Disabled; end record; type GPIO_Point is new HAL.GPIO.GPIO_Point with record Pin : GPIO_Pin_Index; end record; overriding function Support (This : GPIO_Point; Capa : HAL.GPIO.Capability) return Boolean is (case Capa is when others => True); -- nRF51 supports all GPIO capabilities overriding function Mode (This : GPIO_Point) return HAL.GPIO.GPIO_Mode; overriding procedure Set_Mode (This : in out GPIO_Point; Mode : HAL.GPIO.GPIO_Config_Mode); overriding function Pull_Resistor (This : GPIO_Point) return HAL.GPIO.GPIO_Pull_Resistor; overriding procedure Set_Pull_Resistor (This : in out GPIO_Point; Pull : HAL.GPIO.GPIO_Pull_Resistor); overriding function Set (This : GPIO_Point) return Boolean with Inline; -- Returns True if the bit specified by This.Pin is set (not zero) in the -- input data register of This.Port.all; returns False otherwise. overriding procedure Set (This : in out GPIO_Point) with Inline; -- For This.Port.all, sets the output data register bit specified by -- This.Pin to one. Other pins are unaffected. overriding procedure Clear (This : in out GPIO_Point) with Inline; -- For This.Port.all, sets the output data register bit specified by -- This.Pin to zero. Other pins are unaffected. overriding procedure Toggle (This : in out GPIO_Point) with Inline; -- For This.Port.all, negates the output data register bit specified by -- This.Pin (one becomes zero and vice versa). Other pins are unaffected. procedure Configure_IO (This : GPIO_Point; Config : GPIO_Configuration); -- Configures the characteristics specified by Config end nRF51.GPIO;
AdaCore/libadalang
Ada
241
ads
with Subp_G; -- The result should be 'None' but should not raise an error saying -- that file 'Subp.adb' is not found, since we don't expect to have a body -- for this unit. procedure Subp is new Subp_G; --% node.p_next_part_for_decl()
hamadgin2/dd-wrt
Ada
5,197
ads
------------------------------------------------------------------------------ -- -- -- GNAT ncurses Binding -- -- -- -- Terminal_Interface.Curses.Forms.Field_Types.Enumeration -- -- -- -- S P E C -- -- -- ------------------------------------------------------------------------------ -- Copyright (c) 1998-2009,2018 Free Software Foundation, Inc. -- -- -- -- Permission is hereby granted, free of charge, to any person obtaining a -- -- copy of this software and associated documentation files (the -- -- "Software"), to deal in the Software without restriction, including -- -- without limitation the rights to use, copy, modify, merge, publish, -- -- distribute, distribute with modifications, sublicense, and/or sell -- -- copies of the Software, and to permit persons to whom the Software is -- -- furnished to do so, subject to the following conditions: -- -- -- -- The above copyright notice and this permission notice shall be included -- -- in all copies or substantial portions of the Software. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -- -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- -- -- -- Except as contained in this notice, the name(s) of the above copyright -- -- holders shall not be used in advertising or otherwise to promote the -- -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------ -- Author: Juergen Pfeifer, 1996 -- Version Control: -- $Revision: 1.13 $ -- Binding Version 01.00 ------------------------------------------------------------------------------ with Interfaces.C.Strings; package Terminal_Interface.Curses.Forms.Field_Types.Enumeration is pragma Preelaborate (Terminal_Interface.Curses.Forms.Field_Types.Enumeration); type String_Access is access String; -- Type_Set is used by the child package Ada type Type_Set is (Lower_Case, Upper_Case, Mixed_Case); type Enum_Array is array (Positive range <>) of String_Access; type Enumeration_Info (C : Positive) is record Case_Sensitive : Boolean := False; Match_Must_Be_Unique : Boolean := False; Names : Enum_Array (1 .. C); end record; type Enumeration_Field is new Field_Type with private; function Create (Info : Enumeration_Info; Auto_Release_Names : Boolean := False) return Enumeration_Field; -- Make an fieldtype from the info. Enumerations are special, because -- they normally don't copy the enum values into a private store, so -- we have to care for the lifetime of the info we provide. -- The Auto_Release_Names flag may be used to automatically releases -- the strings in the Names array of the Enumeration_Info. function Make_Enumeration_Type (Info : Enumeration_Info; Auto_Release_Names : Boolean := False) return Enumeration_Field renames Create; procedure Release (Enum : in out Enumeration_Field); -- But we may want to release the field to release the memory allocated -- by it internally. After that the Enumeration field is no longer usable. -- The next type defintions are all ncurses extensions. They are typically -- not available in other curses implementations. procedure Set_Field_Type (Fld : Field; Typ : Enumeration_Field); pragma Inline (Set_Field_Type); private type CPA_Access is access Interfaces.C.Strings.chars_ptr_array; type Enumeration_Field is new Field_Type with record Case_Sensitive : Boolean := False; Match_Must_Be_Unique : Boolean := False; Arr : CPA_Access := null; end record; end Terminal_Interface.Curses.Forms.Field_Types.Enumeration;
AdaCore/libadalang
Ada
45
ads
package Bar is I : Integer := 0; end Bar;
AdaCore/gpr
Ada
119,838
adb
-- -- Copyright (C) 2019-2023, AdaCore -- -- SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception -- with Ada.Command_Line; with Ada.Directories; with Ada.Exceptions; with Ada.Text_IO; with Ada.Strings.Fixed; with GNAT.Directory_Operations; with GNAT.OS_Lib; with GNATCOLL.OS.Process; with GNATCOLL.Traces; with GNATCOLL.VFS; with GNATCOLL.VFS_Utils; with GPR2.KB.Compiler_Iterator; with GPR2.KB.Parsing; with GPR2.Message; package body GPR2.KB is Main_Trace : constant GNATCOLL.Traces.Trace_Handle := GNATCOLL.Traces.Create ("KNOWLEDGE_BASE", GNATCOLL.Traces.Off); Match_Trace : constant GNATCOLL.Traces.Trace_Handle := GNATCOLL.Traces.Create ("KNOWLEDGE_BASE.MATHCING", GNATCOLL.Traces.Off); No_Compatible_Compilers : exception; -- Raised when any combination of compilers found can form a supported -- configuration. procedure Complete_Command_Line_Compilers (Self : in out Object; On_Target : Name_Type; Filters : Compiler_Lists.List; Compilers : in out Compiler_Lists.List; Selected_Target : in out Unbounded_String; Fallback : Boolean; Errors : out Log.Object; Environment : GPR2.Environment.Object); -- In batch mode, the configuration descriptions indicate what compilers -- should be selected. Each of these descriptions selects the first -- matching compiler available, and all descriptions must match a compiler. -- The information provided by the user does not have to be complete, and -- this procedure completes all missing information like version, runtime, -- and so on. -- Filters is the list specified by the user, and contains potentially -- partial information for each compiler. On output, Compilers is completed -- with the full information for all compilers in Filters. -- If any of the required compilers cannot be found corresponding -- diagnostic is passed through Errors. -- If no set of compatible compilers was found raises -- No_Compatible_Compilers. function Extra_Dirs_From_Filters (Filters : Compiler_Lists.List) return String; -- Compute the list of directories that should be prepended to the PATH -- when searching for compilers. These are all the directories that the -- user has explicitly specified in his filters. function Is_Language_With_No_Compiler (Self : Object; Language : Language_Id) return Boolean; -- Given a language name (lower case), returns True if that language is -- known to require no compiler. function Is_Supported_Config (Self : Object; Compilers : Compiler_Lists.List) return Boolean; -- Whether we know how to link code compiled with all the selected -- compilers. procedure Parse_All_Dirs (Processed_Value : out External_Value_Lists.List; Visited : in out String_To_External_Value.Map; Current_Dir : String; Path_To_Check : String; Regexp : Regpat.Pattern_Matcher; Regexp_Str : String; Value_If_Match : String; Group : Integer; Group_Match : String := ""; Group_Count : Natural := 0; Contents : Pattern_Matcher_Holder; Merge_Same_Dirs : Boolean; Error_Sloc : Source_Reference.Object; Messages : in out Log.Object); -- Parses all subdirectories of Current_Dir for those that match -- Path_To_Check (see description of <directory>). When a match is found, -- the regexp is evaluated against the current directory, and the matching -- parenthesis group is appended to Append_To (comma-separated). -- If Group is -1, then Value_If_Match is used instead of the parenthesis -- group. -- Group_Match is the substring that matched Group (if it has been matched -- already). Group_Count is the number of parenthesis groups that have been -- processed so far. The idea is to compute the matching substring as we -- go, since the regexp might no longer match in the end, if for instance -- it includes ".." directories. -- -- If Merge_Same_Dirs is True, then the values that come from a -- <directory> node will be merged (the last one is kept, other removed) if -- they point to the same physical directory (after normalizing names). In -- this case, Visited contains the list of normalized directory names. -- -- Contents, if specified, is a regular expression. It indicates that any -- file matching the pattern should be parsed, and the first line matching -- that regexp should be used as the name of the file instead. This is a -- way to simulate symbolic links on platforms that do not use them. generic with function Callback (Var_Name, Index : String) return String; function Substitute_Variables (Str : String; Error_Sloc : Source_Reference.Object; Messages : in out Log.Object) return String; -- Substitutes variables in Str (their value is computed through Callback). -- Possible errors are stored in Messages. function Substitute_Variables_In_Compiler_Description (Str : String; Comp : Compiler; Error_Sloc : Source_Reference.Object; Messages : in out Log.Object) return String; -- Substitutes the special "$..." names in compiler description package Ordered_Languages_Vectors is new Ada.Containers.Vectors (Positive, Language_Id); subtype Ordered_Languages is Ordered_Languages_Vectors.Vector; function Substitute_Variables_In_Configuration (Self : Object; Str : String; Comps : Compiler_Lists.List; Langs : Ordered_Languages; Error_Sloc : Source_Reference.Object; Messages : in out Log.Object) return String; -- Substitutes the special "$..." names in configuration function Get_Variable_Value (Comp : Compiler; Name : String) return String; -- Returns the value of a predefined or user-defined variable. -- If the variable is not defined a warning is emitted and an empty -- string is returned. function Get_String_No_Adalib (Str : String) return String; -- Returns the name without "adalib" at the end function To_String (Comp : Compiler) return String; -- Return a string representing the compiler. Used for diagnostics. function To_String (Compilers : Compiler_Lists.List) return String; -- Return a string representing the list of compilers. Only Selected -- compilers are taken into account. Used for diagnostics. procedure Set_Selection (Compilers : in out Compiler_Lists.List; Cursor : Compiler_Lists.Cursor; Selected : Boolean); function Match (Filter : Compilers_Filter_Lists.List; Compilers : Compiler_Lists.List) return Boolean; -- Returns True if all elements of Filter matches against Compilers. -- Filter represents the list of nodes <configuration><compilers>. function Match (Filter : Compilers_Filter; Compilers : Compiler_Lists.List) return Boolean; -- Returns True if at least one component of Filter matches against -- Compilers, taking into account the negate value. -- Filter represents a single node <configuration><compilers>. function Match (Filter : Compiler_Filter; Compilers : Compiler_Lists.List) return Boolean; -- Returns True if at least on of the Compilers match the filter. -- Filter represents a single node <configuration><compilers><compiler>. function Match (Target_Filter : Double_String_Lists.List; Negate : Boolean; Compilers : Compiler_Lists.List) return Boolean; -- Return True if Filter matches the list of selected configurations function Generate_Configuration (Self : Object; Compilers : Compiler_Lists.List; Target : String; Langs : Ordered_Languages; Errors : in out Log.Object) return Unbounded_String; -- Generate the configuration string for the list of selected compilers package String_Maps is new Ada.Containers.Indefinite_Ordered_Maps (String, String); procedure Merge_Config (Self : Object; Packages : in out String_Maps.Map; Compilers : Compiler_Lists.List; Config : String; Langs : Ordered_Languages; Error_Sloc : Source_Reference.Object; Errors : in out Log.Object); -- Merge the contents of Config into Packages, so that each attributes ends -- up in the right package, and the packages are not duplicated. procedure Update_With_Compiler_Runtime (Self : in out Object; Comp : Compiler; Environment : GPR2.Environment.Object); -- Update the knowledge base with additional runtime specific chunks -- if a given compiler has any. function Create_Filter (Self : Object; Descr : Project.Configuration.Description) return Compiler; -- Transform Description into Compiler object function Configuration_Node_Image (Config : Configuration_Type) return Unbounded_String; -- Returns partial image of <configuration> node that is used in verbose -- output to explain unsupported configuration. function GPR_Executable_Prefix_Path return String; -- Tries to find the installation location of gprtools. -- If current executable may be one of gprtools and is spawned with path -- prefix, returns corresponding prefix directory. -- Returns empty string if all approaches do not work. -- When a directory is returned, it is guaranteed to end with a directory -- separator. Default_Target_Parsed : Boolean := False; Default_Target_Val : Unbounded_String; procedure Parse_Default_Target_Val; -- Tries to parse <gprtools directory>/share/gprconfig/default_target -- and sets Default_Target_Val. --------- -- Add -- --------- procedure Add (Self : in out Object; Flags : Parsing_Flags; Location : GPR2.Path_Name.Object; Environment : GPR2.Environment.Object := GPR2.Environment.Process_Environment) is begin if Self.Parsed_Directories.Contains (Location) then -- Do not parse several times the same database directory return; end if; Self.Parsed_Directories.Append (Location); Parsing.Parse_Knowledge_Base (Self, Location, Flags, Environment); end Add; --------- -- Add -- --------- procedure Add (Self : in out Object; Flags : Parsing_Flags; Content : Value_Not_Empty; Environment : GPR2.Environment.Object := GPR2.Environment.Process_Environment) is begin Parsing.Add (Self, Flags, Content, Environment); end Add; ------------------- -- All_Compilers -- ------------------- function All_Compilers (Self : in out Object; Settings : Project.Configuration.Description_Set; Target : Name_Type; Messages : in out GPR2.Log.Object; Environment : GPR2.Environment.Object := GPR2.Environment.Process_Environment) return Compiler_Array is use Compiler_Lists; use Ada.Containers; use KB.Compiler_Iterator; use Project.Configuration; Compilers : Compiler_Lists.List; Filters : Compiler_Lists.List; type Boolean_Array is array (Count_Type range <>) of Boolean; type All_Iterator (Count : Count_Type) is new GPR2.KB.Compiler_Iterator.Object with record Filter_Matched : Boolean_Array (1 .. Count) := (others => False); Filters : Compiler_Lists.List; Compilers : Compiler_Lists.List; end record; overriding procedure Callback (Iterator : in out All_Iterator; Base : in out Object; Comp : Compiler; Runtime_Specified : Boolean; From_Extra_Dir : Boolean; Continue : out Boolean); -- Search all compilers on path, preselecting the first one matching -- each of the filters. function Display_Before (Comp1, Comp2 : Compiler) return Boolean; -- Whether Comp1 should be displayed before Comp2 when displaying lists -- of compilers. This ensures that similar languages are grouped, -- among other things. package Compiler_Sort is new Compiler_Lists.Generic_Sorting (Display_Before); -------------- -- Callback -- -------------- overriding procedure Callback (Iterator : in out All_Iterator; Base : in out Object; Comp : Compiler; Runtime_Specified : Boolean; From_Extra_Dir : Boolean; Continue : out Boolean) is New_Comp : Compiler := Comp; C : Compiler_Lists.Cursor; Index : Count_Type := 1; begin -- Do nothing if a runtime needs to be specified, as this is only for -- interactive use. if not Runtime_Specified then if Iterator.Filter_Matched /= (Iterator.Filter_Matched'Range => True) then C := First (Iterator.Filters); while Has_Element (C) loop if not Iterator.Filter_Matched (Index) and then Filter_Match (Base, Comp => Comp, Filter => Element (C)) then Set_Selection (New_Comp, True); Iterator.Filter_Matched (Index) := True; exit; end if; Index := Index + 1; Next (C); end loop; end if; -- Ignore compilers from extra directories, unless they have been -- selected because of a --config argument. if Is_Selected (New_Comp) or else not From_Extra_Dir then GNATCOLL.Traces.Trace (Main_Trace, "Adding compiler to interactive menu " & To_String (Comp) & " selected=" & Is_Selected (New_Comp)'Img); Append (Iterator.Compilers, New_Comp); end if; end if; Continue := True; end Callback; -------------------- -- Display_Before -- -------------------- function Display_Before (Comp1, Comp2 : Compiler) return Boolean is type Compare_Type is (Before, Equal, After); function Compare (Name1, Name2 : Unbounded_String) return Compare_Type; -- Compare alphabetically two strings ------------- -- Compare -- ------------- function Compare (Name1, Name2 : Unbounded_String) return Compare_Type is begin if Name1 = Null_Unbounded_String then if Name2 = Null_Unbounded_String then return Equal; else return Before; end if; elsif Name2 = Null_Unbounded_String then return After; end if; if Name1 < Name2 then return Before; elsif Name1 > Name2 then return After; else return Equal; end if; end Compare; begin if Comp1.Language /= Comp2.Language then return Name (Comp1.Language) < Name (Comp2.Language); else if Comp1.Path_Order < Comp2.Path_Order then return True; elsif Comp2.Path_Order < Comp1.Path_Order then return False; else -- If the "default" attribute was specified for <runtime>, -- this only impacts the batch mode. We still want to sort -- the runtimes alphabetically in the interactive display. case Compare (Comp1.Runtime, Comp2.Runtime) is when Before => return True; when After => return False; when Equal => return Compare (Comp1.Version, Comp2.Version) = Before; end case; end if; end if; end Display_Before; Iter : All_Iterator (Settings'Length); begin for Setting of Settings loop if Is_Language_With_No_Compiler (Self, Language (Setting)) then Compilers.Append (Create_Filter (Self, Setting)); else Filters.Append (Create_Filter (Self, Setting)); end if; end loop; Iter.Filters := Filters; Foreach_In_Path (Self => Iter, Base => Self, On_Target => Target, Environment => Environment, Extra_Dirs => Extra_Dirs_From_Filters (Filters)); Splice (Target => Compilers, Before => Compiler_Lists.No_Element, Source => Iter.Compilers); if Compilers.Is_Empty then return No_Compilers; end if; Compiler_Sort.Sort (Compilers); return Res : Compiler_Array (1 .. Integer (Compilers.Length)) do for Idx in Res'Range loop Res (Idx) := Compilers.First_Element; Compilers.Delete_First; end loop; end return; exception when Invalid_KB => return No_Compilers; end All_Compilers; ------------------------------------- -- Complete_Command_Line_Compilers -- ------------------------------------- procedure Complete_Command_Line_Compilers (Self : in out Object; On_Target : Name_Type; Filters : Compiler_Lists.List; Compilers : in out Compiler_Lists.List; Selected_Target : in out Unbounded_String; Fallback : Boolean; Errors : out Log.Object; Environment : GPR2.Environment.Object) is use Compiler_Lists; use Ada.Containers; use GNATCOLL.Traces; type Cursor_Array is array (Count_Type range <>) of Compiler_Lists.Cursor; type Boolean_Array is array (Count_Type range <>) of Boolean; type Batch_Iterator (Count : Count_Type) is new GPR2.KB.Compiler_Iterator.Object with record Found : Count_Type := 0; Compilers : Compiler_Lists.List; Matched : Cursor_Array (1 .. Count) := (others => Compiler_Lists.No_Element); Filters : Compiler_Lists.List; Found_One : Boolean_Array (1 .. Count) := (others => False); -- Whether we found at least one matching compiler for each filter end record; overriding procedure Callback (Iterator : in out Batch_Iterator; Base : in out Object; Comp : Compiler; Runtime_Specified : Boolean; From_Extra_Dir : Boolean; Continue : out Boolean); -- Search the first compiler matching each --config command line -- argument. -- It might be discovered either in a path added through a --config -- parameter (in which case From_Extra_Dir is True), or in a path -- specified in the environment variable $PATH (in which case it is -- False). If the directory is both in Extra_Dirs and in $PATH, -- From_Extra_Dir is set to False. -- If Runtime_Specified is True, only filters with a specified runtime -- are taken into account. -- -- On exit, Continue should be set to False if there is no need -- to discover further compilers. Iterator : Batch_Iterator (Length (Filters)); function Foreach_Nth_Compiler (Filter : Compiler_Lists.Cursor) return Boolean; -- For all possible compiler matching the filter, check whether we -- find a compatible set of compilers matching the next filters. -- Return True if one was found (in which case it is the current -- selection on exit). -------------- -- Callback -- -------------- overriding procedure Callback (Iterator : in out Batch_Iterator; Base : in out Object; Comp : Compiler; Runtime_Specified : Boolean; From_Extra_Dir : Boolean; Continue : out Boolean) is C : Compiler_Lists.Cursor := First (Iterator.Filters); Index : Count_Type := 1; Ncomp : Compiler; El : Compiler; use GPR2.Path_Name; begin while Has_Element (C) loop Ncomp := No_Compiler; El := Compiler_Lists.Element (C); -- A compiler in an "extra_dir" (ie specified on the command line) -- can only match if that directory was explicitly specified in -- --config. We do not want to find all compilers in /dir if that -- directory is not in $PATH if (not From_Extra_Dir or else El.Path = Comp.Path) and then Filter_Match (Base, Comp => Comp, Filter => El) and then (not Runtime_Specified or else El.Runtime_Dir /= Null_Unbounded_String) then Ncomp := Comp; if El.Runtime_Dir /= Null_Unbounded_String then Ncomp.Runtime_Dir := El.Runtime_Dir; Ncomp.Runtime := El.Runtime; end if; if not Ncomp.Any_Runtime and then Ncomp.Runtime = Null_Unbounded_String and then El.Runtime /= Null_Unbounded_String then Ncomp.Runtime := El.Runtime; end if; Append (Iterator.Compilers, Ncomp); Trace (Match_Trace, "Saving compiler for possible backtracking: " & To_String (Ncomp) & " (matches --config " & To_String (El) & ")"); if Iterator.Matched (Index) = Compiler_Lists.No_Element then Iterator.Found := Iterator.Found + 1; Trace (Match_Trace, "Selecting it since this filter was not matched yet " & Iterator.Found'Img & "/" & Iterator.Count'Img); Iterator.Matched (Index) := Last (Iterator.Compilers); Iterator.Found_One (Index) := True; Set_Selection (Iterator.Compilers, Iterator.Matched (Index), True); -- Only keep those compilers that are not incompatible -- (according to the knowledge base). It might happen that -- none is selected as a result, but appropriate action is -- taken in Complete_Command_Line_Compilers. We ignore -- incompatible sets as early as possible, in the hope to -- limit the number of system calls if another set is found -- before all directories are traversed. if not Is_Supported_Config (Base, Iterator.Compilers) then Set_Selection (Iterator.Compilers, Iterator.Matched (Index), False); Trace (Match_Trace, "Compilers are not compatible, canceling last" & " compiler found"); Iterator.Matched (Index) := Compiler_Lists.No_Element; Iterator.Found := Iterator.Found - 1; end if; end if; end if; Index := Index + 1; Next (C); end loop; -- Stop at first compiler Continue := Iterator.Found /= Iterator.Count; end Callback; -------------------------- -- Foreach_Nth_Compiler -- -------------------------- function Foreach_Nth_Compiler (Filter : Compiler_Lists.Cursor) return Boolean is C : Compiler_Lists.Cursor := First (Iterator.Compilers); Comp_Filter : constant Compiler := Compiler_Lists.Element (Filter); begin while Has_Element (C) loop if Filter_Match (Self, Compiler_Lists.Element (C), Filter => Comp_Filter) then Set_Selection (Iterator.Compilers, C, True); if Next (Filter) = Compiler_Lists.No_Element then Increase_Indent (Match_Trace, "Testing the following compiler set:"); Trace (Match_Trace, To_String (Iterator.Compilers)); if Is_Supported_Config (Self, Iterator.Compilers) then Decrease_Indent (Match_Trace, "They are compatible"); return True; else Decrease_Indent (Match_Trace); end if; else if Foreach_Nth_Compiler (Next (Filter)) then return True; end if; end if; Set_Selection (Iterator.Compilers, C, False); end if; Next (C); end loop; return False; end Foreach_Nth_Compiler; C : Compiler_Lists.Cursor; Extra_Dirs : constant String := Extra_Dirs_From_Filters (Filters); Found_All : Boolean := True; Found_All_Fallback : Boolean := True; begin Iterator.Filters := Filters; Selected_Target := To_Unbounded_String (String (On_Target)); Increase_Indent (Main_Trace, "Completing info for --config parameters, extra_dirs=" & Extra_Dirs); -- Find all the compilers in PATH and Extra_Dirs Compiler_Iterator.Foreach_In_Path (Self => Iterator, Base => Self, On_Target => On_Target, Environment => Environment, Extra_Dirs => Extra_Dirs); Decrease_Indent (Main_Trace); -- Check that we could find at least one of each compiler if Fallback then -- Check to see if fallback targets are of interest C := First (Filters); for F in Iterator.Found_One'Range loop if not Iterator.Found_One (F) then if Self.Languages_Known.Contains (Compiler_Lists.Element (C).Language) then -- Fallback should not be triggered for unknown languages Found_All_Fallback := False; end if; Found_All := False; end if; Next (C); end loop; if not Found_All_Fallback then -- Looking for corresponding fallback set declare FB_List : GPR2.Containers.Name_List := Fallback_List (Self, On_Target); Cur : GPR2.Containers.Name_Type_List.Cursor := FB_List.First; N_Target : constant Name_Type := Self.Normalized_Target (On_Target); use GPR2.Containers.Name_Type_List; begin while Cur /= GPR2.Containers.Name_Type_List.No_Element loop if Element (Cur) = N_Target then -- No point processing the same target again FB_List.Delete (Cur); exit; end if; Next (Cur); end loop; Cur := FB_List.First; while Cur /= GPR2.Containers.Name_Type_List.No_Element loop Trace (Match_Trace, "Attempting to fall back to target " & String (Element (Cur))); declare Local_Iter : Batch_Iterator (Length (Filters)); begin Local_Iter.Filters := Iterator.Filters; Compiler_Iterator.Foreach_In_Path (Self => Local_Iter, Base => Self, On_Target => Element (Cur), Environment => Environment, Extra_Dirs => Extra_Dirs); Found_All := True; C := First (Filters); for F in Local_Iter.Found_One'Range loop if not Local_Iter.Found_One (F) and then Self.Languages_Known.Contains (Compiler_Lists.Element (C).Language) then -- Not finding a compiler for an unknown language -- should not invalidate fallback search. Found_All := False; end if; Next (C); end loop; if Found_All then Iterator := Local_Iter; Selected_Target := To_Unbounded_String (String (Element (Cur))); Trace (Match_Trace, String (Element (Cur)) & " fallback target selected"); exit; end if; end; Next (Cur); end loop; end; end if; end if; C := First (Filters); for F in Iterator.Found_One'Range loop if not Iterator.Found_One (F) then declare Comp : constant Compiler := Compiler_Lists.Element (C); Language_Known : constant Boolean := Self.Languages_Known.Contains (Comp.Language); begin if not Language_Known then Errors.Append (Message.Create (Message.Information, "unknown language '" & Image (Comp.Language) & "'", Source_Reference.Create ("embedded_kb/kb", 0, 0))); else Errors.Append (Message.Create (Message.Warning, "can't find a toolchain " & "for the following configuration: language '" & Image (Comp.Language) & "', target '" & String (On_Target) & "'" & (if Comp.Runtime = Null_Unbounded_String then ", default runtime" else ", runtime '" & To_String (Comp.Runtime) & "'") & (if Comp.Version /= Null_Unbounded_String then ", version '" & To_String (Comp.Version) & "'" else "") & (if Comp.Path.Is_Defined then ", path '" & Comp.Path.Value & "'" else "") & (if Comp.Name /= Null_Unbounded_String then ", name '" & To_String (Comp.Name) & "'" else ""), Source_Reference.Create ("embedded_kb/kb", 0, 0))); end if; end; Found_All := False; end if; Next (C); end loop; -- If we could find at least one of each compiler, but that our initial -- attempt returned incompatible sets of compiler, we do a more thorough -- attempt now if Found_All and then Iterator.Found /= Iterator.Count then -- If no compatible set was found, try all possible combinations, in -- the hope that we can finally find one. In the following algorithm, -- we end up checking again some set that were checked in Callback, -- but that would be hard to avoid since the compilers can be found -- in any order. Increase_Indent (Match_Trace, "Attempting to find a supported compiler set"); -- Unselect all compilers C := First (Iterator.Compilers); while Has_Element (C) loop Set_Selection (Iterator.Compilers, C, False); Next (C); end loop; if not Foreach_Nth_Compiler (First (Iterator.Filters)) then Errors.Append (Message.Create (Message.Error, "no set of compatible compilers was found", Source_Reference.Create ("embedded_kb/kb", 0, 0))); Decrease_Indent (Match_Trace); raise No_Compatible_Compilers; end if; end if; Splice (Target => Compilers, Before => Compiler_Lists.No_Element, Source => Iterator.Compilers); end Complete_Command_Line_Compilers; ------------------- -- Configuration -- ------------------- function Configuration (Self : in out Object; Settings : Project.Configuration.Description_Set; Target : Name_Type; Messages : in out GPR2.Log.Object; Fallback : Boolean := False; Environment : GPR2.Environment.Object := GPR2.Environment.Process_Environment) return Ada.Strings.Unbounded.Unbounded_String is use Project.Configuration; Filters : Compiler_Lists.List; Compilers : Compiler_Lists.List; Selected_Target : Unbounded_String; Runtime_Specific_KB : Object; Langs : Ordered_Languages; Configuration_String : Unbounded_String; begin for Setting of Settings loop if Is_Language_With_No_Compiler (Self, Language (Setting)) then Compilers.Append (Create_Filter (Self, Setting)); elsif not Self.Languages_Known.Contains (Language (Setting)) then Messages.Append (Message.Create (Message.Information, "unknown language '" & Image (Language (Setting)) & "'", Source_Reference.Create ("embedded_kb/kb", 0, 0))); else Filters.Append (Create_Filter (Self, Setting)); Langs.Append (Language (Setting)); end if; end loop; begin Complete_Command_Line_Compilers (Self => Self, On_Target => Target, Filters => Filters, Compilers => Compilers, Selected_Target => Selected_Target, Fallback => Fallback, Errors => Messages, Environment => Environment); exception when No_Compatible_Compilers | Invalid_KB => return Null_Unbounded_String; end; -- Runtime dir may have additional knowledge base chunks specific to -- given runtime. We do not want to include them in Self, otherwise -- it becomes unusable for other runtimes/compilers. Runtime_Specific_KB := Self; for Comp of Compilers loop Update_With_Compiler_Runtime (Runtime_Specific_KB, Comp, Environment); end loop; Configuration_String := Runtime_Specific_KB.Generate_Configuration (Compilers, To_String (Selected_Target), Langs, Messages); return Configuration_String; end Configuration; ------------------- -- Configuration -- ------------------- function Configuration (Self : in out Object; Selection : Compiler_Array; Target : Name_Type; Messages : in out GPR2.Log.Object; Environment : GPR2.Environment.Object := GPR2.Environment.Process_Environment) return Ada.Strings.Unbounded.Unbounded_String is Configuration_String : Unbounded_String; Runtime_Specific_KB : Object; Compilers : Compiler_Lists.List; -- ??? atm follow order of selection Langs : Ordered_Languages; begin -- Runtime dir may have additional knowledge base chunks specific to -- given runtime. We do not want to include them in Self, otherwise -- it becomes unusable for other runtimes/compilers. Runtime_Specific_KB := Self; for Comp of Selection loop Update_With_Compiler_Runtime (Runtime_Specific_KB, Comp, Environment); Compilers.Append (Comp); Langs.Append (Comp.Language); end loop; Configuration_String := Runtime_Specific_KB.Generate_Configuration (Compilers, String (Target), Langs, Messages); return Configuration_String; end Configuration; ------------------------------ -- Configuration_Node_Image -- ------------------------------ function Configuration_Node_Image (Config : Configuration_Type) return Unbounded_String is Result : Unbounded_String; begin for Comp_Filter of Config.Compilers_Filters loop Append (Result, "<compilers negate='" & Comp_Filter.Negate'Img & "'>" & ASCII.LF); for Filter of Comp_Filter.Compiler loop Append (Result, " <compiler name='" & To_String (Filter.Name) & "' version='" & To_String (Filter.Version) & "' runtime='" & To_String (Filter.Runtime) & "' language='" & String (Name (Filter.Language)) & "' />" & ASCII.LF); end loop; Append (Result, "</compilers>" & ASCII.LF); end loop; Append (Result, "<config supported='" & Config.Supported'Img & "' />"); return Result; end Configuration_Node_Image; ------------ -- Create -- ------------ function Create (Flags : Parsing_Flags := Targetset_Only_Flags; Default_KB : Boolean := True; Custom_KB : GPR2.Path_Name.Set.Object := GPR2.Path_Name.Set.Empty_Set; Environment : GPR2.Environment.Object := GPR2.Environment.Process_Environment) return Object is Result : Object; begin if Default_KB then Result := Create_Default (Flags => Flags, Environment => Environment); else Result := Create_Empty; end if; for Location of Custom_KB loop Result.Add (Flags, Location, Environment); end loop; return Result; end Create; ------------ -- Create -- ------------ function Create (Content : GPR2.Containers.Value_List; Flags : Parsing_Flags; Environment : GPR2.Environment.Object := GPR2.Environment.Process_Environment) return Object is Result : Object := Create_Empty; begin for Cont of Content loop if Cont /= "" then Result.Add (Flags, Cont, Environment); end if; end loop; return Result; end Create; ------------ -- Create -- ------------ function Create (Location : GPR2.Path_Name.Object; Flags : Parsing_Flags; Environment : GPR2.Environment.Object := GPR2.Environment.Process_Environment) return Object is Result : Object := Create_Empty; begin Result.Parsed_Directories.Append (Location); Parsing.Parse_Knowledge_Base (Result, Location, Flags, Environment); return Result; end Create; -------------------- -- Create_Default -- -------------------- function Create_Default (Flags : Parsing_Flags; Environment : GPR2.Environment.Object := GPR2.Environment.Process_Environment) return Object is Ret : Object; begin Ret := Parsing.Parse_Default_Knowledge_Base (Flags, Environment); return Ret; end Create_Default; ------------------ -- Create_Empty -- ------------------ function Create_Empty return Object is Result : Object; begin Result.Initialized := True; Result.Is_Default := False; return Result; end Create_Empty; ------------------- -- Create_Filter -- ------------------- function Create_Filter (Self : Object; Descr : Project.Configuration.Description) return Compiler is use GNATCOLL.Traces; use Project.Configuration; Result : Compiler; Lang_Id : Language_Id renames Language (Descr); Exec_Suffix : constant String := Get_Executable_Suffix; function Legacy_Name_Support (Name : String; Lang : Language_Id) return String; -- For Ada, gnatmake was previously used to detect a GNAT compiler. -- However, as gnatmake may not be present in all the GNAT -- distributions, gnatls is now used. For upward compatibility, -- replace gnatmake with gnatls, so that a GNAT compiler may -- be detected. ------------------------- -- Legacy_Name_Support -- ------------------------- function Legacy_Name_Support (Name : String; Lang : Language_Id) return String is use Ada.Strings.Fixed; Idx : constant Natural := Index (Name, "gnatmake"); begin if Lang = Ada_Language and then Idx >= Name'First then return Replace_Slice (Name, Idx, Idx + 7, "gnatls"); else return Name; end if; end Legacy_Name_Support; begin Result.Language := Lang_Id; if Is_Language_With_No_Compiler (Self, Language (Descr)) then Trace (Main_Trace, "Language " & Image (Lang_Id) & " requires no compiler"); Result.Complete := True; Result.Selected := True; Result.Targets_Set := All_Target_Sets; return Result; end if; Result.Version := To_Unbounded_String (String (Version (Descr))); Result.Runtime := To_Unbounded_String (String (Runtime (Descr))); if Result.Runtime /= Null_Unbounded_String and then GNAT.OS_Lib.Is_Absolute_Path (To_String (Result.Runtime)) then -- If the runtime is a full path, set Runtime and -- Runtime_Dir to the same value. Result.Runtime_Dir := Result.Runtime; end if; if Path (Descr) /= No_Filename then Result.Path := Path_Name.Create_Directory (Path (Descr), Resolve_Links => True); end if; if Name (Descr) /= No_Name then Result.Name := To_Unbounded_String (GNAT.Directory_Operations.Base_Name (Legacy_Name_Support (String (Name (Descr)), Lang_Id), Exec_Suffix)); end if; Result.Complete := False; Trace (Main_Trace, "Language " & Image (Lang_Id) & " requires a compiler"); return Result; end Create_Filter; -------------------------------------- -- Default_Knowledge_Base_Directory -- -------------------------------------- function Default_Location return GPR2.Path_Name.Object is use GNATCOLL.VFS; use GNATCOLL.VFS_Utils; GPRbuild : Filesystem_String_Access := Locate_Exec_On_Path ("gprbuild"); Dir : Virtual_File; begin if GPRbuild = null then raise Default_Location_Error; end if; Dir := Get_Parent (Create (Dir_Name (GPRbuild.all))); Free (GPRbuild); if Dir = No_File then raise Default_Location_Error; end if; Dir := Dir.Join ("share").Join ("gprconfig"); if not OS_Lib.Is_Directory (Dir.Display_Full_Name) then raise Default_Location_Error; end if; return GPR2.Path_Name.Create_Directory (Filename_Type (Dir.Display_Full_Name)); end Default_Location; -------------------- -- Default_Target -- -------------------- function Default_Target return Name_Type is begin if not Default_Target_Parsed then Parse_Default_Target_Val; end if; if Default_Target_Val = Null_Unbounded_String then return Name_Type (System.OS_Constants.Target_Name); else return Name_Type (To_String (Default_Target_Val)); end if; end Default_Target; ----------------------------- -- Extra_Dirs_From_Filters -- ----------------------------- function Extra_Dirs_From_Filters (Filters : Compiler_Lists.List) return String is use Compiler_Lists; use GPR2.Path_Name; C : Compiler_Lists.Cursor := First (Filters); Extra_Dirs : Unbounded_String; Elem : Compiler; begin while Has_Element (C) loop Elem := Compiler_Lists.Element (C); if Elem.Path /= GPR2.Path_Name.Undefined then Append (Extra_Dirs, Elem.Path.Value & GNAT.OS_Lib.Path_Separator); end if; Next (C); end loop; return To_String (Extra_Dirs); end Extra_Dirs_From_Filters; ------------------- -- Fallback_List -- ------------------- function Fallback_List (Self : Object; Target : Name_Type) return GPR2.Containers.Name_List is use GPR2.Containers.Name_Type_List; N_Target : constant Name_Type := Self.Normalized_Target (Target); Result : GPR2.Containers.Name_List; Cur : GPR2.Containers.Name_Type_List.Cursor; begin for Fallback_List of Self.Fallback_Targets_Sets loop Result := Fallback_List; Cur := Result.First; while Cur /= No_Element loop if Element (Cur) = N_Target then return Result; end if; Next (Cur); end loop; end loop; Result.Clear; Result.Append (N_Target); return Result; end Fallback_List; --------------------------- -- Filter_Compilers_List -- --------------------------- procedure Filter_Compilers_List (Self : Object; Compilers : in out Compiler_Array; For_Target : Name_Type) is use GNATCOLL.Traces; For_Target_Set : constant Targets_Set_Id := Self.Query_Targets_Set (For_Target); Check_List : Compiler_Lists.List; begin Increase_Indent (Main_Trace, "Filtering the list of compilers"); for Idx in Compilers'Range loop if not Compilers (Idx).Selected then if For_Target_Set /= All_Target_Sets and then Compilers (Idx).Targets_Set /= All_Target_Sets and then Compilers (Idx).Targets_Set /= For_Target_Set then Compilers (Idx).Selectable := False; Trace (Main_Trace, "Incompatible target for: " & To_String (Compilers (Idx))); goto Next_Compiler; end if; for Other_Compiler of Compilers loop if Other_Compiler.Language = Compilers (Idx).Language and then Other_Compiler.Selected then Compilers (Idx).Selectable := False; Trace (Main_Trace, "Already selected language for: " & To_String (Compilers (Idx))); goto Next_Compiler; end if; end loop; -- We need to check if the resulting selection would -- lead to a supported configuration. Compilers (Idx).Selected := True; for Comp of Compilers loop Check_List.Append (Comp); end loop; Compilers (Idx).Selected := False; if not Is_Supported_Config (Self, Check_List) then Compilers (Idx).Selectable := False; Trace (Main_Trace, "Unsupported config for: " & To_String (Compilers (Idx))); goto Next_Compiler; end if; Compilers (Idx).Selectable := True; end if; <<Next_Compiler>> Check_List.Clear; end loop; Decrease_Indent (Main_Trace); end Filter_Compilers_List; ------------------ -- Filter_Match -- ------------------ function Filter_Match (Self : Object; Comp : Compiler; Filter : Compiler) return Boolean is use GNATCOLL.Traces; use GPR2.Path_Name; begin if Filter.Name /= Null_Unbounded_String and then Comp.Name /= Filter.Name and then Comp.Base_Name /= Filter.Name then Trace (Match_Trace, "Filter=" & To_String (Filter) & ": name does not match"); return False; end if; if Filter.Path.Is_Defined and then Filter.Path /= Comp.Path then Trace (Match_Trace, "Filter=" & To_String (Filter) & ": path does not match"); return False; end if; if Filter.Version /= Null_Unbounded_String and then Filter.Version /= Comp.Version then Trace (Match_Trace, "Filter=" & To_String (Filter) & ": version does not match"); return False; end if; if Comp.Any_Runtime then -- If compiler has no runtime node all runtimes should be accepted, -- no need to apply filter. if Filter.Runtime /= Null_Unbounded_String then if not GNAT.OS_Lib.Is_Absolute_Path (To_String (Filter.Runtime)) and then Filter.Runtime /= Comp.Runtime and then Filter.Runtime /= Comp.Alt_Runtime then Trace (Match_Trace, "Filter=" & To_String (Filter) & ": runtime does not match"); return False; end if; elsif not Comp.Default_Runtime then Trace (Match_Trace, "Filter=" & To_String (Filter) & ": no default runtime"); return False; end if; end if; if Filter.Language /= No_Language and then Filter.Language /= Comp.Language then Trace (Match_Trace, "Filter=" & To_String (Filter) & ": language does not match"); return False; end if; return True; end Filter_Match; ---------------------------- -- Generate_Configuration -- ---------------------------- function Generate_Configuration (Self : Object; Compilers : Compiler_Lists.List; Target : String; Langs : Ordered_Languages; Errors : in out Log.Object) return Unbounded_String is Project_Name : constant String := "Default"; Packages : String_Maps.Map; Result : Unbounded_String; procedure Add_Line (S : String); -- Appends to result the given string and a line terminator. There is no -- actual need for the terminators but it makes it more readable in -- traces. procedure Gen (C : String_Maps.Cursor); -- C is a cursor of the map "Packages" -- Generate the chunk of the config file corresponding to the -- given package. procedure Gen_And_Remove (Name : String); -- Generate the chunk of the config file corresponding to the -- package name and remove it from the map. -------------- -- Add_Line -- -------------- procedure Add_Line (S : String) is begin Append (Result, S & ASCII.LF); end Add_Line; --------- -- Gen -- --------- procedure Gen (C : String_Maps.Cursor) is use String_Maps; begin if Key (C) /= "" then Add_Line (""); Add_Line (" package " & Key (C) & " is"); end if; Add_Line (String_Maps.Element (C)); if Key (C) /= "" then Add_Line (" end " & Key (C) & ";"); end if; end Gen; -------------------- -- Gen_And_Remove -- -------------------- procedure Gen_And_Remove (Name : String) is use String_Maps; C : String_Maps.Cursor := Find (Packages, Name); begin if Has_Element (C) then Gen (C); Delete (Packages, C); end if; end Gen_And_Remove; begin for Config of Self.Configurations loop if Match (Config.Compilers_Filters, Compilers) and then Match (Config.Targets_Filters, Config.Negate_Targets, Compilers) then if not Config.Supported then Errors.Append (Message.Create (Message.Error, "Code generated by these compilers cannot be linked" & " as far as we know.", Sloc => Source_Reference.Create ("embedded_kb/kb", 0, 0))); return Null_Unbounded_String; end if; Merge_Config (Self, Packages, Compilers, To_String (Config.Config), Langs, Config.Sloc, Errors); end if; end loop; if Packages.Is_Empty then Errors.Append (Message.Create (Message.Error, "No valid configuration found", Sloc => Source_Reference.Create ("embedded_kb/kb", 0, 0))); return Null_Unbounded_String; end if; Add_Line ("configuration project " & Project_Name & " is"); Add_Line (" for Target use """ & Target & """;"); Add_Line (" for Canonical_Target use """ & String (Self.Normalized_Target (Name_Type (Target))) & """;"); -- Generate known packages in order. This takes care of possible -- dependencies. Gen_And_Remove (""); Gen_And_Remove ("Builder"); Gen_And_Remove ("Compiler"); Gen_And_Remove ("Naming"); Gen_And_Remove ("Binder"); Gen_And_Remove ("Linker"); -- Generate remaining packages Packages.Iterate (Gen'Access); Add_Line ("end " & Project_Name & ";"); return Result; exception when Invalid_KB => -- Errors have already been added to the log return Null_Unbounded_String; end Generate_Configuration; ------------------------ -- Get_External_Value -- ------------------------ procedure Get_External_Value (Attribute : String; Value : External_Value; Comp : Compiler; Environment : GPR2.Environment.Object; Split_Into_Words : Boolean := True; Merge_Same_Dirs : Boolean := False; Calls_Cache : in out GPR2.Containers.Name_Value_Map; Messages : in out Log.Object; Processed_Value : out External_Value_Lists.List; Ignore_Compiler : out Boolean) is use External_Value_Nodes; use GNAT.Regpat; use GNATCOLL.Traces; Error_Sloc : constant Source_Reference.Object := Value.Sloc; Saved_Path : constant String := Environment.Value ("PATH"); Used_Env : GPR2.Environment.Object := Environment; function Get_Command_Output_Cache (Path : String; Command : String) return Unbounded_String; -- Spawns given command and caches results. When the same command -- (same full path and arguments) should be spawned again, -- returns output from cache instead. ------------------------------ -- Get_Command_Output_Cache -- ------------------------------ function Get_Command_Output_Cache (Path : String; Command : String) return Unbounded_String is use GNAT.OS_Lib; use GPR2.Containers.Name_Value_Map_Package; Path_Dir : constant String := GPR2.Path_Name.Create_Directory (Filename_Type (Path)).Dir_Name; Key : constant Name_Type := Name_Type (Path_Dir & Command); Cur : constant GPR2.Containers.Name_Value_Map_Package.Cursor := Calls_Cache.Find (Key); Tmp_Result : Unbounded_String; begin if Cur = GPR2.Containers.Name_Value_Map_Package.No_Element then declare Args : Argument_List_Access := Argument_String_To_List (Command); Args_Vector : GNATCOLL.OS.Process.Argument_List; Dummy : Integer; begin Args_Vector.Append (Path_Dir & Args (Args'First).all); for J in Args'First + 1 .. Args'Last loop Args_Vector.Append (Args (J).all); end loop; OS_Lib.Free (Args); Tmp_Result := GNATCOLL.OS.Process.Run (Args => Args_Vector, Env => Used_Env.To_GNATCOLL_Environment, Stdin => GNATCOLL.OS.Process.FS.Null_FD, Stderr => GNATCOLL.OS.Process.FS.To_Stdout, Status => Dummy, Inherit_Env => Used_Env.Inherit); Args_Vector.Clear; Calls_Cache.Include (Key, To_String (Tmp_Result)); return Tmp_Result; end; else return To_Unbounded_String (Calls_Cache.Element (Key)); end if; end Get_Command_Output_Cache; Extracted_From : Unbounded_String := Null_Unbounded_String; Tmp_Result : Unbounded_String; Node_Cursor : External_Value_Nodes.Cursor := Value.EV.First; Node : External_Value_Node; From_Static : Boolean := False; Visited : String_To_External_Value.Map; begin Processed_Value.Clear; Ignore_Compiler := False; while Has_Element (Node_Cursor) loop while Has_Element (Node_Cursor) loop Node := External_Value_Nodes.Element (Node_Cursor); case Node.Typ is when Value_Variable => Extracted_From := Node.Var_Name; when Value_Constant => if Node.Value = Null_Unbounded_String then Tmp_Result := Null_Unbounded_String; else Tmp_Result := To_Unbounded_String (Substitute_Variables_In_Compiler_Description (To_String (Node.Value), Comp, Error_Sloc, Messages)); end if; From_Static := True; Trace (Main_Trace, Attribute & ": constant := " & To_String (Tmp_Result)); when Value_Shell => Used_Env.Insert ("PATH", Comp.Path.Value & OS_Lib.Path_Separator & Saved_Path); declare Command : constant String := Substitute_Variables_In_Compiler_Description (To_String (Node.Command), Comp, Error_Sloc, Messages); begin Tmp_Result := Null_Unbounded_String; Tmp_Result := Get_Command_Output_Cache (Comp.Path.Value, Command); Used_Env := Environment; Trace (Main_Trace, Attribute & ": executing """ & Command & """ output=""" & To_String (Tmp_Result) & """"); exception when GNATCOLL.OS.OS_Error => Trace (Main_Trace, "Spawn failed for " & Command); end; when Value_Directory => declare Search : constant String := Substitute_Variables_In_Compiler_Description (To_String (Node.Directory), Comp, Error_Sloc, Messages); begin if Search (Search'First) = '/' then Increase_Indent (Main_Trace, Attribute & ": search directories matching " & Search & ", starting from /"); Parse_All_Dirs (Processed_Value => Processed_Value, Visited => Visited, Current_Dir => "", Path_To_Check => Search, Contents => Node.Contents, Regexp => Compile (Search (Search'First + 1 .. Search'Last)), Regexp_Str => Search, Value_If_Match => To_String (Node.Dir_If_Match), Merge_Same_Dirs => Merge_Same_Dirs, Group => Node.Directory_Group, Error_Sloc => Error_Sloc, Messages => Messages); else Increase_Indent (Main_Trace, Attribute & ": search directories matching " & Search & ", starting from " & Comp.Path.Value); Parse_All_Dirs (Processed_Value => Processed_Value, Visited => Visited, Current_Dir => Comp.Path.Value, Path_To_Check => Search, Contents => Node.Contents, Regexp => Compile (Search), Regexp_Str => Search, Value_If_Match => To_String (Node.Dir_If_Match), Merge_Same_Dirs => Merge_Same_Dirs, Group => Node.Directory_Group, Error_Sloc => Error_Sloc, Messages => Messages); end if; Decrease_Indent (Main_Trace, "Done search directories"); end; when Value_Grep => declare Tmp_Str : constant String := To_String (Tmp_Result); Matched : Match_Array (0 .. Node.Group); begin Match (Node.Regexp_Re.Element, Tmp_Str, Matched); if Matched (0) /= No_Match then Tmp_Result := To_Unbounded_String (Tmp_Str (Matched (Node.Group).First .. Matched (Node.Group).Last)); Trace (Main_Trace, Attribute & ": grep matched=""" & To_String (Tmp_Result) & """"); else Tmp_Result := Null_Unbounded_String; Trace (Main_Trace, Attribute & ": grep no match"); end if; end; when Value_Nogrep => declare Tmp_Str : constant String := To_String (Tmp_Result); Matched : Match_Array (0 .. 0); begin Match (Node.Regexp_No.Element, Tmp_Str, Matched); if Matched (0) /= No_Match then Trace (Main_Trace, Attribute & ": nogrep matched=""" & Tmp_Str & """"); Ignore_Compiler := True; return; else Trace (Main_Trace, Attribute & ": nogrep no match"); end if; end; when Value_Must_Match => if not Match (Expression => To_String (Node.Must_Match), Data => To_String (Tmp_Result)) then Trace (Main_Trace, "Ignore compiler since external value """ & To_String (Tmp_Result) & """ must match " & To_String (Node.Must_Match)); Tmp_Result := Null_Unbounded_String; Ignore_Compiler := True; return; end if; exit; when Value_Done | Value_Filter => exit; end case; Next (Node_Cursor); end loop; case Node.Typ is when Value_Done | Value_Filter | Value_Must_Match => if Tmp_Result = Null_Unbounded_String then -- Value could not be computed if Extracted_From /= Null_Unbounded_String then Processed_Value.Append (External_Value_Item' (Value => Null_Unbounded_String, Alternate => Null_Unbounded_String, Extracted_From => Extracted_From)); end if; elsif Split_Into_Words then declare Filter : constant String := (if Node.Typ = Value_Filter then To_String (Node.Filter) else ""); Split : Containers.Value_List; begin -- When an external value is defined as a static string, -- the only valid separator is ','. When computed -- however, we also allow space as a separator. if From_Static then Get_Words (Words => To_String (Tmp_Result), Filter => Filter, Separator1 => ',', Separator2 => ',', Map => Split, Allow_Empty_Elements => False); else Get_Words (Words => To_String (Tmp_Result), Filter => Filter, Separator1 => ' ', Separator2 => ',', Map => Split, Allow_Empty_Elements => False); end if; for Elem of Split loop Processed_Value.Append (External_Value_Item' (Value => To_Unbounded_String (String (Elem)), Alternate => Null_Unbounded_String, Extracted_From => Extracted_From)); end loop; end; else Processed_Value.Append (External_Value_Item' (Value => Tmp_Result, Alternate => Null_Unbounded_String, Extracted_From => Extracted_From)); end if; when others => null; end case; Extracted_From := Null_Unbounded_String; Next (Node_Cursor); end loop; end Get_External_Value; -------------------------- -- Get_String_No_Adalib -- -------------------------- function Get_String_No_Adalib (Str : String) return String is use GNAT.OS_Lib; Name : constant String (1 .. Str'Length) := Str; Last : Natural := Name'Last; begin if Last > 7 and then (Name (Last) in Directory_Separator | '/') then Last := Last - 1; end if; if Last > 6 and then Name (Last - 5 .. Last) = "adalib" and then (Name (Last - 6) in Directory_Separator | '/') then Last := Last - 6; else Last := Name'Last; end if; return Name (1 .. Last); end Get_String_No_Adalib; ------------------------ -- Get_Variable_Value -- ------------------------ function Get_Variable_Value (Comp : Compiler; Name : String) return String is N : constant Unbounded_String := To_Unbounded_String (Name); begin if Variables_Maps.Contains (Comp.Variables, N) then return To_String (Variables_Maps.Element (Comp.Variables, N)); elsif Name = "HOST" then return String (Default_Target); elsif Name = "TARGET" then return To_String (Comp.Target); elsif Name = "RUNTIME_DIR" then return Name_As_Directory (To_String (Comp.Runtime_Dir)); elsif Name = "EXEC" then return To_String (Comp.Executable); elsif Name = "VERSION" then return To_String (Comp.Version); elsif Name = "LANGUAGE" then return String (GPR2.Name (Comp.Language)); elsif Name = "RUNTIME" then return To_String (Comp.Runtime); elsif Name = "PREFIX" then return To_String (Comp.Prefix); elsif Name = "PATH" then return GNAT.OS_Lib.Normalize_Pathname (Comp.Path.Value, Case_Sensitive => False) & GNAT.OS_Lib.Directory_Separator; elsif Name = "GPRCONFIG_PREFIX" then return GPR_Executable_Prefix_Path; end if; raise Invalid_KB with "variable '" & Name & "' is not defined"; end Get_Variable_Value; --------------- -- Get_Words -- --------------- procedure Get_Words (Words : String; Filter : String; Separator1 : Character; Separator2 : Character; Map : out Containers.Value_List; Allow_Empty_Elements : Boolean) is First : Integer := Words'First; Last : Integer; Filter_Set : GPR2.Containers.Value_List; begin if Filter /= "" then Get_Words (Filter, "", Separator1, Separator2, Filter_Set, Allow_Empty_Elements => True); end if; if not Allow_Empty_Elements then while First <= Words'Last and then (Words (First) = Separator1 or else Words (First) = Separator2) loop First := First + 1; end loop; end if; while First <= Words'Last loop if Words (First) /= Separator1 and then Words (First) /= Separator2 then Last := First + 1; while Last <= Words'Last and then Words (Last) /= Separator1 and then Words (Last) /= Separator2 loop Last := Last + 1; end loop; else Last := First; end if; if (Allow_Empty_Elements or else First <= Last - 1) and then (Filter_Set.Is_Empty or else Filter_Set.Contains (Value_Type (Words (First .. Last - 1)))) then Map.Append (Value_Type (Words (First .. Last - 1))); end if; First := Last + 1; end loop; end Get_Words; -------------------------------- -- GPR_Executable_Prefix_Path -- -------------------------------- function GPR_Executable_Prefix_Path return String is use Ada.Directories; use Ada.Strings.Fixed; use GNAT.OS_Lib; Tools_Dir : constant String := Get_Tools_Directory; Exec_Name : constant String := Normalize_Pathname (Ada.Command_Line.Command_Name, Resolve_Links => True); begin if Has_Directory_Separator (Exec_Name) and then Head (Base_Name (Exec_Name), 3) = "gpr" and then Base_Name (Containing_Directory (Exec_Name)) = "bin" then -- A gprtool has been called with path prefix, we need -- to return the prefix of corresponding gprtools installation, -- in case it is not the first one on the path. return Containing_Directory (Containing_Directory (Exec_Name)) & GNAT.OS_Lib.Directory_Separator; end if; -- It's either a gprtool called by base name or another kind of tool, -- in both cases we need to find gprtools on PATH. if Tools_Dir = "" then return ""; else return Tools_Dir & GNAT.OS_Lib.Directory_Separator; end if; end GPR_Executable_Prefix_Path; ---------------------------------- -- Is_Language_With_No_Compiler -- ---------------------------------- function Is_Language_With_No_Compiler (Self : Object; Language : Language_Id) return Boolean is begin return Self.No_Compilers.Contains (Language); end Is_Language_With_No_Compiler; ------------------------- -- Is_Supported_Config -- ------------------------- function Is_Supported_Config (Self : Object; Compilers : Compiler_Lists.List) return Boolean is use Configuration_Lists; Config : Configuration_Lists.Cursor := First (Self.Configurations); M : Boolean; begin while Has_Element (Config) loop M := Match (Configuration_Lists.Element (Config).Compilers_Filters, Compilers); if M and then Match (Configuration_Lists.Element (Config).Targets_Filters, Configuration_Lists.Element (Config).Negate_Targets, Compilers) then if not Configuration_Lists.Element (Config).Supported then GNATCOLL.Traces.Trace (Match_Trace, "Selected compilers are not compatible, because of:"); GNATCOLL.Traces.Trace (Match_Trace, To_String (Configuration_Node_Image (Configuration_Lists.Element (Config)))); return False; end if; end if; Next (Config); end loop; return True; end Is_Supported_Config; -------------------------- -- Known_Compiler_Names -- -------------------------- function Known_Compiler_Names (Self : Object) return Unbounded_String is use Compiler_Description_Maps; Result : Unbounded_String; Cur : Compiler_Description_Maps.Cursor := Self.Compilers.First; begin while Has_Element (Cur) loop if Result /= Null_Unbounded_String then Append (Result, ","); end if; Append (Result, String (Key (Cur))); Next (Cur); end loop; return Result; end Known_Compiler_Names; ----------- -- Match -- ----------- function Match (Filter : Compilers_Filter_Lists.List; Compilers : Compiler_Lists.List) return Boolean is use Compilers_Filter_Lists; C : Compilers_Filter_Lists.Cursor := First (Filter); M : Boolean; begin while Has_Element (C) loop M := Match (Compilers_Filter_Lists.Element (C), Compilers); if not M then return False; end if; Next (C); end loop; return True; end Match; ----------- -- Match -- ----------- function Match (Filter : Compilers_Filter; Compilers : Compiler_Lists.List) return Boolean is use Compiler_Filter_Lists; C : Compiler_Filter_Lists.Cursor := First (Filter.Compiler); M : Boolean; begin while Has_Element (C) loop M := Match (Compiler_Filter_Lists.Element (C), Compilers); if M then return not Filter.Negate; end if; Next (C); end loop; return Filter.Negate; end Match; ----------- -- Match -- ----------- function Match (Filter : Compiler_Filter; Compilers : Compiler_Lists.List) return Boolean is use Compiler_Lists; use GNAT.Regpat; C : Compiler_Lists.Cursor := First (Compilers); Comp : Compiler; function Runtime_Base_Name (Rt : Unbounded_String) return String is (GNAT.Directory_Operations.Base_Name (To_String (Rt))); -- Runtime filters should only apply to the base name of runtime when -- full path is given, otherwise we can potentially match some unrelated -- patterns from enclosing directory names. function Name_Matches return Boolean; function Version_Matches return Boolean; function Runtime_Matches return Boolean; function Language_Matches return Boolean; -- Predicates checking matching of corresponding attributes ---------------------- -- Language_Matches -- ---------------------- function Language_Matches return Boolean is begin if Filter.Language = No_Language or else Filter.Language = Comp.Language then return True; end if; return False; end Language_Matches; ------------------ -- Name_Matches -- ------------------ function Name_Matches return Boolean is begin if Filter.Name = Null_Unbounded_String then return True; end if; if Comp.Name /= Null_Unbounded_String and then Match (Filter.Name_Re.Element, To_String (Comp.Name)) then return True; end if; if Comp.Base_Name = Filter.Name then return True; end if; return False; end Name_Matches; --------------------- -- Runtime_Matches -- --------------------- function Runtime_Matches return Boolean is begin if Filter.Runtime_Re.Is_Empty then return True; end if; if Comp.Runtime /= Null_Unbounded_String and then Match (Filter.Runtime_Re.Element, Runtime_Base_Name (Comp.Runtime)) then return True; end if; return False; end Runtime_Matches; ---------------------- -- Version_Matches -- ---------------------- function Version_Matches return Boolean is begin if Filter.Version_Re.Is_Empty then return True; end if; if Comp.Version /= Null_Unbounded_String and then Match (Filter.Version_Re.Element, To_String (Comp.Version)) then return True; end if; return False; end Version_Matches; begin while Has_Element (C) loop Comp := Compiler_Lists.Element (C); if Comp.Selected and then Name_Matches and then Version_Matches and then Runtime_Matches and then Language_Matches then return True; end if; Next (C); end loop; return False; end Match; ----------- -- Match -- ----------- function Match (Target_Filter : Double_String_Lists.List; Negate : Boolean; Compilers : Compiler_Lists.List) return Boolean is use Compiler_Lists; use Double_String_Lists; use GNAT.Regpat; Target : Double_String_Lists.Cursor := First (Target_Filter); Comp : Compiler_Lists.Cursor; begin if Is_Empty (Target_Filter) then return True; else while Has_Element (Target) loop declare Positive_Pattern : constant Pattern_Matcher := Compile (To_String (Double_String_Lists.Element (Target).Positive_Regexp), GNAT.Regpat.Case_Insensitive); Negative_Pattern : constant Pattern_Matcher := Compile (To_String (Double_String_Lists.Element (Target).Negative_Regexp), GNAT.Regpat.Case_Insensitive); Ignore_Negative : constant Boolean := Double_String_Lists.Element (Target).Negative_Regexp = ""; begin Comp := First (Compilers); while Has_Element (Comp) loop if Compiler_Lists.Element (Comp).Selected then if Compiler_Lists.Element (Comp).Target = Null_Unbounded_String then if Match (Positive_Pattern, "") then return not Negate; end if; elsif Match (Positive_Pattern, To_String (Compiler_Lists.Element (Comp).Target)) and then (Ignore_Negative or else not Match (Negative_Pattern, To_String (Compiler_Lists.Element (Comp).Target))) then return not Negate; end if; end if; Next (Comp); end loop; end; Next (Target); end loop; return Negate; end if; end Match; ------------------ -- Merge_Config -- ------------------ procedure Merge_Config (Self : Object; Packages : in out String_Maps.Map; Compilers : Compiler_Lists.List; Config : String; Langs : Ordered_Languages; Error_Sloc : Source_Reference.Object; Errors : in out Log.Object) is procedure Add_Package (Name : String; Chunk : String; Prefix : String := " "); -- Add the chunk in the appropriate package procedure Skip_Spaces (Str : String; Index : in out Integer); -- Move Index from its current position to the next non-whitespace -- character in Str procedure Skip_Spaces_Backward (Str : String; Index : in out Integer); -- Same as Skip_Spaces, but goes backward ----------------- -- Add_Package -- ----------------- procedure Add_Package (Name : String; Chunk : String; Prefix : String := " ") is use String_Maps; C : constant String_Maps.Cursor := Find (Packages, Name); Replaced : constant String := Substitute_Variables_In_Configuration (Self, Chunk, Compilers, Langs, Error_Sloc, Errors); begin if Replaced /= "" then if Has_Element (C) then Replace_Element (Packages, C, Element (C) & ASCII.LF & Prefix & Replaced); else Insert (Packages, Name, Prefix & Replaced); end if; end if; end Add_Package; ----------------- -- Skip_Spaces -- ----------------- procedure Skip_Spaces (Str : String; Index : in out Integer) is begin while Index <= Str'Last and then (Str (Index) = ' ' or else Str (Index) = ASCII.LF) loop Index := Index + 1; end loop; end Skip_Spaces; -------------------------- -- Skip_Spaces_Backward -- -------------------------- procedure Skip_Spaces_Backward (Str : String; Index : in out Integer) is begin while Index >= Str'First and then (Str (Index) = ' ' or else Str (Index) = ASCII.LF) loop Index := Index - 1; end loop; end Skip_Spaces_Backward; First : Integer := Config'First; Pkg_Name_First, Pkg_Name_Last : Integer; Pkg_Content_First : Integer; Last : Integer; use Ada.Strings.Fixed; begin while First /= 0 and then First <= Config'Last loop -- Do we have a top-level attribute ? Skip_Spaces (Config, First); Pkg_Name_First := Index (Config (First .. Config'Last), "package "); if Pkg_Name_First = 0 then Pkg_Name_First := Config'Last + 1; end if; Last := Pkg_Name_First - 1; Skip_Spaces_Backward (Config, Last); Add_Package (Name => "", Chunk => Config (First .. Last), Prefix => " "); exit when Pkg_Name_First > Config'Last; -- Parse the current package Pkg_Name_First := Pkg_Name_First + 8; -- skip "package " Skip_Spaces (Config, Pkg_Name_First); Pkg_Name_Last := Pkg_Name_First + 1; while Pkg_Name_Last <= Config'Last and then Config (Pkg_Name_Last) /= ' ' and then Config (Pkg_Name_Last) /= ASCII.LF loop Pkg_Name_Last := Pkg_Name_Last + 1; end loop; Pkg_Content_First := Pkg_Name_Last + 1; Skip_Spaces (Config, Pkg_Content_First); Pkg_Content_First := Pkg_Content_First + 2; -- skip "is" Skip_Spaces (Config, Pkg_Content_First); Last := Index (Config (Pkg_Content_First .. Config'Last), "end " & Config (Pkg_Name_First .. Pkg_Name_Last - 1)); if Last /= 0 then First := Last - 1; Skip_Spaces_Backward (Config, First); Add_Package (Name => Config (Pkg_Name_First .. Pkg_Name_Last - 1), Chunk => Config (Pkg_Content_First .. First)); while Last <= Config'Last and then Config (Last) /= ';' loop Last := Last + 1; end loop; Last := Last + 1; end if; First := Last; end loop; end Merge_Config; ----------------------- -- Name_As_Directory -- ----------------------- function Name_As_Directory (Dir : String) return String is use GNAT.OS_Lib; begin if Dir = "" or else Dir (Dir'Last) in Directory_Separator | '/' then return Dir; else return Dir & Directory_Separator; end if; end Name_As_Directory; ----------------------- -- Normalized_Target -- ----------------------- function Normalized_Target (Self : Object; Target : Name_Type) return Name_Type is Result : Target_Set_Description; begin Result := Targets_Set_Vectors.Element (Self.Targets_Sets, Self.Query_Targets_Set (Target)); return Name_Type (To_String (Result.Name)); exception when others => return "unknown"; end Normalized_Target; -------------------- -- Parse_All_Dirs -- -------------------- procedure Parse_All_Dirs (Processed_Value : out External_Value_Lists.List; Visited : in out String_To_External_Value.Map; Current_Dir : String; Path_To_Check : String; Regexp : Regpat.Pattern_Matcher; Regexp_Str : String; Value_If_Match : String; Group : Integer; Group_Match : String := ""; Group_Count : Natural := 0; Contents : Pattern_Matcher_Holder; Merge_Same_Dirs : Boolean; Error_Sloc : Source_Reference.Object; Messages : in out Log.Object) is use GNAT.Regpat; use GNAT.OS_Lib; use GNATCOLL.Traces; procedure Save_File (Current_Dir : String; Val : String); -- Mark the given directory as valid for the <directory> configuration. -- This takes care of removing duplicates if needed. function Is_Regexp (Str : String) return Boolean; -- Whether Str is a regular expression function Unquote_Regexp (Str : String; Remove_Quoted : Boolean := False) return String; -- Remove special '\' quoting characters from Str. -- As a special case, if Remove_Quoted is true, then '\' -- and the following char are simply omitted in the output. -- For instance: -- Str="A\." Remove_Quoted=False => output is "A." -- Str="A\." Remove_Quoted=False => output is "A" --------------- -- Is_Regexp -- --------------- function Is_Regexp (Str : String) return Boolean is -- Take into account characters quoted by '\'. We just remove them -- for now, so that when we quote the regexp it won't see these -- potentially special characters. -- The goal is that for instance "\.\." is not considered -- as a regexp, but "\.." is. Str2 : constant String := Unquote_Regexp (Str, Remove_Quoted => True); begin return Regpat.Quote (Str2) /= Str2; end Is_Regexp; --------------- -- Save_File -- --------------- procedure Save_File (Current_Dir : String; Val : String) is begin if not Merge_Same_Dirs then Trace (Main_Trace, "<dir>: SAVE " & Current_Dir); Processed_Value.Append ((Value => To_Unbounded_String (Val), Alternate => Null_Unbounded_String, Extracted_From => To_Unbounded_String (Get_String_No_Adalib (Current_Dir)))); else declare use String_To_External_Value; Normalized : constant String := Normalize_Pathname (Name => Current_Dir, Directory => "", Resolve_Links => True, Case_Sensitive => True); Prev : External_Value_Lists.Cursor; Rec : External_Value_Item; begin if Visited.Contains (Normalized) then Trace (Main_Trace, "<dir>: ALREADY FOUND (" & Val & ") " & Current_Dir); Prev := Visited.Element (Normalized); Rec := External_Value_Lists.Element (Prev); Rec.Alternate := To_Unbounded_String (Val); External_Value_Lists.Replace_Element (Container => Processed_Value, Position => Prev, New_Item => Rec); else Trace (Main_Trace, "<dir>: SAVE (" & Val & ") " & Current_Dir); Processed_Value.Append ((Value => To_Unbounded_String (Val), Alternate => Null_Unbounded_String, Extracted_From => To_Unbounded_String (Get_String_No_Adalib (Current_Dir)))); Visited.Include (Normalized, External_Value_Lists.Last (Processed_Value)); end if; end; end if; end Save_File; -------------------- -- Unquote_Regexp -- -------------------- function Unquote_Regexp (Str : String; Remove_Quoted : Boolean := False) return String is Str2 : String (Str'Range); S : Integer := Str'First; Index : Integer := Str2'First; begin while S <= Str'Last loop if Str (S) = '\' then S := S + 1; if not Remove_Quoted then Str2 (Index) := Str (S); Index := Index + 1; end if; else Str2 (Index) := Str (S); Index := Index + 1; end if; S := S + 1; end loop; return Str2 (Str2'First .. Index - 1); end Unquote_Regexp; First : constant Integer := Path_To_Check'First; Last : Integer; Val : Unbounded_String; begin if Path_To_Check'Length = 0 or else Path_To_Check = "/" or else Path_To_Check = String'(1 => Directory_Separator) then if Group = -1 then Val := To_Unbounded_String (Value_If_Match); else Val := To_Unbounded_String (Group_Match); end if; if not Contents.Is_Empty and then Is_Regular_File (Current_Dir) then Trace (Main_Trace, "<dir>: Checking inside file " & Current_Dir); declare use Ada.Text_IO; use Directory_Operations; F : File_Type; begin Open (F, In_File, Current_Dir); while not End_Of_File (F) loop declare Line : constant String := Get_Line (F); begin Trace (Main_Trace, "<dir>: read line " & Line); if Match (Contents.Element, Line) then Save_File (Normalize_Pathname (Name => Line, Directory => Dir_Name (Current_Dir), Resolve_Links => True), To_String (Val)); exit; end if; end; end loop; Close (F); end; else Save_File (Current_Dir, To_String (Val)); end if; else -- Do not split on '\', since we document we only accept UNIX paths -- anyway. This leaves \ for regexp quotes. Last := First + 1; while Last <= Path_To_Check'Last and then Path_To_Check (Last) /= '/' loop Last := Last + 1; end loop; -- If we do not have a regexp if not Is_Regexp (Path_To_Check (First .. Last - 1)) then declare Dir : constant String := Normalize_Pathname (Current_Dir, Resolve_Links => False) & Directory_Separator & Unquote_Regexp (Path_To_Check (First .. Last - 1)); Remains : constant String := Path_To_Check (Last + 1 .. Path_To_Check'Last); begin if (Remains'Length = 0 or else Remains = "/" or else Remains = String'(1 => Directory_Separator)) and then Is_Regular_File (Dir) then Trace (Main_Trace, "<dir>: Found file " & Dir); -- If there is such a subdir, keep checking Parse_All_Dirs (Processed_Value => Processed_Value, Visited => Visited, Current_Dir => Dir, Path_To_Check => Remains, Regexp => Regexp, Regexp_Str => Regexp_Str, Value_If_Match => Value_If_Match, Group => Group, Group_Match => Group_Match, Group_Count => Group_Count, Contents => Contents, Merge_Same_Dirs => Merge_Same_Dirs, Error_Sloc => Error_Sloc, Messages => Messages); elsif Is_Directory (Dir) then Trace (Main_Trace, "<dir>: Recurse into " & Dir); -- If there is such a subdir, keep checking Parse_All_Dirs (Processed_Value => Processed_Value, Visited => Visited, Current_Dir => Dir & Directory_Separator, Path_To_Check => Remains, Regexp => Regexp, Regexp_Str => Regexp_Str, Value_If_Match => Value_If_Match, Group => Group, Group_Match => Group_Match, Group_Count => Group_Count, Contents => Contents, Merge_Same_Dirs => Merge_Same_Dirs, Error_Sloc => Error_Sloc, Messages => Messages); else Trace (Main_Trace, "<dir>: No such directory: " & Dir); end if; end; -- Else we have a regexp, check all files else declare use Ada.Directories; File_Re : constant String := Path_To_Check (First .. Last - 1); File_Regexp : constant Pattern_Matcher := Compile (File_Re); Search : Search_Type; File : Directory_Entry_Type; Filter : Ada.Directories.Filter_Type; begin if File_Re = ".." then Trace (Main_Trace, "Potential error: .. is generally not meant as a regexp," & " and should be quoted in this case, as in \.\."); end if; if Path_To_Check (Last) = '/' then Trace (Main_Trace, "<dir>: Check directories in " & Current_Dir & " that match " & File_Re); Filter := (Directory => True, others => False); else Trace (Main_Trace, "<dir>: Check files in " & Current_Dir & " that match " & File_Re); Filter := (others => True); end if; Start_Search (Search => Search, Directory => Current_Dir, Filter => Filter, Pattern => ""); while More_Entries (Search) loop begin Get_Next_Entry (Search, File); exception when E : others => Trace (Main_Trace, "<dir>: ignoring entry, " & Ada.Exceptions.Exception_Message (E)); goto Next_Entry; end; if Directories.Simple_Name (File) /= "." and then Directories.Simple_Name (File) /= ".." then declare Simple : constant String := Directories.Simple_Name (File); Count : constant Natural := Paren_Count (File_Regexp); Matched : Match_Array (0 .. Integer'Max (Group, 0)); begin Match (File_Regexp, Simple, Matched); if Matched (0) /= No_Match then Trace (Main_Trace, "<dir>: Matched " & Ada.Directories.Simple_Name (File)); if Group_Count < Group and then Group_Count + Count >= Group then if Matched (Group - Group_Count) = No_Match then Trace (Main_Trace, "<dir>: Matched group is empty, skipping"); return; end if; Trace (Main_Trace, "<dir>: Found matched group: " & Simple (Matched (Group - Group_Count).First .. Matched (Group - Group_Count).Last)); Parse_All_Dirs (Processed_Value => Processed_Value, Visited => Visited, Current_Dir => Full_Name (File) & Directory_Separator, Path_To_Check => Path_To_Check (Last + 1 .. Path_To_Check'Last), Regexp => Regexp, Regexp_Str => Regexp_Str, Value_If_Match => Value_If_Match, Group => Group, Group_Match => Simple (Matched (Group - Group_Count).First .. Matched (Group - Group_Count).Last), Group_Count => Group_Count + Count, Contents => Contents, Merge_Same_Dirs => Merge_Same_Dirs, Error_Sloc => Error_Sloc, Messages => Messages); else Parse_All_Dirs (Processed_Value => Processed_Value, Visited => Visited, Current_Dir => Full_Name (File) & Directory_Separator, Path_To_Check => Path_To_Check (Last + 1 .. Path_To_Check'Last), Regexp => Regexp, Regexp_Str => Regexp_Str, Value_If_Match => Value_If_Match, Group => Group, Group_Match => Group_Match, Group_Count => Group_Count + Count, Contents => Contents, Merge_Same_Dirs => Merge_Same_Dirs, Error_Sloc => Error_Sloc, Messages => Messages); end if; end if; end; end if; << Next_Entry >> end loop; end; end if; end if; end Parse_All_Dirs; ------------------------------ -- Parse_Default_Target_Val -- ------------------------------ procedure Parse_Default_Target_Val is use GNATCOLL.Traces; use GNAT.OS_Lib; Tgt_File_Base : constant String := "default_target"; Tgt_File_Full : constant String := GPR_Executable_Prefix_Path & "share" & Directory_Separator & "gprconfig" & Directory_Separator & Tgt_File_Base; F : Ada.Text_IO.File_Type; begin Trace (Main_Trace, "Parsing default target"); Default_Target_Parsed := True; if GPR_Executable_Prefix_Path = "" then Trace (Main_Trace, "Gprtools installation not found"); return; end if; if not Is_Regular_File (Tgt_File_Full) then Trace (Main_Trace, Tgt_File_Full & " not found"); return; end if; Ada.Text_IO.Open (F, Ada.Text_IO.In_File, Tgt_File_Full); Default_Target_Val := To_Unbounded_String (Ada.Text_IO.Get_Line (F)); Ada.Text_IO.Close (F); exception when X : others => Trace (Main_Trace, "Cannot parse " & Tgt_File_Full); Trace (Main_Trace, Ada.Exceptions.Exception_Information (X)); end Parse_Default_Target_Val; ----------------------- -- Query_Targets_Set -- ----------------------- function Query_Targets_Set (Self : Object; Target : Name_Type) return Targets_Set_Id is use Targets_Set_Vectors; use Target_Lists; Tgt : constant String := String (Target); begin if Target = "all" then return All_Target_Sets; end if; for I in First_Index (Self.Targets_Sets) .. Last_Index (Self.Targets_Sets) loop declare Set : constant Target_Lists.List := Targets_Set_Vectors.Element (Self.Targets_Sets, I).Patterns; C : Target_Lists.Cursor := First (Set); begin while Has_Element (C) loop if GNAT.Regpat.Match (Target_Lists.Element (C), Tgt) > Tgt'First - 1 then return I; end if; Next (C); end loop; end; end loop; return Unknown_Targets_Set; end Query_Targets_Set; ------------- -- Release -- ------------- procedure Release (Self : in out Object) is begin null; end Release; ------------- -- Runtime -- ------------- function Runtime (Comp : Compiler; Alternate : Boolean := False) return Optional_Name_Type is begin if Alternate then if Comp.Runtime /= Null_Unbounded_String then if Comp.Alt_Runtime /= Null_Unbounded_String then return Optional_Name_Type (To_String (Comp.Runtime) & " [" & To_String (Comp.Alt_Runtime) & "]"); else return Optional_Name_Type (To_String (Comp.Runtime)); end if; else return No_Name; end if; end if; if Comp.Alt_Runtime /= Null_Unbounded_String then return Optional_Name_Type (To_String (Comp.Alt_Runtime)); elsif Comp.Runtime /= Null_Unbounded_String then return Optional_Name_Type (To_String (Comp.Runtime)); else return No_Name; end if; end Runtime; ------------------------ -- Set_Default_Target -- ------------------------ procedure Set_Default_Target (New_Target : Name_Type) is begin Default_Target_Parsed := True; Default_Target_Val := To_Unbounded_String (String (New_Target)); end Set_Default_Target; ------------------- -- Set_Selection -- ------------------- procedure Set_Selection (Compilers : in out Compiler_Lists.List; Cursor : Compiler_Lists.Cursor; Selected : Boolean) is procedure Internal (Comp : in out Compiler); -------------- -- Internal -- -------------- procedure Internal (Comp : in out Compiler) is begin Set_Selection (Comp, Selected); end Internal; begin Compiler_Lists.Update_Element (Compilers, Cursor, Internal'Access); end Set_Selection; ------------------- -- Set_Selection -- ------------------- procedure Set_Selection (Comp : in out Compiler; Selected : Boolean) is begin Comp.Selected := Selected; end Set_Selection; -------------------------- -- Substitute_Variables -- -------------------------- function Substitute_Variables (Str : String; Error_Sloc : Source_Reference.Object; Messages : in out Log.Object) return String is use Ada.Characters.Handling; Str_Len : constant Natural := Str'Last; Pos : Natural := Str'First; Last : Natural := Pos; Result : Unbounded_String; Word_Start, Word_End : Natural; Tmp : Natural; Has_Index : Boolean; begin while Pos < Str_Len loop if Str (Pos) = '$' and then Str (Pos + 1) = '$' then Append (Result, Str (Last .. Pos - 1)); Append (Result, "$"); Last := Pos + 2; Pos := Last; elsif Str (Pos) = '$' then if Str (Pos + 1) = '{' then Word_Start := Pos + 2; Tmp := Pos + 2; while Tmp <= Str_Len and then Str (Tmp) /= '}' loop Tmp := Tmp + 1; end loop; Tmp := Tmp + 1; Word_End := Tmp - 2; else Word_Start := Pos + 1; Tmp := Pos + 1; while Tmp <= Str_Len and then (Is_Alphanumeric (Str (Tmp)) or else Str (Tmp) = '_') loop Tmp := Tmp + 1; end loop; Word_End := Tmp - 1; end if; Append (Result, Str (Last .. Pos - 1)); Has_Index := False; for W in Word_Start .. Word_End loop if Str (W) = '(' then Has_Index := True; if Str (Word_End) /= ')' then Messages.Append (Message.Create (Message.Error, "Missing closing parenthesis in variable name: " & Str (Word_Start .. Word_End), Sloc => Error_Sloc)); raise Invalid_KB; else Append (Result, Callback (Var_Name => Str (Word_Start .. W - 1), Index => Str (W + 1 .. Word_End - 1))); end if; exit; end if; end loop; if not Has_Index then Append (Result, Callback (Str (Word_Start .. Word_End), "")); end if; Last := Tmp; Pos := Last; else Pos := Pos + 1; end if; end loop; Append (Result, Str (Last .. Str_Len)); return To_String (Result); end Substitute_Variables; -------------------------------------------------- -- Substitute_Variables_In_Compiler_Description -- -------------------------------------------------- function Substitute_Variables_In_Compiler_Description (Str : String; Comp : Compiler; Error_Sloc : Source_Reference.Object; Messages : in out Log.Object) return String is function Callback (Var_Name, Index : String) return String; -- Wraps Get_Variable_Value for <compiler_description> nodes -- and aborts KB parsing in case of improper use of indexed -- variables in those nodes. -------------- -- Callback -- -------------- function Callback (Var_Name, Index : String) return String is begin if Index /= "" then Messages.Append (Message.Create (Message.Error, "Indexed variables only allowed in <configuration> (in " & Var_Name & "(" & Index & ")", Sloc => Error_Sloc)); raise Invalid_KB; end if; begin return Get_Variable_Value (Comp, Var_Name); exception when Ex : Invalid_KB => Messages.Append (Message.Create (Message.Error, Ada.Exceptions.Exception_Message (Ex), Sloc => Error_Sloc)); raise Invalid_KB; end; end Callback; function Do_Substitute is new Substitute_Variables (Callback); begin return Do_Substitute (Str, Error_Sloc, Messages); end Substitute_Variables_In_Compiler_Description; ------------------------------------------- -- Substitute_Variables_In_Configuration -- ------------------------------------------- function Substitute_Variables_In_Configuration (Self : Object; Str : String; Comps : Compiler_Lists.List; Langs : Ordered_Languages; Error_Sloc : Source_Reference.Object; Messages : in out Log.Object) return String is function Callback (Var_Name, Index : String) return String; -- Wraps Get_Variable_Value for configuration> nodes -- and aborts configuration creation in case of improper use of indexed -- variables in those nodes. -------------- -- Callback -- -------------- function Callback (Var_Name, Index : String) return String is function Do_Subst (Lang : Language_Id) return String; -- Performs substitution with a given language index -------------- -- Do_Subst -- -------------- function Do_Subst (Lang : Language_Id) return String is begin for Comp of Comps loop if Comp.Selected and then Comp.Language = Lang then return Get_Variable_Value (Comp, Var_Name); end if; end loop; return ""; end Do_Subst; begin if Var_Name = "GPRCONFIG_PREFIX" then return GPR_Executable_Prefix_Path; elsif Index = "" then if Var_Name = "TARGET" and then not Comps.Is_Empty then -- Can have an optional language index. -- If there is no index, all compilers share the same target, -- so just take that of the first compiler in the list return String (Self.Normalized_Target (Name_Type (To_String (Comps.First_Element.Target)))); else Messages.Append (Message.Create (Message.Error, "Ambiguous variable substitution, need to specify the" & " language (in " & Var_Name & ")", Sloc => Error_Sloc)); raise Invalid_KB; end if; else if Index = "*" then for Lang of Langs loop begin return Do_Subst (Lang); exception when Ex : Invalid_KB => GNATCOLL.Traces.Trace (Main_Trace, Ada.Exceptions.Exception_Message (Ex) & " for language " & Image (Lang)); end; end loop; Messages.Append (Message.Create (Message.Error, "variable '" & Var_Name & "' is not defined for any language", Sloc => Error_Sloc)); raise Invalid_KB; else begin return Do_Subst (+Name_Type (Index)); exception when Ex : Invalid_KB => Messages.Append (Message.Create (Message.Error, Ada.Exceptions.Exception_Message (Ex), Sloc => Error_Sloc)); raise Invalid_KB; end; end if; end if; end Callback; function Do_Substitute is new Substitute_Variables (Callback); begin return Do_Substitute (Str, Error_Sloc, Messages); end Substitute_Variables_In_Configuration; --------------- -- To_String -- --------------- function To_String (Comp : Compiler) return String is function Get_String_Or_Empty (S : Unbounded_String) return String is (if S = Null_Unbounded_String then "" else To_String (S)); begin return String (Name (Comp.Language)) & ',' & Get_String_Or_Empty (Comp.Version) & ',' & Get_String_Or_Empty (Comp.Runtime) & ',' & (if Comp.Path.Is_Defined then Comp.Path.Value else "") & ',' & Get_String_Or_Empty (Comp.Name); end To_String; --------------- -- To_String -- --------------- function To_String (Compilers : Compiler_Lists.List) return String is use Compiler_Lists; Comp : Compiler_Lists.Cursor := First (Compilers); Result : Unbounded_String; begin while Has_Element (Comp) loop if Compiler_Lists.Element (Comp).Selected then Append (Result, To_String (Compiler_Lists.Element (Comp))); Append (Result, ASCII.LF); end if; Next (Comp); end loop; return To_String (Result); end To_String; ---------------------------------- -- Update_With_Compiler_Runtime -- ---------------------------------- procedure Update_With_Compiler_Runtime (Self : in out Object; Comp : Compiler; Environment : GPR2.Environment.Object) is begin if Comp.Selected and then Comp.Runtime_Dir /= Null_Unbounded_String then declare RTS : constant String := To_String (Comp.Runtime_Dir); Last : Natural := RTS'Last; begin if RTS (Last) = '/' or else RTS (Last) = GNAT.OS_Lib.Directory_Separator then Last := Last - 1; end if; if Last - RTS'First > 6 and then RTS (Last - 5 .. Last) = "adalib" and then (RTS (Last - 6) = GNAT.OS_Lib.Directory_Separator or else (RTS (Last - 6) = '/')) then Last := Last - 6; else Last := RTS'Last; end if; if GNAT.OS_Lib.Is_Directory (RTS (RTS'First .. Last)) then GNATCOLL.Traces.Trace (Main_Trace, "Parsing runtime-specific KB chunks at " & RTS (RTS'First .. Last)); Self.Add (Default_Flags, GPR2.Path_Name.Create_Directory (Filename_Type (RTS (RTS'First .. Last))), Environment); end if; end; end if; end Update_With_Compiler_Runtime; end GPR2.KB;
radekwlsk/concurrent-railroad-ada
Ada
3,977
adb
-- -- Radoslaw Kowalski 221454 -- package body Rails is protected body Track is function Get_Id return Integer is begin return Id; end Get_Id; function Get_Type return Track_Type is begin return Typee; end Get_Type; entry Get_Lock(Suc : out Boolean) when TRUE is begin case Locked is when TRUE => Suc := FALSE; when FALSE => Locked := TRUE; Suc := TRUE; end case; end Get_Lock; entry Lock when not Locked is begin Locked := TRUE; end Lock; entry Unlock when Locked is begin Locked := FALSE; end Unlock; function As_String return String is begin case Typee is when Turntable => return "Turntable" & Integer'Image (Id); when Normal => return "NormalTrack" & Integer'Image (Id); when Station => return "StationTrack" & Integer'Image (Id) & " " & SU.To_String (Spec.Name); end case; end As_String; function As_Verbose_String return String is Id : String := Integer'Image (Get_Id); begin case Typee is when Turntable => return "rails.Turntable:" & Id (2 .. Id'Last) & "{time:" & Integer'Image (Spec.Rotation_Time) & "}"; when Normal => return "rails.NormalTrack:" & Id (2 .. Id'Last) & "{len:" & Integer'Image (Spec.Length) & ", limit:" & Integer'Image (Spec.Speed_Limit) & "}"; when Station => return "rails.StationTrack:" & Id (2 .. Id'Last) & ":" & SU.To_String (Spec.Name) & "{time:" & Integer'Image (Spec.Stop_Time) & "}"; end case; end As_Verbose_String; function Action_Time(Train_Speed : Integer) return Float is begin case Typee is when Turntable => return Float (Spec.Rotation_Time) / 60.0; when Normal => return Float (Spec.Length) / Float (Integer'Min(Spec.Speed_Limit, Train_Speed)); when Station => return Float (Spec.Stop_Time) / 60.0; end case; end Action_Time; procedure Init (I : in Integer; S : in Track_Record) is begin Id := I; Spec := S; end Init; end Track; function New_Turntable(I : Integer; T : Integer) return Track_Ptr is TP : Track_Ptr; S : Track_Record; begin TP := new Track(Turntable); S := (Typee => Turntable, Rotation_Time => T); TP.Init(I, S); return TP; end New_Turntable; function New_Normal_Track(I : Integer; L : Integer; SL : Integer) return Track_Ptr is TP : Track_Ptr; S : Track_Record; begin TP := new Track(Normal); S := (Typee => Normal, Length => L, Speed_Limit => SL); TP.Init(I, S); return TP; end New_Normal_Track; function New_Station_Track(I : Integer; T : Integer; N : SU.Unbounded_String) return Track_Ptr is TP : Track_Ptr; S : Track_Record; begin TP := new Track(Station); S := (Typee => Station, Stop_Time => T, Name => N); TP.Init(I, S); return TP; end New_Station_Track; function As_String(Self: Route_Array) return String is S : SU.Unbounded_String; begin S := SU.To_Unbounded_String ("["); for I in Self'range loop SU.Append(S, Integer'Image (I) (2 .. Integer'Image (I)'Last) & " "); end loop; SU.Append(S, "]"); return SU.To_String (S); end As_String; end Rails;
thorstel/Advent-of-Code-2018
Ada
2,350
adb
with Ada.Text_IO; use Ada.Text_IO; with Input; use Input; procedure Day10 is procedure Print_Grid (Points : Point_Array; Min_X, Max_X, Min_Y, Max_Y : Integer) is Grid : array (Integer range Min_X .. Max_X, Integer range Min_Y .. Max_Y) of Character := (others => (others => '.')); begin for I in Points'Range loop Grid (Points (I).X, Points (I).Y) := '#'; end loop; for Y in Min_Y .. Max_Y loop for X in Min_X .. Max_X loop Put ("" & Grid (X, Y)); end loop; Put_Line (""); end loop; end Print_Grid; Seconds : Natural := 0; begin -- Assumption: The points are converging until the message appears -- and then diverge again. Meaning the diameter on the Y-axis should -- increase for the first time directly after the message is shown. Infinite_Loop : loop declare Min_X : Integer := Integer'Last; Max_X : Integer := Integer'First; Min_Y_Before : Integer := Integer'Last; Max_Y_Before : Integer := Integer'First; Min_Y_After : Integer := Integer'Last; Max_Y_After : Integer := Integer'First; begin for I in Points'Range loop Min_X := Integer'Min (Min_X, Points (I).X); Max_X := Integer'Max (Max_X, Points (I).X); Min_Y_Before := Integer'Min (Min_Y_Before, Points (I).Y); Max_Y_Before := Integer'Max (Max_Y_Before, Points (I).Y); Points (I) := Points (I) + Velocities (I); Min_Y_After := Integer'Min (Min_Y_After, Points (I).Y); Max_Y_After := Integer'Max (Max_Y_After, Points (I).Y); end loop; if abs (Max_Y_After - Min_Y_After) > abs (Max_Y_Before - Min_Y_Before) then -- Roll-back the last step for I in Points'Range loop Points (I) := Points (I) - Velocities (I); end loop; -- Print the result Put_Line ("Part 1:"); Print_Grid (Points, Min_X, Max_X, Min_Y_Before, Max_Y_Before); Put_Line ("Part 2 =" & Natural'Image (Seconds)); exit Infinite_Loop; end if; Seconds := Seconds + 1; end; end loop Infinite_Loop; end Day10;
reznikmm/matreshka
Ada
3,753
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.Internals.Generic_Element_Table; with AMF.Internals.Tables.UTP_Types; package AMF.Internals.Tables.UTP_Element_Table is new AMF.Internals.Generic_Element_Table (AMF.Internals.Tables.UTP_Types.Element_Record); pragma Preelaborate (AMF.Internals.Tables.UTP_Element_Table);
damaki/SPARKNaCl
Ada
7,426
adb
with HAL; use HAL; with HiFive1.LEDs; use HiFive1.LEDs; with FE310; with FE310.CLINT; with FE310.Time; use FE310.Time; with Interfaces; use Interfaces; with IO; with SPARKNaCl; use SPARKNaCl; with SPARKNaCl.Cryptobox; use SPARKNaCl.Cryptobox; with SPARKNaCl.Stream; with TweetNaCl_API; with RISCV.CSR; use RISCV.CSR; procedure TBox is subtype U64 is Unsigned_64; -- AlicePK : constant Public_Key := -- Construct ((16#85#, 16#20#, 16#f0#, 16#09#, -- 16#89#, 16#30#, 16#a7#, 16#54#, -- 16#74#, 16#8b#, 16#7d#, 16#dc#, -- 16#b4#, 16#3e#, 16#f7#, 16#5a#, -- 16#0d#, 16#bf#, 16#3a#, 16#0d#, -- 16#26#, 16#38#, 16#1a#, 16#f4#, -- 16#eb#, 16#a4#, 16#a9#, 16#8e#, -- 16#aa#, 16#9b#, 16#4e#, 16#6a#)); AliceSK : constant Secret_Key := Construct ((16#77#, 16#07#, 16#6d#, 16#0a#, 16#73#, 16#18#, 16#a5#, 16#7d#, 16#3c#, 16#16#, 16#c1#, 16#72#, 16#51#, 16#b2#, 16#66#, 16#45#, 16#df#, 16#4c#, 16#2f#, 16#87#, 16#eb#, 16#c0#, 16#99#, 16#2a#, 16#b1#, 16#77#, 16#fb#, 16#a5#, 16#1d#, 16#b9#, 16#2c#, 16#2a#)); BobPK : constant Public_Key := Construct ((16#de#, 16#9e#, 16#db#, 16#7d#, 16#7b#, 16#7d#, 16#c1#, 16#b4#, 16#d3#, 16#5b#, 16#61#, 16#c2#, 16#ec#, 16#e4#, 16#35#, 16#37#, 16#3f#, 16#83#, 16#43#, 16#c8#, 16#5b#, 16#78#, 16#67#, 16#4d#, 16#ad#, 16#fc#, 16#7e#, 16#14#, 16#6f#, 16#88#, 16#2b#, 16#4f#)); -- BobSK : constant Secret_Key := -- Construct ((16#5d#, 16#ab#, 16#08#, 16#7e#, -- 16#62#, 16#4a#, 16#8a#, 16#4b#, -- 16#79#, 16#e1#, 16#7f#, 16#8b#, -- 16#83#, 16#80#, 16#0e#, 16#e6#, -- 16#6f#, 16#3b#, 16#b1#, 16#29#, -- 16#26#, 16#18#, 16#b6#, 16#fd#, -- 16#1c#, 16#2f#, 16#8b#, 16#27#, -- 16#ff#, 16#88#, 16#e0#, 16#eb#)); Nonce : constant Stream.HSalsa20_Nonce := (16#69#, 16#69#, 16#6e#, 16#e9#, 16#55#, 16#b6#, 16#2b#, 16#73#, 16#cd#, 16#62#, 16#bd#, 16#a8#, 16#75#, 16#fc#, 16#73#, 16#d6#, 16#82#, 16#19#, 16#e0#, 16#03#, 16#6b#, 16#7a#, 16#0b#, 16#37#); M : constant Byte_Seq (0 .. 162) := (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, 16#be#, 16#07#, 16#5f#, 16#c5#, 16#3c#, 16#81#, 16#f2#, 16#d5#, 16#cf#, 16#14#, 16#13#, 16#16#, 16#eb#, 16#eb#, 16#0c#, 16#7b#, 16#52#, 16#28#, 16#c5#, 16#2a#, 16#4c#, 16#62#, 16#cb#, 16#d4#, 16#4b#, 16#66#, 16#84#, 16#9b#, 16#64#, 16#24#, 16#4f#, 16#fc#, 16#e5#, 16#ec#, 16#ba#, 16#af#, 16#33#, 16#bd#, 16#75#, 16#1a#, 16#1a#, 16#c7#, 16#28#, 16#d4#, 16#5e#, 16#6c#, 16#61#, 16#29#, 16#6c#, 16#dc#, 16#3c#, 16#01#, 16#23#, 16#35#, 16#61#, 16#f4#, 16#1d#, 16#b6#, 16#6c#, 16#ce#, 16#31#, 16#4a#, 16#db#, 16#31#, 16#0e#, 16#3b#, 16#e8#, 16#25#, 16#0c#, 16#46#, 16#f0#, 16#6d#, 16#ce#, 16#ea#, 16#3a#, 16#7f#, 16#a1#, 16#34#, 16#80#, 16#57#, 16#e2#, 16#f6#, 16#55#, 16#6a#, 16#d6#, 16#b1#, 16#31#, 16#8a#, 16#02#, 16#4a#, 16#83#, 16#8f#, 16#21#, 16#af#, 16#1f#, 16#de#, 16#04#, 16#89#, 16#77#, 16#eb#, 16#48#, 16#f5#, 16#9f#, 16#fd#, 16#49#, 16#24#, 16#ca#, 16#1c#, 16#60#, 16#90#, 16#2e#, 16#52#, 16#f0#, 16#a0#, 16#89#, 16#bc#, 16#76#, 16#89#, 16#70#, 16#40#, 16#e0#, 16#82#, 16#f9#, 16#37#, 16#76#, 16#38#, 16#48#, 16#64#, 16#5e#, 16#07#, 16#05#); C1 : Byte_Seq (0 .. 162); C2 : Byte_Seq (0 .. 162); Status : Boolean; T1, T2 : UInt64; Total_Time : Unsigned_64; CPU_Hz1, CPU_Hz2 : UInt32; procedure Report; procedure Tweet_Cryptobox (C : out Byte_Seq; Status : out Boolean; M : in Byte_Seq; N : in Stream.HSalsa20_Nonce; Recipient_PK : in Public_Key; Sender_SK : in Secret_Key); procedure Tweet_Cryptobox (C : out Byte_Seq; Status : out Boolean; M : in Byte_Seq; N : in Stream.HSalsa20_Nonce; Recipient_PK : in Public_Key; Sender_SK : in Secret_Key) is begin TweetNaCl_API.Crypto_Box (C, M, M'Length, N, Recipient_PK, Sender_SK); Status := True; end Tweet_Cryptobox; procedure Report is begin IO.Put ("Total: "); IO.Put (UInt64 (Total_Time)); IO.Put_Line (" cycles"); end Report; begin CPU_Hz1 := FE310.CPU_Frequency; -- The SPI flash clock divider should be as small as possible to increase -- the execution speed of instructions that are not yet in the instruction -- cache. FE310.Set_SPI_Flash_Clock_Divider (2); -- Load the internal oscillator factory calibration to be sure it -- oscillates at a known frequency. FE310.Load_Internal_Oscilator_Calibration; -- Use the HiFive1 16 MHz crystal oscillator which is more acurate than the -- internal oscillator. FE310.Use_Crystal_Oscillator; HiFive1.LEDs.Initialize; CPU_Hz2 := FE310.CPU_Frequency; IO.Put_Line ("CPU Frequency reset was: ", U64 (CPU_Hz1)); IO.Put_Line ("CPU Frequency now is: ", U64 (CPU_Hz2)); Turn_On (Red_LED); T1 := FE310.CLINT.Machine_Time; T2 := FE310.CLINT.Machine_Time; IO.Put_Line ("Null timing test:", U64 (T2 - T1)); T1 := Mcycle.Read; Delay_S (1); T2 := Mcycle.Read; IO.Put_Line ("One second test (CYCLE): ", U64 (T2 - T1)); T1 := Minstret.Read; Delay_S (1); T2 := Minstret.Read; IO.Put_Line ("One second test (INSTRET):", U64 (T2 - T1)); T1 := FE310.CLINT.Machine_Time; Delay_S (1); T2 := FE310.CLINT.Machine_Time; IO.Put_Line ("One second test (CLINT): ", U64 (T2 - T1)); IO.Put_Line ("SPARKNaCl.Cryptobox.Create test"); T1 := Mcycle.Read; SPARKNaCl.Cryptobox.Create (C1, Status, M, Nonce, BobPK, AliceSK); T2 := Mcycle.Read; Total_Time := Unsigned_64 (T2 - T1); Report; Turn_Off (Red_LED); Turn_On (Green_LED); IO.New_Line; IO.Put_Line ("TweetNaCl.Cryptobox test"); TweetNaCl_API.Reset; T1 := Mcycle.Read; Tweet_Cryptobox (C2, Status, M, Nonce, BobPK, AliceSK); T2 := Mcycle.Read; Total_Time := Unsigned_64 (T2 - T1); Report; if C1 = C2 then IO.Put_Line ("Pass"); else IO.Put_Line ("Fail"); end if; Turn_Off (Green_LED); -- Blinky! loop Turn_On (Red_LED); Delay_S (1); Turn_Off (Red_LED); Turn_On (Green_LED); Delay_S (1); Turn_Off (Green_LED); Turn_On (Blue_LED); Delay_S (1); Turn_Off (Blue_LED); end loop; end TBox;
1Crazymoney/LearnAda
Ada
14,043
ads
pragma Ada_95; with System; package ada_main is pragma Warnings (Off); gnat_argc : Integer; gnat_argv : System.Address; gnat_envp : System.Address; pragma Import (C, gnat_argc); pragma Import (C, gnat_argv); pragma Import (C, gnat_envp); gnat_exit_status : Integer; pragma Import (C, gnat_exit_status); GNAT_Version : constant String := "GNAT Version: GPL 2015 (20150428-49)" & ASCII.NUL; pragma Export (C, GNAT_Version, "__gnat_version"); Ada_Main_Program_Name : constant String := "_ada_sum" & ASCII.NUL; pragma Export (C, Ada_Main_Program_Name, "__gnat_ada_main_program_name"); procedure adainit; pragma Export (C, adainit, "adainit"); procedure adafinal; pragma Export (C, adafinal, "adafinal"); function main (argc : Integer; argv : System.Address; envp : System.Address) return Integer; pragma Export (C, main, "main"); type Version_32 is mod 2 ** 32; u00001 : constant Version_32 := 16#9da74c43#; pragma Export (C, u00001, "sumB"); u00002 : constant Version_32 := 16#fbff4c67#; pragma Export (C, u00002, "system__standard_libraryB"); u00003 : constant Version_32 := 16#f72f352b#; pragma Export (C, u00003, "system__standard_libraryS"); u00004 : constant Version_32 := 16#3ffc8e18#; pragma Export (C, u00004, "adaS"); u00005 : constant Version_32 := 16#f64b89a4#; pragma Export (C, u00005, "ada__integer_text_ioB"); u00006 : constant Version_32 := 16#f1daf268#; pragma Export (C, u00006, "ada__integer_text_ioS"); u00007 : constant Version_32 := 16#b612ca65#; pragma Export (C, u00007, "ada__exceptionsB"); u00008 : constant Version_32 := 16#1d190453#; pragma Export (C, u00008, "ada__exceptionsS"); u00009 : constant Version_32 := 16#a46739c0#; pragma Export (C, u00009, "ada__exceptions__last_chance_handlerB"); u00010 : constant Version_32 := 16#3aac8c92#; pragma Export (C, u00010, "ada__exceptions__last_chance_handlerS"); u00011 : constant Version_32 := 16#f4ce8c3a#; pragma Export (C, u00011, "systemS"); u00012 : constant Version_32 := 16#a207fefe#; pragma Export (C, u00012, "system__soft_linksB"); u00013 : constant Version_32 := 16#af945ded#; pragma Export (C, u00013, "system__soft_linksS"); u00014 : constant Version_32 := 16#b01dad17#; pragma Export (C, u00014, "system__parametersB"); u00015 : constant Version_32 := 16#8ae48145#; pragma Export (C, u00015, "system__parametersS"); u00016 : constant Version_32 := 16#b19b6653#; pragma Export (C, u00016, "system__secondary_stackB"); u00017 : constant Version_32 := 16#5faf4353#; pragma Export (C, u00017, "system__secondary_stackS"); u00018 : constant Version_32 := 16#39a03df9#; pragma Export (C, u00018, "system__storage_elementsB"); u00019 : constant Version_32 := 16#d90dc63e#; pragma Export (C, u00019, "system__storage_elementsS"); u00020 : constant Version_32 := 16#41837d1e#; pragma Export (C, u00020, "system__stack_checkingB"); u00021 : constant Version_32 := 16#7a71e7d2#; pragma Export (C, u00021, "system__stack_checkingS"); u00022 : constant Version_32 := 16#393398c1#; pragma Export (C, u00022, "system__exception_tableB"); u00023 : constant Version_32 := 16#5ad7ea2f#; pragma Export (C, u00023, "system__exception_tableS"); u00024 : constant Version_32 := 16#ce4af020#; pragma Export (C, u00024, "system__exceptionsB"); u00025 : constant Version_32 := 16#9cade1cc#; pragma Export (C, u00025, "system__exceptionsS"); u00026 : constant Version_32 := 16#37d758f1#; pragma Export (C, u00026, "system__exceptions__machineS"); u00027 : constant Version_32 := 16#b895431d#; pragma Export (C, u00027, "system__exceptions_debugB"); u00028 : constant Version_32 := 16#472c9584#; pragma Export (C, u00028, "system__exceptions_debugS"); u00029 : constant Version_32 := 16#570325c8#; pragma Export (C, u00029, "system__img_intB"); u00030 : constant Version_32 := 16#f6156cf8#; pragma Export (C, u00030, "system__img_intS"); u00031 : constant Version_32 := 16#b98c3e16#; pragma Export (C, u00031, "system__tracebackB"); u00032 : constant Version_32 := 16#6af355e1#; pragma Export (C, u00032, "system__tracebackS"); u00033 : constant Version_32 := 16#9ed49525#; pragma Export (C, u00033, "system__traceback_entriesB"); u00034 : constant Version_32 := 16#f4957a4a#; pragma Export (C, u00034, "system__traceback_entriesS"); u00035 : constant Version_32 := 16#8c33a517#; pragma Export (C, u00035, "system__wch_conB"); u00036 : constant Version_32 := 16#efb3aee8#; pragma Export (C, u00036, "system__wch_conS"); u00037 : constant Version_32 := 16#9721e840#; pragma Export (C, u00037, "system__wch_stwB"); u00038 : constant Version_32 := 16#c2a282e9#; pragma Export (C, u00038, "system__wch_stwS"); u00039 : constant Version_32 := 16#92b797cb#; pragma Export (C, u00039, "system__wch_cnvB"); u00040 : constant Version_32 := 16#e004141b#; pragma Export (C, u00040, "system__wch_cnvS"); u00041 : constant Version_32 := 16#6033a23f#; pragma Export (C, u00041, "interfacesS"); u00042 : constant Version_32 := 16#ece6fdb6#; pragma Export (C, u00042, "system__wch_jisB"); u00043 : constant Version_32 := 16#60740d3a#; pragma Export (C, u00043, "system__wch_jisS"); u00044 : constant Version_32 := 16#28f088c2#; pragma Export (C, u00044, "ada__text_ioB"); u00045 : constant Version_32 := 16#1a9b0017#; pragma Export (C, u00045, "ada__text_ioS"); u00046 : constant Version_32 := 16#10558b11#; pragma Export (C, u00046, "ada__streamsB"); u00047 : constant Version_32 := 16#2e6701ab#; pragma Export (C, u00047, "ada__streamsS"); u00048 : constant Version_32 := 16#db5c917c#; pragma Export (C, u00048, "ada__io_exceptionsS"); u00049 : constant Version_32 := 16#12c8cd7d#; pragma Export (C, u00049, "ada__tagsB"); u00050 : constant Version_32 := 16#ce72c228#; pragma Export (C, u00050, "ada__tagsS"); u00051 : constant Version_32 := 16#c3335bfd#; pragma Export (C, u00051, "system__htableB"); u00052 : constant Version_32 := 16#700c3fd0#; pragma Export (C, u00052, "system__htableS"); u00053 : constant Version_32 := 16#089f5cd0#; pragma Export (C, u00053, "system__string_hashB"); u00054 : constant Version_32 := 16#d25254ae#; pragma Export (C, u00054, "system__string_hashS"); u00055 : constant Version_32 := 16#699628fa#; pragma Export (C, u00055, "system__unsigned_typesS"); u00056 : constant Version_32 := 16#b44f9ae7#; pragma Export (C, u00056, "system__val_unsB"); u00057 : constant Version_32 := 16#793ec5c1#; pragma Export (C, u00057, "system__val_unsS"); u00058 : constant Version_32 := 16#27b600b2#; pragma Export (C, u00058, "system__val_utilB"); u00059 : constant Version_32 := 16#586e3ac4#; pragma Export (C, u00059, "system__val_utilS"); u00060 : constant Version_32 := 16#d1060688#; pragma Export (C, u00060, "system__case_utilB"); u00061 : constant Version_32 := 16#d0c7e5ed#; pragma Export (C, u00061, "system__case_utilS"); u00062 : constant Version_32 := 16#84a27f0d#; pragma Export (C, u00062, "interfaces__c_streamsB"); u00063 : constant Version_32 := 16#8bb5f2c0#; pragma Export (C, u00063, "interfaces__c_streamsS"); u00064 : constant Version_32 := 16#845f5a34#; pragma Export (C, u00064, "system__crtlS"); u00065 : constant Version_32 := 16#431faf3c#; pragma Export (C, u00065, "system__file_ioB"); u00066 : constant Version_32 := 16#53bf6d5f#; pragma Export (C, u00066, "system__file_ioS"); u00067 : constant Version_32 := 16#b7ab275c#; pragma Export (C, u00067, "ada__finalizationB"); u00068 : constant Version_32 := 16#19f764ca#; pragma Export (C, u00068, "ada__finalizationS"); u00069 : constant Version_32 := 16#95817ed8#; pragma Export (C, u00069, "system__finalization_rootB"); u00070 : constant Version_32 := 16#bb3cffaa#; pragma Export (C, u00070, "system__finalization_rootS"); u00071 : constant Version_32 := 16#769e25e6#; pragma Export (C, u00071, "interfaces__cB"); u00072 : constant Version_32 := 16#4a38bedb#; pragma Export (C, u00072, "interfaces__cS"); u00073 : constant Version_32 := 16#ee0f26dd#; pragma Export (C, u00073, "system__os_libB"); u00074 : constant Version_32 := 16#d7b69782#; pragma Export (C, u00074, "system__os_libS"); u00075 : constant Version_32 := 16#1a817b8e#; pragma Export (C, u00075, "system__stringsB"); u00076 : constant Version_32 := 16#8a719d5c#; pragma Export (C, u00076, "system__stringsS"); u00077 : constant Version_32 := 16#09511692#; pragma Export (C, u00077, "system__file_control_blockS"); u00078 : constant Version_32 := 16#f6fdca1c#; pragma Export (C, u00078, "ada__text_io__integer_auxB"); u00079 : constant Version_32 := 16#b9793d30#; pragma Export (C, u00079, "ada__text_io__integer_auxS"); u00080 : constant Version_32 := 16#181dc502#; pragma Export (C, u00080, "ada__text_io__generic_auxB"); u00081 : constant Version_32 := 16#a6c327d3#; pragma Export (C, u00081, "ada__text_io__generic_auxS"); u00082 : constant Version_32 := 16#18d57884#; pragma Export (C, u00082, "system__img_biuB"); u00083 : constant Version_32 := 16#afb4a0b7#; pragma Export (C, u00083, "system__img_biuS"); u00084 : constant Version_32 := 16#e7d8734f#; pragma Export (C, u00084, "system__img_llbB"); u00085 : constant Version_32 := 16#ee73b049#; pragma Export (C, u00085, "system__img_llbS"); u00086 : constant Version_32 := 16#9777733a#; pragma Export (C, u00086, "system__img_lliB"); u00087 : constant Version_32 := 16#e581d9eb#; pragma Export (C, u00087, "system__img_lliS"); u00088 : constant Version_32 := 16#0e8808d4#; pragma Export (C, u00088, "system__img_llwB"); u00089 : constant Version_32 := 16#471f93df#; pragma Export (C, u00089, "system__img_llwS"); u00090 : constant Version_32 := 16#428b07f8#; pragma Export (C, u00090, "system__img_wiuB"); u00091 : constant Version_32 := 16#c1f52725#; pragma Export (C, u00091, "system__img_wiuS"); u00092 : constant Version_32 := 16#7ebd8839#; pragma Export (C, u00092, "system__val_intB"); u00093 : constant Version_32 := 16#bc6ba605#; pragma Export (C, u00093, "system__val_intS"); u00094 : constant Version_32 := 16#b3aa7b17#; pragma Export (C, u00094, "system__val_lliB"); u00095 : constant Version_32 := 16#6eea6a9a#; pragma Export (C, u00095, "system__val_lliS"); u00096 : constant Version_32 := 16#06052bd0#; pragma Export (C, u00096, "system__val_lluB"); u00097 : constant Version_32 := 16#13647f88#; pragma Export (C, u00097, "system__val_lluS"); u00098 : constant Version_32 := 16#2bce1226#; pragma Export (C, u00098, "system__memoryB"); u00099 : constant Version_32 := 16#adb3ea0e#; pragma Export (C, u00099, "system__memoryS"); -- BEGIN ELABORATION ORDER -- ada%s -- interfaces%s -- system%s -- system.case_util%s -- system.case_util%b -- system.htable%s -- system.img_int%s -- system.img_int%b -- system.img_lli%s -- system.img_lli%b -- system.parameters%s -- system.parameters%b -- system.crtl%s -- interfaces.c_streams%s -- interfaces.c_streams%b -- system.standard_library%s -- system.exceptions_debug%s -- system.exceptions_debug%b -- system.storage_elements%s -- system.storage_elements%b -- system.stack_checking%s -- system.stack_checking%b -- system.string_hash%s -- system.string_hash%b -- system.htable%b -- system.strings%s -- system.strings%b -- system.os_lib%s -- system.traceback_entries%s -- system.traceback_entries%b -- ada.exceptions%s -- system.soft_links%s -- system.unsigned_types%s -- system.img_biu%s -- system.img_biu%b -- system.img_llb%s -- system.img_llb%b -- system.img_llw%s -- system.img_llw%b -- system.img_wiu%s -- system.img_wiu%b -- system.val_int%s -- system.val_lli%s -- system.val_llu%s -- system.val_uns%s -- system.val_util%s -- system.val_util%b -- system.val_uns%b -- system.val_llu%b -- system.val_lli%b -- system.val_int%b -- system.wch_con%s -- system.wch_con%b -- system.wch_cnv%s -- system.wch_jis%s -- system.wch_jis%b -- system.wch_cnv%b -- system.wch_stw%s -- system.wch_stw%b -- ada.exceptions.last_chance_handler%s -- ada.exceptions.last_chance_handler%b -- system.exception_table%s -- system.exception_table%b -- ada.io_exceptions%s -- ada.tags%s -- ada.streams%s -- ada.streams%b -- interfaces.c%s -- system.exceptions%s -- system.exceptions%b -- system.exceptions.machine%s -- system.file_control_block%s -- system.file_io%s -- system.finalization_root%s -- system.finalization_root%b -- ada.finalization%s -- ada.finalization%b -- system.memory%s -- system.memory%b -- system.standard_library%b -- system.secondary_stack%s -- system.file_io%b -- interfaces.c%b -- ada.tags%b -- system.soft_links%b -- system.os_lib%b -- system.secondary_stack%b -- system.traceback%s -- ada.exceptions%b -- system.traceback%b -- ada.text_io%s -- ada.text_io%b -- ada.text_io.generic_aux%s -- ada.text_io.generic_aux%b -- ada.text_io.integer_aux%s -- ada.text_io.integer_aux%b -- ada.integer_text_io%s -- ada.integer_text_io%b -- sum%b -- END ELABORATION ORDER end ada_main;
zhmu/ananas
Ada
5,586
ads
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- S Y S T E M . S C A L A R _ V A L U E S -- -- -- -- S p e c -- -- -- -- Copyright (C) 2001-2022, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This package defines the constants used for initializing scalar values -- when pragma Initialize_Scalars is used. The actual values are defined -- in the binder generated file. This package contains the Ada names that -- are used by the generated code, which are linked to the actual values -- by the use of pragma Import. with Interfaces; package System.Scalar_Values is -- Note: logically this package should be Pure since it can be accessed -- from pure units, but the IS_xxx variables below get set at run time, -- so they have to be library level variables. In fact we only ever -- access this from generated code, and the compiler knows that it is -- OK to access this unit from generated code. subtype Byte1 is Interfaces.Unsigned_8; subtype Byte2 is Interfaces.Unsigned_16; subtype Byte4 is Interfaces.Unsigned_32; subtype Byte8 is Interfaces.Unsigned_64; -- The explicit initializations here are not really required, since these -- variables are always set by System.Scalar_Values.Initialize. IS_Is1 : Byte1 := 0; -- Initialize 1 byte signed IS_Is2 : Byte2 := 0; -- Initialize 2 byte signed IS_Is4 : Byte4 := 0; -- Initialize 4 byte signed IS_Is8 : Byte8 := 0; -- Initialize 8 byte signed -- For the above cases, the undefined value (set by the binder -Sin switch) -- is the largest negative number (1 followed by all zero bits). IS_Iu1 : Byte1 := 0; -- Initialize 1 byte unsigned IS_Iu2 : Byte2 := 0; -- Initialize 2 byte unsigned IS_Iu4 : Byte4 := 0; -- Initialize 4 byte unsigned IS_Iu8 : Byte8 := 0; -- Initialize 8 byte unsigned -- For the above cases, the undefined value (set by the binder -Sin switch) -- is the largest unsigned number (all 1 bits). IS_Iz1 : Byte1 := 0; -- Initialize 1 byte zeroes IS_Iz2 : Byte2 := 0; -- Initialize 2 byte zeroes IS_Iz4 : Byte4 := 0; -- Initialize 4 byte zeroes IS_Iz8 : Byte8 := 0; -- Initialize 8 byte zeroes -- For the above cases, the undefined value (set by the binder -Sin switch) -- is the zero (all 0 bits). This is used when zero is known to be an -- invalid value. -- The float definitions are aliased, because we use overlays to set them IS_Isf : aliased Short_Float := 0.0; -- Initialize short float IS_Ifl : aliased Float := 0.0; -- Initialize float IS_Ilf : aliased Long_Float := 0.0; -- Initialize long float IS_Ill : aliased Long_Long_Float := 0.0; -- Initialize long long float procedure Initialize (Mode1 : Character; Mode2 : Character); -- This procedure is called from the binder when Initialize_Scalars mode -- is active. The arguments are the two characters from the -S switch, -- with letters forced upper case. So for example if -S5a is given, then -- Mode1 will be '5' and Mode2 will be 'A'. If the parameters are EV, -- then this routine reads the environment variable GNAT_INIT_SCALARS. -- The possible settings are the same as those for the -S switch (except -- for EV), i.e. IN/LO/HO/xx, xx = 2 hex digits. If no -S switch is given -- then the default of IN (invalid values) is passed on the call. end System.Scalar_Values;
zhmu/ananas
Ada
156
adb
package body Varsize_Return_Pkg2 is function Get (X : T) return Data_T is Result : Data_T; begin return Result; end; end Varsize_Return_Pkg2;
coopht/axmpp
Ada
5,828
ads
------------------------------------------------------------------------------ -- -- -- AXMPP Project -- -- -- -- XMPP Library for Ada -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2016, Alexander Basov <[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 Alexander Basov, 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 XML.SAX.Pretty_Writers; with XMPP.IQS; package XMPP.Versions is Name_Element : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("name"); OS_Element : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("os"); Query_Element : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("query"); Version_Element : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("version"); Version_URI : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("jabber:iq:version"); type XMPP_Version is new XMPP.IQS.XMPP_IQ with private; type XMPP_Version_Access is access all XMPP_Version'Class; -- Public API -- not overriding function Get_Name (Self : XMPP_Version) return League.Strings.Universal_String; -- Returns client's name not overriding function Get_OS (Self : XMPP_Version) return League.Strings.Universal_String; -- Returns os information not overriding function Get_Version (Self : XMPP_Version) return League.Strings.Universal_String; -- Returns version information not overriding procedure Set_Name (Self : in out XMPP_Version; Name : League.Strings.Universal_String); -- Sets name information not overriding procedure Set_OS (Self : in out XMPP_Version; OS : League.Strings.Universal_String); -- Sets os information not overriding procedure Set_Version (Self : in out XMPP_Version; Version : League.Strings.Universal_String); -- Sets version information function Create return XMPP_Version_Access; -- Returns heap allocated object. -- Private API -- Should not be used in application overriding procedure Set_Content (Self : in out XMPP_Version; Parameter : League.Strings.Universal_String; Value : League.Strings.Universal_String); overriding function Get_Kind (Self : XMPP_Version) return Object_Kind; overriding procedure Serialize (Self : XMPP_Version; Writer : in out XML.SAX.Pretty_Writers.XML_Pretty_Writer'Class); private type XMPP_Version is new XMPP.IQS.XMPP_IQ with record Name : League.Strings.Universal_String := League.Strings.To_Universal_String ("ada xmpp library"); OS : League.Strings.Universal_String; Version : League.Strings.Universal_String := League.Strings.To_Universal_String ("0.0.1"); end record; end XMPP.Versions;
mhanuel26/ada-enet
Ada
12,819
ads
----------------------------------------------------------------------- -- net-dhcp -- DHCP client -- Copyright (C) 2016, 2017 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.Real_Time; with Net.Interfaces; with Net.Buffers; with Net.Sockets.Udp; -- == DHCP Client == -- The DHCP client can be used to configure the IPv4 network stack by using -- the DHCP protocol (RFC 2131). The DHCP client uses a UDP socket on port 68 -- to send and receive DHCP messages. The DHCP client state is maintained by -- two procedures which are called asynchronously: the <tt>Process</tt> -- and <tt>Receive</tt> procedures. The <tt>Process</tt> procedure is responsible -- for sending requests to the DHCP server and to manage the timeouts used for -- the retransmissions, renewal and lease expiration. On its hand, the <tt>Receive</tt> -- procedure is called by the UDP socket layer when a DHCP packet is received. -- These two procedures are typically called from different tasks. -- -- To make the implementation simple and ready to use, the DHCP client uses a pre-defined -- configuration that should meet most requirements. The DHCP client asks for the following -- DHCP options: -- -- * Option 1: Subnetmask -- * Option 3: Router -- * Option 6: Domain name server -- * Option 12: Hostname -- * Option 15: Domain name -- * Option 26: Interface MTU size -- * Option 28: Brodcast address -- * Option 42: NTP server -- * Option 72: WWW server -- * Option 51: Lease time -- * Option 58: Renew time -- * Option 59: Rebind time -- -- It sends the following options to help the server identify the client: -- -- * Option 60: Vendor class identifier, the string "Ada Embedded Network" is sent. -- * Option 61: Client identifier, the Ethernet address is used as identifier. -- -- === Initialization === -- To use the client, one will have to declare a global aliased DHCP client instance -- (the aliased is necessary as the UDP socket layer needs to get an access to it): -- -- C : aliased Net.DHCP.Client; -- -- The DHCP client instance must then be initialized after the network interface -- is initialized. The <tt>Initialize</tt> procedure needs an access to the interface -- instance. -- -- C.Initialize (Ifnet'Access); -- -- The initialization only binds the UDP socket to the port 68 and prepares the DHCP -- state machine. At this stage, no DHCP packet is sent yet but the UDP socket is now -- able to receive them. -- -- === Processing === -- The <tt>Process</tt> procedure must be called either by a main task or by a dedicated -- task to send the DHCP requests and maintain the DHCP state machine. Each time this -- procedure is called, it looks whether some DHCP processing must be done and it computes -- a deadline that indicates the time for the next call. It is safe -- to call the <tt>Process</tt> procedure more often than required. The operation will -- perform different operations depending on the DHCP state: -- -- In the <tt>STATE_INIT</tt> state, it records the begining of the DHCP discovering state, -- switches to the <tt>STATE_SELECTING</tt> and sends the first DHCP discover packet. -- -- When the DHCP state machine is in the <tt>STATE_SELECTING</tt> state, it continues to -- send the DHCP discover packet taking into account the backoff timeout. -- -- In the <tt>STATE_REQUESTING</tt> state, it sends the DHCP request packet to the server. -- -- In the <tt>STATE_BOUND</tt> state, it configures the interface if it is not yet configured -- and it then waits for the DHCP lease renewal. If the DHCP lease must be renewed, it -- switches to the <tt>STATE_RENEWING</tt> state. -- -- [images/ada-net-dhcp.png] -- -- The DHCP client does not use any task to give you the freedom on how you want to integrate -- the DHCP client in your application. The <tt>Process</tt> procedure may be integrated in -- a loop similar to the loop below: -- -- declare -- Dhcp_Deadline : Ada.Real_Time.Time; -- begin -- loop -- C.Process (Dhcp_Deadline); -- delay until Dhcp_Deadline; -- end loop; -- end; -- -- This loop may be part of a dedicated task for the DHCP client but it may also be part -- of another task that could also handle other network house keeping (such as ARP management). -- -- === Interface Configuration === -- Once in the <tt>STATE_BOUND</tt>, the interface configuration is done by the <tt>Process</tt> -- procedure that calls the <tt>Bind</tt> procedure with the DHCP received options. -- This procedure configures the interface IP, netmask, gateway, MTU and DNS. It is possible -- to override this procedure in an application to be notified and extract other information -- from the received DHCP options. In that case, it is still important to call the overriden -- procedure so that the interface and network stack is correctly configured. -- package Net.DHCP is -- The <tt>State_Type</tt> defines the DHCP client finite state machine. type State_Type is (STATE_INIT, STATE_INIT_REBOOT, STATE_SELECTING, STATE_REQUESTING, STATE_DAD, STATE_BOUND, STATE_RENEWING, STATE_REBINDING, STATE_REBOOTING); -- Options extracted from the server response. type Options_Type is record Msg_Type : Net.Uint8; Hostname : String (1 .. 255); Hostname_Len : Natural := 0; Domain : String (1 .. 255); Domain_Len : Natural := 0; Ip : Net.Ip_Addr := (0, 0, 0, 0); Broadcast : Net.Ip_Addr := (255, 255, 255, 255); Router : Net.Ip_Addr := (0, 0, 0, 0); Netmask : Net.Ip_Addr := (255, 255, 255, 0); Server : Net.Ip_Addr := (0, 0, 0, 0); Ntp : Net.Ip_Addr := (0, 0, 0, 0); Www : Net.Ip_Addr := (0, 0, 0, 0); Dns1 : Net.Ip_Addr := (0, 0, 0, 0); Dns2 : Net.Ip_Addr := (0, 0, 0, 0); Lease_Time : Natural := 0; Renew_Time : Natural := 0; Rebind_Time : Natural := 0; Mtu : Ip_Length := 1500; end record; type Client is new Net.Sockets.Udp.Raw_Socket with private; -- Get the current DHCP client state. function Get_State (Request : in Client) return State_Type; -- Get the DHCP options that were configured during the bind process. function Get_Config (Request : in Client) return Options_Type; -- Initialize the DHCP request. procedure Initialize (Request : in out Client; Ifnet : access Net.Interfaces.Ifnet_Type'Class); -- Process the DHCP client. Depending on the DHCP state machine, proceed to the -- discover, request, renew, rebind operations. Return in <tt>Next_Call</tt> the -- deadline time before the next call. procedure Process (Request : in out Client; Next_Call : out Ada.Real_Time.Time); -- Send the DHCP discover packet to initiate the DHCP discovery process. procedure Discover (Request : in out Client) with Pre => Request.Get_State = STATE_SELECTING; -- Send the DHCP request packet after we received an offer. procedure Request (Request : in out Client) with Pre => Request.Get_State = STATE_REQUESTING; -- Check for duplicate address on the network. If we find someone else using -- the IP, send a DHCPDECLINE to the server. At the end of the DAD process, -- switch to the STATE_BOUND state. procedure Check_Address (Request : in out Client); -- Configure the IP stack and the interface after the DHCP ACK is received. -- The interface is configured to use the IP address, the ARP cache is flushed -- so that the duplicate address check can be made. procedure Configure (Request : in out Client; Ifnet : in out Net.Interfaces.Ifnet_Type'Class; Config : in Options_Type) with Pre => Request.Get_State in STATE_DAD | STATE_RENEWING | STATE_REBINDING, Post => Request.Get_State in STATE_DAD | STATE_RENEWING | STATE_REBINDING; -- Bind the interface with the DHCP configuration that was recieved by the DHCP ACK. -- This operation is called by the <tt>Process</tt> procedure when the BOUND state -- is entered. It can be overriden to perform specific actions. procedure Bind (Request : in out Client; Ifnet : in out Net.Interfaces.Ifnet_Type'Class; Config : in Options_Type) with Pre => Request.Get_State = STATE_BOUND; -- Send the DHCPDECLINE message to notify the DHCP server that we refuse the IP -- because the DAD discovered that the address is used. procedure Decline (Request : in out Client) with Pre => Request.Get_State = STATE_DAD, Post => Request.Get_State = STATE_INIT; -- Send the DHCPREQUEST in unicast to the DHCP server to renew the DHCP lease. procedure Renew (Request : in out Client) with Pre => Request.Get_State = STATE_RENEWING; -- Fill the DHCP options in the request. procedure Fill_Options (Request : in Client; Packet : in out Net.Buffers.Buffer_Type; Kind : in Net.Uint8; Mac : in Net.Ether_Addr); -- Receive the DHCP offer/ack/nak from the DHCP server and update the DHCP state machine. -- It only updates the DHCP state machine (the DHCP request are only sent by -- <tt>Process</tt>). overriding procedure Receive (Request : in out Client; From : in Net.Sockets.Sockaddr_In; Packet : in out Net.Buffers.Buffer_Type); -- Extract the DHCP options from the DHCP packet. procedure Extract_Options (Packet : in out Net.Buffers.Buffer_Type; Options : out Options_Type); -- Update the UDP header for the packet and send it. overriding procedure Send (Request : in out Client; Packet : in out Net.Buffers.Buffer_Type); private -- Compute the next timeout according to the DHCP state. procedure Next_Timeout (Request : in out Client); type Retry_Type is new Net.Uint8 range 0 .. 5; type Backoff_Array is array (Retry_Type) of Integer; -- Timeout table used for the DHCP backoff algorithm during for DHCP DISCOVER. Backoff : constant Backoff_Array := (0, 4, 8, 16, 32, 64); -- Wait 30 seconds before starting again a DHCP discovery process after a NAK/DECLINE. DEFAULT_PAUSE_DELAY : constant Natural := 30; -- The DHCP state machine is accessed by the <tt>Process</tt> procedure to proceed to -- the DHCP discovery and re-new process. In parallel, the <tt>Receive</tt> procedure -- handles the DHCP packets received by the DHCP server and it changes the state according -- to the received packet. protected type Machine is -- Get the current state. function Get_State return State_Type; -- Set the new DHCP state. procedure Set_State (New_State : in State_Type); -- Set the DHCP options and the DHCP state to the STATE_BOUND. procedure Bind (Options : in Options_Type); -- Get the DHCP options that were configured during the bind process. function Get_Config return Options_Type; private State : State_Type := STATE_INIT; Config : Options_Type; end Machine; type Client is new Net.Sockets.Udp.Raw_Socket with record Ifnet : access Net.Interfaces.Ifnet_Type'Class; State : Machine; Current : State_Type := STATE_INIT; Mac : Net.Ether_Addr := (others => 0); Timeout : Ada.Real_Time.Time; Start_Time : Ada.Real_Time.Time; Renew_Time : Ada.Real_Time.Time; Rebind_Time : Ada.Real_Time.Time; Expire_Time : Ada.Real_Time.Time; Pause_Delay : Natural := DEFAULT_PAUSE_DELAY; Xid : Net.Uint32; Secs : Net.Uint16 := 0; Ip : Net.Ip_Addr := (others => 0); Server_Ip : Net.Ip_Addr := (others => 0); Retry : Retry_Type := 0; Configured : Boolean := False; end record; end Net.DHCP;
ekoeppen/STM32_Generic_Ada_Drivers
Ada
1,620
adb
with Last_Chance_Handler; pragma Unreferenced (Last_Chance_Handler); with Ada.Real_Time; use Ada.Real_Time; with STM32GD.Board; with STM32GD.GPIO; with STM32GD.GPIO.Pin; with Peripherals; use Peripherals; with Drivers.Text_IO; procedure Main is package GPIO renames STM32GD.GPIO; package Text_IO is new Drivers.Text_IO (USART => STM32GD.Board.USART); use Text_IO; procedure Print_Registers is new Peripherals.Radio.Print_Registers (Put_Line => Text_IO.Put_Line); procedure RX_Test is RX_Address : constant Radio.Address_Type := 0; begin Put_Line ("Starting RX test"); Radio.Set_RX_Address (RX_Address); Radio.RX_Mode; loop STM32GD.Board.LED.Toggle; Timer.After (Seconds (10), Radio.Cancel'Access); if Radio.Wait_For_RX then Put_Line ("Packet received"); end if; Print_Registers; end loop; end RX_Test; procedure TX_Test is Period : constant Time_Span := Seconds (3); Broadcast_Address : constant Radio.Address_Type := 0; TX_Data : constant Radio.Packet_Type := ( 16#00#, 16#FF#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FF#, 16#55#, others => 0); begin Put_Line ("Starting TX test"); Radio.Set_TX_Address (Broadcast_Address); Radio.TX_Mode; loop STM32GD.Board.LED.Toggle; Radio.TX (TX_Data); Print_Registers; delay until Clock + Period; end loop; end TX_Test; begin STM32GD.Board.Init; Peripherals.Init; loop TX_Test; end loop; end Main;
onox/orka
Ada
10,824
adb
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2017 onox <[email protected]> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. with System.Multiprocessors.Dispatching_Domains; with Ada.Unchecked_Conversion; with Ada.Unchecked_Deallocation; with Ada.Exceptions; with Orka.Futures; with Orka.Loggers; with Orka.Logging.Default; with Orka.Simulation; with Orka.Simulation_Jobs; package body Orka.Loops is use all type Orka.Logging.Default_Module; use all type Orka.Logging.Severity; use Orka.Logging; procedure Log is new Orka.Logging.Default.Generic_Log (Engine); function "+" (Value : Ada.Real_Time.Time_Span) return Duration renames Ada.Real_Time.To_Duration; procedure Free is new Ada.Unchecked_Deallocation (Behaviors.Behavior_Array, Behaviors.Behavior_Array_Access); function "<" (Left, Right : Behaviors.Behavior_Ptr) return Boolean is function Convert is new Ada.Unchecked_Conversion (Source => System.Address, Target => Long_Integer); begin return Convert (Left.all'Address) < Convert (Right.all'Address); end "<"; protected body Handler is procedure Stop is begin Stop_Flag := True; end Stop; procedure Set_Frame_Limit (Value : Time_Span) is begin Limit := Value; end Set_Frame_Limit; function Frame_Limit return Time_Span is (Limit); procedure Enable_Limit (Enable : Boolean) is begin Limit_Flag := Enable; end Enable_Limit; function Limit_Enabled return Boolean is (Limit_Flag); function Should_Stop return Boolean is (Stop_Flag); end Handler; protected body Scene is procedure Add (Object : Behaviors.Behavior_Ptr) is begin Behaviors_Set.Insert (Object); Modified_Flag := True; end Add; procedure Remove (Object : Behaviors.Behavior_Ptr) is begin Behaviors_Set.Delete (Object); Modified_Flag := True; end Remove; procedure Replace_Array (Target : in out Behaviors.Behavior_Array_Access) is pragma Assert (Modified); Index : Positive := 1; Count : constant Positive := Positive (Behaviors_Set.Length); begin Free (Target); Target := new Behaviors.Behavior_Array'(1 .. Count => Behaviors.Null_Behavior); -- Copy the elements from the set to the array -- for faster iteration by the game loop for Element of Behaviors_Set loop Target (Index) := Element; Index := Index + 1; end loop; Modified_Flag := False; end Replace_Array; function Modified return Boolean is (Modified_Flag); procedure Set_Camera (Camera : Cameras.Camera_Ptr) is begin Scene_Camera := Camera; end Set_Camera; function Camera return Cameras.Camera_Ptr is (Scene_Camera); end Scene; package SJ renames Simulation_Jobs; procedure Stop_Loop is begin Handler.Stop; end Stop_Loop; procedure Run_Game_Loop (Fence : not null access SJ.Fences.Buffer_Fence; Render : Simulation.Render_Ptr) is subtype Time is Ada.Real_Time.Time; Previous_Time : Time := Clock; Next_Time : Time := Previous_Time; Lag : Time_Span := Time_Span_Zero; Scene_Array : not null Behaviors.Behavior_Array_Access := Behaviors.Empty_Behavior_Array; Batch_Length : constant := 10; One_Second : constant Time_Span := Seconds (1); Frame_Counter : Natural := 0; Exceeded_Frame_Counter : Natural := 0; Clock_FPS_Start : Time := Clock; Stat_Sum : Time_Span := Time_Span_Zero; Stat_Min : Duration := To_Duration (One_Second); Stat_Max : Duration := To_Duration (-One_Second); begin Scene.Replace_Array (Scene_Array); Log (Debug, "Simulation tick resolution: " & Trim (Image (+Tick))); -- Based on http://gameprogrammingpatterns.com/game-loop.html loop declare Current_Time : constant Time := Clock; Elapsed : constant Time_Span := Current_Time - Previous_Time; begin Previous_Time := Current_Time; Lag := Lag + Elapsed; exit when Handler.Should_Stop; declare Iterations : constant Natural := Lag / Time_Step; begin Lag := Lag - Iterations * Time_Step; Scene.Camera.Update (To_Duration (Lag)); declare Fixed_Update_Job : constant Jobs.Job_Ptr := Jobs.Parallelize (SJ.Create_Fixed_Update_Job (Scene_Array, Time_Step, Iterations), SJ.Clone_Fixed_Update_Job'Access, Scene_Array'Length, Batch_Length); Finished_Job : constant Jobs.Job_Ptr := SJ.Create_Finished_Job (Scene_Array, Time_Step, Scene.Camera.View_Position, Batch_Length); Render_Scene_Job : constant Jobs.Job_Ptr := SJ.Create_Scene_Render_Job (Render, Scene_Array, Scene.Camera); Render_Start_Job : constant Jobs.Job_Ptr := SJ.Create_Start_Render_Job (Fence); Render_Finish_Job : constant Jobs.Job_Ptr := SJ.Create_Finish_Render_Job (Fence); Handle : Futures.Pointers.Mutable_Pointer; Status : Futures.Status; begin Orka.Jobs.Chain ((Render_Start_Job, Fixed_Update_Job, Finished_Job, Render_Scene_Job, Render_Finish_Job)); Job_Manager.Queue.Enqueue (Render_Start_Job, Handle); declare Frame_Future : constant Orka.Futures.Future_Access := Handle.Get.Value; begin select Frame_Future.Wait_Until_Done (Status); or delay until Current_Time + Maximum_Frame_Time; raise Program_Error with "Maximum frame time of " & Trim (Image (+Maximum_Frame_Time)) & " exceeded"; end select; end; end; end; if Scene.Modified then Scene.Replace_Array (Scene_Array); end if; declare Total_Elapsed : constant Time_Span := Clock - Clock_FPS_Start; Limit_Exceeded : constant Time_Span := Elapsed - Handler.Frame_Limit; begin Frame_Counter := Frame_Counter + 1; if Limit_Exceeded > Time_Span_Zero then Stat_Sum := Stat_Sum + Limit_Exceeded; Stat_Min := Duration'Min (Stat_Min, To_Duration (Limit_Exceeded)); Stat_Max := Duration'Max (Stat_Max, To_Duration (Limit_Exceeded)); Exceeded_Frame_Counter := Exceeded_Frame_Counter + 1; end if; if Total_Elapsed > One_Second then declare Frame_Time : constant Time_Span := Total_Elapsed / Frame_Counter; FPS : constant Integer := Integer (1.0 / To_Duration (Frame_Time)); begin Log (Debug, Trim (FPS'Image) & " FPS, frame time: " & Trim (Image (+Frame_Time))); end; if Exceeded_Frame_Counter > 0 then declare Stat_Avg : constant Duration := +(Stat_Sum / Exceeded_Frame_Counter); begin Log (Debug, " deadline missed: " & Trim (Exceeded_Frame_Counter'Image) & " (limit is " & Trim (Image (+Handler.Frame_Limit)) & ")"); Log (Debug, " avg/min/max: " & Image (Stat_Avg) & Image (Stat_Min) & Image (Stat_Max)); end; end if; Clock_FPS_Start := Clock; Frame_Counter := 0; Exceeded_Frame_Counter := 0; Stat_Sum := Time_Span_Zero; Stat_Min := To_Duration (One_Second); Stat_Max := To_Duration (Time_Span_Zero); end if; end; if Handler.Limit_Enabled then -- Do not sleep if Next_Time fell behind more than one frame -- due to high workload (FPS dropping below limit), otherwise -- the FPS will be exceeded during a subsequent low workload -- until Next_Time has catched up if Next_Time < Current_Time - Handler.Frame_Limit then Next_Time := Current_Time; else Next_Time := Next_Time + Handler.Frame_Limit; delay until Next_Time; end if; end if; end; end loop; Job_Manager.Shutdown; exception when others => Job_Manager.Shutdown; raise; end Run_Game_Loop; procedure Run_Loop (Render : not null access procedure (Scene : not null Behaviors.Behavior_Array_Access; Camera : Cameras.Camera_Ptr)) is Fence : aliased SJ.Fences.Buffer_Fence := SJ.Fences.Create_Buffer_Fence (Regions => 4); begin declare -- Create a separate task for the game loop. The current task -- will be used to dequeue and execute GPU jobs. task Simulation; task body Simulation is begin System.Multiprocessors.Dispatching_Domains.Set_CPU (1); Run_Game_Loop (Fence'Unchecked_Access, Render); exception when Error : others => Log (Loggers.Error, Ada.Exceptions.Exception_Information (Error)); end Simulation; begin System.Multiprocessors.Dispatching_Domains.Set_CPU (1); -- Execute GPU jobs in the current task Job_Manager.Execute_GPU_Jobs; end; end Run_Loop; end Orka.Loops;
reznikmm/matreshka
Ada
6,431
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Web Framework -- -- -- -- Examples Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011, 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 XML.SAX.Attributes; with XML.SAX.Content_Handlers; with XML.SAX.Declaration_Handlers; with XML.SAX.DTD_Handlers; with XML.SAX.Entity_Resolvers; with XML.SAX.Error_Handlers; with XML.SAX.Input_Sources; with XML.SAX.Lexical_Handlers; with XML.SAX.Locators; with XML.SAX.Parse_Exceptions; with Ada.Wide_Wide_Text_IO; package Events_Printers is type Events_Printer is limited new XML.SAX.Content_Handlers.SAX_Content_Handler and XML.SAX.Declaration_Handlers.SAX_Declaration_Handler and XML.SAX.DTD_Handlers.SAX_DTD_Handler and XML.SAX.Entity_Resolvers.SAX_Entity_Resolver and XML.SAX.Error_Handlers.SAX_Error_Handler and XML.SAX.Lexical_Handlers.SAX_Lexical_Handler with record Locator : XML.SAX.Locators.SAX_Locator; end record; -- GNAT GPL 2010: compiler is unable to compile declaration of this type -- when it is declared as private. procedure Initialize; procedure Close; overriding procedure Characters (Self : in out Events_Printer; Text : League.Strings.Universal_String; Success : in out Boolean); overriding procedure Comment (Self : in out Events_Printer; Text : League.Strings.Universal_String; Success : in out Boolean); overriding procedure End_Element (Self : in out Events_Printer; Namespace_URI : League.Strings.Universal_String; Local_Name : League.Strings.Universal_String; Qualified_Name : League.Strings.Universal_String; Success : in out Boolean); overriding procedure End_Prefix_Mapping (Self : in out Events_Printer; Prefix : League.Strings.Universal_String; Success : in out Boolean); overriding procedure Error (Self : in out Events_Printer; Occurrence : XML.SAX.Parse_Exceptions.SAX_Parse_Exception; Success : in out Boolean); overriding function Error_String (Self : Events_Printer) return League.Strings.Universal_String; overriding procedure Fatal_Error (Self : in out Events_Printer; Occurrence : XML.SAX.Parse_Exceptions.SAX_Parse_Exception; Success : in out Boolean); overriding procedure Set_Document_Locator (Self : in out Events_Printer; Locator : XML.SAX.Locators.SAX_Locator); overriding procedure Start_Element (Self : in out Events_Printer; Namespace_URI : League.Strings.Universal_String; Local_Name : League.Strings.Universal_String; Qualified_Name : League.Strings.Universal_String; Attributes : XML.SAX.Attributes.SAX_Attributes; Success : in out Boolean); overriding procedure Start_Prefix_Mapping (Self : in out Events_Printer; Prefix : League.Strings.Universal_String; Namespace_URI : League.Strings.Universal_String; Success : in out Boolean); overriding procedure Warning (Self : in out Events_Printer; Occurrence : XML.SAX.Parse_Exceptions.SAX_Parse_Exception; Success : in out Boolean); end Events_Printers;
caqg/linux-home
Ada
11,817
adb
-- Abstract : -- -- See spec. -- -- Copyright (C) 2018 - 2019 Free Software Foundation, Inc. -- -- This program 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 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 -- distributed with this program; see file COPYING. If not, write to -- the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, -- MA 02110-1335, USA. pragma License (GPL); with Ada.Command_Line; with Ada.Exceptions; with Ada.IO_Exceptions; with Ada.Real_Time; with Ada.Text_IO; with GNAT.Traceback.Symbolic; with SAL; with System.Multiprocessors; package body Run_Wisi_Common_Parse is procedure Usage (Parser : in out WisiToken.Parse.LR.Parser.Parser) is use all type WisiToken.Parse.LR.Parse_Table_Ptr; use Ada.Text_IO; begin Put_Line ("usage: <file_name> <parse_action> [partial parse params]" & "[options]"); Put_Line ("parse_action: {Navigate | Face | Indent}"); Put_Line ("partial parse params: begin_byte_pos end_byte_pos goal_byte_pos begin_char_pos begin_line" & " end_line begin_indent"); Put_Line ("options:"); Put_Line ("--verbosity n m l:"); Put_Line (" n: parser; m: mckenzie; l: action"); Put_Line (" 0 - only report parse errors"); Put_Line (" 1 - shows spawn/terminate parallel parsers, error recovery enter/exit"); Put_Line (" 2 - add each parser cycle, error recovery enqueue/check"); Put_Line (" 3 - parse stack in each cycle, error recovery parse actions"); Put_Line (" 4 - add lexer debug"); Put_Line ("--check_limit n : set error recover token check limit" & (if Parser.Table = null then "" else "; default" & WisiToken.Token_Index'Image (Parser.Table.McKenzie_Param.Check_Limit))); Put_Line ("--enqueue_limit n : set error recover token enqueue limit" & (if Parser.Table = null then "" else "; default" & Integer'Image (Parser.Table.McKenzie_Param.Enqueue_Limit))); Put_Line ("--max_parallel n : set maximum count of parallel parsers (default" & Integer'Image (WisiToken.Parse.LR.Parser.Default_Max_Parallel) & ")"); Put_Line ("--task_count n : worker tasks in error recovery"); Put_Line ("--disable_recover : disable error recovery; default enabled"); Put_Line ("--debug_mode : tracebacks from unhandled exceptions; default disabled"); Put_Line ("--lang_params <language-specific params>"); Put_Line ("--repeat_count n : repeat parse count times, for profiling; default 1"); New_Line; end Usage; function Get_CL_Params (Parser : in out WisiToken.Parse.LR.Parser.Parser) return Command_Line_Params is use Ada.Command_Line; use WisiToken; Arg : Integer := 1; begin return Result : Command_Line_Params do if Argument_Count < 1 then Usage (Parser); Set_Exit_Status (Failure); raise Finish; elsif Argument (Arg) = "--help" then Usage (Parser); raise Finish; elsif Argument_Count < 2 then Usage (Parser); Set_Exit_Status (Failure); raise Finish; end if; Result.Source_File_Name := +Ada.Command_Line.Argument (1); Result.Post_Parse_Action := Wisi.Post_Parse_Action_Type'Value (Ada.Command_Line.Argument (2)); if Argument_Count >= 3 and then Argument (3)(1) /= '-' then Result.Begin_Byte_Pos := WisiToken.Buffer_Pos'Value (Argument (3)); Result.End_Byte_Pos := WisiToken.Buffer_Pos'Value (Argument (4)) - 1; -- match emacs region Result.Goal_Byte_Pos := WisiToken.Buffer_Pos'Value (Argument (5)); Result.Begin_Char_Pos := WisiToken.Buffer_Pos'Value (Argument (6)); Result.Begin_Line := WisiToken.Line_Number_Type'Value (Argument (7)); Result.End_Line := WisiToken.Line_Number_Type'Value (Argument (8)); Result.Begin_Indent := Integer'Value (Argument (9)); Arg := 10; else Result.Begin_Byte_Pos := WisiToken.Invalid_Buffer_Pos; Result.End_Byte_Pos := WisiToken.Invalid_Buffer_Pos; Result.Begin_Char_Pos := WisiToken.Buffer_Pos'First; Result.Begin_Line := WisiToken.Line_Number_Type'First; Arg := 3; end if; loop exit when Arg > Argument_Count; if Argument (Arg) = "--verbosity" then WisiToken.Trace_Parse := Integer'Value (Argument (Arg + 1)); WisiToken.Trace_McKenzie := Integer'Value (Argument (Arg + 2)); WisiToken.Trace_Action := Integer'Value (Argument (Arg + 3)); Arg := Arg + 4; elsif Argument (Arg) = "--check_limit" then Parser.Table.McKenzie_Param.Check_Limit := Token_Index'Value (Argument (Arg + 1)); Arg := Arg + 2; elsif Argument (Arg) = "--debug_mode" then WisiToken.Debug_Mode := True; Arg := Arg + 1; elsif Argument (Arg) = "--disable_recover" then Parser.Enable_McKenzie_Recover := False; Arg := Arg + 1; elsif Argument (Arg) = "--enqueue_limit" then Parser.Table.McKenzie_Param.Enqueue_Limit := Integer'Value (Argument (Arg + 1)); Arg := Arg + 2; elsif Argument (Arg) = "--lang_params" then Result.Lang_Params := +Argument (Arg + 1); Arg := Arg + 2; elsif Argument (Arg) = "--max_parallel" then Parser.Max_Parallel := SAL.Base_Peek_Type'Value (Argument (Arg + 1)); Arg := Arg + 2; elsif Argument (Arg) = "--repeat_count" then Result.Repeat_Count := Integer'Value (Argument (Arg + 1)); Arg := Arg + 2; elsif Argument (Arg) = "--task_count" then Parser.Table.McKenzie_Param.Task_Count := System.Multiprocessors.CPU_Range'Value (Argument (Arg + 1)); Arg := Arg + 2; else Ada.Text_IO.Put_Line ("unrecognized option: '" & Argument (Arg) & "'"); Usage (Parser); Set_Exit_Status (Failure); raise SAL.Parameter_Error; end if; end loop; end return; exception when Finish => raise; when E : others => Ada.Text_IO.Put_Line (Ada.Exceptions.Exception_Name (E) & ": " & Ada.Exceptions.Exception_Message (E)); Usage (Parser); Set_Exit_Status (Failure); raise SAL.Parameter_Error; end Get_CL_Params; procedure Parse_File (Parser : in out WisiToken.Parse.LR.Parser.Parser; Parse_Data : in out Wisi.Parse_Data_Type'Class; Descriptor : in WisiToken.Descriptor) is use Ada.Text_IO; use WisiToken; Cl_Params : Command_Line_Params; -- not initialized for exception handler Start : Ada.Real_Time.Time; begin Cl_Params := Get_CL_Params (Parser); -- Do this after setting Trace_Parse so lexer verbosity is set begin Parser.Lexer.Reset_With_File (-Cl_Params.Source_File_Name, Cl_Params.Begin_Byte_Pos, Cl_Params.End_Byte_Pos, Cl_Params.Begin_Char_Pos, Cl_Params.Begin_Line); exception when Ada.IO_Exceptions.Name_Error => Put_Line (Standard_Error, "'" & (-Cl_Params.Source_File_Name) & "' cannot be opened"); return; end; if Cl_Params.End_Line = Invalid_Line_Number then -- User did not provide; run lexer to get end line. declare Token : Base_Token; Lexer_Error : Boolean; pragma Unreferenced (Lexer_Error); begin loop Lexer_Error := Parser.Lexer.Find_Next (Token); exit when Token.ID = Descriptor.EOI_ID; end loop; Cl_Params.End_Line := Token.Line; end; end if; Parse_Data.Initialize (Post_Parse_Action => Cl_Params.Post_Parse_Action, Descriptor => Descriptor'Unrestricted_Access, Source_File_Name => -Cl_Params.Source_File_Name, Begin_Line => Cl_Params.Begin_Line, End_Line => Cl_Params.End_Line, Begin_Indent => Cl_Params.Begin_Indent, Params => -Cl_Params.Lang_Params); if Cl_Params.Repeat_Count > 1 then Start := Ada.Real_Time.Clock; end if; for I in 1 .. Cl_Params.Repeat_Count loop declare procedure Clean_Up is use all type SAL.Base_Peek_Type; begin Parser.Lexer.Discard_Rest_Of_Input; if Cl_Params.Repeat_Count = 1 and Parser.Parsers.Count > 0 then Parse_Data.Put (Parser.Lexer.Errors, Parser.Parsers.First.State_Ref.Errors, Parser.Parsers.First.State_Ref.Tree); end if; end Clean_Up; begin Parse_Data.Reset; Parser.Lexer.Reset; begin Parser.Parse; exception when WisiToken.Partial_Parse => null; end; Parser.Execute_Actions; if Cl_Params.Repeat_Count = 1 then Parse_Data.Put (Parser); Parse_Data.Put (Parser.Lexer.Errors, Parser.Parsers.First.State_Ref.Errors, Parser.Parsers.First.State_Ref.Tree); end if; exception when WisiToken.Syntax_Error => Clean_Up; Put_Line ("(parse_error)"); when E : WisiToken.Parse_Error => Clean_Up; Put_Line ("(parse_error """ & Ada.Exceptions.Exception_Message (E) & """)"); when E : WisiToken.Fatal_Error => Clean_Up; Put_Line ("(error """ & Ada.Exceptions.Exception_Message (E) & """)"); end; end loop; if Cl_Params.Repeat_Count > 1 then declare use Ada.Real_Time; Finish : constant Time := Clock; begin Put_Line ("Total time:" & Duration'Image (To_Duration (Finish - Start))); Put_Line ("per iteration:" & Duration'Image (To_Duration ((Finish - Start) / Cl_Params.Repeat_Count))); end; end if; exception when SAL.Parameter_Error | Finish => -- From Get_CL_Params; already handled. null; when E : others => Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); New_Line (2); Put_Line ("(error ""unhandled exception: " & Ada.Exceptions.Exception_Name (E) & ": " & Ada.Exceptions.Exception_Message (E) & """)"); Put_Line (GNAT.Traceback.Symbolic.Symbolic_Traceback (E)); end Parse_File; end Run_Wisi_Common_Parse;
reznikmm/matreshka
Ada
4,654
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Svg.Overline_Position_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Svg_Overline_Position_Attribute_Node is begin return Self : Svg_Overline_Position_Attribute_Node do Matreshka.ODF_Svg.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Svg_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Svg_Overline_Position_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Overline_Position_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Svg_URI, Matreshka.ODF_String_Constants.Overline_Position_Attribute, Svg_Overline_Position_Attribute_Node'Tag); end Matreshka.ODF_Svg.Overline_Position_Attributes;
spacekookie/learn_ada
Ada
429
adb
with Ada.Text_IO; use Ada.Text_IO; procedure UglyForm is begin Put("Good form "); Put("can aid in "); Put ("understanding a program,"); New_Line; Put("and bad form "); Put("can make a program "); Put("unreadable."); New_Line; end UglyForm; -- Result of execution -- Good form can aid in understanding a program, -- and bad form can make a program unreadable.
faelys/natools
Ada
1,766
adb
------------------------------------------------------------------------------ -- Copyright (c) 2014, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Natools.Time_Statistics.Fine_Timer_Difference provides a difference -- -- function between real-time moments as a Duration value. -- ------------------------------------------------------------------------------ with Ada.Real_Time; function Natools.Time_Statistics.Fine_Timer_Difference (Left, Right : Ada.Real_Time.Time) return Duration is begin return Ada.Real_Time.To_Duration (Ada.Real_Time."-" (Left, Right)); end Natools.Time_Statistics.Fine_Timer_Difference;
coopht/axmpp
Ada
4,343
ads
------------------------------------------------------------------------------ -- -- -- AXMPP Project -- -- -- -- XMPP Library for Ada -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011, Alexander Basov <[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 Alexander Basov, 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; package XMPP.Base64 is -- RFC 1521, MIME Base64 encode/decode -- Assumes Ada.Streams.Stream_Element is a byte. procedure Decode (Source : String; Target : out Ada.Streams.Stream_Element_Array; Last : out Ada.Streams.Stream_Element_Offset); -- decode Source into Target(Target'first .. Last) -- Note: it may be appropriate to prescan Source for '=', -- indicating termination, or for illegitimate characters, -- indicating corruption, before calling Decode. procedure Encode (Source : Ada.Streams.Stream_Element_Array; Target : out String; Last : out Natural); -- Target is filled in four character increments, except that -- a CR-LF pair is inserted after every 76 characters. -- Target'length must be at least: -- Output_Quad_Count: constant := (Source'length + 2) / 3; -- Output_Byte_Count: constant := 4 * Output_Quad_Count; -- Target'length = Output_Byte_Count + 2 * (Output_Byte_Count / 76) -- Constraint_Error will be raised if Target isn't long enough. end XMPP.Base64;
NCommander/dnscatcher
Ada
8,472
ads
-- Copyright 2019 Michael Casadevall <[email protected]> -- -- Permission is hereby granted, free of charge, to any person obtaining a copy -- of this software and associated documentation files (the "Software"), to -- deal in the Software without restriction, including without limitation the -- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -- sell copies of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in -- all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -- DEALINGS IN THE SOFTWARE. with Ada.Containers.Vectors; use Ada.Containers; -- @summary -- Handles logging functionality for DNSCatcher. This represents a common -- class of functionality, with individual subclasses defining logging to -- null, stdout, file, and syslog -- -- @description -- DNSCatcher's Logger is designed to work on the basis of message compliation -- and dispatching. Throughout a given operation, data may be passed through -- multiple processors, modules, and other components, with other data being -- handled simulatiously. As such Log messages are contained in a specific -- queue which is then gathered up, and dispatched as one giant chunk of logs. -- -- Given that many different component can be used for logging such as syslog -- on POSIX systems, or perhaps Logstash, this is designed to be abstracted -- away quickly and easily -- package DNSCatcher.Utils.Logger is -- Handles logging operations in a sane and consistent way within the -- Catcher -- Represents the type and severity of a log message. This type is directly -- based on syslog message symatics. type Log_Levels is (EMERGERENCY, -- Emergency message; reserved for emergency bail outs ALERT, -- Alert condition, system admin intervention required CRITICAL, -- Critical message, something has gone wrong in a component ERROR, -- Error message, may be fatal or non-fatal WARNING, -- Warning NOTICE, -- Information notice INFO, -- Basic information DEBUG -- Debug information ); --!pp off for Log_Levels use (EMERGERENCY => 0, ALERT => 1, CRITICAL => 2, ERROR => 3, WARNING => 4, NOTICE => 5, INFO => 6, DEBUG => 7); --!pp on -- Logger configuration object -- -- @value Log_Level -- Sets the filter level for messages being sent -- -- @value Use_Color -- If supported, use color within the log message type Logger_Configuration is record Log_Level : Log_Levels; Use_Color : Boolean; end record; -- Component_Vector is a list of Unbounded_Strings that make up the -- component part of a given log message, creating a hierarchy of log -- messages based on component and calling path package Component_Vector is new Vectors (Natural, Unbounded_String); -- Individual log message, which contains the component -- -- @value Log_Level -- The log level of a given message -- -- @value Component -- The vector containing the component levels -- -- @value Message -- The actual log message as an unbounded string type Log_Message_Record is record Log_Level : Log_Levels; Component : Component_Vector.Vector; Message : Unbounded_String; end record; type Log_Message_Record_Ptr is access Log_Message_Record; -- Logger Message Queue is used by a task to ensure mesages are delivered in -- order. One queue exists per task. package Log_Message_Vector is new Vectors (Natural, Log_Message_Record); -- Logger Message Component -- -- This is a protected type that handles all log messages within a given -- component, and is pushed into the global packet vector protected type Logger_Message_Packet is -- Pushes a component name onto the component stack -- -- @value Component -- Name of the component entry Push_Component (Component : String); -- Pops the latest component on the stack entry Pop_Component; -- Logs a message -- -- @value Level -- Log level of the message -- -- @value Msg -- String of the msg to be added entry Log_Message (Level : Log_Levels; Msg : String); -- Pops the top message of the internal message stack -- -- @value Msg -- Output for Log_Message_Record entry Get (Msg : out Log_Message_Record); -- Gets all messages from this component queue, and clears it -- -- @value Queue -- Returns a Log_Message_Vector with all the component objects entry Get_All_And_Empty (Queue : out Log_Message_Vector.Vector); -- Gets count of all messages in this queue -- -- @value Count -- Integer to return the count to entry Count (Count : out Integer); -- Empties queue of all messages entry Empty; private Current_Component : Component_Vector.Vector; Logged_Msgs : Log_Message_Vector.Vector; end Logger_Message_Packet; type Logger_Message_Packet_Ptr is access Logger_Message_Packet; -- Vector containing sets of log messages package Logger_Message_Packet_Vector is new Vectors (Natural, Logger_Message_Packet_Ptr); -- Implements the global logger queue message type; this is used as a global -- object for taking logger packets and dispatching them to whatever end -- point is configured by the logger -- protected type Logger_Queue_Type is -- Adds a logger message packet to the queue -- -- @value Queue -- Pointer to the logger message to add entry Add_Packet (Queue : Logger_Message_Packet_Ptr); -- Gets the top of the queue -- -- @value Queue -- Variable to write the pointer to entry Get (Queue : out Logger_Message_Packet_Ptr); -- Gets a count of the number of logger packets in the queue -- -- @value Count -- Count of all message -- entry Count (Count : out Integer); -- Empties the logger queue entry Empty; private Queued_Packets : Logger_Message_Packet_Vector.Vector; end Logger_Queue_Type; -- Global for logging queues Logger_Queue : Logger_Queue_Type; -- Task for handling logger functionality task type Logger is -- Initializes the logger task -- -- @value Cfg -- Configuration object entry Initialize (Cfg : Logger_Configuration); -- Starts the logger thread entry Start; -- Stops the logger thread entry Stop; end Logger; private -- ANSI Color Codes, and Reset message for STDOUT printing on Linux ANSI_Default : constant String := ASCII.ESC & "[39m"; ANSI_Black : constant String := ASCII.ESC & "[30m"; ANSI_Red : constant String := ASCII.ESC & "[31m"; ANSI_Green : constant String := ASCII.ESC & "[32m"; ANSI_Yellow : constant String := ASCII.ESC & "[33m"; ANSI_Blue : constant String := ASCII.ESC & "[34m"; ANSI_Magenta : constant String := ASCII.ESC & "[35m"; ANSI_Cyan : constant String := ASCII.ESC & "[36m"; ANSI_Light_Gray : constant String := ASCII.ESC & "[37m"; ANSI_Dark_Gray : constant String := ASCII.ESC & "[90m"; ANSI_Light_Red : constant String := ASCII.ESC & "[91m"; ANSI_Light_Green : constant String := ASCII.ESC & "[92m"; ANSI_Light_Yellow : constant String := ASCII.ESC & "[93m"; ANSI_Light_Blue : constant String := ASCII.ESC & "[94m"; ANSI_Light_Magenta : constant String := ASCII.ESC & "[95m"; ANSI_Light_Cyan : constant String := ASCII.ESC & "[96m"; ANSI_Reset : constant String := ASCII.ESC & "[0m"; end DNSCatcher.Utils.Logger;
charlie5/cBound
Ada
1,486
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_map_window_request_t is -- Item -- type Item is record major_opcode : aliased Interfaces.Unsigned_8; pad0 : aliased Interfaces.Unsigned_8; length : aliased Interfaces.Unsigned_16; window : aliased xcb.xcb_window_t; end record; -- Item_Array -- type Item_Array is array (Interfaces.C.size_t range <>) of aliased xcb.xcb_map_window_request_t .Item; -- Pointer -- package C_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_map_window_request_t.Item, Element_Array => xcb.xcb_map_window_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_map_window_request_t .Pointer; -- Pointer_Pointer -- package C_Pointer_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_map_window_request_t.Pointer, Element_Array => xcb.xcb_map_window_request_t.Pointer_Array, Default_Terminator => null); subtype Pointer_Pointer is C_Pointer_Pointers.Pointer; end xcb.xcb_map_window_request_t;
jscparker/math_packages
Ada
11,396
adb
------------------------------------------------------------------------------- -- package body Chi_Gaussian_CDF, CDF of Normal and Chi-square distributions -- Copyright (C) 1995-2018 Jonathan S. Parker -- -- Permission to use, copy, modify, and/or distribute this software for any -- purpose with or without fee is hereby granted, provided that the above -- copyright notice and this permission notice appear in all copies. -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ------------------------------------------------------------------------------- with Ada.Numerics.Generic_Elementary_Functions; with Gamma; package body Chi_Gaussian_CDF is package Math is new Ada.Numerics.Generic_Elementary_Functions(Real); use Math; package Gam is new Gamma(Real); use Gam; --provides log_gamma; for reals to 32 digits Real_Epsilon : constant Real := Real'Epsilon * 0.5; -- 4.4*e-16 for ieee Max_Log : constant Real := 666.0; --------------------- -- Chi_Squared_CDF -- --------------------- -- Cumulative distribution function for Chi^2 distribution. function Chi_Squared_CDF (True_Degrees_Freedom : Real; Chi_Squared : Real) return Real is a : constant Real := True_Degrees_Freedom * 0.5; x : constant Real := Chi_Squared * 0.5; begin if not x'Valid then raise Constraint_Error; end if; -- In some cases, input of (say) inf or NaN will make numeric programs -- hang rather than crash .. very difficult to diagnose, so this seems -- best policy for function calls that are rarely found in time-sensitive -- inner loops return Incomplete_Gamma (a, x); end Chi_Squared_CDF; function Normal_CDF_x (x : in Real) return Real; ----------------- -- Normal_CDF -- ----------------- -- Cumulative distribution function for Standard Normal Distribution. -- -- Normal (v) = exp(-v*v/2) / Sqrt(2 pi) -- -- Want to integrate this from -inf to x using the Incomplete Gamma function: -- -- Inc_Gamma(a, w) = Int{from 0 to w} [exp(-t) t**(a-1) dt] / Gamma(a) -- -- Set a = 0.5. Use Gamma(0.5) = Sqrt(pi) and let t = u*u/2: -- -- Inc_Gamma(0.5, w) = Int{from 0 to sqrt(2w)} [2 exp(-v*v/2) dv] / Sqrt(2 pi) -- -- Inc_Gamma(0.5, x*x/2) / 2 = Int{from 0 to x)} [exp(-v*v/2) dv] / Sqrt(2 pi) -- -- function Normal_CDF (x : Real) return Real is a : constant Real := 0.5; begin if not x'Valid then raise Constraint_Error; end if; -- In some cases, input of (say) inf or NaN will make numeric programs -- hang rather than crash .. very difficult to diagnose, so this seems -- best policy for function calls that are rarely found in time-sensitive -- inner loops. if x > 0.0 then return 0.5 * (1.0 + Incomplete_Gamma (a, x*x*0.5)); elsif x <= -4.5 then return Normal_CDF_x (x); -- get better accuracy here out on tail. else return 0.5 * (1.0 - Incomplete_Gamma (a, x*x*0.5)); end if; end Normal_CDF; ------------------------ -- Incomplete_Gamma_C -- ------------------------ -- This is the complemented Incomplete_Gamma function: -- -- Incomplete_Gamma_C (a,x) -- = Integral {t=x to inf} [exp(-t) * t**(a-1) * dt] / Gamma(a) -- -- Notice that because the integrals are nomalized by 1 / Gamma(a): -- -- Incomplete_Gamma (a,x) + Incomplete_Gamma_C (a,x) = 1.0 -- -- Uses Gauss' (c. 1813) continued fraction (see wikipedia for inc. gamma) -- function Incomplete_Gamma_C (a : Real; x : Real) return Real is Exagam, Arg : Real; C_Fraction, N, g_2, g_1 : Real; r, t : Real; P, P_1, P_2 : Real; Q, Q_1, Q_2 : Real; Max_Allowed_Val : constant Real := 2.0**48; Reciprocal_of_Max_Allowed_Val : constant Real := 2.0**(-48); Min_Allowed_Real : constant Real := 2.0**(Real'Machine_Emin / 2); begin if not x'Valid then raise Constraint_Error; end if; if (x <= 0.0) or (a <= 0.0) then return 1.0; end if; -- Use series solution for small x: if (x < 1.0) or (x < a) then return 1.0 - Incomplete_Gamma(a,x); end if; -- Exagam := x**a * Exp(-x) / Gamma(a): Arg := a * Log (x) - x - Log_Gamma (a); -- notice never gets big > 0 if x>0 if (Arg < -Max_Log) then return 0.0; else Exagam := Exp (Arg); end if; N := 0.0; g_1 := x - a + 2.0; P_2 := 1.0; --P(-2) Q_2 := x; --Q(-2) P_1 := x + 1.0; --P(-1) Q_1 := Q_2 * g_1; --Q(-1) C_Fraction := P_1 / Q_1; Continued_Fraction_Evaluation: loop N := N + 1.0; g_1 := g_1 + 2.0; g_2 := (N + 1.0 - a) * N; P := P_1 * g_1 - P_2 * g_2; Q := Q_1 * g_1 - Q_2 * g_2; if (Abs Q > Min_Allowed_Real) then r := P / Q; t := Abs ((C_Fraction - r) / r); C_Fraction := r; else t := 1.0; end if; -- scale P's and Q's identically with 2.0**n if P gets too large. -- Final answer is P/Q. P_2 := P_1; P_1 := P; Q_2 := Q_1; Q_1 := Q; if (Abs (P) > Max_Allowed_Val) then P_2 := P_2 * Reciprocal_of_Max_Allowed_Val; P_1 := P_1 * Reciprocal_of_Max_Allowed_Val; Q_2 := Q_2 * Reciprocal_of_Max_Allowed_Val; Q_1 := Q_1 * Reciprocal_of_Max_Allowed_Val; end if; if (t < Real_Epsilon) then exit Continued_Fraction_Evaluation; end if; end loop Continued_Fraction_Evaluation; return C_Fraction * Exagam; end Incomplete_Gamma_C; ---------------------- -- Incomplete_Gamma -- ---------------------- -- Incomplete_Gamma (a,x) = Integral {t=0 to x} [exp(-t) * t**(a-1) * dt] / Gamma(a) -- -- Notice as x -> inf, the Integral -> Gamma(a), and Incomplete_Gamma (a,x) -> 1.0 -- -- Abramowitz, Stegun 6.5.29: -- -- = Exp(-x) * x**a * Sum {k=0 to inf} [x**k / Gamma(a+k+1)] -- -- use Gamma(a+1) = a * Gamma(a): -- -- = Exp(-x) * x**a * Sum {k=0 to inf} [a! * (-x)**k / (a+k)!] / Gamma(a) -- -- = Exp(-x) * x**a * [1/a + x/(a(a+1)) + x^2/(a(a+1)(a+2)) + ...] / Gamma(a) -- function Incomplete_Gamma (a : Real; x : Real) return Real is Sum, Exagam, Arg, Next_Term, a_plus_n : Real; begin if not x'Valid then raise Constraint_Error; end if; if (x <= 0.0) or (a <= 0.0) then return 0.0; end if; if not ((x < 1.0) or (x < a)) then return (1.0 - Incomplete_Gamma_C (a,x)); end if; -- Exagam := x**a * Exp(-x) / Gamma(a): Arg := a * Log (x) - x - Log_Gamma (a); if Arg < -Max_Log then return 0.0; else Exagam := Exp (Arg); end if; -- -- (Exp(-x) * x**a / Gamma(a))* [1/a + x/(a(a+1)) + x^2/(a(a+1)(a+2)) + ...] -- -- factor out the 1/a: -- -- = (Exagam / a) * [1 + x/(a+1) + x^2/((a+1)(a+2)) + ...] -- a_plus_n := a; -- n = 0 Next_Term := 1.0; Sum := 1.0; -- max number of allowed iterations arbitrarily set at 2**12: Series_Summation: for Iteration_id in 1 .. 2**12 loop a_plus_n := a_plus_n + 1.0; Next_Term := Next_Term * x / a_plus_n; Sum := Sum + Next_Term; if (Next_Term/Sum < Real_Epsilon) then exit Series_Summation; end if; end loop Series_Summation; return Sum * Exagam / a; end Incomplete_Gamma; ------------------ -- Normal_CDF_x -- ------------------ -- Here just used for x out on tail, where it seems more accurate -- than the other method used above. -- -- Evaluates the cumulative distribution function of a gaussian. -- Finds area of the standardized normal distribution -- (normalized gaussian with unit width) from -inf to x. -- based on Algorithm AS66 Applied Statistics (1973) vol.22, no.3. -- Usually 7 digits accuracy; better on x<<0 tail. function Normal_CDF_x (x : in Real) return Real is z, y, Result : Real; con : constant Real := 1.28; ltone : constant Real := 7.0; utzero : constant Real := 40.0; p : constant Real := 0.398942280444; q : constant Real := 0.39990348504; r : constant Real := 0.398942280385; a1 : constant Real := 5.75885480458; a2 : constant Real := 2.62433121679; a3 : constant Real := 5.92885724438; b1 : constant Real :=-29.8213557807; b2 : constant Real := 48.6959930692; c1 : constant Real :=-3.8052E-8; c2 : constant Real := 3.98064794E-4; c3 : constant Real :=-0.151679116635; c4 : constant Real := 4.8385912808; c5 : constant Real := 0.742380924027; c6 : constant Real := 3.99019417011; d1 : constant Real := 1.00000615302; d2 : constant Real := 1.98615381364; d3 : constant Real := 5.29330324926; d4 : constant Real :=-15.1508972451; d5 : constant Real := 30.789933034; begin if not x'Valid then raise Constraint_Error; end if; z := Abs (x); if (z <= ltone OR (x < 0.0 AND (z <= utzero)) ) then y := 0.5*z*z; if (z > con) then Result := r*Exp(-y) / (z+c1+d1/(z+c2+d2/(z+c3+d3/(z+c4+d4/(z+c5+d5/(z+c6)))))); else Result := 0.5 - z*(p-q*y/(y+a1+b1/(y+a2+b2/(y+a3)))); end if; else Result := 0.0; end if; if (x >= 0.0) then Result := 1.0 - Result; end if; return Result; end Normal_CDF_x; -- rough test; more of working order than actual accuracy procedure Test_Normal_CDF (x_0 : in Real; Error : out Real) is Delta_x : constant Real := 2.0**(-6); -- 6 ok. type First_Deriv_Range_17 is range -8 .. 8; d_17 : constant array(First_Deriv_Range_17) of Real := (9.71250971250971250971250971250971250E-6 , -1.77600177600177600177600177600177600E-4 , 1.55400155400155400155400155400155400E-3 , -8.70240870240870240870240870240870240E-3 , 3.53535353535353535353535353535353535E-2 , -1.13131313131313131313131313131313131E-1 , 3.11111111111111111111111111111111111E-1 , -8.88888888888888888888888888888888888E-1 , 0.0, 8.88888888888888888888888888888888888E-1 , -3.11111111111111111111111111111111111E-1 , 1.13131313131313131313131313131313131E-1 , -3.53535353535353535353535353535353535E-2 , 8.70240870240870240870240870240870240E-3 , -1.55400155400155400155400155400155400E-3 , 1.77600177600177600177600177600177600E-4 , -9.71250971250971250971250971250971250E-6); One_over_sqrt_2_pi : constant := 0.398942280401432677939946; sum, x, Integral_of_Gaussian, Deriv : Real; begin sum := 0.0; for i in First_Deriv_Range_17 loop x := x_0 + Real(i)*Delta_x; Integral_of_Gaussian := Normal_CDF (x); sum := sum + d_17 (i) * Integral_of_Gaussian; end loop; Deriv := sum / Delta_x; -- relative --Error := (Deriv - Exp (-x_0**2 * 0.5) * One_over_sqrt_2_pi) / (Abs(Deriv)+1.0e-307); -- absolute Error := (Deriv - Exp (-x_0**2 * 0.5) * One_over_sqrt_2_pi); end Test_Normal_CDF; end Chi_Gaussian_CDF;
charlie5/lace
Ada
15,929
ads
with gel.Joint, openGL.Model, openGL.Visual, openGL.Program, physics.Model, physics.Object, physics.Shape, physics.Space, lace.Subject_and_deferred_Observer, lace.Response, lace.Any, ada.Containers.Vectors; limited with gel.World; package gel.Sprite -- -- Combines a graphics 'visual' and a physics 'solid'. -- is type Item is limited new lace.Subject_and_deferred_Observer.item with private; type View is access all Item'Class; type Items is array (math.Index range <>) of aliased Item; type Views is array (math.Index range <>) of View; null_Sprites : constant Sprite.views; type physics_Space_view is access all physics.Space.item'Class; type World_view is access all gel.World .item'Class; type any_user_Data is new lace.Any.limited_item with null record; type any_user_Data_view is access all any_user_Data'Class; use Math; -------------- --- Containers -- type Grid is array (math.Index range <>, math.Index range <>) of Sprite.view; type Grid_view is access all Grid; package Vectors is new ada.Containers.Vectors (Positive, Sprite.view); ---------- --- Forge -- procedure define (Self : access Item; World : in World_view; at_Site : in Vector_3; graphics_Model : access openGL. Model.item'Class; physics_Model : access physics.Model.item'Class; owns_Graphics : in Boolean; owns_Physics : in Boolean; is_Kinematic : in Boolean := False; user_Data : in any_user_Data_view := null); procedure destroy (Self : access Item; and_Children : in Boolean); function is_Destroyed (Self : in Item) return Boolean; procedure free (Self : in out View); package Forge is function to_Sprite (Name : in String; World : in World_view; at_Site : in Vector_3; graphics_Model : access openGL. Model.item'Class; physics_Model : access physics.Model.item'Class; owns_Graphics : in Boolean; owns_Physics : in Boolean; is_Kinematic : in Boolean := False; user_Data : in any_user_Data_view := null) return Item; function new_Sprite (Name : in String; World : in World_view; at_Site : in Vector_3; graphics_Model : access openGL. Model.item'Class; physics_Model : access physics.Model.item'Class; owns_Graphics : in Boolean := True; owns_Physics : in Boolean := True; is_Kinematic : in Boolean := False; user_Data : in any_user_Data_view := null) return View; end Forge; --------------- --- Attributes -- function World (Self : in Item) return access gel.World.item'Class; function Id (Self : in Item) return gel.sprite_Id; procedure Id_is (Self : in out Item; Now : in gel.sprite_Id); function Visual (Self : access Item) return openGL.Visual.view; function graphics_Model (Self : in Item) return openGL.Model.view; procedure Model_is (Self : in out Item; Now : in openGL.Model.view); function owns_Graphics (Self : in Item) return Boolean; function physics_Model (Self : in Item) return access physics.Model.item'Class; procedure physics_Model_is (Self : in out Item; Now : in physics.Model.view); function Scale (Self : in Item) return Vector_3; procedure Scale_is (Self : in out Item; Now : in Vector_3); function Mass (Self : in Item) return Real; function is_Static (Self : in Item) return Boolean; function is_Kinematic (Self : in Item) return Boolean; function Depth_in_camera_space (Self : in Item) return Real; procedure mvp_Matrix_is (Self : in out Item; Now : in Matrix_4x4); function mvp_Matrix (Self : in Item) return Matrix_4x4; procedure is_Visible (Self : in out Item; Now : in Boolean); function is_Visible (Self : in Item) return Boolean; procedure key_Response_is (Self : in out Item; Now : in lace.Response.view); function key_Response (Self : in Item) return lace.Response.view; subtype physics_Object_view is physics.Object.view; subtype physics_Shape_view is physics.Shape .view; function Solid (Self : in Item) return physics_Object_view; procedure Solid_is (Self : in out Item; Now : in physics_Object_view); function Shape (Self : in Item) return physics_Shape_view; function to_GEL (the_Solid : in physics_Object_view) return gel.Sprite.view; function user_Data (Self : in Item) return any_user_Data_view; procedure user_Data_is (Self : in out Item; Now : in any_user_Data_view); ------------- --- Dynamics -- --- Bounds -- function Bounds (Self : in Item) return Geometry_3d.bounding_Box; --- Site -- function Site (Self : in Item) return Vector_3; procedure Site_is (Self : in out Item; Now : in Vector_3); procedure move (Self : in out Item; to_Site : in Vector_3); -- -- Moves the sprite to a new site and recursively move children such that -- relative positions are maintained. --- Spin -- function Spin (Self : in Item) return Matrix_3x3; procedure Spin_is (Self : in out Item; Now : in Matrix_3x3); function xy_Spin (Self : in Item) return Radians; procedure xy_Spin_is (Self : in out Item; Now : in Radians); procedure rotate (Self : in out Item; to_Spin : in Matrix_3x3); -- -- Rotates the sprite to a new spin and recursively moves and rotates children such that -- relative positions/orientations are maintained. --- Transform -- function Transform (Self : in Item) return Matrix_4x4; procedure Transform_is (Self : in out Item; Now : in Matrix_4x4); --- Speed -- function Speed (Self : in Item) return Vector_3; procedure Speed_is (Self : in out Item; Now : in Vector_3); procedure set_Speed (Self : in out Item; to_Speed : in Vector_3); -- -- Set Self and all children to given value. --- Gyre -- function Gyre (Self : in Item) return Vector_3; procedure Gyre_is (Self : in out Item; Now : in Vector_3); procedure set_Gyre (Self : in out Item; to_Gyre : in Vector_3); -- -- Set Self and all children to given value. --- Forces -- procedure apply_Torque (Self : in out Item; Torque : in Vector_3); procedure apply_Torque_impulse (Self : in out Item; Torque : in Vector_3); procedure apply_Force (Self : in out Item; Force : in Vector_3); --- Mirrored Dynamics -- procedure desired_Dynamics_are (Self : in out Item; Site : in Vector_3; Spin : in Quaternion); procedure interpolate_Motion (Self : in out Item); --- Hierachy -- type DoF_Limits is record Low : math.Real; High : math.Real; end record; function parent_Joint (Self : in Item) return gel.Joint.view; function child_Joints (Self : in Item) return gel.Joint.views; function top_Parent (Self : access Item) return gel.Sprite.view; function Parent (Self : in Item) return gel.Sprite.view; function tree_Depth (Self : in Item) return Natural; procedure detach (Self : in out Item; the_Child : gel.Sprite.view); no_such_Child : exception; type Action is access procedure (the_Sprite : in out Item'Class); procedure apply (Self : in out Item; do_Action : Action); -- -- Applies an action to a sprite and its children recursively. --- Hinge -- procedure attach_via_Hinge (Self : access Item; the_Child : in Sprite.view; pivot_Axis : in Vector_3; Anchor : in Vector_3; child_Anchor : in Vector_3; low_Limit : in Real; high_Limit : in Real; collide_Connected : in Boolean; new_joint : out gel.Joint.view); procedure attach_via_Hinge (Self : access Item; the_Child : in Sprite.view; pivot_Axis : in Vector_3; pivot_Anchor : in Vector_3; low_Limit : in Real; high_Limit : in Real; new_joint : out gel.Joint.view); procedure attach_via_Hinge (Self : access Item; the_Child : in Sprite.view; pivot_Axis : in Vector_3; low_Limit : in Real; high_Limit : in Real; new_joint : out gel.Joint.view); -- -- Uses midpoint between Self and the_Child sprite as pivot_Anchor. procedure attach_via_Hinge (Self : access Item; the_Child : in Sprite.view; Frame_in_parent : in Matrix_4x4; Frame_in_child : in Matrix_4x4; Limits : in DoF_Limits; collide_Connected : in Boolean; new_joint : out gel.Joint.view); --- Ball/Socket -- procedure attach_via_ball_Socket (Self : access Item; the_Child : in Sprite.view; pivot_Anchor : in Vector_3; pivot_Axis : in Matrix_3x3; pitch_Limits : in DoF_Limits; yaw_Limits : in DoF_Limits; roll_Limits : in DoF_Limits; new_joint : out gel.Joint.view); procedure attach_via_ball_Socket (Self : access Item; the_Child : in Sprite.view; Frame_in_parent : in Matrix_4x4; Frame_in_child : in Matrix_4x4; pitch_Limits : in DoF_Limits; yaw_Limits : in DoF_Limits; roll_Limits : in DoF_Limits; new_joint : out gel.Joint.view); --- Graphics -- procedure program_Parameters_are (Self : in out Item; Now : in opengl.Program.Parameters_view); function program_Parameters (Self : in Item) return opengl.Program.Parameters_view; --- Physics -- procedure rebuild_Shape (Self : in out Item); procedure rebuild_Solid (Self : in out Item; at_Site : in Vector_3); private type access_Joint_views is access all Joint.views; use type Joint.view; package joint_Vectors is new ada.Containers.Vectors (Positive, Joint.view); -- protected -- type safe_Matrix_4x4 -- is -- function Value return Matrix_4x4; -- procedure Value_is (Now : in Matrix_4x4); -- procedure Site_is (Now : in Vector_3); -- -- private -- the_Value : Matrix_4x4 := Identity_4x4; -- end safe_Matrix_4x4; ----------------- --- Interpolation -- type site_Interpolation is record Initial : Vector_3; Desired : Vector_3; end record; type spin_Interpolation is record Initial : Quaternion; Desired : Quaternion; end record; type Interpolation is record Site : site_Interpolation; Spin : spin_Interpolation; Percent : unit_Percentage; end record; protected type safe_Interpolation is procedure set (desired_Site : in Vector_3; desired_Spin : in Quaternion); procedure get (Site : out Vector_3; Spin : out Quaternion); private Safe : Interpolation := (Site => (Initial => Origin_3D, Desired => Origin_3D), Spin => (Initial => (R => 0.0, V => [0.0, 1.0, 0.0]), Desired => (R => 0.0, V => [0.0, 1.0, 0.0])), Percent => 0.0); end safe_Interpolation; --------------- --- Sprite Item -- type Item is limited new lace.Subject_and_deferred_Observer.item with record Id : gel.sprite_Id := null_sprite_Id; Visual : openGL.Visual.view := new openGL.Visual.item; program_Parameters : openGL.program.Parameters_view; owns_Graphics : Boolean; physics_Model : physics.Model.view; owns_Physics : Boolean; World : World_view; Shape : physics_Shape_view; Solid : physics_Object_view; is_Kinematic : Boolean; Depth_in_camera_space : Real; Interpolation : safe_Interpolation; parent_Joint : gel.Joint.view; child_Joints : joint_Vectors.Vector; is_Visible : Boolean := True; key_Response : lace.Response.view; user_Data : any_user_Data_view; is_Destroyed : Boolean := False; end record; null_Sprites : constant Sprite.views (1 .. 0) := [others => null]; end gel.Sprite;
reznikmm/matreshka
Ada
3,792
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Web 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$ ------------------------------------------------------------------------------ with AWF.Internals.AWF_Layouts; package body AWF.Layouts is ------------ -- Create -- ------------ function Create return not null AWF_Layout_Access is Result : constant AWF.Internals.AWF_Layouts.AWF_Layout_Proxy_Access := new AWF.Internals.AWF_Layouts.AWF_Layout_Proxy; begin AWF.Internals.AWF_Layouts.Constructors.Initialize (Result); return AWF_Layout_Access (Result); end Create; end AWF.Layouts;
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.Db_Data_Type_Attributes is pragma Preelaborate; type ODF_Db_Data_Type_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Db_Data_Type_Attribute_Access is access all ODF_Db_Data_Type_Attribute'Class with Storage_Size => 0; end ODF.DOM.Db_Data_Type_Attributes;
reznikmm/matreshka
Ada
17,105
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Tools 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$ ------------------------------------------------------------------------------ -- -- This is simple minimal perfect hash function generator for small set of -- universal string. Driver accept JSON file with list of strings. -- Example: -- [ "OpenSession", "CloseSession", "GetBalance", "Deposit" ] -- or -- { -- "package" : "Test", -- "strings" : -- [ -- {"name" : "S1", "text" : "OpenSession"}, -- {"name" : "S2", "text" : "CloseSession"}, -- {"name" : "S3", "text" : "GetBalance"}, -- {"name" : "S4", "text" : "Deposit"} -- ] -- } with Ada.Directories; with Ada.Numerics.Discrete_Random; with Ada.Streams.Stream_IO; with Ada.Wide_Wide_Text_IO; with League.Application; with League.JSON.Documents; with League.Strings; with League.String_Vectors; with League.Text_Codecs; with League.JSON.Objects; with League.JSON.Arrays; with League.JSON.Values; procedure Perf_Driver is Min_Length : Natural := Natural'Last; subtype Position is Natural; type Position_Array is array (Positive range <>) of Position; type Index_Array is array (Positive range <>) of Natural; function "+" (Item : Wide_Wide_String) return League.Strings.Universal_String renames League.Strings.To_Universal_String; function Read_File (Name : League.Strings.Universal_String) return League.Strings.Universal_String; -- Read content of gigen file into universal string procedure Read_JSON_Object (X : League.JSON.Objects.JSON_Object; Name : in out League.Strings.Universal_String; Enum : in out League.String_Vectors.Universal_String_Vector; List : in out League.String_Vectors.Universal_String_Vector); -- Read target package name (if any), list of strings to make perfect hash -- Collect sting names into Enum if any. procedure Read_JSON_Array (X : League.JSON.Arrays.JSON_Array; Enum : in out League.String_Vectors.Universal_String_Vector; List : in out League.String_Vectors.Universal_String_Vector); -- Read list of strings to make perfect hash function Find_Distinct (V : League.String_Vectors.Universal_String_Vector; Max : Position; Pos : in out Position_Array; Use_Length : Boolean; From : Positive := 1) return Boolean; -- Find indexes Pos where all strings in V has distinct characters -- Dont go over Max characters in string. -- From is index in Pos to start working from. function Try_Hash (List : League.String_Vectors.Universal_String_Vector; A, B : Positive; Pos : Position_Array; Map : in out Index_Array) return Boolean; -- For each item in List fill Map (Index (item) := Hash (Item) -- Return True if no conflicts in Map found. -- Let Hash function be -- (A * Item (Pos(1)) + B * Item (Pos(2)) + Item.Length) mod Map'Length package Randoms is new Ada.Numerics.Discrete_Random (Positive); ------------------- -- Find_Distinct -- ------------------- function Find_Distinct (V : League.String_Vectors.Universal_String_Vector; Max : Position; Pos : in out Position_Array; Use_Length : Boolean; From : Positive := 1) return Boolean is use League.Strings; use League.String_Vectors; begin if From = Pos'First then Pos (From) := 1; else Pos (From) := Pos (From - 1) + 1; end if; if From /= Pos'Last then while Pos (From) <= Max + From - Pos'Last loop if Find_Distinct (V, Max, Pos, Use_Length, From + 1) then return True; end if; Pos (From) := Pos (From) + 1; end loop; return False; else declare T : Universal_String_Vector; E : Universal_String; S : Wide_Wide_String (Pos'Range); Len : Natural; begin for J in 1 .. V.Length loop E := V.Element (J); for K in Pos'Range loop S (K) := E.Element (Pos (K)).To_Wide_Wide_Character; end loop; Len := E.Length; E := To_Universal_String (S); if Use_Length then for X in 1 .. J - 1 loop if T.Element (X) = E and then V.Element (X).Length = Len then return False; end if; end loop; elsif T.Index (E) > 0 then return False; end if; T.Append (E); end loop; return True; end; end if; end Find_Distinct; --------------- -- Read_File -- --------------- function Read_File (Name : League.Strings.Universal_String) return League.Strings.Universal_String is File_Name : constant String := League.Text_Codecs.To_Exception_Message (Name); begin if Ada.Directories.Exists (File_Name) then declare Decoder : League.Text_Codecs.Text_Codec := League.Text_Codecs.Codec (+"utf-8"); Size : constant Ada.Directories.File_Size := Ada.Directories.Size (File_Name); Length : constant Ada.Streams.Stream_Element_Offset := Ada.Streams.Stream_Element_Count (Size); File : Ada.Streams.Stream_IO.File_Type; Data : Ada.Streams.Stream_Element_Array (1 .. Length); Last : Ada.Streams.Stream_Element_Offset; begin Ada.Streams.Stream_IO.Open (File, Ada.Streams.Stream_IO.In_File, File_Name); Ada.Streams.Stream_IO.Read (File, Data, Last); Ada.Streams.Stream_IO.Close (File); return Decoder.Decode (Data (1 .. Last)); end; else return League.Strings.Empty_Universal_String; end if; end Read_File; ---------------------- -- Read_JSON_Object -- ---------------------- procedure Read_JSON_Object (X : League.JSON.Objects.JSON_Object; Name : in out League.Strings.Universal_String; Enum : in out League.String_Vectors.Universal_String_Vector; List : in out League.String_Vectors.Universal_String_Vector) is begin Name := X.Value (+"package").To_String (Default => Name); Read_JSON_Array (X.Value (+"strings").To_Array, Enum, List); end Read_JSON_Object; --------------------- -- Read_JSON_Array -- --------------------- procedure Read_JSON_Array (X : League.JSON.Arrays.JSON_Array; Enum : in out League.String_Vectors.Universal_String_Vector; List : in out League.String_Vectors.Universal_String_Vector) is Item : League.JSON.Values.JSON_Value; Object : League.JSON.Objects.JSON_Object; begin for J in 1 .. X.Length loop Item := X.Element (J); if Item.Is_Object then Object := Item.To_Object; List.Append (Object.Value (+"text").To_String); if Object.Contains (+"name") then Enum.Append (Object.Value (+"name").To_String); end if; elsif Item.Is_String then List.Append (Item.To_String); else raise Constraint_Error; end if; end loop; end Read_JSON_Array; -------------- -- Try_Hash -- -------------- function Try_Hash (List : League.String_Vectors.Universal_String_Vector; A, B : Positive; Pos : Position_Array; Map : in out Index_Array) return Boolean is use League.Strings; use League.String_Vectors; type Unsigned is mod 2 ** 32; function Hash (S : Universal_String) return Positive; function Hash (S : Universal_String) return Positive is Result : Unsigned := Unsigned (S.Length); Char : Unsigned; begin for K in Pos'Range loop Char := Unsigned (Wide_Wide_Character'Pos (S.Element (Pos (K)).To_Wide_Wide_Character)); if K = 1 then Result := Result + Unsigned (A) * Char; else Result := Result + Unsigned (B) * Char; end if; end loop; return Natural (Result mod Map'Length) + 1; end Hash; H : Positive; begin for J in 1 .. List.Length loop H := Hash (List.Element (J)); if Map (H) = 0 then Map (H) := J; else return False; end if; end loop; return True; end Try_Hash; ------------------ -- Print_Source -- ------------------ procedure Print_Source (Name : League.Strings.Universal_String; Enum : League.String_Vectors.Universal_String_Vector; A, B : Positive; Pos : Position_Array; Map : Index_Array) is use League.Strings; use League.String_Vectors; procedure P (X : Wide_Wide_String); procedure P (X : Universal_String); procedure P (X : Integer); procedure N (X : Wide_Wide_String := ""); procedure N (X : Universal_String); Output : Universal_String; New_Line : Wide_Wide_String := (1 => Wide_Wide_Character'Val (10)); procedure P (X : Wide_Wide_String) is begin Output.Append (X); end P; procedure P (X : Universal_String) is begin Output.Append (X); end P; procedure P (X : Integer) is Image : Wide_Wide_String := Integer'Wide_Wide_Image (X); begin P (Image (2 .. Image'Last)); end P; procedure N (X : Wide_Wide_String := "") is begin P (X); P (New_Line); end N; procedure N (X : Universal_String) is begin P (X); P (New_Line); end N; begin N ("with League.Strings;"); N; P ("package "); P (Name); N (" is"); N (" function Hash (X : League.Strings.Universal_String)" & " return Natural;"); P ("end "); P (Name); N (";"); P ("package body "); P (Name); N (" is"); N (" type Unsigned is mod 2 ** 32;"); N; P (" M : array (Unsigned range 1 .. "); P (Map'Last); N (") of Natural :="); P (" ("); for J in Map'Range loop if Map (J) /= 0 then P (J); P (" => "); P (Natural (Map (J))); N (","); P (" "); end if; end loop; N ("others => 0);"); N; N (" function Hash (X : League.Strings.Universal_String)" & " return Natural is"); N (" Result : Unsigned := Unsigned (X.Length);"); N (" Char : Unsigned;"); N (" begin"); for K in Pos'Range loop N (" Char := Unsigned (Wide_Wide_Character'Pos"); P (" (X.Element ("); P (Pos (K)); N (").To_Wide_Wide_Character));"); P (" Result := Result + Unsigned ("); if K = 1 then P (A); else P (B); end if; N (") * Char;"); end loop; P (" return M ((Result mod "); P (Map'Length); N (") + 1);"); N (" end Hash;"); N; P ("end "); P (Name); N (";"); Ada.Wide_Wide_Text_IO.Put_Line (Output.To_Wide_Wide_String); end Print_Source; Arg : constant League.String_Vectors.Universal_String_Vector := League.Application.Arguments; Text : League.Strings.Universal_String; Doc : League.JSON.Documents.JSON_Document; Name : League.Strings.Universal_String := +"Perfect_Hash"; Enum : League.String_Vectors.Universal_String_Vector; List : League.String_Vectors.Universal_String_Vector; begin if Arg.Length /= 1 then Ada.Wide_Wide_Text_IO.Put_Line ("File name expected as argument"); return; end if; Text := Read_File (Arg.Element (1)); Doc := League.JSON.Documents.From_JSON (Text); if Doc.Is_Object then Read_JSON_Object (Doc.To_Object, Name, Enum, List); elsif Doc.Is_Array then Read_JSON_Array (Doc.To_Array, Enum, List); else Ada.Wide_Wide_Text_IO.Put_Line ("bad json in input file"); return; end if; -- Get min length of any string in List for J in 1 .. List.Length loop declare Item : constant League.Strings.Universal_String := List.Element (J); begin Min_Length := Natural'Min (Min_Length, Item.Length); end; end loop; -- Try to find shortest sequence of positions in string with unique chars for K in 1 .. Min_Length loop declare Random : Randoms.Generator; Pos : Position_Array (1 .. K); begin Randoms.Reset (Random); if Find_Distinct (List, Min_Length, Pos, Use_Length => True) then -- Here we found positions in string with unique chars declare A, B : Positive := Randoms.Random (Random); Map : Index_Array (1 .. List.Length * 2) := (others => 0); begin -- Try to find hash while not Try_Hash (List => List, A => A, B => B, Pos => Pos, Map => Map) loop A := Randoms.Random (Random); B := Randoms.Random (Random); Map := (others => 0); end loop; -- We found suitable A, B for out Hash and fill Map with -- corresponding indexes. Print package now Print_Source (Name, Enum, A, B, Pos, Map); exit; end; end if; end; end loop; end Perf_Driver;
rveenker/sdlada
Ada
17,405
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. -------------------------------------------------------------------------------------------------------------------- -- Pixel_Format_Test_Cases -------------------------------------------------------------------------------------------------------------------- with Ada.Unchecked_Conversion; with Ada.Strings.Fixed; use Ada.Strings.Fixed; use Ada.Strings; with Interfaces.C; with SDL.Video.Pixel_Formats; use SDL.Video.Pixel_Formats; with AUnit.Assertions; use AUnit.Assertions; with Ada.Text_Io; -- use Ada.Text_Io; package body Pixel_Format_Test_Cases is overriding function Name (Test : Pixel_Format_Test_Case) return Message_String is begin return Format ("Pixel format test"); end Name; use type C.int; function To_int is new Ada.Unchecked_Conversion (Source => Pixel_Format_Names, Target => C.int); package int_IO is new Ada.Text_IO.Integer_Io (C.int); use int_IO; function To_Binary (Num : in C.int) return String is Result : String (1 .. 100); begin Put (Result, Num, 2); return Trim (Result, Left); end To_Binary; overriding procedure Run_Test (Test : in out Pixel_Format_Test_Case) is begin declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_Unknown)); C_Value : constant String := To_Binary (C_Unknown); Error : constant String := "Pixel_Format_Unknown (" & Ada_Value & ") /= C_Index_Unknown (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_Unknown) = C_Unknown, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_Index_1_LSB)); C_Value : constant String := To_Binary (C_Index_1_LSB); Error : constant String := "Pixel_Format_Index_1_LSB (" & Ada_Value & ") /= C_Index_1_LSB (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_Index_1_LSB) = C_Index_1_LSB, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_Index_1_MSB)); C_Value : constant String := To_Binary (C_Index_1_MSB); Error : constant String := "Pixel_Format_Index_1_MSB (" & Ada_Value & ") /= C_Index_1_MSB (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_Index_1_MSB) = C_Index_1_MSB, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_Index_4_LSB)); C_Value : constant String := To_Binary (C_Index_4_LSB); Error : constant String := "Pixel_Format_Index_4_LSB (" & Ada_Value & ") /= C_Index_4_LSB (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_Index_4_LSB) = C_Index_4_LSB, Error); end; -- Put (To => Ada_Value, Item => To_int (Pixel_Format_Index_4_MSB), Base => 16); -- Put (To => C_Value, Item => C_Index_4_MSB, Base => 16); declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_Index_4_MSB)); C_Value : constant String := To_Binary (C_Index_4_MSB); Error : constant String := "Pixel_Format_Index_4_MSB (" & Ada_Value & ") /= C_Index_4_MSB (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_Index_4_MSB) = C_Index_4_MSB, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_Index_8)); C_Value : constant String := To_Binary (C_Index_8); Error : constant String := "Pixel_Format_Index_8 (" & Ada_Value & ") /= C_Index_8 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_Index_8) = C_Index_8, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_RGB_332)); C_Value : constant String := To_Binary (C_RGB_332); Error : constant String := "Pixel_Format_RGB_332 (" & Ada_Value & ") /= C_RGB_332 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_RGB_332) = C_RGB_332, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_RGB_444)); C_Value : constant String := To_Binary (C_RGB_444); Error : constant String := "Pixel_Format_RGB_444 (" & Ada_Value & ") /= C_RGB_444 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_RGB_444) = C_RGB_444, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_RGB_555)); C_Value : constant String := To_Binary (C_RGB_555); Error : constant String := "Pixel_Format_RGB_555 (" & Ada_Value & ") /= C_RGB_555 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_RGB_555) = C_RGB_555, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_BGR_555)); C_Value : constant String := To_Binary (C_BGR_555); Error : constant String := "Pixel_Format_BGR_555 (" & Ada_Value & ") /= C_BGR_555 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_BGR_555) = C_BGR_555, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_ARGB_4444)); C_Value : constant String := To_Binary (C_ARGB_4444); Error : constant String := "Pixel_Format_ARGB_4444 (" & Ada_Value & ") /= C_ARGB_4444 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_ARGB_4444) = C_ARGB_4444, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_RGBA_4444)); C_Value : constant String := To_Binary (C_RGBA_4444); Error : constant String := "Pixel_Format_RGBA_4444 (" & Ada_Value & ") /= C_RGBA_4444 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_RGBA_4444) = C_RGBA_4444, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_ABGR_4444)); C_Value : constant String := To_Binary (C_ABGR_4444); Error : constant String := "Pixel_Format_ABGR_4444 (" & Ada_Value & ") /= C_ABGR_4444 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_ABGR_4444) = C_ABGR_4444, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_BGRA_4444)); C_Value : constant String := To_Binary (C_BGRA_4444); Error : constant String := "Pixel_Format_BGRA_4444 (" & Ada_Value & ") /= C_BGRA_4444 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_BGRA_4444) = C_BGRA_4444, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_ARGB_1555)); C_Value : constant String := To_Binary (C_ARGB_1555); Error : constant String := "Pixel_Format_ARGB_1555 (" & Ada_Value & ") /= C_ARGB_1555 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_ARGB_1555) = C_ARGB_1555, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_RGBA_5551)); C_Value : constant String := To_Binary (C_RGBA_5551); Error : constant String := "Pixel_Format_RGBA_5551 (" & Ada_Value & ") /= C_RGBA_5551 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_RGBA_5551) = C_RGBA_5551, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_ABGR_1555)); C_Value : constant String := To_Binary (C_ABGR_1555); Error : constant String := "Pixel_Format_ABGR_1555 (" & Ada_Value & ") /= C_ABGR_1555 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_ABGR_1555) = C_ABGR_1555, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_BGRA_5551)); C_Value : constant String := To_Binary (C_BGRA_5551); Error : constant String := "Pixel_Format_BGRA_5551 (" & Ada_Value & ") /= C_BGRA_5551 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_BGRA_5551) = C_BGRA_5551, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_RGB_565)); C_Value : constant String := To_Binary (C_RGB_565); Error : constant String := "Pixel_Format_RGB_565 (" & Ada_Value & ") /= C_RGB_565 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_RGB_565) = C_RGB_565, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_BGR_565)); C_Value : constant String := To_Binary (C_BGR_565); Error : constant String := "Pixel_Format_BGR_565 (" & Ada_Value & ") /= C_BGR_565 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_BGR_565) = C_BGR_565, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_RGB_24)); C_Value : constant String := To_Binary (C_RGB_24); Error : constant String := "Pixel_Format_RGB_24 (" & Ada_Value & ") /= C_RGB_24 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_RGB_24) = C_RGB_24, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_BGR_24)); C_Value : constant String := To_Binary (C_BGR_24); Error : constant String := "Pixel_Format_BGR_24 (" & Ada_Value & ") /= C_BGR_24 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_BGR_24) = C_BGR_24, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_RGB_888)); C_Value : constant String := To_Binary (C_RGB_888); Error : constant String := "Pixel_Format_RGB_888 (" & Ada_Value & ") /= C_RGB_888 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_RGB_888) = C_RGB_888, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_RGBX_8888)); C_Value : constant String := To_Binary (C_RGBX_8888); Error : constant String := "Pixel_Format_RGBX_8888 (" & Ada_Value & ") /= C_RGBX_8888 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_RGBX_8888) = C_RGBX_8888, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_BGR_888)); C_Value : constant String := To_Binary (C_BGR_888); Error : constant String := "Pixel_Format_BGR_888 (" & Ada_Value & ") /= C_BGR_888 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_BGR_888) = C_BGR_888, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_BGRX_8888)); C_Value : constant String := To_Binary (C_BGRX_8888); Error : constant String := "Pixel_Format_BGRX_8888 (" & Ada_Value & ") /= C_BGRX_8888 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_BGRX_8888) = C_BGRX_8888, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_ARGB_8888)); C_Value : constant String := To_Binary (C_ARGB_8888); Error : constant String := "Pixel_Format_ARGB_8888 (" & Ada_Value & ") /= C_ARGB_8888 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_ARGB_8888) /= C_ARGB_8888, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_RGBA_8888)); C_Value : constant String := To_Binary (C_RGBA_8888); Error : constant String := "Pixel_Format_RGBA_8888 (" & Ada_Value & ") /= C_RGBA_8888 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_RGBA_8888) = C_RGBA_8888, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_ABGR_8888)); C_Value : constant String := To_Binary (C_ABGR_8888); Error : constant String := "Pixel_Format_ABGR_8888 (" & Ada_Value & ") /= C_ABGR_8888 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_ABGR_8888) = C_ABGR_8888, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_BGRA_8888)); C_Value : constant String := To_Binary (C_BGRA_8888); Error : constant String := "Pixel_Format_BGRA_8888 (" & Ada_Value & ") /= C_BGRA_8888 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_BGRA_8888) = C_BGRA_8888, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_ARGB_2101010)); C_Value : constant String := To_Binary (C_ARGB_2101010); Error : constant String := "Pixel_Format_ARGB_2101010 (" & Ada_Value & ") /= C_ARGB_2101010 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_ARGB_2101010) = C_ARGB_2101010, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_YV_12)); C_Value : constant String := To_Binary (C_YV_12); Error : constant String := "Pixel_Format_YV_12 (" & Ada_Value & ") /= C_YV_12 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_YV_12) = C_YV_12, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_IYUV)); C_Value : constant String := To_Binary (C_IYUV); Error : constant String := "Pixel_Format_IYUV (" & Ada_Value & ") /= C_IYUV (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_IYUV) = C_IYUV, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_YUY_2)); C_Value : constant String := To_Binary (C_YUY_2); Error : constant String := "Pixel_Format_YUY_2 (" & Ada_Value & ") /= C_YUY_2 (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_YUY_2) = C_YUY_2, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_UYVY)); C_Value : constant String := To_Binary (C_UYVY); Error : constant String := "Pixel_Format_UYVY (" & Ada_Value & ") /= C_UYVY (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_UYVY) = C_UYVY, Error); end; declare Ada_Value : constant String := To_Binary (To_int (Pixel_Format_YVYU)); C_Value : constant String := To_Binary (C_YVYU); Error : constant String := "Pixel_Format_YVYU (" & Ada_Value & ") /= C_YVYU (" & C_Value & ")"; begin -- Put_Line (Error); Assert (To_int (Pixel_Format_YVYU) = C_YVYU, Error); end; end Run_Test; end Pixel_Format_Test_Cases;
cborao/Ada-P2
Ada
4,875
adb
--PRÁCTICA 2: César Borao Moratinos (chat_server) with Ada.Text_IO; with Chat_Messages; with Lower_Layer_UDP; with Ada.Command_Line; with Client_Collections; with Ada.Strings.Unbounded; procedure Chat_Server is package ATI renames Ada.Text_IO; package CM renames Chat_Messages; package LLU renames Lower_Layer_UDP; package ACL renames Ada.Command_Line; package CC renames Client_Collections; package ASU renames Ada.Strings.Unbounded; use type CM.Message_Type; Server_EP: LLU.End_Point_Type; EP: LLU.End_Point_Type; Expired: Boolean; Port: Integer; Buffer_In: aliased LLU.Buffer_Type(1024); Buffer_Out: aliased LLU.Buffer_Type(1024); Collection_W: CC.Collection_Type; Collection_R: CC.Collection_Type; Unique: Boolean; Mess: CM.Message_Type; Nick: ASU.Unbounded_String; Comment: ASU.Unbounded_String; Nick_Server: ASU.Unbounded_String; Password: ASU.Unbounded_String; Data: ASU.Unbounded_String; Admin_EP: LLU.End_Point_Type; Admin_Pass: ASU.Unbounded_String; Shutdown: Boolean; begin -- Asignación y bindeado del Servidor Port := Integer'Value(ACL.Argument(1)); Password := ASU.To_Unbounded_String(ACL.Argument(2)); Server_EP := LLU.Build (LLU.To_IP(LLU.Get_Host_Name), Port); LLU.Bind (Server_EP); Shutdown := False; loop LLU.Reset (Buffer_In); LLU.Reset (Buffer_Out); LLU.Receive (Server_EP, Buffer_In'Access, 1000.0, Expired); if Expired then ATI.Put_Line ("Please, try again"); else Mess := CM.Message_Type'Input (Buffer_In'Access); if Mess = CM.Init then EP := LLU.End_Point_Type'Input (Buffer_In'Access); Nick := ASU.Unbounded_String'Input (Buffer_In'Access); ATI.Put("INIT received from " & ASU.To_String(Nick)); if ASU.To_String (Nick) = "reader" then Unique := False; CC.Add_Client (Collection_R, EP, Nick, Unique); else Unique := True; begin CC.Add_Client (Collection_W, EP, Nick, Unique); --Aviso de entrada al servidor Mess := CM.Server; CM.Message_Type'Output(Buffer_Out'Access, Mess); Nick_Server := ASU.To_Unbounded_String("server"); ASU.Unbounded_String'Output(Buffer_Out'Access, Nick_Server); Comment := ASU.To_Unbounded_String(ASU.To_String(Nick) & " joins the chat"); ASU.Unbounded_String'Output(Buffer_Out'Access, Comment); CC.Send_To_All (Collection_R, Buffer_Out'Access); exception when CC.Client_Collection_Error => ATI.Put (". IGNORED, nick already used"); end; end if; ATI.New_Line; LLU.Reset(Buffer_In); LLU.Reset(Buffer_Out); elsif Mess = CM.Writer then begin EP := LLU.End_Point_Type'Input (Buffer_In'Access); Comment := ASU.Unbounded_String'Input (Buffer_In'Access); Nick := CC.Search_Client (Collection_W, EP); --reenvío del mensaje a los readers Mess := CM.Server; CM.Message_Type'Output(Buffer_Out'Access, Mess); ASU.Unbounded_String'Output(Buffer_Out'Access, Nick); ASU.Unbounded_String'Output(Buffer_Out'Access, Comment); CC.Send_To_All (Collection_R, Buffer_Out'Access); Ada.Text_IO.Put_Line ("WRITER received from " & ASU.To_String (Nick) & ": " & ASU.To_String(Comment)); LLU.Reset(Buffer_In); LLU.Reset(Buffer_Out); exception when CC.Client_Collection_Error => ATI.Put_Line ("WRITER received from unknown client. IGNORED"); end; elsif Mess = CM.Collection_Request then ATI.Put_Line("LIST_REQUEST received"); Admin_EP := LLU.End_Point_Type'Input (Buffer_In'Access); Admin_Pass := ASU.Unbounded_String'Input (Buffer_In'Access); if ASU.To_String(Admin_Pass) = ASU.To_String(Password) then --Enviamos respuesta Mess := CM.Collection_Data; Data := ASU.To_Unbounded_String(CC.Collection_Image(Collection_W)); CM.Message_Type'Output (Buffer_Out'Access, Mess); ASU.Unbounded_String'Output (Buffer_Out'Access, Data); LLU.Send(Admin_EP, Buffer_Out'Access); LLU.Reset(Buffer_In); LLU.Reset(Buffer_Out); end if; elsif Mess = CM.Ban then begin Admin_Pass := ASU.Unbounded_String'Input (Buffer_In'Access); Nick := ASU.Unbounded_String'Input (Buffer_In'Access); ATI.Put_Line("BAN received for " & ASU.To_String(Nick)); if ASU.To_String(Admin_Pass) = ASU.To_String(Password) then CC.Delete_Client (Collection_W, Nick); end if; exception when CC.Client_Collection_Error => ATI.Put_Line ("BAN received for " & ASU.To_String(Nick) & ". IGNORED, nick not found"); end; elsif Mess = CM.Shutdown then ATI.Put_Line("SHUTDOWN received"); Admin_Pass := ASU.Unbounded_String'Input (Buffer_In'Access); if ASU.To_String(Admin_Pass) = ASU.To_String(Password) then Shutdown := True; end if; end if; end if; exit when Shutdown; end loop; LLU.Finalize; end Chat_Server;
reznikmm/matreshka
Ada
3,577
adb
------------------------------------------------------------------------------ -- -- -- 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$ ------------------------------------------------------------------------------ separate (AMF.Internals.Factories.DC_Factories) function Convert_String_To_String (Value : League.Holders.Holder) return League.Strings.Universal_String is begin return League.Holders.Element (Value); end Convert_String_To_String;
AdaCore/langkit
Ada
6,926
adb
with Ada.Text_IO; use Ada.Text_IO; with Langkit_Support.Generic_API.Introspection; use Langkit_Support.Generic_API.Introspection; with Langkit_Support.Text; use Langkit_Support.Text; with Libfoolang.Analysis; use Libfoolang.Analysis; with Libfoolang.Common; use Libfoolang.Common; with Libfoolang.Generic_API.Introspection; use Libfoolang.Generic_API.Introspection; with Libfoolang.Rewriting; use Libfoolang.Rewriting; with Process_Apply; procedure Rewrite is Buffer : constant String := ("def a = 1" & ASCII.LF & "def b = (2 + a) + 3" & ASCII.LF & "def c = a + b" & ASCII.LF & "def d = 4" & ASCII.LF & "def e = 5" & ASCII.LF); procedure Try (Label : String; Proc : access procedure); function Create_Def (Name : Text_Type; Expr : Node_Rewriting_Handle) return Node_Rewriting_Handle; procedure Check_Diagnostics (U : Analysis_Unit); --------- -- Try -- --------- procedure Try (Label : String; Proc : access procedure) is begin Put_Line (Label & "..."); Proc.all; Put_Line (" Done with no precondition failure"); exception when Libfoolang.Common.Precondition_Failure => Put_Line (" Got a precondition failure"); end Try; ----------------------- -- Check_Diagnostics -- ----------------------- procedure Check_Diagnostics (U : Analysis_Unit) is begin if Has_Diagnostics (U) then Put_Line ("Errors in " & Get_Filename (U) & ":"); for D of Diagnostics (U) loop Put_Line (Format_GNU_Diagnostic (U, D)); end loop; return; end if; end Check_Diagnostics; Ctx : constant Analysis_Context := Create_Context; U1 : constant Analysis_Unit := Get_From_Buffer (Ctx, "u1.txt", Buffer => Buffer); U2 : constant Analysis_Unit := Get_From_Buffer (Ctx, "u2.txt", Buffer => "def z = 100"); RH : Rewriting_Handle; N : Node_Rewriting_Handle; ---------------- -- Create_Def -- ---------------- function Create_Def (Name : Text_Type; Expr : Node_Rewriting_Handle) return Node_Rewriting_Handle is Name_Node : constant Node_Rewriting_Handle := Create_Token_Node (RH, Foo_Name, Name); begin return Create_Def (RH, Name_Node, No_Node_Rewriting_Handle, Expr); end Create_Def; begin Check_Diagnostics (U1); Check_Diagnostics (U2); RH := Start_Rewriting (Ctx); N := Handle (Root (U1)); Put ("Node type for the root: "); Put_Line (Debug_Name (Type_Of (N))); declare procedure Set_Tied_Child; procedure Create_Error_Node; procedure Create_Regular_Error_Node; ---------- -- Proc -- ---------- procedure Set_Tied_Child is begin Set_Child (N, 2, Child (N, 3)); end Set_Tied_Child; ----------------------- -- Create_Error_Node -- ----------------------- procedure Create_Error_Node is begin N := Create_Node (RH, Foo_Error_Def); end Create_Error_Node; ------------------------------- -- Create_Regular_Error_Node -- ------------------------------- procedure Create_Regular_Error_Node is begin N := Create_Regular_Node (RH, Foo_Error_Def, (1 .. 0 => <>)); end Create_Regular_Error_Node; begin Try ("Try assigning a child that is already tied to a tree", Set_Tied_Child'Access); Try ("Try creating an error node (Create_Node)", Create_Error_Node'Access); Try ("Try creating an error node (Create_Regular_Node)", Create_Regular_Error_Node'Access); New_Line; Put_Line ("Replace the middle definition (b) with a clone of the last" & " definition (c)"); Set_Child (N, 2, Clone (Child (N, 3))); end; New_Line; Put_Line ("Creating a tree from a template:"); declare N : constant Node_Rewriting_Handle := Create_From_Template (Handle => RH, Template => "def foo = 1 + 2", Arguments => (1 .. 0 => <>), Rule => Def_Rule_Rule); function Img (N : Node_Rewriting_Handle) return String is (Image (Unparse (N))); begin Put_Line (" Tree: " & Img (N)); Put_Line (" F_Name child: " & Img (Child (N, Member_Refs.Def_F_Name))); Put_Line (" F_Expr/F_LHS child: " & Img (Child (N, (Member_Refs.Def_F_Expr, Member_Refs.Plus_F_Lhs)))); end; New_Line; Put_Line ("Swap first and fourth defs"); declare N1 : constant Node_Rewriting_Handle := Child (N, 1); N4 : constant Node_Rewriting_Handle := Child (N, 4); begin if not Tied (N1) then raise Program_Error; end if; if not Tied (N4) then raise Program_Error; end if; Set_Child (N, 1, No_Node_Rewriting_Handle); Set_Child (N, 4, No_Node_Rewriting_Handle); if Tied (N1) then raise Program_Error; end if; if Tied (N4) then raise Program_Error; end if; Set_Child (N, 1, N4); Set_Child (N, 4, N1); if not Tied (N1) then raise Program_Error; end if; if not Tied (N4) then raise Program_Error; end if; end; New_Line; Put_Line ("Replace the expression of the fifth definition"); declare Nested_Expr : constant Node_Rewriting_Handle := Create_Paren_Expr (RH, Create_Plus (RH, Create_Token_Node (RH, Foo_Literal, "5"), Create_Ref (RH, Create_Token_Node (RH, Foo_Name, "c")))); Top_Expr : constant Node_Rewriting_Handle := Create_Paren_Expr (RH, Create_Plus (RH, Create_Ref (RH, Create_Token_Node (RH, Foo_Name, "d")), Nested_Expr)); Fifth_Child : constant Node_Rewriting_Handle := Child (N, 5); begin Set_Child (Fifth_Child, Member_Refs.Def_F_Expr, Top_Expr); end; New_Line; Put_Line ("Replace the root of unit 2"); declare New_Root : constant Node_Rewriting_Handle := Create_Node (RH, Foo_Foo_Node_List); Expr_1 : constant Node_Rewriting_Handle := Create_Token_Node (RH, Foo_Literal, "111"); Expr_2 : constant Node_Rewriting_Handle := Create_Token_Node (RH, Foo_Literal, "222"); begin Append_Child (New_Root, Create_Def ("zz", Expr_1)); Append_Child (New_Root, Create_Def ("yy", Expr_2)); Replace (Expr_2, Create_Token_Node (RH, Foo_Literal, "333")); Replace (Handle (Root (U2)), New_Root); end; New_Line; Put_Line ("Applying the diff..."); Process_Apply (RH); New_Line; Put_Line ("u1.txt:"); Root (U1).Print (Show_Slocs => False); New_Line; Put_Line ("u2.txt:"); Root (U2).Print (Show_Slocs => False); Put_Line ("rewrite.adb: Done."); end Rewrite;
alvaromb/Compilemon
Ada
29,768
adb
-- Copyright (c) 1990 Regents of the University of California. -- All rights reserved. -- -- This software was developed by John Self of the Arcadia project -- at the University of California, Irvine. -- -- Redistribution and use in source and binary forms are permitted -- provided that the above copyright notice and this paragraph are -- duplicated in all such forms and that any documentation, -- advertising materials, and other materials related to such -- distribution and use acknowledge that the software was developed -- by the University of California, Irvine. The name of the -- University may not be used to endorse or promote products derived -- from this software without specific prior written permission. -- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR -- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED -- WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. -- TITLE DFA construction routines -- AUTHOR: John Self (UCI) -- DESCRIPTION converts non-deterministic finite automatons to finite ones. -- $Header: /dc/uc/self/tmp/gnat_aflex/RCS/dfa.adb,v 1.1 1995/07/04 20:18:39 self Exp self $ with dfa, int_io, misc_defs, text_io, misc, tblcmp, ccl, external_file_manager; with ecs, nfa, tstring, gen, skeleton_manager; use misc_defs, external_file_manager; package body dfa is use TSTRING; -- check_for_backtracking - check a DFA state for backtracking -- -- ds is the number of the state to check and state[) is its out-transitions, -- indexed by equivalence class, and state_rules[) is the set of rules -- associated with this state DID_STK_INIT : BOOLEAN := FALSE; STK : INT_PTR; procedure CHECK_FOR_BACKTRACKING(DS : in INTEGER; STATE : in UNBOUNDED_INT_ARRAY) is use MISC_DEFS; begin if (DFAACC(DS).DFAACC_STATE = 0) then -- state is non-accepting NUM_BACKTRACKING := NUM_BACKTRACKING + 1; if (BACKTRACK_REPORT) then TEXT_IO.PUT(BACKTRACK_FILE, "State #"); INT_IO.PUT(BACKTRACK_FILE, DS, 1); TEXT_IO.PUT(BACKTRACK_FILE, "is non-accepting -"); TEXT_IO.NEW_LINE(BACKTRACK_FILE); -- identify the state DUMP_ASSOCIATED_RULES(BACKTRACK_FILE, DS); -- now identify it further using the out- and jam-transitions DUMP_TRANSITIONS(BACKTRACK_FILE, STATE); TEXT_IO.NEW_LINE(BACKTRACK_FILE); end if; end if; end CHECK_FOR_BACKTRACKING; -- check_trailing_context - check to see if NFA state set constitutes -- "dangerous" trailing context -- -- NOTES -- Trailing context is "dangerous" if both the head and the trailing -- part are of variable size \and/ there's a DFA state which contains -- both an accepting state for the head part of the rule and NFA states -- which occur after the beginning of the trailing context. -- When such a rule is matched, it's impossible to tell if having been -- in the DFA state indicates the beginning of the trailing context -- or further-along scanning of the pattern. In these cases, a warning -- message is issued. -- -- nfa_states[1 .. num_states) is the list of NFA states in the DFA. -- accset[1 .. nacc) is the list of accepting numbers for the DFA state. procedure CHECK_TRAILING_CONTEXT(NFA_STATES : in INT_PTR; NUM_STATES : in INTEGER; ACCSET : in INT_PTR; NACC : in INTEGER) is NS, AR : INTEGER; STATE_VAR, TYPE_VAR : STATE_ENUM; use MISC_DEFS, MISC, TEXT_IO; begin for I in 1 .. NUM_STATES loop NS := NFA_STATES(I); TYPE_VAR := STATE_TYPE(NS); AR := ASSOC_RULE(NS); if ((TYPE_VAR = STATE_NORMAL) or (RULE_TYPE(AR) /= RULE_VARIABLE)) then null; -- do nothing else if (TYPE_VAR = STATE_TRAILING_CONTEXT) then -- potential trouble. Scan set of accepting numbers for -- the one marking the end of the "head". We assume that -- this looping will be fairly cheap since it's rare that -- an accepting number set is large. for J in 1 .. NACC loop if (CHECK_YY_TRAILING_HEAD_MASK(ACCSET(J)) /= 0) then TEXT_IO.PUT(STANDARD_ERROR, "aflex: Dangerous trailing context in rule at line "); INT_IO.PUT(STANDARD_ERROR, RULE_LINENUM(AR), 1); TEXT_IO.NEW_LINE(STANDARD_ERROR); return; end if; end loop; end if; end if; end loop; end CHECK_TRAILING_CONTEXT; -- dump_associated_rules - list the rules associated with a DFA state -- -- goes through the set of NFA states associated with the DFA and -- extracts the first MAX_ASSOC_RULES unique rules, sorts them, -- and writes a report to the given file procedure DUMP_ASSOCIATED_RULES(F : in FILE_TYPE; DS : in INTEGER) is J : INTEGER; NUM_ASSOCIATED_RULES : INTEGER := 0; RULE_SET : INT_PTR; SIZE, RULE_NUM : INTEGER; begin RULE_SET := new UNBOUNDED_INT_ARRAY(0 .. MAX_ASSOC_RULES + 1); SIZE := DFASIZ(DS); for I in 1 .. SIZE loop RULE_NUM := RULE_LINENUM(ASSOC_RULE(DSS(DS)(I))); J := 1; while (J <= NUM_ASSOCIATED_RULES) loop if (RULE_NUM = RULE_SET(J)) then exit; end if; J := J + 1; end loop; if (J > NUM_ASSOCIATED_RULES) then --new rule if (NUM_ASSOCIATED_RULES < MAX_ASSOC_RULES) then NUM_ASSOCIATED_RULES := NUM_ASSOCIATED_RULES + 1; RULE_SET(NUM_ASSOCIATED_RULES) := RULE_NUM; end if; end if; end loop; MISC.BUBBLE(RULE_SET, NUM_ASSOCIATED_RULES); TEXT_IO.PUT(F, " associated rules:"); for I in 1 .. NUM_ASSOCIATED_RULES loop if (I mod 8 = 1) then TEXT_IO.NEW_LINE(F); end if; TEXT_IO.PUT(F, ASCII.HT); INT_IO.PUT(F, RULE_SET(I), 1); end loop; TEXT_IO.NEW_LINE(F); exception when STORAGE_ERROR => MISC.AFLEXFATAL("dynamic memory failure in dump_associated_rules()"); end DUMP_ASSOCIATED_RULES; -- dump_transitions - list the transitions associated with a DFA state -- -- goes through the set of out-transitions and lists them in human-readable -- form (i.e., not as equivalence classes); also lists jam transitions -- (i.e., all those which are not out-transitions, plus EOF). The dump -- is done to the given file. procedure DUMP_TRANSITIONS(F : in FILE_TYPE; STATE : in UNBOUNDED_INT_ARRAY) is EC : INTEGER; OUT_CHAR_SET : C_SIZE_BOOL_ARRAY; begin for I in 1 .. CSIZE loop EC := ECGROUP(I); if (EC < 0) then EC := -EC; end if; OUT_CHAR_SET(I) := (STATE(EC) /= 0); end loop; TEXT_IO.PUT(F, " out-transitions: "); CCL.LIST_CHARACTER_SET(F, OUT_CHAR_SET); -- now invert the members of the set to get the jam transitions for I in 1 .. CSIZE loop OUT_CHAR_SET(I) := not OUT_CHAR_SET(I); end loop; TEXT_IO.NEW_LINE(F); TEXT_IO.PUT(F, "jam-transitions: EOF "); CCL.LIST_CHARACTER_SET(F, OUT_CHAR_SET); TEXT_IO.NEW_LINE(F); end DUMP_TRANSITIONS; -- epsclosure - construct the epsilon closure of a set of ndfa states -- -- NOTES -- the epsilon closure is the set of all states reachable by an arbitrary -- number of epsilon transitions which themselves do not have epsilon -- transitions going out, unioned with the set of states which have non-null -- accepting numbers. t is an array of size numstates of nfa state numbers. -- Upon return, t holds the epsilon closure and numstates is updated. accset -- holds a list of the accepting numbers, and the size of accset is given -- by nacc. t may be subjected to reallocation if it is not large enough -- to hold the epsilon closure. -- -- hashval is the hash value for the dfa corresponding to the state set procedure EPSCLOSURE(T : in out INT_PTR; NS_ADDR : in out INTEGER; ACCSET : in out INT_PTR; NACC_ADDR, HV_ADDR : out INTEGER; RESULT : out INT_PTR) is NS, TSP : INTEGER; NUMSTATES, NACC, HASHVAL, TRANSSYM, NFACCNUM : INTEGER; STKEND : INTEGER; STKPOS : INTEGER; procedure MARK_STATE(STATE : in INTEGER) is begin TRANS1(STATE) := TRANS1(STATE) - MARKER_DIFFERENCE; end MARK_STATE; pragma INLINE(MARK_STATE); function IS_MARKED(STATE : in INTEGER) return BOOLEAN is begin return TRANS1(STATE) < 0; end IS_MARKED; pragma INLINE(IS_MARKED); procedure UNMARK_STATE(STATE : in INTEGER) is begin TRANS1(STATE) := TRANS1(STATE) + MARKER_DIFFERENCE; end UNMARK_STATE; pragma INLINE(UNMARK_STATE); procedure CHECK_ACCEPT(STATE : in INTEGER) is begin NFACCNUM := ACCPTNUM(STATE); if (NFACCNUM /= NIL) then NACC := NACC + 1; ACCSET(NACC) := NFACCNUM; end if; end CHECK_ACCEPT; pragma INLINE(CHECK_ACCEPT); procedure DO_REALLOCATION is begin CURRENT_MAX_DFA_SIZE := CURRENT_MAX_DFA_SIZE + MAX_DFA_SIZE_INCREMENT; NUM_REALLOCS := NUM_REALLOCS + 1; REALLOCATE_INTEGER_ARRAY(T, CURRENT_MAX_DFA_SIZE); REALLOCATE_INTEGER_ARRAY(STK, CURRENT_MAX_DFA_SIZE); end DO_REALLOCATION; pragma INLINE(DO_REALLOCATION); procedure PUT_ON_STACK(STATE : in INTEGER) is begin STKEND := STKEND + 1; if (STKEND >= CURRENT_MAX_DFA_SIZE) then DO_REALLOCATION; end if; STK(STKEND) := STATE; MARK_STATE(STATE); end PUT_ON_STACK; pragma INLINE(PUT_ON_STACK); procedure ADD_STATE(STATE : in INTEGER) is begin NUMSTATES := NUMSTATES + 1; if (NUMSTATES >= CURRENT_MAX_DFA_SIZE) then DO_REALLOCATION; end if; T(NUMSTATES) := STATE; HASHVAL := HASHVAL + STATE; end ADD_STATE; pragma INLINE(ADD_STATE); procedure STACK_STATE(STATE : in INTEGER) is begin PUT_ON_STACK(STATE); CHECK_ACCEPT(STATE); if ((NFACCNUM /= NIL) or (TRANSCHAR(STATE) /= SYM_EPSILON)) then ADD_STATE(STATE); end if; end STACK_STATE; pragma INLINE(STACK_STATE); begin NUMSTATES := NS_ADDR; if (not DID_STK_INIT) then STK := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_DFA_SIZE); DID_STK_INIT := TRUE; end if; NACC := 0; STKEND := 0; HASHVAL := 0; for NSTATE in 1 .. NUMSTATES loop NS := T(NSTATE); -- the state could be marked if we've already pushed it onto -- the stack if (not IS_MARKED(NS)) then PUT_ON_STACK(NS); null; end if; CHECK_ACCEPT(NS); HASHVAL := HASHVAL + NS; end loop; STKPOS := 1; while (STKPOS <= STKEND) loop NS := STK(STKPOS); TRANSSYM := TRANSCHAR(NS); if (TRANSSYM = SYM_EPSILON) then TSP := TRANS1(NS) + MARKER_DIFFERENCE; if (TSP /= NO_TRANSITION) then if (not IS_MARKED(TSP)) then STACK_STATE(TSP); end if; TSP := TRANS2(NS); if (TSP /= NO_TRANSITION) then if (not IS_MARKED(TSP)) then STACK_STATE(TSP); end if; end if; end if; end if; STKPOS := STKPOS + 1; end loop; -- clear out "visit" markers for CHK_STKPOS in 1 .. STKEND loop if (IS_MARKED(STK(CHK_STKPOS))) then UNMARK_STATE(STK(CHK_STKPOS)); else MISC.AFLEXFATAL("consistency check failed in epsclosure()"); end if; end loop; NS_ADDR := NUMSTATES; HV_ADDR := HASHVAL; NACC_ADDR := NACC; RESULT := T; end EPSCLOSURE; -- increase_max_dfas - increase the maximum number of DFAs procedure INCREASE_MAX_DFAS is begin CURRENT_MAX_DFAS := CURRENT_MAX_DFAS + MAX_DFAS_INCREMENT; NUM_REALLOCS := NUM_REALLOCS + 1; REALLOCATE_INTEGER_ARRAY(BASE, CURRENT_MAX_DFAS); REALLOCATE_INTEGER_ARRAY(DEF, CURRENT_MAX_DFAS); REALLOCATE_INTEGER_ARRAY(DFASIZ, CURRENT_MAX_DFAS); REALLOCATE_INTEGER_ARRAY(ACCSIZ, CURRENT_MAX_DFAS); REALLOCATE_INTEGER_ARRAY(DHASH, CURRENT_MAX_DFAS); REALLOCATE_INT_PTR_ARRAY(DSS, CURRENT_MAX_DFAS); REALLOCATE_DFAACC_UNION(DFAACC, CURRENT_MAX_DFAS); end INCREASE_MAX_DFAS; -- ntod - convert an ndfa to a dfa -- -- creates the dfa corresponding to the ndfa we've constructed. the -- dfa starts out in state #1. procedure NTOD is ACCSET : INT_PTR; DS, NACC, NEWDS : INTEGER; DUPLIST, TARGFREQ, TARGSTATE, STATE : C_SIZE_ARRAY; SYMLIST : C_SIZE_BOOL_ARRAY; HASHVAL, NUMSTATES, DSIZE : INTEGER; NSET, DSET : INT_PTR; TARGPTR, TOTALTRANS, I, J, COMSTATE, COMFREQ, TARG : INTEGER; NUM_START_STATES, TODO_HEAD, TODO_NEXT : INTEGER; SNSRESULT : BOOLEAN; FULL_TABLE_TEMP_FILE : FILE_TYPE; BUF : VSTRING; NUM_NXT_STATES : INTEGER; use TEXT_IO; -- this is so find_table_space(...) will know where to start looking in -- chk/nxt for unused records for space to put in the state begin ACCSET := ALLOCATE_INTEGER_ARRAY(NUM_RULES + 1); NSET := ALLOCATE_INTEGER_ARRAY(CURRENT_MAX_DFA_SIZE); -- the "todo" queue is represented by the head, which is the DFA -- state currently being processed, and the "next", which is the -- next DFA state number available (not in use). We depend on the -- fact that snstods() returns DFA's \in increasing order/, and thus -- need only know the bounds of the dfas to be processed. TODO_HEAD := 0; TODO_NEXT := 0; for CNT in 0 .. CSIZE loop DUPLIST(CNT) := NIL; SYMLIST(CNT) := FALSE; end loop; for CNT in 0 .. NUM_RULES loop ACCSET(CNT) := NIL; end loop; if (TRACE) then NFA.DUMPNFA(SCSET(1)); TEXT_IO.NEW_LINE(STANDARD_ERROR); TEXT_IO.NEW_LINE(STANDARD_ERROR); TEXT_IO.PUT(STANDARD_ERROR, "DFA Dump:"); TEXT_IO.NEW_LINE(STANDARD_ERROR); TEXT_IO.NEW_LINE(STANDARD_ERROR); end if; TBLCMP.INITTBL; if (FULLTBL) then GEN.DO_SECT3_OUT; -- output user code up to ## SKELETON_MANAGER.SKELOUT; -- declare it "short" because it's a real long-shot that that -- won't be large enough begin -- make a temporary file to write yy_nxt array into CREATE(FULL_TABLE_TEMP_FILE, OUT_FILE); exception when USE_ERROR | NAME_ERROR => MISC.AFLEXFATAL("can't create temporary file"); end; NUM_NXT_STATES := 1; TEXT_IO.PUT(FULL_TABLE_TEMP_FILE, "( "); -- generate 0 entries for state #0 for CNT in 0 .. NUMECS loop MISC.MK2DATA(FULL_TABLE_TEMP_FILE, 0); end loop; TEXT_IO.PUT(FULL_TABLE_TEMP_FILE, " )"); -- force extra blank line next dataflush() DATALINE := NUMDATALINES; end if; -- create the first states NUM_START_STATES := LASTSC*2; for CNT in 1 .. NUM_START_STATES loop NUMSTATES := 1; -- for each start condition, make one state for the case when -- we're at the beginning of the line (the '%' operator) and -- one for the case when we're not if (CNT mod 2 = 1) then NSET(NUMSTATES) := SCSET((CNT/2) + 1); else NSET(NUMSTATES) := NFA.MKBRANCH(SCBOL(CNT/2), SCSET(CNT/2)); end if; DFA.EPSCLOSURE(NSET, NUMSTATES, ACCSET, NACC, HASHVAL, NSET); SNSTODS(NSET, NUMSTATES, ACCSET, NACC, HASHVAL, DS, SNSRESULT); if (SNSRESULT) then NUMAS := NUMAS + NACC; TOTNST := TOTNST + NUMSTATES; TODO_NEXT := TODO_NEXT + 1; if (VARIABLE_TRAILING_CONTEXT_RULES and (NACC > 0)) then CHECK_TRAILING_CONTEXT(NSET, NUMSTATES, ACCSET, NACC); end if; end if; end loop; SNSTODS(NSET, 0, ACCSET, 0, 0, END_OF_BUFFER_STATE, SNSRESULT); if (not SNSRESULT) then MISC.AFLEXFATAL("could not create unique end-of-buffer state"); end if; NUMAS := NUMAS + 1; NUM_START_STATES := NUM_START_STATES + 1; TODO_NEXT := TODO_NEXT + 1; while (TODO_HEAD < TODO_NEXT) loop NUM_NXT_STATES := NUM_NXT_STATES + 1; TARGPTR := 0; TOTALTRANS := 0; for STATE_CNT in 1 .. NUMECS loop STATE(STATE_CNT) := 0; end loop; TODO_HEAD := TODO_HEAD + 1; DS := TODO_HEAD; DSET := DSS(DS); DSIZE := DFASIZ(DS); if (TRACE) then TEXT_IO.PUT(STANDARD_ERROR, "state # "); INT_IO.PUT(STANDARD_ERROR, DS, 1); TEXT_IO.PUT_LINE(STANDARD_ERROR, ":"); end if; SYMPARTITION(DSET, DSIZE, SYMLIST, DUPLIST); for SYM in 1 .. NUMECS loop if (SYMLIST(SYM)) then SYMLIST(SYM) := FALSE; if (DUPLIST(SYM) = NIL) then -- symbol has unique out-transitions NUMSTATES := SYMFOLLOWSET(DSET, DSIZE, SYM, NSET); DFA.EPSCLOSURE(NSET, NUMSTATES, ACCSET, NACC, HASHVAL, NSET); SNSTODS(NSET, NUMSTATES, ACCSET, NACC, HASHVAL, NEWDS, SNSRESULT); if (SNSRESULT) then TOTNST := TOTNST + NUMSTATES; TODO_NEXT := TODO_NEXT + 1; NUMAS := NUMAS + NACC; if (VARIABLE_TRAILING_CONTEXT_RULES and (NACC > 0)) then CHECK_TRAILING_CONTEXT(NSET, NUMSTATES, ACCSET, NACC); end if; end if; STATE(SYM) := NEWDS; if (TRACE) then TEXT_IO.PUT(STANDARD_ERROR, ASCII.HT); INT_IO.PUT(STANDARD_ERROR, SYM, 1); TEXT_IO.PUT(STANDARD_ERROR, ASCII.HT); INT_IO.PUT(STANDARD_ERROR, NEWDS, 1); TEXT_IO.NEW_LINE(STANDARD_ERROR); end if; TARGPTR := TARGPTR + 1; TARGFREQ(TARGPTR) := 1; TARGSTATE(TARGPTR) := NEWDS; NUMUNIQ := NUMUNIQ + 1; else -- sym's equivalence class has the same transitions -- as duplist(sym)'s equivalence class TARG := STATE(DUPLIST(SYM)); STATE(SYM) := TARG; if (TRACE) then TEXT_IO.PUT(STANDARD_ERROR, ASCII.HT); INT_IO.PUT(STANDARD_ERROR, SYM, 1); TEXT_IO.PUT(STANDARD_ERROR, ASCII.HT); INT_IO.PUT(STANDARD_ERROR, TARG, 1); TEXT_IO.NEW_LINE(STANDARD_ERROR); end if; -- update frequency count for destination state I := 1; while (TARGSTATE(I) /= TARG) loop I := I + 1; end loop; TARGFREQ(I) := TARGFREQ(I) + 1; NUMDUP := NUMDUP + 1; end if; TOTALTRANS := TOTALTRANS + 1; DUPLIST(SYM) := NIL; end if; end loop; NUMSNPAIRS := NUMSNPAIRS + TOTALTRANS; if (CASEINS and not USEECS) then I := CHARACTER'POS('A'); J := CHARACTER'POS('a'); while (I < CHARACTER'POS('Z')) loop STATE(I) := STATE(J); I := I + 1; J := J + 1; end loop; end if; if (DS > NUM_START_STATES) then CHECK_FOR_BACKTRACKING(DS, STATE); end if; if (FULLTBL) then -- supply array's 0-element TEXT_IO.PUT(FULL_TABLE_TEMP_FILE, ","); MISC.DATAFLUSH(FULL_TABLE_TEMP_FILE); TEXT_IO.PUT(FULL_TABLE_TEMP_FILE, "( "); if (DS = END_OF_BUFFER_STATE) then MISC.MK2DATA(FULL_TABLE_TEMP_FILE, -END_OF_BUFFER_STATE); else MISC.MK2DATA(FULL_TABLE_TEMP_FILE, END_OF_BUFFER_STATE); end if; for CNT in 1 .. NUMECS loop -- jams are marked by negative of state number if ((STATE(CNT) /= 0)) then MISC.MK2DATA(FULL_TABLE_TEMP_FILE, STATE(CNT)); else MISC.MK2DATA(FULL_TABLE_TEMP_FILE, -DS); end if; end loop; TEXT_IO.PUT(FULL_TABLE_TEMP_FILE, " )"); -- force extra blank line next dataflush() DATALINE := NUMDATALINES; else if (DS = END_OF_BUFFER_STATE) then -- special case this state to make sure it does what it's -- supposed to, i.e., jam on end-of-buffer TBLCMP.STACK1(DS, 0, 0, JAMSTATE_CONST); else -- normal, compressed state -- determine which destination state is the most common, and -- how many transitions to it there are COMFREQ := 0; COMSTATE := 0; for CNT in 1 .. TARGPTR loop if (TARGFREQ(CNT) > COMFREQ) then COMFREQ := TARGFREQ(CNT); COMSTATE := TARGSTATE(CNT); end if; end loop; TBLCMP.BLDTBL(STATE, DS, TOTALTRANS, COMSTATE, COMFREQ); end if; end if; end loop; if (FULLTBL) then TEXT_IO.PUT("yy_nxt : constant array(0.."); INT_IO.PUT(NUM_NXT_STATES - 1, 1); TEXT_IO.PUT_LINE(" , ASCII.NUL..ASCII.DEL) of short :="); TEXT_IO.PUT_LINE(" ("); RESET(FULL_TABLE_TEMP_FILE, IN_FILE); while (not END_OF_FILE(FULL_TABLE_TEMP_FILE)) loop TSTRING.GET_LINE(FULL_TABLE_TEMP_FILE, BUF); TSTRING.PUT_LINE(BUF); end loop; DELETE(FULL_TABLE_TEMP_FILE); MISC.DATAEND; else TBLCMP.CMPTMPS; -- create compressed template entries -- create tables for all the states with only one out-transition while (ONESP > 0) loop TBLCMP.MK1TBL(ONESTATE(ONESP), ONESYM(ONESP), ONENEXT(ONESP), ONEDEF( ONESP)); ONESP := ONESP - 1; end loop; TBLCMP.MKDEFTBL; end if; end NTOD; -- snstods - converts a set of ndfa states into a dfa state -- -- on return, the dfa state number is in newds. procedure SNSTODS(SNS : in INT_PTR; NUMSTATES : in INTEGER; ACCSET : in INT_PTR; NACC, HASHVAL : in INTEGER; NEWDS_ADDR : out INTEGER; RESULT : out BOOLEAN) is DIDSORT : BOOLEAN := FALSE; J : INTEGER; NEWDS : INTEGER; OLDSNS : INT_PTR; begin for I in 1 .. LASTDFA loop if (HASHVAL = DHASH(I)) then if (NUMSTATES = DFASIZ(I)) then OLDSNS := DSS(I); if (not DIDSORT) then -- we sort the states in sns so we can compare it to -- oldsns quickly. we use bubble because there probably -- aren't very many states MISC.BUBBLE(SNS, NUMSTATES); DIDSORT := TRUE; end if; J := 1; while (J <= NUMSTATES) loop if (SNS(J) /= OLDSNS(J)) then exit; end if; J := J + 1; end loop; if (J > NUMSTATES) then DFAEQL := DFAEQL + 1; NEWDS_ADDR := I; RESULT := FALSE; return; end if; HSHCOL := HSHCOL + 1; else HSHSAVE := HSHSAVE + 1; end if; end if; end loop; -- make a new dfa LASTDFA := LASTDFA + 1; if (LASTDFA >= CURRENT_MAX_DFAS) then INCREASE_MAX_DFAS; end if; NEWDS := LASTDFA; DSS(NEWDS) := new UNBOUNDED_INT_ARRAY(0 .. NUMSTATES + 1); -- if we haven't already sorted the states in sns, we do so now, so that -- future comparisons with it can be made quickly if (not DIDSORT) then MISC.BUBBLE(SNS, NUMSTATES); end if; for I in 1 .. NUMSTATES loop DSS(NEWDS)(I) := SNS(I); end loop; DFASIZ(NEWDS) := NUMSTATES; DHASH(NEWDS) := HASHVAL; if (NACC = 0) then DFAACC(NEWDS).DFAACC_STATE := 0; ACCSIZ(NEWDS) := 0; else -- find lowest numbered rule so the disambiguating rule will work J := NUM_RULES + 1; for I in 1 .. NACC loop if (ACCSET(I) < J) then J := ACCSET(I); end if; end loop; DFAACC(NEWDS).DFAACC_STATE := J; end if; NEWDS_ADDR := NEWDS; RESULT := TRUE; return; exception when STORAGE_ERROR => MISC.AFLEXFATAL("dynamic memory failure in snstods()"); end SNSTODS; -- symfollowset - follow the symbol transitions one step function SYMFOLLOWSET(DS : in INT_PTR; DSIZE, TRANSSYM : in INTEGER; NSET : in INT_PTR) return INTEGER is NS, TSP, SYM, LENCCL, CH, NUMSTATES, CCLLIST : INTEGER; begin NUMSTATES := 0; for I in 1 .. DSIZE loop -- for each nfa state ns in the state set of ds NS := DS(I); SYM := TRANSCHAR(NS); TSP := TRANS1(NS); if (SYM < 0) then -- it's a character class SYM := -SYM; CCLLIST := CCLMAP(SYM); LENCCL := CCLLEN(SYM); if (CCLNG(SYM) /= 0) then for J in 0 .. LENCCL - 1 loop -- loop through negated character class CH := CHARACTER'POS(CCLTBL(CCLLIST + J)); if (CH > TRANSSYM) then exit; -- transsym isn't in negated ccl else if (CH = TRANSSYM) then goto BOTTOM; -- next 2 end if; end if; end loop; -- didn't find transsym in ccl NUMSTATES := NUMSTATES + 1; NSET(NUMSTATES) := TSP; else for J in 0 .. LENCCL - 1 loop CH := CHARACTER'POS(CCLTBL(CCLLIST + J)); if (CH > TRANSSYM) then exit; else if (CH = TRANSSYM) then NUMSTATES := NUMSTATES + 1; NSET(NUMSTATES) := TSP; exit; end if; end if; end loop; end if; else if ((SYM >= CHARACTER'POS('A')) and (SYM <= CHARACTER'POS('Z')) and CASEINS) then MISC.AFLEXFATAL("consistency check failed in symfollowset"); else if (SYM = SYM_EPSILON) then null; -- do nothing else if (ECGROUP(SYM) = TRANSSYM) then NUMSTATES := NUMSTATES + 1; NSET(NUMSTATES) := TSP; end if; end if; end if; end if; <<BOTTOM>> null; end loop; return NUMSTATES; end SYMFOLLOWSET; -- sympartition - partition characters with same out-transitions procedure SYMPARTITION(DS : in INT_PTR; NUMSTATES : in INTEGER; SYMLIST : in out C_SIZE_BOOL_ARRAY; DUPLIST : in out C_SIZE_ARRAY) is TCH, J, NS, LENCCL, CCLP, ICH : INTEGER; DUPFWD : C_SIZE_ARRAY; -- partitioning is done by creating equivalence classes for those -- characters which have out-transitions from the given state. Thus -- we are really creating equivalence classes of equivalence classes. begin for I in 1 .. NUMECS loop -- initialize equivalence class list DUPLIST(I) := I - 1; DUPFWD(I) := I + 1; end loop; DUPLIST(1) := NIL; DUPFWD(NUMECS) := NIL; DUPFWD(0) := 0; for I in 1 .. NUMSTATES loop NS := DS(I); TCH := TRANSCHAR(NS); if (TCH /= SYM_EPSILON) then if ((TCH < -LASTCCL) or (TCH > CSIZE)) then MISC.AFLEXFATAL("bad transition character detected in sympartition()") ; end if; if (TCH > 0) then -- character transition ECS.MKECHAR(ECGROUP(TCH), DUPFWD, DUPLIST); SYMLIST(ECGROUP(TCH)) := TRUE; else -- character class TCH := -TCH; LENCCL := CCLLEN(TCH); CCLP := CCLMAP(TCH); ECS.MKECCL(CCLTBL(CCLP .. CCLP + LENCCL), LENCCL, DUPFWD, DUPLIST, NUMECS); if (CCLNG(TCH) /= 0) then J := 0; for K in 0 .. LENCCL - 1 loop ICH := CHARACTER'POS(CCLTBL(CCLP + K)); J := J + 1; while (J < ICH) loop SYMLIST(J) := TRUE; J := J + 1; end loop; end loop; J := J + 1; while (J <= NUMECS) loop SYMLIST(J) := TRUE; J := J + 1; end loop; else for K in 0 .. LENCCL - 1 loop ICH := CHARACTER'POS(CCLTBL(CCLP + K)); SYMLIST(ICH) := TRUE; end loop; end if; end if; end if; end loop; end SYMPARTITION; end dfa;
optikos/ada-lsp
Ada
1,575
ads
-- Copyright (c) 2017 Maxim Reznik <[email protected]> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- private with Ada.Containers.Hashed_Maps; with Ada.Streams; with League.Strings; private with League.Strings.Hash; with LSP.Message_Handlers; with LSP.Types; package LSP.Notification_Dispatchers is pragma Preelaborate; type Notification_Dispatcher is tagged limited private; type Parameter_Handler_Access is access procedure (Stream : access Ada.Streams.Root_Stream_Type'Class; Handler : not null LSP.Message_Handlers.Notification_Handler_Access); not overriding procedure Register (Self : in out Notification_Dispatcher; Method : League.Strings.Universal_String; Value : Parameter_Handler_Access); not overriding procedure Dispatch (Self : in out Notification_Dispatcher; Method : LSP.Types.LSP_String; Stream : access Ada.Streams.Root_Stream_Type'Class; Handler : not null LSP.Message_Handlers.Notification_Handler_Access); private package Maps is new Ada.Containers.Hashed_Maps (Key_Type => League.Strings.Universal_String, Element_Type => Parameter_Handler_Access, Hash => League.Strings.Hash, Equivalent_Keys => League.Strings."=", "=" => "="); type Notification_Dispatcher is tagged limited record Map : Maps.Map; Value : LSP.Message_Handlers.Notification_Handler_Access; end record; end LSP.Notification_Dispatchers;
reznikmm/matreshka
Ada
4,736
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.Values_Cell_Range_Address_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Chart_Values_Cell_Range_Address_Attribute_Node is begin return Self : Chart_Values_Cell_Range_Address_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_Values_Cell_Range_Address_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Values_Cell_Range_Address_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Chart_URI, Matreshka.ODF_String_Constants.Values_Cell_Range_Address_Attribute, Chart_Values_Cell_Range_Address_Attribute_Node'Tag); end Matreshka.ODF_Chart.Values_Cell_Range_Address_Attributes;
stcarrez/ada-asf
Ada
2,604
ads
----------------------------------------------------------------------- -- components-ajax-includes -- AJAX Include component -- 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.Html; with ASF.Contexts.Faces; package ASF.Components.Ajax.Includes is -- @attribute -- Defines whether the inclusion is asynchronous or not. -- When true, an AJAX call will be made by the client browser to fetch the content. -- When false, the view is included in the current component tree. ASYNC_ATTR_NAME : constant String := "async"; -- @attribute -- Defines the HTML container element that will contain the included view. LAYOUT_ATTR_NAME : constant String := "layout"; -- @attribute -- Defines the view name to include. SRC_ATTR_NAME : constant String := "src"; -- @tag include -- The <b>ajax:include</b> component allows to include type UIInclude is new ASF.Components.Html.UIHtmlComponent with private; -- Get the HTML layout that must be used for the include container. -- The default layout is a "div". -- Returns "div", "span", "pre", "b". function Get_Layout (UI : in UIInclude; Context : in ASF.Contexts.Faces.Faces_Context'Class) return String; -- The included XHTML file is rendered according to the <b>async</b> attribute: -- -- When <b>async</b> is false, render the specified XHTML file in such a way that inner -- forms will be posted on the included view. -- -- When <b>async</b> is true, trigger an AJAX call to include the specified -- XHTML view when the page is loaded. -- -- overriding procedure Encode_Children (UI : in UIInclude; Context : in out ASF.Contexts.Faces.Faces_Context'Class); private type UIInclude is new ASF.Components.Html.UIHtmlComponent with null record; end ASF.Components.Ajax.Includes;
usainzg/EHU
Ada
71
ads
with Listas; package Listas_Enteros is new Listas(Elemento => Integer);
tum-ei-rcs/StratoX
Ada
522
ads
-- Project: StratoX -- System: Stratosphere Balloon Flight Controller -- Author: Martin Becker ([email protected]) -- @summary tools for SD Logging package SDLog.Tools with SPARK_Mode => Off is procedure Perf_Test (FS : in FAT_Filesystem.FAT_Filesystem_Access; megabytes : Interfaces.Unsigned_32); -- Write performance test. Creates a file with the given length -- dumps throughput. procedure List_Rootdir (FS : in FAT_Filesystem.FAT_Filesystem_Access); end SDLog.Tools;
sungyeon/drake
Ada
1,837
ads
pragma License (Unrestricted); -- implementation unit specialized for Linux with C.sys.statfs; package System.Native_Directories.Volumes is -- File system information. pragma Preelaborate; subtype File_Size is Ada.Streams.Stream_Element_Count; type File_System is record Statistics : aliased C.sys.statfs.struct_statfs := (f_type => 0, others => <>); Format_Name_Offset : C.ptrdiff_t; Format_Name_Length : C.size_t; Directory_Offset : C.ptrdiff_t; Directory_Length : C.size_t; Device_Offset : C.ptrdiff_t; Device_Length : C.size_t; Info : C.char_ptr := null; -- the line of /proc/self/mountinfo end record; pragma Suppress_Initialization (File_System); function Is_Assigned (FS : File_System) return Boolean; pragma Inline (Is_Assigned); Disable_Controlled : constant Boolean := True; procedure Get (Name : String; FS : aliased out File_System); procedure Finalize (FS : in out File_System); function Size (FS : File_System) return File_Size; function Free_Space (FS : File_System) return File_Size; function Format_Name (FS : aliased in out File_System) return String; function Directory (FS : aliased in out File_System) return String; function Device (FS : aliased in out File_System) return String; function Case_Preserving (FS : File_System) return Boolean is (True); function Case_Sensitive (FS : File_System) return Boolean is (True); function Is_HFS (FS : File_System) return Boolean is (False); subtype File_System_Id is C.sys.types.fsid_t; function Identity (FS : File_System) return File_System_Id; -- unimplemented function Owner (FS : File_System) return String with Import, Convention => Ada, External_Name => "__drake_program_error"; end System.Native_Directories.Volumes;
reznikmm/matreshka
Ada
3,669
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.Text_Ruby_Base_Elements is pragma Preelaborate; type ODF_Text_Ruby_Base is limited interface and XML.DOM.Elements.DOM_Element; type ODF_Text_Ruby_Base_Access is access all ODF_Text_Ruby_Base'Class with Storage_Size => 0; end ODF.DOM.Text_Ruby_Base_Elements;
reznikmm/matreshka
Ada
27,808
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-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$ ------------------------------------------------------------------------------ -- Calendar operations according to ISO-8601 standard. It is based on -- proleptic Gregorian calendar with astronomical year numbering. ------------------------------------------------------------------------------ with League.Strings; package League.Calendars.ISO_8601 is pragma Preelaborate; type Year_Number is range -9_999 .. 9_999; type Month_Number is range 1 .. 12; type Day_Number is range 1 .. 31; type Hour_Number is range 0 .. 23; type Minute_Number is range 0 .. 59; type Second_Number is range 0 .. 60; type Nanosecond_100_Number is range 0 .. 9_999_999; type Day_Of_Week_Number is range 1 .. 7; -- XXX Does it depend from locale? type Day_Of_Year_Number is range 1 .. 366; type Week_Of_Year_Number is range 1 .. 53; type ISO_8601_Calendar is new Abstract_Calendar with private; function Year (Self : ISO_8601_Calendar'Class; Stamp : Date) return Year_Number; function Year (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Year_Number; function Year (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Year_Number; -- Returns the year of this date. Negative numbers indicate years before -- 1 A.D. function Month (Self : ISO_8601_Calendar'Class; Stamp : Date) return Month_Number; function Month (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Month_Number; function Month (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Month_Number; -- Returns the number corresponding to the month of this date. function Day (Self : ISO_8601_Calendar'Class; Stamp : Date) return Day_Number; function Day (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Day_Number; function Day (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Day_Number; -- Returns the day of the month of this date. function Hour (Self : ISO_8601_Calendar'Class; Stamp : Time) return Hour_Number; function Hour (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Hour_Number; function Hour (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Hour_Number; -- Returns the hour part (0 to 23) of the time. function Minute (Self : ISO_8601_Calendar'Class; Stamp : Time) return Minute_Number; function Minute (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Minute_Number; function Minute (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Minute_Number; -- Returns the minute part (0 to 59) of the time. function Second (Self : ISO_8601_Calendar'Class; Stamp : Time) return Second_Number; function Second (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Second_Number; function Second (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Second_Number; -- Returns the second part (0 to 60) of the time. function Nanosecond_100 (Self : ISO_8601_Calendar'Class; Stamp : Time) return Nanosecond_100_Number; function Nanosecond_100 (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Nanosecond_100_Number; function Nanosecond_100 (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Nanosecond_100_Number; -- Returns the fractional part of second in 100th nanoseconds (0 to -- 9999999) of the time. function Day_Of_Week (Self : ISO_8601_Calendar'Class; Stamp : Date) return Day_Of_Week_Number; function Day_Of_Week (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Day_Of_Week_Number; function Day_Of_Week (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Day_Of_Week_Number; -- Returns the weekday for this date. function Day_Of_Year (Self : ISO_8601_Calendar'Class; Stamp : Date) return Day_Of_Year_Number; function Day_Of_Year (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Day_Of_Year_Number; function Day_Of_Year (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Day_Of_Year_Number; -- Returns the day of the year (1 to 365 or 366 on leap years) for this -- date. function Week_Of_Year (Self : ISO_8601_Calendar'Class; Stamp : Date) return Week_Of_Year_Number; function Week_Of_Year (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Week_Of_Year_Number; function Week_Of_Year (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Week_Of_Year_Number; -- Returns the week number (1 to 53). -- -- In accordance with ISO 8601, weeks start on Monday and the first -- Thursday of a year is always in week 1 of that year. Most years have 52 -- weeks, but some have 53. procedure Week_Of_Year (Self : ISO_8601_Calendar'Class; Stamp : Date; Week : out Week_Of_Year_Number; Year : out Year_Number); procedure Week_Of_Year (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Week : out Week_Of_Year_Number; Year : out Year_Number); procedure Week_Of_Year (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone; Week : out Week_Of_Year_Number; Year : out Year_Number); -- Sets Week to the week number (1 to 53) and Year to year number. -- -- In accordance with ISO 8601, weeks start on Monday and the first -- Thursday of a year is always in week 1 of that year. Most years have 52 -- weeks, but some have 53. -- -- Year is not always the same as Calendar.Year. For example, 1 January -- 2000 has week number 52 in the year 1999, and 31 December 2002 has week -- number 1 in the year 2003. function Days_In_Year (Self : ISO_8601_Calendar'Class; Stamp : Date) return Day_Of_Year_Number; function Days_In_Year (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Day_Of_Year_Number; function Days_In_Year (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Day_Of_Year_Number; function Days_In_Year (Self : ISO_8601_Calendar'Class; Year : Year_Number) return Day_Of_Year_Number; -- Returns the number of days in the year (365 or 366) for this date. function Days_In_Month (Self : ISO_8601_Calendar'Class; Stamp : Date) return Day_Number; function Days_In_Month (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Day_Number; function Days_In_Month (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Day_Number; function Days_In_Month (Self : ISO_8601_Calendar'Class; Year : Year_Number; Month : Month_Number) return Day_Number; -- Returns the number of days in the month (28 to 31) for this date. function Days_To (Self : ISO_8601_Calendar'Class; From : Date; To : Date) return Integer; -- Returns the number of days from date From to date To (which is negative -- if To is earlier than From date). function Is_Leap_Year (Self : ISO_8601_Calendar'Class; Year : Year_Number) return Boolean; function Is_Leap_Year (Self : ISO_8601_Calendar'Class; Stamp : Date) return Boolean; function Is_Leap_Year (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Boolean; function Is_Leap_Year (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Boolean; -- Returns True if the specified year is a leap year; otherwise returns -- False. function Add_Days (Self : ISO_8601_Calendar'Class; Stamp : Date; Days : Integer) return Date; function Add_Days (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Days : Integer) return Date_Time; -- Returns a date containing a date Days later than the date of Stamp (or -- earlier if Days is negative). procedure Add_Days (Self : ISO_8601_Calendar'Class; Stamp : in out Date; Days : Integer); procedure Add_Days (Self : ISO_8601_Calendar'Class; Stamp : in out Date_Time; Days : Integer); -- Sets Stamp to a date Days later than the date of Stamp (or earlier if -- Days is negative). function Add_Months (Self : ISO_8601_Calendar'Class; Stamp : Date; Months : Integer) return Date; function Add_Months (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Months : Integer) return Date_Time; -- Returns a date containing a date Months later than the date of Stamp (or -- earlier if Months is negative). -- -- Note: If the ending day/month combination does not exist in the -- resulting month/year, this function will return a date that is the -- latest valid date. procedure Add_Months (Self : ISO_8601_Calendar'Class; Stamp : in out Date; Months : Integer); procedure Add_Months (Self : ISO_8601_Calendar'Class; Stamp : in out Date_Time; Months : Integer); -- Sets Stamp to a date Months later than the date of Stamp (or earlier if -- Months is negative). -- -- Note: If the ending day/month combination does not exist in the -- resulting month/year, this function will return a date that is the -- latest valid date. function Add_Years (Self : ISO_8601_Calendar'Class; Stamp : Date; Years : Integer) return Date; function Add_Years (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Years : Integer) return Date_Time; -- Returns a date Years later than the date of Stamp (or earlier if Years -- is negative). -- -- Note: If the ending day/month combination does not exist in the -- resulting year (i.e., if the date was Feb 29 and the final year is not -- a leap year), this function will return a date that is the latest valid -- date (that is, Feb 28). procedure Add_Years (Self : ISO_8601_Calendar'Class; Stamp : in out Date; Years : Integer); procedure Add_Years (Self : ISO_8601_Calendar'Class; Stamp : in out Date_Time; Years : Integer); -- Sets Stamp to a date Years later than the date of Stamp (or earlier if -- Years is negative). -- -- Note: If the ending day/month combination does not exist in the -- resulting year (i.e., if the date was Feb 29 and the final year is not -- a leap year), this function will return a date that is the latest valid -- date (that is, Feb 28). function Is_Valid (Self : ISO_8601_Calendar'Class; Year : Year_Number; Month : Month_Number; Day : Day_Number) return Boolean; -- Returns True if the specified date (Year, Month, and Day) is valid; -- otherwise returns False. procedure Split (Self : ISO_8601_Calendar'Class; Stamp : Date; Year : out Year_Number; Month : out Month_Number; Day : out Day_Number); procedure Split (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Year : out Year_Number; Month : out Month_Number; Day : out Day_Number; Hour : out Hour_Number; Minute : out Minute_Number; Second : out Second_Number; Nanosecond_100 : out Nanosecond_100_Number); procedure Split (Self : ISO_8601_Calendar'Class; Zone : Time_Zone; Stamp : Date_Time; Year : out Year_Number; Month : out Month_Number; Day : out Day_Number; Hour : out Hour_Number; Minute : out Minute_Number; Second : out Second_Number; Nanosecond_100 : out Nanosecond_100_Number); -- Extracts the date's year, month, day, hour, minute, second and fraction -- of second, and assigns them to Year, Month, Day, Hour, Minute, Second -- and Nanosecond_100. function Create (Self : ISO_8601_Calendar'Class; Year : Year_Number; Month : Month_Number; Day : Day_Number) return Date; function Create (Self : ISO_8601_Calendar'Class; Year : Year_Number; Month : Month_Number; Day : Day_Number; Hour : Hour_Number; Minute : Minute_Number; Second : Second_Number; Nanosecond_100 : Nanosecond_100_Number) return Date_Time; function Create (Self : ISO_8601_Calendar'Class; Zone : Time_Zone; Year : Year_Number; Month : Month_Number; Day : Day_Number; Hour : Hour_Number; Minute : Minute_Number; Second : Second_Number; Nanosecond_100 : Nanosecond_100_Number) return Date_Time; -- Constructs a date with Year, Month, Day, Hour, Minute, Second and -- franction of second. -- -- If the specified date is invalid, Constraint_Error is raised. function To_Julian_Day (Self : ISO_8601_Calendar'Class; Stamp : Date) return Integer; function To_Julian_Day (Self : ISO_8601_Calendar'Class; Stamp : Date_Time) return Integer; function To_Julian_Day (Self : ISO_8601_Calendar'Class; Stamp : Date_Time; Zone : Time_Zone) return Integer; -- Converts the date to a Julian day. function From_Julian_Day (Self : ISO_8601_Calendar'Class; Day : Integer) return Date; -- Converts the Julian day Day to a date. function Image (Self : ISO_8601_Calendar'Class; Pattern : League.Strings.Universal_String; Stamp : Date_Time) return League.Strings.Universal_String; function Image (Self : ISO_8601_Calendar'Class; Pattern : League.Strings.Universal_String; Stamp : Date_Time; Zone : Time_Zone) return League.Strings.Universal_String; ----------------------------------------------------------------------- -- Subprograms below don't have calendar parameter for convenience. -- ----------------------------------------------------------------------- function Year (Stamp : Date) return Year_Number; function Year (Stamp : Date_Time) return Year_Number; function Year (Stamp : Date_Time; Zone : Time_Zone) return Year_Number; -- Returns the year of this date. Negative numbers indicate years before -- 1 A.D. function Month (Stamp : Date) return Month_Number; function Month (Stamp : Date_Time) return Month_Number; function Month (Stamp : Date_Time; Zone : Time_Zone) return Month_Number; -- Returns the number corresponding to the month of this date. function Day (Stamp : Date) return Day_Number; function Day (Stamp : Date_Time) return Day_Number; function Day (Stamp : Date_Time; Zone : Time_Zone) return Day_Number; -- Returns the day of the month of this date. function Hour (Stamp : Time) return Hour_Number; function Hour (Stamp : Date_Time) return Hour_Number; function Hour (Stamp : Date_Time; Zone : Time_Zone) return Hour_Number; -- Returns the hour part (0 to 23) of the time. function Minute (Stamp : Time) return Minute_Number; function Minute (Stamp : Date_Time) return Minute_Number; function Minute (Stamp : Date_Time; Zone : Time_Zone) return Minute_Number; -- Returns the minute part (0 to 59) of the time. function Second (Stamp : Time) return Second_Number; function Second (Stamp : Date_Time) return Second_Number; function Second (Stamp : Date_Time; Zone : Time_Zone) return Second_Number; -- Returns the second part (0 to 60) of the time. function Nanosecond_100 (Stamp : Time) return Nanosecond_100_Number; function Nanosecond_100 (Stamp : Date_Time) return Nanosecond_100_Number; function Nanosecond_100 (Stamp : Date_Time; Zone : Time_Zone) return Nanosecond_100_Number; -- Returns the fractional part of second in 100th nanoseconds (0 to -- 9999999) of the time. function Day_Of_Week (Stamp : Date) return Day_Of_Week_Number; function Day_Of_Week (Stamp : Date_Time) return Day_Of_Week_Number; function Day_Of_Week (Stamp : Date_Time; Zone : Time_Zone) return Day_Of_Week_Number; -- Returns the day of the year (1 to 365 or 366 on leap years) for this -- date. function Day_Of_Year (Stamp : Date) return Day_Of_Year_Number; function Day_Of_Year (Stamp : Date_Time) return Day_Of_Year_Number; function Day_Of_Year (Stamp : Date_Time; Zone : Time_Zone) return Day_Of_Year_Number; -- Returns the day of the year (1 to 365 or 366 on leap years) for this -- date. function Week_Of_Year (Stamp : Date) return Week_Of_Year_Number; function Week_Of_Year (Stamp : Date_Time) return Week_Of_Year_Number; function Week_Of_Year (Stamp : Date_Time; Zone : Time_Zone) return Week_Of_Year_Number; -- Returns the week number (1 to 53). -- -- In accordance with ISO 8601, weeks start on Monday and the first -- Thursday of a year is always in week 1 of that year. Most years have 52 -- weeks, but some have 53. procedure Week_Of_Year (Stamp : Date; Week : out Week_Of_Year_Number; Year : out Year_Number); procedure Week_Of_Year (Stamp : Date_Time; Week : out Week_Of_Year_Number; Year : out Year_Number); procedure Week_Of_Year (Stamp : Date_Time; Zone : Time_Zone; Week : out Week_Of_Year_Number; Year : out Year_Number); -- Sets Week to the week number (1 to 53) and Year to year number. -- -- In accordance with ISO 8601, weeks start on Monday and the first -- Thursday of a year is always in week 1 of that year. Most years have 52 -- weeks, but some have 53. -- -- Year is not always the same as Calendar.Year. For example, 1 January -- 2000 has week number 52 in the year 1999, and 31 December 2002 has week -- number 1 in the year 2003. function Days_To (From : Date; To : Date) return Integer; -- Returns the number of days from date From to date To (which is negative -- if To is earlier than From date). function Days_In_Year (Stamp : Date) return Day_Of_Year_Number; function Days_In_Year (Stamp : Date_Time) return Day_Of_Year_Number; function Days_In_Year (Stamp : Date_Time; Zone : Time_Zone) return Day_Of_Year_Number; function Days_In_Year (Year : Year_Number) return Day_Of_Year_Number; -- Returns the number of days in the year (365 or 366) for this date. function Days_In_Month (Stamp : Date) return Day_Number; function Days_In_Month (Stamp : Date_Time) return Day_Number; function Days_In_Month (Stamp : Date_Time; Zone : Time_Zone) return Day_Number; function Days_In_Month (Year : Year_Number; Month : Month_Number) return Day_Number; -- Returns the number of days in the month (28 to 31) for this date. function Is_Leap_Year (Year : Year_Number) return Boolean; function Is_Leap_Year (Stamp : Date) return Boolean; function Is_Leap_Year (Stamp : Date_Time) return Boolean; function Is_Leap_Year (Stamp : Date_Time; Zone : Time_Zone) return Boolean; -- Returns True if the specified year is a leap year; otherwise returns -- False. function Add_Days (Stamp : Date; Days : Integer) return Date; function Add_Days (Stamp : Date_Time; Days : Integer) return Date_Time; -- Returns a date containing a date Days later than the date of Stamp (or -- earlier if Days is negative). procedure Add_Days (Stamp : in out Date; Days : Integer); procedure Add_Days (Stamp : in out Date_Time; Days : Integer); -- Sets Stamp to a date Days later than the date of Stamp (or earlier if -- Days is negative). function Add_Months (Stamp : Date; Months : Integer) return Date; function Add_Months (Stamp : Date_Time; Months : Integer) return Date_Time; -- Returns a date containing a date Months later than the date of Stamp (or -- earlier if Months is negative). -- -- Note: If the ending day/month combination does not exist in the -- resulting month/year, this function will return a date that is the -- latest valid date. procedure Add_Months (Stamp : in out Date; Months : Integer); procedure Add_Months (Stamp : in out Date_Time; Months : Integer); -- Sets Stamp to a date Months later than the date of Stamp (or earlier if -- Months is negative). -- -- Note: If the ending day/month combination does not exist in the -- resulting month/year, this function will return a date that is the -- latest valid date. function Add_Years (Stamp : Date; Years : Integer) return Date; function Add_Years (Stamp : Date_Time; Years : Integer) return Date_Time; -- Returns a date Years later than the date of Stamp (or earlier if Years -- is negative). -- -- Note: If the ending day/month combination does not exist in the -- resulting year (i.e., if the date was Feb 29 and the final year is not -- a leap year), this function will return a date that is the latest valid -- date (that is, Feb 28). procedure Add_Years (Stamp : in out Date; Years : Integer); procedure Add_Years (Stamp : in out Date_Time; Years : Integer); -- Sets Stamp to a date Years later than the date of Stamp (or earlier if -- Years is negative). -- -- Note: If the ending day/month combination does not exist in the -- resulting year (i.e., if the date was Feb 29 and the final year is not -- a leap year), this function will return a date that is the latest valid -- date (that is, Feb 28). function Is_Valid (Year : Year_Number; Month : Month_Number; Day : Day_Number) return Boolean; -- Returns True if the specified date (Year, Month, and Day) is valid; -- otherwise returns False. procedure Split (Stamp : Date; Year : out Year_Number; Month : out Month_Number; Day : out Day_Number); procedure Split (Stamp : Date_Time; Year : out Year_Number; Month : out Month_Number; Day : out Day_Number; Hour : out Hour_Number; Minute : out Minute_Number; Second : out Second_Number; Nanosecond_100 : out Nanosecond_100_Number); procedure Split (Stamp : Date_Time; Zone : Time_Zone; Year : out Year_Number; Month : out Month_Number; Day : out Day_Number; Hour : out Hour_Number; Minute : out Minute_Number; Second : out Second_Number; Nanosecond_100 : out Nanosecond_100_Number); -- Extracts the date's year, month, day, and time, and assigns them to -- Year, Month, Day, and Seconds. function Create (Year : Year_Number; Month : Month_Number; Day : Day_Number) return Date; function Create (Year : Year_Number; Month : Month_Number; Day : Day_Number; Hour : Hour_Number; Minute : Minute_Number; Second : Second_Number; Nanosecond_100 : Nanosecond_100_Number) return Date_Time; function Create (Zone : Time_Zone; Year : Year_Number; Month : Month_Number; Day : Day_Number; Hour : Hour_Number; Minute : Minute_Number; Second : Second_Number; Nanosecond_100 : Nanosecond_100_Number) return Date_Time; -- Constructs a date with Year, Month, Day, Hour, Minute, Second and -- fraction of second. -- -- If the specified date is invalid, Constraint_Error is raised. function To_Julian_Day (Stamp : Date) return Integer; function To_Julian_Day (Stamp : Date_Time) return Integer; function To_Julian_Day (Stamp : Date_Time; Zone : Time_Zone) return Integer; -- Converts the date to a Julian day. function From_Julian_Day (Day : Integer) return Date; -- Converts the Julian day Day to a date. function Image (Pattern : League.Strings.Universal_String; Stamp : Date_Time) return League.Strings.Universal_String; function Image (Pattern : League.Strings.Universal_String; Stamp : Date_Time; Zone : Time_Zone) return League.Strings.Universal_String; private type ISO_8601_Calendar is new Abstract_Calendar with null record; end League.Calendars.ISO_8601;
danieagle/ASAP-Modular_Hashing
Ada
7,899
ads
------------------------------------------------------------------------------ -- -- -- Modular Hash Infrastructure -- -- -- -- ------------------------------------------------------------------------ -- -- -- -- Copyright (C) 2018-2021, ANNEXI-STRAYLINE Trans-Human Ltd. -- -- All rights reserved. -- -- -- -- Original Contributors: -- -- * Richard Wai, Ensi Martini, Aninda Poddar, Noshen Atashe -- -- (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 Interfaces; with Ada.Streams; package Modular_Hashing is ---------- -- Hash -- ---------- type Hash is abstract tagged null record; -- The Hash Type represents a prototypical Hash value, being some kind of -- fixed-sized representation derrived from an input, such that two equal -- inputs generate the same Hash value. function "<" (Left, Right: Hash) return Boolean is abstract; function ">" (Left, Right: Hash) return Boolean is abstract; function "=" (Left, Right: Hash) return Boolean is abstract; -- Representation -- -------------------- type Hash_Binary_Value is array (Positive range <>) of Interfaces.Unsigned_8; function Binary_Bytes (Value: Hash) return Positive is abstract; -- Returns the number of bytes required to represent the Hash value with -- a Hash_Binary array. function Binary (Value: Hash) return Hash_Binary_Value is abstract with Post'Class => Binary'Result'Length = Value.Binary_Bytes; -- Returns a binary represetnation of the Hash value as an array of bytes. -- This output is used by the default implementation of Hexadecimal, which -- assumes that the resulting value is in ** LITTLE ENDIAN ** order function Hexadecimal_Digits (Value: Hash) return Positive is (Hash'Class(Value).Binary_Bytes * 2); -- Returns the number of hexidecimal digits required to represent the Hash -- value. function Hexadecimal (Value : Hash; Lower_Case: Boolean := True) return String with Post => Hexadecimal'Result'Length = Value.Hexadecimal_Digits; -- Returns the Hexadecimal representation of the Binary representation of -- Hash value. The size of the returned String is always constant for any -- value of the same Hash'Class type, and can be queried via -- Hexidecimal_Digits function. -------------------- -- Hash_Algorithm -- -------------------- type Hash_Algorithm is abstract new Ada.Streams.Root_Stream_Type with null record; -- Members of Hash_Algorithm'Class represent any given Hashing algorithm -- which can produce a value of Hash'Class from an arbitrary input delivered -- via the Ada Stream interface. -- -- Hash_Algorithm'Class members are not required, and should not be expected -- to be, task-safe. -- Streams Interface -- ----------------------- overriding procedure Read (Stream: in out Hash_Algorithm; Item : out Ada.Streams.Stream_Element_Array; Last : out Ada.Streams.Stream_Element_Offset); -- Hash algorithms are always "one way". Reading from a Hash_Algorithm'Class -- constitutes an incorrect application of a Hash_Algorithm and causes an -- explicit raise of Program_Error overriding procedure Write (Stream: in out Hash_Algorithm; Item : in Ada.Streams.Stream_Element_Array) is abstract; -- Accepts a stream or message of an arbitrary size. -- -- For message digest algorithms, content streamed to Write consitutes the -- message, and is held in a buffer until Digest is executed, which triggers -- digestion of the message (buffer contents at that point), into a single -- Hash value. -- Executive Operations -- -------------------------- procedure Reset (Engine: in out Hash_Algorithm) is abstract; -- Resets any internal state to the initial state, and clears any buffers. -- -- Hash_Algorithms shall be self-initializing. Reset should only be -- required to flush an aborted message function Digest (Engine: in out Hash_Algorithm) return Hash'Class is abstract; -- Returns the Hash value from the Hash_Algoritm. For digest algorithms, -- this also causes the Hash to be computed. -- -- The state of the Hash_Algorithm is reset. Any buffers are cleared. -- Message digest function Digest (Engine : in out Hash_Algorithm'Class; Message: in String) return Hash'Class; function Digest (Engine : in out Hash_Algorithm'Class; Message: in Wide_String) return Hash'Class; function Digest (Engine : in out Hash_Algorithm'Class; Message: in Wide_Wide_String) return Hash'Class; -- Directly writes Message to Engine's stream, and then invokes Digest, -- returning the result end Modular_Hashing;
stcarrez/ada-awa
Ada
29,741
ads
----------------------------------------------------------------------- -- AWA.Countries.Models -- AWA.Countries.Models ----------------------------------------------------------------------- -- File generated by Dynamo DO NOT MODIFY -- Template used: templates/model/package-spec.xhtml -- Ada Generator: https://github.com/stcarrez/dynamo Version 1.4.0 ----------------------------------------------------------------------- -- Copyright (C) 2023 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); with ADO.Sessions; with ADO.Objects; with ADO.Statements; with ADO.SQL; with ADO.Schemas; with Ada.Containers.Vectors; with Ada.Strings.Unbounded; with Util.Beans.Objects; with Util.Beans.Basic.Lists; pragma Warnings (On); package AWA.Countries.Models is pragma Style_Checks ("-mrIu"); type Country_Ref is new ADO.Objects.Object_Ref with null record; type City_Ref is new ADO.Objects.Object_Ref with null record; type Country_Neighbor_Ref is new ADO.Objects.Object_Ref with null record; type Region_Ref is new ADO.Objects.Object_Ref with null record; -- -------------------- -- The country model is a system data model for the application. -- In theory, it never changes. -- -------------------- -- Create an object key for Country. function Country_Key (Id : in ADO.Identifier) return ADO.Objects.Object_Key; -- Create an object key for Country from a string. -- Raises Constraint_Error if the string cannot be converted into the object key. function Country_Key (Id : in String) return ADO.Objects.Object_Key; Null_Country : constant Country_Ref; function "=" (Left, Right : Country_Ref'Class) return Boolean; -- Set the country identifier procedure Set_Id (Object : in out Country_Ref; Value : in ADO.Identifier); -- Get the country identifier function Get_Id (Object : in Country_Ref) return ADO.Identifier; -- Set the country name procedure Set_Name (Object : in out Country_Ref; Value : in Ada.Strings.Unbounded.Unbounded_String); procedure Set_Name (Object : in out Country_Ref; Value : in String); -- Get the country name function Get_Name (Object : in Country_Ref) return Ada.Strings.Unbounded.Unbounded_String; function Get_Name (Object : in Country_Ref) return String; -- Set the continent name procedure Set_Continent (Object : in out Country_Ref; Value : in Ada.Strings.Unbounded.Unbounded_String); procedure Set_Continent (Object : in out Country_Ref; Value : in String); -- Get the continent name function Get_Continent (Object : in Country_Ref) return Ada.Strings.Unbounded.Unbounded_String; function Get_Continent (Object : in Country_Ref) return String; -- Set the currency used in the country procedure Set_Currency (Object : in out Country_Ref; Value : in Ada.Strings.Unbounded.Unbounded_String); procedure Set_Currency (Object : in out Country_Ref; Value : in String); -- Get the currency used in the country function Get_Currency (Object : in Country_Ref) return Ada.Strings.Unbounded.Unbounded_String; function Get_Currency (Object : in Country_Ref) return String; -- Set the country ISO code procedure Set_Iso_Code (Object : in out Country_Ref; Value : in Ada.Strings.Unbounded.Unbounded_String); procedure Set_Iso_Code (Object : in out Country_Ref; Value : in String); -- Get the country ISO code function Get_Iso_Code (Object : in Country_Ref) return Ada.Strings.Unbounded.Unbounded_String; function Get_Iso_Code (Object : in Country_Ref) return String; -- Set the country geoname id procedure Set_Geonameid (Object : in out Country_Ref; Value : in Integer); -- Get the country geoname id function Get_Geonameid (Object : in Country_Ref) return Integer; -- Set the country main language procedure Set_Languages (Object : in out Country_Ref; Value : in Ada.Strings.Unbounded.Unbounded_String); procedure Set_Languages (Object : in out Country_Ref; Value : in String); -- Get the country main language function Get_Languages (Object : in Country_Ref) return Ada.Strings.Unbounded.Unbounded_String; function Get_Languages (Object : in Country_Ref) return String; -- Set the TLD associated with this country procedure Set_Tld (Object : in out Country_Ref; Value : in Ada.Strings.Unbounded.Unbounded_String); procedure Set_Tld (Object : in out Country_Ref; Value : in String); -- Get the TLD associated with this country function Get_Tld (Object : in Country_Ref) return Ada.Strings.Unbounded.Unbounded_String; function Get_Tld (Object : in Country_Ref) return String; -- Set the currency code procedure Set_Currency_Code (Object : in out Country_Ref; Value : in Ada.Strings.Unbounded.Unbounded_String); procedure Set_Currency_Code (Object : in out Country_Ref; Value : in String); -- Get the currency code function Get_Currency_Code (Object : in Country_Ref) return Ada.Strings.Unbounded.Unbounded_String; function Get_Currency_Code (Object : in Country_Ref) return String; -- Load the entity identified by 'Id'. -- Raises the NOT_FOUND exception if it does not exist. procedure Load (Object : in out Country_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 Country_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 Country_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 Country_Ref; Session : in out ADO.Sessions.Master_Session'Class); -- Delete the entity. overriding procedure Delete (Object : in out Country_Ref; Session : in out ADO.Sessions.Master_Session'Class); overriding function Get_Value (From : in Country_Ref; Name : in String) return Util.Beans.Objects.Object; -- Table definition COUNTRY_TABLE : constant ADO.Schemas.Class_Mapping_Access; -- Internal method to allocate the Object_Record instance overriding procedure Allocate (Object : in out Country_Ref); -- Copy of the object. procedure Copy (Object : in Country_Ref; Into : in out Country_Ref); -- Create an object key for City. function City_Key (Id : in ADO.Identifier) return ADO.Objects.Object_Key; -- Create an object key for City from a string. -- Raises Constraint_Error if the string cannot be converted into the object key. function City_Key (Id : in String) return ADO.Objects.Object_Key; Null_City : constant City_Ref; function "=" (Left, Right : City_Ref'Class) return Boolean; -- Set the city identifier procedure Set_Id (Object : in out City_Ref; Value : in ADO.Identifier); -- Get the city identifier function Get_Id (Object : in City_Ref) return ADO.Identifier; -- Set the city name procedure Set_Name (Object : in out City_Ref; Value : in Ada.Strings.Unbounded.Unbounded_String); procedure Set_Name (Object : in out City_Ref; Value : in String); -- Get the city name function Get_Name (Object : in City_Ref) return Ada.Strings.Unbounded.Unbounded_String; function Get_Name (Object : in City_Ref) return String; -- Set the city ZIP code procedure Set_Zip_Code (Object : in out City_Ref; Value : in Integer); -- Get the city ZIP code function Get_Zip_Code (Object : in City_Ref) return Integer; -- Set the city latitude procedure Set_Latitude (Object : in out City_Ref; Value : in Integer); -- Get the city latitude function Get_Latitude (Object : in City_Ref) return Integer; -- Set the city longitude procedure Set_Longitude (Object : in out City_Ref; Value : in Integer); -- Get the city longitude function Get_Longitude (Object : in City_Ref) return Integer; -- Set the region that this city belongs to procedure Set_Region (Object : in out City_Ref; Value : in Region_Ref'Class); -- Get the region that this city belongs to function Get_Region (Object : in City_Ref) return Region_Ref'Class; -- Set the country that this city belongs to procedure Set_Country (Object : in out City_Ref; Value : in Country_Ref'Class); -- Get the country that this city belongs to function Get_Country (Object : in City_Ref) return Country_Ref'Class; -- Load the entity identified by 'Id'. -- Raises the NOT_FOUND exception if it does not exist. procedure Load (Object : in out City_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 City_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 City_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 City_Ref; Session : in out ADO.Sessions.Master_Session'Class); -- Delete the entity. overriding procedure Delete (Object : in out City_Ref; Session : in out ADO.Sessions.Master_Session'Class); overriding function Get_Value (From : in City_Ref; Name : in String) return Util.Beans.Objects.Object; -- Table definition CITY_TABLE : constant ADO.Schemas.Class_Mapping_Access; -- Internal method to allocate the Object_Record instance overriding procedure Allocate (Object : in out City_Ref); -- Copy of the object. procedure Copy (Object : in City_Ref; Into : in out City_Ref); -- -------------------- -- The country neighbor defines what countries -- are neigbors with each other -- -------------------- -- Create an object key for Country_Neighbor. function Country_Neighbor_Key (Id : in ADO.Identifier) return ADO.Objects.Object_Key; -- Create an object key for Country_Neighbor from a string. -- Raises Constraint_Error if the string cannot be converted into the object key. function Country_Neighbor_Key (Id : in String) return ADO.Objects.Object_Key; Null_Country_Neighbor : constant Country_Neighbor_Ref; function "=" (Left, Right : Country_Neighbor_Ref'Class) return Boolean; -- procedure Set_Id (Object : in out Country_Neighbor_Ref; Value : in ADO.Identifier); -- function Get_Id (Object : in Country_Neighbor_Ref) return ADO.Identifier; -- procedure Set_Neighbor_Of (Object : in out Country_Neighbor_Ref; Value : in Country_Ref'Class); -- function Get_Neighbor_Of (Object : in Country_Neighbor_Ref) return Country_Ref'Class; -- procedure Set_Neighbor (Object : in out Country_Neighbor_Ref; Value : in Country_Ref'Class); -- function Get_Neighbor (Object : in Country_Neighbor_Ref) return Country_Ref'Class; -- Load the entity identified by 'Id'. -- Raises the NOT_FOUND exception if it does not exist. procedure Load (Object : in out Country_Neighbor_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 Country_Neighbor_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 Country_Neighbor_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 Country_Neighbor_Ref; Session : in out ADO.Sessions.Master_Session'Class); -- Delete the entity. overriding procedure Delete (Object : in out Country_Neighbor_Ref; Session : in out ADO.Sessions.Master_Session'Class); overriding function Get_Value (From : in Country_Neighbor_Ref; Name : in String) return Util.Beans.Objects.Object; -- Table definition COUNTRY_NEIGHBOR_TABLE : constant ADO.Schemas.Class_Mapping_Access; -- Internal method to allocate the Object_Record instance overriding procedure Allocate (Object : in out Country_Neighbor_Ref); -- Copy of the object. procedure Copy (Object : in Country_Neighbor_Ref; Into : in out Country_Neighbor_Ref); -- -------------------- -- Region defines an area within a country. -- -------------------- -- Create an object key for Region. function Region_Key (Id : in ADO.Identifier) return ADO.Objects.Object_Key; -- Create an object key for Region from a string. -- Raises Constraint_Error if the string cannot be converted into the object key. function Region_Key (Id : in String) return ADO.Objects.Object_Key; Null_Region : constant Region_Ref; function "=" (Left, Right : Region_Ref'Class) return Boolean; -- Set the region identifier procedure Set_Id (Object : in out Region_Ref; Value : in ADO.Identifier); -- Get the region identifier function Get_Id (Object : in Region_Ref) return ADO.Identifier; -- Set the region name procedure Set_Name (Object : in out Region_Ref; Value : in Ada.Strings.Unbounded.Unbounded_String); procedure Set_Name (Object : in out Region_Ref; Value : in String); -- Get the region name function Get_Name (Object : in Region_Ref) return Ada.Strings.Unbounded.Unbounded_String; function Get_Name (Object : in Region_Ref) return String; -- Set the region geonameid procedure Set_Geonameid (Object : in out Region_Ref; Value : in Integer); -- Get the region geonameid function Get_Geonameid (Object : in Region_Ref) return Integer; -- Set the country that this region belongs to procedure Set_Country (Object : in out Region_Ref; Value : in Country_Ref'Class); -- Get the country that this region belongs to function Get_Country (Object : in Region_Ref) return Country_Ref'Class; -- Load the entity identified by 'Id'. -- Raises the NOT_FOUND exception if it does not exist. procedure Load (Object : in out Region_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 Region_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 Region_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 Region_Ref; Session : in out ADO.Sessions.Master_Session'Class); -- Delete the entity. overriding procedure Delete (Object : in out Region_Ref; Session : in out ADO.Sessions.Master_Session'Class); overriding function Get_Value (From : in Region_Ref; Name : in String) return Util.Beans.Objects.Object; -- Table definition REGION_TABLE : constant ADO.Schemas.Class_Mapping_Access; -- Internal method to allocate the Object_Record instance overriding procedure Allocate (Object : in out Region_Ref); -- Copy of the object. procedure Copy (Object : in Region_Ref; Into : in out Region_Ref); private COUNTRY_NAME : aliased constant String := "awa_country"; COL_0_1_NAME : aliased constant String := "id"; COL_1_1_NAME : aliased constant String := "name"; COL_2_1_NAME : aliased constant String := "continent"; COL_3_1_NAME : aliased constant String := "currency"; COL_4_1_NAME : aliased constant String := "iso_code"; COL_5_1_NAME : aliased constant String := "geonameid"; COL_6_1_NAME : aliased constant String := "languages"; COL_7_1_NAME : aliased constant String := "tld"; COL_8_1_NAME : aliased constant String := "currency_code"; COUNTRY_DEF : aliased constant ADO.Schemas.Class_Mapping := (Count => 9, Table => COUNTRY_NAME'Access, Members => ( 1 => COL_0_1_NAME'Access, 2 => COL_1_1_NAME'Access, 3 => COL_2_1_NAME'Access, 4 => COL_3_1_NAME'Access, 5 => COL_4_1_NAME'Access, 6 => COL_5_1_NAME'Access, 7 => COL_6_1_NAME'Access, 8 => COL_7_1_NAME'Access, 9 => COL_8_1_NAME'Access) ); COUNTRY_TABLE : constant ADO.Schemas.Class_Mapping_Access := COUNTRY_DEF'Access; Null_Country : constant Country_Ref := Country_Ref'(ADO.Objects.Object_Ref with null record); type Country_Impl is new ADO.Objects.Object_Record (Key_Type => ADO.Objects.KEY_INTEGER, Of_Class => COUNTRY_DEF'Access) with record Name : Ada.Strings.Unbounded.Unbounded_String; Continent : Ada.Strings.Unbounded.Unbounded_String; Currency : Ada.Strings.Unbounded.Unbounded_String; Iso_Code : Ada.Strings.Unbounded.Unbounded_String; Geonameid : Integer; Languages : Ada.Strings.Unbounded.Unbounded_String; Tld : Ada.Strings.Unbounded.Unbounded_String; Currency_Code : Ada.Strings.Unbounded.Unbounded_String; end record; type Country_Access is access all Country_Impl; overriding procedure Destroy (Object : access Country_Impl); overriding procedure Find (Object : in out Country_Impl; Session : in out ADO.Sessions.Session'Class; Query : in ADO.SQL.Query'Class; Found : out Boolean); overriding procedure Load (Object : in out Country_Impl; Session : in out ADO.Sessions.Session'Class); procedure Load (Object : in out Country_Impl; Stmt : in out ADO.Statements.Query_Statement'Class; Session : in out ADO.Sessions.Session'Class); overriding procedure Save (Object : in out Country_Impl; Session : in out ADO.Sessions.Master_Session'Class); overriding procedure Create (Object : in out Country_Impl; Session : in out ADO.Sessions.Master_Session'Class); overriding procedure Delete (Object : in out Country_Impl; Session : in out ADO.Sessions.Master_Session'Class); procedure Set_Field (Object : in out Country_Ref'Class; Impl : out Country_Access); CITY_NAME : aliased constant String := "awa_city"; COL_0_2_NAME : aliased constant String := "id"; COL_1_2_NAME : aliased constant String := "name"; COL_2_2_NAME : aliased constant String := "zip_code"; COL_3_2_NAME : aliased constant String := "latitude"; COL_4_2_NAME : aliased constant String := "longitude"; COL_5_2_NAME : aliased constant String := "region_id"; COL_6_2_NAME : aliased constant String := "country_id"; CITY_DEF : aliased constant ADO.Schemas.Class_Mapping := (Count => 7, Table => CITY_NAME'Access, Members => ( 1 => COL_0_2_NAME'Access, 2 => COL_1_2_NAME'Access, 3 => COL_2_2_NAME'Access, 4 => COL_3_2_NAME'Access, 5 => COL_4_2_NAME'Access, 6 => COL_5_2_NAME'Access, 7 => COL_6_2_NAME'Access) ); CITY_TABLE : constant ADO.Schemas.Class_Mapping_Access := CITY_DEF'Access; Null_City : constant City_Ref := City_Ref'(ADO.Objects.Object_Ref with null record); type City_Impl is new ADO.Objects.Object_Record (Key_Type => ADO.Objects.KEY_INTEGER, Of_Class => CITY_DEF'Access) with record Name : Ada.Strings.Unbounded.Unbounded_String; Zip_Code : Integer; Latitude : Integer; Longitude : Integer; Region : Region_Ref; Country : Country_Ref; end record; type City_Access is access all City_Impl; overriding procedure Destroy (Object : access City_Impl); overriding procedure Find (Object : in out City_Impl; Session : in out ADO.Sessions.Session'Class; Query : in ADO.SQL.Query'Class; Found : out Boolean); overriding procedure Load (Object : in out City_Impl; Session : in out ADO.Sessions.Session'Class); procedure Load (Object : in out City_Impl; Stmt : in out ADO.Statements.Query_Statement'Class; Session : in out ADO.Sessions.Session'Class); overriding procedure Save (Object : in out City_Impl; Session : in out ADO.Sessions.Master_Session'Class); overriding procedure Create (Object : in out City_Impl; Session : in out ADO.Sessions.Master_Session'Class); overriding procedure Delete (Object : in out City_Impl; Session : in out ADO.Sessions.Master_Session'Class); procedure Set_Field (Object : in out City_Ref'Class; Impl : out City_Access); COUNTRY_NEIGHBOR_NAME : aliased constant String := "awa_country_neighbor"; COL_0_3_NAME : aliased constant String := "id"; COL_1_3_NAME : aliased constant String := "neighbor_of_id"; COL_2_3_NAME : aliased constant String := "neighbor_id"; COUNTRY_NEIGHBOR_DEF : aliased constant ADO.Schemas.Class_Mapping := (Count => 3, Table => COUNTRY_NEIGHBOR_NAME'Access, Members => ( 1 => COL_0_3_NAME'Access, 2 => COL_1_3_NAME'Access, 3 => COL_2_3_NAME'Access) ); COUNTRY_NEIGHBOR_TABLE : constant ADO.Schemas.Class_Mapping_Access := COUNTRY_NEIGHBOR_DEF'Access; Null_Country_Neighbor : constant Country_Neighbor_Ref := Country_Neighbor_Ref'(ADO.Objects.Object_Ref with null record); type Country_Neighbor_Impl is new ADO.Objects.Object_Record (Key_Type => ADO.Objects.KEY_INTEGER, Of_Class => COUNTRY_NEIGHBOR_DEF'Access) with record Neighbor_Of : Country_Ref; Neighbor : Country_Ref; end record; type Country_Neighbor_Access is access all Country_Neighbor_Impl; overriding procedure Destroy (Object : access Country_Neighbor_Impl); overriding procedure Find (Object : in out Country_Neighbor_Impl; Session : in out ADO.Sessions.Session'Class; Query : in ADO.SQL.Query'Class; Found : out Boolean); overriding procedure Load (Object : in out Country_Neighbor_Impl; Session : in out ADO.Sessions.Session'Class); procedure Load (Object : in out Country_Neighbor_Impl; Stmt : in out ADO.Statements.Query_Statement'Class; Session : in out ADO.Sessions.Session'Class); overriding procedure Save (Object : in out Country_Neighbor_Impl; Session : in out ADO.Sessions.Master_Session'Class); overriding procedure Create (Object : in out Country_Neighbor_Impl; Session : in out ADO.Sessions.Master_Session'Class); overriding procedure Delete (Object : in out Country_Neighbor_Impl; Session : in out ADO.Sessions.Master_Session'Class); procedure Set_Field (Object : in out Country_Neighbor_Ref'Class; Impl : out Country_Neighbor_Access); REGION_NAME : aliased constant String := "awa_region"; COL_0_4_NAME : aliased constant String := "id"; COL_1_4_NAME : aliased constant String := "name"; COL_2_4_NAME : aliased constant String := "geonameid"; COL_3_4_NAME : aliased constant String := "country_id"; REGION_DEF : aliased constant ADO.Schemas.Class_Mapping := (Count => 4, Table => REGION_NAME'Access, Members => ( 1 => COL_0_4_NAME'Access, 2 => COL_1_4_NAME'Access, 3 => COL_2_4_NAME'Access, 4 => COL_3_4_NAME'Access) ); REGION_TABLE : constant ADO.Schemas.Class_Mapping_Access := REGION_DEF'Access; Null_Region : constant Region_Ref := Region_Ref'(ADO.Objects.Object_Ref with null record); type Region_Impl is new ADO.Objects.Object_Record (Key_Type => ADO.Objects.KEY_INTEGER, Of_Class => REGION_DEF'Access) with record Name : Ada.Strings.Unbounded.Unbounded_String; Geonameid : Integer; Country : Country_Ref; end record; type Region_Access is access all Region_Impl; overriding procedure Destroy (Object : access Region_Impl); overriding procedure Find (Object : in out Region_Impl; Session : in out ADO.Sessions.Session'Class; Query : in ADO.SQL.Query'Class; Found : out Boolean); overriding procedure Load (Object : in out Region_Impl; Session : in out ADO.Sessions.Session'Class); procedure Load (Object : in out Region_Impl; Stmt : in out ADO.Statements.Query_Statement'Class; Session : in out ADO.Sessions.Session'Class); overriding procedure Save (Object : in out Region_Impl; Session : in out ADO.Sessions.Master_Session'Class); overriding procedure Create (Object : in out Region_Impl; Session : in out ADO.Sessions.Master_Session'Class); overriding procedure Delete (Object : in out Region_Impl; Session : in out ADO.Sessions.Master_Session'Class); procedure Set_Field (Object : in out Region_Ref'Class; Impl : out Region_Access); end AWA.Countries.Models;
stcarrez/ada-servlet
Ada
4,431
adb
----------------------------------------------------------------------- -- monitor - A simple monitor API -- Copyright (C) 2016, 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 Servlet.Responses; package body Monitor is type Monitor_Array is array (1 .. MAX_MONITOR) of Monitor_Data; Monitors : Monitor_Array; -- Get values of the monitor. procedure Get_Values (Req : in out Servlet.Rest.Request'Class; Reply : in out Servlet.Rest.Response'Class; Stream : in out Servlet.Rest.Output_Stream'Class) is Id : constant String := Req.Get_Path_Parameter (1); Pos : Positive; begin Pos := Positive'Value (Id); -- Monitors (Pos).Put (0); -- Get the monitor values. declare Values : constant Value_Array := Monitors (Pos).Get_Values; begin -- Write the JSON/XML document. Stream.Start_Document; Stream.Start_Array ("values"); for V of Values loop Stream.Write_Long_Entity ("value", Long_Long_Integer (V)); end loop; Stream.End_Array ("values"); Stream.End_Document; end; exception when others => Reply.Set_Status (Servlet.Responses.SC_NOT_FOUND); end Get_Values; -- PUT /mon/:id procedure Put_Value (Req : in out Servlet.Rest.Request'Class; Reply : in out Servlet.Rest.Response'Class; Stream : in out Servlet.Rest.Output_Stream'Class) is pragma Unreferenced (Stream); Id : constant String := Req.Get_Path_Parameter (1); Pos : Positive; Val : Natural; begin Pos := Positive'Value (Id); begin Val := Natural'Value (Req.Get_Parameter ("value")); Monitors (Pos).Put (Val); exception when others => Reply.Set_Status (Servlet.Responses.SC_BAD_REQUEST); end; exception when others => Reply.Set_Status (Servlet.Responses.SC_NOT_FOUND); end Put_Value; protected body Monitor_Data is procedure Put (Value : in Natural) is use type Ada.Calendar.Time; Now : constant Ada.Calendar.Time := Ada.Calendar.Clock; Dt : constant Duration := Now - Slot_Start; Cnt : Natural := Natural (Dt / Slot_Size); begin if Cnt > 0 then while Cnt > 0 loop Cnt := Cnt - 1; Pos := Pos + 1; if Pos > Values'Last then Pos := Values'First; Value_Count := Values'Length; elsif Value_Count < Values'Length then Value_Count := Value_Count + 1; end if; Slot_Start := Slot_Start + Slot_Size; end loop; end if; Values (Pos) := Value; end Put; procedure Put (Value : in Natural; Slot : in Natural) is begin null; end Put; function Get_Values return Value_Array is Result : Value_Array (1 .. Value_Count); Cnt : Natural; N : Natural; begin if Value_Count = Values'Length then Cnt := Values'Last - Pos; else Cnt := 0; end if; if Cnt > 0 then Result (1 .. Cnt) := Values (Pos + 1 .. Pos + 1 + Cnt - 1); N := Cnt + 1; else N := 1; end if; if Value_Count = Values'Length then Cnt := Pos; else Cnt := Pos - 1; end if; if Cnt > 0 then Result (N .. N + Cnt - 1) := Values (1 .. Cnt); end if; return Result; end Get_Values; end Monitor_Data; end Monitor;
reznikmm/matreshka
Ada
18,522
adb
------------------------------------------------------------------------------ -- -- -- 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.Internals.Elements; with AMF.Internals.Extents; with AMF.Internals.Helpers; with AMF.Internals.Links; with AMF.Internals.Listener_Registry; with AMF.Internals.Tables.DD_Constructors; with AMF.Internals.Tables.DG_Metamodel; package body AMF.Internals.Factories.DG_Factories is ----------------- -- Constructor -- ----------------- function Constructor (Extent : AMF.Internals.AMF_Extent) return not null AMF.Factories.Factory_Access is begin return new DG_Factory'(Extent => Extent); end Constructor; ----------------------- -- Convert_To_String -- ----------------------- overriding function Convert_To_String (Self : not null access DG_Factory; Data_Type : not null access AMF.CMOF.Data_Types.CMOF_Data_Type'Class; Value : League.Holders.Holder) return League.Strings.Universal_String is begin raise Program_Error; return League.Strings.Empty_Universal_String; end Convert_To_String; ------------ -- Create -- ------------ overriding function Create (Self : not null access DG_Factory; Meta_Class : not null access AMF.CMOF.Classes.CMOF_Class'Class) return not null AMF.Elements.Element_Access is MC : constant AMF.Internals.CMOF_Element := AMF.Internals.Elements.Element_Base'Class (Meta_Class.all).Element; Element : AMF.Internals.AMF_Element; begin if MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Canvas then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Canvas; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Circle then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Circle; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Clip_Path then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Clip_Path; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Ellipse then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Ellipse; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Group then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Group; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Image then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Image; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Line then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Line; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Linear_Gradient then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Linear_Gradient; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Marked_Element then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Marked_Element; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Marker then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Marker; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Path then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Path; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Pattern then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Pattern; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Polygon then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Polygon; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Polyline then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Polyline; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Radial_Gradient then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Radial_Gradient; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Rectangle then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Rectangle; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Style then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Style; elsif MC = AMF.Internals.Tables.DG_Metamodel.MC_DG_Text then Element := AMF.Internals.Tables.DD_Constructors.Create_DG_Text; else raise Program_Error; end if; AMF.Internals.Extents.Internal_Append (Self.Extent, Element); AMF.Internals.Listener_Registry.Notify_Instance_Create (AMF.Internals.Helpers.To_Element (Element)); return AMF.Internals.Helpers.To_Element (Element); end Create; ------------------------ -- Create_From_String -- ------------------------ overriding function Create_From_String (Self : not null access DG_Factory; Data_Type : not null access AMF.CMOF.Data_Types.CMOF_Data_Type'Class; Image : League.Strings.Universal_String) return League.Holders.Holder is begin raise Program_Error; return League.Holders.Empty_Holder; end Create_From_String; ----------------- -- Create_Link -- ----------------- overriding function Create_Link (Self : not null access DG_Factory; Association : not null access AMF.CMOF.Associations.CMOF_Association'Class; First_Element : not null AMF.Elements.Element_Access; Second_Element : not null AMF.Elements.Element_Access) return not null AMF.Links.Link_Access is pragma Unreferenced (Self); begin return AMF.Internals.Links.Proxy (AMF.Internals.Links.Create_Link (AMF.Internals.Elements.Element_Base'Class (Association.all).Element, AMF.Internals.Helpers.To_Element (First_Element), AMF.Internals.Helpers.To_Element (Second_Element))); end Create_Link; ----------------- -- Get_Package -- ----------------- overriding function Get_Package (Self : not null access constant DG_Factory) return AMF.CMOF.Packages.Collections.Set_Of_CMOF_Package is pragma Unreferenced (Self); begin return Result : AMF.CMOF.Packages.Collections.Set_Of_CMOF_Package do Result.Add (Get_Package); end return; end Get_Package; ----------------- -- Get_Package -- ----------------- function Get_Package return not null AMF.CMOF.Packages.CMOF_Package_Access is begin return AMF.CMOF.Packages.CMOF_Package_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MM_DG_DG)); end Get_Package; ------------------- -- Create_Canvas -- ------------------- overriding function Create_Canvas (Self : not null access DG_Factory) return AMF.DG.Canvases.DG_Canvas_Access is begin return AMF.DG.Canvases.DG_Canvas_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Canvas)))); end Create_Canvas; ------------------- -- Create_Circle -- ------------------- overriding function Create_Circle (Self : not null access DG_Factory) return AMF.DG.Circles.DG_Circle_Access is begin return AMF.DG.Circles.DG_Circle_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Circle)))); end Create_Circle; ---------------------- -- Create_Clip_Path -- ---------------------- overriding function Create_Clip_Path (Self : not null access DG_Factory) return AMF.DG.Clip_Paths.DG_Clip_Path_Access is begin return AMF.DG.Clip_Paths.DG_Clip_Path_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Clip_Path)))); end Create_Clip_Path; -------------------- -- Create_Ellipse -- -------------------- overriding function Create_Ellipse (Self : not null access DG_Factory) return AMF.DG.Ellipses.DG_Ellipse_Access is begin return AMF.DG.Ellipses.DG_Ellipse_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Ellipse)))); end Create_Ellipse; ------------------ -- Create_Group -- ------------------ overriding function Create_Group (Self : not null access DG_Factory) return AMF.DG.Groups.DG_Group_Access is begin return AMF.DG.Groups.DG_Group_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Group)))); end Create_Group; ------------------ -- Create_Image -- ------------------ overriding function Create_Image (Self : not null access DG_Factory) return AMF.DG.Images.DG_Image_Access is begin return AMF.DG.Images.DG_Image_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Image)))); end Create_Image; ----------------- -- Create_Line -- ----------------- overriding function Create_Line (Self : not null access DG_Factory) return AMF.DG.Lines.DG_Line_Access is begin return AMF.DG.Lines.DG_Line_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Line)))); end Create_Line; ---------------------------- -- Create_Linear_Gradient -- ---------------------------- overriding function Create_Linear_Gradient (Self : not null access DG_Factory) return AMF.DG.Linear_Gradients.DG_Linear_Gradient_Access is begin return AMF.DG.Linear_Gradients.DG_Linear_Gradient_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Linear_Gradient)))); end Create_Linear_Gradient; --------------------------- -- Create_Marked_Element -- --------------------------- overriding function Create_Marked_Element (Self : not null access DG_Factory) return AMF.DG.Marked_Elements.DG_Marked_Element_Access is begin return AMF.DG.Marked_Elements.DG_Marked_Element_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Marked_Element)))); end Create_Marked_Element; ------------------- -- Create_Marker -- ------------------- overriding function Create_Marker (Self : not null access DG_Factory) return AMF.DG.Markers.DG_Marker_Access is begin return AMF.DG.Markers.DG_Marker_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Marker)))); end Create_Marker; ----------------- -- Create_Path -- ----------------- overriding function Create_Path (Self : not null access DG_Factory) return AMF.DG.Paths.DG_Path_Access is begin return AMF.DG.Paths.DG_Path_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Path)))); end Create_Path; -------------------- -- Create_Pattern -- -------------------- overriding function Create_Pattern (Self : not null access DG_Factory) return AMF.DG.Patterns.DG_Pattern_Access is begin return AMF.DG.Patterns.DG_Pattern_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Pattern)))); end Create_Pattern; -------------------- -- Create_Polygon -- -------------------- overriding function Create_Polygon (Self : not null access DG_Factory) return AMF.DG.Polygons.DG_Polygon_Access is begin return AMF.DG.Polygons.DG_Polygon_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Polygon)))); end Create_Polygon; --------------------- -- Create_Polyline -- --------------------- overriding function Create_Polyline (Self : not null access DG_Factory) return AMF.DG.Polylines.DG_Polyline_Access is begin return AMF.DG.Polylines.DG_Polyline_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Polyline)))); end Create_Polyline; ---------------------------- -- Create_Radial_Gradient -- ---------------------------- overriding function Create_Radial_Gradient (Self : not null access DG_Factory) return AMF.DG.Radial_Gradients.DG_Radial_Gradient_Access is begin return AMF.DG.Radial_Gradients.DG_Radial_Gradient_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Radial_Gradient)))); end Create_Radial_Gradient; ---------------------- -- Create_Rectangle -- ---------------------- overriding function Create_Rectangle (Self : not null access DG_Factory) return AMF.DG.Rectangles.DG_Rectangle_Access is begin return AMF.DG.Rectangles.DG_Rectangle_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Rectangle)))); end Create_Rectangle; ------------------ -- Create_Style -- ------------------ overriding function Create_Style (Self : not null access DG_Factory) return AMF.DG.Styles.DG_Style_Access is begin return AMF.DG.Styles.DG_Style_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Style)))); end Create_Style; ----------------- -- Create_Text -- ----------------- overriding function Create_Text (Self : not null access DG_Factory) return AMF.DG.Texts.DG_Text_Access is begin return AMF.DG.Texts.DG_Text_Access (Self.Create (AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.DG_Metamodel.MC_DG_Text)))); end Create_Text; end AMF.Internals.Factories.DG_Factories;
BrickBot/Bound-T-H8-300
Ada
11,397
adb
-- Topo_Sort (body) -- -- Topological sorting. -- Reference: D.Knuth, Fundamental Algorithms, 1969, page 259. -- Author: Niklas Holsti, Space Systems Finland, 2000. -- -- A component of the Bound-T Worst-Case Execution Time Tool. -- ------------------------------------------------------------------------------- -- Copyright (c) 1999 .. 2015 Tidorum Ltd -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met: -- -- 1. Redistributions of source code must retain the above copyright notice, this -- list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above copyright notice, -- this list of conditions and the following disclaimer in the documentation -- and/or other materials provided with the distribution. -- -- This software is provided by the copyright holders and contributors "as is" and -- any express or implied warranties, including, but not limited to, the implied -- warranties of merchantability and fitness for a particular purpose are -- disclaimed. In no event shall the copyright owner or contributors be liable for -- any direct, indirect, incidental, special, exemplary, or consequential damages -- (including, but not limited to, procurement of substitute goods or services; -- loss of use, data, or profits; or business interruption) however caused and -- on any theory of liability, whether in contract, strict liability, or tort -- (including negligence or otherwise) arising in any way out of the use of this -- software, even if advised of the possibility of such damage. -- -- Other modules (files) of this software composition should contain their -- own copyright statements, which may have different copyright and usage -- conditions. The above conditions apply to this file. ------------------------------------------------------------------------------- -- -- $Revision: 1.5 $ -- $Date: 2015/10/24 20:05:52 $ -- -- $Log: topo_sort.adb,v $ -- Revision 1.5 2015/10/24 20:05:52 niklas -- Moved to free licence. -- -- Revision 1.4 2004-04-25 07:53:26 niklas -- First Tidorum version. Handling duplicates. -- -- Revision 1.3 2000/08/18 18:02:43 holsti -- Range of List_Ref_T increased to include Elements. -- -- Revision 1.2 2000/07/12 20:41:24 holsti -- Added Elements parameter for disconnected or singleton graphs. -- -- Revision 1.1 2000/05/07 12:40:02 holsti -- First version -- function Topo_Sort ( Elements : Element_List; Pairs : Pair_List) return Element_List is -- Principle of Operation: -- -- The algorithm has two phases: addition and subtraction. -- -- In the addition phase, the given Elements and Pairs are entered into -- an internal data structure that contains the following: -- -- > The set of all the elements mentioned in Elements or Pairs. -- -- > For each such element E: -- -- - The number of predecessor elements L, that is, the number of -- pairs P in which Lesser(P) = L and Greater(P) = E. -- -- - The list of successor elements S, formed by listing S = Greater(P) -- for all pairs P where Lesser(P) = E. -- -- If Pairs contains duplicates, that is two or more pairs with the -- same Lesser and same Greater elements, these are counted separately -- in the number of predecessors and create as many duplicate entries -- in the successor list. Thus, actually we count and list the incoming -- and outgoing arcs, rather than predecessor and successor elements. -- -- In the subtraction phase, we remove one by one any element that has -- no predecessors and is therefore a "root" or minimal element in the -- Pair order. The removed elements become the sorted element list. When -- an element R is found to be a root (number of predecessors = 0), it -- is appended to the sorted list and removed from the internal data -- structure in the following way: -- -- > Since R has no predecessors, it does not appear in the successor -- list of any other element. Thus those lists need no update. -- -- > Since R is about to be removed from the set, it should no longer be -- counted as a predecessor of its successors. Therefore the successor -- list of R itself is scanned and for every successor element S the -- predecessor count of S is decremented. If the result is zero, S is -- a new root element. -- -- The set of root elements is maintained as a queue, although any order -- could be used (all root elements are by definition incomparable and -- could be emitted in any order). -- -- The set of all elements: -- Max_Elements : constant Natural := Elements'Length + 2 * Pairs'Length; -- -- The maximum number of elements. -- Each component of Elements can define one new element. -- Each component of Pairs can define two new elements. subtype Loc_T is Natural range 0 .. Max_Elements; -- -- Refers to an element in the local element-set if positive. -- Refers to no element if zero. Last_Loc : Loc_T := 0; -- -- Refers to the last element found, which has the highest index. -- Zero if no element found yet. subtype Index_T is Loc_T range 1 .. Loc_T'last; -- -- Refers to an element in the local element-set. -- The valid range is 1 .. Last_Loc. Elems : Element_List (Index_T); -- -- All the elements, in the order they happen to be found in Elements -- and Pairs. The valid ones are Elems(1 .. Last_Loc). There are no -- duplicates in the list. -- -- Predecessor count -- Pred_Count : array (Index_T) of Natural; -- -- For each element, the number of predecessor elements (in fact, -- the number of pairs in which this element is the Greater half). -- -- Successor lists -- Max_List_Nodes : constant Natural := Pairs'Length; -- -- Maximum number of successor list nodes. -- Each component of Pairs defines a successor node. subtype List_Ref_T is Natural range 0 .. Max_List_Nodes; -- -- Refers to a list-pool node, or none if zero. No_List : constant List_Ref_T := 0; -- -- The null list reference. subtype List_Index_T is List_Ref_T range 1 .. List_Ref_T'last; -- -- The non-null list references. Loc : array (List_Index_T) of Loc_T; Next : array (List_Index_T) of List_Ref_T; -- -- These two arrays form the successor list pool. -- For a list node L (List_Ref_T), Loc(L) identifies the element -- in the list node, and Next(L) leads to the next node (if not -- null). Last_List : List_Ref_T := 0; -- -- The last used location in the list pool (Loc, Next). -- Zero if no locations used yet. Succ_List : array (Loc_T) of List_Ref_T; -- -- For each element, refers to the list of the element's direct -- successors (in fact the list of Greater elements for each Pair -- in which the given is the Lesser one). -- -- No_List if there are no successors. -- -- The resulting sorted list: -- subtype Pos_T is Natural range 0 .. Max_Elements; -- -- A position in the sorted result. -- Zero means before the first element. Result : Element_List (Pos_T range 1 .. Max_Elements); -- -- Accumulates the result, sorted in topological order. Last_Result : Pos_T := 0; -- -- Result(1 .. Last_Result) are valid. Last_Subtracted : Pos_T := 0; -- -- The last Result element that has been subtracted from the internal -- data structure (predecessor counts and successor lists). -- The slice Result(1 .. Last_Subtracted) is fully finished. -- The slice Result(Last_Subtracted + 1 .. Last_Result) contains -- elements that have been identified as subtractable (no predecessors) -- but have not yet been subtracted. Pos_Loc : array (Pos_T range 1 .. Max_Elements) of Index_T; -- -- The locations in Elems of the result elements. -- The valid part is Pos_Loc(1 .. Last_Result). procedure Locate ( Elem : in Element; Loc : out Loc_T) -- -- Adds Elem to Elems, if not already there. -- Anyway, returns its location in Loc. -- is begin for I in Elems'First .. Last_Loc loop if Elems(I) = Elem then -- Element was already listed. Loc := I; return; end if; end loop; -- The element is a new one. Last_Loc := Last_Loc + 1; Loc := Last_Loc; Elems (Loc) := Elem; Pred_Count(Loc) := 0; Succ_List (Loc) := No_List; end Locate; procedure Push ( This : in Loc_T; Onto : in out List_Ref_T) -- -- Pushes This on top (head) of the Onto list. -- is begin Last_List := Last_List + 1; Loc (Last_List) := This; Next(Last_List) := Onto; Onto := Last_List; end Push; procedure Add_Result (Loc : in Loc_T) -- -- Adds Elems(Loc) to the Result list. -- is begin Last_Result := Last_Result + 1; Result (Last_Result) := Elems(Loc); Pos_Loc(Last_Result) := Loc; end Add_Result; Unused : Loc_T; -- -- An unused output from Locate, for Elements. Less, Great : Loc_T; -- -- The locations of the Lesser and Greater elements of a Pair. Subtract : Loc_T; -- -- The root element being subtracted from the internal data structures. L : List_Ref_T; -- -- One node (tail) in the successor list of Subtract. Succ : Loc_T; -- -- The location of the successor L. begin -- Topo_Sort -- -- Addition phase: -- -- Enter all the given elements: for E in Elements'Range loop Locate (Elem => Elements(E), Loc => Unused); end loop; -- Scan all order-pairs, count predecessors, list successors: for P in Pairs'range loop -- Record the lesser and greater elements as follows: Locate (Elem => Lesser (Pairs(P)), Loc => Less ); Locate (Elem => Greater(Pairs(P)), Loc => Great); Pred_Count(Great) := Pred_Count(Great) + 1; Push (This => Great, Onto => Succ_List(Less)); end loop; -- -- Subtraction phase: -- -- Collect the initial root queue: for E in Elems'First .. Last_Loc loop if Pred_Count(E) = 0 then Add_Result (E); end if; end loop; -- Emit in linear order, subtracting predecessor-less elements -- one by one and decreasing predecessor counts as predecessors are -- emitted: while Last_Subtracted < Last_Result loop -- There is a Result element that has not yet been subtracted. Subtract := Last_Subtracted + 1; -- Remove this element from its successor's pred-counts: L := Succ_List(Pos_Loc(Subtract)); while L /= No_List loop Succ := Loc(L); Pred_Count(Succ) := Pred_Count(Succ) - 1; if Pred_Count(Succ) = 0 then -- This is a new root. Throw it in the Result. Add_Result (Succ); end if; -- Go on to next successor: L := Next(L); end loop; -- This element has been subtracted: Last_Subtracted := Subtract; end loop; return Result (Result'First .. Last_Result); end Topo_Sort;
jklmnn/ash
Ada
662
adb
with Ada.Text_IO; use Ada.Text_IO; with Ada.Exceptions; use Ada.Exceptions; with Listeners; use Listeners; with CLI; use CLI; procedure Main is Listener_Task : Launch_Listener; l1 : Listeners.Listener := Make_Listener (Port => 3000, Root => "./www1", Host => "localhost"); begin Process_Command_Line_Arguments (l1); Listener_Task.Construct (l1); Listener_Task.Start; Listener_Task.Stop; exception when E : CLI_Argument_Exception => Put_Line ("Error: " & Exception_Message (E)); New_Line; Put_Line ("Example usage: "); Put_Line ("ash [-h HOST] [-p PORT] [-r ROOTDIR]"); end Main;
stcarrez/ada-util
Ada
2,993
adb
----------------------------------------------------------------------- -- decrypt -- Decrypt file using Util.Streams.AES -- Copyright (C) 2019, 2021, 2023 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.Text_IO; with Ada.Command_Line; with Ada.Streams.Stream_IO; with Util.Streams.Files; with Util.Streams.AES; with Util.Encoders.AES; with Util.Encoders.KDF.PBKDF2_HMAC_SHA256; procedure Decrypt is use Util.Encoders.KDF; procedure Decrypt_File (Source : in String; Destination : in String; Password : in String); procedure Decrypt_File (Source : in String; Destination : in String; Password : in String) is In_Stream : aliased Util.Streams.Files.File_Stream; Out_Stream : aliased Util.Streams.Files.File_Stream; Decipher : aliased Util.Streams.AES.Decoding_Stream; Password_Key : constant Util.Encoders.Secret_Key := Util.Encoders.Create (Password); Salt : constant Util.Encoders.Secret_Key := Util.Encoders.Create ("fake-salt"); Key : Util.Encoders.Secret_Key (Length => Util.Encoders.AES.AES_256_Length); begin -- Generate a derived key from the password. PBKDF2_HMAC_SHA256 (Password => Password_Key, Salt => Salt, Counter => 20000, Result => Key); -- Setup file -> input and cipher -> output file streams. In_Stream.Open (Ada.Streams.Stream_IO.In_File, Source); Out_Stream.Create (Mode => Ada.Streams.Stream_IO.Out_File, Name => Destination); Decipher.Produces (Output => Out_Stream'Unchecked_Access, Size => 32768); Decipher.Set_Key (Secret => Key, Mode => Util.Encoders.AES.ECB); -- Copy input to output through the cipher. Util.Streams.Copy (From => In_Stream, Into => Decipher); end Decrypt_File; begin if Ada.Command_Line.Argument_Count /= 3 then Ada.Text_IO.Put_Line ("Usage: decrypt source password destination"); return; end if; Decrypt_File (Source => Ada.Command_Line.Argument (1), Destination => Ada.Command_Line.Argument (3), Password => Ada.Command_Line.Argument (2)); end Decrypt;
sudoadminservices/bugbountyservices
Ada
1,766
ads
-- Copyright 2021 Jeff Foley. All rights reserved. -- Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. local json = require("json") name = "ThreatBook" type = "api" function start() setratelimit(5) end function check() local c local cfg = datasrc_config() if cfg ~= nil then c = cfg.credentials end if (c ~= nil and c.key ~= nil and c.key ~= "") then return true end return false end function vertical(ctx, domain) local c local cfg = datasrc_config() if cfg ~= nil then c = cfg.credentials end if (c == nil or c.key == nil or c.key == "") then return end local resp local vurl = verturl(domain, key) -- Check if the response data is in the graph database if (cfg.ttl ~= nil and cfg.ttl > 0) then resp = obtain_response(cacheurl(domain), cfg.ttl) end if (resp == nil or resp == "") then local err resp, err = request({ url=vurl, headers={['Content-Type']="application/json"}, }) if (err ~= nil and err ~= "") then return end if (cfg.ttl ~= nil and cfg.ttl > 0) then cache_response(cacheurl(domain), resp) end end local d = json.decode(resp) if (d == nil or d.response_code ~= 0 or #(d.sub_domains.data) == 0) then return end for i, sub in pairs(d.sub_domains.data) do newname(ctx, sub) end end function verturl(domain, key) return "https://api.threatbook.cn/v3/domain/sub_domains?apikey=" .. key .. "&resource=" .. domain end function cacheurl(domain) return "https://api.threatbook.cn/v3/domain/sub_domains?resource=" .. domain end
onox/orka
Ada
1,714
adb
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2022 onox <[email protected]> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. with Orka.SIMD.AVX.Integers.Swizzle; with Orka.SIMD.SSE2.Integers.Arithmetic; package body Orka.SIMD.AVX.Integers.Arithmetic.Emulation is use SIMD.AVX.Integers.Swizzle; use SIMD.SSE2.Integers; use SIMD.SSE2.Integers.Arithmetic; function "+" (Left, Right : m256i) return m256i is Left_Low : constant m128i := Extract (Left, 0); Left_High : constant m128i := Extract (Left, 1); Right_Low : constant m128i := Extract (Right, 0); Right_High : constant m128i := Extract (Right, 1); begin return Pack (High => Left_High + Right_High, Low => Left_Low + Right_Low); end "+"; function "-" (Left, Right : m256i) return m256i is Left_Low : constant m128i := Extract (Left, 0); Left_High : constant m128i := Extract (Left, 1); Right_Low : constant m128i := Extract (Right, 0); Right_High : constant m128i := Extract (Right, 1); begin return Pack (High => Left_High - Right_High, Low => Left_Low - Right_Low); end "-"; end Orka.SIMD.AVX.Integers.Arithmetic.Emulation;
charlie5/cBound
Ada
1,649
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_text_8_request_t is -- Item -- type Item is record major_opcode : aliased Interfaces.Unsigned_8; pad0 : aliased Interfaces.Unsigned_8; length : aliased Interfaces.Unsigned_16; drawable : aliased xcb.xcb_drawable_t; gc : aliased xcb.xcb_gcontext_t; x : aliased Interfaces.Integer_16; y : aliased Interfaces.Integer_16; end record; -- Item_Array -- type Item_Array is array (Interfaces.C.size_t range <>) of aliased xcb.xcb_poly_text_8_request_t .Item; -- Pointer -- package C_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_poly_text_8_request_t.Item, Element_Array => xcb.xcb_poly_text_8_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_text_8_request_t .Pointer; -- Pointer_Pointer -- package C_Pointer_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_poly_text_8_request_t.Pointer, Element_Array => xcb.xcb_poly_text_8_request_t.Pointer_Array, Default_Terminator => null); subtype Pointer_Pointer is C_Pointer_Pointers.Pointer; end xcb.xcb_poly_text_8_request_t;
faelys/natools
Ada
819
adb
-- Generated at 2015-06-24 18:19:13 +0000 by Natools.Static_Hash_Maps -- from src/natools-s_expressions-templates-dates-maps.sx with Natools.Static_Maps.S_Expressions.Templates.Dates.Cmds; with Natools.Static_Maps.S_Expressions.Templates.Dates.Zones; function Natools.Static_Maps.S_Expressions.Templates.Dates.T return Boolean is begin for I in Map_1_Keys'Range loop if Natools.Static_Maps.S_Expressions.Templates.Dates.Cmds.Hash (Map_1_Keys (I).all) /= I then return False; end if; end loop; for I in Map_2_Keys'Range loop if Natools.Static_Maps.S_Expressions.Templates.Dates.Zones.Hash (Map_2_Keys (I).all) /= I then return False; end if; end loop; return True; end Natools.Static_Maps.S_Expressions.Templates.Dates.T;
reznikmm/matreshka
Ada
4,597
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_Fo.Font_Family_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Fo_Font_Family_Attribute_Node is begin return Self : Fo_Font_Family_Attribute_Node do Matreshka.ODF_Fo.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Fo_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Fo_Font_Family_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Font_Family_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Fo_URI, Matreshka.ODF_String_Constants.Font_Family_Attribute, Fo_Font_Family_Attribute_Node'Tag); end Matreshka.ODF_Fo.Font_Family_Attributes;
reznikmm/matreshka
Ada
4,539
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- 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$ ------------------------------------------------------------------------------ package body Matreshka.File_Engines is -- package Platform is -- -- -- This package provides platform specific implementation of some -- -- subprograms. Its body is separate compilation unit, it is substituted -- -- to use coresponding version. -- -- function Parse -- (Path : League.Strings.Universal_String) -- return Matreshka.Internals.Files.Shared_File_Information_Access; -- -- Parses the given path and constructs file information object. -- -- end Platform; -- -- package body Platform is separate; ----------- -- Parse -- ----------- -- function Parse -- (Path : League.Strings.Universal_String) -- return Matreshka.Internals.Files.Shared_File_Information_Access is -- begin -- return Constructor (Path).Create_File_Information (Path); ---- return Engine.Create_File_Information (Path); ---- return null; -------- return Platform.Parse (Path); -- end Parse; -- function Parse -- (Path : League.Strings.Universal_String) -- return Matreshka.Internals.Files.Shared_File_Information_Access -- renames Platform.Parse; procedure Dummy is null; end Matreshka.File_Engines;
AdaCore/libadalang
Ada
424
adb
procedure Test is function "+" (X : Integer) return Integer is begin return 0; end; B : Boolean; begin -- The unary `+` below should not resolve to the user-defined `+` operator -- above, even though it's the most visible one. That's because the unary -- `+` operator on `root_integer` takes precedence in ambiguous cases. B := 1.0 * (+1) in 0.0 .. 0.0; pragma Test_Statement; end Test;
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.Num_Suffix_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Style_Num_Suffix_Attribute_Node is begin return Self : Style_Num_Suffix_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_Num_Suffix_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Num_Suffix_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Style_URI, Matreshka.ODF_String_Constants.Num_Suffix_Attribute, Style_Num_Suffix_Attribute_Node'Tag); end Matreshka.ODF_Style.Num_Suffix_Attributes;
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.Style_List_Level_Attributes is pragma Preelaborate; type ODF_Style_List_Level_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Style_List_Level_Attribute_Access is access all ODF_Style_List_Level_Attribute'Class with Storage_Size => 0; end ODF.DOM.Style_List_Level_Attributes;
ekoeppen/STM32_Generic_Ada_Drivers
Ada
5,016
ads
with STM32_SVD; use STM32_SVD; with STM32_SVD.GPIO; with STM32_SVD.USB; with System; package STM32GD.USB is ----------------------------------------------------------------------------- -- Endpoint register and associated types and operations ----------------------------------------------------------------------------- subtype EPxR_EA_Field is STM32_SVD.UInt4; subtype EPxR_STAT_TX_Field is STM32_SVD.UInt2; subtype EPxR_DTOG_TX_Field is STM32_SVD.Bit; subtype EPxR_CTR_TX_Field is STM32_SVD.Bit; subtype EPxR_EP_KIND_Field is STM32_SVD.Bit; subtype EPxR_EP_TYPE_Field is STM32_SVD.UInt2; subtype EPxR_SETUP_Field is STM32_SVD.Bit; subtype EPxR_STAT_RX_Field is STM32_SVD.UInt2; subtype EPxR_DTOG_RX_Field is STM32_SVD.Bit; subtype EPxR_CTR_RX_Field is STM32_SVD.Bit; type EPxR_Register is record -- Endpoint address EA : EPxR_EA_Field := 16#0#; -- Status bits, for transmission transfers STAT_TX : EPxR_STAT_TX_Field := 16#0#; -- Data Toggle, for transmission transfers DTOG_TX : EPxR_DTOG_TX_Field := 16#0#; -- Correct Transfer for transmission CTR_TX : EPxR_CTR_TX_Field := 16#0#; -- Endpoint kind EP_KIND : EPxR_EP_KIND_Field := 16#0#; -- Endpoint type EP_TYPE : EPxR_EP_TYPE_Field := 16#0#; -- Setup transaction completed SETUP : EPxR_SETUP_Field := 16#0#; -- Status bits, for reception transfers STAT_RX : EPxR_STAT_RX_Field := 16#0#; -- Data Toggle, for reception transfers DTOG_RX : EPxR_DTOG_RX_Field := 16#0#; -- Correct transfer for reception CTR_RX : EPxR_CTR_RX_Field := 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 EPxR_Register use record EA at 0 range 0 .. 3; STAT_TX at 0 range 4 .. 5; DTOG_TX at 0 range 6 .. 6; CTR_TX at 0 range 7 .. 7; EP_KIND at 0 range 8 .. 8; EP_TYPE at 0 range 9 .. 10; SETUP at 0 range 11 .. 11; STAT_RX at 0 range 12 .. 13; DTOG_RX at 0 range 14 .. 14; CTR_RX at 0 range 15 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; type EP_Status is (Disabled, Stall, NAK, Valid); for EP_Status use (Disabled => 0, Stall => 1, NAK => 2, Valid => 3); type EP_Type is (Bulk, Control, Iso, Interrupt); for EP_Type use (Bulk => 0, Control => 1, Iso => 2, Interrupt => 3); type Endpoint_Range is range 0 .. 7; type Endpoint_Array_Type is array (Endpoint_Range) of EPxR_Register; USB_Endpoints : aliased Endpoint_Array_Type with Import, Address => System'To_Address (16#40005C00#); function EP_Unused_Reset (BTable_Offset : Integer) return Integer; procedure EP_Unused_Handler (Out_Transaction : Boolean); procedure Set_TX_Status (EP : Endpoint_Range; Status : EP_Status); procedure Set_RX_Status (EP : Endpoint_Range; Status : EP_Status); procedure Set_TX_RX_Status (EP : Endpoint_Range; TX_Status : EP_Status; RX_Status : EP_Status); ----------------------------------------------------------------------------- -- Buffer table types and operations ----------------------------------------------------------------------------- subtype USB_ADDRx_TX is STM32_SVD.UInt16 with Dynamic_Predicate => USB_ADDRx_TX mod 2 = 0; subtype USB_ADDRx_RX is STM32_SVD.UInt16 with Dynamic_Predicate => USB_ADDRx_RX mod 2 = 0; subtype USB_COUNTx_TX is STM32_SVD.UInt10; type USB_COUNTx_RX is record BL_SIZE : STM32_SVD.Bit := 16#0#; NUM_BLOCKS : STM32_SVD.UInt5 := 16#0#; COUNTx_RX : STM32_SVD.UInt10 := 16#0#; end record; for USB_COUNTx_RX use record BL_SIZE at 0 range 15 .. 15; NUM_BLOCKS at 0 range 10 .. 14; COUNTx_RX at 0 range 0 .. 9; end record; type USB_BTABLE_Descriptor is record Addr_TX : USB_ADDRx_TX := 16#0#; Count_TX : USB_COUNTx_TX := 16#0#; Addr_RX : USB_ADDRx_RX := 16#0#; Count_RX : USB_COUNTx_RX; end record; for USB_BTABLE_Descriptor use record Addr_TX at 0 range 0 .. 15; Count_TX at 2 range 0 .. 15; Addr_RX at 4 range 0 .. 15; Count_RX at 6 range 0 .. 15; end record; pragma Warnings (Off, "bits of*unused"); for USB_BTABLE_Descriptor'Size use (4 * 2 + 4 * 2) * 8; pragma Warnings (On, "bits of*unused"); type USB_BTABLE_Descriptor_Array is array (Endpoint_Range) of USB_BTABLE_Descriptor; USB_BTABLE_Descriptors : aliased USB_BTABLE_Descriptor_Array with Import, Address => System'To_Address (16#40006000#); type USB_BTABLE_Type is array (0 .. 1023) of UInt16; USB_BTABLE : aliased USB_BTABLE_Type with Import, Address => System'To_Address (16#40006000#); end STM32GD.USB;
tum-ei-rcs/StratoX
Ada
9,358
adb
-- LED-Library by Emanuel Regnath ([email protected]) Date:2_015-05-20 -- -- Description: -- Portable LED Library that features switching, blinking and morse (non-blocking) -- -- Setup: -- To port the lib to your system, simply overwrite the 2 functions LED_HAL_init -- and LED_HAL_set in the .c file and adjust the HAL part in the .h file -- -- Usage: -- 1. call LED_init which will configure the LED port and pin -- 2. call LED_switch or LED_blink or LED_morse to select the operation mode -- 3. frequently call LED_tick and LED_sync to manage LED timings. -- -- ToDo: Support MORSE function (proper translation of C shifts) with LED; package body LED_Manager with SPARK_Mode is type Bits_8 is mod 2**8; LED_id : LED_Id_Type; -- HAL: adjust these functions to your system -- ---------------------------------------------------------------------------- procedure LED_HAL_init(LED_id : LED_Id_Type) is begin LED.init; end LED_HAL_init; procedure LED_HAL_set(state : LED_State_Type) is begin case state is when ON => LED.on; when OFF => LED.off; end case; end LED_HAL_set; -- ---------------------------------------------------------------------------- type LED_Mode_Type is (FIXED, BLINK, MORSE); LED_mode : LED_Mode_Type := FIXED; LED_state : LED_State_Type := OFF; time_counter : Time_Type := 0; type Pulse_Type is record time_mark_on : Time_Type; time_mark_off : Time_Type; end record; current_pulse : Pulse_Type := (others => 0); -- official morse timings MORSE_DIT_TIME : constant Time_Type := BLINK_TIME; MORSE_DAH_TIME : constant Time_Type := BLINK_TIME * 3; MORSE_PAUSE_TIME : constant Time_Type := BLINK_TIME * 7; Blink_Speed : constant LED_Blink_Speed_Type := (FLASH => BLINK_TIME/2, FAST => BLINK_TIME, SLOW => BLINK_TIME*3 ); -- official morse codes: type morse_alphabet_Type is array (1 .. 26) of Bits_8; morse_alphabet : morse_alphabet_Type := ( -- first 1 bit defines length 2#101#, -- a: .- 2#11000#, -- b: -... 2#11010#, -- c: -.-. 2#1100#, -- d: -.. 2#10#, -- e: . 2#10010#, -- f: ..-. 2#1110#, -- g: --. 2#10000#, -- h: .... 2#100#, -- i: .. 2#10111#, -- j: .--- 2#1101#, -- k: -.- 2#10100#, -- l: .-.. 2#111#, -- m: -- 2#110#, -- n: -. 2#1111#, -- o: --- 2#10110#, -- p: .--. 2#11101#, -- q: --.- 2#1010#, -- r: .-. 2#1000#, -- s: ... 2#11#, -- t: - 2#1001#, -- u: ..- 2#10001#, -- v: ...- 2#1011#, -- w: .-- 2#11001#, -- x: -..- 2#11011#, -- y: -.-- 2#11100# -- z: --.. ); type morse_numbers_Type is array (1 .. 10) of Bits_8; morse_numbers : morse_numbers_Type := ( 2#111111#, -- 0: ----- 2#101111#, -- 1: .---- 2#100111#, -- 2: ..--- 2#100011#, -- 3: ...-- 2#100001#, -- 4: ....- 2#100000#, -- 5: ..... 2#110000#, -- 6: -.... 2#111000#, -- 7: --... 2#111100#, -- 8: ---.. 2#111110# -- 9: ----. ); pattern : Character := ' '; pattern_length : Natural := 0; message : String := ""; message_length : Natural := 0; current_character_pos : Natural := 0; procedure LED_init(id : LED_Id_Type) is begin LED_id := id; LED_HAL_init(id); end LED_init; procedure LED_set(state : LED_State_Type) is begin LED_state := state; LED_HAL_set(LED_state); end LED_set; -- switch functions procedure LED_switchOn is begin LED_mode := FIXED; LED_set(ON); end LED_switchOn; procedure LED_switchOff is begin LED_mode := FIXED; LED_set(OFF); end LED_switchOff; -- blink functions procedure LED_blink(speed : LED_Blink_Type) is pulse_time : constant Time_Type := Blink_Speed(speed); begin LED_blinkPulse(pulse_time, pulse_time); end LED_blink; procedure LED_blinkPulse(on_time : Time_Type; off_time : Time_Type) is begin LED_mode := BLINK; current_pulse.time_mark_on := on_time; current_pulse.time_mark_off := current_pulse.time_mark_on + off_time; end LED_blinkPulse; -- morse functions -- procedure LED_loadNextCharacter is -- current_character : Character := message(current_character_pos); -- begin -- if current_character_pos >= message_length then -- current_character_pos := 0; -- end if; -- -- pattern_length := 1; -- -- if current_character >= 'a' and then current_character <= 'z' then -- a-z -- pattern := morse_alphabet( current_character - 'a' ); -- elsif current_character >= 'A' and then current_character <= 'Z' then -- A-Z -- pattern := morse_alphabet( current_character - 'A' ); -- elsif current_character >= '0' and then current_character <= '9' then -- 0-9 -- pattern := morse_numbers( current_character - '0' ); -- elsif current_character <= 32 then -- space or escape chars -- pattern := 1; -- pause -- else -- pattern := 010_1000; -- wait signal -- end if; -- -- while pattern >> (pattern_length + 1) loop -- pattern_length := pattern_length + 1; -- end loop; -- current_character_pos := current_character_pos + 1; -- end LED_loadNextCharacter; -- procedure LED_morseNextPulse is -- begin -- if pattern_length = 0 then -- LED_loadNextCharacter; -- end if; -- pattern_length := pattern_length - 1; -- -- if pattern = 1 then -- current_pulse.time_mark_on := 0; -- current_pulse.time_mark_off := MORSE_DAH_TIME + MORSE_DIT_TIME; -- + pause from last Character := 7 * DIT_TIME -- else -- if pattern and (Shift_Left(1, pattern_length)) then -- current_pulse.time_mark_on := MORSE_DAH_TIME; -- else -- current_pulse.time_mark_on := MORSE_DIT_TIME; -- end if; -- -- if pattern_length = 0 then -- if current_character_pos < message_length then -- current_pulse.time_mark_off := current_pulse.time_mark_on + MORSE_DAH_TIME; -- else -- current_pulse.time_mark_off := current_pulse.time_mark_on + MORSE_PAUSE_TIME; -- end if; -- else -- current_pulse.time_mark_off := current_pulse.time_mark_on + MORSE_DIT_TIME; -- end if; -- end if; -- end LED_morseNextPulse; -- -- procedure LED_morse(Character* msg_string) is -- begin -- LED_mode := MORSE; -- message_length := 0; -- message := msg_string; -- while message(message_length) /= 0 loop -- message_length := message_length + 1; -- end loop; -- LED_loadNextCharacter; -- end LED_morse; -- sync functions procedure LED_tick(elapsed_time : Time_Type) is begin time_counter := time_counter + elapsed_time; end LED_tick; procedure LED_sync is begin if LED_mode = FIXED then return; -- no timing needed end if; if LED_state = OFF then if time_counter >= current_pulse.time_mark_off then time_counter := 0; if LED_mode = MORSE then null; -- LED_morseNextPulse; end if; if current_pulse.time_mark_on > 0 then LED_set(ON); end if; elsif time_counter < current_pulse.time_mark_on then LED_set(ON); end if; elsif LED_state = ON then if time_counter >= current_pulse.time_mark_on then LED_set(OFF); end if; end if; end LED_sync; end LED_Manager;
zhmu/ananas
Ada
10,608
ads
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- A D A . W I D E _ W I D E _ C H A R A C T E R T S . U N I C O D E -- -- -- -- S p e c -- -- -- -- Copyright (C) 2005-2022, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- Unicode categorization routines for Wide_Wide_Character with System.UTF_32; package Ada.Wide_Wide_Characters.Unicode is pragma Pure; -- The following type defines the categories from the unicode definitions. -- The one addition we make is Fe, which represents the characters FFFE -- and FFFF in any of the planes. type Category is new System.UTF_32.Category; -- Cc Other, Control -- Cf Other, Format -- Cn Other, Not Assigned -- Co Other, Private Use -- Cs Other, Surrogate -- Ll Letter, Lowercase -- Lm Letter, Modifier -- Lo Letter, Other -- Lt Letter, Titlecase -- Lu Letter, Uppercase -- Mc Mark, Spacing Combining -- Me Mark, Enclosing -- Mn Mark, Nonspacing -- Nd Number, Decimal Digit -- Nl Number, Letter -- No Number, Other -- Pc Punctuation, Connector -- Pd Punctuation, Dash -- Pe Punctuation, Close -- Pf Punctuation, Final quote -- Pi Punctuation, Initial quote -- Po Punctuation, Other -- Ps Punctuation, Open -- Sc Symbol, Currency -- Sk Symbol, Modifier -- Sm Symbol, Math -- So Symbol, Other -- Zl Separator, Line -- Zp Separator, Paragraph -- Zs Separator, Space -- Fe relative position FFFE/FFFF in plane function Get_Category (U : Wide_Wide_Character) return Category; pragma Inline (Get_Category); -- Given a Wide_Wide_Character, returns corresponding Category, or Cn if -- the code does not have an assigned unicode category. -- The following functions perform category tests corresponding to lexical -- classes defined in the Ada standard. There are two interfaces for each -- function. The second takes a Category (e.g. returned by Get_Category). -- The first takes a Wide_Wide_Character. The form taking the -- Wide_Wide_Character is typically more efficient than calling -- Get_Category, but if several different tests are to be performed on the -- same code, it is more efficient to use Get_Category to get the category, -- then test the resulting category. function Is_Letter (U : Wide_Wide_Character) return Boolean; function Is_Letter (C : Category) return Boolean; pragma Inline (Is_Letter); -- Returns true iff U is a letter that can be used to start an identifier, -- or if C is one of the corresponding categories, which are the following: -- Letter, Uppercase (Lu) -- Letter, Lowercase (Ll) -- Letter, Titlecase (Lt) -- Letter, Modifier (Lm) -- Letter, Other (Lo) -- Number, Letter (Nl) function Is_Digit (U : Wide_Wide_Character) return Boolean; function Is_Digit (C : Category) return Boolean; pragma Inline (Is_Digit); -- Returns true iff U is a digit that can be used to extend an identifer, -- or if C is one of the corresponding categories, which are the following: -- Number, Decimal_Digit (Nd) function Is_Line_Terminator (U : Wide_Wide_Character) return Boolean; pragma Inline (Is_Line_Terminator); -- Returns true iff U is an allowed line terminator for source programs, -- if U is in the category Zp (Separator, Paragaph), or Zs (Separator, -- Line), or if U is a conventional line terminator (CR, LF, VT, FF). -- There is no category version for this function, since the set of -- characters does not correspond to a set of Unicode categories. function Is_Mark (U : Wide_Wide_Character) return Boolean; function Is_Mark (C : Category) return Boolean; pragma Inline (Is_Mark); -- Returns true iff U is a mark character which can be used to extend an -- identifier, or if C is one of the corresponding categories, which are -- the following: -- Mark, Non-Spacing (Mn) -- Mark, Spacing Combining (Mc) function Is_Other (U : Wide_Wide_Character) return Boolean; function Is_Other (C : Category) return Boolean; pragma Inline (Is_Other); -- Returns true iff U is an other format character, which means that it -- can be used to extend an identifier, but is ignored for the purposes of -- matching of identiers, or if C is one of the corresponding categories, -- which are the following: -- Other, Format (Cf) function Is_Punctuation (U : Wide_Wide_Character) return Boolean; function Is_Punctuation (C : Category) return Boolean; pragma Inline (Is_Punctuation); -- Returns true iff U is a punctuation character that can be used to -- separate pices of an identifier, or if C is one of the corresponding -- categories, which are the following: -- Punctuation, Connector (Pc) function Is_Space (U : Wide_Wide_Character) return Boolean; function Is_Space (C : Category) return Boolean; pragma Inline (Is_Space); -- Returns true iff U is considered a space to be ignored, or if C is one -- of the corresponding categories, which are the following: -- Separator, Space (Zs) function Is_NFKC (U : Wide_Wide_Character) return Boolean; pragma Inline (Is_NFKC); -- Returns True if the Wide_Wide_Character designated by U could be present -- in a string normalized to Normalization Form KC (as defined by Clause -- 21 of ISO/IEC 10646:2017), otherwise returns False. function Is_Non_Graphic (U : Wide_Wide_Character) return Boolean; function Is_Non_Graphic (C : Category) return Boolean; pragma Inline (Is_Non_Graphic); -- Returns true iff U is considered to be a non-graphic character, or if C -- is one of the corresponding categories, which are the following: -- Other, Control (Cc) -- Other, Private Use (Co) -- Other, Surrogate (Cs) -- Separator, Line (Zl) -- Separator, Paragraph (Zp) -- FFFE or FFFF positions in any plane (Fe) -- -- Note that the Ada category format effector is subsumed by the above -- list of Unicode categories. -- -- Note that Other, Unassiged (Cn) is quite deliberately not included -- in the list of categories above. This means that should any of these -- code positions be defined in future with graphic characters they will -- be allowed without a need to change implementations or the standard. -- -- Note that Other, Format (Cf) is also quite deliberately not included -- in the list of categories above. This means that these characters can -- be included in character and string literals. function Is_Basic (U : Wide_Wide_Character) return Boolean; pragma Inline (Is_Basic); -- Returns True if the Wide_Wide_Character designated by Item has no -- Decomposition Mapping in the code charts of ISO/IEC 10646:2017, -- otherwise returns False. function To_Basic (U : Wide_Wide_Character) return Wide_Wide_Character; pragma Inline (To_Basic); -- Returns the Wide_Wide_Character whose code point is given by the first -- value of its Decomposition Mapping in the code charts of -- ISO/IEC 10646:2017 if any, returns Item otherwise. -- The following function is used to fold to upper case, as required by -- the Ada 2005 standard rules for identifier case folding. Two -- identifiers are equivalent if they are identical after folding all -- letters to upper case using this routine. A fold to lower routine is -- also provided. function To_Lower_Case (U : Wide_Wide_Character) return Wide_Wide_Character; pragma Inline (To_Lower_Case); -- If U represents an upper case letter, returns the corresponding lower -- case letter, otherwise U is returned unchanged. The folding is locale -- independent as defined by documents referenced in the note in section -- 1 of ISO/IEC 10646:2003 function To_Upper_Case (U : Wide_Wide_Character) return Wide_Wide_Character; pragma Inline (To_Upper_Case); -- If U represents a lower case letter, returns the corresponding upper -- case letter, otherwise U is returned unchanged. The folding is locale -- independent as defined by documents referenced in the note in section -- 1 of ISO/IEC 10646:2003 end Ada.Wide_Wide_Characters.Unicode;
stcarrez/ada-awa
Ada
2,591
ads
----------------------------------------------------------------------- -- awa-jobs-beans -- AWA Jobs Ada Beans -- Copyright (C) 2012, 2015 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Util.Beans.Objects; with Util.Beans.Basic; with Util.Beans.Methods; with AWA.Events; with AWA.Jobs.Services; with AWA.Jobs.Modules; package AWA.Jobs.Beans is -- The <tt>Process_Bean</tt> is the Ada bean that receives the job event and -- performs the job action associated with it. type Process_Bean is limited new Util.Beans.Basic.Bean and Util.Beans.Methods.Method_Bean with private; type Process_Bean_Access is access all Process_Bean'Class; -- Get the value identified by the name. overriding function Get_Value (From : in Process_Bean; Name : in String) return Util.Beans.Objects.Object; -- Set the value identified by the name. overriding procedure Set_Value (From : in out Process_Bean; Name : in String; Value : in Util.Beans.Objects.Object); -- This bean provides some methods that can be used in a Method_Expression overriding function Get_Method_Bindings (From : in Process_Bean) return Util.Beans.Methods.Method_Binding_Array_Access; -- Execute the job described by the event. procedure Execute (Bean : in out Process_Bean; Event : in AWA.Events.Module_Event'Class); -- Create the job process bean instance. function Create_Process_Bean (Module : in AWA.Jobs.Modules.Job_Module_Access) return Util.Beans.Basic.Readonly_Bean_Access; private type Process_Bean is limited new Util.Beans.Basic.Bean and Util.Beans.Methods.Method_Bean with record Module : AWA.Jobs.Modules.Job_Module_Access; Job : AWA.Jobs.Services.Job_Ref; end record; end AWA.Jobs.Beans;
wookey-project/ewok-legacy
Ada
959
adb
-- -- Copyright 2018 The wookey project team <[email protected]> -- - Ryad Benadjila -- - Arnauld Michelizza -- - Mathieu Renard -- - Philippe Thierry -- - Philippe Trebuchet -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- package body ewok.exti.interfaces with spark_mode => off is procedure interfaces_init is begin ewok.exti.init; end interfaces_init; end ewok.exti.interfaces;
AdaCore/libadalang
Ada
826,935
adb
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E M _ C H 3 -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2017, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Aspects; use Aspects; with Atree; use Atree; with Checks; use Checks; with Contracts; use Contracts; with Debug; use Debug; with Elists; use Elists; with Einfo; use Einfo; with Errout; use Errout; with Eval_Fat; use Eval_Fat; with Exp_Ch3; use Exp_Ch3; with Exp_Ch9; use Exp_Ch9; with Exp_Disp; use Exp_Disp; with Exp_Dist; use Exp_Dist; with Exp_Tss; use Exp_Tss; with Exp_Util; use Exp_Util; with Freeze; use Freeze; with Ghost; use Ghost; with Itypes; use Itypes; with Layout; use Layout; with Lib; use Lib; with Lib.Xref; use Lib.Xref; with Namet; use Namet; with Nmake; use Nmake; with Opt; use Opt; with Restrict; use Restrict; with Rident; use Rident; with Rtsfind; use Rtsfind; with Sem; use Sem; with Sem_Aux; use Sem_Aux; with Sem_Case; use Sem_Case; with Sem_Cat; use Sem_Cat; with Sem_Ch6; use Sem_Ch6; with Sem_Ch7; use Sem_Ch7; with Sem_Ch8; use Sem_Ch8; with Sem_Ch13; use Sem_Ch13; with Sem_Dim; use Sem_Dim; with Sem_Disp; use Sem_Disp; with Sem_Dist; use Sem_Dist; with Sem_Elim; use Sem_Elim; with Sem_Eval; use Sem_Eval; with Sem_Mech; use Sem_Mech; with Sem_Res; use Sem_Res; with Sem_Smem; use Sem_Smem; with Sem_Type; use Sem_Type; with Sem_Util; use Sem_Util; with Sem_Warn; use Sem_Warn; with Stand; use Stand; with Sinfo; use Sinfo; with Sinput; use Sinput; with Snames; use Snames; with Targparm; use Targparm; with Tbuild; use Tbuild; with Ttypes; use Ttypes; with Uintp; use Uintp; with Urealp; use Urealp; package body Sem_Ch3 is ----------------------- -- Local Subprograms -- ----------------------- procedure Add_Interface_Tag_Components (N : Node_Id; Typ : Entity_Id); -- Ada 2005 (AI-251): Add the tag components corresponding to all the -- abstract interface types implemented by a record type or a derived -- record type. procedure Build_Derived_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id; Is_Completion : Boolean; Derive_Subps : Boolean := True); -- Create and decorate a Derived_Type given the Parent_Type entity. N is -- the N_Full_Type_Declaration node containing the derived type definition. -- Parent_Type is the entity for the parent type in the derived type -- definition and Derived_Type the actual derived type. Is_Completion must -- be set to False if Derived_Type is the N_Defining_Identifier node in N -- (i.e. Derived_Type = Defining_Identifier (N)). In this case N is not the -- completion of a private type declaration. If Is_Completion is set to -- True, N is the completion of a private type declaration and Derived_Type -- is different from the defining identifier inside N (i.e. Derived_Type /= -- Defining_Identifier (N)). Derive_Subps indicates whether the parent -- subprograms should be derived. The only case where this parameter is -- False is when Build_Derived_Type is recursively called to process an -- implicit derived full type for a type derived from a private type (in -- that case the subprograms must only be derived for the private view of -- the type). -- -- ??? These flags need a bit of re-examination and re-documentation: -- ??? are they both necessary (both seem related to the recursion)? procedure Build_Derived_Access_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id); -- Subsidiary procedure to Build_Derived_Type. For a derived access type, -- create an implicit base if the parent type is constrained or if the -- subtype indication has a constraint. procedure Build_Derived_Array_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id); -- Subsidiary procedure to Build_Derived_Type. For a derived array type, -- create an implicit base if the parent type is constrained or if the -- subtype indication has a constraint. procedure Build_Derived_Concurrent_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id); -- Subsidiary procedure to Build_Derived_Type. For a derived task or -- protected type, inherit entries and protected subprograms, check -- legality of discriminant constraints if any. procedure Build_Derived_Enumeration_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id); -- Subsidiary procedure to Build_Derived_Type. For a derived enumeration -- type, we must create a new list of literals. Types derived from -- Character and [Wide_]Wide_Character are special-cased. procedure Build_Derived_Numeric_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id); -- Subsidiary procedure to Build_Derived_Type. For numeric types, create -- an anonymous base type, and propagate constraint to subtype if needed. procedure Build_Derived_Private_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id; Is_Completion : Boolean; Derive_Subps : Boolean := True); -- Subsidiary procedure to Build_Derived_Type. This procedure is complex -- because the parent may or may not have a completion, and the derivation -- may itself be a completion. procedure Build_Derived_Record_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id; Derive_Subps : Boolean := True); -- Subsidiary procedure used for tagged and untagged record types -- by Build_Derived_Type and Analyze_Private_Extension_Declaration. -- All parameters are as in Build_Derived_Type except that N, in -- addition to being an N_Full_Type_Declaration node, can also be an -- N_Private_Extension_Declaration node. See the definition of this routine -- for much more info. Derive_Subps indicates whether subprograms should be -- derived from the parent type. The only case where Derive_Subps is False -- is for an implicit derived full type for a type derived from a private -- type (see Build_Derived_Type). procedure Build_Discriminal (Discrim : Entity_Id); -- Create the discriminal corresponding to discriminant Discrim, that is -- the parameter corresponding to Discrim to be used in initialization -- procedures for the type where Discrim is a discriminant. Discriminals -- are not used during semantic analysis, and are not fully defined -- entities until expansion. Thus they are not given a scope until -- initialization procedures are built. function Build_Discriminant_Constraints (T : Entity_Id; Def : Node_Id; Derived_Def : Boolean := False) return Elist_Id; -- Validate discriminant constraints and return the list of the constraints -- in order of discriminant declarations, where T is the discriminated -- unconstrained type. Def is the N_Subtype_Indication node where the -- discriminants constraints for T are specified. Derived_Def is True -- when building the discriminant constraints in a derived type definition -- of the form "type D (...) is new T (xxx)". In this case T is the parent -- type and Def is the constraint "(xxx)" on T and this routine sets the -- Corresponding_Discriminant field of the discriminants in the derived -- type D to point to the corresponding discriminants in the parent type T. procedure Build_Discriminated_Subtype (T : Entity_Id; Def_Id : Entity_Id; Elist : Elist_Id; Related_Nod : Node_Id; For_Access : Boolean := False); -- Subsidiary procedure to Constrain_Discriminated_Type and to -- Process_Incomplete_Dependents. Given -- -- T (a possibly discriminated base type) -- Def_Id (a very partially built subtype for T), -- -- the call completes Def_Id to be the appropriate E_*_Subtype. -- -- The Elist is the list of discriminant constraints if any (it is set -- to No_Elist if T is not a discriminated type, and to an empty list if -- T has discriminants but there are no discriminant constraints). The -- Related_Nod is the same as Decl_Node in Create_Constrained_Components. -- The For_Access says whether or not this subtype is really constraining -- an access type. That is its sole purpose is the designated type of an -- access type -- in which case a Private_Subtype Is_For_Access_Subtype -- is built to avoid freezing T when the access subtype is frozen. function Build_Scalar_Bound (Bound : Node_Id; Par_T : Entity_Id; Der_T : Entity_Id) return Node_Id; -- The bounds of a derived scalar type are conversions of the bounds of -- the parent type. Optimize the representation if the bounds are literals. -- Needs a more complete spec--what are the parameters exactly, and what -- exactly is the returned value, and how is Bound affected??? procedure Build_Underlying_Full_View (N : Node_Id; Typ : Entity_Id; Par : Entity_Id); -- If the completion of a private type is itself derived from a private -- type, or if the full view of a private subtype is itself private, the -- back-end has no way to compute the actual size of this type. We build -- an internal subtype declaration of the proper parent type to convey -- this information. This extra mechanism is needed because a full -- view cannot itself have a full view (it would get clobbered during -- view exchanges). procedure Check_Access_Discriminant_Requires_Limited (D : Node_Id; Loc : Node_Id); -- Check the restriction that the type to which an access discriminant -- belongs must be a concurrent type or a descendant of a type with -- the reserved word 'limited' in its declaration. procedure Check_Anonymous_Access_Components (Typ_Decl : Node_Id; Typ : Entity_Id; Prev : Entity_Id; Comp_List : Node_Id); -- Ada 2005 AI-382: an access component in a record definition can refer to -- the enclosing record, in which case it denotes the type itself, and not -- the current instance of the type. We create an anonymous access type for -- the component, and flag it as an access to a component, so accessibility -- checks are properly performed on it. The declaration of the access type -- is placed ahead of that of the record to prevent order-of-elaboration -- circularity issues in Gigi. We create an incomplete type for the record -- declaration, which is the designated type of the anonymous access. procedure Check_Delta_Expression (E : Node_Id); -- Check that the expression represented by E is suitable for use as a -- delta expression, i.e. it is of real type and is static. procedure Check_Digits_Expression (E : Node_Id); -- Check that the expression represented by E is suitable for use as a -- digits expression, i.e. it is of integer type, positive and static. procedure Check_Initialization (T : Entity_Id; Exp : Node_Id); -- Validate the initialization of an object declaration. T is the required -- type, and Exp is the initialization expression. procedure Check_Interfaces (N : Node_Id; Def : Node_Id); -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2) procedure Check_Or_Process_Discriminants (N : Node_Id; T : Entity_Id; Prev : Entity_Id := Empty); -- If N is the full declaration of the completion T of an incomplete or -- private type, check its discriminants (which are already known to be -- conformant with those of the partial view, see Find_Type_Name), -- otherwise process them. Prev is the entity of the partial declaration, -- if any. procedure Check_Real_Bound (Bound : Node_Id); -- Check given bound for being of real type and static. If not, post an -- appropriate message, and rewrite the bound with the real literal zero. procedure Constant_Redeclaration (Id : Entity_Id; N : Node_Id; T : out Entity_Id); -- Various checks on legality of full declaration of deferred constant. -- Id is the entity for the redeclaration, N is the N_Object_Declaration, -- node. The caller has not yet set any attributes of this entity. function Contain_Interface (Iface : Entity_Id; Ifaces : Elist_Id) return Boolean; -- Ada 2005: Determine whether Iface is present in the list Ifaces procedure Convert_Scalar_Bounds (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id; Loc : Source_Ptr); -- For derived scalar types, convert the bounds in the type definition to -- the derived type, and complete their analysis. Given a constraint of the -- form ".. new T range Lo .. Hi", Lo and Hi are analyzed and resolved with -- T'Base, the parent_type. The bounds of the derived type (the anonymous -- base) are copies of Lo and Hi. Finally, the bounds of the derived -- subtype are conversions of those bounds to the derived_type, so that -- their typing is consistent. procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id); -- Copies attributes from array base type T2 to array base type T1. Copies -- only attributes that apply to base types, but not subtypes. procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id); -- Copies attributes from array subtype T2 to array subtype T1. Copies -- attributes that apply to both subtypes and base types. procedure Create_Constrained_Components (Subt : Entity_Id; Decl_Node : Node_Id; Typ : Entity_Id; Constraints : Elist_Id); -- Build the list of entities for a constrained discriminated record -- subtype. If a component depends on a discriminant, replace its subtype -- using the discriminant values in the discriminant constraint. Subt -- is the defining identifier for the subtype whose list of constrained -- entities we will create. Decl_Node is the type declaration node where -- we will attach all the itypes created. Typ is the base discriminated -- type for the subtype Subt. Constraints is the list of discriminant -- constraints for Typ. function Constrain_Component_Type (Comp : Entity_Id; Constrained_Typ : Entity_Id; Related_Node : Node_Id; Typ : Entity_Id; Constraints : Elist_Id) return Entity_Id; -- Given a discriminated base type Typ, a list of discriminant constraints, -- Constraints, for Typ and a component Comp of Typ, create and return the -- type corresponding to Etype (Comp) where all discriminant references -- are replaced with the corresponding constraint. If Etype (Comp) contains -- no discriminant references then it is returned as-is. Constrained_Typ -- is the final constrained subtype to which the constrained component -- belongs. Related_Node is the node where we attach all created itypes. procedure Constrain_Access (Def_Id : in out Entity_Id; S : Node_Id; Related_Nod : Node_Id); -- Apply a list of constraints to an access type. If Def_Id is empty, it is -- an anonymous type created for a subtype indication. In that case it is -- created in the procedure and attached to Related_Nod. procedure Constrain_Array (Def_Id : in out Entity_Id; SI : Node_Id; Related_Nod : Node_Id; Related_Id : Entity_Id; Suffix : Character); -- Apply a list of index constraints to an unconstrained array type. The -- first parameter is the entity for the resulting subtype. A value of -- Empty for Def_Id indicates that an implicit type must be created, but -- creation is delayed (and must be done by this procedure) because other -- subsidiary implicit types must be created first (which is why Def_Id -- is an in/out parameter). The second parameter is a subtype indication -- node for the constrained array to be created (e.g. something of the -- form string (1 .. 10)). Related_Nod gives the place where this type -- has to be inserted in the tree. The Related_Id and Suffix parameters -- are used to build the associated Implicit type name. procedure Constrain_Concurrent (Def_Id : in out Entity_Id; SI : Node_Id; Related_Nod : Node_Id; Related_Id : Entity_Id; Suffix : Character); -- Apply list of discriminant constraints to an unconstrained concurrent -- type. -- -- SI is the N_Subtype_Indication node containing the constraint and -- the unconstrained type to constrain. -- -- Def_Id is the entity for the resulting constrained subtype. A value -- of Empty for Def_Id indicates that an implicit type must be created, -- but creation is delayed (and must be done by this procedure) because -- other subsidiary implicit types must be created first (which is why -- Def_Id is an in/out parameter). -- -- Related_Nod gives the place where this type has to be inserted -- in the tree. -- -- The last two arguments are used to create its external name if needed. function Constrain_Corresponding_Record (Prot_Subt : Entity_Id; Corr_Rec : Entity_Id; Related_Nod : Node_Id) return Entity_Id; -- When constraining a protected type or task type with discriminants, -- constrain the corresponding record with the same discriminant values. procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id); -- Constrain a decimal fixed point type with a digits constraint and/or a -- range constraint, and build E_Decimal_Fixed_Point_Subtype entity. procedure Constrain_Discriminated_Type (Def_Id : Entity_Id; S : Node_Id; Related_Nod : Node_Id; For_Access : Boolean := False); -- Process discriminant constraints of composite type. Verify that values -- have been provided for all discriminants, that the original type is -- unconstrained, and that the types of the supplied expressions match -- the discriminant types. The first three parameters are like in routine -- Constrain_Concurrent. See Build_Discriminated_Subtype for an explanation -- of For_Access. procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id); -- Constrain an enumeration type with a range constraint. This is identical -- to Constrain_Integer, but for the Ekind of the resulting subtype. procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id); -- Constrain a floating point type with either a digits constraint -- and/or a range constraint, building a E_Floating_Point_Subtype. procedure Constrain_Index (Index : Node_Id; S : Node_Id; Related_Nod : Node_Id; Related_Id : Entity_Id; Suffix : Character; Suffix_Index : Nat); -- Process an index constraint S in a constrained array declaration. The -- constraint can be a subtype name, or a range with or without an explicit -- subtype mark. The index is the corresponding index of the unconstrained -- array. The Related_Id and Suffix parameters are used to build the -- associated Implicit type name. procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id); -- Build subtype of a signed or modular integer type procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id); -- Constrain an ordinary fixed point type with a range constraint, and -- build an E_Ordinary_Fixed_Point_Subtype entity. procedure Copy_And_Swap (Priv, Full : Entity_Id); -- Copy the Priv entity into the entity of its full declaration then swap -- the two entities in such a manner that the former private type is now -- seen as a full type. procedure Decimal_Fixed_Point_Type_Declaration (T : Entity_Id; Def : Node_Id); -- Create a new decimal fixed point type, and apply the constraint to -- obtain a subtype of this new type. procedure Complete_Private_Subtype (Priv : Entity_Id; Full : Entity_Id; Full_Base : Entity_Id; Related_Nod : Node_Id); -- Complete the implicit full view of a private subtype by setting the -- appropriate semantic fields. If the full view of the parent is a record -- type, build constrained components of subtype. procedure Derive_Progenitor_Subprograms (Parent_Type : Entity_Id; Tagged_Type : Entity_Id); -- Ada 2005 (AI-251): To complete type derivation, collect the primitive -- operations of progenitors of Tagged_Type, and replace the subsidiary -- subtypes with Tagged_Type, to build the specs of the inherited interface -- primitives. The derived primitives are aliased to those of the -- interface. This routine takes care also of transferring to the full view -- subprograms associated with the partial view of Tagged_Type that cover -- interface primitives. procedure Derived_Standard_Character (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id); -- Subsidiary procedure to Build_Derived_Enumeration_Type which handles -- derivations from types Standard.Character and Standard.Wide_Character. procedure Derived_Type_Declaration (T : Entity_Id; N : Node_Id; Is_Completion : Boolean); -- Process a derived type declaration. Build_Derived_Type is invoked -- to process the actual derived type definition. Parameters N and -- Is_Completion have the same meaning as in Build_Derived_Type. -- T is the N_Defining_Identifier for the entity defined in the -- N_Full_Type_Declaration node N, that is T is the derived type. procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id); -- Insert each literal in symbol table, as an overloadable identifier. Each -- enumeration type is mapped into a sequence of integers, and each literal -- is defined as a constant with integer value. If any of the literals are -- character literals, the type is a character type, which means that -- strings are legal aggregates for arrays of components of the type. function Expand_To_Stored_Constraint (Typ : Entity_Id; Constraint : Elist_Id) return Elist_Id; -- Given a constraint (i.e. a list of expressions) on the discriminants of -- Typ, expand it into a constraint on the stored discriminants and return -- the new list of expressions constraining the stored discriminants. function Find_Type_Of_Object (Obj_Def : Node_Id; Related_Nod : Node_Id) return Entity_Id; -- Get type entity for object referenced by Obj_Def, attaching the implicit -- types generated to Related_Nod. procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id); -- Create a new float and apply the constraint to obtain subtype of it function Has_Range_Constraint (N : Node_Id) return Boolean; -- Given an N_Subtype_Indication node N, return True if a range constraint -- is present, either directly, or as part of a digits or delta constraint. -- In addition, a digits constraint in the decimal case returns True, since -- it establishes a default range if no explicit range is present. function Inherit_Components (N : Node_Id; Parent_Base : Entity_Id; Derived_Base : Entity_Id; Is_Tagged : Boolean; Inherit_Discr : Boolean; Discs : Elist_Id) return Elist_Id; -- Called from Build_Derived_Record_Type to inherit the components of -- Parent_Base (a base type) into the Derived_Base (the derived base type). -- For more information on derived types and component inheritance please -- consult the comment above the body of Build_Derived_Record_Type. -- -- N is the original derived type declaration -- -- Is_Tagged is set if we are dealing with tagged types -- -- If Inherit_Discr is set, Derived_Base inherits its discriminants from -- Parent_Base, otherwise no discriminants are inherited. -- -- Discs gives the list of constraints that apply to Parent_Base in the -- derived type declaration. If Discs is set to No_Elist, then we have -- the following situation: -- -- type Parent (D1..Dn : ..) is [tagged] record ...; -- type Derived is new Parent [with ...]; -- -- which gets treated as -- -- type Derived (D1..Dn : ..) is new Parent (D1,..,Dn) [with ...]; -- -- For untagged types the returned value is an association list. The list -- starts from the association (Parent_Base => Derived_Base), and then it -- contains a sequence of the associations of the form -- -- (Old_Component => New_Component), -- -- where Old_Component is the Entity_Id of a component in Parent_Base and -- New_Component is the Entity_Id of the corresponding component in -- Derived_Base. For untagged records, this association list is needed when -- copying the record declaration for the derived base. In the tagged case -- the value returned is irrelevant. procedure Inherit_Predicate_Flags (Subt, Par : Entity_Id); -- Propagate static and dynamic predicate flags from a parent to the -- subtype in a subtype declaration with and without constraints. function Is_EVF_Procedure (Subp : Entity_Id) return Boolean; -- Subsidiary to Check_Abstract_Overriding and Derive_Subprogram. -- Determine whether subprogram Subp is a procedure subject to pragma -- Extensions_Visible with value False and has at least one controlling -- parameter of mode OUT. function Is_Valid_Constraint_Kind (T_Kind : Type_Kind; Constraint_Kind : Node_Kind) return Boolean; -- Returns True if it is legal to apply the given kind of constraint to the -- given kind of type (index constraint to an array type, for example). procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id); -- Create new modular type. Verify that modulus is in bounds procedure New_Concatenation_Op (Typ : Entity_Id); -- Create an abbreviated declaration for an operator in order to -- materialize concatenation on array types. procedure Ordinary_Fixed_Point_Type_Declaration (T : Entity_Id; Def : Node_Id); -- Create a new ordinary fixed point type, and apply the constraint to -- obtain subtype of it. procedure Prepare_Private_Subtype_Completion (Id : Entity_Id; Related_Nod : Node_Id); -- Id is a subtype of some private type. Creates the full declaration -- associated with Id whenever possible, i.e. when the full declaration -- of the base type is already known. Records each subtype into -- Private_Dependents of the base type. procedure Process_Incomplete_Dependents (N : Node_Id; Full_T : Entity_Id; Inc_T : Entity_Id); -- Process all entities that depend on an incomplete type. There include -- subtypes, subprogram types that mention the incomplete type in their -- profiles, and subprogram with access parameters that designate the -- incomplete type. -- Inc_T is the defining identifier of an incomplete type declaration, its -- Ekind is E_Incomplete_Type. -- -- N is the corresponding N_Full_Type_Declaration for Inc_T. -- -- Full_T is N's defining identifier. -- -- Subtypes of incomplete types with discriminants are completed when the -- parent type is. This is simpler than private subtypes, because they can -- only appear in the same scope, and there is no need to exchange views. -- Similarly, access_to_subprogram types may have a parameter or a return -- type that is an incomplete type, and that must be replaced with the -- full type. -- -- If the full type is tagged, subprogram with access parameters that -- designated the incomplete may be primitive operations of the full type, -- and have to be processed accordingly. procedure Process_Real_Range_Specification (Def : Node_Id); -- Given the type definition for a real type, this procedure processes and -- checks the real range specification of this type definition if one is -- present. If errors are found, error messages are posted, and the -- Real_Range_Specification of Def is reset to Empty. procedure Record_Type_Declaration (T : Entity_Id; N : Node_Id; Prev : Entity_Id); -- Process a record type declaration (for both untagged and tagged -- records). Parameters T and N are exactly like in procedure -- Derived_Type_Declaration, except that no flag Is_Completion is needed -- for this routine. If this is the completion of an incomplete type -- declaration, Prev is the entity of the incomplete declaration, used for -- cross-referencing. Otherwise Prev = T. procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id); -- This routine is used to process the actual record type definition (both -- for untagged and tagged records). Def is a record type definition node. -- This procedure analyzes the components in this record type definition. -- Prev_T is the entity for the enclosing record type. It is provided so -- that its Has_Task flag can be set if any of the component have Has_Task -- set. If the declaration is the completion of an incomplete type -- declaration, Prev_T is the original incomplete type, whose full view is -- the record type. procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id); -- Subsidiary to Build_Derived_Record_Type. For untagged records, we -- build a copy of the declaration tree of the parent, and we create -- independently the list of components for the derived type. Semantic -- information uses the component entities, but record representation -- clauses are validated on the declaration tree. This procedure replaces -- discriminants and components in the declaration with those that have -- been created by Inherit_Components. procedure Set_Fixed_Range (E : Entity_Id; Loc : Source_Ptr; Lo : Ureal; Hi : Ureal); -- Build a range node with the given bounds and set it as the Scalar_Range -- of the given fixed-point type entity. Loc is the source location used -- for the constructed range. See body for further details. procedure Set_Scalar_Range_For_Subtype (Def_Id : Entity_Id; R : Node_Id; Subt : Entity_Id); -- This routine is used to set the scalar range field for a subtype given -- Def_Id, the entity for the subtype, and R, the range expression for the -- scalar range. Subt provides the parent subtype to be used to analyze, -- resolve, and check the given range. procedure Set_Default_SSO (T : Entity_Id); -- T is the entity for an array or record being declared. This procedure -- sets the flags SSO_Set_Low_By_Default/SSO_Set_High_By_Default according -- to the setting of Opt.Default_SSO. procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id); -- Create a new signed integer entity, and apply the constraint to obtain -- the required first named subtype of this type. procedure Set_Stored_Constraint_From_Discriminant_Constraint (E : Entity_Id); -- E is some record type. This routine computes E's Stored_Constraint -- from its Discriminant_Constraint. procedure Diagnose_Interface (N : Node_Id; E : Entity_Id); -- Check that an entity in a list of progenitors is an interface, -- emit error otherwise. ----------------------- -- Access_Definition -- ----------------------- function Access_Definition (Related_Nod : Node_Id; N : Node_Id) return Entity_Id is Anon_Type : Entity_Id; Anon_Scope : Entity_Id; Desig_Type : Entity_Id; Enclosing_Prot_Type : Entity_Id := Empty; begin Check_SPARK_05_Restriction ("access type is not allowed", N); if Is_Entry (Current_Scope) and then Is_Task_Type (Etype (Scope (Current_Scope))) then Error_Msg_N ("task entries cannot have access parameters", N); return Empty; end if; -- Ada 2005: For an object declaration the corresponding anonymous -- type is declared in the current scope. -- If the access definition is the return type of another access to -- function, scope is the current one, because it is the one of the -- current type declaration, except for the pathological case below. if Nkind_In (Related_Nod, N_Object_Declaration, N_Access_Function_Definition) then Anon_Scope := Current_Scope; -- A pathological case: function returning access functions that -- return access functions, etc. Each anonymous access type created -- is in the enclosing scope of the outermost function. declare Par : Node_Id; begin Par := Related_Nod; while Nkind_In (Par, N_Access_Function_Definition, N_Access_Definition) loop Par := Parent (Par); end loop; if Nkind (Par) = N_Function_Specification then Anon_Scope := Scope (Defining_Entity (Par)); end if; end; -- For the anonymous function result case, retrieve the scope of the -- function specification's associated entity rather than using the -- current scope. The current scope will be the function itself if the -- formal part is currently being analyzed, but will be the parent scope -- in the case of a parameterless function, and we always want to use -- the function's parent scope. Finally, if the function is a child -- unit, we must traverse the tree to retrieve the proper entity. elsif Nkind (Related_Nod) = N_Function_Specification and then Nkind (Parent (N)) /= N_Parameter_Specification then -- If the current scope is a protected type, the anonymous access -- is associated with one of the protected operations, and must -- be available in the scope that encloses the protected declaration. -- Otherwise the type is in the scope enclosing the subprogram. -- If the function has formals, The return type of a subprogram -- declaration is analyzed in the scope of the subprogram (see -- Process_Formals) and thus the protected type, if present, is -- the scope of the current function scope. if Ekind (Current_Scope) = E_Protected_Type then Enclosing_Prot_Type := Current_Scope; elsif Ekind (Current_Scope) = E_Function and then Ekind (Scope (Current_Scope)) = E_Protected_Type then Enclosing_Prot_Type := Scope (Current_Scope); end if; if Present (Enclosing_Prot_Type) then Anon_Scope := Scope (Enclosing_Prot_Type); else Anon_Scope := Scope (Defining_Entity (Related_Nod)); end if; -- For an access type definition, if the current scope is a child -- unit it is the scope of the type. elsif Is_Compilation_Unit (Current_Scope) then Anon_Scope := Current_Scope; -- For access formals, access components, and access discriminants, the -- scope is that of the enclosing declaration, else Anon_Scope := Scope (Current_Scope); end if; Anon_Type := Create_Itype (E_Anonymous_Access_Type, Related_Nod, Scope_Id => Anon_Scope); if All_Present (N) and then Ada_Version >= Ada_2005 then Error_Msg_N ("ALL is not permitted for anonymous access types", N); end if; -- Ada 2005 (AI-254): In case of anonymous access to subprograms call -- the corresponding semantic routine if Present (Access_To_Subprogram_Definition (N)) then -- Compiler runtime units are compiled in Ada 2005 mode when building -- the runtime library but must also be compilable in Ada 95 mode -- (when bootstrapping the compiler). Check_Compiler_Unit ("anonymous access to subprogram", N); Access_Subprogram_Declaration (T_Name => Anon_Type, T_Def => Access_To_Subprogram_Definition (N)); if Ekind (Anon_Type) = E_Access_Protected_Subprogram_Type then Set_Ekind (Anon_Type, E_Anonymous_Access_Protected_Subprogram_Type); else Set_Ekind (Anon_Type, E_Anonymous_Access_Subprogram_Type); end if; Set_Can_Use_Internal_Rep (Anon_Type, not Always_Compatible_Rep_On_Target); -- If the anonymous access is associated with a protected operation, -- create a reference to it after the enclosing protected definition -- because the itype will be used in the subsequent bodies. -- If the anonymous access itself is protected, a full type -- declaratiton will be created for it, so that the equivalent -- record type can be constructed. For further details, see -- Replace_Anonymous_Access_To_Protected-Subprogram. if Ekind (Current_Scope) = E_Protected_Type and then not Protected_Present (Access_To_Subprogram_Definition (N)) then Build_Itype_Reference (Anon_Type, Parent (Current_Scope)); end if; return Anon_Type; end if; Find_Type (Subtype_Mark (N)); Desig_Type := Entity (Subtype_Mark (N)); Set_Directly_Designated_Type (Anon_Type, Desig_Type); Set_Etype (Anon_Type, Anon_Type); -- Make sure the anonymous access type has size and alignment fields -- set, as required by gigi. This is necessary in the case of the -- Task_Body_Procedure. if not Has_Private_Component (Desig_Type) then Layout_Type (Anon_Type); end if; -- Ada 2005 (AI-231): Ada 2005 semantics for anonymous access differs -- from Ada 95 semantics. In Ada 2005, anonymous access must specify if -- the null value is allowed. In Ada 95 the null value is never allowed. if Ada_Version >= Ada_2005 then Set_Can_Never_Be_Null (Anon_Type, Null_Exclusion_Present (N)); else Set_Can_Never_Be_Null (Anon_Type, True); end if; -- The anonymous access type is as public as the discriminated type or -- subprogram that defines it. It is imported (for back-end purposes) -- if the designated type is. Set_Is_Public (Anon_Type, Is_Public (Scope (Anon_Type))); -- Ada 2005 (AI-231): Propagate the access-constant attribute Set_Is_Access_Constant (Anon_Type, Constant_Present (N)); -- The context is either a subprogram declaration, object declaration, -- or an access discriminant, in a private or a full type declaration. -- In the case of a subprogram, if the designated type is incomplete, -- the operation will be a primitive operation of the full type, to be -- updated subsequently. If the type is imported through a limited_with -- clause, the subprogram is not a primitive operation of the type -- (which is declared elsewhere in some other scope). if Ekind (Desig_Type) = E_Incomplete_Type and then not From_Limited_With (Desig_Type) and then Is_Overloadable (Current_Scope) then Append_Elmt (Current_Scope, Private_Dependents (Desig_Type)); Set_Has_Delayed_Freeze (Current_Scope); end if; -- Ada 2005: If the designated type is an interface that may contain -- tasks, create a Master entity for the declaration. This must be done -- before expansion of the full declaration, because the declaration may -- include an expression that is an allocator, whose expansion needs the -- proper Master for the created tasks. if Nkind (Related_Nod) = N_Object_Declaration and then Expander_Active then if Is_Interface (Desig_Type) and then Is_Limited_Record (Desig_Type) then Build_Class_Wide_Master (Anon_Type); -- Similarly, if the type is an anonymous access that designates -- tasks, create a master entity for it in the current context. elsif Has_Task (Desig_Type) and then Comes_From_Source (Related_Nod) then Build_Master_Entity (Defining_Identifier (Related_Nod)); Build_Master_Renaming (Anon_Type); end if; end if; -- For a private component of a protected type, it is imperative that -- the back-end elaborate the type immediately after the protected -- declaration, because this type will be used in the declarations -- created for the component within each protected body, so we must -- create an itype reference for it now. if Nkind (Parent (Related_Nod)) = N_Protected_Definition then Build_Itype_Reference (Anon_Type, Parent (Parent (Related_Nod))); -- Similarly, if the access definition is the return result of a -- function, create an itype reference for it because it will be used -- within the function body. For a regular function that is not a -- compilation unit, insert reference after the declaration. For a -- protected operation, insert it after the enclosing protected type -- declaration. In either case, do not create a reference for a type -- obtained through a limited_with clause, because this would introduce -- semantic dependencies. -- Similarly, do not create a reference if the designated type is a -- generic formal, because no use of it will reach the backend. elsif Nkind (Related_Nod) = N_Function_Specification and then not From_Limited_With (Desig_Type) and then not Is_Generic_Type (Desig_Type) then if Present (Enclosing_Prot_Type) then Build_Itype_Reference (Anon_Type, Parent (Enclosing_Prot_Type)); elsif Is_List_Member (Parent (Related_Nod)) and then Nkind (Parent (N)) /= N_Parameter_Specification then Build_Itype_Reference (Anon_Type, Parent (Related_Nod)); end if; -- Finally, create an itype reference for an object declaration of an -- anonymous access type. This is strictly necessary only for deferred -- constants, but in any case will avoid out-of-scope problems in the -- back-end. elsif Nkind (Related_Nod) = N_Object_Declaration then Build_Itype_Reference (Anon_Type, Related_Nod); end if; return Anon_Type; end Access_Definition; ----------------------------------- -- Access_Subprogram_Declaration -- ----------------------------------- procedure Access_Subprogram_Declaration (T_Name : Entity_Id; T_Def : Node_Id) is procedure Check_For_Premature_Usage (Def : Node_Id); -- Check that type T_Name is not used, directly or recursively, as a -- parameter or a return type in Def. Def is either a subtype, an -- access_definition, or an access_to_subprogram_definition. ------------------------------- -- Check_For_Premature_Usage -- ------------------------------- procedure Check_For_Premature_Usage (Def : Node_Id) is Param : Node_Id; begin -- Check for a subtype mark if Nkind (Def) in N_Has_Etype then if Etype (Def) = T_Name then Error_Msg_N ("type& cannot be used before end of its declaration", Def); end if; -- If this is not a subtype, then this is an access_definition elsif Nkind (Def) = N_Access_Definition then if Present (Access_To_Subprogram_Definition (Def)) then Check_For_Premature_Usage (Access_To_Subprogram_Definition (Def)); else Check_For_Premature_Usage (Subtype_Mark (Def)); end if; -- The only cases left are N_Access_Function_Definition and -- N_Access_Procedure_Definition. else if Present (Parameter_Specifications (Def)) then Param := First (Parameter_Specifications (Def)); while Present (Param) loop Check_For_Premature_Usage (Parameter_Type (Param)); Param := Next (Param); end loop; end if; if Nkind (Def) = N_Access_Function_Definition then Check_For_Premature_Usage (Result_Definition (Def)); end if; end if; end Check_For_Premature_Usage; -- Local variables Formals : constant List_Id := Parameter_Specifications (T_Def); Formal : Entity_Id; D_Ityp : Node_Id; Desig_Type : constant Entity_Id := Create_Itype (E_Subprogram_Type, Parent (T_Def)); -- Start of processing for Access_Subprogram_Declaration begin Check_SPARK_05_Restriction ("access type is not allowed", T_Def); -- Associate the Itype node with the inner full-type declaration or -- subprogram spec or entry body. This is required to handle nested -- anonymous declarations. For example: -- procedure P -- (X : access procedure -- (Y : access procedure -- (Z : access T))) D_Ityp := Associated_Node_For_Itype (Desig_Type); while not (Nkind_In (D_Ityp, N_Full_Type_Declaration, N_Private_Type_Declaration, N_Private_Extension_Declaration, N_Procedure_Specification, N_Function_Specification, N_Entry_Body) or else Nkind_In (D_Ityp, N_Object_Declaration, N_Object_Renaming_Declaration, N_Formal_Object_Declaration, N_Formal_Type_Declaration, N_Task_Type_Declaration, N_Protected_Type_Declaration)) loop D_Ityp := Parent (D_Ityp); pragma Assert (D_Ityp /= Empty); end loop; Set_Associated_Node_For_Itype (Desig_Type, D_Ityp); if Nkind_In (D_Ityp, N_Procedure_Specification, N_Function_Specification) then Set_Scope (Desig_Type, Scope (Defining_Entity (D_Ityp))); elsif Nkind_In (D_Ityp, N_Full_Type_Declaration, N_Object_Declaration, N_Object_Renaming_Declaration, N_Formal_Type_Declaration) then Set_Scope (Desig_Type, Scope (Defining_Identifier (D_Ityp))); end if; if Nkind (T_Def) = N_Access_Function_Definition then if Nkind (Result_Definition (T_Def)) = N_Access_Definition then declare Acc : constant Node_Id := Result_Definition (T_Def); begin if Present (Access_To_Subprogram_Definition (Acc)) and then Protected_Present (Access_To_Subprogram_Definition (Acc)) then Set_Etype (Desig_Type, Replace_Anonymous_Access_To_Protected_Subprogram (T_Def)); else Set_Etype (Desig_Type, Access_Definition (T_Def, Result_Definition (T_Def))); end if; end; else Analyze (Result_Definition (T_Def)); declare Typ : constant Entity_Id := Entity (Result_Definition (T_Def)); begin -- If a null exclusion is imposed on the result type, then -- create a null-excluding itype (an access subtype) and use -- it as the function's Etype. if Is_Access_Type (Typ) and then Null_Exclusion_In_Return_Present (T_Def) then Set_Etype (Desig_Type, Create_Null_Excluding_Itype (T => Typ, Related_Nod => T_Def, Scope_Id => Current_Scope)); else if From_Limited_With (Typ) then -- AI05-151: Incomplete types are allowed in all basic -- declarations, including access to subprograms. if Ada_Version >= Ada_2012 then null; else Error_Msg_NE ("illegal use of incomplete type&", Result_Definition (T_Def), Typ); end if; elsif Ekind (Current_Scope) = E_Package and then In_Private_Part (Current_Scope) then if Ekind (Typ) = E_Incomplete_Type then Append_Elmt (Desig_Type, Private_Dependents (Typ)); elsif Is_Class_Wide_Type (Typ) and then Ekind (Etype (Typ)) = E_Incomplete_Type then Append_Elmt (Desig_Type, Private_Dependents (Etype (Typ))); end if; end if; Set_Etype (Desig_Type, Typ); end if; end; end if; if not (Is_Type (Etype (Desig_Type))) then Error_Msg_N ("expect type in function specification", Result_Definition (T_Def)); end if; else Set_Etype (Desig_Type, Standard_Void_Type); end if; if Present (Formals) then Push_Scope (Desig_Type); -- Some special tests here. These special tests can be removed -- if and when Itypes always have proper parent pointers to their -- declarations??? -- Special test 1) Link defining_identifier of formals. Required by -- First_Formal to provide its functionality. declare F : Node_Id; begin F := First (Formals); -- In ASIS mode, the access_to_subprogram may be analyzed twice, -- when it is part of an unconstrained type and subtype expansion -- is disabled. To avoid back-end problems with shared profiles, -- use previous subprogram type as the designated type, and then -- remove scope added above. if ASIS_Mode and then Present (Scope (Defining_Identifier (F))) then Set_Etype (T_Name, T_Name); Init_Size_Align (T_Name); Set_Directly_Designated_Type (T_Name, Scope (Defining_Identifier (F))); End_Scope; return; end if; while Present (F) loop if No (Parent (Defining_Identifier (F))) then Set_Parent (Defining_Identifier (F), F); end if; Next (F); end loop; end; Process_Formals (Formals, Parent (T_Def)); -- Special test 2) End_Scope requires that the parent pointer be set -- to something reasonable, but Itypes don't have parent pointers. So -- we set it and then unset it ??? Set_Parent (Desig_Type, T_Name); End_Scope; Set_Parent (Desig_Type, Empty); end if; -- Check for premature usage of the type being defined Check_For_Premature_Usage (T_Def); -- The return type and/or any parameter type may be incomplete. Mark the -- subprogram_type as depending on the incomplete type, so that it can -- be updated when the full type declaration is seen. This only applies -- to incomplete types declared in some enclosing scope, not to limited -- views from other packages. -- Prior to Ada 2012, access to functions can only have in_parameters. if Present (Formals) then Formal := First_Formal (Desig_Type); while Present (Formal) loop if Ekind (Formal) /= E_In_Parameter and then Nkind (T_Def) = N_Access_Function_Definition and then Ada_Version < Ada_2012 then Error_Msg_N ("functions can only have IN parameters", Formal); end if; if Ekind (Etype (Formal)) = E_Incomplete_Type and then In_Open_Scopes (Scope (Etype (Formal))) then Append_Elmt (Desig_Type, Private_Dependents (Etype (Formal))); Set_Has_Delayed_Freeze (Desig_Type); end if; Next_Formal (Formal); end loop; end if; -- Check whether an indirect call without actuals may be possible. This -- is used when resolving calls whose result is then indexed. May_Need_Actuals (Desig_Type); -- If the return type is incomplete, this is legal as long as the type -- is declared in the current scope and will be completed in it (rather -- than being part of limited view). if Ekind (Etype (Desig_Type)) = E_Incomplete_Type and then not Has_Delayed_Freeze (Desig_Type) and then In_Open_Scopes (Scope (Etype (Desig_Type))) then Append_Elmt (Desig_Type, Private_Dependents (Etype (Desig_Type))); Set_Has_Delayed_Freeze (Desig_Type); end if; Check_Delayed_Subprogram (Desig_Type); if Protected_Present (T_Def) then Set_Ekind (T_Name, E_Access_Protected_Subprogram_Type); Set_Convention (Desig_Type, Convention_Protected); else Set_Ekind (T_Name, E_Access_Subprogram_Type); end if; Set_Can_Use_Internal_Rep (T_Name, not Always_Compatible_Rep_On_Target); Set_Etype (T_Name, T_Name); Init_Size_Align (T_Name); Set_Directly_Designated_Type (T_Name, Desig_Type); Generate_Reference_To_Formals (T_Name); -- Ada 2005 (AI-231): Propagate the null-excluding attribute Set_Can_Never_Be_Null (T_Name, Null_Exclusion_Present (T_Def)); Check_Restriction (No_Access_Subprograms, T_Def); end Access_Subprogram_Declaration; ---------------------------- -- Access_Type_Declaration -- ---------------------------- procedure Access_Type_Declaration (T : Entity_Id; Def : Node_Id) is P : constant Node_Id := Parent (Def); S : constant Node_Id := Subtype_Indication (Def); Full_Desig : Entity_Id; begin Check_SPARK_05_Restriction ("access type is not allowed", Def); -- Check for permissible use of incomplete type if Nkind (S) /= N_Subtype_Indication then Analyze (S); if Present (Entity (S)) and then Ekind (Root_Type (Entity (S))) = E_Incomplete_Type then Set_Directly_Designated_Type (T, Entity (S)); -- If the designated type is a limited view, we cannot tell if -- the full view contains tasks, and there is no way to handle -- that full view in a client. We create a master entity for the -- scope, which will be used when a client determines that one -- is needed. if From_Limited_With (Entity (S)) and then not Is_Class_Wide_Type (Entity (S)) then Set_Ekind (T, E_Access_Type); Build_Master_Entity (T); Build_Master_Renaming (T); end if; else Set_Directly_Designated_Type (T, Process_Subtype (S, P, T, 'P')); end if; -- If the access definition is of the form: ACCESS NOT NULL .. -- the subtype indication must be of an access type. Create -- a null-excluding subtype of it. if Null_Excluding_Subtype (Def) then if not Is_Access_Type (Entity (S)) then Error_Msg_N ("null exclusion must apply to access type", Def); else declare Loc : constant Source_Ptr := Sloc (S); Decl : Node_Id; Nam : constant Entity_Id := Make_Temporary (Loc, 'S'); begin Decl := Make_Subtype_Declaration (Loc, Defining_Identifier => Nam, Subtype_Indication => New_Occurrence_Of (Entity (S), Loc)); Set_Null_Exclusion_Present (Decl); Insert_Before (Parent (Def), Decl); Analyze (Decl); Set_Entity (S, Nam); end; end if; end if; else Set_Directly_Designated_Type (T, Process_Subtype (S, P, T, 'P')); end if; if All_Present (Def) or Constant_Present (Def) then Set_Ekind (T, E_General_Access_Type); else Set_Ekind (T, E_Access_Type); end if; Full_Desig := Designated_Type (T); if Base_Type (Full_Desig) = T then Error_Msg_N ("access type cannot designate itself", S); -- In Ada 2005, the type may have a limited view through some unit in -- its own context, allowing the following circularity that cannot be -- detected earlier. elsif Is_Class_Wide_Type (Full_Desig) and then Etype (Full_Desig) = T then Error_Msg_N ("access type cannot designate its own class-wide type", S); -- Clean up indication of tagged status to prevent cascaded errors Set_Is_Tagged_Type (T, False); end if; Set_Etype (T, T); -- If the type has appeared already in a with_type clause, it is frozen -- and the pointer size is already set. Else, initialize. if not From_Limited_With (T) then Init_Size_Align (T); end if; -- Note that Has_Task is always false, since the access type itself -- is not a task type. See Einfo for more description on this point. -- Exactly the same consideration applies to Has_Controlled_Component -- and to Has_Protected. Set_Has_Task (T, False); Set_Has_Protected (T, False); Set_Has_Timing_Event (T, False); Set_Has_Controlled_Component (T, False); -- Initialize field Finalization_Master explicitly to Empty, to avoid -- problems where an incomplete view of this entity has been previously -- established by a limited with and an overlaid version of this field -- (Stored_Constraint) was initialized for the incomplete view. -- This reset is performed in most cases except where the access type -- has been created for the purposes of allocating or deallocating a -- build-in-place object. Such access types have explicitly set pools -- and finalization masters. if No (Associated_Storage_Pool (T)) then Set_Finalization_Master (T, Empty); end if; -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant -- attributes Set_Can_Never_Be_Null (T, Null_Exclusion_Present (Def)); Set_Is_Access_Constant (T, Constant_Present (Def)); end Access_Type_Declaration; ---------------------------------- -- Add_Interface_Tag_Components -- ---------------------------------- procedure Add_Interface_Tag_Components (N : Node_Id; Typ : Entity_Id) is Loc : constant Source_Ptr := Sloc (N); L : List_Id; Last_Tag : Node_Id; procedure Add_Tag (Iface : Entity_Id); -- Add tag for one of the progenitor interfaces ------------- -- Add_Tag -- ------------- procedure Add_Tag (Iface : Entity_Id) is Decl : Node_Id; Def : Node_Id; Tag : Entity_Id; Offset : Entity_Id; begin pragma Assert (Is_Tagged_Type (Iface) and then Is_Interface (Iface)); -- This is a reasonable place to propagate predicates if Has_Predicates (Iface) then Set_Has_Predicates (Typ); end if; Def := Make_Component_Definition (Loc, Aliased_Present => True, Subtype_Indication => New_Occurrence_Of (RTE (RE_Interface_Tag), Loc)); Tag := Make_Temporary (Loc, 'V'); Decl := Make_Component_Declaration (Loc, Defining_Identifier => Tag, Component_Definition => Def); Analyze_Component_Declaration (Decl); Set_Analyzed (Decl); Set_Ekind (Tag, E_Component); Set_Is_Tag (Tag); Set_Is_Aliased (Tag); Set_Related_Type (Tag, Iface); Init_Component_Location (Tag); pragma Assert (Is_Frozen (Iface)); Set_DT_Entry_Count (Tag, DT_Entry_Count (First_Entity (Iface))); if No (Last_Tag) then Prepend (Decl, L); else Insert_After (Last_Tag, Decl); end if; Last_Tag := Decl; -- If the ancestor has discriminants we need to give special support -- to store the offset_to_top value of the secondary dispatch tables. -- For this purpose we add a supplementary component just after the -- field that contains the tag associated with each secondary DT. if Typ /= Etype (Typ) and then Has_Discriminants (Etype (Typ)) then Def := Make_Component_Definition (Loc, Subtype_Indication => New_Occurrence_Of (RTE (RE_Storage_Offset), Loc)); Offset := Make_Temporary (Loc, 'V'); Decl := Make_Component_Declaration (Loc, Defining_Identifier => Offset, Component_Definition => Def); Analyze_Component_Declaration (Decl); Set_Analyzed (Decl); Set_Ekind (Offset, E_Component); Set_Is_Aliased (Offset); Set_Related_Type (Offset, Iface); Init_Component_Location (Offset); Insert_After (Last_Tag, Decl); Last_Tag := Decl; end if; end Add_Tag; -- Local variables Elmt : Elmt_Id; Ext : Node_Id; Comp : Node_Id; -- Start of processing for Add_Interface_Tag_Components begin if not RTE_Available (RE_Interface_Tag) then Error_Msg ("(Ada 2005) interface types not supported by this run-time!", Sloc (N)); return; end if; if Ekind (Typ) /= E_Record_Type or else (Is_Concurrent_Record_Type (Typ) and then Is_Empty_List (Abstract_Interface_List (Typ))) or else (not Is_Concurrent_Record_Type (Typ) and then No (Interfaces (Typ)) and then Is_Empty_Elmt_List (Interfaces (Typ))) then return; end if; -- Find the current last tag if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then Ext := Record_Extension_Part (Type_Definition (N)); else pragma Assert (Nkind (Type_Definition (N)) = N_Record_Definition); Ext := Type_Definition (N); end if; Last_Tag := Empty; if not (Present (Component_List (Ext))) then Set_Null_Present (Ext, False); L := New_List; Set_Component_List (Ext, Make_Component_List (Loc, Component_Items => L, Null_Present => False)); else if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then L := Component_Items (Component_List (Record_Extension_Part (Type_Definition (N)))); else L := Component_Items (Component_List (Type_Definition (N))); end if; -- Find the last tag component Comp := First (L); while Present (Comp) loop if Nkind (Comp) = N_Component_Declaration and then Is_Tag (Defining_Identifier (Comp)) then Last_Tag := Comp; end if; Next (Comp); end loop; end if; -- At this point L references the list of components and Last_Tag -- references the current last tag (if any). Now we add the tag -- corresponding with all the interfaces that are not implemented -- by the parent. if Present (Interfaces (Typ)) then Elmt := First_Elmt (Interfaces (Typ)); while Present (Elmt) loop Add_Tag (Node (Elmt)); Next_Elmt (Elmt); end loop; end if; end Add_Interface_Tag_Components; ------------------------------------- -- Add_Internal_Interface_Entities -- ------------------------------------- procedure Add_Internal_Interface_Entities (Tagged_Type : Entity_Id) is Elmt : Elmt_Id; Iface : Entity_Id; Iface_Elmt : Elmt_Id; Iface_Prim : Entity_Id; Ifaces_List : Elist_Id; New_Subp : Entity_Id := Empty; Prim : Entity_Id; Restore_Scope : Boolean := False; begin pragma Assert (Ada_Version >= Ada_2005 and then Is_Record_Type (Tagged_Type) and then Is_Tagged_Type (Tagged_Type) and then Has_Interfaces (Tagged_Type) and then not Is_Interface (Tagged_Type)); -- Ensure that the internal entities are added to the scope of the type if Scope (Tagged_Type) /= Current_Scope then Push_Scope (Scope (Tagged_Type)); Restore_Scope := True; end if; Collect_Interfaces (Tagged_Type, Ifaces_List); Iface_Elmt := First_Elmt (Ifaces_List); while Present (Iface_Elmt) loop Iface := Node (Iface_Elmt); -- Originally we excluded here from this processing interfaces that -- are parents of Tagged_Type because their primitives are located -- in the primary dispatch table (and hence no auxiliary internal -- entities are required to handle secondary dispatch tables in such -- case). However, these auxiliary entities are also required to -- handle derivations of interfaces in formals of generics (see -- Derive_Subprograms). Elmt := First_Elmt (Primitive_Operations (Iface)); while Present (Elmt) loop Iface_Prim := Node (Elmt); if not Is_Predefined_Dispatching_Operation (Iface_Prim) then Prim := Find_Primitive_Covering_Interface (Tagged_Type => Tagged_Type, Iface_Prim => Iface_Prim); if No (Prim) and then Serious_Errors_Detected > 0 then goto Continue; end if; pragma Assert (Present (Prim)); -- Ada 2012 (AI05-0197): If the name of the covering primitive -- differs from the name of the interface primitive then it is -- a private primitive inherited from a parent type. In such -- case, given that Tagged_Type covers the interface, the -- inherited private primitive becomes visible. For such -- purpose we add a new entity that renames the inherited -- private primitive. if Chars (Prim) /= Chars (Iface_Prim) then pragma Assert (Has_Suffix (Prim, 'P')); Derive_Subprogram (New_Subp => New_Subp, Parent_Subp => Iface_Prim, Derived_Type => Tagged_Type, Parent_Type => Iface); Set_Alias (New_Subp, Prim); Set_Is_Abstract_Subprogram (New_Subp, Is_Abstract_Subprogram (Prim)); end if; Derive_Subprogram (New_Subp => New_Subp, Parent_Subp => Iface_Prim, Derived_Type => Tagged_Type, Parent_Type => Iface); declare Anc : Entity_Id; begin if Is_Inherited_Operation (Prim) and then Present (Alias (Prim)) then Anc := Alias (Prim); else Anc := Overridden_Operation (Prim); end if; -- Apply legality checks in RM 6.1.1 (10-13) concerning -- nonconforming preconditions in both an ancestor and -- a progenitor operation. if Present (Anc) and then Has_Non_Trivial_Precondition (Anc) and then Has_Non_Trivial_Precondition (Iface_Prim) then if Is_Abstract_Subprogram (Prim) or else (Ekind (Prim) = E_Procedure and then Nkind (Parent (Prim)) = N_Procedure_Specification and then Null_Present (Parent (Prim))) then null; -- The inherited operation must be overridden elsif not Comes_From_Source (Prim) then Error_Msg_NE ("&inherits non-conforming preconditions and must " & "be overridden (RM 6.1.1 (10-16)", Parent (Tagged_Type), Prim); end if; end if; end; -- Ada 2005 (AI-251): Decorate internal entity Iface_Subp -- associated with interface types. These entities are -- only registered in the list of primitives of its -- corresponding tagged type because they are only used -- to fill the contents of the secondary dispatch tables. -- Therefore they are removed from the homonym chains. Set_Is_Hidden (New_Subp); Set_Is_Internal (New_Subp); Set_Alias (New_Subp, Prim); Set_Is_Abstract_Subprogram (New_Subp, Is_Abstract_Subprogram (Prim)); Set_Interface_Alias (New_Subp, Iface_Prim); -- If the returned type is an interface then propagate it to -- the returned type. Needed by the thunk to generate the code -- which displaces "this" to reference the corresponding -- secondary dispatch table in the returned object. if Is_Interface (Etype (Iface_Prim)) then Set_Etype (New_Subp, Etype (Iface_Prim)); end if; -- Internal entities associated with interface types are only -- registered in the list of primitives of the tagged type. -- They are only used to fill the contents of the secondary -- dispatch tables. Therefore they are not needed in the -- homonym chains. Remove_Homonym (New_Subp); -- Hidden entities associated with interfaces must have set -- the Has_Delay_Freeze attribute to ensure that, in case -- of locally defined tagged types (or compiling with static -- dispatch tables generation disabled) the corresponding -- entry of the secondary dispatch table is filled when such -- an entity is frozen. This is an expansion activity that must -- be suppressed for ASIS because it leads to gigi elaboration -- issues in annotate mode. if not ASIS_Mode then Set_Has_Delayed_Freeze (New_Subp); end if; end if; <<Continue>> Next_Elmt (Elmt); end loop; Next_Elmt (Iface_Elmt); end loop; if Restore_Scope then Pop_Scope; end if; end Add_Internal_Interface_Entities; ----------------------------------- -- Analyze_Component_Declaration -- ----------------------------------- procedure Analyze_Component_Declaration (N : Node_Id) is Loc : constant Source_Ptr := Sloc (Component_Definition (N)); Id : constant Entity_Id := Defining_Identifier (N); E : constant Node_Id := Expression (N); Typ : constant Node_Id := Subtype_Indication (Component_Definition (N)); T : Entity_Id; P : Entity_Id; function Contains_POC (Constr : Node_Id) return Boolean; -- Determines whether a constraint uses the discriminant of a record -- type thus becoming a per-object constraint (POC). function Is_Known_Limited (Typ : Entity_Id) return Boolean; -- Typ is the type of the current component, check whether this type is -- a limited type. Used to validate declaration against that of -- enclosing record. ------------------ -- Contains_POC -- ------------------ function Contains_POC (Constr : Node_Id) return Boolean is begin -- Prevent cascaded errors if Error_Posted (Constr) then return False; end if; case Nkind (Constr) is when N_Attribute_Reference => return Attribute_Name (Constr) = Name_Access and then Prefix (Constr) = Scope (Entity (Prefix (Constr))); when N_Discriminant_Association => return Denotes_Discriminant (Expression (Constr)); when N_Identifier => return Denotes_Discriminant (Constr); when N_Index_Or_Discriminant_Constraint => declare IDC : Node_Id; begin IDC := First (Constraints (Constr)); while Present (IDC) loop -- One per-object constraint is sufficient if Contains_POC (IDC) then return True; end if; Next (IDC); end loop; return False; end; when N_Range => return Denotes_Discriminant (Low_Bound (Constr)) or else Denotes_Discriminant (High_Bound (Constr)); when N_Range_Constraint => return Denotes_Discriminant (Range_Expression (Constr)); when others => return False; end case; end Contains_POC; ---------------------- -- Is_Known_Limited -- ---------------------- function Is_Known_Limited (Typ : Entity_Id) return Boolean is P : constant Entity_Id := Etype (Typ); R : constant Entity_Id := Root_Type (Typ); begin if Is_Limited_Record (Typ) then return True; -- If the root type is limited (and not a limited interface) -- so is the current type elsif Is_Limited_Record (R) and then (not Is_Interface (R) or else not Is_Limited_Interface (R)) then return True; -- Else the type may have a limited interface progenitor, but a -- limited record parent. elsif R /= P and then Is_Limited_Record (P) then return True; else return False; end if; end Is_Known_Limited; -- Start of processing for Analyze_Component_Declaration begin Generate_Definition (Id); Enter_Name (Id); if Present (Typ) then T := Find_Type_Of_Object (Subtype_Indication (Component_Definition (N)), N); if not Nkind_In (Typ, N_Identifier, N_Expanded_Name) then Check_SPARK_05_Restriction ("subtype mark required", Typ); end if; -- Ada 2005 (AI-230): Access Definition case else pragma Assert (Present (Access_Definition (Component_Definition (N)))); T := Access_Definition (Related_Nod => N, N => Access_Definition (Component_Definition (N))); Set_Is_Local_Anonymous_Access (T); -- Ada 2005 (AI-254) if Present (Access_To_Subprogram_Definition (Access_Definition (Component_Definition (N)))) and then Protected_Present (Access_To_Subprogram_Definition (Access_Definition (Component_Definition (N)))) then T := Replace_Anonymous_Access_To_Protected_Subprogram (N); end if; end if; -- If the subtype is a constrained subtype of the enclosing record, -- (which must have a partial view) the back-end does not properly -- handle the recursion. Rewrite the component declaration with an -- explicit subtype indication, which is acceptable to Gigi. We can copy -- the tree directly because side effects have already been removed from -- discriminant constraints. if Ekind (T) = E_Access_Subtype and then Is_Entity_Name (Subtype_Indication (Component_Definition (N))) and then Comes_From_Source (T) and then Nkind (Parent (T)) = N_Subtype_Declaration and then Etype (Directly_Designated_Type (T)) = Current_Scope then Rewrite (Subtype_Indication (Component_Definition (N)), New_Copy_Tree (Subtype_Indication (Parent (T)))); T := Find_Type_Of_Object (Subtype_Indication (Component_Definition (N)), N); end if; -- If the component declaration includes a default expression, then we -- check that the component is not of a limited type (RM 3.7(5)), -- and do the special preanalysis of the expression (see section on -- "Handling of Default and Per-Object Expressions" in the spec of -- package Sem). if Present (E) then Check_SPARK_05_Restriction ("default expression is not allowed", E); Preanalyze_Default_Expression (E, T); Check_Initialization (T, E); if Ada_Version >= Ada_2005 and then Ekind (T) = E_Anonymous_Access_Type and then Etype (E) /= Any_Type then -- Check RM 3.9.2(9): "if the expected type for an expression is -- an anonymous access-to-specific tagged type, then the object -- designated by the expression shall not be dynamically tagged -- unless it is a controlling operand in a call on a dispatching -- operation" if Is_Tagged_Type (Directly_Designated_Type (T)) and then Ekind (Directly_Designated_Type (T)) /= E_Class_Wide_Type and then Ekind (Directly_Designated_Type (Etype (E))) = E_Class_Wide_Type then Error_Msg_N ("access to specific tagged type required (RM 3.9.2(9))", E); end if; -- (Ada 2005: AI-230): Accessibility check for anonymous -- components if Type_Access_Level (Etype (E)) > Deepest_Type_Access_Level (T) then Error_Msg_N ("expression has deeper access level than component " & "(RM 3.10.2 (12.2))", E); end if; -- The initialization expression is a reference to an access -- discriminant. The type of the discriminant is always deeper -- than any access type. if Ekind (Etype (E)) = E_Anonymous_Access_Type and then Is_Entity_Name (E) and then Ekind (Entity (E)) = E_In_Parameter and then Present (Discriminal_Link (Entity (E))) then Error_Msg_N ("discriminant has deeper accessibility level than target", E); end if; end if; end if; -- The parent type may be a private view with unknown discriminants, -- and thus unconstrained. Regular components must be constrained. if not Is_Definite_Subtype (T) and then Chars (Id) /= Name_uParent then if Is_Class_Wide_Type (T) then Error_Msg_N ("class-wide subtype with unknown discriminants" & " in component declaration", Subtype_Indication (Component_Definition (N))); else Error_Msg_N ("unconstrained subtype in component declaration", Subtype_Indication (Component_Definition (N))); end if; -- Components cannot be abstract, except for the special case of -- the _Parent field (case of extending an abstract tagged type) elsif Is_Abstract_Type (T) and then Chars (Id) /= Name_uParent then Error_Msg_N ("type of a component cannot be abstract", N); end if; Set_Etype (Id, T); Set_Is_Aliased (Id, Aliased_Present (Component_Definition (N))); -- The component declaration may have a per-object constraint, set -- the appropriate flag in the defining identifier of the subtype. if Present (Subtype_Indication (Component_Definition (N))) then declare Sindic : constant Node_Id := Subtype_Indication (Component_Definition (N)); begin if Nkind (Sindic) = N_Subtype_Indication and then Present (Constraint (Sindic)) and then Contains_POC (Constraint (Sindic)) then Set_Has_Per_Object_Constraint (Id); end if; end; end if; -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry -- out some static checks. if Ada_Version >= Ada_2005 and then Can_Never_Be_Null (T) then Null_Exclusion_Static_Checks (N); end if; -- If this component is private (or depends on a private type), flag the -- record type to indicate that some operations are not available. P := Private_Component (T); if Present (P) then -- Check for circular definitions if P = Any_Type then Set_Etype (Id, Any_Type); -- There is a gap in the visibility of operations only if the -- component type is not defined in the scope of the record type. elsif Scope (P) = Scope (Current_Scope) then null; elsif Is_Limited_Type (P) then Set_Is_Limited_Composite (Current_Scope); else Set_Is_Private_Composite (Current_Scope); end if; end if; if P /= Any_Type and then Is_Limited_Type (T) and then Chars (Id) /= Name_uParent and then Is_Tagged_Type (Current_Scope) then if Is_Derived_Type (Current_Scope) and then not Is_Known_Limited (Current_Scope) then Error_Msg_N ("extension of nonlimited type cannot have limited components", N); if Is_Interface (Root_Type (Current_Scope)) then Error_Msg_N ("\limitedness is not inherited from limited interface", N); Error_Msg_N ("\add LIMITED to type indication", N); end if; Explain_Limited_Type (T, N); Set_Etype (Id, Any_Type); Set_Is_Limited_Composite (Current_Scope, False); elsif not Is_Derived_Type (Current_Scope) and then not Is_Limited_Record (Current_Scope) and then not Is_Concurrent_Type (Current_Scope) then Error_Msg_N ("nonlimited tagged type cannot have limited components", N); Explain_Limited_Type (T, N); Set_Etype (Id, Any_Type); Set_Is_Limited_Composite (Current_Scope, False); end if; end if; -- If the component is an unconstrained task or protected type with -- discriminants, the component and the enclosing record are limited -- and the component is constrained by its default values. Compute -- its actual subtype, else it may be allocated the maximum size by -- the backend, and possibly overflow. if Is_Concurrent_Type (T) and then not Is_Constrained (T) and then Has_Discriminants (T) and then not Has_Discriminants (Current_Scope) then declare Act_T : constant Entity_Id := Build_Default_Subtype (T, N); begin Set_Etype (Id, Act_T); -- Rewrite component definition to use the constrained subtype Rewrite (Component_Definition (N), Make_Component_Definition (Loc, Subtype_Indication => New_Occurrence_Of (Act_T, Loc))); end; end if; Set_Original_Record_Component (Id, Id); if Has_Aspects (N) then Analyze_Aspect_Specifications (N, Id); end if; Analyze_Dimension (N); end Analyze_Component_Declaration; -------------------------- -- Analyze_Declarations -- -------------------------- procedure Analyze_Declarations (L : List_Id) is Decl : Node_Id; procedure Adjust_Decl; -- Adjust Decl not to include implicit label declarations, since these -- have strange Sloc values that result in elaboration check problems. -- (They have the sloc of the label as found in the source, and that -- is ahead of the current declarative part). procedure Build_Assertion_Bodies (Decls : List_Id; Context : Node_Id); -- Create the subprogram bodies which verify the run-time semantics of -- the pragmas listed below for each elibigle type found in declarative -- list Decls. The pragmas are: -- -- Default_Initial_Condition -- Invariant -- Type_Invariant -- -- Context denotes the owner of the declarative list. procedure Check_Entry_Contracts; -- Perform a pre-analysis of the pre- and postconditions of an entry -- declaration. This must be done before full resolution and creation -- of the parameter block, etc. to catch illegal uses within the -- contract expression. Full analysis of the expression is done when -- the contract is processed. procedure Handle_Late_Controlled_Primitive (Body_Decl : Node_Id); -- Determine whether Body_Decl denotes the body of a late controlled -- primitive (either Initialize, Adjust or Finalize). If this is the -- case, add a proper spec if the body lacks one. The spec is inserted -- before Body_Decl and immediately analyzed. procedure Remove_Partial_Visible_Refinements (Spec_Id : Entity_Id); -- Spec_Id is the entity of a package that may define abstract states, -- and in the case of a child unit, whose ancestors may define abstract -- states. If the states have partial visible refinement, remove the -- partial visibility of each constituent at the end of the package -- spec and body declarations. procedure Remove_Visible_Refinements (Spec_Id : Entity_Id); -- Spec_Id is the entity of a package that may define abstract states. -- If the states have visible refinement, remove the visibility of each -- constituent at the end of the package body declaration. procedure Resolve_Aspects; -- Utility to resolve the expressions of aspects at the end of a list of -- declarations. function Uses_Unseen_Lib_Unit_Priv (Pkg : Entity_Id) return Boolean; -- Check if an inner package has entities within it that rely on library -- level private types where the full view has not been seen. ----------------- -- Adjust_Decl -- ----------------- procedure Adjust_Decl is begin while Present (Prev (Decl)) and then Nkind (Decl) = N_Implicit_Label_Declaration loop Prev (Decl); end loop; end Adjust_Decl; ---------------------------- -- Build_Assertion_Bodies -- ---------------------------- procedure Build_Assertion_Bodies (Decls : List_Id; Context : Node_Id) is procedure Build_Assertion_Bodies_For_Type (Typ : Entity_Id); -- Create the subprogram bodies which verify the run-time semantics -- of the pragmas listed below for type Typ. The pragmas are: -- -- Default_Initial_Condition -- Invariant -- Type_Invariant ------------------------------------- -- Build_Assertion_Bodies_For_Type -- ------------------------------------- procedure Build_Assertion_Bodies_For_Type (Typ : Entity_Id) is begin -- Preanalyze and resolve the Default_Initial_Condition assertion -- expression at the end of the declarations to catch any errors. if Has_DIC (Typ) then Build_DIC_Procedure_Body (Typ); end if; if Nkind (Context) = N_Package_Specification then -- Preanalyze and resolve the class-wide invariants of an -- interface at the end of whichever declarative part has the -- interface type. Note that an interface may be declared in -- any non-package declarative part, but reaching the end of -- such a declarative part will always freeze the type and -- generate the invariant procedure (see Freeze_Type). if Is_Interface (Typ) then -- Interfaces are treated as the partial view of a private -- type, in order to achieve uniformity with the general -- case. As a result, an interface receives only a "partial" -- invariant procedure, which is never called. if Has_Own_Invariants (Typ) then Build_Invariant_Procedure_Body (Typ => Typ, Partial_Invariant => True); end if; -- Preanalyze and resolve the invariants of a private type -- at the end of the visible declarations to catch potential -- errors. Inherited class-wide invariants are not included -- because they have already been resolved. elsif Decls = Visible_Declarations (Context) and then Ekind_In (Typ, E_Limited_Private_Type, E_Private_Type, E_Record_Type_With_Private) and then Has_Own_Invariants (Typ) then Build_Invariant_Procedure_Body (Typ => Typ, Partial_Invariant => True); -- Preanalyze and resolve the invariants of a private type's -- full view at the end of the private declarations to catch -- potential errors. elsif Decls = Private_Declarations (Context) and then not Is_Private_Type (Typ) and then Has_Private_Declaration (Typ) and then Has_Invariants (Typ) then Build_Invariant_Procedure_Body (Typ); end if; end if; end Build_Assertion_Bodies_For_Type; -- Local variables Decl : Node_Id; Decl_Id : Entity_Id; -- Start of processing for Build_Assertion_Bodies begin Decl := First (Decls); while Present (Decl) loop if Is_Declaration (Decl) then Decl_Id := Defining_Entity (Decl); if Is_Type (Decl_Id) then Build_Assertion_Bodies_For_Type (Decl_Id); end if; end if; Next (Decl); end loop; end Build_Assertion_Bodies; --------------------------- -- Check_Entry_Contracts -- --------------------------- procedure Check_Entry_Contracts is ASN : Node_Id; Ent : Entity_Id; Exp : Node_Id; begin Ent := First_Entity (Current_Scope); while Present (Ent) loop -- This only concerns entries with pre/postconditions if Ekind (Ent) = E_Entry and then Present (Contract (Ent)) and then Present (Pre_Post_Conditions (Contract (Ent))) then ASN := Pre_Post_Conditions (Contract (Ent)); Push_Scope (Ent); Install_Formals (Ent); -- Pre/postconditions are rewritten as Check pragmas. Analysis -- is performed on a copy of the pragma expression, to prevent -- modifying the original expression. while Present (ASN) loop if Nkind (ASN) = N_Pragma then Exp := New_Copy_Tree (Expression (First (Pragma_Argument_Associations (ASN)))); Set_Parent (Exp, ASN); Preanalyze_Assert_Expression (Exp, Standard_Boolean); end if; ASN := Next_Pragma (ASN); end loop; End_Scope; end if; Next_Entity (Ent); end loop; end Check_Entry_Contracts; -------------------------------------- -- Handle_Late_Controlled_Primitive -- -------------------------------------- procedure Handle_Late_Controlled_Primitive (Body_Decl : Node_Id) is Body_Spec : constant Node_Id := Specification (Body_Decl); Body_Id : constant Entity_Id := Defining_Entity (Body_Spec); Loc : constant Source_Ptr := Sloc (Body_Id); Params : constant List_Id := Parameter_Specifications (Body_Spec); Spec : Node_Id; Spec_Id : Entity_Id; Typ : Node_Id; begin -- Consider only procedure bodies whose name matches one of the three -- controlled primitives. if Nkind (Body_Spec) /= N_Procedure_Specification or else not Nam_In (Chars (Body_Id), Name_Adjust, Name_Finalize, Name_Initialize) then return; -- A controlled primitive must have exactly one formal which is not -- an anonymous access type. elsif List_Length (Params) /= 1 then return; end if; Typ := Parameter_Type (First (Params)); if Nkind (Typ) = N_Access_Definition then return; end if; Find_Type (Typ); -- The type of the formal must be derived from [Limited_]Controlled if not Is_Controlled (Entity (Typ)) then return; end if; -- Check whether a specification exists for this body. We do not -- analyze the spec of the body in full, because it will be analyzed -- again when the body is properly analyzed, and we cannot create -- duplicate entries in the formals chain. We look for an explicit -- specification because the body may be an overriding operation and -- an inherited spec may be present. Spec_Id := Current_Entity (Body_Id); while Present (Spec_Id) loop if Ekind_In (Spec_Id, E_Procedure, E_Generic_Procedure) and then Scope (Spec_Id) = Current_Scope and then Present (First_Formal (Spec_Id)) and then No (Next_Formal (First_Formal (Spec_Id))) and then Etype (First_Formal (Spec_Id)) = Entity (Typ) and then Comes_From_Source (Spec_Id) then return; end if; Spec_Id := Homonym (Spec_Id); end loop; -- At this point the body is known to be a late controlled primitive. -- Generate a matching spec and insert it before the body. Note the -- use of Copy_Separate_Tree - we want an entirely separate semantic -- tree in this case. Spec := Copy_Separate_Tree (Body_Spec); -- Ensure that the subprogram declaration does not inherit the null -- indicator from the body as we now have a proper spec/body pair. Set_Null_Present (Spec, False); -- Ensure that the freeze node is inserted after the declaration of -- the primitive since its expansion will freeze the primitive. Decl := Make_Subprogram_Declaration (Loc, Specification => Spec); Insert_Before_And_Analyze (Body_Decl, Decl); end Handle_Late_Controlled_Primitive; ---------------------------------------- -- Remove_Partial_Visible_Refinements -- ---------------------------------------- procedure Remove_Partial_Visible_Refinements (Spec_Id : Entity_Id) is State_Elmt : Elmt_Id; begin if Present (Abstract_States (Spec_Id)) then State_Elmt := First_Elmt (Abstract_States (Spec_Id)); while Present (State_Elmt) loop Set_Has_Partial_Visible_Refinement (Node (State_Elmt), False); Next_Elmt (State_Elmt); end loop; end if; -- For a child unit, also hide the partial state refinement from -- ancestor packages. if Is_Child_Unit (Spec_Id) then Remove_Partial_Visible_Refinements (Scope (Spec_Id)); end if; end Remove_Partial_Visible_Refinements; -------------------------------- -- Remove_Visible_Refinements -- -------------------------------- procedure Remove_Visible_Refinements (Spec_Id : Entity_Id) is State_Elmt : Elmt_Id; begin if Present (Abstract_States (Spec_Id)) then State_Elmt := First_Elmt (Abstract_States (Spec_Id)); while Present (State_Elmt) loop Set_Has_Visible_Refinement (Node (State_Elmt), False); Next_Elmt (State_Elmt); end loop; end if; end Remove_Visible_Refinements; --------------------- -- Resolve_Aspects -- --------------------- procedure Resolve_Aspects is E : Entity_Id; begin E := First_Entity (Current_Scope); while Present (E) loop Resolve_Aspect_Expressions (E); Next_Entity (E); end loop; end Resolve_Aspects; ------------------------------- -- Uses_Unseen_Lib_Unit_Priv -- ------------------------------- function Uses_Unseen_Lib_Unit_Priv (Pkg : Entity_Id) return Boolean is Curr : Entity_Id; begin -- Avoid looking through scopes that do not meet the precondition of -- Pkg not being within a library unit spec. if not Is_Compilation_Unit (Pkg) and then not Is_Generic_Instance (Pkg) and then not In_Package_Body (Enclosing_Lib_Unit_Entity (Pkg)) then -- Loop through all entities in the current scope to identify -- an entity that depends on a private type. Curr := First_Entity (Pkg); loop if Nkind (Curr) in N_Entity and then Depends_On_Private (Curr) then return True; end if; exit when Last_Entity (Current_Scope) = Curr; Curr := Next_Entity (Curr); end loop; end if; return False; end Uses_Unseen_Lib_Unit_Priv; -- Local variables Context : Node_Id := Empty; Freeze_From : Entity_Id := Empty; Next_Decl : Node_Id; Body_Seen : Boolean := False; -- Flag set when the first body [stub] is encountered -- Start of processing for Analyze_Declarations begin if Restriction_Check_Required (SPARK_05) then Check_Later_Vs_Basic_Declarations (L, During_Parsing => False); end if; Decl := First (L); while Present (Decl) loop -- Package spec cannot contain a package declaration in SPARK if Nkind (Decl) = N_Package_Declaration and then Nkind (Parent (L)) = N_Package_Specification then Check_SPARK_05_Restriction ("package specification cannot contain a package declaration", Decl); end if; -- Complete analysis of declaration Analyze (Decl); Next_Decl := Next (Decl); if No (Freeze_From) then Freeze_From := First_Entity (Current_Scope); end if; -- At the end of a declarative part, freeze remaining entities -- declared in it. The end of the visible declarations of package -- specification is not the end of a declarative part if private -- declarations are present. The end of a package declaration is a -- freezing point only if it a library package. A task definition or -- protected type definition is not a freeze point either. Finally, -- we do not freeze entities in generic scopes, because there is no -- code generated for them and freeze nodes will be generated for -- the instance. -- The end of a package instantiation is not a freeze point, but -- for now we make it one, because the generic body is inserted -- (currently) immediately after. Generic instantiations will not -- be a freeze point once delayed freezing of bodies is implemented. -- (This is needed in any case for early instantiations ???). if No (Next_Decl) then if Nkind (Parent (L)) = N_Component_List then null; elsif Nkind_In (Parent (L), N_Protected_Definition, N_Task_Definition) then Check_Entry_Contracts; elsif Nkind (Parent (L)) /= N_Package_Specification then if Nkind (Parent (L)) = N_Package_Body then Freeze_From := First_Entity (Current_Scope); end if; -- There may have been several freezing points previously, -- for example object declarations or subprogram bodies, but -- at the end of a declarative part we check freezing from -- the beginning, even though entities may already be frozen, -- in order to perform visibility checks on delayed aspects. Adjust_Decl; Freeze_All (First_Entity (Current_Scope), Decl); Freeze_From := Last_Entity (Current_Scope); -- Current scope is a package specification elsif Scope (Current_Scope) /= Standard_Standard and then not Is_Child_Unit (Current_Scope) and then No (Generic_Parent (Parent (L))) then -- This is needed in all cases to catch visibility errors in -- aspect expressions, but several large user tests are now -- rejected. Pending notification we restrict this call to -- ASIS mode. if ASIS_Mode then Resolve_Aspects; end if; elsif L /= Visible_Declarations (Parent (L)) or else No (Private_Declarations (Parent (L))) or else Is_Empty_List (Private_Declarations (Parent (L))) then Adjust_Decl; -- End of a package declaration -- In compilation mode the expansion of freeze node takes care -- of resolving expressions of all aspects in the list. In ASIS -- mode this must be done explicitly. if ASIS_Mode and then Scope (Current_Scope) = Standard_Standard then Resolve_Aspects; end if; -- This is a freeze point because it is the end of a -- compilation unit. Freeze_All (First_Entity (Current_Scope), Decl); Freeze_From := Last_Entity (Current_Scope); -- At the end of the visible declarations the expressions in -- aspects of all entities declared so far must be resolved. -- The entities themselves might be frozen later, and the -- generated pragmas and attribute definition clauses analyzed -- in full at that point, but name resolution must take place -- now. -- In addition to being the proper semantics, this is mandatory -- within generic units, because global name capture requires -- those expressions to be analyzed, given that the generated -- pragmas do not appear in the original generic tree. elsif Serious_Errors_Detected = 0 then Resolve_Aspects; end if; -- If next node is a body then freeze all types before the body. -- An exception occurs for some expander-generated bodies. If these -- are generated at places where in general language rules would not -- allow a freeze point, then we assume that the expander has -- explicitly checked that all required types are properly frozen, -- and we do not cause general freezing here. This special circuit -- is used when the encountered body is marked as having already -- been analyzed. -- In all other cases (bodies that come from source, and expander -- generated bodies that have not been analyzed yet), freeze all -- types now. Note that in the latter case, the expander must take -- care to attach the bodies at a proper place in the tree so as to -- not cause unwanted freezing at that point. -- It is also necessary to check for a case where both an expression -- function is used and the current scope depends on an unseen -- private type from a library unit, otherwise premature freezing of -- the private type will occur. elsif not Analyzed (Next_Decl) and then Is_Body (Next_Decl) and then ((Nkind (Next_Decl) /= N_Subprogram_Body or else not Was_Expression_Function (Next_Decl)) or else not Uses_Unseen_Lib_Unit_Priv (Current_Scope)) then -- When a controlled type is frozen, the expander generates stream -- and controlled-type support routines. If the freeze is caused -- by the stand-alone body of Initialize, Adjust, or Finalize, the -- expander will end up using the wrong version of these routines, -- as the body has not been processed yet. To remedy this, detect -- a late controlled primitive and create a proper spec for it. -- This ensures that the primitive will override its inherited -- counterpart before the freeze takes place. -- If the declaration we just processed is a body, do not attempt -- to examine Next_Decl as the late primitive idiom can only apply -- to the first encountered body. -- The spec of the late primitive is not generated in ASIS mode to -- ensure a consistent list of primitives that indicates the true -- semantic structure of the program (which is not relevant when -- generating executable code). -- ??? A cleaner approach may be possible and/or this solution -- could be extended to general-purpose late primitives, TBD. if not ASIS_Mode and then not Body_Seen and then not Is_Body (Decl) then Body_Seen := True; if Nkind (Next_Decl) = N_Subprogram_Body then Handle_Late_Controlled_Primitive (Next_Decl); end if; end if; Adjust_Decl; -- The generated body of an expression function does not freeze, -- unless it is a completion, in which case only the expression -- itself freezes. This is handled when the body itself is -- analyzed (see Freeze_Expr_Types, sem_ch6.adb). Freeze_All (Freeze_From, Decl); Freeze_From := Last_Entity (Current_Scope); end if; Decl := Next_Decl; end loop; -- Post-freezing actions if Present (L) then Context := Parent (L); -- Analyze the contracts of packages and their bodies if Nkind (Context) = N_Package_Specification then -- When a package has private declarations, its contract must be -- analyzed at the end of the said declarations. This way both the -- analysis and freeze actions are properly synchronized in case -- of private type use within the contract. if L = Private_Declarations (Context) then Analyze_Package_Contract (Defining_Entity (Context)); -- Otherwise the contract is analyzed at the end of the visible -- declarations. elsif L = Visible_Declarations (Context) and then No (Private_Declarations (Context)) then Analyze_Package_Contract (Defining_Entity (Context)); end if; elsif Nkind (Context) = N_Package_Body then Analyze_Package_Body_Contract (Defining_Entity (Context)); end if; -- Analyze the contracts of various constructs now due to the delayed -- visibility needs of their aspects and pragmas. Analyze_Contracts (L); if Nkind (Context) = N_Package_Body then -- Ensure that all abstract states and objects declared in the -- state space of a package body are utilized as constituents. Check_Unused_Body_States (Defining_Entity (Context)); -- State refinements are visible up to the end of the package body -- declarations. Hide the state refinements from visibility to -- restore the original state conditions. Remove_Visible_Refinements (Corresponding_Spec (Context)); Remove_Partial_Visible_Refinements (Corresponding_Spec (Context)); elsif Nkind (Context) = N_Package_Declaration then -- Partial state refinements are visible up to the end of the -- package spec declarations. Hide the partial state refinements -- from visibility to restore the original state conditions. Remove_Partial_Visible_Refinements (Corresponding_Spec (Context)); end if; -- Verify that all abstract states found in any package declared in -- the input declarative list have proper refinements. The check is -- performed only when the context denotes a block, entry, package, -- protected, subprogram, or task body (SPARK RM 7.2.2(3)). Check_State_Refinements (Context); -- Create the subprogram bodies which verify the run-time semantics -- of pragmas Default_Initial_Condition and [Type_]Invariant for all -- types within the current declarative list. This ensures that all -- assertion expressions are preanalyzed and resolved at the end of -- the declarative part. Note that the resolution happens even when -- freezing does not take place. Build_Assertion_Bodies (L, Context); end if; end Analyze_Declarations; ----------------------------------- -- Analyze_Full_Type_Declaration -- ----------------------------------- procedure Analyze_Full_Type_Declaration (N : Node_Id) is Def : constant Node_Id := Type_Definition (N); Def_Id : constant Entity_Id := Defining_Identifier (N); T : Entity_Id; Prev : Entity_Id; Is_Remote : constant Boolean := (Is_Remote_Types (Current_Scope) or else Is_Remote_Call_Interface (Current_Scope)) and then not (In_Private_Part (Current_Scope) or else In_Package_Body (Current_Scope)); procedure Check_Nonoverridable_Aspects; -- Apply the rule in RM 13.1.1(18.4/4) on iterator aspects that cannot -- be overridden, and can only be confirmed on derivation. procedure Check_Ops_From_Incomplete_Type; -- If there is a tagged incomplete partial view of the type, traverse -- the primitives of the incomplete view and change the type of any -- controlling formals and result to indicate the full view. The -- primitives will be added to the full type's primitive operations -- list later in Sem_Disp.Check_Operation_From_Incomplete_Type (which -- is called from Process_Incomplete_Dependents). ---------------------------------- -- Check_Nonoverridable_Aspects -- ---------------------------------- procedure Check_Nonoverridable_Aspects is function Get_Aspect_Spec (Specs : List_Id; Aspect_Name : Name_Id) return Node_Id; -- Check whether a list of aspect specifications includes an entry -- for a specific aspect. The list is either that of a partial or -- a full view. --------------------- -- Get_Aspect_Spec -- --------------------- function Get_Aspect_Spec (Specs : List_Id; Aspect_Name : Name_Id) return Node_Id is Spec : Node_Id; begin Spec := First (Specs); while Present (Spec) loop if Chars (Identifier (Spec)) = Aspect_Name then return Spec; end if; Next (Spec); end loop; return Empty; end Get_Aspect_Spec; -- Local variables Prev_Aspects : constant List_Id := Aspect_Specifications (Parent (Def_Id)); Par_Type : Entity_Id; Prev_Aspect : Node_Id; -- Start of processing for Check_Nonoverridable_Aspects begin -- Get parent type of derived type. Note that Prev is the entity in -- the partial declaration, but its contents are now those of full -- view, while Def_Id reflects the partial view. if Is_Private_Type (Def_Id) then Par_Type := Etype (Full_View (Def_Id)); else Par_Type := Etype (Def_Id); end if; -- If there is an inherited Implicit_Dereference, verify that it is -- made explicit in the partial view. if Has_Discriminants (Base_Type (Par_Type)) and then Nkind (Parent (Prev)) = N_Full_Type_Declaration and then Present (Discriminant_Specifications (Parent (Prev))) and then Present (Get_Reference_Discriminant (Par_Type)) then Prev_Aspect := Get_Aspect_Spec (Prev_Aspects, Name_Implicit_Dereference); if No (Prev_Aspect) and then Present (Discriminant_Specifications (Original_Node (Parent (Prev)))) then Error_Msg_N ("type does not inherit implicit dereference", Prev); else -- If one of the views has the aspect specified, verify that it -- is consistent with that of the parent. declare Par_Discr : constant Entity_Id := Get_Reference_Discriminant (Par_Type); Cur_Discr : constant Entity_Id := Get_Reference_Discriminant (Prev); begin if Corresponding_Discriminant (Cur_Discr) /= Par_Discr then Error_Msg_N ("aspect incosistent with that of parent", N); end if; -- Check that specification in partial view matches the -- inherited aspect. Compare names directly because aspect -- expression may not be analyzed. if Present (Prev_Aspect) and then Nkind (Expression (Prev_Aspect)) = N_Identifier and then Chars (Expression (Prev_Aspect)) /= Chars (Cur_Discr) then Error_Msg_N ("aspect incosistent with that of parent", N); end if; end; end if; end if; -- TBD : other nonoverridable aspects. end Check_Nonoverridable_Aspects; ------------------------------------ -- Check_Ops_From_Incomplete_Type -- ------------------------------------ procedure Check_Ops_From_Incomplete_Type is Elmt : Elmt_Id; Formal : Entity_Id; Op : Entity_Id; begin if Prev /= T and then Ekind (Prev) = E_Incomplete_Type and then Is_Tagged_Type (Prev) and then Is_Tagged_Type (T) then Elmt := First_Elmt (Primitive_Operations (Prev)); while Present (Elmt) loop Op := Node (Elmt); Formal := First_Formal (Op); while Present (Formal) loop if Etype (Formal) = Prev then Set_Etype (Formal, T); end if; Next_Formal (Formal); end loop; if Etype (Op) = Prev then Set_Etype (Op, T); end if; Next_Elmt (Elmt); end loop; end if; end Check_Ops_From_Incomplete_Type; -- Start of processing for Analyze_Full_Type_Declaration begin Prev := Find_Type_Name (N); -- The full view, if present, now points to the current type. If there -- is an incomplete partial view, set a link to it, to simplify the -- retrieval of primitive operations of the type. -- Ada 2005 (AI-50217): If the type was previously decorated when -- imported through a LIMITED WITH clause, it appears as incomplete -- but has no full view. if Ekind (Prev) = E_Incomplete_Type and then Present (Full_View (Prev)) then T := Full_View (Prev); Set_Incomplete_View (N, Parent (Prev)); else T := Prev; end if; Set_Is_Pure (T, Is_Pure (Current_Scope)); -- We set the flag Is_First_Subtype here. It is needed to set the -- corresponding flag for the Implicit class-wide-type created -- during tagged types processing. Set_Is_First_Subtype (T, True); -- Only composite types other than array types are allowed to have -- discriminants. case Nkind (Def) is -- For derived types, the rule will be checked once we've figured -- out the parent type. when N_Derived_Type_Definition => null; -- For record types, discriminants are allowed, unless we are in -- SPARK. when N_Record_Definition => if Present (Discriminant_Specifications (N)) then Check_SPARK_05_Restriction ("discriminant type is not allowed", Defining_Identifier (First (Discriminant_Specifications (N)))); end if; when others => if Present (Discriminant_Specifications (N)) then Error_Msg_N ("elementary or array type cannot have discriminants", Defining_Identifier (First (Discriminant_Specifications (N)))); end if; end case; -- Elaborate the type definition according to kind, and generate -- subsidiary (implicit) subtypes where needed. We skip this if it was -- already done (this happens during the reanalysis that follows a call -- to the high level optimizer). if not Analyzed (T) then Set_Analyzed (T); case Nkind (Def) is when N_Access_To_Subprogram_Definition => Access_Subprogram_Declaration (T, Def); -- If this is a remote access to subprogram, we must create the -- equivalent fat pointer type, and related subprograms. if Is_Remote then Process_Remote_AST_Declaration (N); end if; -- Validate categorization rule against access type declaration -- usually a violation in Pure unit, Shared_Passive unit. Validate_Access_Type_Declaration (T, N); when N_Access_To_Object_Definition => Access_Type_Declaration (T, Def); -- Validate categorization rule against access type declaration -- usually a violation in Pure unit, Shared_Passive unit. Validate_Access_Type_Declaration (T, N); -- If we are in a Remote_Call_Interface package and define a -- RACW, then calling stubs and specific stream attributes -- must be added. if Is_Remote and then Is_Remote_Access_To_Class_Wide_Type (Def_Id) then Add_RACW_Features (Def_Id); end if; when N_Array_Type_Definition => Array_Type_Declaration (T, Def); when N_Derived_Type_Definition => Derived_Type_Declaration (T, N, T /= Def_Id); when N_Enumeration_Type_Definition => Enumeration_Type_Declaration (T, Def); when N_Floating_Point_Definition => Floating_Point_Type_Declaration (T, Def); when N_Decimal_Fixed_Point_Definition => Decimal_Fixed_Point_Type_Declaration (T, Def); when N_Ordinary_Fixed_Point_Definition => Ordinary_Fixed_Point_Type_Declaration (T, Def); when N_Signed_Integer_Type_Definition => Signed_Integer_Type_Declaration (T, Def); when N_Modular_Type_Definition => Modular_Type_Declaration (T, Def); when N_Record_Definition => Record_Type_Declaration (T, N, Prev); -- If declaration has a parse error, nothing to elaborate. when N_Error => null; when others => raise Program_Error; end case; end if; if Etype (T) = Any_Type then return; end if; -- Controlled type is not allowed in SPARK if Is_Visibly_Controlled (T) then Check_SPARK_05_Restriction ("controlled type is not allowed", N); end if; -- Some common processing for all types Set_Depends_On_Private (T, Has_Private_Component (T)); Check_Ops_From_Incomplete_Type; -- Both the declared entity, and its anonymous base type if one was -- created, need freeze nodes allocated. declare B : constant Entity_Id := Base_Type (T); begin -- In the case where the base type differs from the first subtype, we -- pre-allocate a freeze node, and set the proper link to the first -- subtype. Freeze_Entity will use this preallocated freeze node when -- it freezes the entity. -- This does not apply if the base type is a generic type, whose -- declaration is independent of the current derived definition. if B /= T and then not Is_Generic_Type (B) then Ensure_Freeze_Node (B); Set_First_Subtype_Link (Freeze_Node (B), T); end if; -- A type that is imported through a limited_with clause cannot -- generate any code, and thus need not be frozen. However, an access -- type with an imported designated type needs a finalization list, -- which may be referenced in some other package that has non-limited -- visibility on the designated type. Thus we must create the -- finalization list at the point the access type is frozen, to -- prevent unsatisfied references at link time. if not From_Limited_With (T) or else Is_Access_Type (T) then Set_Has_Delayed_Freeze (T); end if; end; -- Case where T is the full declaration of some private type which has -- been swapped in Defining_Identifier (N). if T /= Def_Id and then Is_Private_Type (Def_Id) then Process_Full_View (N, T, Def_Id); -- Record the reference. The form of this is a little strange, since -- the full declaration has been swapped in. So the first parameter -- here represents the entity to which a reference is made which is -- the "real" entity, i.e. the one swapped in, and the second -- parameter provides the reference location. -- Also, we want to kill Has_Pragma_Unreferenced temporarily here -- since we don't want a complaint about the full type being an -- unwanted reference to the private type declare B : constant Boolean := Has_Pragma_Unreferenced (T); begin Set_Has_Pragma_Unreferenced (T, False); Generate_Reference (T, T, 'c'); Set_Has_Pragma_Unreferenced (T, B); end; Set_Completion_Referenced (Def_Id); -- For completion of incomplete type, process incomplete dependents -- and always mark the full type as referenced (it is the incomplete -- type that we get for any real reference). elsif Ekind (Prev) = E_Incomplete_Type then Process_Incomplete_Dependents (N, T, Prev); Generate_Reference (Prev, Def_Id, 'c'); Set_Completion_Referenced (Def_Id); -- If not private type or incomplete type completion, this is a real -- definition of a new entity, so record it. else Generate_Definition (Def_Id); end if; -- Propagate any pending access types whose finalization masters need to -- be fully initialized from the partial to the full view. Guard against -- an illegal full view that remains unanalyzed. if Is_Type (Def_Id) and then Is_Incomplete_Or_Private_Type (Prev) then Set_Pending_Access_Types (Def_Id, Pending_Access_Types (Prev)); end if; if Chars (Scope (Def_Id)) = Name_System and then Chars (Def_Id) = Name_Address and then In_Predefined_Unit (N) then Set_Is_Descendant_Of_Address (Def_Id); Set_Is_Descendant_Of_Address (Base_Type (Def_Id)); Set_Is_Descendant_Of_Address (Prev); end if; Set_Optimize_Alignment_Flags (Def_Id); Check_Eliminated (Def_Id); -- If the declaration is a completion and aspects are present, apply -- them to the entity for the type which is currently the partial -- view, but which is the one that will be frozen. if Has_Aspects (N) then -- In most cases the partial view is a private type, and both views -- appear in different declarative parts. In the unusual case where -- the partial view is incomplete, perform the analysis on the -- full view, to prevent freezing anomalies with the corresponding -- class-wide type, which otherwise might be frozen before the -- dispatch table is built. if Prev /= Def_Id and then Ekind (Prev) /= E_Incomplete_Type then Analyze_Aspect_Specifications (N, Prev); -- Normal case else Analyze_Aspect_Specifications (N, Def_Id); end if; end if; if Is_Derived_Type (Prev) and then Def_Id /= Prev then Check_Nonoverridable_Aspects; end if; end Analyze_Full_Type_Declaration; ---------------------------------- -- Analyze_Incomplete_Type_Decl -- ---------------------------------- procedure Analyze_Incomplete_Type_Decl (N : Node_Id) is F : constant Boolean := Is_Pure (Current_Scope); T : Entity_Id; begin Check_SPARK_05_Restriction ("incomplete type is not allowed", N); Generate_Definition (Defining_Identifier (N)); -- Process an incomplete declaration. The identifier must not have been -- declared already in the scope. However, an incomplete declaration may -- appear in the private part of a package, for a private type that has -- already been declared. -- In this case, the discriminants (if any) must match T := Find_Type_Name (N); Set_Ekind (T, E_Incomplete_Type); Init_Size_Align (T); Set_Is_First_Subtype (T, True); Set_Etype (T, T); -- Ada 2005 (AI-326): Minimum decoration to give support to tagged -- incomplete types. if Tagged_Present (N) then Set_Is_Tagged_Type (T, True); Set_No_Tagged_Streams_Pragma (T, No_Tagged_Streams); Make_Class_Wide_Type (T); Set_Direct_Primitive_Operations (T, New_Elmt_List); end if; Set_Stored_Constraint (T, No_Elist); if Present (Discriminant_Specifications (N)) then Push_Scope (T); Process_Discriminants (N); End_Scope; end if; -- If the type has discriminants, nontrivial subtypes may be declared -- before the full view of the type. The full views of those subtypes -- will be built after the full view of the type. Set_Private_Dependents (T, New_Elmt_List); Set_Is_Pure (T, F); end Analyze_Incomplete_Type_Decl; ----------------------------------- -- Analyze_Interface_Declaration -- ----------------------------------- procedure Analyze_Interface_Declaration (T : Entity_Id; Def : Node_Id) is CW : constant Entity_Id := Class_Wide_Type (T); begin Set_Is_Tagged_Type (T); Set_No_Tagged_Streams_Pragma (T, No_Tagged_Streams); Set_Is_Limited_Record (T, Limited_Present (Def) or else Task_Present (Def) or else Protected_Present (Def) or else Synchronized_Present (Def)); -- Type is abstract if full declaration carries keyword, or if previous -- partial view did. Set_Is_Abstract_Type (T); Set_Is_Interface (T); -- Type is a limited interface if it includes the keyword limited, task, -- protected, or synchronized. Set_Is_Limited_Interface (T, Limited_Present (Def) or else Protected_Present (Def) or else Synchronized_Present (Def) or else Task_Present (Def)); Set_Interfaces (T, New_Elmt_List); Set_Direct_Primitive_Operations (T, New_Elmt_List); -- Complete the decoration of the class-wide entity if it was already -- built (i.e. during the creation of the limited view) if Present (CW) then Set_Is_Interface (CW); Set_Is_Limited_Interface (CW, Is_Limited_Interface (T)); end if; -- Check runtime support for synchronized interfaces if (Is_Task_Interface (T) or else Is_Protected_Interface (T) or else Is_Synchronized_Interface (T)) and then not RTE_Available (RE_Select_Specific_Data) then Error_Msg_CRT ("synchronized interfaces", T); end if; end Analyze_Interface_Declaration; ----------------------------- -- Analyze_Itype_Reference -- ----------------------------- -- Nothing to do. This node is placed in the tree only for the benefit of -- back end processing, and has no effect on the semantic processing. procedure Analyze_Itype_Reference (N : Node_Id) is begin pragma Assert (Is_Itype (Itype (N))); null; end Analyze_Itype_Reference; -------------------------------- -- Analyze_Number_Declaration -- -------------------------------- procedure Analyze_Number_Declaration (N : Node_Id) is E : constant Node_Id := Expression (N); Id : constant Entity_Id := Defining_Identifier (N); Index : Interp_Index; It : Interp; T : Entity_Id; begin Generate_Definition (Id); Enter_Name (Id); -- This is an optimization of a common case of an integer literal if Nkind (E) = N_Integer_Literal then Set_Is_Static_Expression (E, True); Set_Etype (E, Universal_Integer); Set_Etype (Id, Universal_Integer); Set_Ekind (Id, E_Named_Integer); Set_Is_Frozen (Id, True); return; end if; Set_Is_Pure (Id, Is_Pure (Current_Scope)); -- Process expression, replacing error by integer zero, to avoid -- cascaded errors or aborts further along in the processing -- Replace Error by integer zero, which seems least likely to cause -- cascaded errors. if E = Error then Rewrite (E, Make_Integer_Literal (Sloc (E), Uint_0)); Set_Error_Posted (E); end if; Analyze (E); -- Verify that the expression is static and numeric. If -- the expression is overloaded, we apply the preference -- rule that favors root numeric types. if not Is_Overloaded (E) then T := Etype (E); if Has_Dynamic_Predicate_Aspect (T) then Error_Msg_N ("subtype has dynamic predicate, " & "not allowed in number declaration", N); end if; else T := Any_Type; Get_First_Interp (E, Index, It); while Present (It.Typ) loop if (Is_Integer_Type (It.Typ) or else Is_Real_Type (It.Typ)) and then (Scope (Base_Type (It.Typ))) = Standard_Standard then if T = Any_Type then T := It.Typ; elsif It.Typ = Universal_Real or else It.Typ = Universal_Integer then -- Choose universal interpretation over any other T := It.Typ; exit; end if; end if; Get_Next_Interp (Index, It); end loop; end if; if Is_Integer_Type (T) then Resolve (E, T); Set_Etype (Id, Universal_Integer); Set_Ekind (Id, E_Named_Integer); elsif Is_Real_Type (T) then -- Because the real value is converted to universal_real, this is a -- legal context for a universal fixed expression. if T = Universal_Fixed then declare Loc : constant Source_Ptr := Sloc (N); Conv : constant Node_Id := Make_Type_Conversion (Loc, Subtype_Mark => New_Occurrence_Of (Universal_Real, Loc), Expression => Relocate_Node (E)); begin Rewrite (E, Conv); Analyze (E); end; elsif T = Any_Fixed then Error_Msg_N ("illegal context for mixed mode operation", E); -- Expression is of the form : universal_fixed * integer. Try to -- resolve as universal_real. T := Universal_Real; Set_Etype (E, T); end if; Resolve (E, T); Set_Etype (Id, Universal_Real); Set_Ekind (Id, E_Named_Real); else Wrong_Type (E, Any_Numeric); Resolve (E, T); Set_Etype (Id, T); Set_Ekind (Id, E_Constant); Set_Never_Set_In_Source (Id, True); Set_Is_True_Constant (Id, True); return; end if; if Nkind_In (E, N_Integer_Literal, N_Real_Literal) then Set_Etype (E, Etype (Id)); end if; if not Is_OK_Static_Expression (E) then Flag_Non_Static_Expr ("non-static expression used in number declaration!", E); Rewrite (E, Make_Integer_Literal (Sloc (N), 1)); Set_Etype (E, Any_Type); end if; Analyze_Dimension (N); end Analyze_Number_Declaration; -------------------------------- -- Analyze_Object_Declaration -- -------------------------------- -- WARNING: This routine manages Ghost regions. Return statements must be -- replaced by gotos which jump to the end of the routine and restore the -- Ghost mode. procedure Analyze_Object_Declaration (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); Id : constant Entity_Id := Defining_Identifier (N); Act_T : Entity_Id; T : Entity_Id; E : Node_Id := Expression (N); -- E is set to Expression (N) throughout this routine. When -- Expression (N) is modified, E is changed accordingly. Prev_Entity : Entity_Id := Empty; function Count_Tasks (T : Entity_Id) return Uint; -- This function is called when a non-generic library level object of a -- task type is declared. Its function is to count the static number of -- tasks declared within the type (it is only called if Has_Task is set -- for T). As a side effect, if an array of tasks with non-static bounds -- or a variant record type is encountered, Check_Restriction is called -- indicating the count is unknown. function Delayed_Aspect_Present return Boolean; -- If the declaration has an expression that is an aggregate, and it -- has aspects that require delayed analysis, the resolution of the -- aggregate must be deferred to the freeze point of the objet. This -- special processing was created for address clauses, but it must -- also apply to Alignment. This must be done before the aspect -- specifications are analyzed because we must handle the aggregate -- before the analysis of the object declaration is complete. -- Any other relevant delayed aspects on object declarations ??? ----------------- -- Count_Tasks -- ----------------- function Count_Tasks (T : Entity_Id) return Uint is C : Entity_Id; X : Node_Id; V : Uint; begin if Is_Task_Type (T) then return Uint_1; elsif Is_Record_Type (T) then if Has_Discriminants (T) then Check_Restriction (Max_Tasks, N); return Uint_0; else V := Uint_0; C := First_Component (T); while Present (C) loop V := V + Count_Tasks (Etype (C)); Next_Component (C); end loop; return V; end if; elsif Is_Array_Type (T) then X := First_Index (T); V := Count_Tasks (Component_Type (T)); while Present (X) loop C := Etype (X); if not Is_OK_Static_Subtype (C) then Check_Restriction (Max_Tasks, N); return Uint_0; else V := V * (UI_Max (Uint_0, Expr_Value (Type_High_Bound (C)) - Expr_Value (Type_Low_Bound (C)) + Uint_1)); end if; Next_Index (X); end loop; return V; else return Uint_0; end if; end Count_Tasks; ---------------------------- -- Delayed_Aspect_Present -- ---------------------------- function Delayed_Aspect_Present return Boolean is A : Node_Id; A_Id : Aspect_Id; begin if Present (Aspect_Specifications (N)) then A := First (Aspect_Specifications (N)); A_Id := Get_Aspect_Id (Chars (Identifier (A))); while Present (A) loop if A_Id = Aspect_Alignment or else A_Id = Aspect_Address then return True; end if; Next (A); end loop; end if; return False; end Delayed_Aspect_Present; -- Local variables Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; -- Save the Ghost mode to restore on exit Related_Id : Entity_Id; -- Start of processing for Analyze_Object_Declaration begin -- There are three kinds of implicit types generated by an -- object declaration: -- 1. Those generated by the original Object Definition -- 2. Those generated by the Expression -- 3. Those used to constrain the Object Definition with the -- expression constraints when the definition is unconstrained. -- They must be generated in this order to avoid order of elaboration -- issues. Thus the first step (after entering the name) is to analyze -- the object definition. if Constant_Present (N) then Prev_Entity := Current_Entity_In_Scope (Id); if Present (Prev_Entity) and then -- If the homograph is an implicit subprogram, it is overridden -- by the current declaration. ((Is_Overloadable (Prev_Entity) and then Is_Inherited_Operation (Prev_Entity)) -- The current object is a discriminal generated for an entry -- family index. Even though the index is a constant, in this -- particular context there is no true constant redeclaration. -- Enter_Name will handle the visibility. or else (Is_Discriminal (Id) and then Ekind (Discriminal_Link (Id)) = E_Entry_Index_Parameter) -- The current object is the renaming for a generic declared -- within the instance. or else (Ekind (Prev_Entity) = E_Package and then Nkind (Parent (Prev_Entity)) = N_Package_Renaming_Declaration and then not Comes_From_Source (Prev_Entity) and then Is_Generic_Instance (Renamed_Entity (Prev_Entity))) -- The entity may be a homonym of a private component of the -- enclosing protected object, for which we create a local -- renaming declaration. The declaration is legal, even if -- useless when it just captures that component. or else (Ekind (Scope (Current_Scope)) = E_Protected_Type and then Nkind (Parent (Prev_Entity)) = N_Object_Renaming_Declaration)) then Prev_Entity := Empty; end if; end if; if Present (Prev_Entity) then -- The object declaration is Ghost when it completes a deferred Ghost -- constant. Mark_And_Set_Ghost_Completion (N, Prev_Entity); Constant_Redeclaration (Id, N, T); Generate_Reference (Prev_Entity, Id, 'c'); Set_Completion_Referenced (Id); if Error_Posted (N) then -- Type mismatch or illegal redeclaration; do not analyze -- expression to avoid cascaded errors. T := Find_Type_Of_Object (Object_Definition (N), N); Set_Etype (Id, T); Set_Ekind (Id, E_Variable); goto Leave; end if; -- In the normal case, enter identifier at the start to catch premature -- usage in the initialization expression. else Generate_Definition (Id); Enter_Name (Id); Mark_Coextensions (N, Object_Definition (N)); T := Find_Type_Of_Object (Object_Definition (N), N); if Nkind (Object_Definition (N)) = N_Access_Definition and then Present (Access_To_Subprogram_Definition (Object_Definition (N))) and then Protected_Present (Access_To_Subprogram_Definition (Object_Definition (N))) then T := Replace_Anonymous_Access_To_Protected_Subprogram (N); end if; if Error_Posted (Id) then Set_Etype (Id, T); Set_Ekind (Id, E_Variable); goto Leave; end if; end if; -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry -- out some static checks. if Ada_Version >= Ada_2005 and then Can_Never_Be_Null (T) then -- In case of aggregates we must also take care of the correct -- initialization of nested aggregates bug this is done at the -- point of the analysis of the aggregate (see sem_aggr.adb) ??? if Present (Expression (N)) and then Nkind (Expression (N)) = N_Aggregate then null; else declare Save_Typ : constant Entity_Id := Etype (Id); begin Set_Etype (Id, T); -- Temp. decoration for static checks Null_Exclusion_Static_Checks (N); Set_Etype (Id, Save_Typ); end; end if; end if; -- Object is marked pure if it is in a pure scope Set_Is_Pure (Id, Is_Pure (Current_Scope)); -- If deferred constant, make sure context is appropriate. We detect -- a deferred constant as a constant declaration with no expression. -- A deferred constant can appear in a package body if its completion -- is by means of an interface pragma. if Constant_Present (N) and then No (E) then -- A deferred constant may appear in the declarative part of the -- following constructs: -- blocks -- entry bodies -- extended return statements -- package specs -- package bodies -- subprogram bodies -- task bodies -- When declared inside a package spec, a deferred constant must be -- completed by a full constant declaration or pragma Import. In all -- other cases, the only proper completion is pragma Import. Extended -- return statements are flagged as invalid contexts because they do -- not have a declarative part and so cannot accommodate the pragma. if Ekind (Current_Scope) = E_Return_Statement then Error_Msg_N ("invalid context for deferred constant declaration (RM 7.4)", N); Error_Msg_N ("\declaration requires an initialization expression", N); Set_Constant_Present (N, False); -- In Ada 83, deferred constant must be of private type elsif not Is_Private_Type (T) then if Ada_Version = Ada_83 and then Comes_From_Source (N) then Error_Msg_N ("(Ada 83) deferred constant must be private type", N); end if; end if; -- If not a deferred constant, then the object declaration freezes -- its type, unless the object is of an anonymous type and has delayed -- aspects. In that case the type is frozen when the object itself is. else Check_Fully_Declared (T, N); if Has_Delayed_Aspects (Id) and then Is_Array_Type (T) and then Is_Itype (T) then Set_Has_Delayed_Freeze (T); else Freeze_Before (N, T); end if; end if; -- If the object was created by a constrained array definition, then -- set the link in both the anonymous base type and anonymous subtype -- that are built to represent the array type to point to the object. if Nkind (Object_Definition (Declaration_Node (Id))) = N_Constrained_Array_Definition then Set_Related_Array_Object (T, Id); Set_Related_Array_Object (Base_Type (T), Id); end if; -- Special checks for protected objects not at library level if Has_Protected (T) and then not Is_Library_Level_Entity (Id) then Check_Restriction (No_Local_Protected_Objects, Id); -- Protected objects with interrupt handlers must be at library level -- Ada 2005: This test is not needed (and the corresponding clause -- in the RM is removed) because accessibility checks are sufficient -- to make handlers not at the library level illegal. -- AI05-0303: The AI is in fact a binding interpretation, and thus -- applies to the '95 version of the language as well. if Is_Protected_Type (T) and then Has_Interrupt_Handler (T) and then Ada_Version < Ada_95 then Error_Msg_N ("interrupt object can only be declared at library level", Id); end if; end if; -- Check for violation of No_Local_Timing_Events if Has_Timing_Event (T) and then not Is_Library_Level_Entity (Id) then Check_Restriction (No_Local_Timing_Events, Id); end if; -- The actual subtype of the object is the nominal subtype, unless -- the nominal one is unconstrained and obtained from the expression. Act_T := T; -- These checks should be performed before the initialization expression -- is considered, so that the Object_Definition node is still the same -- as in source code. -- In SPARK, the nominal subtype is always given by a subtype mark -- and must not be unconstrained. (The only exception to this is the -- acceptance of declarations of constants of type String.) if not Nkind_In (Object_Definition (N), N_Expanded_Name, N_Identifier) then Check_SPARK_05_Restriction ("subtype mark required", Object_Definition (N)); elsif Is_Array_Type (T) and then not Is_Constrained (T) and then T /= Standard_String then Check_SPARK_05_Restriction ("subtype mark of constrained type expected", Object_Definition (N)); end if; -- There are no aliased objects in SPARK if Aliased_Present (N) then Check_SPARK_05_Restriction ("aliased object is not allowed", N); end if; -- Process initialization expression if present and not in error if Present (E) and then E /= Error then -- Generate an error in case of CPP class-wide object initialization. -- Required because otherwise the expansion of the class-wide -- assignment would try to use 'size to initialize the object -- (primitive that is not available in CPP tagged types). if Is_Class_Wide_Type (Act_T) and then (Is_CPP_Class (Root_Type (Etype (Act_T))) or else (Present (Full_View (Root_Type (Etype (Act_T)))) and then Is_CPP_Class (Full_View (Root_Type (Etype (Act_T)))))) then Error_Msg_N ("predefined assignment not available for 'C'P'P tagged types", E); end if; Mark_Coextensions (N, E); Analyze (E); -- In case of errors detected in the analysis of the expression, -- decorate it with the expected type to avoid cascaded errors if No (Etype (E)) then Set_Etype (E, T); end if; -- If an initialization expression is present, then we set the -- Is_True_Constant flag. It will be reset if this is a variable -- and it is indeed modified. Set_Is_True_Constant (Id, True); -- If we are analyzing a constant declaration, set its completion -- flag after analyzing and resolving the expression. if Constant_Present (N) then Set_Has_Completion (Id); end if; -- Set type and resolve (type may be overridden later on). Note: -- Ekind (Id) must still be E_Void at this point so that incorrect -- early usage within E is properly diagnosed. Set_Etype (Id, T); -- If the expression is an aggregate we must look ahead to detect -- the possible presence of an address clause, and defer resolution -- and expansion of the aggregate to the freeze point of the entity. -- This is not always legal because the aggregate may contain other -- references that need freezing, e.g. references to other entities -- with address clauses. In any case, when compiling with -gnatI the -- presence of the address clause must be ignored. if Comes_From_Source (N) and then Expander_Active and then Nkind (E) = N_Aggregate and then ((Present (Following_Address_Clause (N)) and then not Ignore_Rep_Clauses) or else Delayed_Aspect_Present) then Set_Etype (E, T); else Resolve (E, T); end if; -- No further action needed if E is a call to an inlined function -- which returns an unconstrained type and it has been expanded into -- a procedure call. In that case N has been replaced by an object -- declaration without initializing expression and it has been -- analyzed (see Expand_Inlined_Call). if Back_End_Inlining and then Expander_Active and then Nkind (E) = N_Function_Call and then Nkind (Name (E)) in N_Has_Entity and then Is_Inlined (Entity (Name (E))) and then not Is_Constrained (Etype (E)) and then Analyzed (N) and then No (Expression (N)) then goto Leave; end if; -- If E is null and has been replaced by an N_Raise_Constraint_Error -- node (which was marked already-analyzed), we need to set the type -- to something other than Any_Access in order to keep gigi happy. if Etype (E) = Any_Access then Set_Etype (E, T); end if; -- If the object is an access to variable, the initialization -- expression cannot be an access to constant. if Is_Access_Type (T) and then not Is_Access_Constant (T) and then Is_Access_Type (Etype (E)) and then Is_Access_Constant (Etype (E)) then Error_Msg_N ("access to variable cannot be initialized with an " & "access-to-constant expression", E); end if; if not Assignment_OK (N) then Check_Initialization (T, E); end if; Check_Unset_Reference (E); -- If this is a variable, then set current value. If this is a -- declared constant of a scalar type with a static expression, -- indicate that it is always valid. if not Constant_Present (N) then if Compile_Time_Known_Value (E) then Set_Current_Value (Id, E); end if; elsif Is_Scalar_Type (T) and then Is_OK_Static_Expression (E) then Set_Is_Known_Valid (Id); end if; -- Deal with setting of null flags if Is_Access_Type (T) then if Known_Non_Null (E) then Set_Is_Known_Non_Null (Id, True); elsif Known_Null (E) and then not Can_Never_Be_Null (Id) then Set_Is_Known_Null (Id, True); end if; end if; -- Check incorrect use of dynamically tagged expressions if Is_Tagged_Type (T) then Check_Dynamically_Tagged_Expression (Expr => E, Typ => T, Related_Nod => N); end if; Apply_Scalar_Range_Check (E, T); Apply_Static_Length_Check (E, T); if Nkind (Original_Node (N)) = N_Object_Declaration and then Comes_From_Source (Original_Node (N)) -- Only call test if needed and then Restriction_Check_Required (SPARK_05) and then not Is_SPARK_05_Initialization_Expr (Original_Node (E)) then Check_SPARK_05_Restriction ("initialization expression is not appropriate", E); end if; -- A formal parameter of a specific tagged type whose related -- subprogram is subject to pragma Extensions_Visible with value -- "False" cannot be implicitly converted to a class-wide type by -- means of an initialization expression (SPARK RM 6.1.7(3)). Do -- not consider internally generated expressions. if Is_Class_Wide_Type (T) and then Comes_From_Source (E) and then Is_EVF_Expression (E) then Error_Msg_N ("formal parameter cannot be implicitly converted to " & "class-wide type when Extensions_Visible is False", E); end if; end if; -- If the No_Streams restriction is set, check that the type of the -- object is not, and does not contain, any subtype derived from -- Ada.Streams.Root_Stream_Type. Note that we guard the call to -- Has_Stream just for efficiency reasons. There is no point in -- spending time on a Has_Stream check if the restriction is not set. if Restriction_Check_Required (No_Streams) then if Has_Stream (T) then Check_Restriction (No_Streams, N); end if; end if; -- Deal with predicate check before we start to do major rewriting. It -- is OK to initialize and then check the initialized value, since the -- object goes out of scope if we get a predicate failure. Note that we -- do this in the analyzer and not the expander because the analyzer -- does some substantial rewriting in some cases. -- We need a predicate check if the type has predicates that are not -- ignored, and if either there is an initializing expression, or for -- default initialization when we have at least one case of an explicit -- default initial value and then this is not an internal declaration -- whose initialization comes later (as for an aggregate expansion). if not Suppress_Assignment_Checks (N) and then Present (Predicate_Function (T)) and then not Predicates_Ignored (T) and then not No_Initialization (N) and then (Present (E) or else Is_Partially_Initialized_Type (T, Include_Implicit => False)) then -- If the type has a static predicate and the expression is known at -- compile time, see if the expression satisfies the predicate. if Present (E) then Check_Expression_Against_Static_Predicate (E, T); end if; -- If the type is a null record and there is no explicit initial -- expression, no predicate check applies. if No (E) and then Is_Null_Record_Type (T) then null; -- Do not generate a predicate check if the initialization expression -- is a type conversion because the conversion has been subjected to -- the same check. This is a small optimization which avoid redundant -- checks. elsif Present (E) and then Nkind (E) = N_Type_Conversion then null; else Insert_After (N, Make_Predicate_Check (T, New_Occurrence_Of (Id, Loc))); end if; end if; -- Case of unconstrained type if not Is_Definite_Subtype (T) then -- In SPARK, a declaration of unconstrained type is allowed -- only for constants of type string. if Is_String_Type (T) and then not Constant_Present (N) then Check_SPARK_05_Restriction ("declaration of object of unconstrained type not allowed", N); end if; -- Nothing to do in deferred constant case if Constant_Present (N) and then No (E) then null; -- Case of no initialization present elsif No (E) then if No_Initialization (N) then null; elsif Is_Class_Wide_Type (T) then Error_Msg_N ("initialization required in class-wide declaration ", N); else Error_Msg_N ("unconstrained subtype not allowed (need initialization)", Object_Definition (N)); if Is_Record_Type (T) and then Has_Discriminants (T) then Error_Msg_N ("\provide initial value or explicit discriminant values", Object_Definition (N)); Error_Msg_NE ("\or give default discriminant values for type&", Object_Definition (N), T); elsif Is_Array_Type (T) then Error_Msg_N ("\provide initial value or explicit array bounds", Object_Definition (N)); end if; end if; -- Case of initialization present but in error. Set initial -- expression as absent (but do not make above complaints) elsif E = Error then Set_Expression (N, Empty); E := Empty; -- Case of initialization present else -- Check restrictions in Ada 83 if not Constant_Present (N) then -- Unconstrained variables not allowed in Ada 83 mode if Ada_Version = Ada_83 and then Comes_From_Source (Object_Definition (N)) then Error_Msg_N ("(Ada 83) unconstrained variable not allowed", Object_Definition (N)); end if; end if; -- Now we constrain the variable from the initializing expression -- If the expression is an aggregate, it has been expanded into -- individual assignments. Retrieve the actual type from the -- expanded construct. if Is_Array_Type (T) and then No_Initialization (N) and then Nkind (Original_Node (E)) = N_Aggregate then Act_T := Etype (E); -- In case of class-wide interface object declarations we delay -- the generation of the equivalent record type declarations until -- its expansion because there are cases in they are not required. elsif Is_Interface (T) then null; -- In GNATprove mode, Expand_Subtype_From_Expr does nothing. Thus, -- we should prevent the generation of another Itype with the -- same name as the one already generated, or we end up with -- two identical types in GNATprove. elsif GNATprove_Mode then null; -- If the type is an unchecked union, no subtype can be built from -- the expression. Rewrite declaration as a renaming, which the -- back-end can handle properly. This is a rather unusual case, -- because most unchecked_union declarations have default values -- for discriminants and are thus not indefinite. elsif Is_Unchecked_Union (T) then if Constant_Present (N) or else Nkind (E) = N_Function_Call then Set_Ekind (Id, E_Constant); else Set_Ekind (Id, E_Variable); end if; Rewrite (N, Make_Object_Renaming_Declaration (Loc, Defining_Identifier => Id, Subtype_Mark => New_Occurrence_Of (T, Loc), Name => E)); Set_Renamed_Object (Id, E); Freeze_Before (N, T); Set_Is_Frozen (Id); goto Leave; else -- Ensure that the generated subtype has a unique external name -- when the related object is public. This guarantees that the -- subtype and its bounds will not be affected by switches or -- pragmas that may offset the internal counter due to extra -- generated code. if Is_Public (Id) then Related_Id := Id; else Related_Id := Empty; end if; Expand_Subtype_From_Expr (N => N, Unc_Type => T, Subtype_Indic => Object_Definition (N), Exp => E, Related_Id => Related_Id); Act_T := Find_Type_Of_Object (Object_Definition (N), N); end if; Set_Is_Constr_Subt_For_U_Nominal (Act_T); if Aliased_Present (N) then Set_Is_Constr_Subt_For_UN_Aliased (Act_T); end if; Freeze_Before (N, Act_T); Freeze_Before (N, T); end if; elsif Is_Array_Type (T) and then No_Initialization (N) and then (Nkind (Original_Node (E)) = N_Aggregate or else (Nkind (Original_Node (E)) = N_Qualified_Expression and then Nkind (Original_Node (Expression (Original_Node (E)))) = N_Aggregate)) then if not Is_Entity_Name (Object_Definition (N)) then Act_T := Etype (E); Check_Compile_Time_Size (Act_T); if Aliased_Present (N) then Set_Is_Constr_Subt_For_UN_Aliased (Act_T); end if; end if; -- When the given object definition and the aggregate are specified -- independently, and their lengths might differ do a length check. -- This cannot happen if the aggregate is of the form (others =>...) if not Is_Constrained (T) then null; elsif Nkind (E) = N_Raise_Constraint_Error then -- Aggregate is statically illegal. Place back in declaration Set_Expression (N, E); Set_No_Initialization (N, False); elsif T = Etype (E) then null; elsif Nkind (E) = N_Aggregate and then Present (Component_Associations (E)) and then Present (Choice_List (First (Component_Associations (E)))) and then Nkind (First (Choice_List (First (Component_Associations (E))))) = N_Others_Choice then null; else Apply_Length_Check (E, T); end if; -- If the type is limited unconstrained with defaulted discriminants and -- there is no expression, then the object is constrained by the -- defaults, so it is worthwhile building the corresponding subtype. elsif (Is_Limited_Record (T) or else Is_Concurrent_Type (T)) and then not Is_Constrained (T) and then Has_Discriminants (T) then if No (E) then Act_T := Build_Default_Subtype (T, N); else -- Ada 2005: A limited object may be initialized by means of an -- aggregate. If the type has default discriminants it has an -- unconstrained nominal type, Its actual subtype will be obtained -- from the aggregate, and not from the default discriminants. Act_T := Etype (E); end if; Rewrite (Object_Definition (N), New_Occurrence_Of (Act_T, Loc)); elsif Nkind (E) = N_Function_Call and then Constant_Present (N) and then Has_Unconstrained_Elements (Etype (E)) then -- The back-end has problems with constants of a discriminated type -- with defaults, if the initial value is a function call. We -- generate an intermediate temporary that will receive a reference -- to the result of the call. The initialization expression then -- becomes a dereference of that temporary. Remove_Side_Effects (E); -- If this is a constant declaration of an unconstrained type and -- the initialization is an aggregate, we can use the subtype of the -- aggregate for the declared entity because it is immutable. elsif not Is_Constrained (T) and then Has_Discriminants (T) and then Constant_Present (N) and then not Has_Unchecked_Union (T) and then Nkind (E) = N_Aggregate then Act_T := Etype (E); end if; -- Check No_Wide_Characters restriction Check_Wide_Character_Restriction (T, Object_Definition (N)); -- Indicate this is not set in source. Certainly true for constants, and -- true for variables so far (will be reset for a variable if and when -- we encounter a modification in the source). Set_Never_Set_In_Source (Id); -- Now establish the proper kind and type of the object if Constant_Present (N) then Set_Ekind (Id, E_Constant); Set_Is_True_Constant (Id); else Set_Ekind (Id, E_Variable); -- A variable is set as shared passive if it appears in a shared -- passive package, and is at the outer level. This is not done for -- entities generated during expansion, because those are always -- manipulated locally. if Is_Shared_Passive (Current_Scope) and then Is_Library_Level_Entity (Id) and then Comes_From_Source (Id) then Set_Is_Shared_Passive (Id); Check_Shared_Var (Id, T, N); end if; -- Set Has_Initial_Value if initializing expression present. Note -- that if there is no initializing expression, we leave the state -- of this flag unchanged (usually it will be False, but notably in -- the case of exception choice variables, it will already be true). if Present (E) then Set_Has_Initial_Value (Id); end if; end if; -- Initialize alignment and size and capture alignment setting Init_Alignment (Id); Init_Esize (Id); Set_Optimize_Alignment_Flags (Id); -- Deal with aliased case if Aliased_Present (N) then Set_Is_Aliased (Id); -- If the object is aliased and the type is unconstrained with -- defaulted discriminants and there is no expression, then the -- object is constrained by the defaults, so it is worthwhile -- building the corresponding subtype. -- Ada 2005 (AI-363): If the aliased object is discriminated and -- unconstrained, then only establish an actual subtype if the -- nominal subtype is indefinite. In definite cases the object is -- unconstrained in Ada 2005. if No (E) and then Is_Record_Type (T) and then not Is_Constrained (T) and then Has_Discriminants (T) and then (Ada_Version < Ada_2005 or else not Is_Definite_Subtype (T)) then Set_Actual_Subtype (Id, Build_Default_Subtype (T, N)); end if; end if; -- Now we can set the type of the object Set_Etype (Id, Act_T); -- Non-constant object is marked to be treated as volatile if type is -- volatile and we clear the Current_Value setting that may have been -- set above. Doing so for constants isn't required and might interfere -- with possible uses of the object as a static expression in contexts -- incompatible with volatility (e.g. as a case-statement alternative). if Ekind (Id) /= E_Constant and then Treat_As_Volatile (Etype (Id)) then Set_Treat_As_Volatile (Id); Set_Current_Value (Id, Empty); end if; -- Deal with controlled types if Has_Controlled_Component (Etype (Id)) or else Is_Controlled (Etype (Id)) then if not Is_Library_Level_Entity (Id) then Check_Restriction (No_Nested_Finalization, N); else Validate_Controlled_Object (Id); end if; end if; if Has_Task (Etype (Id)) then Check_Restriction (No_Tasking, N); -- Deal with counting max tasks -- Nothing to do if inside a generic if Inside_A_Generic then null; -- If library level entity, then count tasks elsif Is_Library_Level_Entity (Id) then Check_Restriction (Max_Tasks, N, Count_Tasks (Etype (Id))); -- If not library level entity, then indicate we don't know max -- tasks and also check task hierarchy restriction and blocking -- operation (since starting a task is definitely blocking). else Check_Restriction (Max_Tasks, N); Check_Restriction (No_Task_Hierarchy, N); Check_Potentially_Blocking_Operation (N); end if; -- A rather specialized test. If we see two tasks being declared -- of the same type in the same object declaration, and the task -- has an entry with an address clause, we know that program error -- will be raised at run time since we can't have two tasks with -- entries at the same address. if Is_Task_Type (Etype (Id)) and then More_Ids (N) then declare E : Entity_Id; begin E := First_Entity (Etype (Id)); while Present (E) loop if Ekind (E) = E_Entry and then Present (Get_Attribute_Definition_Clause (E, Attribute_Address)) then Error_Msg_Warn := SPARK_Mode /= On; Error_Msg_N ("more than one task with same entry address<<", N); Error_Msg_N ("\Program_Error [<<", N); Insert_Action (N, Make_Raise_Program_Error (Loc, Reason => PE_Duplicated_Entry_Address)); exit; end if; Next_Entity (E); end loop; end; end if; end if; -- Some simple constant-propagation: if the expression is a constant -- string initialized with a literal, share the literal. This avoids -- a run-time copy. if Present (E) and then Is_Entity_Name (E) and then Ekind (Entity (E)) = E_Constant and then Base_Type (Etype (E)) = Standard_String then declare Val : constant Node_Id := Constant_Value (Entity (E)); begin if Present (Val) and then Nkind (Val) = N_String_Literal then Rewrite (E, New_Copy (Val)); end if; end; end if; -- Another optimization: if the nominal subtype is unconstrained and -- the expression is a function call that returns an unconstrained -- type, rewrite the declaration as a renaming of the result of the -- call. The exceptions below are cases where the copy is expected, -- either by the back end (Aliased case) or by the semantics, as for -- initializing controlled types or copying tags for class-wide types. if Present (E) and then Nkind (E) = N_Explicit_Dereference and then Nkind (Original_Node (E)) = N_Function_Call and then not Is_Library_Level_Entity (Id) and then not Is_Constrained (Underlying_Type (T)) and then not Is_Aliased (Id) and then not Is_Class_Wide_Type (T) and then not Is_Controlled_Active (T) and then not Has_Controlled_Component (Base_Type (T)) and then Expander_Active then Rewrite (N, Make_Object_Renaming_Declaration (Loc, Defining_Identifier => Id, Access_Definition => Empty, Subtype_Mark => New_Occurrence_Of (Base_Type (Etype (Id)), Loc), Name => E)); Set_Renamed_Object (Id, E); -- Force generation of debugging information for the constant and for -- the renamed function call. Set_Debug_Info_Needed (Id); Set_Debug_Info_Needed (Entity (Prefix (E))); end if; if Present (Prev_Entity) and then Is_Frozen (Prev_Entity) and then not Error_Posted (Id) then Error_Msg_N ("full constant declaration appears too late", N); end if; Check_Eliminated (Id); -- Deal with setting In_Private_Part flag if in private part if Ekind (Scope (Id)) = E_Package and then In_Private_Part (Scope (Id)) then Set_In_Private_Part (Id); end if; <<Leave>> -- Initialize the refined state of a variable here because this is a -- common destination for legal and illegal object declarations. if Ekind (Id) = E_Variable then Set_Encapsulating_State (Id, Empty); end if; if Has_Aspects (N) then Analyze_Aspect_Specifications (N, Id); end if; Analyze_Dimension (N); -- Verify whether the object declaration introduces an illegal hidden -- state within a package subject to a null abstract state. if Ekind (Id) = E_Variable then Check_No_Hidden_State (Id); end if; Restore_Ghost_Mode (Saved_GM); end Analyze_Object_Declaration; --------------------------- -- Analyze_Others_Choice -- --------------------------- -- Nothing to do for the others choice node itself, the semantic analysis -- of the others choice will occur as part of the processing of the parent procedure Analyze_Others_Choice (N : Node_Id) is pragma Warnings (Off, N); begin null; end Analyze_Others_Choice; ------------------------------------------- -- Analyze_Private_Extension_Declaration -- ------------------------------------------- procedure Analyze_Private_Extension_Declaration (N : Node_Id) is Indic : constant Node_Id := Subtype_Indication (N); T : constant Entity_Id := Defining_Identifier (N); Iface : Entity_Id; Iface_Elmt : Elmt_Id; Parent_Base : Entity_Id; Parent_Type : Entity_Id; begin -- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces if Is_Non_Empty_List (Interface_List (N)) then declare Intf : Node_Id; T : Entity_Id; begin Intf := First (Interface_List (N)); while Present (Intf) loop T := Find_Type_Of_Subtype_Indic (Intf); Diagnose_Interface (Intf, T); Next (Intf); end loop; end; end if; Generate_Definition (T); -- For other than Ada 2012, just enter the name in the current scope if Ada_Version < Ada_2012 then Enter_Name (T); -- Ada 2012 (AI05-0162): Enter the name in the current scope handling -- case of private type that completes an incomplete type. else declare Prev : Entity_Id; begin Prev := Find_Type_Name (N); pragma Assert (Prev = T or else (Ekind (Prev) = E_Incomplete_Type and then Present (Full_View (Prev)) and then Full_View (Prev) = T)); end; end if; Parent_Type := Find_Type_Of_Subtype_Indic (Indic); Parent_Base := Base_Type (Parent_Type); if Parent_Type = Any_Type or else Etype (Parent_Type) = Any_Type then Set_Ekind (T, Ekind (Parent_Type)); Set_Etype (T, Any_Type); goto Leave; elsif not Is_Tagged_Type (Parent_Type) then Error_Msg_N ("parent of type extension must be a tagged type ", Indic); goto Leave; elsif Ekind_In (Parent_Type, E_Void, E_Incomplete_Type) then Error_Msg_N ("premature derivation of incomplete type", Indic); goto Leave; elsif Is_Concurrent_Type (Parent_Type) then Error_Msg_N ("parent type of a private extension cannot be a synchronized " & "tagged type (RM 3.9.1 (3/1))", N); Set_Etype (T, Any_Type); Set_Ekind (T, E_Limited_Private_Type); Set_Private_Dependents (T, New_Elmt_List); Set_Error_Posted (T); goto Leave; end if; -- Perhaps the parent type should be changed to the class-wide type's -- specific type in this case to prevent cascading errors ??? if Is_Class_Wide_Type (Parent_Type) then Error_Msg_N ("parent of type extension must not be a class-wide type", Indic); goto Leave; end if; if (not Is_Package_Or_Generic_Package (Current_Scope) and then Nkind (Parent (N)) /= N_Generic_Subprogram_Declaration) or else In_Private_Part (Current_Scope) then Error_Msg_N ("invalid context for private extension", N); end if; -- Set common attributes Set_Is_Pure (T, Is_Pure (Current_Scope)); Set_Scope (T, Current_Scope); Set_Ekind (T, E_Record_Type_With_Private); Init_Size_Align (T); Set_Default_SSO (T); Set_Etype (T, Parent_Base); Propagate_Concurrent_Flags (T, Parent_Base); Set_Convention (T, Convention (Parent_Type)); Set_First_Rep_Item (T, First_Rep_Item (Parent_Type)); Set_Is_First_Subtype (T); Make_Class_Wide_Type (T); if Unknown_Discriminants_Present (N) then Set_Discriminant_Constraint (T, No_Elist); end if; Build_Derived_Record_Type (N, Parent_Type, T); -- A private extension inherits the Default_Initial_Condition pragma -- coming from any parent type within the derivation chain. if Has_DIC (Parent_Type) then Set_Has_Inherited_DIC (T); end if; -- A private extension inherits any class-wide invariants coming from a -- parent type or an interface. Note that the invariant procedure of the -- parent type should not be inherited because the private extension may -- define invariants of its own. if Has_Inherited_Invariants (Parent_Type) or else Has_Inheritable_Invariants (Parent_Type) then Set_Has_Inherited_Invariants (T); elsif Present (Interfaces (T)) then Iface_Elmt := First_Elmt (Interfaces (T)); while Present (Iface_Elmt) loop Iface := Node (Iface_Elmt); if Has_Inheritable_Invariants (Iface) then Set_Has_Inherited_Invariants (T); exit; end if; Next_Elmt (Iface_Elmt); end loop; end if; -- Ada 2005 (AI-443): Synchronized private extension or a rewritten -- synchronized formal derived type. if Ada_Version >= Ada_2005 and then Synchronized_Present (N) then Set_Is_Limited_Record (T); -- Formal derived type case if Is_Generic_Type (T) then -- The parent must be a tagged limited type or a synchronized -- interface. if (not Is_Tagged_Type (Parent_Type) or else not Is_Limited_Type (Parent_Type)) and then (not Is_Interface (Parent_Type) or else not Is_Synchronized_Interface (Parent_Type)) then Error_Msg_NE ("parent type of & must be tagged limited or synchronized", N, T); end if; -- The progenitors (if any) must be limited or synchronized -- interfaces. if Present (Interfaces (T)) then Iface_Elmt := First_Elmt (Interfaces (T)); while Present (Iface_Elmt) loop Iface := Node (Iface_Elmt); if not Is_Limited_Interface (Iface) and then not Is_Synchronized_Interface (Iface) then Error_Msg_NE ("progenitor & must be limited or synchronized", N, Iface); end if; Next_Elmt (Iface_Elmt); end loop; end if; -- Regular derived extension, the parent must be a limited or -- synchronized interface. else if not Is_Interface (Parent_Type) or else (not Is_Limited_Interface (Parent_Type) and then not Is_Synchronized_Interface (Parent_Type)) then Error_Msg_NE ("parent type of & must be limited interface", N, T); end if; end if; -- A consequence of 3.9.4 (6/2) and 7.3 (7.2/2) is that a private -- extension with a synchronized parent must be explicitly declared -- synchronized, because the full view will be a synchronized type. -- This must be checked before the check for limited types below, -- to ensure that types declared limited are not allowed to extend -- synchronized interfaces. elsif Is_Interface (Parent_Type) and then Is_Synchronized_Interface (Parent_Type) and then not Synchronized_Present (N) then Error_Msg_NE ("private extension of& must be explicitly synchronized", N, Parent_Type); elsif Limited_Present (N) then Set_Is_Limited_Record (T); if not Is_Limited_Type (Parent_Type) and then (not Is_Interface (Parent_Type) or else not Is_Limited_Interface (Parent_Type)) then Error_Msg_NE ("parent type& of limited extension must be limited", N, Parent_Type); end if; end if; -- Remember that its parent type has a private extension. Used to warn -- on public primitives of the parent type defined after its private -- extensions (see Check_Dispatching_Operation). Set_Has_Private_Extension (Parent_Type); <<Leave>> if Has_Aspects (N) then Analyze_Aspect_Specifications (N, T); end if; end Analyze_Private_Extension_Declaration; --------------------------------- -- Analyze_Subtype_Declaration -- --------------------------------- procedure Analyze_Subtype_Declaration (N : Node_Id; Skip : Boolean := False) is Id : constant Entity_Id := Defining_Identifier (N); R_Checks : Check_Result; T : Entity_Id; begin Generate_Definition (Id); Set_Is_Pure (Id, Is_Pure (Current_Scope)); Init_Size_Align (Id); -- The following guard condition on Enter_Name is to handle cases where -- the defining identifier has already been entered into the scope but -- the declaration as a whole needs to be analyzed. -- This case in particular happens for derived enumeration types. The -- derived enumeration type is processed as an inserted enumeration type -- declaration followed by a rewritten subtype declaration. The defining -- identifier, however, is entered into the name scope very early in the -- processing of the original type declaration and therefore needs to be -- avoided here, when the created subtype declaration is analyzed. (See -- Build_Derived_Types) -- This also happens when the full view of a private type is derived -- type with constraints. In this case the entity has been introduced -- in the private declaration. -- Finally this happens in some complex cases when validity checks are -- enabled, where the same subtype declaration may be analyzed twice. -- This can happen if the subtype is created by the pre-analysis of -- an attribute tht gives the range of a loop statement, and the loop -- itself appears within an if_statement that will be rewritten during -- expansion. if Skip or else (Present (Etype (Id)) and then (Is_Private_Type (Etype (Id)) or else Is_Task_Type (Etype (Id)) or else Is_Rewrite_Substitution (N))) then null; elsif Current_Entity (Id) = Id then null; else Enter_Name (Id); end if; T := Process_Subtype (Subtype_Indication (N), N, Id, 'P'); -- Class-wide equivalent types of records with unknown discriminants -- involve the generation of an itype which serves as the private view -- of a constrained record subtype. In such cases the base type of the -- current subtype we are processing is the private itype. Use the full -- of the private itype when decorating various attributes. if Is_Itype (T) and then Is_Private_Type (T) and then Present (Full_View (T)) then T := Full_View (T); end if; -- Inherit common attributes Set_Is_Volatile (Id, Is_Volatile (T)); Set_Treat_As_Volatile (Id, Treat_As_Volatile (T)); Set_Is_Generic_Type (Id, Is_Generic_Type (Base_Type (T))); Set_Convention (Id, Convention (T)); -- If ancestor has predicates then so does the subtype, and in addition -- we must delay the freeze to properly arrange predicate inheritance. -- The Ancestor_Type test is really unpleasant, there seem to be cases -- in which T = ID, so the above tests and assignments do nothing??? if Has_Predicates (T) or else (Present (Ancestor_Subtype (T)) and then Has_Predicates (Ancestor_Subtype (T))) then Set_Has_Predicates (Id); Set_Has_Delayed_Freeze (Id); -- Generated subtypes inherit the predicate function from the parent -- (no aspects to examine on the generated declaration). if not Comes_From_Source (N) then Set_Ekind (Id, Ekind (T)); if Present (Predicate_Function (T)) then Set_Predicate_Function (Id, Predicate_Function (T)); elsif Present (Ancestor_Subtype (T)) and then Has_Predicates (Ancestor_Subtype (T)) and then Present (Predicate_Function (Ancestor_Subtype (T))) then Set_Predicate_Function (Id, Predicate_Function (Ancestor_Subtype (T))); end if; end if; end if; -- Subtype of Boolean cannot have a constraint in SPARK if Is_Boolean_Type (T) and then Nkind (Subtype_Indication (N)) = N_Subtype_Indication then Check_SPARK_05_Restriction ("subtype of Boolean cannot have constraint", N); end if; if Nkind (Subtype_Indication (N)) = N_Subtype_Indication then declare Cstr : constant Node_Id := Constraint (Subtype_Indication (N)); One_Cstr : Node_Id; Low : Node_Id; High : Node_Id; begin if Nkind (Cstr) = N_Index_Or_Discriminant_Constraint then One_Cstr := First (Constraints (Cstr)); while Present (One_Cstr) loop -- Index or discriminant constraint in SPARK must be a -- subtype mark. if not Nkind_In (One_Cstr, N_Identifier, N_Expanded_Name) then Check_SPARK_05_Restriction ("subtype mark required", One_Cstr); -- String subtype must have a lower bound of 1 in SPARK. -- Note that we do not need to test for the non-static case -- here, since that was already taken care of in -- Process_Range_Expr_In_Decl. elsif Base_Type (T) = Standard_String then Get_Index_Bounds (One_Cstr, Low, High); if Is_OK_Static_Expression (Low) and then Expr_Value (Low) /= 1 then Check_SPARK_05_Restriction ("String subtype must have lower bound of 1", N); end if; end if; Next (One_Cstr); end loop; end if; end; end if; -- In the case where there is no constraint given in the subtype -- indication, Process_Subtype just returns the Subtype_Mark, so its -- semantic attributes must be established here. if Nkind (Subtype_Indication (N)) /= N_Subtype_Indication then Set_Etype (Id, Base_Type (T)); -- Subtype of unconstrained array without constraint is not allowed -- in SPARK. if Is_Array_Type (T) and then not Is_Constrained (T) then Check_SPARK_05_Restriction ("subtype of unconstrained array must have constraint", N); end if; case Ekind (T) is when Array_Kind => Set_Ekind (Id, E_Array_Subtype); Copy_Array_Subtype_Attributes (Id, T); when Decimal_Fixed_Point_Kind => Set_Ekind (Id, E_Decimal_Fixed_Point_Subtype); Set_Digits_Value (Id, Digits_Value (T)); Set_Delta_Value (Id, Delta_Value (T)); Set_Scale_Value (Id, Scale_Value (T)); Set_Small_Value (Id, Small_Value (T)); Set_Scalar_Range (Id, Scalar_Range (T)); Set_Machine_Radix_10 (Id, Machine_Radix_10 (T)); Set_Is_Constrained (Id, Is_Constrained (T)); Set_Is_Known_Valid (Id, Is_Known_Valid (T)); Set_RM_Size (Id, RM_Size (T)); when Enumeration_Kind => Set_Ekind (Id, E_Enumeration_Subtype); Set_First_Literal (Id, First_Literal (Base_Type (T))); Set_Scalar_Range (Id, Scalar_Range (T)); Set_Is_Character_Type (Id, Is_Character_Type (T)); Set_Is_Constrained (Id, Is_Constrained (T)); Set_Is_Known_Valid (Id, Is_Known_Valid (T)); Set_RM_Size (Id, RM_Size (T)); Inherit_Predicate_Flags (Id, T); when Ordinary_Fixed_Point_Kind => Set_Ekind (Id, E_Ordinary_Fixed_Point_Subtype); Set_Scalar_Range (Id, Scalar_Range (T)); Set_Small_Value (Id, Small_Value (T)); Set_Delta_Value (Id, Delta_Value (T)); Set_Is_Constrained (Id, Is_Constrained (T)); Set_Is_Known_Valid (Id, Is_Known_Valid (T)); Set_RM_Size (Id, RM_Size (T)); when Float_Kind => Set_Ekind (Id, E_Floating_Point_Subtype); Set_Scalar_Range (Id, Scalar_Range (T)); Set_Digits_Value (Id, Digits_Value (T)); Set_Is_Constrained (Id, Is_Constrained (T)); -- If the floating point type has dimensions, these will be -- inherited subsequently when Analyze_Dimensions is called. when Signed_Integer_Kind => Set_Ekind (Id, E_Signed_Integer_Subtype); Set_Scalar_Range (Id, Scalar_Range (T)); Set_Is_Constrained (Id, Is_Constrained (T)); Set_Is_Known_Valid (Id, Is_Known_Valid (T)); Set_RM_Size (Id, RM_Size (T)); Inherit_Predicate_Flags (Id, T); when Modular_Integer_Kind => Set_Ekind (Id, E_Modular_Integer_Subtype); Set_Scalar_Range (Id, Scalar_Range (T)); Set_Is_Constrained (Id, Is_Constrained (T)); Set_Is_Known_Valid (Id, Is_Known_Valid (T)); Set_RM_Size (Id, RM_Size (T)); Inherit_Predicate_Flags (Id, T); when Class_Wide_Kind => Set_Ekind (Id, E_Class_Wide_Subtype); Set_Class_Wide_Type (Id, Class_Wide_Type (T)); Set_Cloned_Subtype (Id, T); Set_Is_Tagged_Type (Id, True); Set_Has_Unknown_Discriminants (Id, True); Set_No_Tagged_Streams_Pragma (Id, No_Tagged_Streams_Pragma (T)); if Ekind (T) = E_Class_Wide_Subtype then Set_Equivalent_Type (Id, Equivalent_Type (T)); end if; when E_Record_Subtype | E_Record_Type => Set_Ekind (Id, E_Record_Subtype); if Ekind (T) = E_Record_Subtype and then Present (Cloned_Subtype (T)) then Set_Cloned_Subtype (Id, Cloned_Subtype (T)); else Set_Cloned_Subtype (Id, T); end if; Set_First_Entity (Id, First_Entity (T)); Set_Last_Entity (Id, Last_Entity (T)); Set_Has_Discriminants (Id, Has_Discriminants (T)); Set_Is_Constrained (Id, Is_Constrained (T)); Set_Is_Limited_Record (Id, Is_Limited_Record (T)); Set_Has_Implicit_Dereference (Id, Has_Implicit_Dereference (T)); Set_Has_Unknown_Discriminants (Id, Has_Unknown_Discriminants (T)); if Has_Discriminants (T) then Set_Discriminant_Constraint (Id, Discriminant_Constraint (T)); Set_Stored_Constraint_From_Discriminant_Constraint (Id); elsif Has_Unknown_Discriminants (Id) then Set_Discriminant_Constraint (Id, No_Elist); end if; if Is_Tagged_Type (T) then Set_Is_Tagged_Type (Id, True); Set_No_Tagged_Streams_Pragma (Id, No_Tagged_Streams_Pragma (T)); Set_Is_Abstract_Type (Id, Is_Abstract_Type (T)); Set_Direct_Primitive_Operations (Id, Direct_Primitive_Operations (T)); Set_Class_Wide_Type (Id, Class_Wide_Type (T)); if Is_Interface (T) then Set_Is_Interface (Id); Set_Is_Limited_Interface (Id, Is_Limited_Interface (T)); end if; end if; when Private_Kind => Set_Ekind (Id, Subtype_Kind (Ekind (T))); Set_Has_Discriminants (Id, Has_Discriminants (T)); Set_Is_Constrained (Id, Is_Constrained (T)); Set_First_Entity (Id, First_Entity (T)); Set_Last_Entity (Id, Last_Entity (T)); Set_Private_Dependents (Id, New_Elmt_List); Set_Is_Limited_Record (Id, Is_Limited_Record (T)); Set_Has_Implicit_Dereference (Id, Has_Implicit_Dereference (T)); Set_Has_Unknown_Discriminants (Id, Has_Unknown_Discriminants (T)); Set_Known_To_Have_Preelab_Init (Id, Known_To_Have_Preelab_Init (T)); if Is_Tagged_Type (T) then Set_Is_Tagged_Type (Id); Set_No_Tagged_Streams_Pragma (Id, No_Tagged_Streams_Pragma (T)); Set_Is_Abstract_Type (Id, Is_Abstract_Type (T)); Set_Class_Wide_Type (Id, Class_Wide_Type (T)); Set_Direct_Primitive_Operations (Id, Direct_Primitive_Operations (T)); end if; -- In general the attributes of the subtype of a private type -- are the attributes of the partial view of parent. However, -- the full view may be a discriminated type, and the subtype -- must share the discriminant constraint to generate correct -- calls to initialization procedures. if Has_Discriminants (T) then Set_Discriminant_Constraint (Id, Discriminant_Constraint (T)); Set_Stored_Constraint_From_Discriminant_Constraint (Id); elsif Present (Full_View (T)) and then Has_Discriminants (Full_View (T)) then Set_Discriminant_Constraint (Id, Discriminant_Constraint (Full_View (T))); Set_Stored_Constraint_From_Discriminant_Constraint (Id); -- This would seem semantically correct, but apparently -- generates spurious errors about missing components ??? -- Set_Has_Discriminants (Id); end if; Prepare_Private_Subtype_Completion (Id, N); -- If this is the subtype of a constrained private type with -- discriminants that has got a full view and we also have -- built a completion just above, show that the completion -- is a clone of the full view to the back-end. if Has_Discriminants (T) and then not Has_Unknown_Discriminants (T) and then not Is_Empty_Elmt_List (Discriminant_Constraint (T)) and then Present (Full_View (T)) and then Present (Full_View (Id)) then Set_Cloned_Subtype (Full_View (Id), Full_View (T)); end if; when Access_Kind => Set_Ekind (Id, E_Access_Subtype); Set_Is_Constrained (Id, Is_Constrained (T)); Set_Is_Access_Constant (Id, Is_Access_Constant (T)); Set_Directly_Designated_Type (Id, Designated_Type (T)); Set_Can_Never_Be_Null (Id, Can_Never_Be_Null (T)); -- A Pure library_item must not contain the declaration of a -- named access type, except within a subprogram, generic -- subprogram, task unit, or protected unit, or if it has -- a specified Storage_Size of zero (RM05-10.2.1(15.4-15.5)). if Comes_From_Source (Id) and then In_Pure_Unit and then not In_Subprogram_Task_Protected_Unit and then not No_Pool_Assigned (Id) then Error_Msg_N ("named access types not allowed in pure unit", N); end if; when Concurrent_Kind => Set_Ekind (Id, Subtype_Kind (Ekind (T))); Set_Corresponding_Record_Type (Id, Corresponding_Record_Type (T)); Set_First_Entity (Id, First_Entity (T)); Set_First_Private_Entity (Id, First_Private_Entity (T)); Set_Has_Discriminants (Id, Has_Discriminants (T)); Set_Is_Constrained (Id, Is_Constrained (T)); Set_Is_Tagged_Type (Id, Is_Tagged_Type (T)); Set_Last_Entity (Id, Last_Entity (T)); if Is_Tagged_Type (T) then Set_No_Tagged_Streams_Pragma (Id, No_Tagged_Streams_Pragma (T)); end if; if Has_Discriminants (T) then Set_Discriminant_Constraint (Id, Discriminant_Constraint (T)); Set_Stored_Constraint_From_Discriminant_Constraint (Id); end if; when Incomplete_Kind => if Ada_Version >= Ada_2005 then -- In Ada 2005 an incomplete type can be explicitly tagged: -- propagate indication. Note that we also have to include -- subtypes for Ada 2012 extended use of incomplete types. Set_Ekind (Id, E_Incomplete_Subtype); Set_Is_Tagged_Type (Id, Is_Tagged_Type (T)); Set_Private_Dependents (Id, New_Elmt_List); if Is_Tagged_Type (Id) then Set_No_Tagged_Streams_Pragma (Id, No_Tagged_Streams_Pragma (T)); Set_Direct_Primitive_Operations (Id, New_Elmt_List); end if; -- Ada 2005 (AI-412): Decorate an incomplete subtype of an -- incomplete type visible through a limited with clause. if From_Limited_With (T) and then Present (Non_Limited_View (T)) then Set_From_Limited_With (Id); Set_Non_Limited_View (Id, Non_Limited_View (T)); -- Ada 2005 (AI-412): Add the regular incomplete subtype -- to the private dependents of the original incomplete -- type for future transformation. else Append_Elmt (Id, Private_Dependents (T)); end if; -- If the subtype name denotes an incomplete type an error -- was already reported by Process_Subtype. else Set_Etype (Id, Any_Type); end if; when others => raise Program_Error; end case; end if; if Etype (Id) = Any_Type then goto Leave; end if; -- Some common processing on all types Set_Size_Info (Id, T); Set_First_Rep_Item (Id, First_Rep_Item (T)); -- If the parent type is a generic actual, so is the subtype. This may -- happen in a nested instance. Why Comes_From_Source test??? if not Comes_From_Source (N) then Set_Is_Generic_Actual_Type (Id, Is_Generic_Actual_Type (T)); end if; -- If this is a subtype declaration for an actual in an instance, -- inherit static and dynamic predicates if any. -- If declaration has no aspect specifications, inherit predicate -- info as well. Unclear how to handle the case of both specified -- and inherited predicates ??? Other inherited aspects, such as -- invariants, should be OK, but the combination with later pragmas -- may also require special merging. if Has_Predicates (T) and then Present (Predicate_Function (T)) and then ((In_Instance and then not Comes_From_Source (N)) or else No (Aspect_Specifications (N))) then Set_Subprograms_For_Type (Id, Subprograms_For_Type (T)); if Has_Static_Predicate (T) then Set_Has_Static_Predicate (Id); Set_Static_Discrete_Predicate (Id, Static_Discrete_Predicate (T)); end if; end if; -- Remaining processing depends on characteristics of base type T := Etype (Id); Set_Is_Immediately_Visible (Id, True); Set_Depends_On_Private (Id, Has_Private_Component (T)); Set_Is_Descendant_Of_Address (Id, Is_Descendant_Of_Address (T)); if Is_Interface (T) then Set_Is_Interface (Id); end if; if Present (Generic_Parent_Type (N)) and then (Nkind (Parent (Generic_Parent_Type (N))) /= N_Formal_Type_Declaration or else Nkind (Formal_Type_Definition (Parent (Generic_Parent_Type (N)))) /= N_Formal_Private_Type_Definition) then if Is_Tagged_Type (Id) then -- If this is a generic actual subtype for a synchronized type, -- the primitive operations are those of the corresponding record -- for which there is a separate subtype declaration. if Is_Concurrent_Type (Id) then null; elsif Is_Class_Wide_Type (Id) then Derive_Subprograms (Generic_Parent_Type (N), Id, Etype (T)); else Derive_Subprograms (Generic_Parent_Type (N), Id, T); end if; elsif Scope (Etype (Id)) /= Standard_Standard then Derive_Subprograms (Generic_Parent_Type (N), Id); end if; end if; if Is_Private_Type (T) and then Present (Full_View (T)) then Conditional_Delay (Id, Full_View (T)); -- The subtypes of components or subcomponents of protected types -- do not need freeze nodes, which would otherwise appear in the -- wrong scope (before the freeze node for the protected type). The -- proper subtypes are those of the subcomponents of the corresponding -- record. elsif Ekind (Scope (Id)) /= E_Protected_Type and then Present (Scope (Scope (Id))) -- error defense and then Ekind (Scope (Scope (Id))) /= E_Protected_Type then Conditional_Delay (Id, T); end if; -- Check that Constraint_Error is raised for a scalar subtype indication -- when the lower or upper bound of a non-null range lies outside the -- range of the type mark. if Nkind (Subtype_Indication (N)) = N_Subtype_Indication then if Is_Scalar_Type (Etype (Id)) and then Scalar_Range (Id) /= Scalar_Range (Etype (Subtype_Mark (Subtype_Indication (N)))) then Apply_Range_Check (Scalar_Range (Id), Etype (Subtype_Mark (Subtype_Indication (N)))); -- In the array case, check compatibility for each index elsif Is_Array_Type (Etype (Id)) and then Present (First_Index (Id)) then -- This really should be a subprogram that finds the indications -- to check??? declare Subt_Index : Node_Id := First_Index (Id); Target_Index : Node_Id := First_Index (Etype (Subtype_Mark (Subtype_Indication (N)))); Has_Dyn_Chk : Boolean := Has_Dynamic_Range_Check (N); begin while Present (Subt_Index) loop if ((Nkind (Subt_Index) = N_Identifier and then Ekind (Entity (Subt_Index)) in Scalar_Kind) or else Nkind (Subt_Index) = N_Subtype_Indication) and then Nkind (Scalar_Range (Etype (Subt_Index))) = N_Range then declare Target_Typ : constant Entity_Id := Etype (Target_Index); begin R_Checks := Get_Range_Checks (Scalar_Range (Etype (Subt_Index)), Target_Typ, Etype (Subt_Index), Defining_Identifier (N)); -- Reset Has_Dynamic_Range_Check on the subtype to -- prevent elision of the index check due to a dynamic -- check generated for a preceding index (needed since -- Insert_Range_Checks tries to avoid generating -- redundant checks on a given declaration). Set_Has_Dynamic_Range_Check (N, False); Insert_Range_Checks (R_Checks, N, Target_Typ, Sloc (Defining_Identifier (N))); -- Record whether this index involved a dynamic check Has_Dyn_Chk := Has_Dyn_Chk or else Has_Dynamic_Range_Check (N); end; end if; Next_Index (Subt_Index); Next_Index (Target_Index); end loop; -- Finally, mark whether the subtype involves dynamic checks Set_Has_Dynamic_Range_Check (N, Has_Dyn_Chk); end; end if; end if; Set_Optimize_Alignment_Flags (Id); Check_Eliminated (Id); <<Leave>> if Has_Aspects (N) then Analyze_Aspect_Specifications (N, Id); end if; Analyze_Dimension (N); -- Check No_Dynamic_Sized_Objects restriction, which disallows subtype -- indications on composite types where the constraints are dynamic. -- Note that object declarations and aggregates generate implicit -- subtype declarations, which this covers. One special case is that the -- implicitly generated "=" for discriminated types includes an -- offending subtype declaration, which is harmless, so we ignore it -- here. if Nkind (Subtype_Indication (N)) = N_Subtype_Indication then declare Cstr : constant Node_Id := Constraint (Subtype_Indication (N)); begin if Nkind (Cstr) = N_Index_Or_Discriminant_Constraint and then not (Is_Internal (Id) and then Is_TSS (Scope (Id), TSS_Composite_Equality)) and then not Within_Init_Proc and then not All_Composite_Constraints_Static (Cstr) then Check_Restriction (No_Dynamic_Sized_Objects, Cstr); end if; end; end if; end Analyze_Subtype_Declaration; -------------------------------- -- Analyze_Subtype_Indication -- -------------------------------- procedure Analyze_Subtype_Indication (N : Node_Id) is T : constant Entity_Id := Subtype_Mark (N); R : constant Node_Id := Range_Expression (Constraint (N)); begin Analyze (T); if R /= Error then Analyze (R); Set_Etype (N, Etype (R)); Resolve (R, Entity (T)); else Set_Error_Posted (R); Set_Error_Posted (T); end if; end Analyze_Subtype_Indication; -------------------------- -- Analyze_Variant_Part -- -------------------------- procedure Analyze_Variant_Part (N : Node_Id) is Discr_Name : Node_Id; Discr_Type : Entity_Id; procedure Process_Variant (A : Node_Id); -- Analyze declarations for a single variant package Analyze_Variant_Choices is new Generic_Analyze_Choices (Process_Variant); use Analyze_Variant_Choices; --------------------- -- Process_Variant -- --------------------- procedure Process_Variant (A : Node_Id) is CL : constant Node_Id := Component_List (A); begin if not Null_Present (CL) then Analyze_Declarations (Component_Items (CL)); if Present (Variant_Part (CL)) then Analyze (Variant_Part (CL)); end if; end if; end Process_Variant; -- Start of processing for Analyze_Variant_Part begin Discr_Name := Name (N); Analyze (Discr_Name); -- If Discr_Name bad, get out (prevent cascaded errors) if Etype (Discr_Name) = Any_Type then return; end if; -- Check invalid discriminant in variant part if Ekind (Entity (Discr_Name)) /= E_Discriminant then Error_Msg_N ("invalid discriminant name in variant part", Discr_Name); end if; Discr_Type := Etype (Entity (Discr_Name)); if not Is_Discrete_Type (Discr_Type) then Error_Msg_N ("discriminant in a variant part must be of a discrete type", Name (N)); return; end if; -- Now analyze the choices, which also analyzes the declarations that -- are associated with each choice. Analyze_Choices (Variants (N), Discr_Type); -- Note: we used to instantiate and call Check_Choices here to check -- that the choices covered the discriminant, but it's too early to do -- that because of statically predicated subtypes, whose analysis may -- be deferred to their freeze point which may be as late as the freeze -- point of the containing record. So this call is now to be found in -- Freeze_Record_Declaration. end Analyze_Variant_Part; ---------------------------- -- Array_Type_Declaration -- ---------------------------- procedure Array_Type_Declaration (T : in out Entity_Id; Def : Node_Id) is Component_Def : constant Node_Id := Component_Definition (Def); Component_Typ : constant Node_Id := Subtype_Indication (Component_Def); P : constant Node_Id := Parent (Def); Element_Type : Entity_Id; Implicit_Base : Entity_Id; Index : Node_Id; Nb_Index : Nat; Priv : Entity_Id; Related_Id : Entity_Id := Empty; begin if Nkind (Def) = N_Constrained_Array_Definition then Index := First (Discrete_Subtype_Definitions (Def)); else Index := First (Subtype_Marks (Def)); end if; -- Find proper names for the implicit types which may be public. In case -- of anonymous arrays we use the name of the first object of that type -- as prefix. if No (T) then Related_Id := Defining_Identifier (P); else Related_Id := T; end if; Nb_Index := 1; while Present (Index) loop Analyze (Index); -- Test for odd case of trying to index a type by the type itself if Is_Entity_Name (Index) and then Entity (Index) = T then Error_Msg_N ("type& cannot be indexed by itself", Index); Set_Entity (Index, Standard_Boolean); Set_Etype (Index, Standard_Boolean); end if; -- Check SPARK restriction requiring a subtype mark if not Nkind_In (Index, N_Identifier, N_Expanded_Name) then Check_SPARK_05_Restriction ("subtype mark required", Index); end if; -- Add a subtype declaration for each index of private array type -- declaration whose etype is also private. For example: -- package Pkg is -- type Index is private; -- private -- type Table is array (Index) of ... -- end; -- This is currently required by the expander for the internally -- generated equality subprogram of records with variant parts in -- which the etype of some component is such private type. if Ekind (Current_Scope) = E_Package and then In_Private_Part (Current_Scope) and then Has_Private_Declaration (Etype (Index)) then declare Loc : constant Source_Ptr := Sloc (Def); Decl : Entity_Id; New_E : Entity_Id; begin New_E := Make_Temporary (Loc, 'T'); Set_Is_Internal (New_E); Decl := Make_Subtype_Declaration (Loc, Defining_Identifier => New_E, Subtype_Indication => New_Occurrence_Of (Etype (Index), Loc)); Insert_Before (Parent (Def), Decl); Analyze (Decl); Set_Etype (Index, New_E); -- If the index is a range the Entity attribute is not -- available. Example: -- package Pkg is -- type T is private; -- private -- type T is new Natural; -- Table : array (T(1) .. T(10)) of Boolean; -- end Pkg; if Nkind (Index) /= N_Range then Set_Entity (Index, New_E); end if; end; end if; Make_Index (Index, P, Related_Id, Nb_Index); -- Check error of subtype with predicate for index type Bad_Predicated_Subtype_Use ("subtype& has predicate, not allowed as index subtype", Index, Etype (Index)); -- Move to next index Next_Index (Index); Nb_Index := Nb_Index + 1; end loop; -- Process subtype indication if one is present if Present (Component_Typ) then Element_Type := Process_Subtype (Component_Typ, P, Related_Id, 'C'); Set_Etype (Component_Typ, Element_Type); if not Nkind_In (Component_Typ, N_Identifier, N_Expanded_Name) then Check_SPARK_05_Restriction ("subtype mark required", Component_Typ); end if; -- Ada 2005 (AI-230): Access Definition case else pragma Assert (Present (Access_Definition (Component_Def))); -- Indicate that the anonymous access type is created by the -- array type declaration. Element_Type := Access_Definition (Related_Nod => P, N => Access_Definition (Component_Def)); Set_Is_Local_Anonymous_Access (Element_Type); -- Propagate the parent. This field is needed if we have to generate -- the master_id associated with an anonymous access to task type -- component (see Expand_N_Full_Type_Declaration.Build_Master) Set_Parent (Element_Type, Parent (T)); -- Ada 2005 (AI-230): In case of components that are anonymous access -- types the level of accessibility depends on the enclosing type -- declaration Set_Scope (Element_Type, Current_Scope); -- Ada 2005 (AI-230) -- Ada 2005 (AI-254) declare CD : constant Node_Id := Access_To_Subprogram_Definition (Access_Definition (Component_Def)); begin if Present (CD) and then Protected_Present (CD) then Element_Type := Replace_Anonymous_Access_To_Protected_Subprogram (Def); end if; end; end if; -- Constrained array case if No (T) then T := Create_Itype (E_Void, P, Related_Id, 'T'); end if; if Nkind (Def) = N_Constrained_Array_Definition then -- Establish Implicit_Base as unconstrained base type Implicit_Base := Create_Itype (E_Array_Type, P, Related_Id, 'B'); Set_Etype (Implicit_Base, Implicit_Base); Set_Scope (Implicit_Base, Current_Scope); Set_Has_Delayed_Freeze (Implicit_Base); Set_Default_SSO (Implicit_Base); -- The constrained array type is a subtype of the unconstrained one Set_Ekind (T, E_Array_Subtype); Init_Size_Align (T); Set_Etype (T, Implicit_Base); Set_Scope (T, Current_Scope); Set_Is_Constrained (T); Set_First_Index (T, First (Discrete_Subtype_Definitions (Def))); Set_Has_Delayed_Freeze (T); -- Complete setup of implicit base type Set_Component_Size (Implicit_Base, Uint_0); Set_Component_Type (Implicit_Base, Element_Type); Set_Finalize_Storage_Only (Implicit_Base, Finalize_Storage_Only (Element_Type)); Set_First_Index (Implicit_Base, First_Index (T)); Set_Has_Controlled_Component (Implicit_Base, Has_Controlled_Component (Element_Type) or else Is_Controlled_Active (Element_Type)); Set_Packed_Array_Impl_Type (Implicit_Base, Empty); Propagate_Concurrent_Flags (Implicit_Base, Element_Type); -- Unconstrained array case else Set_Ekind (T, E_Array_Type); Init_Size_Align (T); Set_Etype (T, T); Set_Scope (T, Current_Scope); Set_Component_Size (T, Uint_0); Set_Is_Constrained (T, False); Set_First_Index (T, First (Subtype_Marks (Def))); Set_Has_Delayed_Freeze (T, True); Propagate_Concurrent_Flags (T, Element_Type); Set_Has_Controlled_Component (T, Has_Controlled_Component (Element_Type) or else Is_Controlled_Active (Element_Type)); Set_Finalize_Storage_Only (T, Finalize_Storage_Only (Element_Type)); Set_Default_SSO (T); end if; -- Common attributes for both cases Set_Component_Type (Base_Type (T), Element_Type); Set_Packed_Array_Impl_Type (T, Empty); if Aliased_Present (Component_Definition (Def)) then Check_SPARK_05_Restriction ("aliased is not allowed", Component_Definition (Def)); Set_Has_Aliased_Components (Etype (T)); end if; -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the -- array type to ensure that objects of this type are initialized. if Ada_Version >= Ada_2005 and then Can_Never_Be_Null (Element_Type) then Set_Can_Never_Be_Null (T); if Null_Exclusion_Present (Component_Definition (Def)) -- No need to check itypes because in their case this check was -- done at their point of creation and then not Is_Itype (Element_Type) then Error_Msg_N ("`NOT NULL` not allowed (null already excluded)", Subtype_Indication (Component_Definition (Def))); end if; end if; Priv := Private_Component (Element_Type); if Present (Priv) then -- Check for circular definitions if Priv = Any_Type then Set_Component_Type (Etype (T), Any_Type); -- There is a gap in the visibility of operations on the composite -- type only if the component type is defined in a different scope. elsif Scope (Priv) = Current_Scope then null; elsif Is_Limited_Type (Priv) then Set_Is_Limited_Composite (Etype (T)); Set_Is_Limited_Composite (T); else Set_Is_Private_Composite (Etype (T)); Set_Is_Private_Composite (T); end if; end if; -- A syntax error in the declaration itself may lead to an empty index -- list, in which case do a minimal patch. if No (First_Index (T)) then Error_Msg_N ("missing index definition in array type declaration", T); declare Indexes : constant List_Id := New_List (New_Occurrence_Of (Any_Id, Sloc (T))); begin Set_Discrete_Subtype_Definitions (Def, Indexes); Set_First_Index (T, First (Indexes)); return; end; end if; -- Create a concatenation operator for the new type. Internal array -- types created for packed entities do not need such, they are -- compatible with the user-defined type. if Number_Dimensions (T) = 1 and then not Is_Packed_Array_Impl_Type (T) then New_Concatenation_Op (T); end if; -- In the case of an unconstrained array the parser has already verified -- that all the indexes are unconstrained but we still need to make sure -- that the element type is constrained. if not Is_Definite_Subtype (Element_Type) then Error_Msg_N ("unconstrained element type in array declaration", Subtype_Indication (Component_Def)); elsif Is_Abstract_Type (Element_Type) then Error_Msg_N ("the type of a component cannot be abstract", Subtype_Indication (Component_Def)); end if; -- There may be an invariant declared for the component type, but -- the construction of the component invariant checking procedure -- takes place during expansion. end Array_Type_Declaration; ------------------------------------------------------ -- Replace_Anonymous_Access_To_Protected_Subprogram -- ------------------------------------------------------ function Replace_Anonymous_Access_To_Protected_Subprogram (N : Node_Id) return Entity_Id is Loc : constant Source_Ptr := Sloc (N); Curr_Scope : constant Scope_Stack_Entry := Scope_Stack.Table (Scope_Stack.Last); Anon : constant Entity_Id := Make_Temporary (Loc, 'S'); Acc : Node_Id; -- Access definition in declaration Comp : Node_Id; -- Object definition or formal definition with an access definition Decl : Node_Id; -- Declaration of anonymous access to subprogram type Spec : Node_Id; -- Original specification in access to subprogram P : Node_Id; begin Set_Is_Internal (Anon); case Nkind (N) is when N_Constrained_Array_Definition | N_Component_Declaration | N_Unconstrained_Array_Definition => Comp := Component_Definition (N); Acc := Access_Definition (Comp); when N_Discriminant_Specification => Comp := Discriminant_Type (N); Acc := Comp; when N_Parameter_Specification => Comp := Parameter_Type (N); Acc := Comp; when N_Access_Function_Definition => Comp := Result_Definition (N); Acc := Comp; when N_Object_Declaration => Comp := Object_Definition (N); Acc := Comp; when N_Function_Specification => Comp := Result_Definition (N); Acc := Comp; when others => raise Program_Error; end case; Spec := Access_To_Subprogram_Definition (Acc); Decl := Make_Full_Type_Declaration (Loc, Defining_Identifier => Anon, Type_Definition => Copy_Separate_Tree (Spec)); Mark_Rewrite_Insertion (Decl); -- In ASIS mode, analyze the profile on the original node, because -- the separate copy does not provide enough links to recover the -- original tree. Analysis is limited to type annotations, within -- a temporary scope that serves as an anonymous subprogram to collect -- otherwise useless temporaries and itypes. if ASIS_Mode then declare Typ : constant Entity_Id := Make_Temporary (Loc, 'S'); begin if Nkind (Spec) = N_Access_Function_Definition then Set_Ekind (Typ, E_Function); else Set_Ekind (Typ, E_Procedure); end if; Set_Parent (Typ, N); Set_Scope (Typ, Current_Scope); Push_Scope (Typ); -- Nothing to do if procedure is parameterless if Present (Parameter_Specifications (Spec)) then Process_Formals (Parameter_Specifications (Spec), Spec); end if; if Nkind (Spec) = N_Access_Function_Definition then declare Def : constant Node_Id := Result_Definition (Spec); begin -- The result might itself be an anonymous access type, so -- have to recurse. if Nkind (Def) = N_Access_Definition then if Present (Access_To_Subprogram_Definition (Def)) then Set_Etype (Def, Replace_Anonymous_Access_To_Protected_Subprogram (Spec)); else Find_Type (Subtype_Mark (Def)); end if; else Find_Type (Def); end if; end; end if; End_Scope; end; end if; -- Insert the new declaration in the nearest enclosing scope. If the -- parent is a body and N is its return type, the declaration belongs -- in the enclosing scope. Likewise if N is the type of a parameter. P := Parent (N); if Nkind (N) = N_Function_Specification and then Nkind (P) = N_Subprogram_Body then P := Parent (P); elsif Nkind (N) = N_Parameter_Specification and then Nkind (P) in N_Subprogram_Specification and then Nkind (Parent (P)) = N_Subprogram_Body then P := Parent (Parent (P)); end if; while Present (P) and then not Has_Declarations (P) loop P := Parent (P); end loop; pragma Assert (Present (P)); if Nkind (P) = N_Package_Specification then Prepend (Decl, Visible_Declarations (P)); else Prepend (Decl, Declarations (P)); end if; -- Replace the anonymous type with an occurrence of the new declaration. -- In all cases the rewritten node does not have the null-exclusion -- attribute because (if present) it was already inherited by the -- anonymous entity (Anon). Thus, in case of components we do not -- inherit this attribute. if Nkind (N) = N_Parameter_Specification then Rewrite (Comp, New_Occurrence_Of (Anon, Loc)); Set_Etype (Defining_Identifier (N), Anon); Set_Null_Exclusion_Present (N, False); elsif Nkind (N) = N_Object_Declaration then Rewrite (Comp, New_Occurrence_Of (Anon, Loc)); Set_Etype (Defining_Identifier (N), Anon); elsif Nkind (N) = N_Access_Function_Definition then Rewrite (Comp, New_Occurrence_Of (Anon, Loc)); elsif Nkind (N) = N_Function_Specification then Rewrite (Comp, New_Occurrence_Of (Anon, Loc)); Set_Etype (Defining_Unit_Name (N), Anon); else Rewrite (Comp, Make_Component_Definition (Loc, Subtype_Indication => New_Occurrence_Of (Anon, Loc))); end if; Mark_Rewrite_Insertion (Comp); if Nkind_In (N, N_Object_Declaration, N_Access_Function_Definition) or else (Nkind (Parent (N)) = N_Full_Type_Declaration and then not Is_Type (Current_Scope)) then -- Declaration can be analyzed in the current scope. Analyze (Decl); else -- Temporarily remove the current scope (record or subprogram) from -- the stack to add the new declarations to the enclosing scope. -- The anonymous entity is an Itype with the proper attributes. Scope_Stack.Decrement_Last; Analyze (Decl); Set_Is_Itype (Anon); Set_Associated_Node_For_Itype (Anon, N); Scope_Stack.Append (Curr_Scope); end if; Set_Ekind (Anon, E_Anonymous_Access_Protected_Subprogram_Type); Set_Can_Use_Internal_Rep (Anon, not Always_Compatible_Rep_On_Target); return Anon; end Replace_Anonymous_Access_To_Protected_Subprogram; ------------------------------- -- Build_Derived_Access_Type -- ------------------------------- procedure Build_Derived_Access_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id) is S : constant Node_Id := Subtype_Indication (Type_Definition (N)); Desig_Type : Entity_Id; Discr : Entity_Id; Discr_Con_Elist : Elist_Id; Discr_Con_El : Elmt_Id; Subt : Entity_Id; begin -- Set the designated type so it is available in case this is an access -- to a self-referential type, e.g. a standard list type with a next -- pointer. Will be reset after subtype is built. Set_Directly_Designated_Type (Derived_Type, Designated_Type (Parent_Type)); Subt := Process_Subtype (S, N); if Nkind (S) /= N_Subtype_Indication and then Subt /= Base_Type (Subt) then Set_Ekind (Derived_Type, E_Access_Subtype); end if; if Ekind (Derived_Type) = E_Access_Subtype then declare Pbase : constant Entity_Id := Base_Type (Parent_Type); Ibase : constant Entity_Id := Create_Itype (Ekind (Pbase), N, Derived_Type, 'B'); Svg_Chars : constant Name_Id := Chars (Ibase); Svg_Next_E : constant Entity_Id := Next_Entity (Ibase); begin Copy_Node (Pbase, Ibase); -- Restore Itype status after Copy_Node Set_Is_Itype (Ibase); Set_Associated_Node_For_Itype (Ibase, N); Set_Chars (Ibase, Svg_Chars); Set_Next_Entity (Ibase, Svg_Next_E); Set_Sloc (Ibase, Sloc (Derived_Type)); Set_Scope (Ibase, Scope (Derived_Type)); Set_Freeze_Node (Ibase, Empty); Set_Is_Frozen (Ibase, False); Set_Comes_From_Source (Ibase, False); Set_Is_First_Subtype (Ibase, False); Set_Etype (Ibase, Pbase); Set_Etype (Derived_Type, Ibase); end; end if; Set_Directly_Designated_Type (Derived_Type, Designated_Type (Subt)); Set_Is_Constrained (Derived_Type, Is_Constrained (Subt)); Set_Is_Access_Constant (Derived_Type, Is_Access_Constant (Parent_Type)); Set_Size_Info (Derived_Type, Parent_Type); Set_RM_Size (Derived_Type, RM_Size (Parent_Type)); Set_Depends_On_Private (Derived_Type, Has_Private_Component (Derived_Type)); Conditional_Delay (Derived_Type, Subt); -- Ada 2005 (AI-231): Set the null-exclusion attribute, and verify -- that it is not redundant. if Null_Exclusion_Present (Type_Definition (N)) then Set_Can_Never_Be_Null (Derived_Type); elsif Can_Never_Be_Null (Parent_Type) then Set_Can_Never_Be_Null (Derived_Type); end if; -- Note: we do not copy the Storage_Size_Variable, since we always go to -- the root type for this information. -- Apply range checks to discriminants for derived record case -- ??? THIS CODE SHOULD NOT BE HERE REALLY. Desig_Type := Designated_Type (Derived_Type); if Is_Composite_Type (Desig_Type) and then (not Is_Array_Type (Desig_Type)) and then Has_Discriminants (Desig_Type) and then Base_Type (Desig_Type) /= Desig_Type then Discr_Con_Elist := Discriminant_Constraint (Desig_Type); Discr_Con_El := First_Elmt (Discr_Con_Elist); Discr := First_Discriminant (Base_Type (Desig_Type)); while Present (Discr_Con_El) loop Apply_Range_Check (Node (Discr_Con_El), Etype (Discr)); Next_Elmt (Discr_Con_El); Next_Discriminant (Discr); end loop; end if; end Build_Derived_Access_Type; ------------------------------ -- Build_Derived_Array_Type -- ------------------------------ procedure Build_Derived_Array_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id) is Loc : constant Source_Ptr := Sloc (N); Tdef : constant Node_Id := Type_Definition (N); Indic : constant Node_Id := Subtype_Indication (Tdef); Parent_Base : constant Entity_Id := Base_Type (Parent_Type); Implicit_Base : Entity_Id; New_Indic : Node_Id; procedure Make_Implicit_Base; -- If the parent subtype is constrained, the derived type is a subtype -- of an implicit base type derived from the parent base. ------------------------ -- Make_Implicit_Base -- ------------------------ procedure Make_Implicit_Base is begin Implicit_Base := Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B'); Set_Ekind (Implicit_Base, Ekind (Parent_Base)); Set_Etype (Implicit_Base, Parent_Base); Copy_Array_Subtype_Attributes (Implicit_Base, Parent_Base); Copy_Array_Base_Type_Attributes (Implicit_Base, Parent_Base); Set_Has_Delayed_Freeze (Implicit_Base, True); end Make_Implicit_Base; -- Start of processing for Build_Derived_Array_Type begin if not Is_Constrained (Parent_Type) then if Nkind (Indic) /= N_Subtype_Indication then Set_Ekind (Derived_Type, E_Array_Type); Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type); Copy_Array_Base_Type_Attributes (Derived_Type, Parent_Type); Set_Has_Delayed_Freeze (Derived_Type, True); else Make_Implicit_Base; Set_Etype (Derived_Type, Implicit_Base); New_Indic := Make_Subtype_Declaration (Loc, Defining_Identifier => Derived_Type, Subtype_Indication => Make_Subtype_Indication (Loc, Subtype_Mark => New_Occurrence_Of (Implicit_Base, Loc), Constraint => Constraint (Indic))); Rewrite (N, New_Indic); Analyze (N); end if; else if Nkind (Indic) /= N_Subtype_Indication then Make_Implicit_Base; Set_Ekind (Derived_Type, Ekind (Parent_Type)); Set_Etype (Derived_Type, Implicit_Base); Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type); else Error_Msg_N ("illegal constraint on constrained type", Indic); end if; end if; -- If parent type is not a derived type itself, and is declared in -- closed scope (e.g. a subprogram), then we must explicitly introduce -- the new type's concatenation operator since Derive_Subprograms -- will not inherit the parent's operator. If the parent type is -- unconstrained, the operator is of the unconstrained base type. if Number_Dimensions (Parent_Type) = 1 and then not Is_Limited_Type (Parent_Type) and then not Is_Derived_Type (Parent_Type) and then not Is_Package_Or_Generic_Package (Scope (Base_Type (Parent_Type))) then if not Is_Constrained (Parent_Type) and then Is_Constrained (Derived_Type) then New_Concatenation_Op (Implicit_Base); else New_Concatenation_Op (Derived_Type); end if; end if; end Build_Derived_Array_Type; ----------------------------------- -- Build_Derived_Concurrent_Type -- ----------------------------------- procedure Build_Derived_Concurrent_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id) is Loc : constant Source_Ptr := Sloc (N); Corr_Record : constant Entity_Id := Make_Temporary (Loc, 'C'); Corr_Decl : Node_Id; Corr_Decl_Needed : Boolean; -- If the derived type has fewer discriminants than its parent, the -- corresponding record is also a derived type, in order to account for -- the bound discriminants. We create a full type declaration for it in -- this case. Constraint_Present : constant Boolean := Nkind (Subtype_Indication (Type_Definition (N))) = N_Subtype_Indication; D_Constraint : Node_Id; New_Constraint : Elist_Id; Old_Disc : Entity_Id; New_Disc : Entity_Id; New_N : Node_Id; begin Set_Stored_Constraint (Derived_Type, No_Elist); Corr_Decl_Needed := False; Old_Disc := Empty; if Present (Discriminant_Specifications (N)) and then Constraint_Present then Old_Disc := First_Discriminant (Parent_Type); New_Disc := First (Discriminant_Specifications (N)); while Present (New_Disc) and then Present (Old_Disc) loop Next_Discriminant (Old_Disc); Next (New_Disc); end loop; end if; if Present (Old_Disc) and then Expander_Active then -- The new type has fewer discriminants, so we need to create a new -- corresponding record, which is derived from the corresponding -- record of the parent, and has a stored constraint that captures -- the values of the discriminant constraints. The corresponding -- record is needed only if expander is active and code generation is -- enabled. -- The type declaration for the derived corresponding record has the -- same discriminant part and constraints as the current declaration. -- Copy the unanalyzed tree to build declaration. Corr_Decl_Needed := True; New_N := Copy_Separate_Tree (N); Corr_Decl := Make_Full_Type_Declaration (Loc, Defining_Identifier => Corr_Record, Discriminant_Specifications => Discriminant_Specifications (New_N), Type_Definition => Make_Derived_Type_Definition (Loc, Subtype_Indication => Make_Subtype_Indication (Loc, Subtype_Mark => New_Occurrence_Of (Corresponding_Record_Type (Parent_Type), Loc), Constraint => Constraint (Subtype_Indication (Type_Definition (New_N)))))); end if; -- Copy Storage_Size and Relative_Deadline variables if task case if Is_Task_Type (Parent_Type) then Set_Storage_Size_Variable (Derived_Type, Storage_Size_Variable (Parent_Type)); Set_Relative_Deadline_Variable (Derived_Type, Relative_Deadline_Variable (Parent_Type)); end if; if Present (Discriminant_Specifications (N)) then Push_Scope (Derived_Type); Check_Or_Process_Discriminants (N, Derived_Type); if Constraint_Present then New_Constraint := Expand_To_Stored_Constraint (Parent_Type, Build_Discriminant_Constraints (Parent_Type, Subtype_Indication (Type_Definition (N)), True)); end if; End_Scope; elsif Constraint_Present then -- Build constrained subtype, copying the constraint, and derive -- from it to create a derived constrained type. declare Loc : constant Source_Ptr := Sloc (N); Anon : constant Entity_Id := Make_Defining_Identifier (Loc, Chars => New_External_Name (Chars (Derived_Type), 'T')); Decl : Node_Id; begin Decl := Make_Subtype_Declaration (Loc, Defining_Identifier => Anon, Subtype_Indication => New_Copy_Tree (Subtype_Indication (Type_Definition (N)))); Insert_Before (N, Decl); Analyze (Decl); Rewrite (Subtype_Indication (Type_Definition (N)), New_Occurrence_Of (Anon, Loc)); Set_Analyzed (Derived_Type, False); Analyze (N); return; end; end if; -- By default, operations and private data are inherited from parent. -- However, in the presence of bound discriminants, a new corresponding -- record will be created, see below. Set_Has_Discriminants (Derived_Type, Has_Discriminants (Parent_Type)); Set_Corresponding_Record_Type (Derived_Type, Corresponding_Record_Type (Parent_Type)); -- Is_Constrained is set according the parent subtype, but is set to -- False if the derived type is declared with new discriminants. Set_Is_Constrained (Derived_Type, (Is_Constrained (Parent_Type) or else Constraint_Present) and then not Present (Discriminant_Specifications (N))); if Constraint_Present then if not Has_Discriminants (Parent_Type) then Error_Msg_N ("untagged parent must have discriminants", N); elsif Present (Discriminant_Specifications (N)) then -- Verify that new discriminants are used to constrain old ones D_Constraint := First (Constraints (Constraint (Subtype_Indication (Type_Definition (N))))); Old_Disc := First_Discriminant (Parent_Type); while Present (D_Constraint) loop if Nkind (D_Constraint) /= N_Discriminant_Association then -- Positional constraint. If it is a reference to a new -- discriminant, it constrains the corresponding old one. if Nkind (D_Constraint) = N_Identifier then New_Disc := First_Discriminant (Derived_Type); while Present (New_Disc) loop exit when Chars (New_Disc) = Chars (D_Constraint); Next_Discriminant (New_Disc); end loop; if Present (New_Disc) then Set_Corresponding_Discriminant (New_Disc, Old_Disc); end if; end if; Next_Discriminant (Old_Disc); -- if this is a named constraint, search by name for the old -- discriminants constrained by the new one. elsif Nkind (Expression (D_Constraint)) = N_Identifier then -- Find new discriminant with that name New_Disc := First_Discriminant (Derived_Type); while Present (New_Disc) loop exit when Chars (New_Disc) = Chars (Expression (D_Constraint)); Next_Discriminant (New_Disc); end loop; if Present (New_Disc) then -- Verify that new discriminant renames some discriminant -- of the parent type, and associate the new discriminant -- with one or more old ones that it renames. declare Selector : Node_Id; begin Selector := First (Selector_Names (D_Constraint)); while Present (Selector) loop Old_Disc := First_Discriminant (Parent_Type); while Present (Old_Disc) loop exit when Chars (Old_Disc) = Chars (Selector); Next_Discriminant (Old_Disc); end loop; if Present (Old_Disc) then Set_Corresponding_Discriminant (New_Disc, Old_Disc); end if; Next (Selector); end loop; end; end if; end if; Next (D_Constraint); end loop; New_Disc := First_Discriminant (Derived_Type); while Present (New_Disc) loop if No (Corresponding_Discriminant (New_Disc)) then Error_Msg_NE ("new discriminant& must constrain old one", N, New_Disc); elsif not Subtypes_Statically_Compatible (Etype (New_Disc), Etype (Corresponding_Discriminant (New_Disc))) then Error_Msg_NE ("& not statically compatible with parent discriminant", N, New_Disc); end if; Next_Discriminant (New_Disc); end loop; end if; elsif Present (Discriminant_Specifications (N)) then Error_Msg_N ("missing discriminant constraint in untagged derivation", N); end if; -- The entity chain of the derived type includes the new discriminants -- but shares operations with the parent. if Present (Discriminant_Specifications (N)) then Old_Disc := First_Discriminant (Parent_Type); while Present (Old_Disc) loop if No (Next_Entity (Old_Disc)) or else Ekind (Next_Entity (Old_Disc)) /= E_Discriminant then Set_Next_Entity (Last_Entity (Derived_Type), Next_Entity (Old_Disc)); exit; end if; Next_Discriminant (Old_Disc); end loop; else Set_First_Entity (Derived_Type, First_Entity (Parent_Type)); if Has_Discriminants (Parent_Type) then Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type)); Set_Discriminant_Constraint ( Derived_Type, Discriminant_Constraint (Parent_Type)); end if; end if; Set_Last_Entity (Derived_Type, Last_Entity (Parent_Type)); Set_Has_Completion (Derived_Type); if Corr_Decl_Needed then Set_Stored_Constraint (Derived_Type, New_Constraint); Insert_After (N, Corr_Decl); Analyze (Corr_Decl); Set_Corresponding_Record_Type (Derived_Type, Corr_Record); end if; end Build_Derived_Concurrent_Type; ------------------------------------ -- Build_Derived_Enumeration_Type -- ------------------------------------ procedure Build_Derived_Enumeration_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id) is Loc : constant Source_Ptr := Sloc (N); Def : constant Node_Id := Type_Definition (N); Indic : constant Node_Id := Subtype_Indication (Def); Implicit_Base : Entity_Id; Literal : Entity_Id; New_Lit : Entity_Id; Literals_List : List_Id; Type_Decl : Node_Id; Hi, Lo : Node_Id; Rang_Expr : Node_Id; begin -- Since types Standard.Character and Standard.[Wide_]Wide_Character do -- not have explicit literals lists we need to process types derived -- from them specially. This is handled by Derived_Standard_Character. -- If the parent type is a generic type, there are no literals either, -- and we construct the same skeletal representation as for the generic -- parent type. if Is_Standard_Character_Type (Parent_Type) then Derived_Standard_Character (N, Parent_Type, Derived_Type); elsif Is_Generic_Type (Root_Type (Parent_Type)) then declare Lo : Node_Id; Hi : Node_Id; begin if Nkind (Indic) /= N_Subtype_Indication then Lo := Make_Attribute_Reference (Loc, Attribute_Name => Name_First, Prefix => New_Occurrence_Of (Derived_Type, Loc)); Set_Etype (Lo, Derived_Type); Hi := Make_Attribute_Reference (Loc, Attribute_Name => Name_Last, Prefix => New_Occurrence_Of (Derived_Type, Loc)); Set_Etype (Hi, Derived_Type); Set_Scalar_Range (Derived_Type, Make_Range (Loc, Low_Bound => Lo, High_Bound => Hi)); else -- Analyze subtype indication and verify compatibility -- with parent type. if Base_Type (Process_Subtype (Indic, N)) /= Base_Type (Parent_Type) then Error_Msg_N ("illegal constraint for formal discrete type", N); end if; end if; end; else -- If a constraint is present, analyze the bounds to catch -- premature usage of the derived literals. if Nkind (Indic) = N_Subtype_Indication and then Nkind (Range_Expression (Constraint (Indic))) = N_Range then Analyze (Low_Bound (Range_Expression (Constraint (Indic)))); Analyze (High_Bound (Range_Expression (Constraint (Indic)))); end if; -- Introduce an implicit base type for the derived type even if there -- is no constraint attached to it, since this seems closer to the -- Ada semantics. Build a full type declaration tree for the derived -- type using the implicit base type as the defining identifier. The -- build a subtype declaration tree which applies the constraint (if -- any) have it replace the derived type declaration. Literal := First_Literal (Parent_Type); Literals_List := New_List; while Present (Literal) and then Ekind (Literal) = E_Enumeration_Literal loop -- Literals of the derived type have the same representation as -- those of the parent type, but this representation can be -- overridden by an explicit representation clause. Indicate -- that there is no explicit representation given yet. These -- derived literals are implicit operations of the new type, -- and can be overridden by explicit ones. if Nkind (Literal) = N_Defining_Character_Literal then New_Lit := Make_Defining_Character_Literal (Loc, Chars (Literal)); else New_Lit := Make_Defining_Identifier (Loc, Chars (Literal)); end if; Set_Ekind (New_Lit, E_Enumeration_Literal); Set_Enumeration_Pos (New_Lit, Enumeration_Pos (Literal)); Set_Enumeration_Rep (New_Lit, Enumeration_Rep (Literal)); Set_Enumeration_Rep_Expr (New_Lit, Empty); Set_Alias (New_Lit, Literal); Set_Is_Known_Valid (New_Lit, True); Append (New_Lit, Literals_List); Next_Literal (Literal); end loop; Implicit_Base := Make_Defining_Identifier (Sloc (Derived_Type), Chars => New_External_Name (Chars (Derived_Type), 'B')); -- Indicate the proper nature of the derived type. This must be done -- before analysis of the literals, to recognize cases when a literal -- may be hidden by a previous explicit function definition (cf. -- c83031a). Set_Ekind (Derived_Type, E_Enumeration_Subtype); Set_Etype (Derived_Type, Implicit_Base); Type_Decl := Make_Full_Type_Declaration (Loc, Defining_Identifier => Implicit_Base, Discriminant_Specifications => No_List, Type_Definition => Make_Enumeration_Type_Definition (Loc, Literals_List)); Mark_Rewrite_Insertion (Type_Decl); Insert_Before (N, Type_Decl); Analyze (Type_Decl); -- The anonymous base now has a full declaration, but this base -- is not a first subtype. Set_Is_First_Subtype (Implicit_Base, False); -- After the implicit base is analyzed its Etype needs to be changed -- to reflect the fact that it is derived from the parent type which -- was ignored during analysis. We also set the size at this point. Set_Etype (Implicit_Base, Parent_Type); Set_Size_Info (Implicit_Base, Parent_Type); Set_RM_Size (Implicit_Base, RM_Size (Parent_Type)); Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Type)); -- Copy other flags from parent type Set_Has_Non_Standard_Rep (Implicit_Base, Has_Non_Standard_Rep (Parent_Type)); Set_Has_Pragma_Ordered (Implicit_Base, Has_Pragma_Ordered (Parent_Type)); Set_Has_Delayed_Freeze (Implicit_Base); -- Process the subtype indication including a validation check on the -- constraint, if any. If a constraint is given, its bounds must be -- implicitly converted to the new type. if Nkind (Indic) = N_Subtype_Indication then declare R : constant Node_Id := Range_Expression (Constraint (Indic)); begin if Nkind (R) = N_Range then Hi := Build_Scalar_Bound (High_Bound (R), Parent_Type, Implicit_Base); Lo := Build_Scalar_Bound (Low_Bound (R), Parent_Type, Implicit_Base); else -- Constraint is a Range attribute. Replace with explicit -- mention of the bounds of the prefix, which must be a -- subtype. Analyze (Prefix (R)); Hi := Convert_To (Implicit_Base, Make_Attribute_Reference (Loc, Attribute_Name => Name_Last, Prefix => New_Occurrence_Of (Entity (Prefix (R)), Loc))); Lo := Convert_To (Implicit_Base, Make_Attribute_Reference (Loc, Attribute_Name => Name_First, Prefix => New_Occurrence_Of (Entity (Prefix (R)), Loc))); end if; end; else Hi := Build_Scalar_Bound (Type_High_Bound (Parent_Type), Parent_Type, Implicit_Base); Lo := Build_Scalar_Bound (Type_Low_Bound (Parent_Type), Parent_Type, Implicit_Base); end if; Rang_Expr := Make_Range (Loc, Low_Bound => Lo, High_Bound => Hi); -- If we constructed a default range for the case where no range -- was given, then the expressions in the range must not freeze -- since they do not correspond to expressions in the source. -- However, if the type inherits predicates the expressions will -- be elaborated earlier and must freeze. if Nkind (Indic) /= N_Subtype_Indication and then not Has_Predicates (Derived_Type) then Set_Must_Not_Freeze (Lo); Set_Must_Not_Freeze (Hi); Set_Must_Not_Freeze (Rang_Expr); end if; Rewrite (N, Make_Subtype_Declaration (Loc, Defining_Identifier => Derived_Type, Subtype_Indication => Make_Subtype_Indication (Loc, Subtype_Mark => New_Occurrence_Of (Implicit_Base, Loc), Constraint => Make_Range_Constraint (Loc, Range_Expression => Rang_Expr)))); Analyze (N); -- Propagate the aspects from the original type declaration to the -- declaration of the implicit base. Move_Aspects (From => Original_Node (N), To => Type_Decl); -- Apply a range check. Since this range expression doesn't have an -- Etype, we have to specifically pass the Source_Typ parameter. Is -- this right??? if Nkind (Indic) = N_Subtype_Indication then Apply_Range_Check (Range_Expression (Constraint (Indic)), Parent_Type, Source_Typ => Entity (Subtype_Mark (Indic))); end if; end if; end Build_Derived_Enumeration_Type; -------------------------------- -- Build_Derived_Numeric_Type -- -------------------------------- procedure Build_Derived_Numeric_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id) is Loc : constant Source_Ptr := Sloc (N); Tdef : constant Node_Id := Type_Definition (N); Indic : constant Node_Id := Subtype_Indication (Tdef); Parent_Base : constant Entity_Id := Base_Type (Parent_Type); No_Constraint : constant Boolean := Nkind (Indic) /= N_Subtype_Indication; Implicit_Base : Entity_Id; Lo : Node_Id; Hi : Node_Id; begin -- Process the subtype indication including a validation check on -- the constraint if any. Discard_Node (Process_Subtype (Indic, N)); -- Introduce an implicit base type for the derived type even if there -- is no constraint attached to it, since this seems closer to the Ada -- semantics. Implicit_Base := Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B'); Set_Etype (Implicit_Base, Parent_Base); Set_Ekind (Implicit_Base, Ekind (Parent_Base)); Set_Size_Info (Implicit_Base, Parent_Base); Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Base)); Set_Parent (Implicit_Base, Parent (Derived_Type)); Set_Is_Known_Valid (Implicit_Base, Is_Known_Valid (Parent_Base)); -- Set RM Size for discrete type or decimal fixed-point type -- Ordinary fixed-point is excluded, why??? if Is_Discrete_Type (Parent_Base) or else Is_Decimal_Fixed_Point_Type (Parent_Base) then Set_RM_Size (Implicit_Base, RM_Size (Parent_Base)); end if; Set_Has_Delayed_Freeze (Implicit_Base); Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base)); Hi := New_Copy_Tree (Type_High_Bound (Parent_Base)); Set_Scalar_Range (Implicit_Base, Make_Range (Loc, Low_Bound => Lo, High_Bound => Hi)); if Has_Infinities (Parent_Base) then Set_Includes_Infinities (Scalar_Range (Implicit_Base)); end if; -- The Derived_Type, which is the entity of the declaration, is a -- subtype of the implicit base. Its Ekind is a subtype, even in the -- absence of an explicit constraint. Set_Etype (Derived_Type, Implicit_Base); -- If we did not have a constraint, then the Ekind is set from the -- parent type (otherwise Process_Subtype has set the bounds) if No_Constraint then Set_Ekind (Derived_Type, Subtype_Kind (Ekind (Parent_Type))); end if; -- If we did not have a range constraint, then set the range from the -- parent type. Otherwise, the Process_Subtype call has set the bounds. if No_Constraint or else not Has_Range_Constraint (Indic) then Set_Scalar_Range (Derived_Type, Make_Range (Loc, Low_Bound => New_Copy_Tree (Type_Low_Bound (Parent_Type)), High_Bound => New_Copy_Tree (Type_High_Bound (Parent_Type)))); Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type)); if Has_Infinities (Parent_Type) then Set_Includes_Infinities (Scalar_Range (Derived_Type)); end if; Set_Is_Known_Valid (Derived_Type, Is_Known_Valid (Parent_Type)); end if; Set_Is_Descendant_Of_Address (Derived_Type, Is_Descendant_Of_Address (Parent_Type)); Set_Is_Descendant_Of_Address (Implicit_Base, Is_Descendant_Of_Address (Parent_Type)); -- Set remaining type-specific fields, depending on numeric type if Is_Modular_Integer_Type (Parent_Type) then Set_Modulus (Implicit_Base, Modulus (Parent_Base)); Set_Non_Binary_Modulus (Implicit_Base, Non_Binary_Modulus (Parent_Base)); Set_Is_Known_Valid (Implicit_Base, Is_Known_Valid (Parent_Base)); elsif Is_Floating_Point_Type (Parent_Type) then -- Digits of base type is always copied from the digits value of -- the parent base type, but the digits of the derived type will -- already have been set if there was a constraint present. Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base)); Set_Float_Rep (Implicit_Base, Float_Rep (Parent_Base)); if No_Constraint then Set_Digits_Value (Derived_Type, Digits_Value (Parent_Type)); end if; elsif Is_Fixed_Point_Type (Parent_Type) then -- Small of base type and derived type are always copied from the -- parent base type, since smalls never change. The delta of the -- base type is also copied from the parent base type. However the -- delta of the derived type will have been set already if a -- constraint was present. Set_Small_Value (Derived_Type, Small_Value (Parent_Base)); Set_Small_Value (Implicit_Base, Small_Value (Parent_Base)); Set_Delta_Value (Implicit_Base, Delta_Value (Parent_Base)); if No_Constraint then Set_Delta_Value (Derived_Type, Delta_Value (Parent_Type)); end if; -- The scale and machine radix in the decimal case are always -- copied from the parent base type. if Is_Decimal_Fixed_Point_Type (Parent_Type) then Set_Scale_Value (Derived_Type, Scale_Value (Parent_Base)); Set_Scale_Value (Implicit_Base, Scale_Value (Parent_Base)); Set_Machine_Radix_10 (Derived_Type, Machine_Radix_10 (Parent_Base)); Set_Machine_Radix_10 (Implicit_Base, Machine_Radix_10 (Parent_Base)); Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base)); if No_Constraint then Set_Digits_Value (Derived_Type, Digits_Value (Parent_Base)); else -- the analysis of the subtype_indication sets the -- digits value of the derived type. null; end if; end if; end if; if Is_Integer_Type (Parent_Type) then Set_Has_Shift_Operator (Implicit_Base, Has_Shift_Operator (Parent_Type)); end if; -- The type of the bounds is that of the parent type, and they -- must be converted to the derived type. Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc); -- The implicit_base should be frozen when the derived type is frozen, -- but note that it is used in the conversions of the bounds. For fixed -- types we delay the determination of the bounds until the proper -- freezing point. For other numeric types this is rejected by GCC, for -- reasons that are currently unclear (???), so we choose to freeze the -- implicit base now. In the case of integers and floating point types -- this is harmless because subsequent representation clauses cannot -- affect anything, but it is still baffling that we cannot use the -- same mechanism for all derived numeric types. -- There is a further complication: actually some representation -- clauses can affect the implicit base type. For example, attribute -- definition clauses for stream-oriented attributes need to set the -- corresponding TSS entries on the base type, and this normally -- cannot be done after the base type is frozen, so the circuitry in -- Sem_Ch13.New_Stream_Subprogram must account for this possibility -- and not use Set_TSS in this case. -- There are also consequences for the case of delayed representation -- aspects for some cases. For example, a Size aspect is delayed and -- should not be evaluated to the freeze point. This early freezing -- means that the size attribute evaluation happens too early??? if Is_Fixed_Point_Type (Parent_Type) then Conditional_Delay (Implicit_Base, Parent_Type); else Freeze_Before (N, Implicit_Base); end if; end Build_Derived_Numeric_Type; -------------------------------- -- Build_Derived_Private_Type -- -------------------------------- procedure Build_Derived_Private_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id; Is_Completion : Boolean; Derive_Subps : Boolean := True) is Loc : constant Source_Ptr := Sloc (N); Par_Base : constant Entity_Id := Base_Type (Parent_Type); Par_Scope : constant Entity_Id := Scope (Par_Base); Full_N : constant Node_Id := New_Copy_Tree (N); Full_Der : Entity_Id := New_Copy (Derived_Type); Full_P : Entity_Id; procedure Build_Full_Derivation; -- Build full derivation, i.e. derive from the full view procedure Copy_And_Build; -- Copy derived type declaration, replace parent with its full view, -- and build derivation --------------------------- -- Build_Full_Derivation -- --------------------------- procedure Build_Full_Derivation is begin -- If parent scope is not open, install the declarations if not In_Open_Scopes (Par_Scope) then Install_Private_Declarations (Par_Scope); Install_Visible_Declarations (Par_Scope); Copy_And_Build; Uninstall_Declarations (Par_Scope); -- If parent scope is open and in another unit, and parent has a -- completion, then the derivation is taking place in the visible -- part of a child unit. In that case retrieve the full view of -- the parent momentarily. elsif not In_Same_Source_Unit (N, Parent_Type) then Full_P := Full_View (Parent_Type); Exchange_Declarations (Parent_Type); Copy_And_Build; Exchange_Declarations (Full_P); -- Otherwise it is a local derivation else Copy_And_Build; end if; end Build_Full_Derivation; -------------------- -- Copy_And_Build -- -------------------- procedure Copy_And_Build is Full_Parent : Entity_Id := Parent_Type; begin -- If the parent is itself derived from another private type, -- installing the private declarations has not affected its -- privacy status, so use its own full view explicitly. if Is_Private_Type (Full_Parent) and then Present (Full_View (Full_Parent)) then Full_Parent := Full_View (Full_Parent); end if; -- And its underlying full view if necessary if Is_Private_Type (Full_Parent) and then Present (Underlying_Full_View (Full_Parent)) then Full_Parent := Underlying_Full_View (Full_Parent); end if; -- For record, access and most enumeration types, derivation from -- the full view requires a fully-fledged declaration. In the other -- cases, just use an itype. if Ekind (Full_Parent) in Record_Kind or else Ekind (Full_Parent) in Access_Kind or else (Ekind (Full_Parent) in Enumeration_Kind and then not Is_Standard_Character_Type (Full_Parent) and then not Is_Generic_Type (Root_Type (Full_Parent))) then -- Copy and adjust declaration to provide a completion for what -- is originally a private declaration. Indicate that full view -- is internally generated. Set_Comes_From_Source (Full_N, False); Set_Comes_From_Source (Full_Der, False); Set_Parent (Full_Der, Full_N); Set_Defining_Identifier (Full_N, Full_Der); -- If there are no constraints, adjust the subtype mark if Nkind (Subtype_Indication (Type_Definition (Full_N))) /= N_Subtype_Indication then Set_Subtype_Indication (Type_Definition (Full_N), New_Occurrence_Of (Full_Parent, Sloc (Full_N))); end if; Insert_After (N, Full_N); -- Build full view of derived type from full view of parent which -- is now installed. Subprograms have been derived on the partial -- view, the completion does not derive them anew. if Ekind (Full_Parent) in Record_Kind then -- If parent type is tagged, the completion inherits the proper -- primitive operations. if Is_Tagged_Type (Parent_Type) then Build_Derived_Record_Type (Full_N, Full_Parent, Full_Der, Derive_Subps); else Build_Derived_Record_Type (Full_N, Full_Parent, Full_Der, Derive_Subps => False); end if; else Build_Derived_Type (Full_N, Full_Parent, Full_Der, Is_Completion => False, Derive_Subps => False); end if; -- The full declaration has been introduced into the tree and -- processed in the step above. It should not be analyzed again -- (when encountered later in the current list of declarations) -- to prevent spurious name conflicts. The full entity remains -- invisible. Set_Analyzed (Full_N); else Full_Der := Make_Defining_Identifier (Sloc (Derived_Type), Chars => Chars (Derived_Type)); Set_Is_Itype (Full_Der); Set_Associated_Node_For_Itype (Full_Der, N); Set_Parent (Full_Der, N); Build_Derived_Type (N, Full_Parent, Full_Der, Is_Completion => False, Derive_Subps => False); end if; Set_Has_Private_Declaration (Full_Der); Set_Has_Private_Declaration (Derived_Type); Set_Scope (Full_Der, Scope (Derived_Type)); Set_Is_First_Subtype (Full_Der, Is_First_Subtype (Derived_Type)); Set_Has_Size_Clause (Full_Der, False); Set_Has_Alignment_Clause (Full_Der, False); Set_Has_Delayed_Freeze (Full_Der); Set_Is_Frozen (Full_Der, False); Set_Freeze_Node (Full_Der, Empty); Set_Depends_On_Private (Full_Der, Has_Private_Component (Full_Der)); Set_Is_Public (Full_Der, Is_Public (Derived_Type)); -- The convention on the base type may be set in the private part -- and not propagated to the subtype until later, so we obtain the -- convention from the base type of the parent. Set_Convention (Full_Der, Convention (Base_Type (Full_Parent))); end Copy_And_Build; -- Start of processing for Build_Derived_Private_Type begin if Is_Tagged_Type (Parent_Type) then Full_P := Full_View (Parent_Type); -- A type extension of a type with unknown discriminants is an -- indefinite type that the back-end cannot handle directly. -- We treat it as a private type, and build a completion that is -- derived from the full view of the parent, and hopefully has -- known discriminants. -- If the full view of the parent type has an underlying record view, -- use it to generate the underlying record view of this derived type -- (required for chains of derivations with unknown discriminants). -- Minor optimization: we avoid the generation of useless underlying -- record view entities if the private type declaration has unknown -- discriminants but its corresponding full view has no -- discriminants. if Has_Unknown_Discriminants (Parent_Type) and then Present (Full_P) and then (Has_Discriminants (Full_P) or else Present (Underlying_Record_View (Full_P))) and then not In_Open_Scopes (Par_Scope) and then Expander_Active then declare Full_Der : constant Entity_Id := Make_Temporary (Loc, 'T'); New_Ext : constant Node_Id := Copy_Separate_Tree (Record_Extension_Part (Type_Definition (N))); Decl : Node_Id; begin Build_Derived_Record_Type (N, Parent_Type, Derived_Type, Derive_Subps); -- Build anonymous completion, as a derivation from the full -- view of the parent. This is not a completion in the usual -- sense, because the current type is not private. Decl := Make_Full_Type_Declaration (Loc, Defining_Identifier => Full_Der, Type_Definition => Make_Derived_Type_Definition (Loc, Subtype_Indication => New_Copy_Tree (Subtype_Indication (Type_Definition (N))), Record_Extension_Part => New_Ext)); -- If the parent type has an underlying record view, use it -- here to build the new underlying record view. if Present (Underlying_Record_View (Full_P)) then pragma Assert (Nkind (Subtype_Indication (Type_Definition (Decl))) = N_Identifier); Set_Entity (Subtype_Indication (Type_Definition (Decl)), Underlying_Record_View (Full_P)); end if; Install_Private_Declarations (Par_Scope); Install_Visible_Declarations (Par_Scope); Insert_Before (N, Decl); -- Mark entity as an underlying record view before analysis, -- to avoid generating the list of its primitive operations -- (which is not really required for this entity) and thus -- prevent spurious errors associated with missing overriding -- of abstract primitives (overridden only for Derived_Type). Set_Ekind (Full_Der, E_Record_Type); Set_Is_Underlying_Record_View (Full_Der); Set_Default_SSO (Full_Der); Analyze (Decl); pragma Assert (Has_Discriminants (Full_Der) and then not Has_Unknown_Discriminants (Full_Der)); Uninstall_Declarations (Par_Scope); -- Freeze the underlying record view, to prevent generation of -- useless dispatching information, which is simply shared with -- the real derived type. Set_Is_Frozen (Full_Der); -- If the derived type has access discriminants, create -- references to their anonymous types now, to prevent -- back-end problems when their first use is in generated -- bodies of primitives. declare E : Entity_Id; begin E := First_Entity (Full_Der); while Present (E) loop if Ekind (E) = E_Discriminant and then Ekind (Etype (E)) = E_Anonymous_Access_Type then Build_Itype_Reference (Etype (E), Decl); end if; Next_Entity (E); end loop; end; -- Set up links between real entity and underlying record view Set_Underlying_Record_View (Derived_Type, Base_Type (Full_Der)); Set_Underlying_Record_View (Base_Type (Full_Der), Derived_Type); end; -- If discriminants are known, build derived record else Build_Derived_Record_Type (N, Parent_Type, Derived_Type, Derive_Subps); end if; return; elsif Has_Discriminants (Parent_Type) then -- Build partial view of derived type from partial view of parent. -- This must be done before building the full derivation because the -- second derivation will modify the discriminants of the first and -- the discriminants are chained with the rest of the components in -- the full derivation. Build_Derived_Record_Type (N, Parent_Type, Derived_Type, Derive_Subps); -- Build the full derivation if this is not the anonymous derived -- base type created by Build_Derived_Record_Type in the constrained -- case (see point 5. of its head comment) since we build it for the -- derived subtype. And skip it for protected types altogether, as -- gigi does not use these types directly. if Present (Full_View (Parent_Type)) and then not Is_Itype (Derived_Type) and then not (Ekind (Full_View (Parent_Type)) in Protected_Kind) then declare Der_Base : constant Entity_Id := Base_Type (Derived_Type); Discr : Entity_Id; Last_Discr : Entity_Id; begin -- If this is not a completion, construct the implicit full -- view by deriving from the full view of the parent type. -- But if this is a completion, the derived private type -- being built is a full view and the full derivation can -- only be its underlying full view. Build_Full_Derivation; if not Is_Completion then Set_Full_View (Derived_Type, Full_Der); else Set_Underlying_Full_View (Derived_Type, Full_Der); Set_Is_Underlying_Full_View (Full_Der); end if; if not Is_Base_Type (Derived_Type) then Set_Full_View (Der_Base, Base_Type (Full_Der)); end if; -- Copy the discriminant list from full view to the partial -- view (base type and its subtype). Gigi requires that the -- partial and full views have the same discriminants. -- Note that since the partial view points to discriminants -- in the full view, their scope will be that of the full -- view. This might cause some front end problems and need -- adjustment??? Discr := First_Discriminant (Base_Type (Full_Der)); Set_First_Entity (Der_Base, Discr); loop Last_Discr := Discr; Next_Discriminant (Discr); exit when No (Discr); end loop; Set_Last_Entity (Der_Base, Last_Discr); Set_First_Entity (Derived_Type, First_Entity (Der_Base)); Set_Last_Entity (Derived_Type, Last_Entity (Der_Base)); Set_Stored_Constraint (Full_Der, Stored_Constraint (Derived_Type)); end; end if; elsif Present (Full_View (Parent_Type)) and then Has_Discriminants (Full_View (Parent_Type)) then if Has_Unknown_Discriminants (Parent_Type) and then Nkind (Subtype_Indication (Type_Definition (N))) = N_Subtype_Indication then Error_Msg_N ("cannot constrain type with unknown discriminants", Subtype_Indication (Type_Definition (N))); return; end if; -- If this is not a completion, construct the implicit full view by -- deriving from the full view of the parent type. But if this is a -- completion, the derived private type being built is a full view -- and the full derivation can only be its underlying full view. Build_Full_Derivation; if not Is_Completion then Set_Full_View (Derived_Type, Full_Der); else Set_Underlying_Full_View (Derived_Type, Full_Der); Set_Is_Underlying_Full_View (Full_Der); end if; -- In any case, the primitive operations are inherited from the -- parent type, not from the internal full view. Set_Etype (Base_Type (Derived_Type), Base_Type (Parent_Type)); if Derive_Subps then Derive_Subprograms (Parent_Type, Derived_Type); end if; Set_Stored_Constraint (Derived_Type, No_Elist); Set_Is_Constrained (Derived_Type, Is_Constrained (Full_View (Parent_Type))); else -- Untagged type, No discriminants on either view if Nkind (Subtype_Indication (Type_Definition (N))) = N_Subtype_Indication then Error_Msg_N ("illegal constraint on type without discriminants", N); end if; if Present (Discriminant_Specifications (N)) and then Present (Full_View (Parent_Type)) and then not Is_Tagged_Type (Full_View (Parent_Type)) then Error_Msg_N ("cannot add discriminants to untagged type", N); end if; Set_Stored_Constraint (Derived_Type, No_Elist); Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type)); Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type)); Set_Disable_Controlled (Derived_Type, Disable_Controlled (Parent_Type)); Set_Has_Controlled_Component (Derived_Type, Has_Controlled_Component (Parent_Type)); -- Direct controlled types do not inherit Finalize_Storage_Only flag if not Is_Controlled_Active (Parent_Type) then Set_Finalize_Storage_Only (Base_Type (Derived_Type), Finalize_Storage_Only (Parent_Type)); end if; -- If this is not a completion, construct the implicit full view by -- deriving from the full view of the parent type. -- ??? If the parent is untagged private and its completion is -- tagged, this mechanism will not work because we cannot derive from -- the tagged full view unless we have an extension. if Present (Full_View (Parent_Type)) and then not Is_Tagged_Type (Full_View (Parent_Type)) and then not Is_Completion then Build_Full_Derivation; Set_Full_View (Derived_Type, Full_Der); end if; end if; Set_Has_Unknown_Discriminants (Derived_Type, Has_Unknown_Discriminants (Parent_Type)); if Is_Private_Type (Derived_Type) then Set_Private_Dependents (Derived_Type, New_Elmt_List); end if; -- If the parent base type is in scope, add the derived type to its -- list of private dependents, because its full view may become -- visible subsequently (in a nested private part, a body, or in a -- further child unit). if Is_Private_Type (Par_Base) and then In_Open_Scopes (Par_Scope) then Append_Elmt (Derived_Type, Private_Dependents (Parent_Type)); -- Check for unusual case where a type completed by a private -- derivation occurs within a package nested in a child unit, and -- the parent is declared in an ancestor. if Is_Child_Unit (Scope (Current_Scope)) and then Is_Completion and then In_Private_Part (Current_Scope) and then Scope (Parent_Type) /= Current_Scope -- Note that if the parent has a completion in the private part, -- (which is itself a derivation from some other private type) -- it is that completion that is visible, there is no full view -- available, and no special processing is needed. and then Present (Full_View (Parent_Type)) then -- In this case, the full view of the parent type will become -- visible in the body of the enclosing child, and only then will -- the current type be possibly non-private. Build an underlying -- full view that will be installed when the enclosing child body -- is compiled. if Present (Underlying_Full_View (Derived_Type)) then Full_Der := Underlying_Full_View (Derived_Type); else Build_Full_Derivation; Set_Underlying_Full_View (Derived_Type, Full_Der); Set_Is_Underlying_Full_View (Full_Der); end if; -- The full view will be used to swap entities on entry/exit to -- the body, and must appear in the entity list for the package. Append_Entity (Full_Der, Scope (Derived_Type)); end if; end if; end Build_Derived_Private_Type; ------------------------------- -- Build_Derived_Record_Type -- ------------------------------- -- 1. INTRODUCTION -- Ideally we would like to use the same model of type derivation for -- tagged and untagged record types. Unfortunately this is not quite -- possible because the semantics of representation clauses is different -- for tagged and untagged records under inheritance. Consider the -- following: -- type R (...) is [tagged] record ... end record; -- type T (...) is new R (...) [with ...]; -- The representation clauses for T can specify a completely different -- record layout from R's. Hence the same component can be placed in two -- very different positions in objects of type T and R. If R and T are -- tagged types, representation clauses for T can only specify the layout -- of non inherited components, thus components that are common in R and T -- have the same position in objects of type R and T. -- This has two implications. The first is that the entire tree for R's -- declaration needs to be copied for T in the untagged case, so that T -- can be viewed as a record type of its own with its own representation -- clauses. The second implication is the way we handle discriminants. -- Specifically, in the untagged case we need a way to communicate to Gigi -- what are the real discriminants in the record, while for the semantics -- we need to consider those introduced by the user to rename the -- discriminants in the parent type. This is handled by introducing the -- notion of stored discriminants. See below for more. -- Fortunately the way regular components are inherited can be handled in -- the same way in tagged and untagged types. -- To complicate things a bit more the private view of a private extension -- cannot be handled in the same way as the full view (for one thing the -- semantic rules are somewhat different). We will explain what differs -- below. -- 2. DISCRIMINANTS UNDER INHERITANCE -- The semantic rules governing the discriminants of derived types are -- quite subtle. -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART] -- If parent type has discriminants, then the discriminants that are -- declared in the derived type are [3.4 (11)]: -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if -- there is one; -- o Otherwise, each discriminant of the parent type (implicitly declared -- in the same order with the same specifications). In this case, the -- discriminants are said to be "inherited", or if unknown in the parent -- are also unknown in the derived type. -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]: -- o The parent subtype must be constrained; -- o If the parent type is not a tagged type, then each discriminant of -- the derived type must be used in the constraint defining a parent -- subtype. [Implementation note: This ensures that the new discriminant -- can share storage with an existing discriminant.] -- For the derived type each discriminant of the parent type is either -- inherited, constrained to equal some new discriminant of the derived -- type, or constrained to the value of an expression. -- When inherited or constrained to equal some new discriminant, the -- parent discriminant and the discriminant of the derived type are said -- to "correspond". -- If a discriminant of the parent type is constrained to a specific value -- in the derived type definition, then the discriminant is said to be -- "specified" by that derived type definition. -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES -- We have spoken about stored discriminants in point 1 (introduction) -- above. There are two sort of stored discriminants: implicit and -- explicit. As long as the derived type inherits the same discriminants as -- the root record type, stored discriminants are the same as regular -- discriminants, and are said to be implicit. However, if any discriminant -- in the root type was renamed in the derived type, then the derived -- type will contain explicit stored discriminants. Explicit stored -- discriminants are discriminants in addition to the semantically visible -- discriminants defined for the derived type. Stored discriminants are -- used by Gigi to figure out what are the physical discriminants in -- objects of the derived type (see precise definition in einfo.ads). -- As an example, consider the following: -- type R (D1, D2, D3 : Int) is record ... end record; -- type T1 is new R; -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1); -- type T3 is new T2; -- type T4 (Y : Int) is new T3 (Y, 99); -- The following table summarizes the discriminants and stored -- discriminants in R and T1 through T4. -- Type Discrim Stored Discrim Comment -- R (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in R -- T1 (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in T1 -- T2 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T2 -- T3 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T3 -- T4 (Y) (D1, D2, D3) Girder discrims EXPLICIT in T4 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to -- find the corresponding discriminant in the parent type, while -- Original_Record_Component (abbreviated ORC below), the actual physical -- component that is renamed. Finally the field Is_Completely_Hidden -- (abbreviated ICH below) is set for all explicit stored discriminants -- (see einfo.ads for more info). For the above example this gives: -- Discrim CD ORC ICH -- ^^^^^^^ ^^ ^^^ ^^^ -- D1 in R empty itself no -- D2 in R empty itself no -- D3 in R empty itself no -- D1 in T1 D1 in R itself no -- D2 in T1 D2 in R itself no -- D3 in T1 D3 in R itself no -- X1 in T2 D3 in T1 D3 in T2 no -- X2 in T2 D1 in T1 D1 in T2 no -- D1 in T2 empty itself yes -- D2 in T2 empty itself yes -- D3 in T2 empty itself yes -- X1 in T3 X1 in T2 D3 in T3 no -- X2 in T3 X2 in T2 D1 in T3 no -- D1 in T3 empty itself yes -- D2 in T3 empty itself yes -- D3 in T3 empty itself yes -- Y in T4 X1 in T3 D3 in T3 no -- D1 in T3 empty itself yes -- D2 in T3 empty itself yes -- D3 in T3 empty itself yes -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES -- Type derivation for tagged types is fairly straightforward. If no -- discriminants are specified by the derived type, these are inherited -- from the parent. No explicit stored discriminants are ever necessary. -- The only manipulation that is done to the tree is that of adding a -- _parent field with parent type and constrained to the same constraint -- specified for the parent in the derived type definition. For instance: -- type R (D1, D2, D3 : Int) is tagged record ... end record; -- type T1 is new R with null record; -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record; -- are changed into: -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record -- _parent : R (D1, D2, D3); -- end record; -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record -- _parent : T1 (X2, 88, X1); -- end record; -- The discriminants actually present in R, T1 and T2 as well as their CD, -- ORC and ICH fields are: -- Discrim CD ORC ICH -- ^^^^^^^ ^^ ^^^ ^^^ -- D1 in R empty itself no -- D2 in R empty itself no -- D3 in R empty itself no -- D1 in T1 D1 in R D1 in R no -- D2 in T1 D2 in R D2 in R no -- D3 in T1 D3 in R D3 in R no -- X1 in T2 D3 in T1 D3 in R no -- X2 in T2 D1 in T1 D1 in R no -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS -- -- Regardless of whether we dealing with a tagged or untagged type -- we will transform all derived type declarations of the form -- -- type T is new R (...) [with ...]; -- or -- subtype S is R (...); -- type T is new S [with ...]; -- into -- type BT is new R [with ...]; -- subtype T is BT (...); -- -- That is, the base derived type is constrained only if it has no -- discriminants. The reason for doing this is that GNAT's semantic model -- assumes that a base type with discriminants is unconstrained. -- -- Note that, strictly speaking, the above transformation is not always -- correct. Consider for instance the following excerpt from ACVC b34011a: -- -- procedure B34011A is -- type REC (D : integer := 0) is record -- I : Integer; -- end record; -- package P is -- type T6 is new Rec; -- function F return T6; -- end P; -- use P; -- package Q6 is -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F. -- end Q6; -- -- The definition of Q6.U is illegal. However transforming Q6.U into -- type BaseU is new T6; -- subtype U is BaseU (Q6.F.I) -- turns U into a legal subtype, which is incorrect. To avoid this problem -- we always analyze the constraint (in this case (Q6.F.I)) before applying -- the transformation described above. -- There is another instance where the above transformation is incorrect. -- Consider: -- package Pack is -- type Base (D : Integer) is tagged null record; -- procedure P (X : Base); -- type Der is new Base (2) with null record; -- procedure P (X : Der); -- end Pack; -- Then the above transformation turns this into -- type Der_Base is new Base with null record; -- -- procedure P (X : Base) is implicitly inherited here -- -- as procedure P (X : Der_Base). -- subtype Der is Der_Base (2); -- procedure P (X : Der); -- -- The overriding of P (X : Der_Base) is illegal since we -- -- have a parameter conformance problem. -- To get around this problem, after having semantically processed Der_Base -- and the rewritten subtype declaration for Der, we copy Der_Base field -- Discriminant_Constraint from Der so that when parameter conformance is -- checked when P is overridden, no semantic errors are flagged. -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS -- Regardless of whether we are dealing with a tagged or untagged type -- we will transform all derived type declarations of the form -- type R (D1, .., Dn : ...) is [tagged] record ...; -- type T is new R [with ...]; -- into -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...]; -- The reason for such transformation is that it allows us to implement a -- very clean form of component inheritance as explained below. -- Note that this transformation is not achieved by direct tree rewriting -- and manipulation, but rather by redoing the semantic actions that the -- above transformation will entail. This is done directly in routine -- Inherit_Components. -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE -- In both tagged and untagged derived types, regular non discriminant -- components are inherited in the derived type from the parent type. In -- the absence of discriminants component, inheritance is straightforward -- as components can simply be copied from the parent. -- If the parent has discriminants, inheriting components constrained with -- these discriminants requires caution. Consider the following example: -- type R (D1, D2 : Positive) is [tagged] record -- S : String (D1 .. D2); -- end record; -- type T1 is new R [with null record]; -- type T2 (X : positive) is new R (1, X) [with null record]; -- As explained in 6. above, T1 is rewritten as -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record]; -- which makes the treatment for T1 and T2 identical. -- What we want when inheriting S, is that references to D1 and D2 in R are -- replaced with references to their correct constraints, i.e. D1 and D2 in -- T1 and 1 and X in T2. So all R's discriminant references are replaced -- with either discriminant references in the derived type or expressions. -- This replacement is achieved as follows: before inheriting R's -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is -- created in the scope of T1 (resp. scope of T2) so that discriminants D1 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible). -- For T2, for instance, this has the effect of replacing String (D1 .. D2) -- by String (1 .. X). -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS -- We explain here the rules governing private type extensions relevant to -- type derivation. These rules are explained on the following example: -- type D [(...)] is new A [(...)] with private; <-- partial view -- type D [(...)] is new P [(...)] with null record; <-- full view -- Type A is called the ancestor subtype of the private extension. -- Type P is the parent type of the full view of the private extension. It -- must be A or a type derived from A. -- The rules concerning the discriminants of private type extensions are -- [7.3(10-13)]: -- o If a private extension inherits known discriminants from the ancestor -- subtype, then the full view must also inherit its discriminants from -- the ancestor subtype and the parent subtype of the full view must be -- constrained if and only if the ancestor subtype is constrained. -- o If a partial view has unknown discriminants, then the full view may -- define a definite or an indefinite subtype, with or without -- discriminants. -- o If a partial view has neither known nor unknown discriminants, then -- the full view must define a definite subtype. -- o If the ancestor subtype of a private extension has constrained -- discriminants, then the parent subtype of the full view must impose a -- statically matching constraint on those discriminants. -- This means that only the following forms of private extensions are -- allowed: -- type D is new A with private; <-- partial view -- type D is new P with null record; <-- full view -- If A has no discriminants than P has no discriminants, otherwise P must -- inherit A's discriminants. -- type D is new A (...) with private; <-- partial view -- type D is new P (:::) with null record; <-- full view -- P must inherit A's discriminants and (...) and (:::) must statically -- match. -- subtype A is R (...); -- type D is new A with private; <-- partial view -- type D is new P with null record; <-- full view -- P must have inherited R's discriminants and must be derived from A or -- any of its subtypes. -- type D (..) is new A with private; <-- partial view -- type D (..) is new P [(:::)] with null record; <-- full view -- No specific constraints on P's discriminants or constraint (:::). -- Note that A can be unconstrained, but the parent subtype P must either -- be constrained or (:::) must be present. -- type D (..) is new A [(...)] with private; <-- partial view -- type D (..) is new P [(:::)] with null record; <-- full view -- P's constraints on A's discriminants must statically match those -- imposed by (...). -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS -- The full view of a private extension is handled exactly as described -- above. The model chose for the private view of a private extension is -- the same for what concerns discriminants (i.e. they receive the same -- treatment as in the tagged case). However, the private view of the -- private extension always inherits the components of the parent base, -- without replacing any discriminant reference. Strictly speaking this is -- incorrect. However, Gigi never uses this view to generate code so this -- is a purely semantic issue. In theory, a set of transformations similar -- to those given in 5. and 6. above could be applied to private views of -- private extensions to have the same model of component inheritance as -- for non private extensions. However, this is not done because it would -- further complicate private type processing. Semantically speaking, this -- leaves us in an uncomfortable situation. As an example consider: -- package Pack is -- type R (D : integer) is tagged record -- S : String (1 .. D); -- end record; -- procedure P (X : R); -- type T is new R (1) with private; -- private -- type T is new R (1) with null record; -- end; -- This is transformed into: -- package Pack is -- type R (D : integer) is tagged record -- S : String (1 .. D); -- end record; -- procedure P (X : R); -- type T is new R (1) with private; -- private -- type BaseT is new R with null record; -- subtype T is BaseT (1); -- end; -- (strictly speaking the above is incorrect Ada) -- From the semantic standpoint the private view of private extension T -- should be flagged as constrained since one can clearly have -- -- Obj : T; -- -- in a unit withing Pack. However, when deriving subprograms for the -- private view of private extension T, T must be seen as unconstrained -- since T has discriminants (this is a constraint of the current -- subprogram derivation model). Thus, when processing the private view of -- a private extension such as T, we first mark T as unconstrained, we -- process it, we perform program derivation and just before returning from -- Build_Derived_Record_Type we mark T as constrained. -- ??? Are there are other uncomfortable cases that we will have to -- deal with. -- 10. RECORD_TYPE_WITH_PRIVATE complications -- Types that are derived from a visible record type and have a private -- extension present other peculiarities. They behave mostly like private -- types, but if they have primitive operations defined, these will not -- have the proper signatures for further inheritance, because other -- primitive operations will use the implicit base that we define for -- private derivations below. This affect subprogram inheritance (see -- Derive_Subprograms for details). We also derive the implicit base from -- the base type of the full view, so that the implicit base is a record -- type and not another private type, This avoids infinite loops. procedure Build_Derived_Record_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id; Derive_Subps : Boolean := True) is Discriminant_Specs : constant Boolean := Present (Discriminant_Specifications (N)); Is_Tagged : constant Boolean := Is_Tagged_Type (Parent_Type); Loc : constant Source_Ptr := Sloc (N); Private_Extension : constant Boolean := Nkind (N) = N_Private_Extension_Declaration; Assoc_List : Elist_Id; Constraint_Present : Boolean; Constrs : Elist_Id; Discrim : Entity_Id; Indic : Node_Id; Inherit_Discrims : Boolean := False; Last_Discrim : Entity_Id; New_Base : Entity_Id; New_Decl : Node_Id; New_Discrs : Elist_Id; New_Indic : Node_Id; Parent_Base : Entity_Id; Save_Etype : Entity_Id; Save_Discr_Constr : Elist_Id; Save_Next_Entity : Entity_Id; Type_Def : Node_Id; Discs : Elist_Id := New_Elmt_List; -- An empty Discs list means that there were no constraints in the -- subtype indication or that there was an error processing it. begin if Ekind (Parent_Type) = E_Record_Type_With_Private and then Present (Full_View (Parent_Type)) and then Has_Discriminants (Parent_Type) then Parent_Base := Base_Type (Full_View (Parent_Type)); else Parent_Base := Base_Type (Parent_Type); end if; -- AI05-0115 : if this is a derivation from a private type in some -- other scope that may lead to invisible components for the derived -- type, mark it accordingly. if Is_Private_Type (Parent_Type) then if Scope (Parent_Type) = Scope (Derived_Type) then null; elsif In_Open_Scopes (Scope (Parent_Type)) and then In_Private_Part (Scope (Parent_Type)) then null; else Set_Has_Private_Ancestor (Derived_Type); end if; else Set_Has_Private_Ancestor (Derived_Type, Has_Private_Ancestor (Parent_Type)); end if; -- Before we start the previously documented transformations, here is -- little fix for size and alignment of tagged types. Normally when we -- derive type D from type P, we copy the size and alignment of P as the -- default for D, and in the absence of explicit representation clauses -- for D, the size and alignment are indeed the same as the parent. -- But this is wrong for tagged types, since fields may be added, and -- the default size may need to be larger, and the default alignment may -- need to be larger. -- We therefore reset the size and alignment fields in the tagged case. -- Note that the size and alignment will in any case be at least as -- large as the parent type (since the derived type has a copy of the -- parent type in the _parent field) -- The type is also marked as being tagged here, which is needed when -- processing components with a self-referential anonymous access type -- in the call to Check_Anonymous_Access_Components below. Note that -- this flag is also set later on for completeness. if Is_Tagged then Set_Is_Tagged_Type (Derived_Type); Init_Size_Align (Derived_Type); end if; -- STEP 0a: figure out what kind of derived type declaration we have if Private_Extension then Type_Def := N; Set_Ekind (Derived_Type, E_Record_Type_With_Private); Set_Default_SSO (Derived_Type); else Type_Def := Type_Definition (N); -- Ekind (Parent_Base) is not necessarily E_Record_Type since -- Parent_Base can be a private type or private extension. However, -- for tagged types with an extension the newly added fields are -- visible and hence the Derived_Type is always an E_Record_Type. -- (except that the parent may have its own private fields). -- For untagged types we preserve the Ekind of the Parent_Base. if Present (Record_Extension_Part (Type_Def)) then Set_Ekind (Derived_Type, E_Record_Type); Set_Default_SSO (Derived_Type); -- Create internal access types for components with anonymous -- access types. if Ada_Version >= Ada_2005 then Check_Anonymous_Access_Components (N, Derived_Type, Derived_Type, Component_List (Record_Extension_Part (Type_Def))); end if; else Set_Ekind (Derived_Type, Ekind (Parent_Base)); end if; end if; -- Indic can either be an N_Identifier if the subtype indication -- contains no constraint or an N_Subtype_Indication if the subtype -- indication has a constraint. Indic := Subtype_Indication (Type_Def); Constraint_Present := (Nkind (Indic) = N_Subtype_Indication); -- Check that the type has visible discriminants. The type may be -- a private type with unknown discriminants whose full view has -- discriminants which are invisible. if Constraint_Present then if not Has_Discriminants (Parent_Base) or else (Has_Unknown_Discriminants (Parent_Base) and then Is_Private_Type (Parent_Base)) then Error_Msg_N ("invalid constraint: type has no discriminant", Constraint (Indic)); Constraint_Present := False; Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic))); elsif Is_Constrained (Parent_Type) then Error_Msg_N ("invalid constraint: parent type is already constrained", Constraint (Indic)); Constraint_Present := False; Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic))); end if; end if; -- STEP 0b: If needed, apply transformation given in point 5. above if not Private_Extension and then Has_Discriminants (Parent_Type) and then not Discriminant_Specs and then (Is_Constrained (Parent_Type) or else Constraint_Present) then -- First, we must analyze the constraint (see comment in point 5.) -- The constraint may come from the subtype indication of the full -- declaration. if Constraint_Present then New_Discrs := Build_Discriminant_Constraints (Parent_Type, Indic); -- If there is no explicit constraint, there might be one that is -- inherited from a constrained parent type. In that case verify that -- it conforms to the constraint in the partial view. In perverse -- cases the parent subtypes of the partial and full view can have -- different constraints. elsif Present (Stored_Constraint (Parent_Type)) then New_Discrs := Stored_Constraint (Parent_Type); else New_Discrs := No_Elist; end if; if Has_Discriminants (Derived_Type) and then Has_Private_Declaration (Derived_Type) and then Present (Discriminant_Constraint (Derived_Type)) and then Present (New_Discrs) then -- Verify that constraints of the full view statically match -- those given in the partial view. declare C1, C2 : Elmt_Id; begin C1 := First_Elmt (New_Discrs); C2 := First_Elmt (Discriminant_Constraint (Derived_Type)); while Present (C1) and then Present (C2) loop if Fully_Conformant_Expressions (Node (C1), Node (C2)) or else (Is_OK_Static_Expression (Node (C1)) and then Is_OK_Static_Expression (Node (C2)) and then Expr_Value (Node (C1)) = Expr_Value (Node (C2))) then null; else if Constraint_Present then Error_Msg_N ("constraint not conformant to previous declaration", Node (C1)); else Error_Msg_N ("constraint of full view is incompatible " & "with partial view", N); end if; end if; Next_Elmt (C1); Next_Elmt (C2); end loop; end; end if; -- Insert and analyze the declaration for the unconstrained base type New_Base := Create_Itype (Ekind (Derived_Type), N, Derived_Type, 'B'); New_Decl := Make_Full_Type_Declaration (Loc, Defining_Identifier => New_Base, Type_Definition => Make_Derived_Type_Definition (Loc, Abstract_Present => Abstract_Present (Type_Def), Limited_Present => Limited_Present (Type_Def), Subtype_Indication => New_Occurrence_Of (Parent_Base, Loc), Record_Extension_Part => Relocate_Node (Record_Extension_Part (Type_Def)), Interface_List => Interface_List (Type_Def))); Set_Parent (New_Decl, Parent (N)); Mark_Rewrite_Insertion (New_Decl); Insert_Before (N, New_Decl); -- In the extension case, make sure ancestor is frozen appropriately -- (see also non-discriminated case below). if Present (Record_Extension_Part (Type_Def)) or else Is_Interface (Parent_Base) then Freeze_Before (New_Decl, Parent_Type); end if; -- Note that this call passes False for the Derive_Subps parameter -- because subprogram derivation is deferred until after creating -- the subtype (see below). Build_Derived_Type (New_Decl, Parent_Base, New_Base, Is_Completion => False, Derive_Subps => False); -- ??? This needs re-examination to determine whether the -- above call can simply be replaced by a call to Analyze. Set_Analyzed (New_Decl); -- Insert and analyze the declaration for the constrained subtype if Constraint_Present then New_Indic := Make_Subtype_Indication (Loc, Subtype_Mark => New_Occurrence_Of (New_Base, Loc), Constraint => Relocate_Node (Constraint (Indic))); else declare Constr_List : constant List_Id := New_List; C : Elmt_Id; Expr : Node_Id; begin C := First_Elmt (Discriminant_Constraint (Parent_Type)); while Present (C) loop Expr := Node (C); -- It is safe here to call New_Copy_Tree since we called -- Force_Evaluation on each constraint previously -- in Build_Discriminant_Constraints. Append (New_Copy_Tree (Expr), To => Constr_List); Next_Elmt (C); end loop; New_Indic := Make_Subtype_Indication (Loc, Subtype_Mark => New_Occurrence_Of (New_Base, Loc), Constraint => Make_Index_Or_Discriminant_Constraint (Loc, Constr_List)); end; end if; Rewrite (N, Make_Subtype_Declaration (Loc, Defining_Identifier => Derived_Type, Subtype_Indication => New_Indic)); Analyze (N); -- Derivation of subprograms must be delayed until the full subtype -- has been established, to ensure proper overriding of subprograms -- inherited by full types. If the derivations occurred as part of -- the call to Build_Derived_Type above, then the check for type -- conformance would fail because earlier primitive subprograms -- could still refer to the full type prior the change to the new -- subtype and hence would not match the new base type created here. -- Subprograms are not derived, however, when Derive_Subps is False -- (since otherwise there could be redundant derivations). if Derive_Subps then Derive_Subprograms (Parent_Type, Derived_Type); end if; -- For tagged types the Discriminant_Constraint of the new base itype -- is inherited from the first subtype so that no subtype conformance -- problem arise when the first subtype overrides primitive -- operations inherited by the implicit base type. if Is_Tagged then Set_Discriminant_Constraint (New_Base, Discriminant_Constraint (Derived_Type)); end if; return; end if; -- If we get here Derived_Type will have no discriminants or it will be -- a discriminated unconstrained base type. -- STEP 1a: perform preliminary actions/checks for derived tagged types if Is_Tagged then -- The parent type is frozen for non-private extensions (RM 13.14(7)) -- The declaration of a specific descendant of an interface type -- freezes the interface type (RM 13.14). if not Private_Extension or else Is_Interface (Parent_Base) then Freeze_Before (N, Parent_Type); end if; -- In Ada 2005 (AI-344), the restriction that a derived tagged type -- cannot be declared at a deeper level than its parent type is -- removed. The check on derivation within a generic body is also -- relaxed, but there's a restriction that a derived tagged type -- cannot be declared in a generic body if it's derived directly -- or indirectly from a formal type of that generic. if Ada_Version >= Ada_2005 then if Present (Enclosing_Generic_Body (Derived_Type)) then declare Ancestor_Type : Entity_Id; begin -- Check to see if any ancestor of the derived type is a -- formal type. Ancestor_Type := Parent_Type; while not Is_Generic_Type (Ancestor_Type) and then Etype (Ancestor_Type) /= Ancestor_Type loop Ancestor_Type := Etype (Ancestor_Type); end loop; -- If the derived type does have a formal type as an -- ancestor, then it's an error if the derived type is -- declared within the body of the generic unit that -- declares the formal type in its generic formal part. It's -- sufficient to check whether the ancestor type is declared -- inside the same generic body as the derived type (such as -- within a nested generic spec), in which case the -- derivation is legal. If the formal type is declared -- outside of that generic body, then it's guaranteed that -- the derived type is declared within the generic body of -- the generic unit declaring the formal type. if Is_Generic_Type (Ancestor_Type) and then Enclosing_Generic_Body (Ancestor_Type) /= Enclosing_Generic_Body (Derived_Type) then Error_Msg_NE ("parent type of& must not be descendant of formal type" & " of an enclosing generic body", Indic, Derived_Type); end if; end; end if; elsif Type_Access_Level (Derived_Type) /= Type_Access_Level (Parent_Type) and then not Is_Generic_Type (Derived_Type) then if Is_Controlled (Parent_Type) then Error_Msg_N ("controlled type must be declared at the library level", Indic); else Error_Msg_N ("type extension at deeper accessibility level than parent", Indic); end if; else declare GB : constant Node_Id := Enclosing_Generic_Body (Derived_Type); begin if Present (GB) and then GB /= Enclosing_Generic_Body (Parent_Base) then Error_Msg_NE ("parent type of& must not be outside generic body" & " (RM 3.9.1(4))", Indic, Derived_Type); end if; end; end if; end if; -- Ada 2005 (AI-251) if Ada_Version >= Ada_2005 and then Is_Tagged then -- "The declaration of a specific descendant of an interface type -- freezes the interface type" (RM 13.14). declare Iface : Node_Id; begin if Is_Non_Empty_List (Interface_List (Type_Def)) then Iface := First (Interface_List (Type_Def)); while Present (Iface) loop Freeze_Before (N, Etype (Iface)); Next (Iface); end loop; end if; end; end if; -- STEP 1b : preliminary cleanup of the full view of private types -- If the type is already marked as having discriminants, then it's the -- completion of a private type or private extension and we need to -- retain the discriminants from the partial view if the current -- declaration has Discriminant_Specifications so that we can verify -- conformance. However, we must remove any existing components that -- were inherited from the parent (and attached in Copy_And_Swap) -- because the full type inherits all appropriate components anyway, and -- we do not want the partial view's components interfering. if Has_Discriminants (Derived_Type) and then Discriminant_Specs then Discrim := First_Discriminant (Derived_Type); loop Last_Discrim := Discrim; Next_Discriminant (Discrim); exit when No (Discrim); end loop; Set_Last_Entity (Derived_Type, Last_Discrim); -- In all other cases wipe out the list of inherited components (even -- inherited discriminants), it will be properly rebuilt here. else Set_First_Entity (Derived_Type, Empty); Set_Last_Entity (Derived_Type, Empty); end if; -- STEP 1c: Initialize some flags for the Derived_Type -- The following flags must be initialized here so that -- Process_Discriminants can check that discriminants of tagged types do -- not have a default initial value and that access discriminants are -- only specified for limited records. For completeness, these flags are -- also initialized along with all the other flags below. -- AI-419: Limitedness is not inherited from an interface parent, so to -- be limited in that case the type must be explicitly declared as -- limited. However, task and protected interfaces are always limited. if Limited_Present (Type_Def) then Set_Is_Limited_Record (Derived_Type); elsif Is_Limited_Record (Parent_Type) or else (Present (Full_View (Parent_Type)) and then Is_Limited_Record (Full_View (Parent_Type))) then if not Is_Interface (Parent_Type) or else Is_Synchronized_Interface (Parent_Type) or else Is_Protected_Interface (Parent_Type) or else Is_Task_Interface (Parent_Type) then Set_Is_Limited_Record (Derived_Type); end if; end if; -- STEP 2a: process discriminants of derived type if any Push_Scope (Derived_Type); if Discriminant_Specs then Set_Has_Unknown_Discriminants (Derived_Type, False); -- The following call initializes fields Has_Discriminants and -- Discriminant_Constraint, unless we are processing the completion -- of a private type declaration. Check_Or_Process_Discriminants (N, Derived_Type); -- For untagged types, the constraint on the Parent_Type must be -- present and is used to rename the discriminants. if not Is_Tagged and then not Has_Discriminants (Parent_Type) then Error_Msg_N ("untagged parent must have discriminants", Indic); elsif not Is_Tagged and then not Constraint_Present then Error_Msg_N ("discriminant constraint needed for derived untagged records", Indic); -- Otherwise the parent subtype must be constrained unless we have a -- private extension. elsif not Constraint_Present and then not Private_Extension and then not Is_Constrained (Parent_Type) then Error_Msg_N ("unconstrained type not allowed in this context", Indic); elsif Constraint_Present then -- The following call sets the field Corresponding_Discriminant -- for the discriminants in the Derived_Type. Discs := Build_Discriminant_Constraints (Parent_Type, Indic, True); -- For untagged types all new discriminants must rename -- discriminants in the parent. For private extensions new -- discriminants cannot rename old ones (implied by [7.3(13)]). Discrim := First_Discriminant (Derived_Type); while Present (Discrim) loop if not Is_Tagged and then No (Corresponding_Discriminant (Discrim)) then Error_Msg_N ("new discriminants must constrain old ones", Discrim); elsif Private_Extension and then Present (Corresponding_Discriminant (Discrim)) then Error_Msg_N ("only static constraints allowed for parent" & " discriminants in the partial view", Indic); exit; end if; -- If a new discriminant is used in the constraint, then its -- subtype must be statically compatible with the parent -- discriminant's subtype (3.7(15)). -- However, if the record contains an array constrained by -- the discriminant but with some different bound, the compiler -- attemps to create a smaller range for the discriminant type. -- (See exp_ch3.Adjust_Discriminants). In this case, where -- the discriminant type is a scalar type, the check must use -- the original discriminant type in the parent declaration. declare Corr_Disc : constant Entity_Id := Corresponding_Discriminant (Discrim); Disc_Type : constant Entity_Id := Etype (Discrim); Corr_Type : Entity_Id; begin if Present (Corr_Disc) then if Is_Scalar_Type (Disc_Type) then Corr_Type := Entity (Discriminant_Type (Parent (Corr_Disc))); else Corr_Type := Etype (Corr_Disc); end if; if not Subtypes_Statically_Compatible (Disc_Type, Corr_Type) then Error_Msg_N ("subtype must be compatible " & "with parent discriminant", Discrim); end if; end if; end; Next_Discriminant (Discrim); end loop; -- Check whether the constraints of the full view statically -- match those imposed by the parent subtype [7.3(13)]. if Present (Stored_Constraint (Derived_Type)) then declare C1, C2 : Elmt_Id; begin C1 := First_Elmt (Discs); C2 := First_Elmt (Stored_Constraint (Derived_Type)); while Present (C1) and then Present (C2) loop if not Fully_Conformant_Expressions (Node (C1), Node (C2)) then Error_Msg_N ("not conformant with previous declaration", Node (C1)); end if; Next_Elmt (C1); Next_Elmt (C2); end loop; end; end if; end if; -- STEP 2b: No new discriminants, inherit discriminants if any else if Private_Extension then Set_Has_Unknown_Discriminants (Derived_Type, Has_Unknown_Discriminants (Parent_Type) or else Unknown_Discriminants_Present (N)); -- The partial view of the parent may have unknown discriminants, -- but if the full view has discriminants and the parent type is -- in scope they must be inherited. elsif Has_Unknown_Discriminants (Parent_Type) and then (not Has_Discriminants (Parent_Type) or else not In_Open_Scopes (Scope (Parent_Type))) then Set_Has_Unknown_Discriminants (Derived_Type); end if; if not Has_Unknown_Discriminants (Derived_Type) and then not Has_Unknown_Discriminants (Parent_Base) and then Has_Discriminants (Parent_Type) then Inherit_Discrims := True; Set_Has_Discriminants (Derived_Type, True); Set_Discriminant_Constraint (Derived_Type, Discriminant_Constraint (Parent_Base)); end if; -- The following test is true for private types (remember -- transformation 5. is not applied to those) and in an error -- situation. if Constraint_Present then Discs := Build_Discriminant_Constraints (Parent_Type, Indic); end if; -- For now mark a new derived type as constrained only if it has no -- discriminants. At the end of Build_Derived_Record_Type we properly -- set this flag in the case of private extensions. See comments in -- point 9. just before body of Build_Derived_Record_Type. Set_Is_Constrained (Derived_Type, not (Inherit_Discrims or else Has_Unknown_Discriminants (Derived_Type))); end if; -- STEP 3: initialize fields of derived type Set_Is_Tagged_Type (Derived_Type, Is_Tagged); Set_Stored_Constraint (Derived_Type, No_Elist); -- Ada 2005 (AI-251): Private type-declarations can implement interfaces -- but cannot be interfaces if not Private_Extension and then Ekind (Derived_Type) /= E_Private_Type and then Ekind (Derived_Type) /= E_Limited_Private_Type then if Interface_Present (Type_Def) then Analyze_Interface_Declaration (Derived_Type, Type_Def); end if; Set_Interfaces (Derived_Type, No_Elist); end if; -- Fields inherited from the Parent_Type Set_Has_Specified_Layout (Derived_Type, Has_Specified_Layout (Parent_Type)); Set_Is_Limited_Composite (Derived_Type, Is_Limited_Composite (Parent_Type)); Set_Is_Private_Composite (Derived_Type, Is_Private_Composite (Parent_Type)); if Is_Tagged_Type (Parent_Type) then Set_No_Tagged_Streams_Pragma (Derived_Type, No_Tagged_Streams_Pragma (Parent_Type)); end if; -- Fields inherited from the Parent_Base Set_Has_Controlled_Component (Derived_Type, Has_Controlled_Component (Parent_Base)); Set_Has_Non_Standard_Rep (Derived_Type, Has_Non_Standard_Rep (Parent_Base)); Set_Has_Primitive_Operations (Derived_Type, Has_Primitive_Operations (Parent_Base)); -- Fields inherited from the Parent_Base in the non-private case if Ekind (Derived_Type) = E_Record_Type then Set_Has_Complex_Representation (Derived_Type, Has_Complex_Representation (Parent_Base)); end if; -- Fields inherited from the Parent_Base for record types if Is_Record_Type (Derived_Type) then declare Parent_Full : Entity_Id; begin -- Ekind (Parent_Base) is not necessarily E_Record_Type since -- Parent_Base can be a private type or private extension. Go -- to the full view here to get the E_Record_Type specific flags. if Present (Full_View (Parent_Base)) then Parent_Full := Full_View (Parent_Base); else Parent_Full := Parent_Base; end if; Set_OK_To_Reorder_Components (Derived_Type, OK_To_Reorder_Components (Parent_Full)); end; end if; -- Set fields for private derived types if Is_Private_Type (Derived_Type) then Set_Depends_On_Private (Derived_Type, True); Set_Private_Dependents (Derived_Type, New_Elmt_List); -- Inherit fields from non private record types. If this is the -- completion of a derivation from a private type, the parent itself -- is private, and the attributes come from its full view, which must -- be present. else if Is_Private_Type (Parent_Base) and then not Is_Record_Type (Parent_Base) then Set_Component_Alignment (Derived_Type, Component_Alignment (Full_View (Parent_Base))); Set_C_Pass_By_Copy (Derived_Type, C_Pass_By_Copy (Full_View (Parent_Base))); else Set_Component_Alignment (Derived_Type, Component_Alignment (Parent_Base)); Set_C_Pass_By_Copy (Derived_Type, C_Pass_By_Copy (Parent_Base)); end if; end if; -- Set fields for tagged types if Is_Tagged then Set_Direct_Primitive_Operations (Derived_Type, New_Elmt_List); -- All tagged types defined in Ada.Finalization are controlled if Chars (Scope (Derived_Type)) = Name_Finalization and then Chars (Scope (Scope (Derived_Type))) = Name_Ada and then Scope (Scope (Scope (Derived_Type))) = Standard_Standard then Set_Is_Controlled (Derived_Type); else Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Base)); end if; -- Minor optimization: there is no need to generate the class-wide -- entity associated with an underlying record view. if not Is_Underlying_Record_View (Derived_Type) then Make_Class_Wide_Type (Derived_Type); end if; Set_Is_Abstract_Type (Derived_Type, Abstract_Present (Type_Def)); if Has_Discriminants (Derived_Type) and then Constraint_Present then Set_Stored_Constraint (Derived_Type, Expand_To_Stored_Constraint (Parent_Base, Discs)); end if; if Ada_Version >= Ada_2005 then declare Ifaces_List : Elist_Id; begin -- Checks rules 3.9.4 (13/2 and 14/2) if Comes_From_Source (Derived_Type) and then not Is_Private_Type (Derived_Type) and then Is_Interface (Parent_Type) and then not Is_Interface (Derived_Type) then if Is_Task_Interface (Parent_Type) then Error_Msg_N ("(Ada 2005) task type required (RM 3.9.4 (13.2))", Derived_Type); elsif Is_Protected_Interface (Parent_Type) then Error_Msg_N ("(Ada 2005) protected type required (RM 3.9.4 (14.2))", Derived_Type); end if; end if; -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2) Check_Interfaces (N, Type_Def); -- Ada 2005 (AI-251): Collect the list of progenitors that are -- not already in the parents. Collect_Interfaces (T => Derived_Type, Ifaces_List => Ifaces_List, Exclude_Parents => True); Set_Interfaces (Derived_Type, Ifaces_List); -- If the derived type is the anonymous type created for -- a declaration whose parent has a constraint, propagate -- the interface list to the source type. This must be done -- prior to the completion of the analysis of the source type -- because the components in the extension may contain current -- instances whose legality depends on some ancestor. if Is_Itype (Derived_Type) then declare Def : constant Node_Id := Associated_Node_For_Itype (Derived_Type); begin if Present (Def) and then Nkind (Def) = N_Full_Type_Declaration then Set_Interfaces (Defining_Identifier (Def), Ifaces_List); end if; end; end if; -- A type extension is automatically Ghost when one of its -- progenitors is Ghost (SPARK RM 6.9(9)). This property is -- also inherited when the parent type is Ghost, but this is -- done in Build_Derived_Type as the mechanism also handles -- untagged derivations. if Implements_Ghost_Interface (Derived_Type) then Set_Is_Ghost_Entity (Derived_Type); end if; end; end if; else Set_Is_Packed (Derived_Type, Is_Packed (Parent_Base)); Set_Has_Non_Standard_Rep (Derived_Type, Has_Non_Standard_Rep (Parent_Base)); end if; -- STEP 4: Inherit components from the parent base and constrain them. -- Apply the second transformation described in point 6. above. if (not Is_Empty_Elmt_List (Discs) or else Inherit_Discrims) or else not Has_Discriminants (Parent_Type) or else not Is_Constrained (Parent_Type) then Constrs := Discs; else Constrs := Discriminant_Constraint (Parent_Type); end if; Assoc_List := Inherit_Components (N, Parent_Base, Derived_Type, Is_Tagged, Inherit_Discrims, Constrs); -- STEP 5a: Copy the parent record declaration for untagged types Set_Has_Implicit_Dereference (Derived_Type, Has_Implicit_Dereference (Parent_Type)); if not Is_Tagged then -- Discriminant_Constraint (Derived_Type) has been properly -- constructed. Save it and temporarily set it to Empty because we -- do not want the call to New_Copy_Tree below to mess this list. if Has_Discriminants (Derived_Type) then Save_Discr_Constr := Discriminant_Constraint (Derived_Type); Set_Discriminant_Constraint (Derived_Type, No_Elist); else Save_Discr_Constr := No_Elist; end if; -- Save the Etype field of Derived_Type. It is correctly set now, -- but the call to New_Copy tree may remap it to point to itself, -- which is not what we want. Ditto for the Next_Entity field. Save_Etype := Etype (Derived_Type); Save_Next_Entity := Next_Entity (Derived_Type); -- Assoc_List maps all stored discriminants in the Parent_Base to -- stored discriminants in the Derived_Type. It is fundamental that -- no types or itypes with discriminants other than the stored -- discriminants appear in the entities declared inside -- Derived_Type, since the back end cannot deal with it. New_Decl := New_Copy_Tree (Parent (Parent_Base), Map => Assoc_List, New_Sloc => Loc); -- Restore the fields saved prior to the New_Copy_Tree call -- and compute the stored constraint. Set_Etype (Derived_Type, Save_Etype); Set_Next_Entity (Derived_Type, Save_Next_Entity); if Has_Discriminants (Derived_Type) then Set_Discriminant_Constraint (Derived_Type, Save_Discr_Constr); Set_Stored_Constraint (Derived_Type, Expand_To_Stored_Constraint (Parent_Type, Discs)); Replace_Components (Derived_Type, New_Decl); end if; -- Insert the new derived type declaration Rewrite (N, New_Decl); -- STEP 5b: Complete the processing for record extensions in generics -- There is no completion for record extensions declared in the -- parameter part of a generic, so we need to complete processing for -- these generic record extensions here. The Record_Type_Definition call -- will change the Ekind of the components from E_Void to E_Component. elsif Private_Extension and then Is_Generic_Type (Derived_Type) then Record_Type_Definition (Empty, Derived_Type); -- STEP 5c: Process the record extension for non private tagged types elsif not Private_Extension then Expand_Record_Extension (Derived_Type, Type_Def); -- Note : previously in ASIS mode we set the Parent_Subtype of the -- derived type to propagate some semantic information. This led -- to other ASIS failures and has been removed. -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the -- implemented interfaces if we are in expansion mode if Expander_Active and then Has_Interfaces (Derived_Type) then Add_Interface_Tag_Components (N, Derived_Type); end if; -- Analyze the record extension Record_Type_Definition (Record_Extension_Part (Type_Def), Derived_Type); end if; End_Scope; -- Nothing else to do if there is an error in the derivation. -- An unusual case: the full view may be derived from a type in an -- instance, when the partial view was used illegally as an actual -- in that instance, leading to a circular definition. if Etype (Derived_Type) = Any_Type or else Etype (Parent_Type) = Derived_Type then return; end if; -- Set delayed freeze and then derive subprograms, we need to do -- this in this order so that derived subprograms inherit the -- derived freeze if necessary. Set_Has_Delayed_Freeze (Derived_Type); if Derive_Subps then Derive_Subprograms (Parent_Type, Derived_Type); end if; -- If we have a private extension which defines a constrained derived -- type mark as constrained here after we have derived subprograms. See -- comment on point 9. just above the body of Build_Derived_Record_Type. if Private_Extension and then Inherit_Discrims then if Constraint_Present and then not Is_Empty_Elmt_List (Discs) then Set_Is_Constrained (Derived_Type, True); Set_Discriminant_Constraint (Derived_Type, Discs); elsif Is_Constrained (Parent_Type) then Set_Is_Constrained (Derived_Type, True); Set_Discriminant_Constraint (Derived_Type, Discriminant_Constraint (Parent_Type)); end if; end if; -- Update the class-wide type, which shares the now-completed entity -- list with its specific type. In case of underlying record views, -- we do not generate the corresponding class wide entity. if Is_Tagged and then not Is_Underlying_Record_View (Derived_Type) then Set_First_Entity (Class_Wide_Type (Derived_Type), First_Entity (Derived_Type)); Set_Last_Entity (Class_Wide_Type (Derived_Type), Last_Entity (Derived_Type)); end if; Check_Function_Writable_Actuals (N); end Build_Derived_Record_Type; ------------------------ -- Build_Derived_Type -- ------------------------ procedure Build_Derived_Type (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id; Is_Completion : Boolean; Derive_Subps : Boolean := True) is Parent_Base : constant Entity_Id := Base_Type (Parent_Type); begin -- Set common attributes Set_Scope (Derived_Type, Current_Scope); Set_Etype (Derived_Type, Parent_Base); Set_Ekind (Derived_Type, Ekind (Parent_Base)); Propagate_Concurrent_Flags (Derived_Type, Parent_Base); Set_Size_Info (Derived_Type, Parent_Type); Set_RM_Size (Derived_Type, RM_Size (Parent_Type)); Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type)); Set_Disable_Controlled (Derived_Type, Disable_Controlled (Parent_Type)); Set_Is_Tagged_Type (Derived_Type, Is_Tagged_Type (Parent_Type)); Set_Is_Volatile (Derived_Type, Is_Volatile (Parent_Type)); if Is_Tagged_Type (Derived_Type) then Set_No_Tagged_Streams_Pragma (Derived_Type, No_Tagged_Streams_Pragma (Parent_Type)); end if; -- If the parent has primitive routines, set the derived type link if Has_Primitive_Operations (Parent_Type) then Set_Derived_Type_Link (Parent_Base, Derived_Type); end if; -- If the parent type is a private subtype, the convention on the base -- type may be set in the private part, and not propagated to the -- subtype until later, so we obtain the convention from the base type. Set_Convention (Derived_Type, Convention (Parent_Base)); -- Set SSO default for record or array type if (Is_Array_Type (Derived_Type) or else Is_Record_Type (Derived_Type)) and then Is_Base_Type (Derived_Type) then Set_Default_SSO (Derived_Type); end if; -- A derived type inherits the Default_Initial_Condition pragma coming -- from any parent type within the derivation chain. if Has_DIC (Parent_Type) then Set_Has_Inherited_DIC (Derived_Type); end if; -- A derived type inherits any class-wide invariants coming from a -- parent type or an interface. Note that the invariant procedure of -- the parent type should not be inherited because the derived type may -- define invariants of its own. if not Is_Interface (Derived_Type) then if Has_Inherited_Invariants (Parent_Type) or else Has_Inheritable_Invariants (Parent_Type) then Set_Has_Inherited_Invariants (Derived_Type); elsif Is_Concurrent_Type (Derived_Type) or else Is_Tagged_Type (Derived_Type) then declare Iface : Entity_Id; Ifaces : Elist_Id; Iface_Elmt : Elmt_Id; begin Collect_Interfaces (T => Derived_Type, Ifaces_List => Ifaces, Exclude_Parents => True); if Present (Ifaces) then Iface_Elmt := First_Elmt (Ifaces); while Present (Iface_Elmt) loop Iface := Node (Iface_Elmt); if Has_Inheritable_Invariants (Iface) then Set_Has_Inherited_Invariants (Derived_Type); exit; end if; Next_Elmt (Iface_Elmt); end loop; end if; end; end if; end if; -- We similarly inherit predicates. Note that for scalar derived types -- the predicate is inherited from the first subtype, and not from its -- (anonymous) base type. if Has_Predicates (Parent_Type) or else Has_Predicates (First_Subtype (Parent_Type)) then Set_Has_Predicates (Derived_Type); end if; -- The derived type inherits the representation clauses of the parent Inherit_Rep_Item_Chain (Derived_Type, Parent_Type); -- If the parent type has delayed rep aspects, then mark the derived -- type as possibly inheriting a delayed rep aspect. if Has_Delayed_Rep_Aspects (Parent_Type) then Set_May_Inherit_Delayed_Rep_Aspects (Derived_Type); end if; -- A derived type becomes Ghost when its parent type is also Ghost -- (SPARK RM 6.9(9)). Note that the Ghost-related attributes are not -- directly inherited because the Ghost policy in effect may differ. if Is_Ghost_Entity (Parent_Type) then Set_Is_Ghost_Entity (Derived_Type); end if; -- Type dependent processing case Ekind (Parent_Type) is when Numeric_Kind => Build_Derived_Numeric_Type (N, Parent_Type, Derived_Type); when Array_Kind => Build_Derived_Array_Type (N, Parent_Type, Derived_Type); when Class_Wide_Kind | E_Record_Subtype | E_Record_Type => Build_Derived_Record_Type (N, Parent_Type, Derived_Type, Derive_Subps); return; when Enumeration_Kind => Build_Derived_Enumeration_Type (N, Parent_Type, Derived_Type); when Access_Kind => Build_Derived_Access_Type (N, Parent_Type, Derived_Type); when Incomplete_Or_Private_Kind => Build_Derived_Private_Type (N, Parent_Type, Derived_Type, Is_Completion, Derive_Subps); -- For discriminated types, the derivation includes deriving -- primitive operations. For others it is done below. if Is_Tagged_Type (Parent_Type) or else Has_Discriminants (Parent_Type) or else (Present (Full_View (Parent_Type)) and then Has_Discriminants (Full_View (Parent_Type))) then return; end if; when Concurrent_Kind => Build_Derived_Concurrent_Type (N, Parent_Type, Derived_Type); when others => raise Program_Error; end case; -- Nothing more to do if some error occurred if Etype (Derived_Type) = Any_Type then return; end if; -- Set delayed freeze and then derive subprograms, we need to do this -- in this order so that derived subprograms inherit the derived freeze -- if necessary. Set_Has_Delayed_Freeze (Derived_Type); if Derive_Subps then Derive_Subprograms (Parent_Type, Derived_Type); end if; Set_Has_Primitive_Operations (Base_Type (Derived_Type), Has_Primitive_Operations (Parent_Type)); end Build_Derived_Type; ----------------------- -- Build_Discriminal -- ----------------------- procedure Build_Discriminal (Discrim : Entity_Id) is D_Minal : Entity_Id; CR_Disc : Entity_Id; begin -- A discriminal has the same name as the discriminant D_Minal := Make_Defining_Identifier (Sloc (Discrim), Chars (Discrim)); Set_Ekind (D_Minal, E_In_Parameter); Set_Mechanism (D_Minal, Default_Mechanism); Set_Etype (D_Minal, Etype (Discrim)); Set_Scope (D_Minal, Current_Scope); Set_Parent (D_Minal, Parent (Discrim)); Set_Discriminal (Discrim, D_Minal); Set_Discriminal_Link (D_Minal, Discrim); -- For task types, build at once the discriminants of the corresponding -- record, which are needed if discriminants are used in entry defaults -- and in family bounds. if Is_Concurrent_Type (Current_Scope) or else Is_Limited_Type (Current_Scope) then CR_Disc := Make_Defining_Identifier (Sloc (Discrim), Chars (Discrim)); Set_Ekind (CR_Disc, E_In_Parameter); Set_Mechanism (CR_Disc, Default_Mechanism); Set_Etype (CR_Disc, Etype (Discrim)); Set_Scope (CR_Disc, Current_Scope); Set_Discriminal_Link (CR_Disc, Discrim); Set_CR_Discriminant (Discrim, CR_Disc); end if; end Build_Discriminal; ------------------------------------ -- Build_Discriminant_Constraints -- ------------------------------------ function Build_Discriminant_Constraints (T : Entity_Id; Def : Node_Id; Derived_Def : Boolean := False) return Elist_Id is C : constant Node_Id := Constraint (Def); Nb_Discr : constant Nat := Number_Discriminants (T); Discr_Expr : array (1 .. Nb_Discr) of Node_Id := (others => Empty); -- Saves the expression corresponding to a given discriminant in T function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat; -- Return the Position number within array Discr_Expr of a discriminant -- D within the discriminant list of the discriminated type T. procedure Process_Discriminant_Expression (Expr : Node_Id; D : Entity_Id); -- If this is a discriminant constraint on a partial view, do not -- generate an overflow check on the discriminant expression. The check -- will be generated when constraining the full view. Otherwise the -- backend creates duplicate symbols for the temporaries corresponding -- to the expressions to be checked, causing spurious assembler errors. ------------------ -- Pos_Of_Discr -- ------------------ function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat is Disc : Entity_Id; begin Disc := First_Discriminant (T); for J in Discr_Expr'Range loop if Disc = D then return J; end if; Next_Discriminant (Disc); end loop; -- Note: Since this function is called on discriminants that are -- known to belong to the discriminated type, falling through the -- loop with no match signals an internal compiler error. raise Program_Error; end Pos_Of_Discr; ------------------------------------- -- Process_Discriminant_Expression -- ------------------------------------- procedure Process_Discriminant_Expression (Expr : Node_Id; D : Entity_Id) is BDT : constant Entity_Id := Base_Type (Etype (D)); begin -- If this is a discriminant constraint on a partial view, do -- not generate an overflow on the discriminant expression. The -- check will be generated when constraining the full view. if Is_Private_Type (T) and then Present (Full_View (T)) then Analyze_And_Resolve (Expr, BDT, Suppress => Overflow_Check); else Analyze_And_Resolve (Expr, BDT); end if; end Process_Discriminant_Expression; -- Declarations local to Build_Discriminant_Constraints Discr : Entity_Id; E : Entity_Id; Elist : constant Elist_Id := New_Elmt_List; Constr : Node_Id; Expr : Node_Id; Id : Node_Id; Position : Nat; Found : Boolean; Discrim_Present : Boolean := False; -- Start of processing for Build_Discriminant_Constraints begin -- The following loop will process positional associations only. -- For a positional association, the (single) discriminant is -- implicitly specified by position, in textual order (RM 3.7.2). Discr := First_Discriminant (T); Constr := First (Constraints (C)); for D in Discr_Expr'Range loop exit when Nkind (Constr) = N_Discriminant_Association; if No (Constr) then Error_Msg_N ("too few discriminants given in constraint", C); return New_Elmt_List; elsif Nkind (Constr) = N_Range or else (Nkind (Constr) = N_Attribute_Reference and then Attribute_Name (Constr) = Name_Range) then Error_Msg_N ("a range is not a valid discriminant constraint", Constr); Discr_Expr (D) := Error; else Process_Discriminant_Expression (Constr, Discr); Discr_Expr (D) := Constr; end if; Next_Discriminant (Discr); Next (Constr); end loop; if No (Discr) and then Present (Constr) then Error_Msg_N ("too many discriminants given in constraint", Constr); return New_Elmt_List; end if; -- Named associations can be given in any order, but if both positional -- and named associations are used in the same discriminant constraint, -- then positional associations must occur first, at their normal -- position. Hence once a named association is used, the rest of the -- discriminant constraint must use only named associations. while Present (Constr) loop -- Positional association forbidden after a named association if Nkind (Constr) /= N_Discriminant_Association then Error_Msg_N ("positional association follows named one", Constr); return New_Elmt_List; -- Otherwise it is a named association else -- E records the type of the discriminants in the named -- association. All the discriminants specified in the same name -- association must have the same type. E := Empty; -- Search the list of discriminants in T to see if the simple name -- given in the constraint matches any of them. Id := First (Selector_Names (Constr)); while Present (Id) loop Found := False; -- If Original_Discriminant is present, we are processing a -- generic instantiation and this is an instance node. We need -- to find the name of the corresponding discriminant in the -- actual record type T and not the name of the discriminant in -- the generic formal. Example: -- generic -- type G (D : int) is private; -- package P is -- subtype W is G (D => 1); -- end package; -- type Rec (X : int) is record ... end record; -- package Q is new P (G => Rec); -- At the point of the instantiation, formal type G is Rec -- and therefore when reanalyzing "subtype W is G (D => 1);" -- which really looks like "subtype W is Rec (D => 1);" at -- the point of instantiation, we want to find the discriminant -- that corresponds to D in Rec, i.e. X. if Present (Original_Discriminant (Id)) and then In_Instance then Discr := Find_Corresponding_Discriminant (Id, T); Found := True; else Discr := First_Discriminant (T); while Present (Discr) loop if Chars (Discr) = Chars (Id) then Found := True; exit; end if; Next_Discriminant (Discr); end loop; if not Found then Error_Msg_N ("& does not match any discriminant", Id); return New_Elmt_List; -- If the parent type is a generic formal, preserve the -- name of the discriminant for subsequent instances. -- see comment at the beginning of this if statement. elsif Is_Generic_Type (Root_Type (T)) then Set_Original_Discriminant (Id, Discr); end if; end if; Position := Pos_Of_Discr (T, Discr); if Present (Discr_Expr (Position)) then Error_Msg_N ("duplicate constraint for discriminant&", Id); else -- Each discriminant specified in the same named association -- must be associated with a separate copy of the -- corresponding expression. if Present (Next (Id)) then Expr := New_Copy_Tree (Expression (Constr)); Set_Parent (Expr, Parent (Expression (Constr))); else Expr := Expression (Constr); end if; Discr_Expr (Position) := Expr; Process_Discriminant_Expression (Expr, Discr); end if; -- A discriminant association with more than one discriminant -- name is only allowed if the named discriminants are all of -- the same type (RM 3.7.1(8)). if E = Empty then E := Base_Type (Etype (Discr)); elsif Base_Type (Etype (Discr)) /= E then Error_Msg_N ("all discriminants in an association " & "must have the same type", Id); end if; Next (Id); end loop; end if; Next (Constr); end loop; -- A discriminant constraint must provide exactly one value for each -- discriminant of the type (RM 3.7.1(8)). for J in Discr_Expr'Range loop if No (Discr_Expr (J)) then Error_Msg_N ("too few discriminants given in constraint", C); return New_Elmt_List; end if; end loop; -- Determine if there are discriminant expressions in the constraint for J in Discr_Expr'Range loop if Denotes_Discriminant (Discr_Expr (J), Check_Concurrent => True) then Discrim_Present := True; end if; end loop; -- Build an element list consisting of the expressions given in the -- discriminant constraint and apply the appropriate checks. The list -- is constructed after resolving any named discriminant associations -- and therefore the expressions appear in the textual order of the -- discriminants. Discr := First_Discriminant (T); for J in Discr_Expr'Range loop if Discr_Expr (J) /= Error then Append_Elmt (Discr_Expr (J), Elist); -- If any of the discriminant constraints is given by a -- discriminant and we are in a derived type declaration we -- have a discriminant renaming. Establish link between new -- and old discriminant. The new discriminant has an implicit -- dereference if the old one does. if Denotes_Discriminant (Discr_Expr (J)) then if Derived_Def then declare New_Discr : constant Entity_Id := Entity (Discr_Expr (J)); begin Set_Corresponding_Discriminant (New_Discr, Discr); Set_Has_Implicit_Dereference (New_Discr, Has_Implicit_Dereference (Discr)); end; end if; -- Force the evaluation of non-discriminant expressions. -- If we have found a discriminant in the constraint 3.4(26) -- and 3.8(18) demand that no range checks are performed are -- after evaluation. If the constraint is for a component -- definition that has a per-object constraint, expressions are -- evaluated but not checked either. In all other cases perform -- a range check. else if Discrim_Present then null; elsif Nkind (Parent (Parent (Def))) = N_Component_Declaration and then Has_Per_Object_Constraint (Defining_Identifier (Parent (Parent (Def)))) then null; elsif Is_Access_Type (Etype (Discr)) then Apply_Constraint_Check (Discr_Expr (J), Etype (Discr)); else Apply_Range_Check (Discr_Expr (J), Etype (Discr)); end if; Force_Evaluation (Discr_Expr (J)); end if; -- Check that the designated type of an access discriminant's -- expression is not a class-wide type unless the discriminant's -- designated type is also class-wide. if Ekind (Etype (Discr)) = E_Anonymous_Access_Type and then not Is_Class_Wide_Type (Designated_Type (Etype (Discr))) and then Etype (Discr_Expr (J)) /= Any_Type and then Is_Class_Wide_Type (Designated_Type (Etype (Discr_Expr (J)))) then Wrong_Type (Discr_Expr (J), Etype (Discr)); elsif Is_Access_Type (Etype (Discr)) and then not Is_Access_Constant (Etype (Discr)) and then Is_Access_Type (Etype (Discr_Expr (J))) and then Is_Access_Constant (Etype (Discr_Expr (J))) then Error_Msg_NE ("constraint for discriminant& must be access to variable", Def, Discr); end if; end if; Next_Discriminant (Discr); end loop; return Elist; end Build_Discriminant_Constraints; --------------------------------- -- Build_Discriminated_Subtype -- --------------------------------- procedure Build_Discriminated_Subtype (T : Entity_Id; Def_Id : Entity_Id; Elist : Elist_Id; Related_Nod : Node_Id; For_Access : Boolean := False) is Has_Discrs : constant Boolean := Has_Discriminants (T); Constrained : constant Boolean := (Has_Discrs and then not Is_Empty_Elmt_List (Elist) and then not Is_Class_Wide_Type (T)) or else Is_Constrained (T); begin if Ekind (T) = E_Record_Type then if For_Access then Set_Ekind (Def_Id, E_Private_Subtype); Set_Is_For_Access_Subtype (Def_Id, True); else Set_Ekind (Def_Id, E_Record_Subtype); end if; -- Inherit preelaboration flag from base, for types for which it -- may have been set: records, private types, protected types. Set_Known_To_Have_Preelab_Init (Def_Id, Known_To_Have_Preelab_Init (T)); elsif Ekind (T) = E_Task_Type then Set_Ekind (Def_Id, E_Task_Subtype); elsif Ekind (T) = E_Protected_Type then Set_Ekind (Def_Id, E_Protected_Subtype); Set_Known_To_Have_Preelab_Init (Def_Id, Known_To_Have_Preelab_Init (T)); elsif Is_Private_Type (T) then Set_Ekind (Def_Id, Subtype_Kind (Ekind (T))); Set_Known_To_Have_Preelab_Init (Def_Id, Known_To_Have_Preelab_Init (T)); -- Private subtypes may have private dependents Set_Private_Dependents (Def_Id, New_Elmt_List); elsif Is_Class_Wide_Type (T) then Set_Ekind (Def_Id, E_Class_Wide_Subtype); else -- Incomplete type. Attach subtype to list of dependents, to be -- completed with full view of parent type, unless is it the -- designated subtype of a record component within an init_proc. -- This last case arises for a component of an access type whose -- designated type is incomplete (e.g. a Taft Amendment type). -- The designated subtype is within an inner scope, and needs no -- elaboration, because only the access type is needed in the -- initialization procedure. Set_Ekind (Def_Id, Ekind (T)); if For_Access and then Within_Init_Proc then null; else Append_Elmt (Def_Id, Private_Dependents (T)); end if; end if; Set_Etype (Def_Id, T); Init_Size_Align (Def_Id); Set_Has_Discriminants (Def_Id, Has_Discrs); Set_Is_Constrained (Def_Id, Constrained); Set_First_Entity (Def_Id, First_Entity (T)); Set_Last_Entity (Def_Id, Last_Entity (T)); Set_Has_Implicit_Dereference (Def_Id, Has_Implicit_Dereference (T)); Set_Has_Pragma_Unreferenced_Objects (Def_Id, Has_Pragma_Unreferenced_Objects (T)); -- If the subtype is the completion of a private declaration, there may -- have been representation clauses for the partial view, and they must -- be preserved. Build_Derived_Type chains the inherited clauses with -- the ones appearing on the extension. If this comes from a subtype -- declaration, all clauses are inherited. if No (First_Rep_Item (Def_Id)) then Set_First_Rep_Item (Def_Id, First_Rep_Item (T)); end if; if Is_Tagged_Type (T) then Set_Is_Tagged_Type (Def_Id); Set_No_Tagged_Streams_Pragma (Def_Id, No_Tagged_Streams_Pragma (T)); Make_Class_Wide_Type (Def_Id); end if; Set_Stored_Constraint (Def_Id, No_Elist); if Has_Discrs then Set_Discriminant_Constraint (Def_Id, Elist); Set_Stored_Constraint_From_Discriminant_Constraint (Def_Id); end if; if Is_Tagged_Type (T) then -- Ada 2005 (AI-251): In case of concurrent types we inherit the -- concurrent record type (which has the list of primitive -- operations). if Ada_Version >= Ada_2005 and then Is_Concurrent_Type (T) then Set_Corresponding_Record_Type (Def_Id, Corresponding_Record_Type (T)); else Set_Direct_Primitive_Operations (Def_Id, Direct_Primitive_Operations (T)); end if; Set_Is_Abstract_Type (Def_Id, Is_Abstract_Type (T)); end if; -- Subtypes introduced by component declarations do not need to be -- marked as delayed, and do not get freeze nodes, because the semantics -- verifies that the parents of the subtypes are frozen before the -- enclosing record is frozen. if not Is_Type (Scope (Def_Id)) then Set_Depends_On_Private (Def_Id, Depends_On_Private (T)); if Is_Private_Type (T) and then Present (Full_View (T)) then Conditional_Delay (Def_Id, Full_View (T)); else Conditional_Delay (Def_Id, T); end if; end if; if Is_Record_Type (T) then Set_Is_Limited_Record (Def_Id, Is_Limited_Record (T)); if Has_Discrs and then not Is_Empty_Elmt_List (Elist) and then not For_Access then Create_Constrained_Components (Def_Id, Related_Nod, T, Elist); elsif not For_Access then Set_Cloned_Subtype (Def_Id, T); end if; end if; end Build_Discriminated_Subtype; --------------------------- -- Build_Itype_Reference -- --------------------------- procedure Build_Itype_Reference (Ityp : Entity_Id; Nod : Node_Id) is IR : constant Node_Id := Make_Itype_Reference (Sloc (Nod)); begin -- Itype references are only created for use by the back-end if Inside_A_Generic then return; else Set_Itype (IR, Ityp); Insert_After (Nod, IR); end if; end Build_Itype_Reference; ------------------------ -- Build_Scalar_Bound -- ------------------------ function Build_Scalar_Bound (Bound : Node_Id; Par_T : Entity_Id; Der_T : Entity_Id) return Node_Id is New_Bound : Entity_Id; begin -- Note: not clear why this is needed, how can the original bound -- be unanalyzed at this point? and if it is, what business do we -- have messing around with it? and why is the base type of the -- parent type the right type for the resolution. It probably is -- not. It is OK for the new bound we are creating, but not for -- the old one??? Still if it never happens, no problem. Analyze_And_Resolve (Bound, Base_Type (Par_T)); if Nkind_In (Bound, N_Integer_Literal, N_Real_Literal) then New_Bound := New_Copy (Bound); Set_Etype (New_Bound, Der_T); Set_Analyzed (New_Bound); elsif Is_Entity_Name (Bound) then New_Bound := OK_Convert_To (Der_T, New_Copy (Bound)); -- The following is almost certainly wrong. What business do we have -- relocating a node (Bound) that is presumably still attached to -- the tree elsewhere??? else New_Bound := OK_Convert_To (Der_T, Relocate_Node (Bound)); end if; Set_Etype (New_Bound, Der_T); return New_Bound; end Build_Scalar_Bound; -------------------------------- -- Build_Underlying_Full_View -- -------------------------------- procedure Build_Underlying_Full_View (N : Node_Id; Typ : Entity_Id; Par : Entity_Id) is Loc : constant Source_Ptr := Sloc (N); Subt : constant Entity_Id := Make_Defining_Identifier (Loc, New_External_Name (Chars (Typ), 'S')); Constr : Node_Id; Indic : Node_Id; C : Node_Id; Id : Node_Id; procedure Set_Discriminant_Name (Id : Node_Id); -- If the derived type has discriminants, they may rename discriminants -- of the parent. When building the full view of the parent, we need to -- recover the names of the original discriminants if the constraint is -- given by named associations. --------------------------- -- Set_Discriminant_Name -- --------------------------- procedure Set_Discriminant_Name (Id : Node_Id) is Disc : Entity_Id; begin Set_Original_Discriminant (Id, Empty); if Has_Discriminants (Typ) then Disc := First_Discriminant (Typ); while Present (Disc) loop if Chars (Disc) = Chars (Id) and then Present (Corresponding_Discriminant (Disc)) then Set_Chars (Id, Chars (Corresponding_Discriminant (Disc))); end if; Next_Discriminant (Disc); end loop; end if; end Set_Discriminant_Name; -- Start of processing for Build_Underlying_Full_View begin if Nkind (N) = N_Full_Type_Declaration then Constr := Constraint (Subtype_Indication (Type_Definition (N))); elsif Nkind (N) = N_Subtype_Declaration then Constr := New_Copy_Tree (Constraint (Subtype_Indication (N))); elsif Nkind (N) = N_Component_Declaration then Constr := New_Copy_Tree (Constraint (Subtype_Indication (Component_Definition (N)))); else raise Program_Error; end if; C := First (Constraints (Constr)); while Present (C) loop if Nkind (C) = N_Discriminant_Association then Id := First (Selector_Names (C)); while Present (Id) loop Set_Discriminant_Name (Id); Next (Id); end loop; end if; Next (C); end loop; Indic := Make_Subtype_Declaration (Loc, Defining_Identifier => Subt, Subtype_Indication => Make_Subtype_Indication (Loc, Subtype_Mark => New_Occurrence_Of (Par, Loc), Constraint => New_Copy_Tree (Constr))); -- If this is a component subtype for an outer itype, it is not -- a list member, so simply set the parent link for analysis: if -- the enclosing type does not need to be in a declarative list, -- neither do the components. if Is_List_Member (N) and then Nkind (N) /= N_Component_Declaration then Insert_Before (N, Indic); else Set_Parent (Indic, Parent (N)); end if; Analyze (Indic); Set_Underlying_Full_View (Typ, Full_View (Subt)); Set_Is_Underlying_Full_View (Full_View (Subt)); end Build_Underlying_Full_View; ------------------------------- -- Check_Abstract_Overriding -- ------------------------------- procedure Check_Abstract_Overriding (T : Entity_Id) is Alias_Subp : Entity_Id; Elmt : Elmt_Id; Op_List : Elist_Id; Subp : Entity_Id; Type_Def : Node_Id; procedure Check_Pragma_Implemented (Subp : Entity_Id); -- Ada 2012 (AI05-0030): Subprogram Subp overrides an interface routine -- which has pragma Implemented already set. Check whether Subp's entity -- kind conforms to the implementation kind of the overridden routine. procedure Check_Pragma_Implemented (Subp : Entity_Id; Iface_Subp : Entity_Id); -- Ada 2012 (AI05-0030): Subprogram Subp overrides interface routine -- Iface_Subp and both entities have pragma Implemented already set on -- them. Check whether the two implementation kinds are conforming. procedure Inherit_Pragma_Implemented (Subp : Entity_Id; Iface_Subp : Entity_Id); -- Ada 2012 (AI05-0030): Interface primitive Subp overrides interface -- subprogram Iface_Subp which has been marked by pragma Implemented. -- Propagate the implementation kind of Iface_Subp to Subp. ------------------------------ -- Check_Pragma_Implemented -- ------------------------------ procedure Check_Pragma_Implemented (Subp : Entity_Id) is Iface_Alias : constant Entity_Id := Interface_Alias (Subp); Impl_Kind : constant Name_Id := Implementation_Kind (Iface_Alias); Subp_Alias : constant Entity_Id := Alias (Subp); Contr_Typ : Entity_Id; Impl_Subp : Entity_Id; begin -- Subp must have an alias since it is a hidden entity used to link -- an interface subprogram to its overriding counterpart. pragma Assert (Present (Subp_Alias)); -- Handle aliases to synchronized wrappers Impl_Subp := Subp_Alias; if Is_Primitive_Wrapper (Impl_Subp) then Impl_Subp := Wrapped_Entity (Impl_Subp); end if; -- Extract the type of the controlling formal Contr_Typ := Etype (First_Formal (Subp_Alias)); if Is_Concurrent_Record_Type (Contr_Typ) then Contr_Typ := Corresponding_Concurrent_Type (Contr_Typ); end if; -- An interface subprogram whose implementation kind is By_Entry must -- be implemented by an entry. if Impl_Kind = Name_By_Entry and then Ekind (Impl_Subp) /= E_Entry then Error_Msg_Node_2 := Iface_Alias; Error_Msg_NE ("type & must implement abstract subprogram & with an entry", Subp_Alias, Contr_Typ); elsif Impl_Kind = Name_By_Protected_Procedure then -- An interface subprogram whose implementation kind is By_ -- Protected_Procedure cannot be implemented by a primitive -- procedure of a task type. if Ekind (Contr_Typ) /= E_Protected_Type then Error_Msg_Node_2 := Contr_Typ; Error_Msg_NE ("interface subprogram & cannot be implemented by a " & "primitive procedure of task type &", Subp_Alias, Iface_Alias); -- An interface subprogram whose implementation kind is By_ -- Protected_Procedure must be implemented by a procedure. elsif Ekind (Impl_Subp) /= E_Procedure then Error_Msg_Node_2 := Iface_Alias; Error_Msg_NE ("type & must implement abstract subprogram & with a " & "procedure", Subp_Alias, Contr_Typ); elsif Present (Get_Rep_Pragma (Impl_Subp, Name_Implemented)) and then Implementation_Kind (Impl_Subp) /= Impl_Kind then Error_Msg_Name_1 := Impl_Kind; Error_Msg_N ("overriding operation& must have synchronization%", Subp_Alias); end if; -- If primitive has Optional synchronization, overriding operation -- must match if it has an explicit synchronization.. elsif Present (Get_Rep_Pragma (Impl_Subp, Name_Implemented)) and then Implementation_Kind (Impl_Subp) /= Impl_Kind then Error_Msg_Name_1 := Impl_Kind; Error_Msg_N ("overriding operation& must have syncrhonization%", Subp_Alias); end if; end Check_Pragma_Implemented; ------------------------------ -- Check_Pragma_Implemented -- ------------------------------ procedure Check_Pragma_Implemented (Subp : Entity_Id; Iface_Subp : Entity_Id) is Iface_Kind : constant Name_Id := Implementation_Kind (Iface_Subp); Subp_Kind : constant Name_Id := Implementation_Kind (Subp); begin -- Ada 2012 (AI05-0030): The implementation kinds of an overridden -- and overriding subprogram are different. In general this is an -- error except when the implementation kind of the overridden -- subprograms is By_Any or Optional. if Iface_Kind /= Subp_Kind and then Iface_Kind /= Name_By_Any and then Iface_Kind /= Name_Optional then if Iface_Kind = Name_By_Entry then Error_Msg_N ("incompatible implementation kind, overridden subprogram " & "is marked By_Entry", Subp); else Error_Msg_N ("incompatible implementation kind, overridden subprogram " & "is marked By_Protected_Procedure", Subp); end if; end if; end Check_Pragma_Implemented; -------------------------------- -- Inherit_Pragma_Implemented -- -------------------------------- procedure Inherit_Pragma_Implemented (Subp : Entity_Id; Iface_Subp : Entity_Id) is Iface_Kind : constant Name_Id := Implementation_Kind (Iface_Subp); Loc : constant Source_Ptr := Sloc (Subp); Impl_Prag : Node_Id; begin -- Since the implementation kind is stored as a representation item -- rather than a flag, create a pragma node. Impl_Prag := Make_Pragma (Loc, Chars => Name_Implemented, Pragma_Argument_Associations => New_List ( Make_Pragma_Argument_Association (Loc, Expression => New_Occurrence_Of (Subp, Loc)), Make_Pragma_Argument_Association (Loc, Expression => Make_Identifier (Loc, Iface_Kind)))); -- The pragma doesn't need to be analyzed because it is internally -- built. It is safe to directly register it as a rep item since we -- are only interested in the characters of the implementation kind. Record_Rep_Item (Subp, Impl_Prag); end Inherit_Pragma_Implemented; -- Start of processing for Check_Abstract_Overriding begin Op_List := Primitive_Operations (T); -- Loop to check primitive operations Elmt := First_Elmt (Op_List); while Present (Elmt) loop Subp := Node (Elmt); Alias_Subp := Alias (Subp); -- Inherited subprograms are identified by the fact that they do not -- come from source, and the associated source location is the -- location of the first subtype of the derived type. -- Ada 2005 (AI-228): Apply the rules of RM-3.9.3(6/2) for -- subprograms that "require overriding". -- Special exception, do not complain about failure to override the -- stream routines _Input and _Output, as well as the primitive -- operations used in dispatching selects since we always provide -- automatic overridings for these subprograms. -- The partial view of T may have been a private extension, for -- which inherited functions dispatching on result are abstract. -- If the full view is a null extension, there is no need for -- overriding in Ada 2005, but wrappers need to be built for them -- (see exp_ch3, Build_Controlling_Function_Wrappers). if Is_Null_Extension (T) and then Has_Controlling_Result (Subp) and then Ada_Version >= Ada_2005 and then Present (Alias_Subp) and then not Comes_From_Source (Subp) and then not Is_Abstract_Subprogram (Alias_Subp) and then not Is_Access_Type (Etype (Subp)) then null; -- Ada 2005 (AI-251): Internal entities of interfaces need no -- processing because this check is done with the aliased -- entity elsif Present (Interface_Alias (Subp)) then null; elsif (Is_Abstract_Subprogram (Subp) or else Requires_Overriding (Subp) or else (Has_Controlling_Result (Subp) and then Present (Alias_Subp) and then not Comes_From_Source (Subp) and then Sloc (Subp) = Sloc (First_Subtype (T)))) and then not Is_TSS (Subp, TSS_Stream_Input) and then not Is_TSS (Subp, TSS_Stream_Output) and then not Is_Abstract_Type (T) and then not Is_Predefined_Interface_Primitive (Subp) -- Ada 2005 (AI-251): Do not consider hidden entities associated -- with abstract interface types because the check will be done -- with the aliased entity (otherwise we generate a duplicated -- error message). and then not Present (Interface_Alias (Subp)) then if Present (Alias_Subp) then -- Only perform the check for a derived subprogram when the -- type has an explicit record extension. This avoids incorrect -- flagging of abstract subprograms for the case of a type -- without an extension that is derived from a formal type -- with a tagged actual (can occur within a private part). -- Ada 2005 (AI-391): In the case of an inherited function with -- a controlling result of the type, the rule does not apply if -- the type is a null extension (unless the parent function -- itself is abstract, in which case the function must still be -- be overridden). The expander will generate an overriding -- wrapper function calling the parent subprogram (see -- Exp_Ch3.Make_Controlling_Wrapper_Functions). Type_Def := Type_Definition (Parent (T)); if Nkind (Type_Def) = N_Derived_Type_Definition and then Present (Record_Extension_Part (Type_Def)) and then (Ada_Version < Ada_2005 or else not Is_Null_Extension (T) or else Ekind (Subp) = E_Procedure or else not Has_Controlling_Result (Subp) or else Is_Abstract_Subprogram (Alias_Subp) or else Requires_Overriding (Subp) or else Is_Access_Type (Etype (Subp))) then -- Avoid reporting error in case of abstract predefined -- primitive inherited from interface type because the -- body of internally generated predefined primitives -- of tagged types are generated later by Freeze_Type if Is_Interface (Root_Type (T)) and then Is_Abstract_Subprogram (Subp) and then Is_Predefined_Dispatching_Operation (Subp) and then not Comes_From_Source (Ultimate_Alias (Subp)) then null; -- A null extension is not obliged to override an inherited -- procedure subject to pragma Extensions_Visible with value -- False and at least one controlling OUT parameter -- (SPARK RM 6.1.7(6)). elsif Is_Null_Extension (T) and then Is_EVF_Procedure (Subp) then null; else Error_Msg_NE ("type must be declared abstract or & overridden", T, Subp); -- Traverse the whole chain of aliased subprograms to -- complete the error notification. This is especially -- useful for traceability of the chain of entities when -- the subprogram corresponds with an interface -- subprogram (which may be defined in another package). if Present (Alias_Subp) then declare E : Entity_Id; begin E := Subp; while Present (Alias (E)) loop -- Avoid reporting redundant errors on entities -- inherited from interfaces if Sloc (E) /= Sloc (T) then Error_Msg_Sloc := Sloc (E); Error_Msg_NE ("\& has been inherited #", T, Subp); end if; E := Alias (E); end loop; Error_Msg_Sloc := Sloc (E); -- AI05-0068: report if there is an overriding -- non-abstract subprogram that is invisible. if Is_Hidden (E) and then not Is_Abstract_Subprogram (E) then Error_Msg_NE ("\& subprogram# is not visible", T, Subp); -- Clarify the case where a non-null extension must -- override inherited procedure subject to pragma -- Extensions_Visible with value False and at least -- one controlling OUT param. elsif Is_EVF_Procedure (E) then Error_Msg_NE ("\& # is subject to Extensions_Visible False", T, Subp); else Error_Msg_NE ("\& has been inherited from subprogram #", T, Subp); end if; end; end if; end if; -- Ada 2005 (AI-345): Protected or task type implementing -- abstract interfaces. elsif Is_Concurrent_Record_Type (T) and then Present (Interfaces (T)) then -- There is no need to check here RM 9.4(11.9/3) since we -- are processing the corresponding record type and the -- mode of the overriding subprograms was verified by -- Check_Conformance when the corresponding concurrent -- type declaration was analyzed. Error_Msg_NE ("interface subprogram & must be overridden", T, Subp); -- Examine primitive operations of synchronized type to find -- homonyms that have the wrong profile. declare Prim : Entity_Id; begin Prim := First_Entity (Corresponding_Concurrent_Type (T)); while Present (Prim) loop if Chars (Prim) = Chars (Subp) then Error_Msg_NE ("profile is not type conformant with prefixed " & "view profile of inherited operation&", Prim, Subp); end if; Next_Entity (Prim); end loop; end; end if; else Error_Msg_Node_2 := T; Error_Msg_N ("abstract subprogram& not allowed for type&", Subp); -- Also post unconditional warning on the type (unconditional -- so that if there are more than one of these cases, we get -- them all, and not just the first one). Error_Msg_Node_2 := Subp; Error_Msg_N ("nonabstract type& has abstract subprogram&!", T); end if; -- A subprogram subject to pragma Extensions_Visible with value -- "True" cannot override a subprogram subject to the same pragma -- with value "False" (SPARK RM 6.1.7(5)). elsif Extensions_Visible_Status (Subp) = Extensions_Visible_True and then Present (Overridden_Operation (Subp)) and then Extensions_Visible_Status (Overridden_Operation (Subp)) = Extensions_Visible_False then Error_Msg_Sloc := Sloc (Overridden_Operation (Subp)); Error_Msg_N ("subprogram & with Extensions_Visible True cannot override " & "subprogram # with Extensions_Visible False", Subp); end if; -- Ada 2012 (AI05-0030): Perform checks related to pragma Implemented -- Subp is an expander-generated procedure which maps an interface -- alias to a protected wrapper. The interface alias is flagged by -- pragma Implemented. Ensure that Subp is a procedure when the -- implementation kind is By_Protected_Procedure or an entry when -- By_Entry. if Ada_Version >= Ada_2012 and then Is_Hidden (Subp) and then Present (Interface_Alias (Subp)) and then Has_Rep_Pragma (Interface_Alias (Subp), Name_Implemented) then Check_Pragma_Implemented (Subp); end if; -- Subp is an interface primitive which overrides another interface -- primitive marked with pragma Implemented. if Ada_Version >= Ada_2012 and then Present (Overridden_Operation (Subp)) and then Has_Rep_Pragma (Overridden_Operation (Subp), Name_Implemented) then -- If the overriding routine is also marked by Implemented, check -- that the two implementation kinds are conforming. if Has_Rep_Pragma (Subp, Name_Implemented) then Check_Pragma_Implemented (Subp => Subp, Iface_Subp => Overridden_Operation (Subp)); -- Otherwise the overriding routine inherits the implementation -- kind from the overridden subprogram. else Inherit_Pragma_Implemented (Subp => Subp, Iface_Subp => Overridden_Operation (Subp)); end if; end if; -- If the operation is a wrapper for a synchronized primitive, it -- may be called indirectly through a dispatching select. We assume -- that it will be referenced elsewhere indirectly, and suppress -- warnings about an unused entity. if Is_Primitive_Wrapper (Subp) and then Present (Wrapped_Entity (Subp)) then Set_Referenced (Wrapped_Entity (Subp)); end if; Next_Elmt (Elmt); end loop; end Check_Abstract_Overriding; ------------------------------------------------ -- Check_Access_Discriminant_Requires_Limited -- ------------------------------------------------ procedure Check_Access_Discriminant_Requires_Limited (D : Node_Id; Loc : Node_Id) is begin -- A discriminant_specification for an access discriminant shall appear -- only in the declaration for a task or protected type, or for a type -- with the reserved word 'limited' in its definition or in one of its -- ancestors (RM 3.7(10)). -- AI-0063: The proper condition is that type must be immutably limited, -- or else be a partial view. if Nkind (Discriminant_Type (D)) = N_Access_Definition then if Is_Limited_View (Current_Scope) or else (Nkind (Parent (Current_Scope)) = N_Private_Type_Declaration and then Limited_Present (Parent (Current_Scope))) then null; else Error_Msg_N ("access discriminants allowed only for limited types", Loc); end if; end if; end Check_Access_Discriminant_Requires_Limited; ----------------------------------- -- Check_Aliased_Component_Types -- ----------------------------------- procedure Check_Aliased_Component_Types (T : Entity_Id) is C : Entity_Id; begin -- ??? Also need to check components of record extensions, but not -- components of protected types (which are always limited). -- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such -- types to be unconstrained. This is safe because it is illegal to -- create access subtypes to such types with explicit discriminant -- constraints. if not Is_Limited_Type (T) then if Ekind (T) = E_Record_Type then C := First_Component (T); while Present (C) loop if Is_Aliased (C) and then Has_Discriminants (Etype (C)) and then not Is_Constrained (Etype (C)) and then not In_Instance_Body and then Ada_Version < Ada_2005 then Error_Msg_N ("aliased component must be constrained (RM 3.6(11))", C); end if; Next_Component (C); end loop; elsif Ekind (T) = E_Array_Type then if Has_Aliased_Components (T) and then Has_Discriminants (Component_Type (T)) and then not Is_Constrained (Component_Type (T)) and then not In_Instance_Body and then Ada_Version < Ada_2005 then Error_Msg_N ("aliased component type must be constrained (RM 3.6(11))", T); end if; end if; end if; end Check_Aliased_Component_Types; --------------------------------------- -- Check_Anonymous_Access_Components -- --------------------------------------- procedure Check_Anonymous_Access_Components (Typ_Decl : Node_Id; Typ : Entity_Id; Prev : Entity_Id; Comp_List : Node_Id) is Loc : constant Source_Ptr := Sloc (Typ_Decl); Anon_Access : Entity_Id; Acc_Def : Node_Id; Comp : Node_Id; Comp_Def : Node_Id; Decl : Node_Id; Type_Def : Node_Id; procedure Build_Incomplete_Type_Declaration; -- If the record type contains components that include an access to the -- current record, then create an incomplete type declaration for the -- record, to be used as the designated type of the anonymous access. -- This is done only once, and only if there is no previous partial -- view of the type. function Designates_T (Subt : Node_Id) return Boolean; -- Check whether a node designates the enclosing record type, or 'Class -- of that type function Mentions_T (Acc_Def : Node_Id) return Boolean; -- Check whether an access definition includes a reference to -- the enclosing record type. The reference can be a subtype mark -- in the access definition itself, a 'Class attribute reference, or -- recursively a reference appearing in a parameter specification -- or result definition of an access_to_subprogram definition. -------------------------------------- -- Build_Incomplete_Type_Declaration -- -------------------------------------- procedure Build_Incomplete_Type_Declaration is Decl : Node_Id; Inc_T : Entity_Id; H : Entity_Id; -- Is_Tagged indicates whether the type is tagged. It is tagged if -- it's "is new ... with record" or else "is tagged record ...". Is_Tagged : constant Boolean := (Nkind (Type_Definition (Typ_Decl)) = N_Derived_Type_Definition and then Present (Record_Extension_Part (Type_Definition (Typ_Decl)))) or else (Nkind (Type_Definition (Typ_Decl)) = N_Record_Definition and then Tagged_Present (Type_Definition (Typ_Decl))); begin -- If there is a previous partial view, no need to create a new one -- If the partial view, given by Prev, is incomplete, If Prev is -- a private declaration, full declaration is flagged accordingly. if Prev /= Typ then if Is_Tagged then Make_Class_Wide_Type (Prev); Set_Class_Wide_Type (Typ, Class_Wide_Type (Prev)); Set_Etype (Class_Wide_Type (Typ), Typ); end if; return; elsif Has_Private_Declaration (Typ) then -- If we refer to T'Class inside T, and T is the completion of a -- private type, then make sure the class-wide type exists. if Is_Tagged then Make_Class_Wide_Type (Typ); end if; return; -- If there was a previous anonymous access type, the incomplete -- type declaration will have been created already. elsif Present (Current_Entity (Typ)) and then Ekind (Current_Entity (Typ)) = E_Incomplete_Type and then Full_View (Current_Entity (Typ)) = Typ then if Is_Tagged and then Comes_From_Source (Current_Entity (Typ)) and then not Is_Tagged_Type (Current_Entity (Typ)) then Make_Class_Wide_Type (Typ); Error_Msg_N ("incomplete view of tagged type should be declared tagged??", Parent (Current_Entity (Typ))); end if; return; else Inc_T := Make_Defining_Identifier (Loc, Chars (Typ)); Decl := Make_Incomplete_Type_Declaration (Loc, Inc_T); -- Type has already been inserted into the current scope. Remove -- it, and add incomplete declaration for type, so that subsequent -- anonymous access types can use it. The entity is unchained from -- the homonym list and from immediate visibility. After analysis, -- the entity in the incomplete declaration becomes immediately -- visible in the record declaration that follows. H := Current_Entity (Typ); if H = Typ then Set_Name_Entity_Id (Chars (Typ), Homonym (Typ)); else while Present (H) and then Homonym (H) /= Typ loop H := Homonym (Typ); end loop; Set_Homonym (H, Homonym (Typ)); end if; Insert_Before (Typ_Decl, Decl); Analyze (Decl); Set_Full_View (Inc_T, Typ); if Is_Tagged then -- Create a common class-wide type for both views, and set the -- Etype of the class-wide type to the full view. Make_Class_Wide_Type (Inc_T); Set_Class_Wide_Type (Typ, Class_Wide_Type (Inc_T)); Set_Etype (Class_Wide_Type (Typ), Typ); end if; end if; end Build_Incomplete_Type_Declaration; ------------------ -- Designates_T -- ------------------ function Designates_T (Subt : Node_Id) return Boolean is Type_Id : constant Name_Id := Chars (Typ); function Names_T (Nam : Node_Id) return Boolean; -- The record type has not been introduced in the current scope -- yet, so we must examine the name of the type itself, either -- an identifier T, or an expanded name of the form P.T, where -- P denotes the current scope. ------------- -- Names_T -- ------------- function Names_T (Nam : Node_Id) return Boolean is begin if Nkind (Nam) = N_Identifier then return Chars (Nam) = Type_Id; elsif Nkind (Nam) = N_Selected_Component then if Chars (Selector_Name (Nam)) = Type_Id then if Nkind (Prefix (Nam)) = N_Identifier then return Chars (Prefix (Nam)) = Chars (Current_Scope); elsif Nkind (Prefix (Nam)) = N_Selected_Component then return Chars (Selector_Name (Prefix (Nam))) = Chars (Current_Scope); else return False; end if; else return False; end if; else return False; end if; end Names_T; -- Start of processing for Designates_T begin if Nkind (Subt) = N_Identifier then return Chars (Subt) = Type_Id; -- Reference can be through an expanded name which has not been -- analyzed yet, and which designates enclosing scopes. elsif Nkind (Subt) = N_Selected_Component then if Names_T (Subt) then return True; -- Otherwise it must denote an entity that is already visible. -- The access definition may name a subtype of the enclosing -- type, if there is a previous incomplete declaration for it. else Find_Selected_Component (Subt); return Is_Entity_Name (Subt) and then Scope (Entity (Subt)) = Current_Scope and then (Chars (Base_Type (Entity (Subt))) = Type_Id or else (Is_Class_Wide_Type (Entity (Subt)) and then Chars (Etype (Base_Type (Entity (Subt)))) = Type_Id)); end if; -- A reference to the current type may appear as the prefix of -- a 'Class attribute. elsif Nkind (Subt) = N_Attribute_Reference and then Attribute_Name (Subt) = Name_Class then return Names_T (Prefix (Subt)); else return False; end if; end Designates_T; ---------------- -- Mentions_T -- ---------------- function Mentions_T (Acc_Def : Node_Id) return Boolean is Param_Spec : Node_Id; Acc_Subprg : constant Node_Id := Access_To_Subprogram_Definition (Acc_Def); begin if No (Acc_Subprg) then return Designates_T (Subtype_Mark (Acc_Def)); end if; -- Component is an access_to_subprogram: examine its formals, -- and result definition in the case of an access_to_function. Param_Spec := First (Parameter_Specifications (Acc_Subprg)); while Present (Param_Spec) loop if Nkind (Parameter_Type (Param_Spec)) = N_Access_Definition and then Mentions_T (Parameter_Type (Param_Spec)) then return True; elsif Designates_T (Parameter_Type (Param_Spec)) then return True; end if; Next (Param_Spec); end loop; if Nkind (Acc_Subprg) = N_Access_Function_Definition then if Nkind (Result_Definition (Acc_Subprg)) = N_Access_Definition then return Mentions_T (Result_Definition (Acc_Subprg)); else return Designates_T (Result_Definition (Acc_Subprg)); end if; end if; return False; end Mentions_T; -- Start of processing for Check_Anonymous_Access_Components begin if No (Comp_List) then return; end if; Comp := First (Component_Items (Comp_List)); while Present (Comp) loop if Nkind (Comp) = N_Component_Declaration and then Present (Access_Definition (Component_Definition (Comp))) and then Mentions_T (Access_Definition (Component_Definition (Comp))) then Comp_Def := Component_Definition (Comp); Acc_Def := Access_To_Subprogram_Definition (Access_Definition (Comp_Def)); Build_Incomplete_Type_Declaration; Anon_Access := Make_Temporary (Loc, 'S'); -- Create a declaration for the anonymous access type: either -- an access_to_object or an access_to_subprogram. if Present (Acc_Def) then if Nkind (Acc_Def) = N_Access_Function_Definition then Type_Def := Make_Access_Function_Definition (Loc, Parameter_Specifications => Parameter_Specifications (Acc_Def), Result_Definition => Result_Definition (Acc_Def)); else Type_Def := Make_Access_Procedure_Definition (Loc, Parameter_Specifications => Parameter_Specifications (Acc_Def)); end if; else Type_Def := Make_Access_To_Object_Definition (Loc, Subtype_Indication => Relocate_Node (Subtype_Mark (Access_Definition (Comp_Def)))); Set_Constant_Present (Type_Def, Constant_Present (Access_Definition (Comp_Def))); Set_All_Present (Type_Def, All_Present (Access_Definition (Comp_Def))); end if; Set_Null_Exclusion_Present (Type_Def, Null_Exclusion_Present (Access_Definition (Comp_Def))); Decl := Make_Full_Type_Declaration (Loc, Defining_Identifier => Anon_Access, Type_Definition => Type_Def); Insert_Before (Typ_Decl, Decl); Analyze (Decl); -- If an access to subprogram, create the extra formals if Present (Acc_Def) then Create_Extra_Formals (Designated_Type (Anon_Access)); -- If an access to object, preserve entity of designated type, -- for ASIS use, before rewriting the component definition. else declare Desig : Entity_Id; begin Desig := Entity (Subtype_Indication (Type_Def)); -- If the access definition is to the current record, -- the visible entity at this point is an incomplete -- type. Retrieve the full view to simplify ASIS queries if Ekind (Desig) = E_Incomplete_Type then Desig := Full_View (Desig); end if; Set_Entity (Subtype_Mark (Access_Definition (Comp_Def)), Desig); end; end if; Rewrite (Comp_Def, Make_Component_Definition (Loc, Subtype_Indication => New_Occurrence_Of (Anon_Access, Loc))); if Ekind (Designated_Type (Anon_Access)) = E_Subprogram_Type then Set_Ekind (Anon_Access, E_Anonymous_Access_Subprogram_Type); else Set_Ekind (Anon_Access, E_Anonymous_Access_Type); end if; Set_Is_Local_Anonymous_Access (Anon_Access); end if; Next (Comp); end loop; if Present (Variant_Part (Comp_List)) then declare V : Node_Id; begin V := First_Non_Pragma (Variants (Variant_Part (Comp_List))); while Present (V) loop Check_Anonymous_Access_Components (Typ_Decl, Typ, Prev, Component_List (V)); Next_Non_Pragma (V); end loop; end; end if; end Check_Anonymous_Access_Components; ---------------------- -- Check_Completion -- ---------------------- procedure Check_Completion (Body_Id : Node_Id := Empty) is E : Entity_Id; procedure Post_Error; -- Post error message for lack of completion for entity E ---------------- -- Post_Error -- ---------------- procedure Post_Error is procedure Missing_Body; -- Output missing body message ------------------ -- Missing_Body -- ------------------ procedure Missing_Body is begin -- Spec is in same unit, so we can post on spec if In_Same_Source_Unit (Body_Id, E) then Error_Msg_N ("missing body for &", E); -- Spec is in a separate unit, so we have to post on the body else Error_Msg_NE ("missing body for & declared#!", Body_Id, E); end if; end Missing_Body; -- Start of processing for Post_Error begin if not Comes_From_Source (E) then if Ekind_In (E, E_Task_Type, E_Protected_Type) then -- It may be an anonymous protected type created for a -- single variable. Post error on variable, if present. declare Var : Entity_Id; begin Var := First_Entity (Current_Scope); while Present (Var) loop exit when Etype (Var) = E and then Comes_From_Source (Var); Next_Entity (Var); end loop; if Present (Var) then E := Var; end if; end; end if; end if; -- If a generated entity has no completion, then either previous -- semantic errors have disabled the expansion phase, or else we had -- missing subunits, or else we are compiling without expansion, -- or else something is very wrong. if not Comes_From_Source (E) then pragma Assert (Serious_Errors_Detected > 0 or else Configurable_Run_Time_Violations > 0 or else Subunits_Missing or else not Expander_Active); return; -- Here for source entity else -- Here if no body to post the error message, so we post the error -- on the declaration that has no completion. This is not really -- the right place to post it, think about this later ??? if No (Body_Id) then if Is_Type (E) then Error_Msg_NE ("missing full declaration for }", Parent (E), E); else Error_Msg_NE ("missing body for &", Parent (E), E); end if; -- Package body has no completion for a declaration that appears -- in the corresponding spec. Post error on the body, with a -- reference to the non-completed declaration. else Error_Msg_Sloc := Sloc (E); if Is_Type (E) then Error_Msg_NE ("missing full declaration for }!", Body_Id, E); elsif Is_Overloadable (E) and then Current_Entity_In_Scope (E) /= E then -- It may be that the completion is mistyped and appears as -- a distinct overloading of the entity. declare Candidate : constant Entity_Id := Current_Entity_In_Scope (E); Decl : constant Node_Id := Unit_Declaration_Node (Candidate); begin if Is_Overloadable (Candidate) and then Ekind (Candidate) = Ekind (E) and then Nkind (Decl) = N_Subprogram_Body and then Acts_As_Spec (Decl) then Check_Type_Conformant (Candidate, E); else Missing_Body; end if; end; else Missing_Body; end if; end if; end if; end Post_Error; -- Local variables Pack_Id : constant Entity_Id := Current_Scope; -- Start of processing for Check_Completion begin E := First_Entity (Pack_Id); while Present (E) loop if Is_Intrinsic_Subprogram (E) then null; -- The following situation requires special handling: a child unit -- that appears in the context clause of the body of its parent: -- procedure Parent.Child (...); -- with Parent.Child; -- package body Parent is -- Here Parent.Child appears as a local entity, but should not be -- flagged as requiring completion, because it is a compilation -- unit. -- Ignore missing completion for a subprogram that does not come from -- source (including the _Call primitive operation of RAS types, -- which has to have the flag Comes_From_Source for other purposes): -- we assume that the expander will provide the missing completion. -- In case of previous errors, other expansion actions that provide -- bodies for null procedures with not be invoked, so inhibit message -- in those cases. -- Note that E_Operator is not in the list that follows, because -- this kind is reserved for predefined operators, that are -- intrinsic and do not need completion. elsif Ekind_In (E, E_Function, E_Procedure, E_Generic_Function, E_Generic_Procedure) then if Has_Completion (E) then null; elsif Is_Subprogram (E) and then Is_Abstract_Subprogram (E) then null; elsif Is_Subprogram (E) and then (not Comes_From_Source (E) or else Chars (E) = Name_uCall) then null; elsif Nkind (Parent (Unit_Declaration_Node (E))) = N_Compilation_Unit then null; elsif Nkind (Parent (E)) = N_Procedure_Specification and then Null_Present (Parent (E)) and then Serious_Errors_Detected > 0 then null; else Post_Error; end if; elsif Is_Entry (E) then if not Has_Completion (E) and then (Ekind (Scope (E)) = E_Protected_Object or else Ekind (Scope (E)) = E_Protected_Type) then Post_Error; end if; elsif Is_Package_Or_Generic_Package (E) then if Unit_Requires_Body (E) then if not Has_Completion (E) and then Nkind (Parent (Unit_Declaration_Node (E))) /= N_Compilation_Unit then Post_Error; end if; elsif not Is_Child_Unit (E) then May_Need_Implicit_Body (E); end if; -- A formal incomplete type (Ada 2012) does not require a completion; -- other incomplete type declarations do. elsif Ekind (E) = E_Incomplete_Type and then No (Underlying_Type (E)) and then not Is_Generic_Type (E) then Post_Error; elsif Ekind_In (E, E_Task_Type, E_Protected_Type) and then not Has_Completion (E) then Post_Error; -- A single task declared in the current scope is a constant, verify -- that the body of its anonymous type is in the same scope. If the -- task is defined elsewhere, this may be a renaming declaration for -- which no completion is needed. elsif Ekind (E) = E_Constant and then Ekind (Etype (E)) = E_Task_Type and then not Has_Completion (Etype (E)) and then Scope (Etype (E)) = Current_Scope then Post_Error; elsif Ekind (E) = E_Protected_Object and then not Has_Completion (Etype (E)) then Post_Error; elsif Ekind (E) = E_Record_Type then if Is_Tagged_Type (E) then Check_Abstract_Overriding (E); Check_Conventions (E); end if; Check_Aliased_Component_Types (E); elsif Ekind (E) = E_Array_Type then Check_Aliased_Component_Types (E); end if; Next_Entity (E); end loop; end Check_Completion; ------------------------------------ -- Check_CPP_Type_Has_No_Defaults -- ------------------------------------ procedure Check_CPP_Type_Has_No_Defaults (T : Entity_Id) is Tdef : constant Node_Id := Type_Definition (Declaration_Node (T)); Clist : Node_Id; Comp : Node_Id; begin -- Obtain the component list if Nkind (Tdef) = N_Record_Definition then Clist := Component_List (Tdef); else pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition); Clist := Component_List (Record_Extension_Part (Tdef)); end if; -- Check all components to ensure no default expressions if Present (Clist) then Comp := First (Component_Items (Clist)); while Present (Comp) loop if Present (Expression (Comp)) then Error_Msg_N ("component of imported 'C'P'P type cannot have " & "default expression", Expression (Comp)); end if; Next (Comp); end loop; end if; end Check_CPP_Type_Has_No_Defaults; ---------------------------- -- Check_Delta_Expression -- ---------------------------- procedure Check_Delta_Expression (E : Node_Id) is begin if not (Is_Real_Type (Etype (E))) then Wrong_Type (E, Any_Real); elsif not Is_OK_Static_Expression (E) then Flag_Non_Static_Expr ("non-static expression used for delta value!", E); elsif not UR_Is_Positive (Expr_Value_R (E)) then Error_Msg_N ("delta expression must be positive", E); else return; end if; -- If any of above errors occurred, then replace the incorrect -- expression by the real 0.1, which should prevent further errors. Rewrite (E, Make_Real_Literal (Sloc (E), Ureal_Tenth)); Analyze_And_Resolve (E, Standard_Float); end Check_Delta_Expression; ----------------------------- -- Check_Digits_Expression -- ----------------------------- procedure Check_Digits_Expression (E : Node_Id) is begin if not (Is_Integer_Type (Etype (E))) then Wrong_Type (E, Any_Integer); elsif not Is_OK_Static_Expression (E) then Flag_Non_Static_Expr ("non-static expression used for digits value!", E); elsif Expr_Value (E) <= 0 then Error_Msg_N ("digits value must be greater than zero", E); else return; end if; -- If any of above errors occurred, then replace the incorrect -- expression by the integer 1, which should prevent further errors. Rewrite (E, Make_Integer_Literal (Sloc (E), 1)); Analyze_And_Resolve (E, Standard_Integer); end Check_Digits_Expression; -------------------------- -- Check_Initialization -- -------------------------- procedure Check_Initialization (T : Entity_Id; Exp : Node_Id) is begin -- Special processing for limited types if Is_Limited_Type (T) and then not In_Instance and then not In_Inlined_Body then if not OK_For_Limited_Init (T, Exp) then -- In GNAT mode, this is just a warning, to allow it to be evilly -- turned off. Otherwise it is a real error. if GNAT_Mode then Error_Msg_N ("??cannot initialize entities of limited type!", Exp); elsif Ada_Version < Ada_2005 then -- The side effect removal machinery may generate illegal Ada -- code to avoid the usage of access types and 'reference in -- SPARK mode. Since this is legal code with respect to theorem -- proving, do not emit the error. if GNATprove_Mode and then Nkind (Exp) = N_Function_Call and then Nkind (Parent (Exp)) = N_Object_Declaration and then not Comes_From_Source (Defining_Identifier (Parent (Exp))) then null; else Error_Msg_N ("cannot initialize entities of limited type", Exp); Explain_Limited_Type (T, Exp); end if; else -- Specialize error message according to kind of illegal -- initial expression. if Nkind (Exp) = N_Type_Conversion and then Nkind (Expression (Exp)) = N_Function_Call then Error_Msg_N ("illegal context for call" & " to function with limited result", Exp); else Error_Msg_N ("initialization of limited object requires aggregate " & "or function call", Exp); end if; end if; end if; end if; -- In gnatc or gnatprove mode, make sure set Do_Range_Check flag gets -- set unless we can be sure that no range check is required. if (GNATprove_Mode or not Expander_Active) and then Is_Scalar_Type (T) and then not Is_In_Range (Exp, T, Assume_Valid => True) then Set_Do_Range_Check (Exp); end if; end Check_Initialization; ---------------------- -- Check_Interfaces -- ---------------------- procedure Check_Interfaces (N : Node_Id; Def : Node_Id) is Parent_Type : constant Entity_Id := Etype (Defining_Identifier (N)); Iface : Node_Id; Iface_Def : Node_Id; Iface_Typ : Entity_Id; Parent_Node : Node_Id; Is_Task : Boolean := False; -- Set True if parent type or any progenitor is a task interface Is_Protected : Boolean := False; -- Set True if parent type or any progenitor is a protected interface procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id); -- Check that a progenitor is compatible with declaration. If an error -- message is output, it is posted on Error_Node. ------------------ -- Check_Ifaces -- ------------------ procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id) is Iface_Id : constant Entity_Id := Defining_Identifier (Parent (Iface_Def)); Type_Def : Node_Id; begin if Nkind (N) = N_Private_Extension_Declaration then Type_Def := N; else Type_Def := Type_Definition (N); end if; if Is_Task_Interface (Iface_Id) then Is_Task := True; elsif Is_Protected_Interface (Iface_Id) then Is_Protected := True; end if; if Is_Synchronized_Interface (Iface_Id) then -- A consequence of 3.9.4 (6/2) and 7.3 (7.2/2) is that a private -- extension derived from a synchronized interface must explicitly -- be declared synchronized, because the full view will be a -- synchronized type. if Nkind (N) = N_Private_Extension_Declaration then if not Synchronized_Present (N) then Error_Msg_NE ("private extension of& must be explicitly synchronized", N, Iface_Id); end if; -- However, by 3.9.4(16/2), a full type that is a record extension -- is never allowed to derive from a synchronized interface (note -- that interfaces must be excluded from this check, because those -- are represented by derived type definitions in some cases). elsif Nkind (Type_Definition (N)) = N_Derived_Type_Definition and then not Interface_Present (Type_Definition (N)) then Error_Msg_N ("record extension cannot derive from synchronized " & "interface", Error_Node); end if; end if; -- Check that the characteristics of the progenitor are compatible -- with the explicit qualifier in the declaration. -- The check only applies to qualifiers that come from source. -- Limited_Present also appears in the declaration of corresponding -- records, and the check does not apply to them. if Limited_Present (Type_Def) and then not Is_Concurrent_Record_Type (Defining_Identifier (N)) then if Is_Limited_Interface (Parent_Type) and then not Is_Limited_Interface (Iface_Id) then Error_Msg_NE ("progenitor & must be limited interface", Error_Node, Iface_Id); elsif (Task_Present (Iface_Def) or else Protected_Present (Iface_Def) or else Synchronized_Present (Iface_Def)) and then Nkind (N) /= N_Private_Extension_Declaration and then not Error_Posted (N) then Error_Msg_NE ("progenitor & must be limited interface", Error_Node, Iface_Id); end if; -- Protected interfaces can only inherit from limited, synchronized -- or protected interfaces. elsif Nkind (N) = N_Full_Type_Declaration and then Protected_Present (Type_Def) then if Limited_Present (Iface_Def) or else Synchronized_Present (Iface_Def) or else Protected_Present (Iface_Def) then null; elsif Task_Present (Iface_Def) then Error_Msg_N ("(Ada 2005) protected interface cannot inherit " & "from task interface", Error_Node); else Error_Msg_N ("(Ada 2005) protected interface cannot inherit " & "from non-limited interface", Error_Node); end if; -- Ada 2005 (AI-345): Synchronized interfaces can only inherit from -- limited and synchronized. elsif Synchronized_Present (Type_Def) then if Limited_Present (Iface_Def) or else Synchronized_Present (Iface_Def) then null; elsif Protected_Present (Iface_Def) and then Nkind (N) /= N_Private_Extension_Declaration then Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit " & "from protected interface", Error_Node); elsif Task_Present (Iface_Def) and then Nkind (N) /= N_Private_Extension_Declaration then Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit " & "from task interface", Error_Node); elsif not Is_Limited_Interface (Iface_Id) then Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit " & "from non-limited interface", Error_Node); end if; -- Ada 2005 (AI-345): Task interfaces can only inherit from limited, -- synchronized or task interfaces. elsif Nkind (N) = N_Full_Type_Declaration and then Task_Present (Type_Def) then if Limited_Present (Iface_Def) or else Synchronized_Present (Iface_Def) or else Task_Present (Iface_Def) then null; elsif Protected_Present (Iface_Def) then Error_Msg_N ("(Ada 2005) task interface cannot inherit from " & "protected interface", Error_Node); else Error_Msg_N ("(Ada 2005) task interface cannot inherit from " & "non-limited interface", Error_Node); end if; end if; end Check_Ifaces; -- Start of processing for Check_Interfaces begin if Is_Interface (Parent_Type) then if Is_Task_Interface (Parent_Type) then Is_Task := True; elsif Is_Protected_Interface (Parent_Type) then Is_Protected := True; end if; end if; if Nkind (N) = N_Private_Extension_Declaration then -- Check that progenitors are compatible with declaration Iface := First (Interface_List (Def)); while Present (Iface) loop Iface_Typ := Find_Type_Of_Subtype_Indic (Iface); Parent_Node := Parent (Base_Type (Iface_Typ)); Iface_Def := Type_Definition (Parent_Node); if not Is_Interface (Iface_Typ) then Diagnose_Interface (Iface, Iface_Typ); else Check_Ifaces (Iface_Def, Iface); end if; Next (Iface); end loop; if Is_Task and Is_Protected then Error_Msg_N ("type cannot derive from task and protected interface", N); end if; return; end if; -- Full type declaration of derived type. -- Check compatibility with parent if it is interface type if Nkind (Type_Definition (N)) = N_Derived_Type_Definition and then Is_Interface (Parent_Type) then Parent_Node := Parent (Parent_Type); -- More detailed checks for interface varieties Check_Ifaces (Iface_Def => Type_Definition (Parent_Node), Error_Node => Subtype_Indication (Type_Definition (N))); end if; Iface := First (Interface_List (Def)); while Present (Iface) loop Iface_Typ := Find_Type_Of_Subtype_Indic (Iface); Parent_Node := Parent (Base_Type (Iface_Typ)); Iface_Def := Type_Definition (Parent_Node); if not Is_Interface (Iface_Typ) then Diagnose_Interface (Iface, Iface_Typ); else -- "The declaration of a specific descendant of an interface -- type freezes the interface type" RM 13.14 Freeze_Before (N, Iface_Typ); Check_Ifaces (Iface_Def, Error_Node => Iface); end if; Next (Iface); end loop; if Is_Task and Is_Protected then Error_Msg_N ("type cannot derive from task and protected interface", N); end if; end Check_Interfaces; ------------------------------------ -- Check_Or_Process_Discriminants -- ------------------------------------ -- If an incomplete or private type declaration was already given for the -- type, the discriminants may have already been processed if they were -- present on the incomplete declaration. In this case a full conformance -- check has been performed in Find_Type_Name, and we then recheck here -- some properties that can't be checked on the partial view alone. -- Otherwise we call Process_Discriminants. procedure Check_Or_Process_Discriminants (N : Node_Id; T : Entity_Id; Prev : Entity_Id := Empty) is begin if Has_Discriminants (T) then -- Discriminants are already set on T if they were already present -- on the partial view. Make them visible to component declarations. declare D : Entity_Id; -- Discriminant on T (full view) referencing expr on partial view Prev_D : Entity_Id; -- Entity of corresponding discriminant on partial view New_D : Node_Id; -- Discriminant specification for full view, expression is -- the syntactic copy on full view (which has been checked for -- conformance with partial view), only used here to post error -- message. begin D := First_Discriminant (T); New_D := First (Discriminant_Specifications (N)); while Present (D) loop Prev_D := Current_Entity (D); Set_Current_Entity (D); Set_Is_Immediately_Visible (D); Set_Homonym (D, Prev_D); -- Handle the case where there is an untagged partial view and -- the full view is tagged: must disallow discriminants with -- defaults, unless compiling for Ada 2012, which allows a -- limited tagged type to have defaulted discriminants (see -- AI05-0214). However, suppress error here if it was already -- reported on the default expression of the partial view. if Is_Tagged_Type (T) and then Present (Expression (Parent (D))) and then (not Is_Limited_Type (Current_Scope) or else Ada_Version < Ada_2012) and then not Error_Posted (Expression (Parent (D))) then if Ada_Version >= Ada_2012 then Error_Msg_N ("discriminants of nonlimited tagged type cannot have " & "defaults", Expression (New_D)); else Error_Msg_N ("discriminants of tagged type cannot have defaults", Expression (New_D)); end if; end if; -- Ada 2005 (AI-230): Access discriminant allowed in -- non-limited record types. if Ada_Version < Ada_2005 then -- This restriction gets applied to the full type here. It -- has already been applied earlier to the partial view. Check_Access_Discriminant_Requires_Limited (Parent (D), N); end if; Next_Discriminant (D); Next (New_D); end loop; end; elsif Present (Discriminant_Specifications (N)) then Process_Discriminants (N, Prev); end if; end Check_Or_Process_Discriminants; ---------------------- -- Check_Real_Bound -- ---------------------- procedure Check_Real_Bound (Bound : Node_Id) is begin if not Is_Real_Type (Etype (Bound)) then Error_Msg_N ("bound in real type definition must be of real type", Bound); elsif not Is_OK_Static_Expression (Bound) then Flag_Non_Static_Expr ("non-static expression used for real type bound!", Bound); else return; end if; Rewrite (Bound, Make_Real_Literal (Sloc (Bound), Ureal_0)); Analyze (Bound); Resolve (Bound, Standard_Float); end Check_Real_Bound; ------------------------------ -- Complete_Private_Subtype -- ------------------------------ procedure Complete_Private_Subtype (Priv : Entity_Id; Full : Entity_Id; Full_Base : Entity_Id; Related_Nod : Node_Id) is Save_Next_Entity : Entity_Id; Save_Homonym : Entity_Id; begin -- Set semantic attributes for (implicit) private subtype completion. -- If the full type has no discriminants, then it is a copy of the -- full view of the base. Otherwise, it is a subtype of the base with -- a possible discriminant constraint. Save and restore the original -- Next_Entity field of full to ensure that the calls to Copy_Node do -- not corrupt the entity chain. -- Note that the type of the full view is the same entity as the type -- of the partial view. In this fashion, the subtype has access to the -- correct view of the parent. Save_Next_Entity := Next_Entity (Full); Save_Homonym := Homonym (Priv); case Ekind (Full_Base) is when Class_Wide_Kind | Private_Kind | Protected_Kind | Task_Kind | E_Record_Subtype | E_Record_Type => Copy_Node (Priv, Full); Set_Has_Discriminants (Full, Has_Discriminants (Full_Base)); Set_Has_Unknown_Discriminants (Full, Has_Unknown_Discriminants (Full_Base)); Set_First_Entity (Full, First_Entity (Full_Base)); Set_Last_Entity (Full, Last_Entity (Full_Base)); -- If the underlying base type is constrained, we know that the -- full view of the subtype is constrained as well (the converse -- is not necessarily true). if Is_Constrained (Full_Base) then Set_Is_Constrained (Full); end if; when others => Copy_Node (Full_Base, Full); Set_Chars (Full, Chars (Priv)); Conditional_Delay (Full, Priv); Set_Sloc (Full, Sloc (Priv)); end case; Set_Next_Entity (Full, Save_Next_Entity); Set_Homonym (Full, Save_Homonym); Set_Associated_Node_For_Itype (Full, Related_Nod); -- Set common attributes for all subtypes: kind, convention, etc. Set_Ekind (Full, Subtype_Kind (Ekind (Full_Base))); Set_Convention (Full, Convention (Full_Base)); -- The Etype of the full view is inconsistent. Gigi needs to see the -- structural full view, which is what the current scheme gives: the -- Etype of the full view is the etype of the full base. However, if the -- full base is a derived type, the full view then looks like a subtype -- of the parent, not a subtype of the full base. If instead we write: -- Set_Etype (Full, Full_Base); -- then we get inconsistencies in the front-end (confusion between -- views). Several outstanding bugs are related to this ??? Set_Is_First_Subtype (Full, False); Set_Scope (Full, Scope (Priv)); Set_Size_Info (Full, Full_Base); Set_RM_Size (Full, RM_Size (Full_Base)); Set_Is_Itype (Full); -- A subtype of a private-type-without-discriminants, whose full-view -- has discriminants with default expressions, is not constrained. if not Has_Discriminants (Priv) then Set_Is_Constrained (Full, Is_Constrained (Full_Base)); if Has_Discriminants (Full_Base) then Set_Discriminant_Constraint (Full, Discriminant_Constraint (Full_Base)); -- The partial view may have been indefinite, the full view -- might not be. Set_Has_Unknown_Discriminants (Full, Has_Unknown_Discriminants (Full_Base)); end if; end if; Set_First_Rep_Item (Full, First_Rep_Item (Full_Base)); Set_Depends_On_Private (Full, Has_Private_Component (Full)); -- Freeze the private subtype entity if its parent is delayed, and not -- already frozen. We skip this processing if the type is an anonymous -- subtype of a record component, or is the corresponding record of a -- protected type, since these are processed when the enclosing type -- is frozen. If the parent type is declared in a nested package then -- the freezing of the private and full views also happens later. if not Is_Type (Scope (Full)) then if Is_Itype (Priv) and then In_Same_Source_Unit (Full, Full_Base) and then Scope (Full_Base) /= Scope (Full) then Set_Has_Delayed_Freeze (Full); Set_Has_Delayed_Freeze (Priv); else Set_Has_Delayed_Freeze (Full, Has_Delayed_Freeze (Full_Base) and then not Is_Frozen (Full_Base)); end if; end if; Set_Freeze_Node (Full, Empty); Set_Is_Frozen (Full, False); Set_Full_View (Priv, Full); if Has_Discriminants (Full) then Set_Stored_Constraint_From_Discriminant_Constraint (Full); Set_Stored_Constraint (Priv, Stored_Constraint (Full)); if Has_Unknown_Discriminants (Full) then Set_Discriminant_Constraint (Full, No_Elist); end if; end if; if Ekind (Full_Base) = E_Record_Type and then Has_Discriminants (Full_Base) and then Has_Discriminants (Priv) -- might not, if errors and then not Has_Unknown_Discriminants (Priv) and then not Is_Empty_Elmt_List (Discriminant_Constraint (Priv)) then Create_Constrained_Components (Full, Related_Nod, Full_Base, Discriminant_Constraint (Priv)); -- If the full base is itself derived from private, build a congruent -- subtype of its underlying type, for use by the back end. For a -- constrained record component, the declaration cannot be placed on -- the component list, but it must nevertheless be built an analyzed, to -- supply enough information for Gigi to compute the size of component. elsif Ekind (Full_Base) in Private_Kind and then Is_Derived_Type (Full_Base) and then Has_Discriminants (Full_Base) and then (Ekind (Current_Scope) /= E_Record_Subtype) then if not Is_Itype (Priv) and then Nkind (Subtype_Indication (Parent (Priv))) = N_Subtype_Indication then Build_Underlying_Full_View (Parent (Priv), Full, Etype (Full_Base)); elsif Nkind (Related_Nod) = N_Component_Declaration then Build_Underlying_Full_View (Related_Nod, Full, Etype (Full_Base)); end if; elsif Is_Record_Type (Full_Base) then -- Show Full is simply a renaming of Full_Base Set_Cloned_Subtype (Full, Full_Base); end if; -- It is unsafe to share the bounds of a scalar type, because the Itype -- is elaborated on demand, and if a bound is non-static then different -- orders of elaboration in different units will lead to different -- external symbols. if Is_Scalar_Type (Full_Base) then Set_Scalar_Range (Full, Make_Range (Sloc (Related_Nod), Low_Bound => Duplicate_Subexpr_No_Checks (Type_Low_Bound (Full_Base)), High_Bound => Duplicate_Subexpr_No_Checks (Type_High_Bound (Full_Base)))); -- This completion inherits the bounds of the full parent, but if -- the parent is an unconstrained floating point type, so is the -- completion. if Is_Floating_Point_Type (Full_Base) then Set_Includes_Infinities (Scalar_Range (Full), Has_Infinities (Full_Base)); end if; end if; -- ??? It seems that a lot of fields are missing that should be copied -- from Full_Base to Full. Here are some that are introduced in a -- non-disruptive way but a cleanup is necessary. if Is_Tagged_Type (Full_Base) then Set_Is_Tagged_Type (Full); Set_Direct_Primitive_Operations (Full, Direct_Primitive_Operations (Full_Base)); Set_No_Tagged_Streams_Pragma (Full, No_Tagged_Streams_Pragma (Full_Base)); -- Inherit class_wide type of full_base in case the partial view was -- not tagged. Otherwise it has already been created when the private -- subtype was analyzed. if No (Class_Wide_Type (Full)) then Set_Class_Wide_Type (Full, Class_Wide_Type (Full_Base)); end if; -- If this is a subtype of a protected or task type, constrain its -- corresponding record, unless this is a subtype without constraints, -- i.e. a simple renaming as with an actual subtype in an instance. elsif Is_Concurrent_Type (Full_Base) then if Has_Discriminants (Full) and then Present (Corresponding_Record_Type (Full_Base)) and then not Is_Empty_Elmt_List (Discriminant_Constraint (Full)) then Set_Corresponding_Record_Type (Full, Constrain_Corresponding_Record (Full, Corresponding_Record_Type (Full_Base), Related_Nod)); else Set_Corresponding_Record_Type (Full, Corresponding_Record_Type (Full_Base)); end if; end if; -- Link rep item chain, and also setting of Has_Predicates from private -- subtype to full subtype, since we will need these on the full subtype -- to create the predicate function. Note that the full subtype may -- already have rep items, inherited from the full view of the base -- type, so we must be sure not to overwrite these entries. declare Append : Boolean; Item : Node_Id; Next_Item : Node_Id; Priv_Item : Node_Id; begin Item := First_Rep_Item (Full); Priv_Item := First_Rep_Item (Priv); -- If no existing rep items on full type, we can just link directly -- to the list of items on the private type, if any exist.. Same if -- the rep items are only those inherited from the base if (No (Item) or else Nkind (Item) /= N_Aspect_Specification or else Entity (Item) = Full_Base) and then Present (First_Rep_Item (Priv)) then Set_First_Rep_Item (Full, Priv_Item); -- Otherwise, search to the end of items currently linked to the full -- subtype and append the private items to the end. However, if Priv -- and Full already have the same list of rep items, then the append -- is not done, as that would create a circularity. -- -- The partial view may have a predicate and the rep item lists of -- both views agree when inherited from the same ancestor. In that -- case, simply propagate the list from one view to the other. -- A more complex analysis needed here ??? elsif Present (Priv_Item) and then Item = Next_Rep_Item (Priv_Item) then Set_First_Rep_Item (Full, Priv_Item); elsif Item /= Priv_Item then Append := True; loop Next_Item := Next_Rep_Item (Item); exit when No (Next_Item); Item := Next_Item; -- If the private view has aspect specifications, the full view -- inherits them. Since these aspects may already have been -- attached to the full view during derivation, do not append -- them if already present. if Item = First_Rep_Item (Priv) then Append := False; exit; end if; end loop; -- And link the private type items at the end of the chain if Append then Set_Next_Rep_Item (Item, First_Rep_Item (Priv)); end if; end if; end; -- Make sure Has_Predicates is set on full type if it is set on the -- private type. Note that it may already be set on the full type and -- if so, we don't want to unset it. Similarly, propagate information -- about delayed aspects, because the corresponding pragmas must be -- analyzed when one of the views is frozen. This last step is needed -- in particular when the full type is a scalar type for which an -- anonymous base type is constructed. -- The predicate functions are generated either at the freeze point -- of the type or at the end of the visible part, and we must avoid -- generating them twice. if Has_Predicates (Priv) then Set_Has_Predicates (Full); if Present (Predicate_Function (Priv)) and then No (Predicate_Function (Full)) then Set_Predicate_Function (Full, Predicate_Function (Priv)); end if; end if; if Has_Delayed_Aspects (Priv) then Set_Has_Delayed_Aspects (Full); end if; end Complete_Private_Subtype; ---------------------------- -- Constant_Redeclaration -- ---------------------------- procedure Constant_Redeclaration (Id : Entity_Id; N : Node_Id; T : out Entity_Id) is Prev : constant Entity_Id := Current_Entity_In_Scope (Id); Obj_Def : constant Node_Id := Object_Definition (N); New_T : Entity_Id; procedure Check_Possible_Deferred_Completion (Prev_Id : Entity_Id; Prev_Obj_Def : Node_Id; Curr_Obj_Def : Node_Id); -- Determine whether the two object definitions describe the partial -- and the full view of a constrained deferred constant. Generate -- a subtype for the full view and verify that it statically matches -- the subtype of the partial view. procedure Check_Recursive_Declaration (Typ : Entity_Id); -- If deferred constant is an access type initialized with an allocator, -- check whether there is an illegal recursion in the definition, -- through a default value of some record subcomponent. This is normally -- detected when generating init procs, but requires this additional -- mechanism when expansion is disabled. ---------------------------------------- -- Check_Possible_Deferred_Completion -- ---------------------------------------- procedure Check_Possible_Deferred_Completion (Prev_Id : Entity_Id; Prev_Obj_Def : Node_Id; Curr_Obj_Def : Node_Id) is begin if Nkind (Prev_Obj_Def) = N_Subtype_Indication and then Present (Constraint (Prev_Obj_Def)) and then Nkind (Curr_Obj_Def) = N_Subtype_Indication and then Present (Constraint (Curr_Obj_Def)) then declare Loc : constant Source_Ptr := Sloc (N); Def_Id : constant Entity_Id := Make_Temporary (Loc, 'S'); Decl : constant Node_Id := Make_Subtype_Declaration (Loc, Defining_Identifier => Def_Id, Subtype_Indication => Relocate_Node (Curr_Obj_Def)); begin Insert_Before_And_Analyze (N, Decl); Set_Etype (Id, Def_Id); if not Subtypes_Statically_Match (Etype (Prev_Id), Def_Id) then Error_Msg_Sloc := Sloc (Prev_Id); Error_Msg_N ("subtype does not statically match deferred " & "declaration #", N); end if; end; end if; end Check_Possible_Deferred_Completion; --------------------------------- -- Check_Recursive_Declaration -- --------------------------------- procedure Check_Recursive_Declaration (Typ : Entity_Id) is Comp : Entity_Id; begin if Is_Record_Type (Typ) then Comp := First_Component (Typ); while Present (Comp) loop if Comes_From_Source (Comp) then if Present (Expression (Parent (Comp))) and then Is_Entity_Name (Expression (Parent (Comp))) and then Entity (Expression (Parent (Comp))) = Prev then Error_Msg_Sloc := Sloc (Parent (Comp)); Error_Msg_NE ("illegal circularity with declaration for & #", N, Comp); return; elsif Is_Record_Type (Etype (Comp)) then Check_Recursive_Declaration (Etype (Comp)); end if; end if; Next_Component (Comp); end loop; end if; end Check_Recursive_Declaration; -- Start of processing for Constant_Redeclaration begin if Nkind (Parent (Prev)) = N_Object_Declaration then if Nkind (Object_Definition (Parent (Prev))) = N_Subtype_Indication then -- Find type of new declaration. The constraints of the two -- views must match statically, but there is no point in -- creating an itype for the full view. if Nkind (Obj_Def) = N_Subtype_Indication then Find_Type (Subtype_Mark (Obj_Def)); New_T := Entity (Subtype_Mark (Obj_Def)); else Find_Type (Obj_Def); New_T := Entity (Obj_Def); end if; T := Etype (Prev); else -- The full view may impose a constraint, even if the partial -- view does not, so construct the subtype. New_T := Find_Type_Of_Object (Obj_Def, N); T := New_T; end if; else -- Current declaration is illegal, diagnosed below in Enter_Name T := Empty; New_T := Any_Type; end if; -- If previous full declaration or a renaming declaration exists, or if -- a homograph is present, let Enter_Name handle it, either with an -- error or with the removal of an overridden implicit subprogram. -- The previous one is a full declaration if it has an expression -- (which in the case of an aggregate is indicated by the Init flag). if Ekind (Prev) /= E_Constant or else Nkind (Parent (Prev)) = N_Object_Renaming_Declaration or else Present (Expression (Parent (Prev))) or else Has_Init_Expression (Parent (Prev)) or else Present (Full_View (Prev)) then Enter_Name (Id); -- Verify that types of both declarations match, or else that both types -- are anonymous access types whose designated subtypes statically match -- (as allowed in Ada 2005 by AI-385). elsif Base_Type (Etype (Prev)) /= Base_Type (New_T) and then (Ekind (Etype (Prev)) /= E_Anonymous_Access_Type or else Ekind (Etype (New_T)) /= E_Anonymous_Access_Type or else Is_Access_Constant (Etype (New_T)) /= Is_Access_Constant (Etype (Prev)) or else Can_Never_Be_Null (Etype (New_T)) /= Can_Never_Be_Null (Etype (Prev)) or else Null_Exclusion_Present (Parent (Prev)) /= Null_Exclusion_Present (Parent (Id)) or else not Subtypes_Statically_Match (Designated_Type (Etype (Prev)), Designated_Type (Etype (New_T)))) then Error_Msg_Sloc := Sloc (Prev); Error_Msg_N ("type does not match declaration#", N); Set_Full_View (Prev, Id); Set_Etype (Id, Any_Type); -- A deferred constant whose type is an anonymous array is always -- illegal (unless imported). A detailed error message might be -- helpful for Ada beginners. if Nkind (Object_Definition (Parent (Prev))) = N_Constrained_Array_Definition and then Nkind (Object_Definition (N)) = N_Constrained_Array_Definition then Error_Msg_N ("\each anonymous array is a distinct type", N); Error_Msg_N ("a deferred constant must have a named type", Object_Definition (Parent (Prev))); end if; elsif Null_Exclusion_Present (Parent (Prev)) and then not Null_Exclusion_Present (N) then Error_Msg_Sloc := Sloc (Prev); Error_Msg_N ("null-exclusion does not match declaration#", N); Set_Full_View (Prev, Id); Set_Etype (Id, Any_Type); -- If so, process the full constant declaration else -- RM 7.4 (6): If the subtype defined by the subtype_indication in -- the deferred declaration is constrained, then the subtype defined -- by the subtype_indication in the full declaration shall match it -- statically. Check_Possible_Deferred_Completion (Prev_Id => Prev, Prev_Obj_Def => Object_Definition (Parent (Prev)), Curr_Obj_Def => Obj_Def); Set_Full_View (Prev, Id); Set_Is_Public (Id, Is_Public (Prev)); Set_Is_Internal (Id); Append_Entity (Id, Current_Scope); -- Check ALIASED present if present before (RM 7.4(7)) if Is_Aliased (Prev) and then not Aliased_Present (N) then Error_Msg_Sloc := Sloc (Prev); Error_Msg_N ("ALIASED required (see declaration #)", N); end if; -- Check that placement is in private part and that the incomplete -- declaration appeared in the visible part. if Ekind (Current_Scope) = E_Package and then not In_Private_Part (Current_Scope) then Error_Msg_Sloc := Sloc (Prev); Error_Msg_N ("full constant for declaration # must be in private part", N); elsif Ekind (Current_Scope) = E_Package and then List_Containing (Parent (Prev)) /= Visible_Declarations (Package_Specification (Current_Scope)) then Error_Msg_N ("deferred constant must be declared in visible part", Parent (Prev)); end if; if Is_Access_Type (T) and then Nkind (Expression (N)) = N_Allocator then Check_Recursive_Declaration (Designated_Type (T)); end if; -- A deferred constant is a visible entity. If type has invariants, -- verify that the initial value satisfies them. if Has_Invariants (T) and then Present (Invariant_Procedure (T)) then Insert_After (N, Make_Invariant_Call (New_Occurrence_Of (Prev, Sloc (N)))); end if; end if; end Constant_Redeclaration; ---------------------- -- Constrain_Access -- ---------------------- procedure Constrain_Access (Def_Id : in out Entity_Id; S : Node_Id; Related_Nod : Node_Id) is T : constant Entity_Id := Entity (Subtype_Mark (S)); Desig_Type : constant Entity_Id := Designated_Type (T); Desig_Subtype : Entity_Id := Create_Itype (E_Void, Related_Nod); Constraint_OK : Boolean := True; begin if Is_Array_Type (Desig_Type) then Constrain_Array (Desig_Subtype, S, Related_Nod, Def_Id, 'P'); elsif (Is_Record_Type (Desig_Type) or else Is_Incomplete_Or_Private_Type (Desig_Type)) and then not Is_Constrained (Desig_Type) then -- ??? The following code is a temporary bypass to ignore a -- discriminant constraint on access type if it is constraining -- the current record. Avoid creating the implicit subtype of the -- record we are currently compiling since right now, we cannot -- handle these. For now, just return the access type itself. if Desig_Type = Current_Scope and then No (Def_Id) then Set_Ekind (Desig_Subtype, E_Record_Subtype); Def_Id := Entity (Subtype_Mark (S)); -- This call added to ensure that the constraint is analyzed -- (needed for a B test). Note that we still return early from -- this procedure to avoid recursive processing. ??? Constrain_Discriminated_Type (Desig_Subtype, S, Related_Nod, For_Access => True); return; end if; -- Enforce rule that the constraint is illegal if there is an -- unconstrained view of the designated type. This means that the -- partial view (either a private type declaration or a derivation -- from a private type) has no discriminants. (Defect Report -- 8652/0008, Technical Corrigendum 1, checked by ACATS B371001). -- Rule updated for Ada 2005: The private type is said to have -- a constrained partial view, given that objects of the type -- can be declared. Furthermore, the rule applies to all access -- types, unlike the rule concerning default discriminants (see -- RM 3.7.1(7/3)) if (Ekind (T) = E_General_Access_Type or else Ada_Version >= Ada_2005) and then Has_Private_Declaration (Desig_Type) and then In_Open_Scopes (Scope (Desig_Type)) and then Has_Discriminants (Desig_Type) then declare Pack : constant Node_Id := Unit_Declaration_Node (Scope (Desig_Type)); Decls : List_Id; Decl : Node_Id; begin if Nkind (Pack) = N_Package_Declaration then Decls := Visible_Declarations (Specification (Pack)); Decl := First (Decls); while Present (Decl) loop if (Nkind (Decl) = N_Private_Type_Declaration and then Chars (Defining_Identifier (Decl)) = Chars (Desig_Type)) or else (Nkind (Decl) = N_Full_Type_Declaration and then Chars (Defining_Identifier (Decl)) = Chars (Desig_Type) and then Is_Derived_Type (Desig_Type) and then Has_Private_Declaration (Etype (Desig_Type))) then if No (Discriminant_Specifications (Decl)) then Error_Msg_N ("cannot constrain access type if designated " & "type has constrained partial view", S); end if; exit; end if; Next (Decl); end loop; end if; end; end if; Constrain_Discriminated_Type (Desig_Subtype, S, Related_Nod, For_Access => True); elsif Is_Concurrent_Type (Desig_Type) and then not Is_Constrained (Desig_Type) then Constrain_Concurrent (Desig_Subtype, S, Related_Nod, Desig_Type, ' '); else Error_Msg_N ("invalid constraint on access type", S); -- We simply ignore an invalid constraint Desig_Subtype := Desig_Type; Constraint_OK := False; end if; if No (Def_Id) then Def_Id := Create_Itype (E_Access_Subtype, Related_Nod); else Set_Ekind (Def_Id, E_Access_Subtype); end if; if Constraint_OK then Set_Etype (Def_Id, Base_Type (T)); if Is_Private_Type (Desig_Type) then Prepare_Private_Subtype_Completion (Desig_Subtype, Related_Nod); end if; else Set_Etype (Def_Id, Any_Type); end if; Set_Size_Info (Def_Id, T); Set_Is_Constrained (Def_Id, Constraint_OK); Set_Directly_Designated_Type (Def_Id, Desig_Subtype); Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id)); Set_Is_Access_Constant (Def_Id, Is_Access_Constant (T)); Conditional_Delay (Def_Id, T); -- AI-363 : Subtypes of general access types whose designated types have -- default discriminants are disallowed. In instances, the rule has to -- be checked against the actual, of which T is the subtype. In a -- generic body, the rule is checked assuming that the actual type has -- defaulted discriminants. if Ada_Version >= Ada_2005 or else Warn_On_Ada_2005_Compatibility then if Ekind (Base_Type (T)) = E_General_Access_Type and then Has_Defaulted_Discriminants (Desig_Type) then if Ada_Version < Ada_2005 then Error_Msg_N ("access subtype of general access type would not " & "be allowed in Ada 2005?y?", S); else Error_Msg_N ("access subtype of general access type not allowed", S); end if; Error_Msg_N ("\discriminants have defaults", S); elsif Is_Access_Type (T) and then Is_Generic_Type (Desig_Type) and then Has_Discriminants (Desig_Type) and then In_Package_Body (Current_Scope) then if Ada_Version < Ada_2005 then Error_Msg_N ("access subtype would not be allowed in generic body " & "in Ada 2005?y?", S); else Error_Msg_N ("access subtype not allowed in generic body", S); end if; Error_Msg_N ("\designated type is a discriminated formal", S); end if; end if; end Constrain_Access; --------------------- -- Constrain_Array -- --------------------- procedure Constrain_Array (Def_Id : in out Entity_Id; SI : Node_Id; Related_Nod : Node_Id; Related_Id : Entity_Id; Suffix : Character) is C : constant Node_Id := Constraint (SI); Number_Of_Constraints : Nat := 0; Index : Node_Id; S, T : Entity_Id; Constraint_OK : Boolean := True; begin T := Entity (Subtype_Mark (SI)); if Is_Access_Type (T) then T := Designated_Type (T); end if; -- If an index constraint follows a subtype mark in a subtype indication -- then the type or subtype denoted by the subtype mark must not already -- impose an index constraint. The subtype mark must denote either an -- unconstrained array type or an access type whose designated type -- is such an array type... (RM 3.6.1) if Is_Constrained (T) then Error_Msg_N ("array type is already constrained", Subtype_Mark (SI)); Constraint_OK := False; else S := First (Constraints (C)); while Present (S) loop Number_Of_Constraints := Number_Of_Constraints + 1; Next (S); end loop; -- In either case, the index constraint must provide a discrete -- range for each index of the array type and the type of each -- discrete range must be the same as that of the corresponding -- index. (RM 3.6.1) if Number_Of_Constraints /= Number_Dimensions (T) then Error_Msg_NE ("incorrect number of index constraints for }", C, T); Constraint_OK := False; else S := First (Constraints (C)); Index := First_Index (T); Analyze (Index); -- Apply constraints to each index type for J in 1 .. Number_Of_Constraints loop Constrain_Index (Index, S, Related_Nod, Related_Id, Suffix, J); Next (Index); Next (S); end loop; end if; end if; if No (Def_Id) then Def_Id := Create_Itype (E_Array_Subtype, Related_Nod, Related_Id, Suffix); Set_Parent (Def_Id, Related_Nod); else Set_Ekind (Def_Id, E_Array_Subtype); end if; Set_Size_Info (Def_Id, (T)); Set_First_Rep_Item (Def_Id, First_Rep_Item (T)); Set_Etype (Def_Id, Base_Type (T)); if Constraint_OK then Set_First_Index (Def_Id, First (Constraints (C))); else Set_First_Index (Def_Id, First_Index (T)); end if; Set_Is_Constrained (Def_Id, True); Set_Is_Aliased (Def_Id, Is_Aliased (T)); Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id)); Set_Is_Private_Composite (Def_Id, Is_Private_Composite (T)); Set_Is_Limited_Composite (Def_Id, Is_Limited_Composite (T)); -- A subtype does not inherit the Packed_Array_Impl_Type of is parent. -- We need to initialize the attribute because if Def_Id is previously -- analyzed through a limited_with clause, it will have the attributes -- of an incomplete type, one of which is an Elist that overlaps the -- Packed_Array_Impl_Type field. Set_Packed_Array_Impl_Type (Def_Id, Empty); -- Build a freeze node if parent still needs one. Also make sure that -- the Depends_On_Private status is set because the subtype will need -- reprocessing at the time the base type does, and also we must set a -- conditional delay. Set_Depends_On_Private (Def_Id, Depends_On_Private (T)); Conditional_Delay (Def_Id, T); end Constrain_Array; ------------------------------ -- Constrain_Component_Type -- ------------------------------ function Constrain_Component_Type (Comp : Entity_Id; Constrained_Typ : Entity_Id; Related_Node : Node_Id; Typ : Entity_Id; Constraints : Elist_Id) return Entity_Id is Loc : constant Source_Ptr := Sloc (Constrained_Typ); Compon_Type : constant Entity_Id := Etype (Comp); function Build_Constrained_Array_Type (Old_Type : Entity_Id) return Entity_Id; -- If Old_Type is an array type, one of whose indexes is constrained -- by a discriminant, build an Itype whose constraint replaces the -- discriminant with its value in the constraint. function Build_Constrained_Discriminated_Type (Old_Type : Entity_Id) return Entity_Id; -- Ditto for record components function Build_Constrained_Access_Type (Old_Type : Entity_Id) return Entity_Id; -- Ditto for access types. Makes use of previous two functions, to -- constrain designated type. function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id; -- T is an array or discriminated type, C is a list of constraints -- that apply to T. This routine builds the constrained subtype. function Is_Discriminant (Expr : Node_Id) return Boolean; -- Returns True if Expr is a discriminant function Get_Discr_Value (Discrim : Entity_Id) return Node_Id; -- Find the value of discriminant Discrim in Constraint ----------------------------------- -- Build_Constrained_Access_Type -- ----------------------------------- function Build_Constrained_Access_Type (Old_Type : Entity_Id) return Entity_Id is Desig_Type : constant Entity_Id := Designated_Type (Old_Type); Itype : Entity_Id; Desig_Subtype : Entity_Id; Scop : Entity_Id; begin -- if the original access type was not embedded in the enclosing -- type definition, there is no need to produce a new access -- subtype. In fact every access type with an explicit constraint -- generates an itype whose scope is the enclosing record. if not Is_Type (Scope (Old_Type)) then return Old_Type; elsif Is_Array_Type (Desig_Type) then Desig_Subtype := Build_Constrained_Array_Type (Desig_Type); elsif Has_Discriminants (Desig_Type) then -- This may be an access type to an enclosing record type for -- which we are constructing the constrained components. Return -- the enclosing record subtype. This is not always correct, -- but avoids infinite recursion. ??? Desig_Subtype := Any_Type; for J in reverse 0 .. Scope_Stack.Last loop Scop := Scope_Stack.Table (J).Entity; if Is_Type (Scop) and then Base_Type (Scop) = Base_Type (Desig_Type) then Desig_Subtype := Scop; end if; exit when not Is_Type (Scop); end loop; if Desig_Subtype = Any_Type then Desig_Subtype := Build_Constrained_Discriminated_Type (Desig_Type); end if; else return Old_Type; end if; if Desig_Subtype /= Desig_Type then -- The Related_Node better be here or else we won't be able -- to attach new itypes to a node in the tree. pragma Assert (Present (Related_Node)); Itype := Create_Itype (E_Access_Subtype, Related_Node); Set_Etype (Itype, Base_Type (Old_Type)); Set_Size_Info (Itype, (Old_Type)); Set_Directly_Designated_Type (Itype, Desig_Subtype); Set_Depends_On_Private (Itype, Has_Private_Component (Old_Type)); Set_Is_Access_Constant (Itype, Is_Access_Constant (Old_Type)); -- The new itype needs freezing when it depends on a not frozen -- type and the enclosing subtype needs freezing. if Has_Delayed_Freeze (Constrained_Typ) and then not Is_Frozen (Constrained_Typ) then Conditional_Delay (Itype, Base_Type (Old_Type)); end if; return Itype; else return Old_Type; end if; end Build_Constrained_Access_Type; ---------------------------------- -- Build_Constrained_Array_Type -- ---------------------------------- function Build_Constrained_Array_Type (Old_Type : Entity_Id) return Entity_Id is Lo_Expr : Node_Id; Hi_Expr : Node_Id; Old_Index : Node_Id; Range_Node : Node_Id; Constr_List : List_Id; Need_To_Create_Itype : Boolean := False; begin Old_Index := First_Index (Old_Type); while Present (Old_Index) loop Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr); if Is_Discriminant (Lo_Expr) or else Is_Discriminant (Hi_Expr) then Need_To_Create_Itype := True; end if; Next_Index (Old_Index); end loop; if Need_To_Create_Itype then Constr_List := New_List; Old_Index := First_Index (Old_Type); while Present (Old_Index) loop Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr); if Is_Discriminant (Lo_Expr) then Lo_Expr := Get_Discr_Value (Lo_Expr); end if; if Is_Discriminant (Hi_Expr) then Hi_Expr := Get_Discr_Value (Hi_Expr); end if; Range_Node := Make_Range (Loc, New_Copy_Tree (Lo_Expr), New_Copy_Tree (Hi_Expr)); Append (Range_Node, To => Constr_List); Next_Index (Old_Index); end loop; return Build_Subtype (Old_Type, Constr_List); else return Old_Type; end if; end Build_Constrained_Array_Type; ------------------------------------------ -- Build_Constrained_Discriminated_Type -- ------------------------------------------ function Build_Constrained_Discriminated_Type (Old_Type : Entity_Id) return Entity_Id is Expr : Node_Id; Constr_List : List_Id; Old_Constraint : Elmt_Id; Need_To_Create_Itype : Boolean := False; begin Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type)); while Present (Old_Constraint) loop Expr := Node (Old_Constraint); if Is_Discriminant (Expr) then Need_To_Create_Itype := True; end if; Next_Elmt (Old_Constraint); end loop; if Need_To_Create_Itype then Constr_List := New_List; Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type)); while Present (Old_Constraint) loop Expr := Node (Old_Constraint); if Is_Discriminant (Expr) then Expr := Get_Discr_Value (Expr); end if; Append (New_Copy_Tree (Expr), To => Constr_List); Next_Elmt (Old_Constraint); end loop; return Build_Subtype (Old_Type, Constr_List); else return Old_Type; end if; end Build_Constrained_Discriminated_Type; ------------------- -- Build_Subtype -- ------------------- function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id is Indic : Node_Id; Subtyp_Decl : Node_Id; Def_Id : Entity_Id; Btyp : Entity_Id := Base_Type (T); begin -- The Related_Node better be here or else we won't be able to -- attach new itypes to a node in the tree. pragma Assert (Present (Related_Node)); -- If the view of the component's type is incomplete or private -- with unknown discriminants, then the constraint must be applied -- to the full type. if Has_Unknown_Discriminants (Btyp) and then Present (Underlying_Type (Btyp)) then Btyp := Underlying_Type (Btyp); end if; Indic := Make_Subtype_Indication (Loc, Subtype_Mark => New_Occurrence_Of (Btyp, Loc), Constraint => Make_Index_Or_Discriminant_Constraint (Loc, C)); Def_Id := Create_Itype (Ekind (T), Related_Node); Subtyp_Decl := Make_Subtype_Declaration (Loc, Defining_Identifier => Def_Id, Subtype_Indication => Indic); Set_Parent (Subtyp_Decl, Parent (Related_Node)); -- Itypes must be analyzed with checks off (see package Itypes) Analyze (Subtyp_Decl, Suppress => All_Checks); return Def_Id; end Build_Subtype; --------------------- -- Get_Discr_Value -- --------------------- function Get_Discr_Value (Discrim : Entity_Id) return Node_Id is D : Entity_Id; E : Elmt_Id; begin -- The discriminant may be declared for the type, in which case we -- find it by iterating over the list of discriminants. If the -- discriminant is inherited from a parent type, it appears as the -- corresponding discriminant of the current type. This will be the -- case when constraining an inherited component whose constraint is -- given by a discriminant of the parent. D := First_Discriminant (Typ); E := First_Elmt (Constraints); while Present (D) loop if D = Entity (Discrim) or else D = CR_Discriminant (Entity (Discrim)) or else Corresponding_Discriminant (D) = Entity (Discrim) then return Node (E); end if; Next_Discriminant (D); Next_Elmt (E); end loop; -- The Corresponding_Discriminant mechanism is incomplete, because -- the correspondence between new and old discriminants is not one -- to one: one new discriminant can constrain several old ones. In -- that case, scan sequentially the stored_constraint, the list of -- discriminants of the parents, and the constraints. -- Previous code checked for the present of the Stored_Constraint -- list for the derived type, but did not use it at all. Should it -- be present when the component is a discriminated task type? if Is_Derived_Type (Typ) and then Scope (Entity (Discrim)) = Etype (Typ) then D := First_Discriminant (Etype (Typ)); E := First_Elmt (Constraints); while Present (D) loop if D = Entity (Discrim) then return Node (E); end if; Next_Discriminant (D); Next_Elmt (E); end loop; end if; -- Something is wrong if we did not find the value raise Program_Error; end Get_Discr_Value; --------------------- -- Is_Discriminant -- --------------------- function Is_Discriminant (Expr : Node_Id) return Boolean is Discrim_Scope : Entity_Id; begin if Denotes_Discriminant (Expr) then Discrim_Scope := Scope (Entity (Expr)); -- Either we have a reference to one of Typ's discriminants, pragma Assert (Discrim_Scope = Typ -- or to the discriminants of the parent type, in the case -- of a derivation of a tagged type with variants. or else Discrim_Scope = Etype (Typ) or else Full_View (Discrim_Scope) = Etype (Typ) -- or same as above for the case where the discriminants -- were declared in Typ's private view. or else (Is_Private_Type (Discrim_Scope) and then Chars (Discrim_Scope) = Chars (Typ)) -- or else we are deriving from the full view and the -- discriminant is declared in the private entity. or else (Is_Private_Type (Typ) and then Chars (Discrim_Scope) = Chars (Typ)) -- Or we are constrained the corresponding record of a -- synchronized type that completes a private declaration. or else (Is_Concurrent_Record_Type (Typ) and then Corresponding_Concurrent_Type (Typ) = Discrim_Scope) -- or we have a class-wide type, in which case make sure the -- discriminant found belongs to the root type. or else (Is_Class_Wide_Type (Typ) and then Etype (Typ) = Discrim_Scope)); return True; end if; -- In all other cases we have something wrong return False; end Is_Discriminant; -- Start of processing for Constrain_Component_Type begin if Nkind (Parent (Comp)) = N_Component_Declaration and then Comes_From_Source (Parent (Comp)) and then Comes_From_Source (Subtype_Indication (Component_Definition (Parent (Comp)))) and then Is_Entity_Name (Subtype_Indication (Component_Definition (Parent (Comp)))) then return Compon_Type; elsif Is_Array_Type (Compon_Type) then return Build_Constrained_Array_Type (Compon_Type); elsif Has_Discriminants (Compon_Type) then return Build_Constrained_Discriminated_Type (Compon_Type); elsif Is_Access_Type (Compon_Type) then return Build_Constrained_Access_Type (Compon_Type); else return Compon_Type; end if; end Constrain_Component_Type; -------------------------- -- Constrain_Concurrent -- -------------------------- -- For concurrent types, the associated record value type carries the same -- discriminants, so when we constrain a concurrent type, we must constrain -- the corresponding record type as well. procedure Constrain_Concurrent (Def_Id : in out Entity_Id; SI : Node_Id; Related_Nod : Node_Id; Related_Id : Entity_Id; Suffix : Character) is -- Retrieve Base_Type to ensure getting to the concurrent type in the -- case of a private subtype (needed when only doing semantic analysis). T_Ent : Entity_Id := Base_Type (Entity (Subtype_Mark (SI))); T_Val : Entity_Id; begin if Is_Access_Type (T_Ent) then T_Ent := Designated_Type (T_Ent); end if; T_Val := Corresponding_Record_Type (T_Ent); if Present (T_Val) then if No (Def_Id) then Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix); -- Elaborate itype now, as it may be used in a subsequent -- synchronized operation in another scope. if Nkind (Related_Nod) = N_Full_Type_Declaration then Build_Itype_Reference (Def_Id, Related_Nod); end if; end if; Constrain_Discriminated_Type (Def_Id, SI, Related_Nod); Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id)); Set_Corresponding_Record_Type (Def_Id, Constrain_Corresponding_Record (Def_Id, T_Val, Related_Nod)); else -- If there is no associated record, expansion is disabled and this -- is a generic context. Create a subtype in any case, so that -- semantic analysis can proceed. if No (Def_Id) then Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix); end if; Constrain_Discriminated_Type (Def_Id, SI, Related_Nod); end if; end Constrain_Concurrent; ------------------------------------ -- Constrain_Corresponding_Record -- ------------------------------------ function Constrain_Corresponding_Record (Prot_Subt : Entity_Id; Corr_Rec : Entity_Id; Related_Nod : Node_Id) return Entity_Id is T_Sub : constant Entity_Id := Create_Itype (E_Record_Subtype, Related_Nod, Corr_Rec, 'C'); begin Set_Etype (T_Sub, Corr_Rec); Set_Has_Discriminants (T_Sub, Has_Discriminants (Prot_Subt)); Set_Is_Constrained (T_Sub, True); Set_First_Entity (T_Sub, First_Entity (Corr_Rec)); Set_Last_Entity (T_Sub, Last_Entity (Corr_Rec)); if Has_Discriminants (Prot_Subt) then -- False only if errors. Set_Discriminant_Constraint (T_Sub, Discriminant_Constraint (Prot_Subt)); Set_Stored_Constraint_From_Discriminant_Constraint (T_Sub); Create_Constrained_Components (T_Sub, Related_Nod, Corr_Rec, Discriminant_Constraint (T_Sub)); end if; Set_Depends_On_Private (T_Sub, Has_Private_Component (T_Sub)); if Ekind (Scope (Prot_Subt)) /= E_Record_Type then Conditional_Delay (T_Sub, Corr_Rec); else -- This is a component subtype: it will be frozen in the context of -- the enclosing record's init_proc, so that discriminant references -- are resolved to discriminals. (Note: we used to skip freezing -- altogether in that case, which caused errors downstream for -- components of a bit packed array type). Set_Has_Delayed_Freeze (T_Sub); end if; return T_Sub; end Constrain_Corresponding_Record; ----------------------- -- Constrain_Decimal -- ----------------------- procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id) is T : constant Entity_Id := Entity (Subtype_Mark (S)); C : constant Node_Id := Constraint (S); Loc : constant Source_Ptr := Sloc (C); Range_Expr : Node_Id; Digits_Expr : Node_Id; Digits_Val : Uint; Bound_Val : Ureal; begin Set_Ekind (Def_Id, E_Decimal_Fixed_Point_Subtype); if Nkind (C) = N_Range_Constraint then Range_Expr := Range_Expression (C); Digits_Val := Digits_Value (T); else pragma Assert (Nkind (C) = N_Digits_Constraint); Check_SPARK_05_Restriction ("digits constraint is not allowed", S); Digits_Expr := Digits_Expression (C); Analyze_And_Resolve (Digits_Expr, Any_Integer); Check_Digits_Expression (Digits_Expr); Digits_Val := Expr_Value (Digits_Expr); if Digits_Val > Digits_Value (T) then Error_Msg_N ("digits expression is incompatible with subtype", C); Digits_Val := Digits_Value (T); end if; if Present (Range_Constraint (C)) then Range_Expr := Range_Expression (Range_Constraint (C)); else Range_Expr := Empty; end if; end if; Set_Etype (Def_Id, Base_Type (T)); Set_Size_Info (Def_Id, (T)); Set_First_Rep_Item (Def_Id, First_Rep_Item (T)); Set_Delta_Value (Def_Id, Delta_Value (T)); Set_Scale_Value (Def_Id, Scale_Value (T)); Set_Small_Value (Def_Id, Small_Value (T)); Set_Machine_Radix_10 (Def_Id, Machine_Radix_10 (T)); Set_Digits_Value (Def_Id, Digits_Val); -- Manufacture range from given digits value if no range present if No (Range_Expr) then Bound_Val := (Ureal_10 ** Digits_Val - Ureal_1) * Small_Value (T); Range_Expr := Make_Range (Loc, Low_Bound => Convert_To (T, Make_Real_Literal (Loc, (-Bound_Val))), High_Bound => Convert_To (T, Make_Real_Literal (Loc, Bound_Val))); end if; Set_Scalar_Range_For_Subtype (Def_Id, Range_Expr, T); Set_Discrete_RM_Size (Def_Id); -- Unconditionally delay the freeze, since we cannot set size -- information in all cases correctly until the freeze point. Set_Has_Delayed_Freeze (Def_Id); end Constrain_Decimal; ---------------------------------- -- Constrain_Discriminated_Type -- ---------------------------------- procedure Constrain_Discriminated_Type (Def_Id : Entity_Id; S : Node_Id; Related_Nod : Node_Id; For_Access : Boolean := False) is E : Entity_Id := Entity (Subtype_Mark (S)); T : Entity_Id; procedure Fixup_Bad_Constraint; -- Called after finding a bad constraint, and after having posted an -- appropriate error message. The goal is to leave type Def_Id in as -- reasonable state as possible. -------------------------- -- Fixup_Bad_Constraint -- -------------------------- procedure Fixup_Bad_Constraint is begin -- Set a reasonable Ekind for the entity. For an incomplete type, -- we can't do much, but for other types, we can set the proper -- corresponding subtype kind. if Ekind (T) = E_Incomplete_Type then Set_Ekind (Def_Id, Ekind (T)); else Set_Ekind (Def_Id, Subtype_Kind (Ekind (T))); end if; -- Set Etype to the known type, to reduce chances of cascaded errors Set_Etype (Def_Id, E); Set_Error_Posted (Def_Id); end Fixup_Bad_Constraint; -- Local variables C : Node_Id; Constr : Elist_Id := New_Elmt_List; -- Start of processing for Constrain_Discriminated_Type begin C := Constraint (S); -- A discriminant constraint is only allowed in a subtype indication, -- after a subtype mark. This subtype mark must denote either a type -- with discriminants, or an access type whose designated type is a -- type with discriminants. A discriminant constraint specifies the -- values of these discriminants (RM 3.7.2(5)). T := Base_Type (Entity (Subtype_Mark (S))); if Is_Access_Type (T) then T := Designated_Type (T); end if; -- In an instance it may be necessary to retrieve the full view of a -- type with unknown discriminants, or a full view with defaulted -- discriminants. In other contexts the constraint is illegal. if In_Instance and then Is_Private_Type (T) and then Present (Full_View (T)) and then (Has_Unknown_Discriminants (T) or else (not Has_Discriminants (T) and then Has_Discriminants (Full_View (T)) and then Present (Discriminant_Default_Value (First_Discriminant (Full_View (T)))))) then T := Full_View (T); E := Full_View (E); end if; -- Ada 2005 (AI-412): Constrained incomplete subtypes are illegal. Avoid -- generating an error for access-to-incomplete subtypes. if Ada_Version >= Ada_2005 and then Ekind (T) = E_Incomplete_Type and then Nkind (Parent (S)) = N_Subtype_Declaration and then not Is_Itype (Def_Id) then -- A little sanity check: emit an error message if the type has -- discriminants to begin with. Type T may be a regular incomplete -- type or imported via a limited with clause. if Has_Discriminants (T) or else (From_Limited_With (T) and then Present (Non_Limited_View (T)) and then Nkind (Parent (Non_Limited_View (T))) = N_Full_Type_Declaration and then Present (Discriminant_Specifications (Parent (Non_Limited_View (T))))) then Error_Msg_N ("(Ada 2005) incomplete subtype may not be constrained", C); else Error_Msg_N ("invalid constraint: type has no discriminant", C); end if; Fixup_Bad_Constraint; return; -- Check that the type has visible discriminants. The type may be -- a private type with unknown discriminants whose full view has -- discriminants which are invisible. elsif not Has_Discriminants (T) or else (Has_Unknown_Discriminants (T) and then Is_Private_Type (T)) then Error_Msg_N ("invalid constraint: type has no discriminant", C); Fixup_Bad_Constraint; return; elsif Is_Constrained (E) or else (Ekind (E) = E_Class_Wide_Subtype and then Present (Discriminant_Constraint (E))) then Error_Msg_N ("type is already constrained", Subtype_Mark (S)); Fixup_Bad_Constraint; return; end if; -- T may be an unconstrained subtype (e.g. a generic actual). Constraint -- applies to the base type. T := Base_Type (T); Constr := Build_Discriminant_Constraints (T, S); -- If the list returned was empty we had an error in building the -- discriminant constraint. We have also already signalled an error -- in the incomplete type case if Is_Empty_Elmt_List (Constr) then Fixup_Bad_Constraint; return; end if; Build_Discriminated_Subtype (T, Def_Id, Constr, Related_Nod, For_Access); end Constrain_Discriminated_Type; --------------------------- -- Constrain_Enumeration -- --------------------------- procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id) is T : constant Entity_Id := Entity (Subtype_Mark (S)); C : constant Node_Id := Constraint (S); begin Set_Ekind (Def_Id, E_Enumeration_Subtype); Set_First_Literal (Def_Id, First_Literal (Base_Type (T))); Set_Etype (Def_Id, Base_Type (T)); Set_Size_Info (Def_Id, (T)); Set_First_Rep_Item (Def_Id, First_Rep_Item (T)); Set_Is_Character_Type (Def_Id, Is_Character_Type (T)); Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T); Set_Discrete_RM_Size (Def_Id); end Constrain_Enumeration; ---------------------- -- Constrain_Float -- ---------------------- procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id) is T : constant Entity_Id := Entity (Subtype_Mark (S)); C : Node_Id; D : Node_Id; Rais : Node_Id; begin Set_Ekind (Def_Id, E_Floating_Point_Subtype); Set_Etype (Def_Id, Base_Type (T)); Set_Size_Info (Def_Id, (T)); Set_First_Rep_Item (Def_Id, First_Rep_Item (T)); -- Process the constraint C := Constraint (S); -- Digits constraint present if Nkind (C) = N_Digits_Constraint then Check_SPARK_05_Restriction ("digits constraint is not allowed", S); Check_Restriction (No_Obsolescent_Features, C); if Warn_On_Obsolescent_Feature then Error_Msg_N ("subtype digits constraint is an " & "obsolescent feature (RM J.3(8))?j?", C); end if; D := Digits_Expression (C); Analyze_And_Resolve (D, Any_Integer); Check_Digits_Expression (D); Set_Digits_Value (Def_Id, Expr_Value (D)); -- Check that digits value is in range. Obviously we can do this -- at compile time, but it is strictly a runtime check, and of -- course there is an ACVC test that checks this. if Digits_Value (Def_Id) > Digits_Value (T) then Error_Msg_Uint_1 := Digits_Value (T); Error_Msg_N ("??digits value is too large, maximum is ^", D); Rais := Make_Raise_Constraint_Error (Sloc (D), Reason => CE_Range_Check_Failed); Insert_Action (Declaration_Node (Def_Id), Rais); end if; C := Range_Constraint (C); -- No digits constraint present else Set_Digits_Value (Def_Id, Digits_Value (T)); end if; -- Range constraint present if Nkind (C) = N_Range_Constraint then Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T); -- No range constraint present else pragma Assert (No (C)); Set_Scalar_Range (Def_Id, Scalar_Range (T)); end if; Set_Is_Constrained (Def_Id); end Constrain_Float; --------------------- -- Constrain_Index -- --------------------- procedure Constrain_Index (Index : Node_Id; S : Node_Id; Related_Nod : Node_Id; Related_Id : Entity_Id; Suffix : Character; Suffix_Index : Nat) is Def_Id : Entity_Id; R : Node_Id := Empty; T : constant Entity_Id := Etype (Index); begin Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix, Suffix_Index); Set_Etype (Def_Id, Base_Type (T)); if Nkind (S) = N_Range or else (Nkind (S) = N_Attribute_Reference and then Attribute_Name (S) = Name_Range) then -- A Range attribute will be transformed into N_Range by Resolve Analyze (S); Set_Etype (S, T); R := S; Process_Range_Expr_In_Decl (R, T); if not Error_Posted (S) and then (Nkind (S) /= N_Range or else not Covers (T, (Etype (Low_Bound (S)))) or else not Covers (T, (Etype (High_Bound (S))))) then if Base_Type (T) /= Any_Type and then Etype (Low_Bound (S)) /= Any_Type and then Etype (High_Bound (S)) /= Any_Type then Error_Msg_N ("range expected", S); end if; end if; elsif Nkind (S) = N_Subtype_Indication then -- The parser has verified that this is a discrete indication Resolve_Discrete_Subtype_Indication (S, T); Bad_Predicated_Subtype_Use ("subtype& has predicate, not allowed in index constraint", S, Entity (Subtype_Mark (S))); R := Range_Expression (Constraint (S)); -- Capture values of bounds and generate temporaries for them if -- needed, since checks may cause duplication of the expressions -- which must not be reevaluated. -- The forced evaluation removes side effects from expressions, which -- should occur also in GNATprove mode. Otherwise, we end up with -- unexpected insertions of actions at places where this is not -- supposed to occur, e.g. on default parameters of a call. if Expander_Active or GNATprove_Mode then Force_Evaluation (Low_Bound (R), Related_Id => Def_Id, Is_Low_Bound => True); Force_Evaluation (High_Bound (R), Related_Id => Def_Id, Is_High_Bound => True); end if; elsif Nkind (S) = N_Discriminant_Association then -- Syntactically valid in subtype indication Error_Msg_N ("invalid index constraint", S); Rewrite (S, New_Occurrence_Of (T, Sloc (S))); return; -- Subtype_Mark case, no anonymous subtypes to construct else Analyze (S); if Is_Entity_Name (S) then if not Is_Type (Entity (S)) then Error_Msg_N ("expect subtype mark for index constraint", S); elsif Base_Type (Entity (S)) /= Base_Type (T) then Wrong_Type (S, Base_Type (T)); -- Check error of subtype with predicate in index constraint else Bad_Predicated_Subtype_Use ("subtype& has predicate, not allowed in index constraint", S, Entity (S)); end if; return; else Error_Msg_N ("invalid index constraint", S); Rewrite (S, New_Occurrence_Of (T, Sloc (S))); return; end if; end if; -- Complete construction of the Itype if Is_Modular_Integer_Type (T) then Set_Ekind (Def_Id, E_Modular_Integer_Subtype); elsif Is_Integer_Type (T) then Set_Ekind (Def_Id, E_Signed_Integer_Subtype); else Set_Ekind (Def_Id, E_Enumeration_Subtype); Set_Is_Character_Type (Def_Id, Is_Character_Type (T)); Set_First_Literal (Def_Id, First_Literal (T)); end if; Set_Size_Info (Def_Id, (T)); Set_RM_Size (Def_Id, RM_Size (T)); Set_First_Rep_Item (Def_Id, First_Rep_Item (T)); Set_Scalar_Range (Def_Id, R); Set_Etype (S, Def_Id); Set_Discrete_RM_Size (Def_Id); end Constrain_Index; ----------------------- -- Constrain_Integer -- ----------------------- procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id) is T : constant Entity_Id := Entity (Subtype_Mark (S)); C : constant Node_Id := Constraint (S); begin Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T); if Is_Modular_Integer_Type (T) then Set_Ekind (Def_Id, E_Modular_Integer_Subtype); else Set_Ekind (Def_Id, E_Signed_Integer_Subtype); end if; Set_Etype (Def_Id, Base_Type (T)); Set_Size_Info (Def_Id, (T)); Set_First_Rep_Item (Def_Id, First_Rep_Item (T)); Set_Discrete_RM_Size (Def_Id); end Constrain_Integer; ------------------------------ -- Constrain_Ordinary_Fixed -- ------------------------------ procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id) is T : constant Entity_Id := Entity (Subtype_Mark (S)); C : Node_Id; D : Node_Id; Rais : Node_Id; begin Set_Ekind (Def_Id, E_Ordinary_Fixed_Point_Subtype); Set_Etype (Def_Id, Base_Type (T)); Set_Size_Info (Def_Id, (T)); Set_First_Rep_Item (Def_Id, First_Rep_Item (T)); Set_Small_Value (Def_Id, Small_Value (T)); -- Process the constraint C := Constraint (S); -- Delta constraint present if Nkind (C) = N_Delta_Constraint then Check_SPARK_05_Restriction ("delta constraint is not allowed", S); Check_Restriction (No_Obsolescent_Features, C); if Warn_On_Obsolescent_Feature then Error_Msg_S ("subtype delta constraint is an " & "obsolescent feature (RM J.3(7))?j?"); end if; D := Delta_Expression (C); Analyze_And_Resolve (D, Any_Real); Check_Delta_Expression (D); Set_Delta_Value (Def_Id, Expr_Value_R (D)); -- Check that delta value is in range. Obviously we can do this -- at compile time, but it is strictly a runtime check, and of -- course there is an ACVC test that checks this. if Delta_Value (Def_Id) < Delta_Value (T) then Error_Msg_N ("??delta value is too small", D); Rais := Make_Raise_Constraint_Error (Sloc (D), Reason => CE_Range_Check_Failed); Insert_Action (Declaration_Node (Def_Id), Rais); end if; C := Range_Constraint (C); -- No delta constraint present else Set_Delta_Value (Def_Id, Delta_Value (T)); end if; -- Range constraint present if Nkind (C) = N_Range_Constraint then Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T); -- No range constraint present else pragma Assert (No (C)); Set_Scalar_Range (Def_Id, Scalar_Range (T)); end if; Set_Discrete_RM_Size (Def_Id); -- Unconditionally delay the freeze, since we cannot set size -- information in all cases correctly until the freeze point. Set_Has_Delayed_Freeze (Def_Id); end Constrain_Ordinary_Fixed; ----------------------- -- Contain_Interface -- ----------------------- function Contain_Interface (Iface : Entity_Id; Ifaces : Elist_Id) return Boolean is Iface_Elmt : Elmt_Id; begin if Present (Ifaces) then Iface_Elmt := First_Elmt (Ifaces); while Present (Iface_Elmt) loop if Node (Iface_Elmt) = Iface then return True; end if; Next_Elmt (Iface_Elmt); end loop; end if; return False; end Contain_Interface; --------------------------- -- Convert_Scalar_Bounds -- --------------------------- procedure Convert_Scalar_Bounds (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id; Loc : Source_Ptr) is Implicit_Base : constant Entity_Id := Base_Type (Derived_Type); Lo : Node_Id; Hi : Node_Id; Rng : Node_Id; begin -- Defend against previous errors if No (Scalar_Range (Derived_Type)) then Check_Error_Detected; return; end if; Lo := Build_Scalar_Bound (Type_Low_Bound (Derived_Type), Parent_Type, Implicit_Base); Hi := Build_Scalar_Bound (Type_High_Bound (Derived_Type), Parent_Type, Implicit_Base); Rng := Make_Range (Loc, Low_Bound => Lo, High_Bound => Hi); Set_Includes_Infinities (Rng, Has_Infinities (Derived_Type)); Set_Parent (Rng, N); Set_Scalar_Range (Derived_Type, Rng); -- Analyze the bounds Analyze_And_Resolve (Lo, Implicit_Base); Analyze_And_Resolve (Hi, Implicit_Base); -- Analyze the range itself, except that we do not analyze it if -- the bounds are real literals, and we have a fixed-point type. -- The reason for this is that we delay setting the bounds in this -- case till we know the final Small and Size values (see circuit -- in Freeze.Freeze_Fixed_Point_Type for further details). if Is_Fixed_Point_Type (Parent_Type) and then Nkind (Lo) = N_Real_Literal and then Nkind (Hi) = N_Real_Literal then return; -- Here we do the analysis of the range -- Note: we do this manually, since if we do a normal Analyze and -- Resolve call, there are problems with the conversions used for -- the derived type range. else Set_Etype (Rng, Implicit_Base); Set_Analyzed (Rng, True); end if; end Convert_Scalar_Bounds; ------------------- -- Copy_And_Swap -- ------------------- procedure Copy_And_Swap (Priv, Full : Entity_Id) is begin -- Initialize new full declaration entity by copying the pertinent -- fields of the corresponding private declaration entity. -- We temporarily set Ekind to a value appropriate for a type to -- avoid assert failures in Einfo from checking for setting type -- attributes on something that is not a type. Ekind (Priv) is an -- appropriate choice, since it allowed the attributes to be set -- in the first place. This Ekind value will be modified later. Set_Ekind (Full, Ekind (Priv)); -- Also set Etype temporarily to Any_Type, again, in the absence -- of errors, it will be properly reset, and if there are errors, -- then we want a value of Any_Type to remain. Set_Etype (Full, Any_Type); -- Now start copying attributes Set_Has_Discriminants (Full, Has_Discriminants (Priv)); if Has_Discriminants (Full) then Set_Discriminant_Constraint (Full, Discriminant_Constraint (Priv)); Set_Stored_Constraint (Full, Stored_Constraint (Priv)); end if; Set_First_Rep_Item (Full, First_Rep_Item (Priv)); Set_Homonym (Full, Homonym (Priv)); Set_Is_Immediately_Visible (Full, Is_Immediately_Visible (Priv)); Set_Is_Public (Full, Is_Public (Priv)); Set_Is_Pure (Full, Is_Pure (Priv)); Set_Is_Tagged_Type (Full, Is_Tagged_Type (Priv)); Set_Has_Pragma_Unmodified (Full, Has_Pragma_Unmodified (Priv)); Set_Has_Pragma_Unreferenced (Full, Has_Pragma_Unreferenced (Priv)); Set_Has_Pragma_Unreferenced_Objects (Full, Has_Pragma_Unreferenced_Objects (Priv)); Conditional_Delay (Full, Priv); if Is_Tagged_Type (Full) then Set_Direct_Primitive_Operations (Full, Direct_Primitive_Operations (Priv)); Set_No_Tagged_Streams_Pragma (Full, No_Tagged_Streams_Pragma (Priv)); if Is_Base_Type (Priv) then Set_Class_Wide_Type (Full, Class_Wide_Type (Priv)); end if; end if; Set_Is_Volatile (Full, Is_Volatile (Priv)); Set_Treat_As_Volatile (Full, Treat_As_Volatile (Priv)); Set_Scope (Full, Scope (Priv)); Set_Next_Entity (Full, Next_Entity (Priv)); Set_First_Entity (Full, First_Entity (Priv)); Set_Last_Entity (Full, Last_Entity (Priv)); -- If access types have been recorded for later handling, keep them in -- the full view so that they get handled when the full view freeze -- node is expanded. if Present (Freeze_Node (Priv)) and then Present (Access_Types_To_Process (Freeze_Node (Priv))) then Ensure_Freeze_Node (Full); Set_Access_Types_To_Process (Freeze_Node (Full), Access_Types_To_Process (Freeze_Node (Priv))); end if; -- Swap the two entities. Now Private is the full type entity and Full -- is the private one. They will be swapped back at the end of the -- private part. This swapping ensures that the entity that is visible -- in the private part is the full declaration. Exchange_Entities (Priv, Full); Append_Entity (Full, Scope (Full)); end Copy_And_Swap; ------------------------------------- -- Copy_Array_Base_Type_Attributes -- ------------------------------------- procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id) is begin Set_Component_Alignment (T1, Component_Alignment (T2)); Set_Component_Type (T1, Component_Type (T2)); Set_Component_Size (T1, Component_Size (T2)); Set_Has_Controlled_Component (T1, Has_Controlled_Component (T2)); Set_Has_Non_Standard_Rep (T1, Has_Non_Standard_Rep (T2)); Propagate_Concurrent_Flags (T1, T2); Set_Is_Packed (T1, Is_Packed (T2)); Set_Has_Aliased_Components (T1, Has_Aliased_Components (T2)); Set_Has_Atomic_Components (T1, Has_Atomic_Components (T2)); Set_Has_Volatile_Components (T1, Has_Volatile_Components (T2)); end Copy_Array_Base_Type_Attributes; ----------------------------------- -- Copy_Array_Subtype_Attributes -- ----------------------------------- procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id) is begin Set_Size_Info (T1, T2); Set_First_Index (T1, First_Index (T2)); Set_Is_Aliased (T1, Is_Aliased (T2)); Set_Is_Volatile (T1, Is_Volatile (T2)); Set_Treat_As_Volatile (T1, Treat_As_Volatile (T2)); Set_Is_Constrained (T1, Is_Constrained (T2)); Set_Depends_On_Private (T1, Has_Private_Component (T2)); Inherit_Rep_Item_Chain (T1, T2); Set_Convention (T1, Convention (T2)); Set_Is_Limited_Composite (T1, Is_Limited_Composite (T2)); Set_Is_Private_Composite (T1, Is_Private_Composite (T2)); Set_Packed_Array_Impl_Type (T1, Packed_Array_Impl_Type (T2)); end Copy_Array_Subtype_Attributes; ----------------------------------- -- Create_Constrained_Components -- ----------------------------------- procedure Create_Constrained_Components (Subt : Entity_Id; Decl_Node : Node_Id; Typ : Entity_Id; Constraints : Elist_Id) is Loc : constant Source_Ptr := Sloc (Subt); Comp_List : constant Elist_Id := New_Elmt_List; Parent_Type : constant Entity_Id := Etype (Typ); Assoc_List : constant List_Id := New_List; Discr_Val : Elmt_Id; Errors : Boolean; New_C : Entity_Id; Old_C : Entity_Id; Is_Static : Boolean := True; procedure Collect_Fixed_Components (Typ : Entity_Id); -- Collect parent type components that do not appear in a variant part procedure Create_All_Components; -- Iterate over Comp_List to create the components of the subtype function Create_Component (Old_Compon : Entity_Id) return Entity_Id; -- Creates a new component from Old_Compon, copying all the fields from -- it, including its Etype, inserts the new component in the Subt entity -- chain and returns the new component. function Is_Variant_Record (T : Entity_Id) return Boolean; -- If true, and discriminants are static, collect only components from -- variants selected by discriminant values. ------------------------------ -- Collect_Fixed_Components -- ------------------------------ procedure Collect_Fixed_Components (Typ : Entity_Id) is begin -- Build association list for discriminants, and find components of the -- variant part selected by the values of the discriminants. Old_C := First_Discriminant (Typ); Discr_Val := First_Elmt (Constraints); while Present (Old_C) loop Append_To (Assoc_List, Make_Component_Association (Loc, Choices => New_List (New_Occurrence_Of (Old_C, Loc)), Expression => New_Copy (Node (Discr_Val)))); Next_Elmt (Discr_Val); Next_Discriminant (Old_C); end loop; -- The tag and the possible parent component are unconditionally in -- the subtype. if Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then Old_C := First_Component (Typ); while Present (Old_C) loop if Nam_In (Chars (Old_C), Name_uTag, Name_uParent) then Append_Elmt (Old_C, Comp_List); end if; Next_Component (Old_C); end loop; end if; end Collect_Fixed_Components; --------------------------- -- Create_All_Components -- --------------------------- procedure Create_All_Components is Comp : Elmt_Id; begin Comp := First_Elmt (Comp_List); while Present (Comp) loop Old_C := Node (Comp); New_C := Create_Component (Old_C); Set_Etype (New_C, Constrain_Component_Type (Old_C, Subt, Decl_Node, Typ, Constraints)); Set_Is_Public (New_C, Is_Public (Subt)); Next_Elmt (Comp); end loop; end Create_All_Components; ---------------------- -- Create_Component -- ---------------------- function Create_Component (Old_Compon : Entity_Id) return Entity_Id is New_Compon : constant Entity_Id := New_Copy (Old_Compon); begin if Ekind (Old_Compon) = E_Discriminant and then Is_Completely_Hidden (Old_Compon) then -- This is a shadow discriminant created for a discriminant of -- the parent type, which needs to be present in the subtype. -- Give the shadow discriminant an internal name that cannot -- conflict with that of visible components. Set_Chars (New_Compon, New_Internal_Name ('C')); end if; -- Set the parent so we have a proper link for freezing etc. This is -- not a real parent pointer, since of course our parent does not own -- up to us and reference us, we are an illegitimate child of the -- original parent. Set_Parent (New_Compon, Parent (Old_Compon)); -- If the old component's Esize was already determined and is a -- static value, then the new component simply inherits it. Otherwise -- the old component's size may require run-time determination, but -- the new component's size still might be statically determinable -- (if, for example it has a static constraint). In that case we want -- Layout_Type to recompute the component's size, so we reset its -- size and positional fields. if Frontend_Layout_On_Target and then not Known_Static_Esize (Old_Compon) then Set_Esize (New_Compon, Uint_0); Init_Normalized_First_Bit (New_Compon); Init_Normalized_Position (New_Compon); Init_Normalized_Position_Max (New_Compon); end if; -- We do not want this node marked as Comes_From_Source, since -- otherwise it would get first class status and a separate cross- -- reference line would be generated. Illegitimate children do not -- rate such recognition. Set_Comes_From_Source (New_Compon, False); -- But it is a real entity, and a birth certificate must be properly -- registered by entering it into the entity list. Enter_Name (New_Compon); return New_Compon; end Create_Component; ----------------------- -- Is_Variant_Record -- ----------------------- function Is_Variant_Record (T : Entity_Id) return Boolean is begin return Nkind (Parent (T)) = N_Full_Type_Declaration and then Nkind (Type_Definition (Parent (T))) = N_Record_Definition and then Present (Component_List (Type_Definition (Parent (T)))) and then Present (Variant_Part (Component_List (Type_Definition (Parent (T))))); end Is_Variant_Record; -- Start of processing for Create_Constrained_Components begin pragma Assert (Subt /= Base_Type (Subt)); pragma Assert (Typ = Base_Type (Typ)); Set_First_Entity (Subt, Empty); Set_Last_Entity (Subt, Empty); -- Check whether constraint is fully static, in which case we can -- optimize the list of components. Discr_Val := First_Elmt (Constraints); while Present (Discr_Val) loop if not Is_OK_Static_Expression (Node (Discr_Val)) then Is_Static := False; exit; end if; Next_Elmt (Discr_Val); end loop; Set_Has_Static_Discriminants (Subt, Is_Static); Push_Scope (Subt); -- Inherit the discriminants of the parent type Add_Discriminants : declare Num_Disc : Nat; Num_Gird : Nat; begin Num_Disc := 0; Old_C := First_Discriminant (Typ); while Present (Old_C) loop Num_Disc := Num_Disc + 1; New_C := Create_Component (Old_C); Set_Is_Public (New_C, Is_Public (Subt)); Next_Discriminant (Old_C); end loop; -- For an untagged derived subtype, the number of discriminants may -- be smaller than the number of inherited discriminants, because -- several of them may be renamed by a single new discriminant or -- constrained. In this case, add the hidden discriminants back into -- the subtype, because they need to be present if the optimizer of -- the GCC 4.x back-end decides to break apart assignments between -- objects using the parent view into member-wise assignments. Num_Gird := 0; if Is_Derived_Type (Typ) and then not Is_Tagged_Type (Typ) then Old_C := First_Stored_Discriminant (Typ); while Present (Old_C) loop Num_Gird := Num_Gird + 1; Next_Stored_Discriminant (Old_C); end loop; end if; if Num_Gird > Num_Disc then -- Find out multiple uses of new discriminants, and add hidden -- components for the extra renamed discriminants. We recognize -- multiple uses through the Corresponding_Discriminant of a -- new discriminant: if it constrains several old discriminants, -- this field points to the last one in the parent type. The -- stored discriminants of the derived type have the same name -- as those of the parent. declare Constr : Elmt_Id; New_Discr : Entity_Id; Old_Discr : Entity_Id; begin Constr := First_Elmt (Stored_Constraint (Typ)); Old_Discr := First_Stored_Discriminant (Typ); while Present (Constr) loop if Is_Entity_Name (Node (Constr)) and then Ekind (Entity (Node (Constr))) = E_Discriminant then New_Discr := Entity (Node (Constr)); if Chars (Corresponding_Discriminant (New_Discr)) /= Chars (Old_Discr) then -- The new discriminant has been used to rename a -- subsequent old discriminant. Introduce a shadow -- component for the current old discriminant. New_C := Create_Component (Old_Discr); Set_Original_Record_Component (New_C, Old_Discr); end if; else -- The constraint has eliminated the old discriminant. -- Introduce a shadow component. New_C := Create_Component (Old_Discr); Set_Original_Record_Component (New_C, Old_Discr); end if; Next_Elmt (Constr); Next_Stored_Discriminant (Old_Discr); end loop; end; end if; end Add_Discriminants; if Is_Static and then Is_Variant_Record (Typ) then Collect_Fixed_Components (Typ); Gather_Components ( Typ, Component_List (Type_Definition (Parent (Typ))), Governed_By => Assoc_List, Into => Comp_List, Report_Errors => Errors); pragma Assert (not Errors or else Serious_Errors_Detected > 0); Create_All_Components; -- If the subtype declaration is created for a tagged type derivation -- with constraints, we retrieve the record definition of the parent -- type to select the components of the proper variant. elsif Is_Static and then Is_Tagged_Type (Typ) and then Nkind (Parent (Typ)) = N_Full_Type_Declaration and then Nkind (Type_Definition (Parent (Typ))) = N_Derived_Type_Definition and then Is_Variant_Record (Parent_Type) then Collect_Fixed_Components (Typ); Gather_Components (Typ, Component_List (Type_Definition (Parent (Parent_Type))), Governed_By => Assoc_List, Into => Comp_List, Report_Errors => Errors); -- Note: previously there was a check at this point that no errors -- were detected. As a consequence of AI05-220 there may be an error -- if an inherited discriminant that controls a variant has a non- -- static constraint. -- If the tagged derivation has a type extension, collect all the -- new components therein. if Present (Record_Extension_Part (Type_Definition (Parent (Typ)))) then Old_C := First_Component (Typ); while Present (Old_C) loop if Original_Record_Component (Old_C) = Old_C and then Chars (Old_C) /= Name_uTag and then Chars (Old_C) /= Name_uParent then Append_Elmt (Old_C, Comp_List); end if; Next_Component (Old_C); end loop; end if; Create_All_Components; else -- If discriminants are not static, or if this is a multi-level type -- extension, we have to include all components of the parent type. Old_C := First_Component (Typ); while Present (Old_C) loop New_C := Create_Component (Old_C); Set_Etype (New_C, Constrain_Component_Type (Old_C, Subt, Decl_Node, Typ, Constraints)); Set_Is_Public (New_C, Is_Public (Subt)); Next_Component (Old_C); end loop; end if; End_Scope; end Create_Constrained_Components; ------------------------------------------ -- Decimal_Fixed_Point_Type_Declaration -- ------------------------------------------ procedure Decimal_Fixed_Point_Type_Declaration (T : Entity_Id; Def : Node_Id) is Loc : constant Source_Ptr := Sloc (Def); Digs_Expr : constant Node_Id := Digits_Expression (Def); Delta_Expr : constant Node_Id := Delta_Expression (Def); Implicit_Base : Entity_Id; Digs_Val : Uint; Delta_Val : Ureal; Scale_Val : Uint; Bound_Val : Ureal; begin Check_SPARK_05_Restriction ("decimal fixed point type is not allowed", Def); Check_Restriction (No_Fixed_Point, Def); -- Create implicit base type Implicit_Base := Create_Itype (E_Decimal_Fixed_Point_Type, Parent (Def), T, 'B'); Set_Etype (Implicit_Base, Implicit_Base); -- Analyze and process delta expression Analyze_And_Resolve (Delta_Expr, Universal_Real); Check_Delta_Expression (Delta_Expr); Delta_Val := Expr_Value_R (Delta_Expr); -- Check delta is power of 10, and determine scale value from it declare Val : Ureal; begin Scale_Val := Uint_0; Val := Delta_Val; if Val < Ureal_1 then while Val < Ureal_1 loop Val := Val * Ureal_10; Scale_Val := Scale_Val + 1; end loop; if Scale_Val > 18 then Error_Msg_N ("scale exceeds maximum value of 18", Def); Scale_Val := UI_From_Int (+18); end if; else while Val > Ureal_1 loop Val := Val / Ureal_10; Scale_Val := Scale_Val - 1; end loop; if Scale_Val < -18 then Error_Msg_N ("scale is less than minimum value of -18", Def); Scale_Val := UI_From_Int (-18); end if; end if; if Val /= Ureal_1 then Error_Msg_N ("delta expression must be a power of 10", Def); Delta_Val := Ureal_10 ** (-Scale_Val); end if; end; -- Set delta, scale and small (small = delta for decimal type) Set_Delta_Value (Implicit_Base, Delta_Val); Set_Scale_Value (Implicit_Base, Scale_Val); Set_Small_Value (Implicit_Base, Delta_Val); -- Analyze and process digits expression Analyze_And_Resolve (Digs_Expr, Any_Integer); Check_Digits_Expression (Digs_Expr); Digs_Val := Expr_Value (Digs_Expr); if Digs_Val > 18 then Digs_Val := UI_From_Int (+18); Error_Msg_N ("digits value out of range, maximum is 18", Digs_Expr); end if; Set_Digits_Value (Implicit_Base, Digs_Val); Bound_Val := UR_From_Uint (10 ** Digs_Val - 1) * Delta_Val; -- Set range of base type from digits value for now. This will be -- expanded to represent the true underlying base range by Freeze. Set_Fixed_Range (Implicit_Base, Loc, -Bound_Val, Bound_Val); -- Note: We leave size as zero for now, size will be set at freeze -- time. We have to do this for ordinary fixed-point, because the size -- depends on the specified small, and we might as well do the same for -- decimal fixed-point. pragma Assert (Esize (Implicit_Base) = Uint_0); -- If there are bounds given in the declaration use them as the -- bounds of the first named subtype. if Present (Real_Range_Specification (Def)) then declare RRS : constant Node_Id := Real_Range_Specification (Def); Low : constant Node_Id := Low_Bound (RRS); High : constant Node_Id := High_Bound (RRS); Low_Val : Ureal; High_Val : Ureal; begin Analyze_And_Resolve (Low, Any_Real); Analyze_And_Resolve (High, Any_Real); Check_Real_Bound (Low); Check_Real_Bound (High); Low_Val := Expr_Value_R (Low); High_Val := Expr_Value_R (High); if Low_Val < (-Bound_Val) then Error_Msg_N ("range low bound too small for digits value", Low); Low_Val := -Bound_Val; end if; if High_Val > Bound_Val then Error_Msg_N ("range high bound too large for digits value", High); High_Val := Bound_Val; end if; Set_Fixed_Range (T, Loc, Low_Val, High_Val); end; -- If no explicit range, use range that corresponds to given -- digits value. This will end up as the final range for the -- first subtype. else Set_Fixed_Range (T, Loc, -Bound_Val, Bound_Val); end if; -- Complete entity for first subtype. The inheritance of the rep item -- chain ensures that SPARK-related pragmas are not clobbered when the -- decimal fixed point type acts as a full view of a private type. Set_Ekind (T, E_Decimal_Fixed_Point_Subtype); Set_Etype (T, Implicit_Base); Set_Size_Info (T, Implicit_Base); Inherit_Rep_Item_Chain (T, Implicit_Base); Set_Digits_Value (T, Digs_Val); Set_Delta_Value (T, Delta_Val); Set_Small_Value (T, Delta_Val); Set_Scale_Value (T, Scale_Val); Set_Is_Constrained (T); end Decimal_Fixed_Point_Type_Declaration; ----------------------------------- -- Derive_Progenitor_Subprograms -- ----------------------------------- procedure Derive_Progenitor_Subprograms (Parent_Type : Entity_Id; Tagged_Type : Entity_Id) is E : Entity_Id; Elmt : Elmt_Id; Iface : Entity_Id; Iface_Elmt : Elmt_Id; Iface_Subp : Entity_Id; New_Subp : Entity_Id := Empty; Prim_Elmt : Elmt_Id; Subp : Entity_Id; Typ : Entity_Id; begin pragma Assert (Ada_Version >= Ada_2005 and then Is_Record_Type (Tagged_Type) and then Is_Tagged_Type (Tagged_Type) and then Has_Interfaces (Tagged_Type)); -- Step 1: Transfer to the full-view primitives associated with the -- partial-view that cover interface primitives. Conceptually this -- work should be done later by Process_Full_View; done here to -- simplify its implementation at later stages. It can be safely -- done here because interfaces must be visible in the partial and -- private view (RM 7.3(7.3/2)). -- Small optimization: This work is only required if the parent may -- have entities whose Alias attribute reference an interface primitive. -- Such a situation may occur if the parent is an abstract type and the -- primitive has not been yet overridden or if the parent is a generic -- formal type covering interfaces. -- If the tagged type is not abstract, it cannot have abstract -- primitives (the only entities in the list of primitives of -- non-abstract tagged types that can reference abstract primitives -- through its Alias attribute are the internal entities that have -- attribute Interface_Alias, and these entities are generated later -- by Add_Internal_Interface_Entities). if In_Private_Part (Current_Scope) and then (Is_Abstract_Type (Parent_Type) or else Is_Generic_Type (Parent_Type)) then Elmt := First_Elmt (Primitive_Operations (Tagged_Type)); while Present (Elmt) loop Subp := Node (Elmt); -- At this stage it is not possible to have entities in the list -- of primitives that have attribute Interface_Alias. pragma Assert (No (Interface_Alias (Subp))); Typ := Find_Dispatching_Type (Ultimate_Alias (Subp)); if Is_Interface (Typ) then E := Find_Primitive_Covering_Interface (Tagged_Type => Tagged_Type, Iface_Prim => Subp); if Present (E) and then Find_Dispatching_Type (Ultimate_Alias (E)) /= Typ then Replace_Elmt (Elmt, E); Remove_Homonym (Subp); end if; end if; Next_Elmt (Elmt); end loop; end if; -- Step 2: Add primitives of progenitors that are not implemented by -- parents of Tagged_Type. if Present (Interfaces (Base_Type (Tagged_Type))) then Iface_Elmt := First_Elmt (Interfaces (Base_Type (Tagged_Type))); while Present (Iface_Elmt) loop Iface := Node (Iface_Elmt); Prim_Elmt := First_Elmt (Primitive_Operations (Iface)); while Present (Prim_Elmt) loop Iface_Subp := Node (Prim_Elmt); -- Exclude derivation of predefined primitives except those -- that come from source, or are inherited from one that comes -- from source. Required to catch declarations of equality -- operators of interfaces. For example: -- type Iface is interface; -- function "=" (Left, Right : Iface) return Boolean; if not Is_Predefined_Dispatching_Operation (Iface_Subp) or else Comes_From_Source (Ultimate_Alias (Iface_Subp)) then E := Find_Primitive_Covering_Interface (Tagged_Type => Tagged_Type, Iface_Prim => Iface_Subp); -- If not found we derive a new primitive leaving its alias -- attribute referencing the interface primitive. if No (E) then Derive_Subprogram (New_Subp, Iface_Subp, Tagged_Type, Iface); -- Ada 2012 (AI05-0197): If the covering primitive's name -- differs from the name of the interface primitive then it -- is a private primitive inherited from a parent type. In -- such case, given that Tagged_Type covers the interface, -- the inherited private primitive becomes visible. For such -- purpose we add a new entity that renames the inherited -- private primitive. elsif Chars (E) /= Chars (Iface_Subp) then pragma Assert (Has_Suffix (E, 'P')); Derive_Subprogram (New_Subp, Iface_Subp, Tagged_Type, Iface); Set_Alias (New_Subp, E); Set_Is_Abstract_Subprogram (New_Subp, Is_Abstract_Subprogram (E)); -- Propagate to the full view interface entities associated -- with the partial view. elsif In_Private_Part (Current_Scope) and then Present (Alias (E)) and then Alias (E) = Iface_Subp and then List_Containing (Parent (E)) /= Private_Declarations (Specification (Unit_Declaration_Node (Current_Scope))) then Append_Elmt (E, Primitive_Operations (Tagged_Type)); end if; end if; Next_Elmt (Prim_Elmt); end loop; Next_Elmt (Iface_Elmt); end loop; end if; end Derive_Progenitor_Subprograms; ----------------------- -- Derive_Subprogram -- ----------------------- procedure Derive_Subprogram (New_Subp : out Entity_Id; Parent_Subp : Entity_Id; Derived_Type : Entity_Id; Parent_Type : Entity_Id; Actual_Subp : Entity_Id := Empty) is Formal : Entity_Id; -- Formal parameter of parent primitive operation Formal_Of_Actual : Entity_Id; -- Formal parameter of actual operation, when the derivation is to -- create a renaming for a primitive operation of an actual in an -- instantiation. New_Formal : Entity_Id; -- Formal of inherited operation Visible_Subp : Entity_Id := Parent_Subp; function Is_Private_Overriding return Boolean; -- If Subp is a private overriding of a visible operation, the inherited -- operation derives from the overridden op (even though its body is the -- overriding one) and the inherited operation is visible now. See -- sem_disp to see the full details of the handling of the overridden -- subprogram, which is removed from the list of primitive operations of -- the type. The overridden subprogram is saved locally in Visible_Subp, -- and used to diagnose abstract operations that need overriding in the -- derived type. procedure Replace_Type (Id, New_Id : Entity_Id); -- When the type is an anonymous access type, create a new access type -- designating the derived type. procedure Set_Derived_Name; -- This procedure sets the appropriate Chars name for New_Subp. This -- is normally just a copy of the parent name. An exception arises for -- type support subprograms, where the name is changed to reflect the -- name of the derived type, e.g. if type foo is derived from type bar, -- then a procedure barDA is derived with a name fooDA. --------------------------- -- Is_Private_Overriding -- --------------------------- function Is_Private_Overriding return Boolean is Prev : Entity_Id; begin -- If the parent is not a dispatching operation there is no -- need to investigate overridings if not Is_Dispatching_Operation (Parent_Subp) then return False; end if; -- The visible operation that is overridden is a homonym of the -- parent subprogram. We scan the homonym chain to find the one -- whose alias is the subprogram we are deriving. Prev := Current_Entity (Parent_Subp); while Present (Prev) loop if Ekind (Prev) = Ekind (Parent_Subp) and then Alias (Prev) = Parent_Subp and then Scope (Parent_Subp) = Scope (Prev) and then not Is_Hidden (Prev) then Visible_Subp := Prev; return True; end if; Prev := Homonym (Prev); end loop; return False; end Is_Private_Overriding; ------------------ -- Replace_Type -- ------------------ procedure Replace_Type (Id, New_Id : Entity_Id) is Id_Type : constant Entity_Id := Etype (Id); Acc_Type : Entity_Id; Par : constant Node_Id := Parent (Derived_Type); begin -- When the type is an anonymous access type, create a new access -- type designating the derived type. This itype must be elaborated -- at the point of the derivation, not on subsequent calls that may -- be out of the proper scope for Gigi, so we insert a reference to -- it after the derivation. if Ekind (Id_Type) = E_Anonymous_Access_Type then declare Desig_Typ : Entity_Id := Designated_Type (Id_Type); begin if Ekind (Desig_Typ) = E_Record_Type_With_Private and then Present (Full_View (Desig_Typ)) and then not Is_Private_Type (Parent_Type) then Desig_Typ := Full_View (Desig_Typ); end if; if Base_Type (Desig_Typ) = Base_Type (Parent_Type) -- Ada 2005 (AI-251): Handle also derivations of abstract -- interface primitives. or else (Is_Interface (Desig_Typ) and then not Is_Class_Wide_Type (Desig_Typ)) then Acc_Type := New_Copy (Id_Type); Set_Etype (Acc_Type, Acc_Type); Set_Scope (Acc_Type, New_Subp); -- Set size of anonymous access type. If we have an access -- to an unconstrained array, this is a fat pointer, so it -- is sizes at twice addtress size. if Is_Array_Type (Desig_Typ) and then not Is_Constrained (Desig_Typ) then Init_Size (Acc_Type, 2 * System_Address_Size); -- Other cases use a thin pointer else Init_Size (Acc_Type, System_Address_Size); end if; -- Set remaining characterstics of anonymous access type Init_Alignment (Acc_Type); Set_Directly_Designated_Type (Acc_Type, Derived_Type); Set_Etype (New_Id, Acc_Type); Set_Scope (New_Id, New_Subp); -- Create a reference to it Build_Itype_Reference (Acc_Type, Parent (Derived_Type)); else Set_Etype (New_Id, Id_Type); end if; end; -- In Ada2012, a formal may have an incomplete type but the type -- derivation that inherits the primitive follows the full view. elsif Base_Type (Id_Type) = Base_Type (Parent_Type) or else (Ekind (Id_Type) = E_Record_Type_With_Private and then Present (Full_View (Id_Type)) and then Base_Type (Full_View (Id_Type)) = Base_Type (Parent_Type)) or else (Ada_Version >= Ada_2012 and then Ekind (Id_Type) = E_Incomplete_Type and then Full_View (Id_Type) = Parent_Type) then -- Constraint checks on formals are generated during expansion, -- based on the signature of the original subprogram. The bounds -- of the derived type are not relevant, and thus we can use -- the base type for the formals. However, the return type may be -- used in a context that requires that the proper static bounds -- be used (a case statement, for example) and for those cases -- we must use the derived type (first subtype), not its base. -- If the derived_type_definition has no constraints, we know that -- the derived type has the same constraints as the first subtype -- of the parent, and we can also use it rather than its base, -- which can lead to more efficient code. if Etype (Id) = Parent_Type then if Is_Scalar_Type (Parent_Type) and then Subtypes_Statically_Compatible (Parent_Type, Derived_Type) then Set_Etype (New_Id, Derived_Type); elsif Nkind (Par) = N_Full_Type_Declaration and then Nkind (Type_Definition (Par)) = N_Derived_Type_Definition and then Is_Entity_Name (Subtype_Indication (Type_Definition (Par))) then Set_Etype (New_Id, Derived_Type); else Set_Etype (New_Id, Base_Type (Derived_Type)); end if; else Set_Etype (New_Id, Base_Type (Derived_Type)); end if; else Set_Etype (New_Id, Etype (Id)); end if; end Replace_Type; ---------------------- -- Set_Derived_Name -- ---------------------- procedure Set_Derived_Name is Nm : constant TSS_Name_Type := Get_TSS_Name (Parent_Subp); begin if Nm = TSS_Null then Set_Chars (New_Subp, Chars (Parent_Subp)); else Set_Chars (New_Subp, Make_TSS_Name (Base_Type (Derived_Type), Nm)); end if; end Set_Derived_Name; -- Start of processing for Derive_Subprogram begin New_Subp := New_Entity (Nkind (Parent_Subp), Sloc (Derived_Type)); Set_Ekind (New_Subp, Ekind (Parent_Subp)); -- Check whether the inherited subprogram is a private operation that -- should be inherited but not yet made visible. Such subprograms can -- become visible at a later point (e.g., the private part of a public -- child unit) via Declare_Inherited_Private_Subprograms. If the -- following predicate is true, then this is not such a private -- operation and the subprogram simply inherits the name of the parent -- subprogram. Note the special check for the names of controlled -- operations, which are currently exempted from being inherited with -- a hidden name because they must be findable for generation of -- implicit run-time calls. if not Is_Hidden (Parent_Subp) or else Is_Internal (Parent_Subp) or else Is_Private_Overriding or else Is_Internal_Name (Chars (Parent_Subp)) or else (Is_Controlled (Parent_Type) and then Nam_In (Chars (Parent_Subp), Name_Adjust, Name_Finalize, Name_Initialize)) then Set_Derived_Name; -- An inherited dispatching equality will be overridden by an internally -- generated one, or by an explicit one, so preserve its name and thus -- its entry in the dispatch table. Otherwise, if Parent_Subp is a -- private operation it may become invisible if the full view has -- progenitors, and the dispatch table will be malformed. -- We check that the type is limited to handle the anomalous declaration -- of Limited_Controlled, which is derived from a non-limited type, and -- which is handled specially elsewhere as well. elsif Chars (Parent_Subp) = Name_Op_Eq and then Is_Dispatching_Operation (Parent_Subp) and then Etype (Parent_Subp) = Standard_Boolean and then not Is_Limited_Type (Etype (First_Formal (Parent_Subp))) and then Etype (First_Formal (Parent_Subp)) = Etype (Next_Formal (First_Formal (Parent_Subp))) then Set_Derived_Name; -- If parent is hidden, this can be a regular derivation if the -- parent is immediately visible in a non-instantiating context, -- or if we are in the private part of an instance. This test -- should still be refined ??? -- The test for In_Instance_Not_Visible avoids inheriting the derived -- operation as a non-visible operation in cases where the parent -- subprogram might not be visible now, but was visible within the -- original generic, so it would be wrong to make the inherited -- subprogram non-visible now. (Not clear if this test is fully -- correct; are there any cases where we should declare the inherited -- operation as not visible to avoid it being overridden, e.g., when -- the parent type is a generic actual with private primitives ???) -- (they should be treated the same as other private inherited -- subprograms, but it's not clear how to do this cleanly). ??? elsif (In_Open_Scopes (Scope (Base_Type (Parent_Type))) and then Is_Immediately_Visible (Parent_Subp) and then not In_Instance) or else In_Instance_Not_Visible then Set_Derived_Name; -- Ada 2005 (AI-251): Regular derivation if the parent subprogram -- overrides an interface primitive because interface primitives -- must be visible in the partial view of the parent (RM 7.3 (7.3/2)) elsif Ada_Version >= Ada_2005 and then Is_Dispatching_Operation (Parent_Subp) and then Present (Covered_Interface_Op (Parent_Subp)) then Set_Derived_Name; -- Otherwise, the type is inheriting a private operation, so enter it -- with a special name so it can't be overridden. else Set_Chars (New_Subp, New_External_Name (Chars (Parent_Subp), 'P')); end if; Set_Parent (New_Subp, Parent (Derived_Type)); if Present (Actual_Subp) then Replace_Type (Actual_Subp, New_Subp); else Replace_Type (Parent_Subp, New_Subp); end if; Conditional_Delay (New_Subp, Parent_Subp); -- If we are creating a renaming for a primitive operation of an -- actual of a generic derived type, we must examine the signature -- of the actual primitive, not that of the generic formal, which for -- example may be an interface. However the name and initial value -- of the inherited operation are those of the formal primitive. Formal := First_Formal (Parent_Subp); if Present (Actual_Subp) then Formal_Of_Actual := First_Formal (Actual_Subp); else Formal_Of_Actual := Empty; end if; while Present (Formal) loop New_Formal := New_Copy (Formal); -- Normally we do not go copying parents, but in the case of -- formals, we need to link up to the declaration (which is the -- parameter specification), and it is fine to link up to the -- original formal's parameter specification in this case. Set_Parent (New_Formal, Parent (Formal)); Append_Entity (New_Formal, New_Subp); if Present (Formal_Of_Actual) then Replace_Type (Formal_Of_Actual, New_Formal); Next_Formal (Formal_Of_Actual); else Replace_Type (Formal, New_Formal); end if; Next_Formal (Formal); end loop; -- If this derivation corresponds to a tagged generic actual, then -- primitive operations rename those of the actual. Otherwise the -- primitive operations rename those of the parent type, If the parent -- renames an intrinsic operator, so does the new subprogram. We except -- concatenation, which is always properly typed, and does not get -- expanded as other intrinsic operations. if No (Actual_Subp) then if Is_Intrinsic_Subprogram (Parent_Subp) then Set_Is_Intrinsic_Subprogram (New_Subp); if Present (Alias (Parent_Subp)) and then Chars (Parent_Subp) /= Name_Op_Concat then Set_Alias (New_Subp, Alias (Parent_Subp)); else Set_Alias (New_Subp, Parent_Subp); end if; else Set_Alias (New_Subp, Parent_Subp); end if; else Set_Alias (New_Subp, Actual_Subp); end if; -- Derived subprograms of a tagged type must inherit the convention -- of the parent subprogram (a requirement of AI-117). Derived -- subprograms of untagged types simply get convention Ada by default. -- If the derived type is a tagged generic formal type with unknown -- discriminants, its convention is intrinsic (RM 6.3.1 (8)). -- However, if the type is derived from a generic formal, the further -- inherited subprogram has the convention of the non-generic ancestor. -- Otherwise there would be no way to override the operation. -- (This is subject to forthcoming ARG discussions). if Is_Tagged_Type (Derived_Type) then if Is_Generic_Type (Derived_Type) and then Has_Unknown_Discriminants (Derived_Type) then Set_Convention (New_Subp, Convention_Intrinsic); else if Is_Generic_Type (Parent_Type) and then Has_Unknown_Discriminants (Parent_Type) then Set_Convention (New_Subp, Convention (Alias (Parent_Subp))); else Set_Convention (New_Subp, Convention (Parent_Subp)); end if; end if; end if; -- Predefined controlled operations retain their name even if the parent -- is hidden (see above), but they are not primitive operations if the -- ancestor is not visible, for example if the parent is a private -- extension completed with a controlled extension. Note that a full -- type that is controlled can break privacy: the flag Is_Controlled is -- set on both views of the type. if Is_Controlled (Parent_Type) and then Nam_In (Chars (Parent_Subp), Name_Initialize, Name_Adjust, Name_Finalize) and then Is_Hidden (Parent_Subp) and then not Is_Visibly_Controlled (Parent_Type) then Set_Is_Hidden (New_Subp); end if; Set_Is_Imported (New_Subp, Is_Imported (Parent_Subp)); Set_Is_Exported (New_Subp, Is_Exported (Parent_Subp)); if Ekind (Parent_Subp) = E_Procedure then Set_Is_Valued_Procedure (New_Subp, Is_Valued_Procedure (Parent_Subp)); else Set_Has_Controlling_Result (New_Subp, Has_Controlling_Result (Parent_Subp)); end if; -- No_Return must be inherited properly. If this is overridden in the -- case of a dispatching operation, then a check is made in Sem_Disp -- that the overriding operation is also No_Return (no such check is -- required for the case of non-dispatching operation. Set_No_Return (New_Subp, No_Return (Parent_Subp)); -- A derived function with a controlling result is abstract. If the -- Derived_Type is a nonabstract formal generic derived type, then -- inherited operations are not abstract: the required check is done at -- instantiation time. If the derivation is for a generic actual, the -- function is not abstract unless the actual is. if Is_Generic_Type (Derived_Type) and then not Is_Abstract_Type (Derived_Type) then null; -- Ada 2005 (AI-228): Calculate the "require overriding" and "abstract" -- properties of the subprogram, as defined in RM-3.9.3(4/2-6/2). -- A subprogram subject to pragma Extensions_Visible with value False -- requires overriding if the subprogram has at least one controlling -- OUT parameter (SPARK RM 6.1.7(6)). elsif Ada_Version >= Ada_2005 and then (Is_Abstract_Subprogram (Alias (New_Subp)) or else (Is_Tagged_Type (Derived_Type) and then Etype (New_Subp) = Derived_Type and then not Is_Null_Extension (Derived_Type)) or else (Is_Tagged_Type (Derived_Type) and then Ekind (Etype (New_Subp)) = E_Anonymous_Access_Type and then Designated_Type (Etype (New_Subp)) = Derived_Type and then not Is_Null_Extension (Derived_Type)) or else (Comes_From_Source (Alias (New_Subp)) and then Is_EVF_Procedure (Alias (New_Subp)))) and then No (Actual_Subp) then if not Is_Tagged_Type (Derived_Type) or else Is_Abstract_Type (Derived_Type) or else Is_Abstract_Subprogram (Alias (New_Subp)) then Set_Is_Abstract_Subprogram (New_Subp); else Set_Requires_Overriding (New_Subp); end if; elsif Ada_Version < Ada_2005 and then (Is_Abstract_Subprogram (Alias (New_Subp)) or else (Is_Tagged_Type (Derived_Type) and then Etype (New_Subp) = Derived_Type and then No (Actual_Subp))) then Set_Is_Abstract_Subprogram (New_Subp); -- AI05-0097 : an inherited operation that dispatches on result is -- abstract if the derived type is abstract, even if the parent type -- is concrete and the derived type is a null extension. elsif Has_Controlling_Result (Alias (New_Subp)) and then Is_Abstract_Type (Etype (New_Subp)) then Set_Is_Abstract_Subprogram (New_Subp); -- Finally, if the parent type is abstract we must verify that all -- inherited operations are either non-abstract or overridden, or that -- the derived type itself is abstract (this check is performed at the -- end of a package declaration, in Check_Abstract_Overriding). A -- private overriding in the parent type will not be visible in the -- derivation if we are not in an inner package or in a child unit of -- the parent type, in which case the abstractness of the inherited -- operation is carried to the new subprogram. elsif Is_Abstract_Type (Parent_Type) and then not In_Open_Scopes (Scope (Parent_Type)) and then Is_Private_Overriding and then Is_Abstract_Subprogram (Visible_Subp) then if No (Actual_Subp) then Set_Alias (New_Subp, Visible_Subp); Set_Is_Abstract_Subprogram (New_Subp, True); else -- If this is a derivation for an instance of a formal derived -- type, abstractness comes from the primitive operation of the -- actual, not from the operation inherited from the ancestor. Set_Is_Abstract_Subprogram (New_Subp, Is_Abstract_Subprogram (Actual_Subp)); end if; end if; New_Overloaded_Entity (New_Subp, Derived_Type); -- Ada RM 6.1.1 (15): If a subprogram inherits nonconforming class-wide -- preconditions and the derived type is abstract, the derived operation -- is abstract as well if parent subprogram is not abstract or null. if Is_Abstract_Type (Derived_Type) and then Has_Non_Trivial_Precondition (Parent_Subp) and then Present (Interfaces (Derived_Type)) then Set_Is_Dispatching_Operation (New_Subp); declare Iface_Prim : constant Entity_Id := Covered_Interface_Op (New_Subp); begin if Present (Iface_Prim) and then Has_Non_Trivial_Precondition (Iface_Prim) then Set_Is_Abstract_Subprogram (New_Subp); end if; end; end if; -- Check for case of a derived subprogram for the instantiation of a -- formal derived tagged type, if so mark the subprogram as dispatching -- and inherit the dispatching attributes of the actual subprogram. The -- derived subprogram is effectively renaming of the actual subprogram, -- so it needs to have the same attributes as the actual. if Present (Actual_Subp) and then Is_Dispatching_Operation (Actual_Subp) then Set_Is_Dispatching_Operation (New_Subp); if Present (DTC_Entity (Actual_Subp)) then Set_DTC_Entity (New_Subp, DTC_Entity (Actual_Subp)); Set_DT_Position_Value (New_Subp, DT_Position (Actual_Subp)); end if; end if; -- Indicate that a derived subprogram does not require a body and that -- it does not require processing of default expressions. Set_Has_Completion (New_Subp); Set_Default_Expressions_Processed (New_Subp); if Ekind (New_Subp) = E_Function then Set_Mechanism (New_Subp, Mechanism (Parent_Subp)); end if; end Derive_Subprogram; ------------------------ -- Derive_Subprograms -- ------------------------ procedure Derive_Subprograms (Parent_Type : Entity_Id; Derived_Type : Entity_Id; Generic_Actual : Entity_Id := Empty) is Op_List : constant Elist_Id := Collect_Primitive_Operations (Parent_Type); function Check_Derived_Type return Boolean; -- Check that all the entities derived from Parent_Type are found in -- the list of primitives of Derived_Type exactly in the same order. procedure Derive_Interface_Subprogram (New_Subp : out Entity_Id; Subp : Entity_Id; Actual_Subp : Entity_Id); -- Derive New_Subp from the ultimate alias of the parent subprogram Subp -- (which is an interface primitive). If Generic_Actual is present then -- Actual_Subp is the actual subprogram corresponding with the generic -- subprogram Subp. ------------------------ -- Check_Derived_Type -- ------------------------ function Check_Derived_Type return Boolean is E : Entity_Id; Elmt : Elmt_Id; List : Elist_Id; New_Subp : Entity_Id; Op_Elmt : Elmt_Id; Subp : Entity_Id; begin -- Traverse list of entities in the current scope searching for -- an incomplete type whose full-view is derived type. E := First_Entity (Scope (Derived_Type)); while Present (E) and then E /= Derived_Type loop if Ekind (E) = E_Incomplete_Type and then Present (Full_View (E)) and then Full_View (E) = Derived_Type then -- Disable this test if Derived_Type completes an incomplete -- type because in such case more primitives can be added -- later to the list of primitives of Derived_Type by routine -- Process_Incomplete_Dependents return True; end if; E := Next_Entity (E); end loop; List := Collect_Primitive_Operations (Derived_Type); Elmt := First_Elmt (List); Op_Elmt := First_Elmt (Op_List); while Present (Op_Elmt) loop Subp := Node (Op_Elmt); New_Subp := Node (Elmt); -- At this early stage Derived_Type has no entities with attribute -- Interface_Alias. In addition, such primitives are always -- located at the end of the list of primitives of Parent_Type. -- Therefore, if found we can safely stop processing pending -- entities. exit when Present (Interface_Alias (Subp)); -- Handle hidden entities if not Is_Predefined_Dispatching_Operation (Subp) and then Is_Hidden (Subp) then if Present (New_Subp) and then Primitive_Names_Match (Subp, New_Subp) then Next_Elmt (Elmt); end if; else if not Present (New_Subp) or else Ekind (Subp) /= Ekind (New_Subp) or else not Primitive_Names_Match (Subp, New_Subp) then return False; end if; Next_Elmt (Elmt); end if; Next_Elmt (Op_Elmt); end loop; return True; end Check_Derived_Type; --------------------------------- -- Derive_Interface_Subprogram -- --------------------------------- procedure Derive_Interface_Subprogram (New_Subp : out Entity_Id; Subp : Entity_Id; Actual_Subp : Entity_Id) is Iface_Subp : constant Entity_Id := Ultimate_Alias (Subp); Iface_Type : constant Entity_Id := Find_Dispatching_Type (Iface_Subp); begin pragma Assert (Is_Interface (Iface_Type)); Derive_Subprogram (New_Subp => New_Subp, Parent_Subp => Iface_Subp, Derived_Type => Derived_Type, Parent_Type => Iface_Type, Actual_Subp => Actual_Subp); -- Given that this new interface entity corresponds with a primitive -- of the parent that was not overridden we must leave it associated -- with its parent primitive to ensure that it will share the same -- dispatch table slot when overridden. We must set the Alias to Subp -- (instead of Iface_Subp), and we must fix Is_Abstract_Subprogram -- (in case we inherited Subp from Iface_Type via a nonabstract -- generic formal type). if No (Actual_Subp) then Set_Alias (New_Subp, Subp); declare T : Entity_Id := Find_Dispatching_Type (Subp); begin while Etype (T) /= T loop if Is_Generic_Type (T) and then not Is_Abstract_Type (T) then Set_Is_Abstract_Subprogram (New_Subp, False); exit; end if; T := Etype (T); end loop; end; -- For instantiations this is not needed since the previous call to -- Derive_Subprogram leaves the entity well decorated. else pragma Assert (Alias (New_Subp) = Actual_Subp); null; end if; end Derive_Interface_Subprogram; -- Local variables Alias_Subp : Entity_Id; Act_List : Elist_Id; Act_Elmt : Elmt_Id; Act_Subp : Entity_Id := Empty; Elmt : Elmt_Id; Need_Search : Boolean := False; New_Subp : Entity_Id := Empty; Parent_Base : Entity_Id; Subp : Entity_Id; -- Start of processing for Derive_Subprograms begin if Ekind (Parent_Type) = E_Record_Type_With_Private and then Has_Discriminants (Parent_Type) and then Present (Full_View (Parent_Type)) then Parent_Base := Full_View (Parent_Type); else Parent_Base := Parent_Type; end if; if Present (Generic_Actual) then Act_List := Collect_Primitive_Operations (Generic_Actual); Act_Elmt := First_Elmt (Act_List); else Act_List := No_Elist; Act_Elmt := No_Elmt; end if; -- Derive primitives inherited from the parent. Note that if the generic -- actual is present, this is not really a type derivation, it is a -- completion within an instance. -- Case 1: Derived_Type does not implement interfaces if not Is_Tagged_Type (Derived_Type) or else (not Has_Interfaces (Derived_Type) and then not (Present (Generic_Actual) and then Has_Interfaces (Generic_Actual))) then Elmt := First_Elmt (Op_List); while Present (Elmt) loop Subp := Node (Elmt); -- Literals are derived earlier in the process of building the -- derived type, and are skipped here. if Ekind (Subp) = E_Enumeration_Literal then null; -- The actual is a direct descendant and the common primitive -- operations appear in the same order. -- If the generic parent type is present, the derived type is an -- instance of a formal derived type, and within the instance its -- operations are those of the actual. We derive from the formal -- type but make the inherited operations aliases of the -- corresponding operations of the actual. else pragma Assert (No (Node (Act_Elmt)) or else (Primitive_Names_Match (Subp, Node (Act_Elmt)) and then Type_Conformant (Subp, Node (Act_Elmt), Skip_Controlling_Formals => True))); Derive_Subprogram (New_Subp, Subp, Derived_Type, Parent_Base, Node (Act_Elmt)); if Present (Act_Elmt) then Next_Elmt (Act_Elmt); end if; end if; Next_Elmt (Elmt); end loop; -- Case 2: Derived_Type implements interfaces else -- If the parent type has no predefined primitives we remove -- predefined primitives from the list of primitives of generic -- actual to simplify the complexity of this algorithm. if Present (Generic_Actual) then declare Has_Predefined_Primitives : Boolean := False; begin -- Check if the parent type has predefined primitives Elmt := First_Elmt (Op_List); while Present (Elmt) loop Subp := Node (Elmt); if Is_Predefined_Dispatching_Operation (Subp) and then not Comes_From_Source (Ultimate_Alias (Subp)) then Has_Predefined_Primitives := True; exit; end if; Next_Elmt (Elmt); end loop; -- Remove predefined primitives of Generic_Actual. We must use -- an auxiliary list because in case of tagged types the value -- returned by Collect_Primitive_Operations is the value stored -- in its Primitive_Operations attribute (and we don't want to -- modify its current contents). if not Has_Predefined_Primitives then declare Aux_List : constant Elist_Id := New_Elmt_List; begin Elmt := First_Elmt (Act_List); while Present (Elmt) loop Subp := Node (Elmt); if not Is_Predefined_Dispatching_Operation (Subp) or else Comes_From_Source (Subp) then Append_Elmt (Subp, Aux_List); end if; Next_Elmt (Elmt); end loop; Act_List := Aux_List; end; end if; Act_Elmt := First_Elmt (Act_List); Act_Subp := Node (Act_Elmt); end; end if; -- Stage 1: If the generic actual is not present we derive the -- primitives inherited from the parent type. If the generic parent -- type is present, the derived type is an instance of a formal -- derived type, and within the instance its operations are those of -- the actual. We derive from the formal type but make the inherited -- operations aliases of the corresponding operations of the actual. Elmt := First_Elmt (Op_List); while Present (Elmt) loop Subp := Node (Elmt); Alias_Subp := Ultimate_Alias (Subp); -- Do not derive internal entities of the parent that link -- interface primitives with their covering primitive. These -- entities will be added to this type when frozen. if Present (Interface_Alias (Subp)) then goto Continue; end if; -- If the generic actual is present find the corresponding -- operation in the generic actual. If the parent type is a -- direct ancestor of the derived type then, even if it is an -- interface, the operations are inherited from the primary -- dispatch table and are in the proper order. If we detect here -- that primitives are not in the same order we traverse the list -- of primitive operations of the actual to find the one that -- implements the interface primitive. if Need_Search or else (Present (Generic_Actual) and then Present (Act_Subp) and then not (Primitive_Names_Match (Subp, Act_Subp) and then Type_Conformant (Subp, Act_Subp, Skip_Controlling_Formals => True))) then pragma Assert (not Is_Ancestor (Parent_Base, Generic_Actual, Use_Full_View => True)); -- Remember that we need searching for all pending primitives Need_Search := True; -- Handle entities associated with interface primitives if Present (Alias_Subp) and then Is_Interface (Find_Dispatching_Type (Alias_Subp)) and then not Is_Predefined_Dispatching_Operation (Subp) then -- Search for the primitive in the homonym chain Act_Subp := Find_Primitive_Covering_Interface (Tagged_Type => Generic_Actual, Iface_Prim => Alias_Subp); -- Previous search may not locate primitives covering -- interfaces defined in generics units or instantiations. -- (it fails if the covering primitive has formals whose -- type is also defined in generics or instantiations). -- In such case we search in the list of primitives of the -- generic actual for the internal entity that links the -- interface primitive and the covering primitive. if No (Act_Subp) and then Is_Generic_Type (Parent_Type) then -- This code has been designed to handle only generic -- formals that implement interfaces that are defined -- in a generic unit or instantiation. If this code is -- needed for other cases we must review it because -- (given that it relies on Original_Location to locate -- the primitive of Generic_Actual that covers the -- interface) it could leave linked through attribute -- Alias entities of unrelated instantiations). pragma Assert (Is_Generic_Unit (Scope (Find_Dispatching_Type (Alias_Subp))) or else Instantiation_Depth (Sloc (Find_Dispatching_Type (Alias_Subp))) > 0); declare Iface_Prim_Loc : constant Source_Ptr := Original_Location (Sloc (Alias_Subp)); Elmt : Elmt_Id; Prim : Entity_Id; begin Elmt := First_Elmt (Primitive_Operations (Generic_Actual)); Search : while Present (Elmt) loop Prim := Node (Elmt); if Present (Interface_Alias (Prim)) and then Original_Location (Sloc (Interface_Alias (Prim))) = Iface_Prim_Loc then Act_Subp := Alias (Prim); exit Search; end if; Next_Elmt (Elmt); end loop Search; end; end if; pragma Assert (Present (Act_Subp) or else Is_Abstract_Type (Generic_Actual) or else Serious_Errors_Detected > 0); -- Handle predefined primitives plus the rest of user-defined -- primitives else Act_Elmt := First_Elmt (Act_List); while Present (Act_Elmt) loop Act_Subp := Node (Act_Elmt); exit when Primitive_Names_Match (Subp, Act_Subp) and then Type_Conformant (Subp, Act_Subp, Skip_Controlling_Formals => True) and then No (Interface_Alias (Act_Subp)); Next_Elmt (Act_Elmt); end loop; if No (Act_Elmt) then Act_Subp := Empty; end if; end if; end if; -- Case 1: If the parent is a limited interface then it has the -- predefined primitives of synchronized interfaces. However, the -- actual type may be a non-limited type and hence it does not -- have such primitives. if Present (Generic_Actual) and then not Present (Act_Subp) and then Is_Limited_Interface (Parent_Base) and then Is_Predefined_Interface_Primitive (Subp) then null; -- Case 2: Inherit entities associated with interfaces that were -- not covered by the parent type. We exclude here null interface -- primitives because they do not need special management. -- We also exclude interface operations that are renamings. If the -- subprogram is an explicit renaming of an interface primitive, -- it is a regular primitive operation, and the presence of its -- alias is not relevant: it has to be derived like any other -- primitive. elsif Present (Alias (Subp)) and then Nkind (Unit_Declaration_Node (Subp)) /= N_Subprogram_Renaming_Declaration and then Is_Interface (Find_Dispatching_Type (Alias_Subp)) and then not (Nkind (Parent (Alias_Subp)) = N_Procedure_Specification and then Null_Present (Parent (Alias_Subp))) then -- If this is an abstract private type then we transfer the -- derivation of the interface primitive from the partial view -- to the full view. This is safe because all the interfaces -- must be visible in the partial view. Done to avoid adding -- a new interface derivation to the private part of the -- enclosing package; otherwise this new derivation would be -- decorated as hidden when the analysis of the enclosing -- package completes. if Is_Abstract_Type (Derived_Type) and then In_Private_Part (Current_Scope) and then Has_Private_Declaration (Derived_Type) then declare Partial_View : Entity_Id; Elmt : Elmt_Id; Ent : Entity_Id; begin Partial_View := First_Entity (Current_Scope); loop exit when No (Partial_View) or else (Has_Private_Declaration (Partial_View) and then Full_View (Partial_View) = Derived_Type); Next_Entity (Partial_View); end loop; -- If the partial view was not found then the source code -- has errors and the derivation is not needed. if Present (Partial_View) then Elmt := First_Elmt (Primitive_Operations (Partial_View)); while Present (Elmt) loop Ent := Node (Elmt); if Present (Alias (Ent)) and then Ultimate_Alias (Ent) = Alias (Subp) then Append_Elmt (Ent, Primitive_Operations (Derived_Type)); exit; end if; Next_Elmt (Elmt); end loop; -- If the interface primitive was not found in the -- partial view then this interface primitive was -- overridden. We add a derivation to activate in -- Derive_Progenitor_Subprograms the machinery to -- search for it. if No (Elmt) then Derive_Interface_Subprogram (New_Subp => New_Subp, Subp => Subp, Actual_Subp => Act_Subp); end if; end if; end; else Derive_Interface_Subprogram (New_Subp => New_Subp, Subp => Subp, Actual_Subp => Act_Subp); end if; -- Case 3: Common derivation else Derive_Subprogram (New_Subp => New_Subp, Parent_Subp => Subp, Derived_Type => Derived_Type, Parent_Type => Parent_Base, Actual_Subp => Act_Subp); end if; -- No need to update Act_Elm if we must search for the -- corresponding operation in the generic actual if not Need_Search and then Present (Act_Elmt) then Next_Elmt (Act_Elmt); Act_Subp := Node (Act_Elmt); end if; <<Continue>> Next_Elmt (Elmt); end loop; -- Inherit additional operations from progenitors. If the derived -- type is a generic actual, there are not new primitive operations -- for the type because it has those of the actual, and therefore -- nothing needs to be done. The renamings generated above are not -- primitive operations, and their purpose is simply to make the -- proper operations visible within an instantiation. if No (Generic_Actual) then Derive_Progenitor_Subprograms (Parent_Base, Derived_Type); end if; end if; -- Final check: Direct descendants must have their primitives in the -- same order. We exclude from this test untagged types and instances -- of formal derived types. We skip this test if we have already -- reported serious errors in the sources. pragma Assert (not Is_Tagged_Type (Derived_Type) or else Present (Generic_Actual) or else Serious_Errors_Detected > 0 or else Check_Derived_Type); end Derive_Subprograms; -------------------------------- -- Derived_Standard_Character -- -------------------------------- procedure Derived_Standard_Character (N : Node_Id; Parent_Type : Entity_Id; Derived_Type : Entity_Id) is Loc : constant Source_Ptr := Sloc (N); Def : constant Node_Id := Type_Definition (N); Indic : constant Node_Id := Subtype_Indication (Def); Parent_Base : constant Entity_Id := Base_Type (Parent_Type); Implicit_Base : constant Entity_Id := Create_Itype (E_Enumeration_Type, N, Derived_Type, 'B'); Lo : Node_Id; Hi : Node_Id; begin Discard_Node (Process_Subtype (Indic, N)); Set_Etype (Implicit_Base, Parent_Base); Set_Size_Info (Implicit_Base, Root_Type (Parent_Type)); Set_RM_Size (Implicit_Base, RM_Size (Root_Type (Parent_Type))); Set_Is_Character_Type (Implicit_Base, True); Set_Has_Delayed_Freeze (Implicit_Base); -- The bounds of the implicit base are the bounds of the parent base. -- Note that their type is the parent base. Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base)); Hi := New_Copy_Tree (Type_High_Bound (Parent_Base)); Set_Scalar_Range (Implicit_Base, Make_Range (Loc, Low_Bound => Lo, High_Bound => Hi)); Conditional_Delay (Derived_Type, Parent_Type); Set_Ekind (Derived_Type, E_Enumeration_Subtype); Set_Etype (Derived_Type, Implicit_Base); Set_Size_Info (Derived_Type, Parent_Type); if Unknown_RM_Size (Derived_Type) then Set_RM_Size (Derived_Type, RM_Size (Parent_Type)); end if; Set_Is_Character_Type (Derived_Type, True); if Nkind (Indic) /= N_Subtype_Indication then -- If no explicit constraint, the bounds are those -- of the parent type. Lo := New_Copy_Tree (Type_Low_Bound (Parent_Type)); Hi := New_Copy_Tree (Type_High_Bound (Parent_Type)); Set_Scalar_Range (Derived_Type, Make_Range (Loc, Lo, Hi)); end if; Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc); -- Because the implicit base is used in the conversion of the bounds, we -- have to freeze it now. This is similar to what is done for numeric -- types, and it equally suspicious, but otherwise a non-static bound -- will have a reference to an unfrozen type, which is rejected by Gigi -- (???). This requires specific care for definition of stream -- attributes. For details, see comments at the end of -- Build_Derived_Numeric_Type. Freeze_Before (N, Implicit_Base); end Derived_Standard_Character; ------------------------------ -- Derived_Type_Declaration -- ------------------------------ procedure Derived_Type_Declaration (T : Entity_Id; N : Node_Id; Is_Completion : Boolean) is Parent_Type : Entity_Id; function Comes_From_Generic (Typ : Entity_Id) return Boolean; -- Check whether the parent type is a generic formal, or derives -- directly or indirectly from one. ------------------------ -- Comes_From_Generic -- ------------------------ function Comes_From_Generic (Typ : Entity_Id) return Boolean is begin if Is_Generic_Type (Typ) then return True; elsif Is_Generic_Type (Root_Type (Parent_Type)) then return True; elsif Is_Private_Type (Typ) and then Present (Full_View (Typ)) and then Is_Generic_Type (Root_Type (Full_View (Typ))) then return True; elsif Is_Generic_Actual_Type (Typ) then return True; else return False; end if; end Comes_From_Generic; -- Local variables Def : constant Node_Id := Type_Definition (N); Iface_Def : Node_Id; Indic : constant Node_Id := Subtype_Indication (Def); Extension : constant Node_Id := Record_Extension_Part (Def); Parent_Node : Node_Id; Taggd : Boolean; -- Start of processing for Derived_Type_Declaration begin Parent_Type := Find_Type_Of_Subtype_Indic (Indic); -- Ada 2005 (AI-251): In case of interface derivation check that the -- parent is also an interface. if Interface_Present (Def) then Check_SPARK_05_Restriction ("interface is not allowed", Def); if not Is_Interface (Parent_Type) then Diagnose_Interface (Indic, Parent_Type); else Parent_Node := Parent (Base_Type (Parent_Type)); Iface_Def := Type_Definition (Parent_Node); -- Ada 2005 (AI-251): Limited interfaces can only inherit from -- other limited interfaces. if Limited_Present (Def) then if Limited_Present (Iface_Def) then null; elsif Protected_Present (Iface_Def) then Error_Msg_NE ("descendant of & must be declared as a protected " & "interface", N, Parent_Type); elsif Synchronized_Present (Iface_Def) then Error_Msg_NE ("descendant of & must be declared as a synchronized " & "interface", N, Parent_Type); elsif Task_Present (Iface_Def) then Error_Msg_NE ("descendant of & must be declared as a task interface", N, Parent_Type); else Error_Msg_N ("(Ada 2005) limited interface cannot inherit from " & "non-limited interface", Indic); end if; -- Ada 2005 (AI-345): Non-limited interfaces can only inherit -- from non-limited or limited interfaces. elsif not Protected_Present (Def) and then not Synchronized_Present (Def) and then not Task_Present (Def) then if Limited_Present (Iface_Def) then null; elsif Protected_Present (Iface_Def) then Error_Msg_NE ("descendant of & must be declared as a protected " & "interface", N, Parent_Type); elsif Synchronized_Present (Iface_Def) then Error_Msg_NE ("descendant of & must be declared as a synchronized " & "interface", N, Parent_Type); elsif Task_Present (Iface_Def) then Error_Msg_NE ("descendant of & must be declared as a task interface", N, Parent_Type); else null; end if; end if; end if; end if; if Is_Tagged_Type (Parent_Type) and then Is_Concurrent_Type (Parent_Type) and then not Is_Interface (Parent_Type) then Error_Msg_N ("parent type of a record extension cannot be a synchronized " & "tagged type (RM 3.9.1 (3/1))", N); Set_Etype (T, Any_Type); return; end if; -- Ada 2005 (AI-251): Decorate all the names in the list of ancestor -- interfaces if Is_Tagged_Type (Parent_Type) and then Is_Non_Empty_List (Interface_List (Def)) then declare Intf : Node_Id; T : Entity_Id; begin Intf := First (Interface_List (Def)); while Present (Intf) loop T := Find_Type_Of_Subtype_Indic (Intf); if not Is_Interface (T) then Diagnose_Interface (Intf, T); -- Check the rules of 3.9.4(12/2) and 7.5(2/2) that disallow -- a limited type from having a nonlimited progenitor. elsif (Limited_Present (Def) or else (not Is_Interface (Parent_Type) and then Is_Limited_Type (Parent_Type))) and then not Is_Limited_Interface (T) then Error_Msg_NE ("progenitor interface& of limited type must be limited", N, T); end if; Next (Intf); end loop; end; end if; if Parent_Type = Any_Type or else Etype (Parent_Type) = Any_Type or else (Is_Class_Wide_Type (Parent_Type) and then Etype (Parent_Type) = T) then -- If Parent_Type is undefined or illegal, make new type into a -- subtype of Any_Type, and set a few attributes to prevent cascaded -- errors. If this is a self-definition, emit error now. if T = Parent_Type or else T = Etype (Parent_Type) then Error_Msg_N ("type cannot be used in its own definition", Indic); end if; Set_Ekind (T, Ekind (Parent_Type)); Set_Etype (T, Any_Type); Set_Scalar_Range (T, Scalar_Range (Any_Type)); if Is_Tagged_Type (T) and then Is_Record_Type (T) then Set_Direct_Primitive_Operations (T, New_Elmt_List); end if; return; end if; -- Ada 2005 (AI-251): The case in which the parent of the full-view is -- an interface is special because the list of interfaces in the full -- view can be given in any order. For example: -- type A is interface; -- type B is interface and A; -- type D is new B with private; -- private -- type D is new A and B with null record; -- 1 -- -- In this case we perform the following transformation of -1-: -- type D is new B and A with null record; -- If the parent of the full-view covers the parent of the partial-view -- we have two possible cases: -- 1) They have the same parent -- 2) The parent of the full-view implements some further interfaces -- In both cases we do not need to perform the transformation. In the -- first case the source program is correct and the transformation is -- not needed; in the second case the source program does not fulfill -- the no-hidden interfaces rule (AI-396) and the error will be reported -- later. -- This transformation not only simplifies the rest of the analysis of -- this type declaration but also simplifies the correct generation of -- the object layout to the expander. if In_Private_Part (Current_Scope) and then Is_Interface (Parent_Type) then declare Iface : Node_Id; Partial_View : Entity_Id; Partial_View_Parent : Entity_Id; New_Iface : Node_Id; begin -- Look for the associated private type declaration Partial_View := First_Entity (Current_Scope); loop exit when No (Partial_View) or else (Has_Private_Declaration (Partial_View) and then Full_View (Partial_View) = T); Next_Entity (Partial_View); end loop; -- If the partial view was not found then the source code has -- errors and the transformation is not needed. if Present (Partial_View) then Partial_View_Parent := Etype (Partial_View); -- If the parent of the full-view covers the parent of the -- partial-view we have nothing else to do. if Interface_Present_In_Ancestor (Parent_Type, Partial_View_Parent) then null; -- Traverse the list of interfaces of the full-view to look -- for the parent of the partial-view and perform the tree -- transformation. else Iface := First (Interface_List (Def)); while Present (Iface) loop if Etype (Iface) = Etype (Partial_View) then Rewrite (Subtype_Indication (Def), New_Copy (Subtype_Indication (Parent (Partial_View)))); New_Iface := Make_Identifier (Sloc (N), Chars (Parent_Type)); Append (New_Iface, Interface_List (Def)); -- Analyze the transformed code Derived_Type_Declaration (T, N, Is_Completion); return; end if; Next (Iface); end loop; end if; end if; end; end if; -- Only composite types other than array types are allowed to have -- discriminants. if Present (Discriminant_Specifications (N)) then if (Is_Elementary_Type (Parent_Type) or else Is_Array_Type (Parent_Type)) and then not Error_Posted (N) then Error_Msg_N ("elementary or array type cannot have discriminants", Defining_Identifier (First (Discriminant_Specifications (N)))); Set_Has_Discriminants (T, False); -- The type is allowed to have discriminants else Check_SPARK_05_Restriction ("discriminant type is not allowed", N); end if; end if; -- In Ada 83, a derived type defined in a package specification cannot -- be used for further derivation until the end of its visible part. -- Note that derivation in the private part of the package is allowed. if Ada_Version = Ada_83 and then Is_Derived_Type (Parent_Type) and then In_Visible_Part (Scope (Parent_Type)) then if Ada_Version = Ada_83 and then Comes_From_Source (Indic) then Error_Msg_N ("(Ada 83): premature use of type for derivation", Indic); end if; end if; -- Check for early use of incomplete or private type if Ekind_In (Parent_Type, E_Void, E_Incomplete_Type) then Error_Msg_N ("premature derivation of incomplete type", Indic); return; elsif (Is_Incomplete_Or_Private_Type (Parent_Type) and then not Comes_From_Generic (Parent_Type)) or else Has_Private_Component (Parent_Type) then -- The ancestor type of a formal type can be incomplete, in which -- case only the operations of the partial view are available in the -- generic. Subsequent checks may be required when the full view is -- analyzed to verify that a derivation from a tagged type has an -- extension. if Nkind (Original_Node (N)) = N_Formal_Type_Declaration then null; elsif No (Underlying_Type (Parent_Type)) or else Has_Private_Component (Parent_Type) then Error_Msg_N ("premature derivation of derived or private type", Indic); -- Flag the type itself as being in error, this prevents some -- nasty problems with subsequent uses of the malformed type. Set_Error_Posted (T); -- Check that within the immediate scope of an untagged partial -- view it's illegal to derive from the partial view if the -- full view is tagged. (7.3(7)) -- We verify that the Parent_Type is a partial view by checking -- that it is not a Full_Type_Declaration (i.e. a private type or -- private extension declaration), to distinguish a partial view -- from a derivation from a private type which also appears as -- E_Private_Type. If the parent base type is not declared in an -- enclosing scope there is no need to check. elsif Present (Full_View (Parent_Type)) and then Nkind (Parent (Parent_Type)) /= N_Full_Type_Declaration and then not Is_Tagged_Type (Parent_Type) and then Is_Tagged_Type (Full_View (Parent_Type)) and then In_Open_Scopes (Scope (Base_Type (Parent_Type))) then Error_Msg_N ("premature derivation from type with tagged full view", Indic); end if; end if; -- Check that form of derivation is appropriate Taggd := Is_Tagged_Type (Parent_Type); -- Set the parent type to the class-wide type's specific type in this -- case to prevent cascading errors if Present (Extension) and then Is_Class_Wide_Type (Parent_Type) then Error_Msg_N ("parent type must not be a class-wide type", Indic); Set_Etype (T, Etype (Parent_Type)); return; end if; if Present (Extension) and then not Taggd then Error_Msg_N ("type derived from untagged type cannot have extension", Indic); elsif No (Extension) and then Taggd then -- If this declaration is within a private part (or body) of a -- generic instantiation then the derivation is allowed (the parent -- type can only appear tagged in this case if it's a generic actual -- type, since it would otherwise have been rejected in the analysis -- of the generic template). if not Is_Generic_Actual_Type (Parent_Type) or else In_Visible_Part (Scope (Parent_Type)) then if Is_Class_Wide_Type (Parent_Type) then Error_Msg_N ("parent type must not be a class-wide type", Indic); -- Use specific type to prevent cascaded errors. Parent_Type := Etype (Parent_Type); else Error_Msg_N ("type derived from tagged type must have extension", Indic); end if; end if; end if; -- AI-443: Synchronized formal derived types require a private -- extension. There is no point in checking the ancestor type or -- the progenitors since the construct is wrong to begin with. if Ada_Version >= Ada_2005 and then Is_Generic_Type (T) and then Present (Original_Node (N)) then declare Decl : constant Node_Id := Original_Node (N); begin if Nkind (Decl) = N_Formal_Type_Declaration and then Nkind (Formal_Type_Definition (Decl)) = N_Formal_Derived_Type_Definition and then Synchronized_Present (Formal_Type_Definition (Decl)) and then No (Extension) -- Avoid emitting a duplicate error message and then not Error_Posted (Indic) then Error_Msg_N ("synchronized derived type must have extension", N); end if; end; end if; if Null_Exclusion_Present (Def) and then not Is_Access_Type (Parent_Type) then Error_Msg_N ("null exclusion can only apply to an access type", N); end if; -- Avoid deriving parent primitives of underlying record views Build_Derived_Type (N, Parent_Type, T, Is_Completion, Derive_Subps => not Is_Underlying_Record_View (T)); -- AI-419: The parent type of an explicitly limited derived type must -- be a limited type or a limited interface. if Limited_Present (Def) then Set_Is_Limited_Record (T); if Is_Interface (T) then Set_Is_Limited_Interface (T); end if; if not Is_Limited_Type (Parent_Type) and then (not Is_Interface (Parent_Type) or else not Is_Limited_Interface (Parent_Type)) then -- AI05-0096: a derivation in the private part of an instance is -- legal if the generic formal is untagged limited, and the actual -- is non-limited. if Is_Generic_Actual_Type (Parent_Type) and then In_Private_Part (Current_Scope) and then not Is_Tagged_Type (Generic_Parent_Type (Parent (Parent_Type))) then null; else Error_Msg_NE ("parent type& of limited type must be limited", N, Parent_Type); end if; end if; end if; -- In SPARK, there are no derived type definitions other than type -- extensions of tagged record types. if No (Extension) then Check_SPARK_05_Restriction ("derived type is not allowed", Original_Node (N)); end if; end Derived_Type_Declaration; ------------------------ -- Diagnose_Interface -- ------------------------ procedure Diagnose_Interface (N : Node_Id; E : Entity_Id) is begin if not Is_Interface (E) and then E /= Any_Type then Error_Msg_NE ("(Ada 2005) & must be an interface", N, E); end if; end Diagnose_Interface; ---------------------------------- -- Enumeration_Type_Declaration -- ---------------------------------- procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id) is Ev : Uint; L : Node_Id; R_Node : Node_Id; B_Node : Node_Id; begin -- Create identifier node representing lower bound B_Node := New_Node (N_Identifier, Sloc (Def)); L := First (Literals (Def)); Set_Chars (B_Node, Chars (L)); Set_Entity (B_Node, L); Set_Etype (B_Node, T); Set_Is_Static_Expression (B_Node, True); R_Node := New_Node (N_Range, Sloc (Def)); Set_Low_Bound (R_Node, B_Node); Set_Ekind (T, E_Enumeration_Type); Set_First_Literal (T, L); Set_Etype (T, T); Set_Is_Constrained (T); Ev := Uint_0; -- Loop through literals of enumeration type setting pos and rep values -- except that if the Ekind is already set, then it means the literal -- was already constructed (case of a derived type declaration and we -- should not disturb the Pos and Rep values. while Present (L) loop if Ekind (L) /= E_Enumeration_Literal then Set_Ekind (L, E_Enumeration_Literal); Set_Enumeration_Pos (L, Ev); Set_Enumeration_Rep (L, Ev); Set_Is_Known_Valid (L, True); end if; Set_Etype (L, T); New_Overloaded_Entity (L); Generate_Definition (L); Set_Convention (L, Convention_Intrinsic); -- Case of character literal if Nkind (L) = N_Defining_Character_Literal then Set_Is_Character_Type (T, True); -- Check violation of No_Wide_Characters if Restriction_Check_Required (No_Wide_Characters) then Get_Name_String (Chars (L)); if Name_Len >= 3 and then Name_Buffer (1 .. 2) = "QW" then Check_Restriction (No_Wide_Characters, L); end if; end if; end if; Ev := Ev + 1; Next (L); end loop; -- Now create a node representing upper bound B_Node := New_Node (N_Identifier, Sloc (Def)); Set_Chars (B_Node, Chars (Last (Literals (Def)))); Set_Entity (B_Node, Last (Literals (Def))); Set_Etype (B_Node, T); Set_Is_Static_Expression (B_Node, True); Set_High_Bound (R_Node, B_Node); -- Initialize various fields of the type. Some of this information -- may be overwritten later through rep.clauses. Set_Scalar_Range (T, R_Node); Set_RM_Size (T, UI_From_Int (Minimum_Size (T))); Set_Enum_Esize (T); Set_Enum_Pos_To_Rep (T, Empty); -- Set Discard_Names if configuration pragma set, or if there is -- a parameterless pragma in the current declarative region if Global_Discard_Names or else Discard_Names (Scope (T)) then Set_Discard_Names (T); end if; -- Process end label if there is one if Present (Def) then Process_End_Label (Def, 'e', T); end if; end Enumeration_Type_Declaration; --------------------------------- -- Expand_To_Stored_Constraint -- --------------------------------- function Expand_To_Stored_Constraint (Typ : Entity_Id; Constraint : Elist_Id) return Elist_Id is Explicitly_Discriminated_Type : Entity_Id; Expansion : Elist_Id; Discriminant : Entity_Id; function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id; -- Find the nearest type that actually specifies discriminants --------------------------------- -- Type_With_Explicit_Discrims -- --------------------------------- function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id is Typ : constant E := Base_Type (Id); begin if Ekind (Typ) in Incomplete_Or_Private_Kind then if Present (Full_View (Typ)) then return Type_With_Explicit_Discrims (Full_View (Typ)); end if; else if Has_Discriminants (Typ) then return Typ; end if; end if; if Etype (Typ) = Typ then return Empty; elsif Has_Discriminants (Typ) then return Typ; else return Type_With_Explicit_Discrims (Etype (Typ)); end if; end Type_With_Explicit_Discrims; -- Start of processing for Expand_To_Stored_Constraint begin if No (Constraint) or else Is_Empty_Elmt_List (Constraint) then return No_Elist; end if; Explicitly_Discriminated_Type := Type_With_Explicit_Discrims (Typ); if No (Explicitly_Discriminated_Type) then return No_Elist; end if; Expansion := New_Elmt_List; Discriminant := First_Stored_Discriminant (Explicitly_Discriminated_Type); while Present (Discriminant) loop Append_Elmt (Get_Discriminant_Value (Discriminant, Explicitly_Discriminated_Type, Constraint), To => Expansion); Next_Stored_Discriminant (Discriminant); end loop; return Expansion; end Expand_To_Stored_Constraint; --------------------------- -- Find_Hidden_Interface -- --------------------------- function Find_Hidden_Interface (Src : Elist_Id; Dest : Elist_Id) return Entity_Id is Iface : Entity_Id; Iface_Elmt : Elmt_Id; begin if Present (Src) and then Present (Dest) then Iface_Elmt := First_Elmt (Src); while Present (Iface_Elmt) loop Iface := Node (Iface_Elmt); if Is_Interface (Iface) and then not Contain_Interface (Iface, Dest) then return Iface; end if; Next_Elmt (Iface_Elmt); end loop; end if; return Empty; end Find_Hidden_Interface; -------------------- -- Find_Type_Name -- -------------------- function Find_Type_Name (N : Node_Id) return Entity_Id is Id : constant Entity_Id := Defining_Identifier (N); New_Id : Entity_Id; Prev : Entity_Id; Prev_Par : Node_Id; procedure Check_Duplicate_Aspects; -- Check that aspects specified in a completion have not been specified -- already in the partial view. procedure Tag_Mismatch; -- Diagnose a tagged partial view whose full view is untagged. We post -- the message on the full view, with a reference to the previous -- partial view. The partial view can be private or incomplete, and -- these are handled in a different manner, so we determine the position -- of the error message from the respective slocs of both. ----------------------------- -- Check_Duplicate_Aspects -- ----------------------------- procedure Check_Duplicate_Aspects is function Get_Partial_View_Aspect (Asp : Node_Id) return Node_Id; -- Return the corresponding aspect of the partial view which matches -- the aspect id of Asp. Return Empty is no such aspect exists. ----------------------------- -- Get_Partial_View_Aspect -- ----------------------------- function Get_Partial_View_Aspect (Asp : Node_Id) return Node_Id is Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp); Prev_Asps : constant List_Id := Aspect_Specifications (Prev_Par); Prev_Asp : Node_Id; begin if Present (Prev_Asps) then Prev_Asp := First (Prev_Asps); while Present (Prev_Asp) loop if Get_Aspect_Id (Prev_Asp) = Asp_Id then return Prev_Asp; end if; Next (Prev_Asp); end loop; end if; return Empty; end Get_Partial_View_Aspect; -- Local variables Full_Asps : constant List_Id := Aspect_Specifications (N); Full_Asp : Node_Id; Part_Asp : Node_Id; -- Start of processing for Check_Duplicate_Aspects begin if Present (Full_Asps) then Full_Asp := First (Full_Asps); while Present (Full_Asp) loop Part_Asp := Get_Partial_View_Aspect (Full_Asp); -- An aspect and its class-wide counterpart are two distinct -- aspects and may apply to both views of an entity. if Present (Part_Asp) and then Class_Present (Part_Asp) = Class_Present (Full_Asp) then Error_Msg_N ("aspect already specified in private declaration", Full_Asp); Remove (Full_Asp); return; end if; if Has_Discriminants (Prev) and then not Has_Unknown_Discriminants (Prev) and then Get_Aspect_Id (Full_Asp) = Aspect_Implicit_Dereference then Error_Msg_N ("cannot specify aspect if partial view has known " & "discriminants", Full_Asp); end if; Next (Full_Asp); end loop; end if; end Check_Duplicate_Aspects; ------------------ -- Tag_Mismatch -- ------------------ procedure Tag_Mismatch is begin if Sloc (Prev) < Sloc (Id) then if Ada_Version >= Ada_2012 and then Nkind (N) = N_Private_Type_Declaration then Error_Msg_NE ("declaration of private } must be a tagged type ", Id, Prev); else Error_Msg_NE ("full declaration of } must be a tagged type ", Id, Prev); end if; else if Ada_Version >= Ada_2012 and then Nkind (N) = N_Private_Type_Declaration then Error_Msg_NE ("declaration of private } must be a tagged type ", Prev, Id); else Error_Msg_NE ("full declaration of } must be a tagged type ", Prev, Id); end if; end if; end Tag_Mismatch; -- Start of processing for Find_Type_Name begin -- Find incomplete declaration, if one was given Prev := Current_Entity_In_Scope (Id); -- New type declaration if No (Prev) then Enter_Name (Id); return Id; -- Previous declaration exists else Prev_Par := Parent (Prev); -- Error if not incomplete/private case except if previous -- declaration is implicit, etc. Enter_Name will emit error if -- appropriate. if not Is_Incomplete_Or_Private_Type (Prev) then Enter_Name (Id); New_Id := Id; -- Check invalid completion of private or incomplete type elsif not Nkind_In (N, N_Full_Type_Declaration, N_Task_Type_Declaration, N_Protected_Type_Declaration) and then (Ada_Version < Ada_2012 or else not Is_Incomplete_Type (Prev) or else not Nkind_In (N, N_Private_Type_Declaration, N_Private_Extension_Declaration)) then -- Completion must be a full type declarations (RM 7.3(4)) Error_Msg_Sloc := Sloc (Prev); Error_Msg_NE ("invalid completion of }", Id, Prev); -- Set scope of Id to avoid cascaded errors. Entity is never -- examined again, except when saving globals in generics. Set_Scope (Id, Current_Scope); New_Id := Id; -- If this is a repeated incomplete declaration, no further -- checks are possible. if Nkind (N) = N_Incomplete_Type_Declaration then return Prev; end if; -- Case of full declaration of incomplete type elsif Ekind (Prev) = E_Incomplete_Type and then (Ada_Version < Ada_2012 or else No (Full_View (Prev)) or else not Is_Private_Type (Full_View (Prev))) then -- Indicate that the incomplete declaration has a matching full -- declaration. The defining occurrence of the incomplete -- declaration remains the visible one, and the procedure -- Get_Full_View dereferences it whenever the type is used. if Present (Full_View (Prev)) then Error_Msg_NE ("invalid redeclaration of }", Id, Prev); end if; Set_Full_View (Prev, Id); Append_Entity (Id, Current_Scope); Set_Is_Public (Id, Is_Public (Prev)); Set_Is_Internal (Id); New_Id := Prev; -- If the incomplete view is tagged, a class_wide type has been -- created already. Use it for the private type as well, in order -- to prevent multiple incompatible class-wide types that may be -- created for self-referential anonymous access components. if Is_Tagged_Type (Prev) and then Present (Class_Wide_Type (Prev)) then Set_Ekind (Id, Ekind (Prev)); -- will be reset later Set_Class_Wide_Type (Id, Class_Wide_Type (Prev)); -- Type of the class-wide type is the current Id. Previously -- this was not done for private declarations because of order- -- of-elaboration issues in the back end, but gigi now handles -- this properly. Set_Etype (Class_Wide_Type (Id), Id); end if; -- Case of full declaration of private type else -- If the private type was a completion of an incomplete type then -- update Prev to reference the private type if Ada_Version >= Ada_2012 and then Ekind (Prev) = E_Incomplete_Type and then Present (Full_View (Prev)) and then Is_Private_Type (Full_View (Prev)) then Prev := Full_View (Prev); Prev_Par := Parent (Prev); end if; if Nkind (N) = N_Full_Type_Declaration and then Nkind_In (Type_Definition (N), N_Record_Definition, N_Derived_Type_Definition) and then Interface_Present (Type_Definition (N)) then Error_Msg_N ("completion of private type cannot be an interface", N); end if; if Nkind (Parent (Prev)) /= N_Private_Extension_Declaration then if Etype (Prev) /= Prev then -- Prev is a private subtype or a derived type, and needs -- no completion. Error_Msg_NE ("invalid redeclaration of }", Id, Prev); New_Id := Id; elsif Ekind (Prev) = E_Private_Type and then Nkind_In (N, N_Task_Type_Declaration, N_Protected_Type_Declaration) then Error_Msg_N ("completion of nonlimited type cannot be limited", N); elsif Ekind (Prev) = E_Record_Type_With_Private and then Nkind_In (N, N_Task_Type_Declaration, N_Protected_Type_Declaration) then if not Is_Limited_Record (Prev) then Error_Msg_N ("completion of nonlimited type cannot be limited", N); elsif No (Interface_List (N)) then Error_Msg_N ("completion of tagged private type must be tagged", N); end if; end if; -- Ada 2005 (AI-251): Private extension declaration of a task -- type or a protected type. This case arises when covering -- interface types. elsif Nkind_In (N, N_Task_Type_Declaration, N_Protected_Type_Declaration) then null; elsif Nkind (N) /= N_Full_Type_Declaration or else Nkind (Type_Definition (N)) /= N_Derived_Type_Definition then Error_Msg_N ("full view of private extension must be an extension", N); elsif not (Abstract_Present (Parent (Prev))) and then Abstract_Present (Type_Definition (N)) then Error_Msg_N ("full view of non-abstract extension cannot be abstract", N); end if; if not In_Private_Part (Current_Scope) then Error_Msg_N ("declaration of full view must appear in private part", N); end if; if Ada_Version >= Ada_2012 then Check_Duplicate_Aspects; end if; Copy_And_Swap (Prev, Id); Set_Has_Private_Declaration (Prev); Set_Has_Private_Declaration (Id); -- AI12-0133: Indicate whether we have a partial view with -- unknown discriminants, in which case initialization of objects -- of the type do not receive an invariant check. Set_Partial_View_Has_Unknown_Discr (Prev, Has_Unknown_Discriminants (Id)); -- Preserve aspect and iterator flags that may have been set on -- the partial view. Set_Has_Delayed_Aspects (Prev, Has_Delayed_Aspects (Id)); Set_Has_Implicit_Dereference (Prev, Has_Implicit_Dereference (Id)); -- If no error, propagate freeze_node from private to full view. -- It may have been generated for an early operational item. if Present (Freeze_Node (Id)) and then Serious_Errors_Detected = 0 and then No (Full_View (Id)) then Set_Freeze_Node (Prev, Freeze_Node (Id)); Set_Freeze_Node (Id, Empty); Set_First_Rep_Item (Prev, First_Rep_Item (Id)); end if; Set_Full_View (Id, Prev); New_Id := Prev; end if; -- Verify that full declaration conforms to partial one if Is_Incomplete_Or_Private_Type (Prev) and then Present (Discriminant_Specifications (Prev_Par)) then if Present (Discriminant_Specifications (N)) then if Ekind (Prev) = E_Incomplete_Type then Check_Discriminant_Conformance (N, Prev, Prev); else Check_Discriminant_Conformance (N, Prev, Id); end if; else Error_Msg_N ("missing discriminants in full type declaration", N); -- To avoid cascaded errors on subsequent use, share the -- discriminants of the partial view. Set_Discriminant_Specifications (N, Discriminant_Specifications (Prev_Par)); end if; end if; -- A prior untagged partial view can have an associated class-wide -- type due to use of the class attribute, and in this case the full -- type must also be tagged. This Ada 95 usage is deprecated in favor -- of incomplete tagged declarations, but we check for it. if Is_Type (Prev) and then (Is_Tagged_Type (Prev) or else Present (Class_Wide_Type (Prev))) then -- Ada 2012 (AI05-0162): A private type may be the completion of -- an incomplete type. if Ada_Version >= Ada_2012 and then Is_Incomplete_Type (Prev) and then Nkind_In (N, N_Private_Type_Declaration, N_Private_Extension_Declaration) then -- No need to check private extensions since they are tagged if Nkind (N) = N_Private_Type_Declaration and then not Tagged_Present (N) then Tag_Mismatch; end if; -- The full declaration is either a tagged type (including -- a synchronized type that implements interfaces) or a -- type extension, otherwise this is an error. elsif Nkind_In (N, N_Task_Type_Declaration, N_Protected_Type_Declaration) then if No (Interface_List (N)) and then not Error_Posted (N) then Tag_Mismatch; end if; elsif Nkind (Type_Definition (N)) = N_Record_Definition then -- Indicate that the previous declaration (tagged incomplete -- or private declaration) requires the same on the full one. if not Tagged_Present (Type_Definition (N)) then Tag_Mismatch; Set_Is_Tagged_Type (Id); end if; elsif Nkind (Type_Definition (N)) = N_Derived_Type_Definition then if No (Record_Extension_Part (Type_Definition (N))) then Error_Msg_NE ("full declaration of } must be a record extension", Prev, Id); -- Set some attributes to produce a usable full view Set_Is_Tagged_Type (Id); end if; else Tag_Mismatch; end if; end if; if Present (Prev) and then Nkind (Parent (Prev)) = N_Incomplete_Type_Declaration and then Present (Premature_Use (Parent (Prev))) then Error_Msg_Sloc := Sloc (N); Error_Msg_N ("\full declaration #", Premature_Use (Parent (Prev))); end if; return New_Id; end if; end Find_Type_Name; ------------------------- -- Find_Type_Of_Object -- ------------------------- function Find_Type_Of_Object (Obj_Def : Node_Id; Related_Nod : Node_Id) return Entity_Id is Def_Kind : constant Node_Kind := Nkind (Obj_Def); P : Node_Id := Parent (Obj_Def); T : Entity_Id; Nam : Name_Id; begin -- If the parent is a component_definition node we climb to the -- component_declaration node if Nkind (P) = N_Component_Definition then P := Parent (P); end if; -- Case of an anonymous array subtype if Nkind_In (Def_Kind, N_Constrained_Array_Definition, N_Unconstrained_Array_Definition) then T := Empty; Array_Type_Declaration (T, Obj_Def); -- Create an explicit subtype whenever possible elsif Nkind (P) /= N_Component_Declaration and then Def_Kind = N_Subtype_Indication then -- Base name of subtype on object name, which will be unique in -- the current scope. -- If this is a duplicate declaration, return base type, to avoid -- generating duplicate anonymous types. if Error_Posted (P) then Analyze (Subtype_Mark (Obj_Def)); return Entity (Subtype_Mark (Obj_Def)); end if; Nam := New_External_Name (Chars (Defining_Identifier (Related_Nod)), 'S', 0, 'T'); T := Make_Defining_Identifier (Sloc (P), Nam); Insert_Action (Obj_Def, Make_Subtype_Declaration (Sloc (P), Defining_Identifier => T, Subtype_Indication => Relocate_Node (Obj_Def))); -- This subtype may need freezing, and this will not be done -- automatically if the object declaration is not in declarative -- part. Since this is an object declaration, the type cannot always -- be frozen here. Deferred constants do not freeze their type -- (which often enough will be private). if Nkind (P) = N_Object_Declaration and then Constant_Present (P) and then No (Expression (P)) then null; -- Here we freeze the base type of object type to catch premature use -- of discriminated private type without a full view. else Insert_Actions (Obj_Def, Freeze_Entity (Base_Type (T), P)); end if; -- Ada 2005 AI-406: the object definition in an object declaration -- can be an access definition. elsif Def_Kind = N_Access_Definition then T := Access_Definition (Related_Nod, Obj_Def); Set_Is_Local_Anonymous_Access (T, V => (Ada_Version < Ada_2012) or else (Nkind (P) /= N_Object_Declaration) or else Is_Library_Level_Entity (Defining_Identifier (P))); -- Otherwise, the object definition is just a subtype_mark else T := Process_Subtype (Obj_Def, Related_Nod); -- If expansion is disabled an object definition that is an aggregate -- will not get expanded and may lead to scoping problems in the back -- end, if the object is referenced in an inner scope. In that case -- create an itype reference for the object definition now. This -- may be redundant in some cases, but harmless. if Is_Itype (T) and then Nkind (Related_Nod) = N_Object_Declaration and then ASIS_Mode then Build_Itype_Reference (T, Related_Nod); end if; end if; return T; end Find_Type_Of_Object; -------------------------------- -- Find_Type_Of_Subtype_Indic -- -------------------------------- function Find_Type_Of_Subtype_Indic (S : Node_Id) return Entity_Id is Typ : Entity_Id; begin -- Case of subtype mark with a constraint if Nkind (S) = N_Subtype_Indication then Find_Type (Subtype_Mark (S)); Typ := Entity (Subtype_Mark (S)); if not Is_Valid_Constraint_Kind (Ekind (Typ), Nkind (Constraint (S))) then Error_Msg_N ("incorrect constraint for this kind of type", Constraint (S)); Rewrite (S, New_Copy_Tree (Subtype_Mark (S))); end if; -- Otherwise we have a subtype mark without a constraint elsif Error_Posted (S) then Rewrite (S, New_Occurrence_Of (Any_Id, Sloc (S))); return Any_Type; else Find_Type (S); Typ := Entity (S); end if; -- Check No_Wide_Characters restriction Check_Wide_Character_Restriction (Typ, S); return Typ; end Find_Type_Of_Subtype_Indic; ------------------------------------- -- Floating_Point_Type_Declaration -- ------------------------------------- procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id) is Digs : constant Node_Id := Digits_Expression (Def); Max_Digs_Val : constant Uint := Digits_Value (Standard_Long_Long_Float); Digs_Val : Uint; Base_Typ : Entity_Id; Implicit_Base : Entity_Id; Bound : Node_Id; function Can_Derive_From (E : Entity_Id) return Boolean; -- Find if given digits value, and possibly a specified range, allows -- derivation from specified type function Find_Base_Type return Entity_Id; -- Find a predefined base type that Def can derive from, or generate -- an error and substitute Long_Long_Float if none exists. --------------------- -- Can_Derive_From -- --------------------- function Can_Derive_From (E : Entity_Id) return Boolean is Spec : constant Entity_Id := Real_Range_Specification (Def); begin -- Check specified "digits" constraint if Digs_Val > Digits_Value (E) then return False; end if; -- Check for matching range, if specified if Present (Spec) then if Expr_Value_R (Type_Low_Bound (E)) > Expr_Value_R (Low_Bound (Spec)) then return False; end if; if Expr_Value_R (Type_High_Bound (E)) < Expr_Value_R (High_Bound (Spec)) then return False; end if; end if; return True; end Can_Derive_From; -------------------- -- Find_Base_Type -- -------------------- function Find_Base_Type return Entity_Id is Choice : Elmt_Id := First_Elmt (Predefined_Float_Types); begin -- Iterate over the predefined types in order, returning the first -- one that Def can derive from. while Present (Choice) loop if Can_Derive_From (Node (Choice)) then return Node (Choice); end if; Next_Elmt (Choice); end loop; -- If we can't derive from any existing type, use Long_Long_Float -- and give appropriate message explaining the problem. if Digs_Val > Max_Digs_Val then -- It might be the case that there is a type with the requested -- range, just not the combination of digits and range. Error_Msg_N ("no predefined type has requested range and precision", Real_Range_Specification (Def)); else Error_Msg_N ("range too large for any predefined type", Real_Range_Specification (Def)); end if; return Standard_Long_Long_Float; end Find_Base_Type; -- Start of processing for Floating_Point_Type_Declaration begin Check_Restriction (No_Floating_Point, Def); -- Create an implicit base type Implicit_Base := Create_Itype (E_Floating_Point_Type, Parent (Def), T, 'B'); -- Analyze and verify digits value Analyze_And_Resolve (Digs, Any_Integer); Check_Digits_Expression (Digs); Digs_Val := Expr_Value (Digs); -- Process possible range spec and find correct type to derive from Process_Real_Range_Specification (Def); -- Check that requested number of digits is not too high. if Digs_Val > Max_Digs_Val then -- The check for Max_Base_Digits may be somewhat expensive, as it -- requires reading System, so only do it when necessary. declare Max_Base_Digits : constant Uint := Expr_Value (Expression (Parent (RTE (RE_Max_Base_Digits)))); begin if Digs_Val > Max_Base_Digits then Error_Msg_Uint_1 := Max_Base_Digits; Error_Msg_N ("digits value out of range, maximum is ^", Digs); elsif No (Real_Range_Specification (Def)) then Error_Msg_Uint_1 := Max_Digs_Val; Error_Msg_N ("types with more than ^ digits need range spec " & "(RM 3.5.7(6))", Digs); end if; end; end if; -- Find a suitable type to derive from or complain and use a substitute Base_Typ := Find_Base_Type; -- If there are bounds given in the declaration use them as the bounds -- of the type, otherwise use the bounds of the predefined base type -- that was chosen based on the Digits value. if Present (Real_Range_Specification (Def)) then Set_Scalar_Range (T, Real_Range_Specification (Def)); Set_Is_Constrained (T); -- The bounds of this range must be converted to machine numbers -- in accordance with RM 4.9(38). Bound := Type_Low_Bound (T); if Nkind (Bound) = N_Real_Literal then Set_Realval (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound)); Set_Is_Machine_Number (Bound); end if; Bound := Type_High_Bound (T); if Nkind (Bound) = N_Real_Literal then Set_Realval (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound)); Set_Is_Machine_Number (Bound); end if; else Set_Scalar_Range (T, Scalar_Range (Base_Typ)); end if; -- Complete definition of implicit base and declared first subtype. The -- inheritance of the rep item chain ensures that SPARK-related pragmas -- are not clobbered when the floating point type acts as a full view of -- a private type. Set_Etype (Implicit_Base, Base_Typ); Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ)); Set_Size_Info (Implicit_Base, Base_Typ); Set_RM_Size (Implicit_Base, RM_Size (Base_Typ)); Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ)); Set_Digits_Value (Implicit_Base, Digits_Value (Base_Typ)); Set_Float_Rep (Implicit_Base, Float_Rep (Base_Typ)); Set_Ekind (T, E_Floating_Point_Subtype); Set_Etype (T, Implicit_Base); Set_Size_Info (T, Implicit_Base); Set_RM_Size (T, RM_Size (Implicit_Base)); Inherit_Rep_Item_Chain (T, Implicit_Base); Set_Digits_Value (T, Digs_Val); end Floating_Point_Type_Declaration; ---------------------------- -- Get_Discriminant_Value -- ---------------------------- -- This is the situation: -- There is a non-derived type -- type T0 (Dx, Dy, Dz...) -- There are zero or more levels of derivation, with each derivation -- either purely inheriting the discriminants, or defining its own. -- type Ti is new Ti-1 -- or -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y) -- or -- subtype Ti is ... -- The subtype issue is avoided by the use of Original_Record_Component, -- and the fact that derived subtypes also derive the constraints. -- This chain leads back from -- Typ_For_Constraint -- Typ_For_Constraint has discriminants, and the value for each -- discriminant is given by its corresponding Elmt of Constraints. -- Discriminant is some discriminant in this hierarchy -- We need to return its value -- We do this by recursively searching each level, and looking for -- Discriminant. Once we get to the bottom, we start backing up -- returning the value for it which may in turn be a discriminant -- further up, so on the backup we continue the substitution. function Get_Discriminant_Value (Discriminant : Entity_Id; Typ_For_Constraint : Entity_Id; Constraint : Elist_Id) return Node_Id is function Root_Corresponding_Discriminant (Discr : Entity_Id) return Entity_Id; -- Given a discriminant, traverse the chain of inherited discriminants -- and return the topmost discriminant. function Search_Derivation_Levels (Ti : Entity_Id; Discrim_Values : Elist_Id; Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id; -- This is the routine that performs the recursive search of levels -- as described above. ------------------------------------- -- Root_Corresponding_Discriminant -- ------------------------------------- function Root_Corresponding_Discriminant (Discr : Entity_Id) return Entity_Id is D : Entity_Id; begin D := Discr; while Present (Corresponding_Discriminant (D)) loop D := Corresponding_Discriminant (D); end loop; return D; end Root_Corresponding_Discriminant; ------------------------------ -- Search_Derivation_Levels -- ------------------------------ function Search_Derivation_Levels (Ti : Entity_Id; Discrim_Values : Elist_Id; Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id is Assoc : Elmt_Id; Disc : Entity_Id; Result : Node_Or_Entity_Id; Result_Entity : Node_Id; begin -- If inappropriate type, return Error, this happens only in -- cascaded error situations, and we want to avoid a blow up. if not Is_Composite_Type (Ti) or else Is_Array_Type (Ti) then return Error; end if; -- Look deeper if possible. Use Stored_Constraints only for -- untagged types. For tagged types use the given constraint. -- This asymmetry needs explanation??? if not Stored_Discrim_Values and then Present (Stored_Constraint (Ti)) and then not Is_Tagged_Type (Ti) then Result := Search_Derivation_Levels (Ti, Stored_Constraint (Ti), True); else declare Td : constant Entity_Id := Etype (Ti); begin if Td = Ti then Result := Discriminant; else if Present (Stored_Constraint (Ti)) then Result := Search_Derivation_Levels (Td, Stored_Constraint (Ti), True); else Result := Search_Derivation_Levels (Td, Discrim_Values, Stored_Discrim_Values); end if; end if; end; end if; -- Extra underlying places to search, if not found above. For -- concurrent types, the relevant discriminant appears in the -- corresponding record. For a type derived from a private type -- without discriminant, the full view inherits the discriminants -- of the full view of the parent. if Result = Discriminant then if Is_Concurrent_Type (Ti) and then Present (Corresponding_Record_Type (Ti)) then Result := Search_Derivation_Levels ( Corresponding_Record_Type (Ti), Discrim_Values, Stored_Discrim_Values); elsif Is_Private_Type (Ti) and then not Has_Discriminants (Ti) and then Present (Full_View (Ti)) and then Etype (Full_View (Ti)) /= Ti then Result := Search_Derivation_Levels ( Full_View (Ti), Discrim_Values, Stored_Discrim_Values); end if; end if; -- If Result is not a (reference to a) discriminant, return it, -- otherwise set Result_Entity to the discriminant. if Nkind (Result) = N_Defining_Identifier then pragma Assert (Result = Discriminant); Result_Entity := Result; else if not Denotes_Discriminant (Result) then return Result; end if; Result_Entity := Entity (Result); end if; -- See if this level of derivation actually has discriminants because -- tagged derivations can add them, hence the lower levels need not -- have any. if not Has_Discriminants (Ti) then return Result; end if; -- Scan Ti's discriminants for Result_Entity, and return its -- corresponding value, if any. Result_Entity := Original_Record_Component (Result_Entity); Assoc := First_Elmt (Discrim_Values); if Stored_Discrim_Values then Disc := First_Stored_Discriminant (Ti); else Disc := First_Discriminant (Ti); end if; while Present (Disc) loop -- If no further associations return the discriminant, value will -- be found on the second pass. if No (Assoc) then return Result; end if; if Original_Record_Component (Disc) = Result_Entity then return Node (Assoc); end if; Next_Elmt (Assoc); if Stored_Discrim_Values then Next_Stored_Discriminant (Disc); else Next_Discriminant (Disc); end if; end loop; -- Could not find it return Result; end Search_Derivation_Levels; -- Local Variables Result : Node_Or_Entity_Id; -- Start of processing for Get_Discriminant_Value begin -- ??? This routine is a gigantic mess and will be deleted. For the -- time being just test for the trivial case before calling recurse. -- We are now celebrating the 20th anniversary of this comment! if Base_Type (Scope (Discriminant)) = Base_Type (Typ_For_Constraint) then declare D : Entity_Id; E : Elmt_Id; begin D := First_Discriminant (Typ_For_Constraint); E := First_Elmt (Constraint); while Present (D) loop if Chars (D) = Chars (Discriminant) then return Node (E); end if; Next_Discriminant (D); Next_Elmt (E); end loop; end; end if; Result := Search_Derivation_Levels (Typ_For_Constraint, Constraint, False); -- ??? hack to disappear when this routine is gone if Nkind (Result) = N_Defining_Identifier then declare D : Entity_Id; E : Elmt_Id; begin D := First_Discriminant (Typ_For_Constraint); E := First_Elmt (Constraint); while Present (D) loop if Root_Corresponding_Discriminant (D) = Discriminant then return Node (E); end if; Next_Discriminant (D); Next_Elmt (E); end loop; end; end if; pragma Assert (Nkind (Result) /= N_Defining_Identifier); return Result; end Get_Discriminant_Value; -------------------------- -- Has_Range_Constraint -- -------------------------- function Has_Range_Constraint (N : Node_Id) return Boolean is C : constant Node_Id := Constraint (N); begin if Nkind (C) = N_Range_Constraint then return True; elsif Nkind (C) = N_Digits_Constraint then return Is_Decimal_Fixed_Point_Type (Entity (Subtype_Mark (N))) or else Present (Range_Constraint (C)); elsif Nkind (C) = N_Delta_Constraint then return Present (Range_Constraint (C)); else return False; end if; end Has_Range_Constraint; ------------------------ -- Inherit_Components -- ------------------------ function Inherit_Components (N : Node_Id; Parent_Base : Entity_Id; Derived_Base : Entity_Id; Is_Tagged : Boolean; Inherit_Discr : Boolean; Discs : Elist_Id) return Elist_Id is Assoc_List : constant Elist_Id := New_Elmt_List; procedure Inherit_Component (Old_C : Entity_Id; Plain_Discrim : Boolean := False; Stored_Discrim : Boolean := False); -- Inherits component Old_C from Parent_Base to the Derived_Base. If -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is -- True, Old_C is a stored discriminant. If they are both false then -- Old_C is a regular component. ----------------------- -- Inherit_Component -- ----------------------- procedure Inherit_Component (Old_C : Entity_Id; Plain_Discrim : Boolean := False; Stored_Discrim : Boolean := False) is procedure Set_Anonymous_Type (Id : Entity_Id); -- Id denotes the entity of an access discriminant or anonymous -- access component. Set the type of Id to either the same type of -- Old_C or create a new one depending on whether the parent and -- the child types are in the same scope. ------------------------ -- Set_Anonymous_Type -- ------------------------ procedure Set_Anonymous_Type (Id : Entity_Id) is Old_Typ : constant Entity_Id := Etype (Old_C); begin if Scope (Parent_Base) = Scope (Derived_Base) then Set_Etype (Id, Old_Typ); -- The parent and the derived type are in two different scopes. -- Reuse the type of the original discriminant / component by -- copying it in order to preserve all attributes. else declare Typ : constant Entity_Id := New_Copy (Old_Typ); begin Set_Etype (Id, Typ); -- Since we do not generate component declarations for -- inherited components, associate the itype with the -- derived type. Set_Associated_Node_For_Itype (Typ, Parent (Derived_Base)); Set_Scope (Typ, Derived_Base); end; end if; end Set_Anonymous_Type; -- Local variables and constants New_C : constant Entity_Id := New_Copy (Old_C); Corr_Discrim : Entity_Id; Discrim : Entity_Id; -- Start of processing for Inherit_Component begin pragma Assert (not Is_Tagged or not Stored_Discrim); Set_Parent (New_C, Parent (Old_C)); -- Regular discriminants and components must be inserted in the scope -- of the Derived_Base. Do it here. if not Stored_Discrim then Enter_Name (New_C); end if; -- For tagged types the Original_Record_Component must point to -- whatever this field was pointing to in the parent type. This has -- already been achieved by the call to New_Copy above. if not Is_Tagged then Set_Original_Record_Component (New_C, New_C); end if; -- Set the proper type of an access discriminant if Ekind (New_C) = E_Discriminant and then Ekind (Etype (New_C)) = E_Anonymous_Access_Type then Set_Anonymous_Type (New_C); end if; -- If we have inherited a component then see if its Etype contains -- references to Parent_Base discriminants. In this case, replace -- these references with the constraints given in Discs. We do not -- do this for the partial view of private types because this is -- not needed (only the components of the full view will be used -- for code generation) and cause problem. We also avoid this -- transformation in some error situations. if Ekind (New_C) = E_Component then -- Set the proper type of an anonymous access component if Ekind (Etype (New_C)) = E_Anonymous_Access_Type then Set_Anonymous_Type (New_C); elsif (Is_Private_Type (Derived_Base) and then not Is_Generic_Type (Derived_Base)) or else (Is_Empty_Elmt_List (Discs) and then not Expander_Active) then Set_Etype (New_C, Etype (Old_C)); else -- The current component introduces a circularity of the -- following kind: -- limited with Pack_2; -- package Pack_1 is -- type T_1 is tagged record -- Comp : access Pack_2.T_2; -- ... -- end record; -- end Pack_1; -- with Pack_1; -- package Pack_2 is -- type T_2 is new Pack_1.T_1 with ...; -- end Pack_2; Set_Etype (New_C, Constrain_Component_Type (Old_C, Derived_Base, N, Parent_Base, Discs)); end if; end if; -- In derived tagged types it is illegal to reference a non -- discriminant component in the parent type. To catch this, mark -- these components with an Ekind of E_Void. This will be reset in -- Record_Type_Definition after processing the record extension of -- the derived type. -- If the declaration is a private extension, there is no further -- record extension to process, and the components retain their -- current kind, because they are visible at this point. if Is_Tagged and then Ekind (New_C) = E_Component and then Nkind (N) /= N_Private_Extension_Declaration then Set_Ekind (New_C, E_Void); end if; if Plain_Discrim then Set_Corresponding_Discriminant (New_C, Old_C); Build_Discriminal (New_C); -- If we are explicitly inheriting a stored discriminant it will be -- completely hidden. elsif Stored_Discrim then Set_Corresponding_Discriminant (New_C, Empty); Set_Discriminal (New_C, Empty); Set_Is_Completely_Hidden (New_C); -- Set the Original_Record_Component of each discriminant in the -- derived base to point to the corresponding stored that we just -- created. Discrim := First_Discriminant (Derived_Base); while Present (Discrim) loop Corr_Discrim := Corresponding_Discriminant (Discrim); -- Corr_Discrim could be missing in an error situation if Present (Corr_Discrim) and then Original_Record_Component (Corr_Discrim) = Old_C then Set_Original_Record_Component (Discrim, New_C); end if; Next_Discriminant (Discrim); end loop; Append_Entity (New_C, Derived_Base); end if; if not Is_Tagged then Append_Elmt (Old_C, Assoc_List); Append_Elmt (New_C, Assoc_List); end if; end Inherit_Component; -- Variables local to Inherit_Component Loc : constant Source_Ptr := Sloc (N); Parent_Discrim : Entity_Id; Stored_Discrim : Entity_Id; D : Entity_Id; Component : Entity_Id; -- Start of processing for Inherit_Components begin if not Is_Tagged then Append_Elmt (Parent_Base, Assoc_List); Append_Elmt (Derived_Base, Assoc_List); end if; -- Inherit parent discriminants if needed if Inherit_Discr then Parent_Discrim := First_Discriminant (Parent_Base); while Present (Parent_Discrim) loop Inherit_Component (Parent_Discrim, Plain_Discrim => True); Next_Discriminant (Parent_Discrim); end loop; end if; -- Create explicit stored discrims for untagged types when necessary if not Has_Unknown_Discriminants (Derived_Base) and then Has_Discriminants (Parent_Base) and then not Is_Tagged and then (not Inherit_Discr or else First_Discriminant (Parent_Base) /= First_Stored_Discriminant (Parent_Base)) then Stored_Discrim := First_Stored_Discriminant (Parent_Base); while Present (Stored_Discrim) loop Inherit_Component (Stored_Discrim, Stored_Discrim => True); Next_Stored_Discriminant (Stored_Discrim); end loop; end if; -- See if we can apply the second transformation for derived types, as -- explained in point 6. in the comments above Build_Derived_Record_Type -- This is achieved by appending Derived_Base discriminants into Discs, -- which has the side effect of returning a non empty Discs list to the -- caller of Inherit_Components, which is what we want. This must be -- done for private derived types if there are explicit stored -- discriminants, to ensure that we can retrieve the values of the -- constraints provided in the ancestors. if Inherit_Discr and then Is_Empty_Elmt_List (Discs) and then Present (First_Discriminant (Derived_Base)) and then (not Is_Private_Type (Derived_Base) or else Is_Completely_Hidden (First_Stored_Discriminant (Derived_Base)) or else Is_Generic_Type (Derived_Base)) then D := First_Discriminant (Derived_Base); while Present (D) loop Append_Elmt (New_Occurrence_Of (D, Loc), Discs); Next_Discriminant (D); end loop; end if; -- Finally, inherit non-discriminant components unless they are not -- visible because defined or inherited from the full view of the -- parent. Don't inherit the _parent field of the parent type. Component := First_Entity (Parent_Base); while Present (Component) loop -- Ada 2005 (AI-251): Do not inherit components associated with -- secondary tags of the parent. if Ekind (Component) = E_Component and then Present (Related_Type (Component)) then null; elsif Ekind (Component) /= E_Component or else Chars (Component) = Name_uParent then null; -- If the derived type is within the parent type's declarative -- region, then the components can still be inherited even though -- they aren't visible at this point. This can occur for cases -- such as within public child units where the components must -- become visible upon entering the child unit's private part. elsif not Is_Visible_Component (Component) and then not In_Open_Scopes (Scope (Parent_Base)) then null; elsif Ekind_In (Derived_Base, E_Private_Type, E_Limited_Private_Type) then null; else Inherit_Component (Component); end if; Next_Entity (Component); end loop; -- For tagged derived types, inherited discriminants cannot be used in -- component declarations of the record extension part. To achieve this -- we mark the inherited discriminants as not visible. if Is_Tagged and then Inherit_Discr then D := First_Discriminant (Derived_Base); while Present (D) loop Set_Is_Immediately_Visible (D, False); Next_Discriminant (D); end loop; end if; return Assoc_List; end Inherit_Components; ----------------------------- -- Inherit_Predicate_Flags -- ----------------------------- procedure Inherit_Predicate_Flags (Subt, Par : Entity_Id) is begin Set_Has_Predicates (Subt, Has_Predicates (Par)); Set_Has_Static_Predicate_Aspect (Subt, Has_Static_Predicate_Aspect (Par)); Set_Has_Dynamic_Predicate_Aspect (Subt, Has_Dynamic_Predicate_Aspect (Par)); end Inherit_Predicate_Flags; ---------------------- -- Is_EVF_Procedure -- ---------------------- function Is_EVF_Procedure (Subp : Entity_Id) return Boolean is Formal : Entity_Id; begin -- Examine the formals of an Extensions_Visible False procedure looking -- for a controlling OUT parameter. if Ekind (Subp) = E_Procedure and then Extensions_Visible_Status (Subp) = Extensions_Visible_False then Formal := First_Formal (Subp); while Present (Formal) loop if Ekind (Formal) = E_Out_Parameter and then Is_Controlling_Formal (Formal) then return True; end if; Next_Formal (Formal); end loop; end if; return False; end Is_EVF_Procedure; ----------------------- -- Is_Null_Extension -- ----------------------- function Is_Null_Extension (T : Entity_Id) return Boolean is Type_Decl : constant Node_Id := Parent (Base_Type (T)); Comp_List : Node_Id; Comp : Node_Id; begin if Nkind (Type_Decl) /= N_Full_Type_Declaration or else not Is_Tagged_Type (T) or else Nkind (Type_Definition (Type_Decl)) /= N_Derived_Type_Definition or else No (Record_Extension_Part (Type_Definition (Type_Decl))) then return False; end if; Comp_List := Component_List (Record_Extension_Part (Type_Definition (Type_Decl))); if Present (Discriminant_Specifications (Type_Decl)) then return False; elsif Present (Comp_List) and then Is_Non_Empty_List (Component_Items (Comp_List)) then Comp := First (Component_Items (Comp_List)); -- Only user-defined components are relevant. The component list -- may also contain a parent component and internal components -- corresponding to secondary tags, but these do not determine -- whether this is a null extension. while Present (Comp) loop if Comes_From_Source (Comp) then return False; end if; Next (Comp); end loop; return True; else return True; end if; end Is_Null_Extension; ------------------------------ -- Is_Valid_Constraint_Kind -- ------------------------------ function Is_Valid_Constraint_Kind (T_Kind : Type_Kind; Constraint_Kind : Node_Kind) return Boolean is begin case T_Kind is when Enumeration_Kind | Integer_Kind => return Constraint_Kind = N_Range_Constraint; when Decimal_Fixed_Point_Kind => return Nkind_In (Constraint_Kind, N_Digits_Constraint, N_Range_Constraint); when Ordinary_Fixed_Point_Kind => return Nkind_In (Constraint_Kind, N_Delta_Constraint, N_Range_Constraint); when Float_Kind => return Nkind_In (Constraint_Kind, N_Digits_Constraint, N_Range_Constraint); when Access_Kind | Array_Kind | Class_Wide_Kind | Concurrent_Kind | Private_Kind | E_Incomplete_Type | E_Record_Subtype | E_Record_Type => return Constraint_Kind = N_Index_Or_Discriminant_Constraint; when others => return True; -- Error will be detected later end case; end Is_Valid_Constraint_Kind; -------------------------- -- Is_Visible_Component -- -------------------------- function Is_Visible_Component (C : Entity_Id; N : Node_Id := Empty) return Boolean is Original_Comp : Entity_Id := Empty; Original_Type : Entity_Id; Type_Scope : Entity_Id; function Is_Local_Type (Typ : Entity_Id) return Boolean; -- Check whether parent type of inherited component is declared locally, -- possibly within a nested package or instance. The current scope is -- the derived record itself. ------------------- -- Is_Local_Type -- ------------------- function Is_Local_Type (Typ : Entity_Id) return Boolean is Scop : Entity_Id; begin Scop := Scope (Typ); while Present (Scop) and then Scop /= Standard_Standard loop if Scop = Scope (Current_Scope) then return True; end if; Scop := Scope (Scop); end loop; return False; end Is_Local_Type; -- Start of processing for Is_Visible_Component begin if Ekind_In (C, E_Component, E_Discriminant) then Original_Comp := Original_Record_Component (C); end if; if No (Original_Comp) then -- Premature usage, or previous error return False; else Original_Type := Scope (Original_Comp); Type_Scope := Scope (Base_Type (Scope (C))); end if; -- This test only concerns tagged types if not Is_Tagged_Type (Original_Type) then return True; -- If it is _Parent or _Tag, there is no visibility issue elsif not Comes_From_Source (Original_Comp) then return True; -- Discriminants are visible unless the (private) type has unknown -- discriminants. If the discriminant reference is inserted for a -- discriminant check on a full view it is also visible. elsif Ekind (Original_Comp) = E_Discriminant and then (not Has_Unknown_Discriminants (Original_Type) or else (Present (N) and then Nkind (N) = N_Selected_Component and then Nkind (Prefix (N)) = N_Type_Conversion and then not Comes_From_Source (Prefix (N)))) then return True; -- In the body of an instantiation, check the visibility of a component -- in case it has a homograph that is a primitive operation of a private -- type which was not visible in the generic unit. -- Should Is_Prefixed_Call be propagated from template to instance??? elsif In_Instance_Body then if not Is_Tagged_Type (Original_Type) or else not Is_Private_Type (Original_Type) then return True; else declare Subp_Elmt : Elmt_Id; begin Subp_Elmt := First_Elmt (Primitive_Operations (Original_Type)); while Present (Subp_Elmt) loop -- The component is hidden by a primitive operation if Chars (Node (Subp_Elmt)) = Chars (C) then return False; end if; Next_Elmt (Subp_Elmt); end loop; return True; end; end if; -- If the component has been declared in an ancestor which is currently -- a private type, then it is not visible. The same applies if the -- component's containing type is not in an open scope and the original -- component's enclosing type is a visible full view of a private type -- (which can occur in cases where an attempt is being made to reference -- a component in a sibling package that is inherited from a visible -- component of a type in an ancestor package; the component in the -- sibling package should not be visible even though the component it -- inherited from is visible). This does not apply however in the case -- where the scope of the type is a private child unit, or when the -- parent comes from a local package in which the ancestor is currently -- visible. The latter suppression of visibility is needed for cases -- that are tested in B730006. elsif Is_Private_Type (Original_Type) or else (not Is_Private_Descendant (Type_Scope) and then not In_Open_Scopes (Type_Scope) and then Has_Private_Declaration (Original_Type)) then -- If the type derives from an entity in a formal package, there -- are no additional visible components. if Nkind (Original_Node (Unit_Declaration_Node (Type_Scope))) = N_Formal_Package_Declaration then return False; -- if we are not in the private part of the current package, there -- are no additional visible components. elsif Ekind (Scope (Current_Scope)) = E_Package and then not In_Private_Part (Scope (Current_Scope)) then return False; else return Is_Child_Unit (Cunit_Entity (Current_Sem_Unit)) and then In_Open_Scopes (Scope (Original_Type)) and then Is_Local_Type (Type_Scope); end if; -- There is another weird way in which a component may be invisible when -- the private and the full view are not derived from the same ancestor. -- Here is an example : -- type A1 is tagged record F1 : integer; end record; -- type A2 is new A1 with record F2 : integer; end record; -- type T is new A1 with private; -- private -- type T is new A2 with null record; -- In this case, the full view of T inherits F1 and F2 but the private -- view inherits only F1 else declare Ancestor : Entity_Id := Scope (C); begin loop if Ancestor = Original_Type then return True; -- The ancestor may have a partial view of the original type, -- but if the full view is in scope, as in a child body, the -- component is visible. elsif In_Private_Part (Scope (Original_Type)) and then Full_View (Ancestor) = Original_Type then return True; elsif Ancestor = Etype (Ancestor) then -- No further ancestors to examine return False; end if; Ancestor := Etype (Ancestor); end loop; end; end if; end Is_Visible_Component; -------------------------- -- Make_Class_Wide_Type -- -------------------------- procedure Make_Class_Wide_Type (T : Entity_Id) is CW_Type : Entity_Id; CW_Name : Name_Id; Next_E : Entity_Id; begin if Present (Class_Wide_Type (T)) then -- The class-wide type is a partially decorated entity created for a -- unanalyzed tagged type referenced through a limited with clause. -- When the tagged type is analyzed, its class-wide type needs to be -- redecorated. Note that we reuse the entity created by Decorate_ -- Tagged_Type in order to preserve all links. if Materialize_Entity (Class_Wide_Type (T)) then CW_Type := Class_Wide_Type (T); Set_Materialize_Entity (CW_Type, False); -- The class wide type can have been defined by the partial view, in -- which case everything is already done. else return; end if; -- Default case, we need to create a new class-wide type else CW_Type := New_External_Entity (E_Void, Scope (T), Sloc (T), T, 'C', 0, 'T'); end if; -- Inherit root type characteristics CW_Name := Chars (CW_Type); Next_E := Next_Entity (CW_Type); Copy_Node (T, CW_Type); Set_Comes_From_Source (CW_Type, False); Set_Chars (CW_Type, CW_Name); Set_Parent (CW_Type, Parent (T)); Set_Next_Entity (CW_Type, Next_E); -- Ensure we have a new freeze node for the class-wide type. The partial -- view may have freeze action of its own, requiring a proper freeze -- node, and the same freeze node cannot be shared between the two -- types. Set_Has_Delayed_Freeze (CW_Type); Set_Freeze_Node (CW_Type, Empty); -- Customize the class-wide type: It has no prim. op., it cannot be -- abstract, its Etype points back to the specific root type, and it -- cannot have any invariants. Set_Ekind (CW_Type, E_Class_Wide_Type); Set_Is_Tagged_Type (CW_Type, True); Set_Direct_Primitive_Operations (CW_Type, New_Elmt_List); Set_Is_Abstract_Type (CW_Type, False); Set_Is_Constrained (CW_Type, False); Set_Is_First_Subtype (CW_Type, Is_First_Subtype (T)); Set_Default_SSO (CW_Type); Set_Has_Inheritable_Invariants (CW_Type, False); Set_Has_Inherited_Invariants (CW_Type, False); Set_Has_Own_Invariants (CW_Type, False); if Ekind (T) = E_Class_Wide_Subtype then Set_Etype (CW_Type, Etype (Base_Type (T))); else Set_Etype (CW_Type, T); end if; Set_No_Tagged_Streams_Pragma (CW_Type, No_Tagged_Streams); -- If this is the class_wide type of a constrained subtype, it does -- not have discriminants. Set_Has_Discriminants (CW_Type, Has_Discriminants (T) and then not Is_Constrained (T)); Set_Has_Unknown_Discriminants (CW_Type, True); Set_Class_Wide_Type (T, CW_Type); Set_Equivalent_Type (CW_Type, Empty); -- The class-wide type of a class-wide type is itself (RM 3.9(14)) Set_Class_Wide_Type (CW_Type, CW_Type); end Make_Class_Wide_Type; ---------------- -- Make_Index -- ---------------- procedure Make_Index (N : Node_Id; Related_Nod : Node_Id; Related_Id : Entity_Id := Empty; Suffix_Index : Nat := 1; In_Iter_Schm : Boolean := False) is R : Node_Id; T : Entity_Id; Def_Id : Entity_Id := Empty; Found : Boolean := False; begin -- For a discrete range used in a constrained array definition and -- defined by a range, an implicit conversion to the predefined type -- INTEGER is assumed if each bound is either a numeric literal, a named -- number, or an attribute, and the type of both bounds (prior to the -- implicit conversion) is the type universal_integer. Otherwise, both -- bounds must be of the same discrete type, other than universal -- integer; this type must be determinable independently of the -- context, but using the fact that the type must be discrete and that -- both bounds must have the same type. -- Character literals also have a universal type in the absence of -- of additional context, and are resolved to Standard_Character. if Nkind (N) = N_Range then -- The index is given by a range constraint. The bounds are known -- to be of a consistent type. if not Is_Overloaded (N) then T := Etype (N); -- For universal bounds, choose the specific predefined type if T = Universal_Integer then T := Standard_Integer; elsif T = Any_Character then Ambiguous_Character (Low_Bound (N)); T := Standard_Character; end if; -- The node may be overloaded because some user-defined operators -- are available, but if a universal interpretation exists it is -- also the selected one. elsif Universal_Interpretation (N) = Universal_Integer then T := Standard_Integer; else T := Any_Type; declare Ind : Interp_Index; It : Interp; begin Get_First_Interp (N, Ind, It); while Present (It.Typ) loop if Is_Discrete_Type (It.Typ) then if Found and then not Covers (It.Typ, T) and then not Covers (T, It.Typ) then Error_Msg_N ("ambiguous bounds in discrete range", N); exit; else T := It.Typ; Found := True; end if; end if; Get_Next_Interp (Ind, It); end loop; if T = Any_Type then Error_Msg_N ("discrete type required for range", N); Set_Etype (N, Any_Type); return; elsif T = Universal_Integer then T := Standard_Integer; end if; end; end if; if not Is_Discrete_Type (T) then Error_Msg_N ("discrete type required for range", N); Set_Etype (N, Any_Type); return; end if; if Nkind (Low_Bound (N)) = N_Attribute_Reference and then Attribute_Name (Low_Bound (N)) = Name_First and then Is_Entity_Name (Prefix (Low_Bound (N))) and then Is_Type (Entity (Prefix (Low_Bound (N)))) and then Is_Discrete_Type (Entity (Prefix (Low_Bound (N)))) then -- The type of the index will be the type of the prefix, as long -- as the upper bound is 'Last of the same type. Def_Id := Entity (Prefix (Low_Bound (N))); if Nkind (High_Bound (N)) /= N_Attribute_Reference or else Attribute_Name (High_Bound (N)) /= Name_Last or else not Is_Entity_Name (Prefix (High_Bound (N))) or else Entity (Prefix (High_Bound (N))) /= Def_Id then Def_Id := Empty; end if; end if; R := N; Process_Range_Expr_In_Decl (R, T, In_Iter_Schm => In_Iter_Schm); elsif Nkind (N) = N_Subtype_Indication then -- The index is given by a subtype with a range constraint T := Base_Type (Entity (Subtype_Mark (N))); if not Is_Discrete_Type (T) then Error_Msg_N ("discrete type required for range", N); Set_Etype (N, Any_Type); return; end if; R := Range_Expression (Constraint (N)); Resolve (R, T); Process_Range_Expr_In_Decl (R, Entity (Subtype_Mark (N)), In_Iter_Schm => In_Iter_Schm); elsif Nkind (N) = N_Attribute_Reference then -- Catch beginner's error (use of attribute other than 'Range) if Attribute_Name (N) /= Name_Range then Error_Msg_N ("expect attribute ''Range", N); Set_Etype (N, Any_Type); return; end if; -- If the node denotes the range of a type mark, that is also the -- resulting type, and we do not need to create an Itype for it. if Is_Entity_Name (Prefix (N)) and then Comes_From_Source (N) and then Is_Type (Entity (Prefix (N))) and then Is_Discrete_Type (Entity (Prefix (N))) then Def_Id := Entity (Prefix (N)); end if; Analyze_And_Resolve (N); T := Etype (N); R := N; -- If none of the above, must be a subtype. We convert this to a -- range attribute reference because in the case of declared first -- named subtypes, the types in the range reference can be different -- from the type of the entity. A range attribute normalizes the -- reference and obtains the correct types for the bounds. -- This transformation is in the nature of an expansion, is only -- done if expansion is active. In particular, it is not done on -- formal generic types, because we need to retain the name of the -- original index for instantiation purposes. else if not Is_Entity_Name (N) or else not Is_Type (Entity (N)) then Error_Msg_N ("invalid subtype mark in discrete range ", N); Set_Etype (N, Any_Integer); return; else -- The type mark may be that of an incomplete type. It is only -- now that we can get the full view, previous analysis does -- not look specifically for a type mark. Set_Entity (N, Get_Full_View (Entity (N))); Set_Etype (N, Entity (N)); Def_Id := Entity (N); if not Is_Discrete_Type (Def_Id) then Error_Msg_N ("discrete type required for index", N); Set_Etype (N, Any_Type); return; end if; end if; if Expander_Active then Rewrite (N, Make_Attribute_Reference (Sloc (N), Attribute_Name => Name_Range, Prefix => Relocate_Node (N))); -- The original was a subtype mark that does not freeze. This -- means that the rewritten version must not freeze either. Set_Must_Not_Freeze (N); Set_Must_Not_Freeze (Prefix (N)); Analyze_And_Resolve (N); T := Etype (N); R := N; -- If expander is inactive, type is legal, nothing else to construct else return; end if; end if; if not Is_Discrete_Type (T) then Error_Msg_N ("discrete type required for range", N); Set_Etype (N, Any_Type); return; elsif T = Any_Type then Set_Etype (N, Any_Type); return; end if; -- We will now create the appropriate Itype to describe the range, but -- first a check. If we originally had a subtype, then we just label -- the range with this subtype. Not only is there no need to construct -- a new subtype, but it is wrong to do so for two reasons: -- 1. A legality concern, if we have a subtype, it must not freeze, -- and the Itype would cause freezing incorrectly -- 2. An efficiency concern, if we created an Itype, it would not be -- recognized as the same type for the purposes of eliminating -- checks in some circumstances. -- We signal this case by setting the subtype entity in Def_Id if No (Def_Id) then Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, 'D', Suffix_Index); Set_Etype (Def_Id, Base_Type (T)); if Is_Signed_Integer_Type (T) then Set_Ekind (Def_Id, E_Signed_Integer_Subtype); elsif Is_Modular_Integer_Type (T) then Set_Ekind (Def_Id, E_Modular_Integer_Subtype); else Set_Ekind (Def_Id, E_Enumeration_Subtype); Set_Is_Character_Type (Def_Id, Is_Character_Type (T)); Set_First_Literal (Def_Id, First_Literal (T)); end if; Set_Size_Info (Def_Id, (T)); Set_RM_Size (Def_Id, RM_Size (T)); Set_First_Rep_Item (Def_Id, First_Rep_Item (T)); Set_Scalar_Range (Def_Id, R); Conditional_Delay (Def_Id, T); if Nkind (N) = N_Subtype_Indication then Inherit_Predicate_Flags (Def_Id, Entity (Subtype_Mark (N))); end if; -- In the subtype indication case, if the immediate parent of the -- new subtype is non-static, then the subtype we create is non- -- static, even if its bounds are static. if Nkind (N) = N_Subtype_Indication and then not Is_OK_Static_Subtype (Entity (Subtype_Mark (N))) then Set_Is_Non_Static_Subtype (Def_Id); end if; end if; -- Final step is to label the index with this constructed type Set_Etype (N, Def_Id); end Make_Index; ------------------------------ -- Modular_Type_Declaration -- ------------------------------ procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id) is Mod_Expr : constant Node_Id := Expression (Def); M_Val : Uint; procedure Set_Modular_Size (Bits : Int); -- Sets RM_Size to Bits, and Esize to normal word size above this ---------------------- -- Set_Modular_Size -- ---------------------- procedure Set_Modular_Size (Bits : Int) is begin Set_RM_Size (T, UI_From_Int (Bits)); if Bits <= 8 then Init_Esize (T, 8); elsif Bits <= 16 then Init_Esize (T, 16); elsif Bits <= 32 then Init_Esize (T, 32); else Init_Esize (T, System_Max_Binary_Modulus_Power); end if; if not Non_Binary_Modulus (T) and then Esize (T) = RM_Size (T) then Set_Is_Known_Valid (T); end if; end Set_Modular_Size; -- Start of processing for Modular_Type_Declaration begin -- If the mod expression is (exactly) 2 * literal, where literal is -- 64 or less,then almost certainly the * was meant to be **. Warn. if Warn_On_Suspicious_Modulus_Value and then Nkind (Mod_Expr) = N_Op_Multiply and then Nkind (Left_Opnd (Mod_Expr)) = N_Integer_Literal and then Intval (Left_Opnd (Mod_Expr)) = Uint_2 and then Nkind (Right_Opnd (Mod_Expr)) = N_Integer_Literal and then Intval (Right_Opnd (Mod_Expr)) <= Uint_64 then Error_Msg_N ("suspicious MOD value, was '*'* intended'??M?", Mod_Expr); end if; -- Proceed with analysis of mod expression Analyze_And_Resolve (Mod_Expr, Any_Integer); Set_Etype (T, T); Set_Ekind (T, E_Modular_Integer_Type); Init_Alignment (T); Set_Is_Constrained (T); if not Is_OK_Static_Expression (Mod_Expr) then Flag_Non_Static_Expr ("non-static expression used for modular type bound!", Mod_Expr); M_Val := 2 ** System_Max_Binary_Modulus_Power; else M_Val := Expr_Value (Mod_Expr); end if; if M_Val < 1 then Error_Msg_N ("modulus value must be positive", Mod_Expr); M_Val := 2 ** System_Max_Binary_Modulus_Power; end if; if M_Val > 2 ** Standard_Long_Integer_Size then Check_Restriction (No_Long_Long_Integers, Mod_Expr); end if; Set_Modulus (T, M_Val); -- Create bounds for the modular type based on the modulus given in -- the type declaration and then analyze and resolve those bounds. Set_Scalar_Range (T, Make_Range (Sloc (Mod_Expr), Low_Bound => Make_Integer_Literal (Sloc (Mod_Expr), 0), High_Bound => Make_Integer_Literal (Sloc (Mod_Expr), M_Val - 1))); -- Properly analyze the literals for the range. We do this manually -- because we can't go calling Resolve, since we are resolving these -- bounds with the type, and this type is certainly not complete yet. Set_Etype (Low_Bound (Scalar_Range (T)), T); Set_Etype (High_Bound (Scalar_Range (T)), T); Set_Is_Static_Expression (Low_Bound (Scalar_Range (T))); Set_Is_Static_Expression (High_Bound (Scalar_Range (T))); -- Loop through powers of two to find number of bits required for Bits in Int range 0 .. System_Max_Binary_Modulus_Power loop -- Binary case if M_Val = 2 ** Bits then Set_Modular_Size (Bits); return; -- Nonbinary case elsif M_Val < 2 ** Bits then Check_SPARK_05_Restriction ("modulus should be a power of 2", T); Set_Non_Binary_Modulus (T); if Bits > System_Max_Nonbinary_Modulus_Power then Error_Msg_Uint_1 := UI_From_Int (System_Max_Nonbinary_Modulus_Power); Error_Msg_F ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr); Set_Modular_Size (System_Max_Binary_Modulus_Power); return; else -- In the nonbinary case, set size as per RM 13.3(55) Set_Modular_Size (Bits); return; end if; end if; end loop; -- If we fall through, then the size exceed System.Max_Binary_Modulus -- so we just signal an error and set the maximum size. Error_Msg_Uint_1 := UI_From_Int (System_Max_Binary_Modulus_Power); Error_Msg_F ("modulus exceeds limit (2 '*'*^)", Mod_Expr); Set_Modular_Size (System_Max_Binary_Modulus_Power); Init_Alignment (T); end Modular_Type_Declaration; -------------------------- -- New_Concatenation_Op -- -------------------------- procedure New_Concatenation_Op (Typ : Entity_Id) is Loc : constant Source_Ptr := Sloc (Typ); Op : Entity_Id; function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id; -- Create abbreviated declaration for the formal of a predefined -- Operator 'Op' of type 'Typ' -------------------- -- Make_Op_Formal -- -------------------- function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id is Formal : Entity_Id; begin Formal := New_Internal_Entity (E_In_Parameter, Op, Loc, 'P'); Set_Etype (Formal, Typ); Set_Mechanism (Formal, Default_Mechanism); return Formal; end Make_Op_Formal; -- Start of processing for New_Concatenation_Op begin Op := Make_Defining_Operator_Symbol (Loc, Name_Op_Concat); Set_Ekind (Op, E_Operator); Set_Scope (Op, Current_Scope); Set_Etype (Op, Typ); Set_Homonym (Op, Get_Name_Entity_Id (Name_Op_Concat)); Set_Is_Immediately_Visible (Op); Set_Is_Intrinsic_Subprogram (Op); Set_Has_Completion (Op); Append_Entity (Op, Current_Scope); Set_Name_Entity_Id (Name_Op_Concat, Op); Append_Entity (Make_Op_Formal (Typ, Op), Op); Append_Entity (Make_Op_Formal (Typ, Op), Op); end New_Concatenation_Op; ------------------------- -- OK_For_Limited_Init -- ------------------------- -- ???Check all calls of this, and compare the conditions under which it's -- called. function OK_For_Limited_Init (Typ : Entity_Id; Exp : Node_Id) return Boolean is begin return Is_CPP_Constructor_Call (Exp) or else (Ada_Version >= Ada_2005 and then not Debug_Flag_Dot_L and then OK_For_Limited_Init_In_05 (Typ, Exp)); end OK_For_Limited_Init; ------------------------------- -- OK_For_Limited_Init_In_05 -- ------------------------------- function OK_For_Limited_Init_In_05 (Typ : Entity_Id; Exp : Node_Id) return Boolean is begin -- An object of a limited interface type can be initialized with any -- expression of a nonlimited descendant type. However this does not -- apply if this is a view conversion of some other expression. This -- is checked below. if Is_Class_Wide_Type (Typ) and then Is_Limited_Interface (Typ) and then not Is_Limited_Type (Etype (Exp)) and then Nkind (Exp) /= N_Type_Conversion then return True; end if; -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in -- case of limited aggregates (including extension aggregates), and -- function calls. The function call may have been given in prefixed -- notation, in which case the original node is an indexed component. -- If the function is parameterless, the original node was an explicit -- dereference. The function may also be parameterless, in which case -- the source node is just an identifier. -- A branch of a conditional expression may have been removed if the -- condition is statically known. This happens during expansion, and -- thus will not happen if previous errors were encountered. The check -- will have been performed on the chosen branch, which replaces the -- original conditional expression. if No (Exp) then return True; end if; case Nkind (Original_Node (Exp)) is when N_Aggregate | N_Extension_Aggregate | N_Function_Call | N_Op => return True; when N_Identifier => return Present (Entity (Original_Node (Exp))) and then Ekind (Entity (Original_Node (Exp))) = E_Function; when N_Qualified_Expression => return OK_For_Limited_Init_In_05 (Typ, Expression (Original_Node (Exp))); -- Ada 2005 (AI-251): If a class-wide interface object is initialized -- with a function call, the expander has rewritten the call into an -- N_Type_Conversion node to force displacement of the pointer to -- reference the component containing the secondary dispatch table. -- Otherwise a type conversion is not a legal context. -- A return statement for a build-in-place function returning a -- synchronized type also introduces an unchecked conversion. when N_Type_Conversion | N_Unchecked_Type_Conversion => return not Comes_From_Source (Exp) and then OK_For_Limited_Init_In_05 (Typ, Expression (Original_Node (Exp))); when N_Explicit_Dereference | N_Indexed_Component | N_Selected_Component => return Nkind (Exp) = N_Function_Call; -- A use of 'Input is a function call, hence allowed. Normally the -- attribute will be changed to a call, but the attribute by itself -- can occur with -gnatc. when N_Attribute_Reference => return Attribute_Name (Original_Node (Exp)) = Name_Input; -- For a case expression, all dependent expressions must be legal when N_Case_Expression => declare Alt : Node_Id; begin Alt := First (Alternatives (Original_Node (Exp))); while Present (Alt) loop if not OK_For_Limited_Init_In_05 (Typ, Expression (Alt)) then return False; end if; Next (Alt); end loop; return True; end; -- For an if expression, all dependent expressions must be legal when N_If_Expression => declare Then_Expr : constant Node_Id := Next (First (Expressions (Original_Node (Exp)))); Else_Expr : constant Node_Id := Next (Then_Expr); begin return OK_For_Limited_Init_In_05 (Typ, Then_Expr) and then OK_For_Limited_Init_In_05 (Typ, Else_Expr); end; when others => return False; end case; end OK_For_Limited_Init_In_05; ------------------------------------------- -- Ordinary_Fixed_Point_Type_Declaration -- ------------------------------------------- procedure Ordinary_Fixed_Point_Type_Declaration (T : Entity_Id; Def : Node_Id) is Loc : constant Source_Ptr := Sloc (Def); Delta_Expr : constant Node_Id := Delta_Expression (Def); RRS : constant Node_Id := Real_Range_Specification (Def); Implicit_Base : Entity_Id; Delta_Val : Ureal; Small_Val : Ureal; Low_Val : Ureal; High_Val : Ureal; begin Check_Restriction (No_Fixed_Point, Def); -- Create implicit base type Implicit_Base := Create_Itype (E_Ordinary_Fixed_Point_Type, Parent (Def), T, 'B'); Set_Etype (Implicit_Base, Implicit_Base); -- Analyze and process delta expression Analyze_And_Resolve (Delta_Expr, Any_Real); Check_Delta_Expression (Delta_Expr); Delta_Val := Expr_Value_R (Delta_Expr); Set_Delta_Value (Implicit_Base, Delta_Val); -- Compute default small from given delta, which is the largest power -- of two that does not exceed the given delta value. declare Tmp : Ureal; Scale : Int; begin Tmp := Ureal_1; Scale := 0; if Delta_Val < Ureal_1 then while Delta_Val < Tmp loop Tmp := Tmp / Ureal_2; Scale := Scale + 1; end loop; else loop Tmp := Tmp * Ureal_2; exit when Tmp > Delta_Val; Scale := Scale - 1; end loop; end if; Small_Val := UR_From_Components (Uint_1, UI_From_Int (Scale), 2); end; Set_Small_Value (Implicit_Base, Small_Val); -- If no range was given, set a dummy range if RRS <= Empty_Or_Error then Low_Val := -Small_Val; High_Val := Small_Val; -- Otherwise analyze and process given range else declare Low : constant Node_Id := Low_Bound (RRS); High : constant Node_Id := High_Bound (RRS); begin Analyze_And_Resolve (Low, Any_Real); Analyze_And_Resolve (High, Any_Real); Check_Real_Bound (Low); Check_Real_Bound (High); -- Obtain and set the range Low_Val := Expr_Value_R (Low); High_Val := Expr_Value_R (High); if Low_Val > High_Val then Error_Msg_NE ("??fixed point type& has null range", Def, T); end if; end; end if; -- The range for both the implicit base and the declared first subtype -- cannot be set yet, so we use the special routine Set_Fixed_Range to -- set a temporary range in place. Note that the bounds of the base -- type will be widened to be symmetrical and to fill the available -- bits when the type is frozen. -- We could do this with all discrete types, and probably should, but -- we absolutely have to do it for fixed-point, since the end-points -- of the range and the size are determined by the small value, which -- could be reset before the freeze point. Set_Fixed_Range (Implicit_Base, Loc, Low_Val, High_Val); Set_Fixed_Range (T, Loc, Low_Val, High_Val); -- Complete definition of first subtype. The inheritance of the rep item -- chain ensures that SPARK-related pragmas are not clobbered when the -- ordinary fixed point type acts as a full view of a private type. Set_Ekind (T, E_Ordinary_Fixed_Point_Subtype); Set_Etype (T, Implicit_Base); Init_Size_Align (T); Inherit_Rep_Item_Chain (T, Implicit_Base); Set_Small_Value (T, Small_Val); Set_Delta_Value (T, Delta_Val); Set_Is_Constrained (T); end Ordinary_Fixed_Point_Type_Declaration; ---------------------------------- -- Preanalyze_Assert_Expression -- ---------------------------------- procedure Preanalyze_Assert_Expression (N : Node_Id; T : Entity_Id) is begin In_Assertion_Expr := In_Assertion_Expr + 1; Preanalyze_Spec_Expression (N, T); In_Assertion_Expr := In_Assertion_Expr - 1; end Preanalyze_Assert_Expression; ----------------------------------- -- Preanalyze_Default_Expression -- ----------------------------------- procedure Preanalyze_Default_Expression (N : Node_Id; T : Entity_Id) is Save_In_Default_Expr : constant Boolean := In_Default_Expr; begin In_Default_Expr := True; Preanalyze_Spec_Expression (N, T); In_Default_Expr := Save_In_Default_Expr; end Preanalyze_Default_Expression; -------------------------------- -- Preanalyze_Spec_Expression -- -------------------------------- procedure Preanalyze_Spec_Expression (N : Node_Id; T : Entity_Id) is Save_In_Spec_Expression : constant Boolean := In_Spec_Expression; begin In_Spec_Expression := True; Preanalyze_And_Resolve (N, T); In_Spec_Expression := Save_In_Spec_Expression; end Preanalyze_Spec_Expression; ---------------------------------------- -- Prepare_Private_Subtype_Completion -- ---------------------------------------- procedure Prepare_Private_Subtype_Completion (Id : Entity_Id; Related_Nod : Node_Id) is Id_B : constant Entity_Id := Base_Type (Id); Full_B : Entity_Id := Full_View (Id_B); Full : Entity_Id; begin if Present (Full_B) then -- Get to the underlying full view if necessary if Is_Private_Type (Full_B) and then Present (Underlying_Full_View (Full_B)) then Full_B := Underlying_Full_View (Full_B); end if; -- The Base_Type is already completed, we can complete the subtype -- now. We have to create a new entity with the same name, Thus we -- can't use Create_Itype. Full := Make_Defining_Identifier (Sloc (Id), Chars (Id)); Set_Is_Itype (Full); Set_Associated_Node_For_Itype (Full, Related_Nod); Complete_Private_Subtype (Id, Full, Full_B, Related_Nod); end if; -- The parent subtype may be private, but the base might not, in some -- nested instances. In that case, the subtype does not need to be -- exchanged. It would still be nice to make private subtypes and their -- bases consistent at all times ??? if Is_Private_Type (Id_B) then Append_Elmt (Id, Private_Dependents (Id_B)); end if; end Prepare_Private_Subtype_Completion; --------------------------- -- Process_Discriminants -- --------------------------- procedure Process_Discriminants (N : Node_Id; Prev : Entity_Id := Empty) is Elist : constant Elist_Id := New_Elmt_List; Id : Node_Id; Discr : Node_Id; Discr_Number : Uint; Discr_Type : Entity_Id; Default_Present : Boolean := False; Default_Not_Present : Boolean := False; begin -- A composite type other than an array type can have discriminants. -- On entry, the current scope is the composite type. -- The discriminants are initially entered into the scope of the type -- via Enter_Name with the default Ekind of E_Void to prevent premature -- use, as explained at the end of this procedure. Discr := First (Discriminant_Specifications (N)); while Present (Discr) loop Enter_Name (Defining_Identifier (Discr)); -- For navigation purposes we add a reference to the discriminant -- in the entity for the type. If the current declaration is a -- completion, place references on the partial view. Otherwise the -- type is the current scope. if Present (Prev) then -- The references go on the partial view, if present. If the -- partial view has discriminants, the references have been -- generated already. if not Has_Discriminants (Prev) then Generate_Reference (Prev, Defining_Identifier (Discr), 'd'); end if; else Generate_Reference (Current_Scope, Defining_Identifier (Discr), 'd'); end if; if Nkind (Discriminant_Type (Discr)) = N_Access_Definition then Discr_Type := Access_Definition (Discr, Discriminant_Type (Discr)); -- Ada 2005 (AI-254) if Present (Access_To_Subprogram_Definition (Discriminant_Type (Discr))) and then Protected_Present (Access_To_Subprogram_Definition (Discriminant_Type (Discr))) then Discr_Type := Replace_Anonymous_Access_To_Protected_Subprogram (Discr); end if; else Find_Type (Discriminant_Type (Discr)); Discr_Type := Etype (Discriminant_Type (Discr)); if Error_Posted (Discriminant_Type (Discr)) then Discr_Type := Any_Type; end if; end if; -- Handling of discriminants that are access types if Is_Access_Type (Discr_Type) then -- Ada 2005 (AI-230): Access discriminant allowed in non- -- limited record types if Ada_Version < Ada_2005 then Check_Access_Discriminant_Requires_Limited (Discr, Discriminant_Type (Discr)); end if; if Ada_Version = Ada_83 and then Comes_From_Source (Discr) then Error_Msg_N ("(Ada 83) access discriminant not allowed", Discr); end if; -- If not access type, must be a discrete type elsif not Is_Discrete_Type (Discr_Type) then Error_Msg_N ("discriminants must have a discrete or access type", Discriminant_Type (Discr)); end if; Set_Etype (Defining_Identifier (Discr), Discr_Type); -- If a discriminant specification includes the assignment compound -- delimiter followed by an expression, the expression is the default -- expression of the discriminant; the default expression must be of -- the type of the discriminant. (RM 3.7.1) Since this expression is -- a default expression, we do the special preanalysis, since this -- expression does not freeze (see section "Handling of Default and -- Per-Object Expressions" in spec of package Sem). if Present (Expression (Discr)) then Preanalyze_Spec_Expression (Expression (Discr), Discr_Type); -- Legaity checks if Nkind (N) = N_Formal_Type_Declaration then Error_Msg_N ("discriminant defaults not allowed for formal type", Expression (Discr)); -- Flag an error for a tagged type with defaulted discriminants, -- excluding limited tagged types when compiling for Ada 2012 -- (see AI05-0214). elsif Is_Tagged_Type (Current_Scope) and then (not Is_Limited_Type (Current_Scope) or else Ada_Version < Ada_2012) and then Comes_From_Source (N) then -- Note: see similar test in Check_Or_Process_Discriminants, to -- handle the (illegal) case of the completion of an untagged -- view with discriminants with defaults by a tagged full view. -- We skip the check if Discr does not come from source, to -- account for the case of an untagged derived type providing -- defaults for a renamed discriminant from a private untagged -- ancestor with a tagged full view (ACATS B460006). if Ada_Version >= Ada_2012 then Error_Msg_N ("discriminants of nonlimited tagged type cannot have" & " defaults", Expression (Discr)); else Error_Msg_N ("discriminants of tagged type cannot have defaults", Expression (Discr)); end if; else Default_Present := True; Append_Elmt (Expression (Discr), Elist); -- Tag the defining identifiers for the discriminants with -- their corresponding default expressions from the tree. Set_Discriminant_Default_Value (Defining_Identifier (Discr), Expression (Discr)); end if; -- In gnatc or gnatprove mode, make sure set Do_Range_Check flag -- gets set unless we can be sure that no range check is required. if (GNATprove_Mode or not Expander_Active) and then not Is_In_Range (Expression (Discr), Discr_Type, Assume_Valid => True) then Set_Do_Range_Check (Expression (Discr)); end if; -- No default discriminant value given else Default_Not_Present := True; end if; -- Ada 2005 (AI-231): Create an Itype that is a duplicate of -- Discr_Type but with the null-exclusion attribute if Ada_Version >= Ada_2005 then -- Ada 2005 (AI-231): Static checks if Can_Never_Be_Null (Discr_Type) then Null_Exclusion_Static_Checks (Discr); elsif Is_Access_Type (Discr_Type) and then Null_Exclusion_Present (Discr) -- No need to check itypes because in their case this check -- was done at their point of creation and then not Is_Itype (Discr_Type) then if Can_Never_Be_Null (Discr_Type) then Error_Msg_NE ("`NOT NULL` not allowed (& already excludes null)", Discr, Discr_Type); end if; Set_Etype (Defining_Identifier (Discr), Create_Null_Excluding_Itype (T => Discr_Type, Related_Nod => Discr)); -- Check for improper null exclusion if the type is otherwise -- legal for a discriminant. elsif Null_Exclusion_Present (Discr) and then Is_Discrete_Type (Discr_Type) then Error_Msg_N ("null exclusion can only apply to an access type", Discr); end if; -- Ada 2005 (AI-402): access discriminants of nonlimited types -- can't have defaults. Synchronized types, or types that are -- explicitly limited are fine, but special tests apply to derived -- types in generics: in a generic body we have to assume the -- worst, and therefore defaults are not allowed if the parent is -- a generic formal private type (see ACATS B370001). if Is_Access_Type (Discr_Type) and then Default_Present then if Ekind (Discr_Type) /= E_Anonymous_Access_Type or else Is_Limited_Record (Current_Scope) or else Is_Concurrent_Type (Current_Scope) or else Is_Concurrent_Record_Type (Current_Scope) or else Ekind (Current_Scope) = E_Limited_Private_Type then if not Is_Derived_Type (Current_Scope) or else not Is_Generic_Type (Etype (Current_Scope)) or else not In_Package_Body (Scope (Etype (Current_Scope))) or else Limited_Present (Type_Definition (Parent (Current_Scope))) then null; else Error_Msg_N ("access discriminants of nonlimited types cannot " & "have defaults", Expression (Discr)); end if; elsif Present (Expression (Discr)) then Error_Msg_N ("(Ada 2005) access discriminants of nonlimited types " & "cannot have defaults", Expression (Discr)); end if; end if; end if; -- A discriminant cannot be effectively volatile (SPARK RM 7.1.3(6)). -- This check is relevant only when SPARK_Mode is on as it is not a -- standard Ada legality rule. if SPARK_Mode = On and then Is_Effectively_Volatile (Defining_Identifier (Discr)) then Error_Msg_N ("discriminant cannot be volatile", Discr); end if; Next (Discr); end loop; -- An element list consisting of the default expressions of the -- discriminants is constructed in the above loop and used to set -- the Discriminant_Constraint attribute for the type. If an object -- is declared of this (record or task) type without any explicit -- discriminant constraint given, this element list will form the -- actual parameters for the corresponding initialization procedure -- for the type. Set_Discriminant_Constraint (Current_Scope, Elist); Set_Stored_Constraint (Current_Scope, No_Elist); -- Default expressions must be provided either for all or for none -- of the discriminants of a discriminant part. (RM 3.7.1) if Default_Present and then Default_Not_Present then Error_Msg_N ("incomplete specification of defaults for discriminants", N); end if; -- The use of the name of a discriminant is not allowed in default -- expressions of a discriminant part if the specification of the -- discriminant is itself given in the discriminant part. (RM 3.7.1) -- To detect this, the discriminant names are entered initially with an -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any -- attempt to use a void entity (for example in an expression that is -- type-checked) produces the error message: premature usage. Now after -- completing the semantic analysis of the discriminant part, we can set -- the Ekind of all the discriminants appropriately. Discr := First (Discriminant_Specifications (N)); Discr_Number := Uint_1; while Present (Discr) loop Id := Defining_Identifier (Discr); Set_Ekind (Id, E_Discriminant); Init_Component_Location (Id); Init_Esize (Id); Set_Discriminant_Number (Id, Discr_Number); -- Make sure this is always set, even in illegal programs Set_Corresponding_Discriminant (Id, Empty); -- Initialize the Original_Record_Component to the entity itself. -- Inherit_Components will propagate the right value to -- discriminants in derived record types. Set_Original_Record_Component (Id, Id); -- Create the discriminal for the discriminant Build_Discriminal (Id); Next (Discr); Discr_Number := Discr_Number + 1; end loop; Set_Has_Discriminants (Current_Scope); end Process_Discriminants; ----------------------- -- Process_Full_View -- ----------------------- -- WARNING: This routine manages Ghost regions. Return statements must be -- replaced by gotos which jump to the end of the routine and restore the -- Ghost mode. procedure Process_Full_View (N : Node_Id; Full_T, Priv_T : Entity_Id) is procedure Collect_Implemented_Interfaces (Typ : Entity_Id; Ifaces : Elist_Id); -- Ada 2005: Gather all the interfaces that Typ directly or -- inherently implements. Duplicate entries are not added to -- the list Ifaces. ------------------------------------ -- Collect_Implemented_Interfaces -- ------------------------------------ procedure Collect_Implemented_Interfaces (Typ : Entity_Id; Ifaces : Elist_Id) is Iface : Entity_Id; Iface_Elmt : Elmt_Id; begin -- Abstract interfaces are only associated with tagged record types if not Is_Tagged_Type (Typ) or else not Is_Record_Type (Typ) then return; end if; -- Recursively climb to the ancestors if Etype (Typ) /= Typ -- Protect the frontend against wrong cyclic declarations like: -- type B is new A with private; -- type C is new A with private; -- private -- type B is new C with null record; -- type C is new B with null record; and then Etype (Typ) /= Priv_T and then Etype (Typ) /= Full_T then -- Keep separate the management of private type declarations if Ekind (Typ) = E_Record_Type_With_Private then -- Handle the following illegal usage: -- type Private_Type is tagged private; -- private -- type Private_Type is new Type_Implementing_Iface; if Present (Full_View (Typ)) and then Etype (Typ) /= Full_View (Typ) then if Is_Interface (Etype (Typ)) then Append_Unique_Elmt (Etype (Typ), Ifaces); end if; Collect_Implemented_Interfaces (Etype (Typ), Ifaces); end if; -- Non-private types else if Is_Interface (Etype (Typ)) then Append_Unique_Elmt (Etype (Typ), Ifaces); end if; Collect_Implemented_Interfaces (Etype (Typ), Ifaces); end if; end if; -- Handle entities in the list of abstract interfaces if Present (Interfaces (Typ)) then Iface_Elmt := First_Elmt (Interfaces (Typ)); while Present (Iface_Elmt) loop Iface := Node (Iface_Elmt); pragma Assert (Is_Interface (Iface)); if not Contain_Interface (Iface, Ifaces) then Append_Elmt (Iface, Ifaces); Collect_Implemented_Interfaces (Iface, Ifaces); end if; Next_Elmt (Iface_Elmt); end loop; end if; end Collect_Implemented_Interfaces; -- Local variables Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; Full_Indic : Node_Id; Full_Parent : Entity_Id; Priv_Parent : Entity_Id; -- Start of processing for Process_Full_View begin Mark_And_Set_Ghost_Completion (N, Priv_T); -- First some sanity checks that must be done after semantic -- decoration of the full view and thus cannot be placed with other -- similar checks in Find_Type_Name if not Is_Limited_Type (Priv_T) and then (Is_Limited_Type (Full_T) or else Is_Limited_Composite (Full_T)) then if In_Instance then null; else Error_Msg_N ("completion of nonlimited type cannot be limited", Full_T); Explain_Limited_Type (Full_T, Full_T); end if; elsif Is_Abstract_Type (Full_T) and then not Is_Abstract_Type (Priv_T) then Error_Msg_N ("completion of nonabstract type cannot be abstract", Full_T); elsif Is_Tagged_Type (Priv_T) and then Is_Limited_Type (Priv_T) and then not Is_Limited_Type (Full_T) then -- If pragma CPP_Class was applied to the private declaration -- propagate the limitedness to the full-view if Is_CPP_Class (Priv_T) then Set_Is_Limited_Record (Full_T); -- GNAT allow its own definition of Limited_Controlled to disobey -- this rule in order in ease the implementation. This test is safe -- because Root_Controlled is defined in a child of System that -- normal programs are not supposed to use. elsif Is_RTE (Etype (Full_T), RE_Root_Controlled) then Set_Is_Limited_Composite (Full_T); else Error_Msg_N ("completion of limited tagged type must be limited", Full_T); end if; elsif Is_Generic_Type (Priv_T) then Error_Msg_N ("generic type cannot have a completion", Full_T); end if; -- Check that ancestor interfaces of private and full views are -- consistent. We omit this check for synchronized types because -- they are performed on the corresponding record type when frozen. if Ada_Version >= Ada_2005 and then Is_Tagged_Type (Priv_T) and then Is_Tagged_Type (Full_T) and then not Is_Concurrent_Type (Full_T) then declare Iface : Entity_Id; Priv_T_Ifaces : constant Elist_Id := New_Elmt_List; Full_T_Ifaces : constant Elist_Id := New_Elmt_List; begin Collect_Implemented_Interfaces (Priv_T, Priv_T_Ifaces); Collect_Implemented_Interfaces (Full_T, Full_T_Ifaces); -- Ada 2005 (AI-251): The partial view shall be a descendant of -- an interface type if and only if the full type is descendant -- of the interface type (AARM 7.3 (7.3/2)). Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces); if Present (Iface) then Error_Msg_NE ("interface in partial view& not implemented by full type " & "(RM-2005 7.3 (7.3/2))", Full_T, Iface); end if; Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces); if Present (Iface) then Error_Msg_NE ("interface & not implemented by partial view " & "(RM-2005 7.3 (7.3/2))", Full_T, Iface); end if; end; end if; if Is_Tagged_Type (Priv_T) and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration and then Is_Derived_Type (Full_T) then Priv_Parent := Etype (Priv_T); -- The full view of a private extension may have been transformed -- into an unconstrained derived type declaration and a subtype -- declaration (see build_derived_record_type for details). if Nkind (N) = N_Subtype_Declaration then Full_Indic := Subtype_Indication (N); Full_Parent := Etype (Base_Type (Full_T)); else Full_Indic := Subtype_Indication (Type_Definition (N)); Full_Parent := Etype (Full_T); end if; -- Check that the parent type of the full type is a descendant of -- the ancestor subtype given in the private extension. If either -- entity has an Etype equal to Any_Type then we had some previous -- error situation [7.3(8)]. if Priv_Parent = Any_Type or else Full_Parent = Any_Type then goto Leave; -- Ada 2005 (AI-251): Interfaces in the full type can be given in -- any order. Therefore we don't have to check that its parent must -- be a descendant of the parent of the private type declaration. elsif Is_Interface (Priv_Parent) and then Is_Interface (Full_Parent) then null; -- Ada 2005 (AI-251): If the parent of the private type declaration -- is an interface there is no need to check that it is an ancestor -- of the associated full type declaration. The required tests for -- this case are performed by Build_Derived_Record_Type. elsif not Is_Interface (Base_Type (Priv_Parent)) and then not Is_Ancestor (Base_Type (Priv_Parent), Full_Parent) then Error_Msg_N ("parent of full type must descend from parent of private " & "extension", Full_Indic); -- First check a formal restriction, and then proceed with checking -- Ada rules. Since the formal restriction is not a serious error, we -- don't prevent further error detection for this check, hence the -- ELSE. else -- In formal mode, when completing a private extension the type -- named in the private part must be exactly the same as that -- named in the visible part. if Priv_Parent /= Full_Parent then Error_Msg_Name_1 := Chars (Priv_Parent); Check_SPARK_05_Restriction ("% expected", Full_Indic); end if; -- Check the rules of 7.3(10): if the private extension inherits -- known discriminants, then the full type must also inherit those -- discriminants from the same (ancestor) type, and the parent -- subtype of the full type must be constrained if and only if -- the ancestor subtype of the private extension is constrained. if No (Discriminant_Specifications (Parent (Priv_T))) and then not Has_Unknown_Discriminants (Priv_T) and then Has_Discriminants (Base_Type (Priv_Parent)) then declare Priv_Indic : constant Node_Id := Subtype_Indication (Parent (Priv_T)); Priv_Constr : constant Boolean := Is_Constrained (Priv_Parent) or else Nkind (Priv_Indic) = N_Subtype_Indication or else Is_Constrained (Entity (Priv_Indic)); Full_Constr : constant Boolean := Is_Constrained (Full_Parent) or else Nkind (Full_Indic) = N_Subtype_Indication or else Is_Constrained (Entity (Full_Indic)); Priv_Discr : Entity_Id; Full_Discr : Entity_Id; begin Priv_Discr := First_Discriminant (Priv_Parent); Full_Discr := First_Discriminant (Full_Parent); while Present (Priv_Discr) and then Present (Full_Discr) loop if Original_Record_Component (Priv_Discr) = Original_Record_Component (Full_Discr) or else Corresponding_Discriminant (Priv_Discr) = Corresponding_Discriminant (Full_Discr) then null; else exit; end if; Next_Discriminant (Priv_Discr); Next_Discriminant (Full_Discr); end loop; if Present (Priv_Discr) or else Present (Full_Discr) then Error_Msg_N ("full view must inherit discriminants of the parent " & "type used in the private extension", Full_Indic); elsif Priv_Constr and then not Full_Constr then Error_Msg_N ("parent subtype of full type must be constrained", Full_Indic); elsif Full_Constr and then not Priv_Constr then Error_Msg_N ("parent subtype of full type must be unconstrained", Full_Indic); end if; end; -- Check the rules of 7.3(12): if a partial view has neither -- known or unknown discriminants, then the full type -- declaration shall define a definite subtype. elsif not Has_Unknown_Discriminants (Priv_T) and then not Has_Discriminants (Priv_T) and then not Is_Constrained (Full_T) then Error_Msg_N ("full view must define a constrained type if partial view " & "has no discriminants", Full_T); end if; -- ??????? Do we implement the following properly ????? -- If the ancestor subtype of a private extension has constrained -- discriminants, then the parent subtype of the full view shall -- impose a statically matching constraint on those discriminants -- [7.3(13)]. end if; else -- For untagged types, verify that a type without discriminants is -- not completed with an unconstrained type. A separate error message -- is produced if the full type has defaulted discriminants. if Is_Definite_Subtype (Priv_T) and then not Is_Definite_Subtype (Full_T) then Error_Msg_Sloc := Sloc (Parent (Priv_T)); Error_Msg_NE ("full view of& not compatible with declaration#", Full_T, Priv_T); if not Is_Tagged_Type (Full_T) then Error_Msg_N ("\one is constrained, the other unconstrained", Full_T); end if; end if; end if; -- AI-419: verify that the use of "limited" is consistent declare Orig_Decl : constant Node_Id := Original_Node (N); begin if Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration and then Nkind (Orig_Decl) = N_Full_Type_Declaration and then Nkind (Type_Definition (Orig_Decl)) = N_Derived_Type_Definition then if not Limited_Present (Parent (Priv_T)) and then not Synchronized_Present (Parent (Priv_T)) and then Limited_Present (Type_Definition (Orig_Decl)) then Error_Msg_N ("full view of non-limited extension cannot be limited", N); -- Conversely, if the partial view carries the limited keyword, -- the full view must as well, even if it may be redundant. elsif Limited_Present (Parent (Priv_T)) and then not Limited_Present (Type_Definition (Orig_Decl)) then Error_Msg_N ("full view of limited extension must be explicitly limited", N); end if; end if; end; -- Ada 2005 (AI-443): A synchronized private extension must be -- completed by a task or protected type. if Ada_Version >= Ada_2005 and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration and then Synchronized_Present (Parent (Priv_T)) and then not Is_Concurrent_Type (Full_T) then Error_Msg_N ("full view of synchronized extension must " & "be synchronized type", N); end if; -- Ada 2005 AI-363: if the full view has discriminants with -- defaults, it is illegal to declare constrained access subtypes -- whose designated type is the current type. This allows objects -- of the type that are declared in the heap to be unconstrained. if not Has_Unknown_Discriminants (Priv_T) and then not Has_Discriminants (Priv_T) and then Has_Discriminants (Full_T) and then Present (Discriminant_Default_Value (First_Discriminant (Full_T))) then Set_Has_Constrained_Partial_View (Full_T); Set_Has_Constrained_Partial_View (Priv_T); end if; -- Create a full declaration for all its subtypes recorded in -- Private_Dependents and swap them similarly to the base type. These -- are subtypes that have been define before the full declaration of -- the private type. We also swap the entry in Private_Dependents list -- so we can properly restore the private view on exit from the scope. declare Priv_Elmt : Elmt_Id; Priv_Scop : Entity_Id; Priv : Entity_Id; Full : Entity_Id; begin Priv_Elmt := First_Elmt (Private_Dependents (Priv_T)); while Present (Priv_Elmt) loop Priv := Node (Priv_Elmt); Priv_Scop := Scope (Priv); if Ekind_In (Priv, E_Private_Subtype, E_Limited_Private_Subtype, E_Record_Subtype_With_Private) then Full := Make_Defining_Identifier (Sloc (Priv), Chars (Priv)); Set_Is_Itype (Full); Set_Parent (Full, Parent (Priv)); Set_Associated_Node_For_Itype (Full, N); -- Now we need to complete the private subtype, but since the -- base type has already been swapped, we must also swap the -- subtypes (and thus, reverse the arguments in the call to -- Complete_Private_Subtype). Also note that we may need to -- re-establish the scope of the private subtype. Copy_And_Swap (Priv, Full); if not In_Open_Scopes (Priv_Scop) then Push_Scope (Priv_Scop); else -- Reset Priv_Scop to Empty to indicate no scope was pushed Priv_Scop := Empty; end if; Complete_Private_Subtype (Full, Priv, Full_T, N); if Present (Priv_Scop) then Pop_Scope; end if; Replace_Elmt (Priv_Elmt, Full); end if; Next_Elmt (Priv_Elmt); end loop; end; -- If the private view was tagged, copy the new primitive operations -- from the private view to the full view. if Is_Tagged_Type (Full_T) then declare Disp_Typ : Entity_Id; Full_List : Elist_Id; Prim : Entity_Id; Prim_Elmt : Elmt_Id; Priv_List : Elist_Id; function Contains (E : Entity_Id; L : Elist_Id) return Boolean; -- Determine whether list L contains element E -------------- -- Contains -- -------------- function Contains (E : Entity_Id; L : Elist_Id) return Boolean is List_Elmt : Elmt_Id; begin List_Elmt := First_Elmt (L); while Present (List_Elmt) loop if Node (List_Elmt) = E then return True; end if; Next_Elmt (List_Elmt); end loop; return False; end Contains; -- Start of processing begin if Is_Tagged_Type (Priv_T) then Priv_List := Primitive_Operations (Priv_T); Prim_Elmt := First_Elmt (Priv_List); -- In the case of a concurrent type completing a private tagged -- type, primitives may have been declared in between the two -- views. These subprograms need to be wrapped the same way -- entries and protected procedures are handled because they -- cannot be directly shared by the two views. if Is_Concurrent_Type (Full_T) then declare Conc_Typ : constant Entity_Id := Corresponding_Record_Type (Full_T); Curr_Nod : Node_Id := Parent (Conc_Typ); Wrap_Spec : Node_Id; begin while Present (Prim_Elmt) loop Prim := Node (Prim_Elmt); if Comes_From_Source (Prim) and then not Is_Abstract_Subprogram (Prim) then Wrap_Spec := Make_Subprogram_Declaration (Sloc (Prim), Specification => Build_Wrapper_Spec (Subp_Id => Prim, Obj_Typ => Conc_Typ, Formals => Parameter_Specifications (Parent (Prim)))); Insert_After (Curr_Nod, Wrap_Spec); Curr_Nod := Wrap_Spec; Analyze (Wrap_Spec); -- Remove the wrapper from visibility to avoid -- spurious conflict with the wrapped entity. Set_Is_Immediately_Visible (Defining_Entity (Specification (Wrap_Spec)), False); end if; Next_Elmt (Prim_Elmt); end loop; goto Leave; end; -- For non-concurrent types, transfer explicit primitives, but -- omit those inherited from the parent of the private view -- since they will be re-inherited later on. else Full_List := Primitive_Operations (Full_T); while Present (Prim_Elmt) loop Prim := Node (Prim_Elmt); if Comes_From_Source (Prim) and then not Contains (Prim, Full_List) then Append_Elmt (Prim, Full_List); end if; Next_Elmt (Prim_Elmt); end loop; end if; -- Untagged private view else Full_List := Primitive_Operations (Full_T); -- In this case the partial view is untagged, so here we locate -- all of the earlier primitives that need to be treated as -- dispatching (those that appear between the two views). Note -- that these additional operations must all be new operations -- (any earlier operations that override inherited operations -- of the full view will already have been inserted in the -- primitives list, marked by Check_Operation_From_Private_View -- as dispatching. Note that implicit "/=" operators are -- excluded from being added to the primitives list since they -- shouldn't be treated as dispatching (tagged "/=" is handled -- specially). Prim := Next_Entity (Full_T); while Present (Prim) and then Prim /= Priv_T loop if Ekind_In (Prim, E_Procedure, E_Function) then Disp_Typ := Find_Dispatching_Type (Prim); if Disp_Typ = Full_T and then (Chars (Prim) /= Name_Op_Ne or else Comes_From_Source (Prim)) then Check_Controlling_Formals (Full_T, Prim); if not Is_Dispatching_Operation (Prim) then Append_Elmt (Prim, Full_List); Set_Is_Dispatching_Operation (Prim, True); Set_DT_Position_Value (Prim, No_Uint); end if; elsif Is_Dispatching_Operation (Prim) and then Disp_Typ /= Full_T then -- Verify that it is not otherwise controlled by a -- formal or a return value of type T. Check_Controlling_Formals (Disp_Typ, Prim); end if; end if; Next_Entity (Prim); end loop; end if; -- For the tagged case, the two views can share the same primitive -- operations list and the same class-wide type. Update attributes -- of the class-wide type which depend on the full declaration. if Is_Tagged_Type (Priv_T) then Set_Direct_Primitive_Operations (Priv_T, Full_List); Set_Class_Wide_Type (Base_Type (Full_T), Class_Wide_Type (Priv_T)); Propagate_Concurrent_Flags (Class_Wide_Type (Priv_T), Full_T); end if; end; end if; -- Ada 2005 AI 161: Check preelaborable initialization consistency if Known_To_Have_Preelab_Init (Priv_T) then -- Case where there is a pragma Preelaborable_Initialization. We -- always allow this in predefined units, which is cheating a bit, -- but it means we don't have to struggle to meet the requirements in -- the RM for having Preelaborable Initialization. Otherwise we -- require that the type meets the RM rules. But we can't check that -- yet, because of the rule about overriding Initialize, so we simply -- set a flag that will be checked at freeze time. if not In_Predefined_Unit (Full_T) then Set_Must_Have_Preelab_Init (Full_T); end if; end if; -- If pragma CPP_Class was applied to the private type declaration, -- propagate it now to the full type declaration. if Is_CPP_Class (Priv_T) then Set_Is_CPP_Class (Full_T); Set_Convention (Full_T, Convention_CPP); -- Check that components of imported CPP types do not have default -- expressions. Check_CPP_Type_Has_No_Defaults (Full_T); end if; -- If the private view has user specified stream attributes, then so has -- the full view. -- Why the test, how could these flags be already set in Full_T ??? if Has_Specified_Stream_Read (Priv_T) then Set_Has_Specified_Stream_Read (Full_T); end if; if Has_Specified_Stream_Write (Priv_T) then Set_Has_Specified_Stream_Write (Full_T); end if; if Has_Specified_Stream_Input (Priv_T) then Set_Has_Specified_Stream_Input (Full_T); end if; if Has_Specified_Stream_Output (Priv_T) then Set_Has_Specified_Stream_Output (Full_T); end if; -- Propagate Default_Initial_Condition-related attributes from the -- partial view to the full view and its base type. Propagate_DIC_Attributes (Full_T, From_Typ => Priv_T); Propagate_DIC_Attributes (Base_Type (Full_T), From_Typ => Priv_T); -- Propagate invariant-related attributes from the partial view to the -- full view and its base type. Propagate_Invariant_Attributes (Full_T, From_Typ => Priv_T); Propagate_Invariant_Attributes (Base_Type (Full_T), From_Typ => Priv_T); -- AI12-0041: Detect an attempt to inherit a class-wide type invariant -- in the full view without advertising the inheritance in the partial -- view. This can only occur when the partial view has no parent type -- and the full view has an interface as a parent. Any other scenarios -- are illegal because implemented interfaces must match between the -- two views. if Is_Tagged_Type (Priv_T) and then Is_Tagged_Type (Full_T) then declare Full_Par : constant Entity_Id := Etype (Full_T); Priv_Par : constant Entity_Id := Etype (Priv_T); begin if not Is_Interface (Priv_Par) and then Is_Interface (Full_Par) and then Has_Inheritable_Invariants (Full_Par) then Error_Msg_N ("hidden inheritance of class-wide type invariants not " & "allowed", N); end if; end; end if; -- Propagate predicates to full type, and predicate function if already -- defined. It is not clear that this can actually happen? the partial -- view cannot be frozen yet, and the predicate function has not been -- built. Still it is a cheap check and seems safer to make it. if Has_Predicates (Priv_T) then Set_Has_Predicates (Full_T); if Present (Predicate_Function (Priv_T)) then Set_Predicate_Function (Full_T, Predicate_Function (Priv_T)); end if; end if; <<Leave>> Restore_Ghost_Mode (Saved_GM); end Process_Full_View; ----------------------------------- -- Process_Incomplete_Dependents -- ----------------------------------- procedure Process_Incomplete_Dependents (N : Node_Id; Full_T : Entity_Id; Inc_T : Entity_Id) is Inc_Elmt : Elmt_Id; Priv_Dep : Entity_Id; New_Subt : Entity_Id; Disc_Constraint : Elist_Id; begin if No (Private_Dependents (Inc_T)) then return; end if; -- Itypes that may be generated by the completion of an incomplete -- subtype are not used by the back-end and not attached to the tree. -- They are created only for constraint-checking purposes. Inc_Elmt := First_Elmt (Private_Dependents (Inc_T)); while Present (Inc_Elmt) loop Priv_Dep := Node (Inc_Elmt); if Ekind (Priv_Dep) = E_Subprogram_Type then -- An Access_To_Subprogram type may have a return type or a -- parameter type that is incomplete. Replace with the full view. if Etype (Priv_Dep) = Inc_T then Set_Etype (Priv_Dep, Full_T); end if; declare Formal : Entity_Id; begin Formal := First_Formal (Priv_Dep); while Present (Formal) loop if Etype (Formal) = Inc_T then Set_Etype (Formal, Full_T); end if; Next_Formal (Formal); end loop; end; elsif Is_Overloadable (Priv_Dep) then -- If a subprogram in the incomplete dependents list is primitive -- for a tagged full type then mark it as a dispatching operation, -- check whether it overrides an inherited subprogram, and check -- restrictions on its controlling formals. Note that a protected -- operation is never dispatching: only its wrapper operation -- (which has convention Ada) is. if Is_Tagged_Type (Full_T) and then Is_Primitive (Priv_Dep) and then Convention (Priv_Dep) /= Convention_Protected then Check_Operation_From_Incomplete_Type (Priv_Dep, Inc_T); Set_Is_Dispatching_Operation (Priv_Dep); Check_Controlling_Formals (Full_T, Priv_Dep); end if; elsif Ekind (Priv_Dep) = E_Subprogram_Body then -- Can happen during processing of a body before the completion -- of a TA type. Ignore, because spec is also on dependent list. return; -- Ada 2005 (AI-412): Transform a regular incomplete subtype into a -- corresponding subtype of the full view. elsif Ekind (Priv_Dep) = E_Incomplete_Subtype then Set_Subtype_Indication (Parent (Priv_Dep), New_Occurrence_Of (Full_T, Sloc (Priv_Dep))); Set_Etype (Priv_Dep, Full_T); Set_Ekind (Priv_Dep, Subtype_Kind (Ekind (Full_T))); Set_Analyzed (Parent (Priv_Dep), False); -- Reanalyze the declaration, suppressing the call to -- Enter_Name to avoid duplicate names. Analyze_Subtype_Declaration (N => Parent (Priv_Dep), Skip => True); -- Dependent is a subtype else -- We build a new subtype indication using the full view of the -- incomplete parent. The discriminant constraints have been -- elaborated already at the point of the subtype declaration. New_Subt := Create_Itype (E_Void, N); if Has_Discriminants (Full_T) then Disc_Constraint := Discriminant_Constraint (Priv_Dep); else Disc_Constraint := No_Elist; end if; Build_Discriminated_Subtype (Full_T, New_Subt, Disc_Constraint, N); Set_Full_View (Priv_Dep, New_Subt); end if; Next_Elmt (Inc_Elmt); end loop; end Process_Incomplete_Dependents; -------------------------------- -- Process_Range_Expr_In_Decl -- -------------------------------- procedure Process_Range_Expr_In_Decl (R : Node_Id; T : Entity_Id; Subtyp : Entity_Id := Empty; Check_List : List_Id := Empty_List; R_Check_Off : Boolean := False; In_Iter_Schm : Boolean := False) is Lo, Hi : Node_Id; R_Checks : Check_Result; Insert_Node : Node_Id; Def_Id : Entity_Id; begin Analyze_And_Resolve (R, Base_Type (T)); if Nkind (R) = N_Range then -- In SPARK, all ranges should be static, with the exception of the -- discrete type definition of a loop parameter specification. if not In_Iter_Schm and then not Is_OK_Static_Range (R) then Check_SPARK_05_Restriction ("range should be static", R); end if; Lo := Low_Bound (R); Hi := High_Bound (R); -- Validity checks on the range of a quantified expression are -- delayed until the construct is transformed into a loop. if Nkind (Parent (R)) = N_Loop_Parameter_Specification and then Nkind (Parent (Parent (R))) = N_Quantified_Expression then null; -- We need to ensure validity of the bounds here, because if we -- go ahead and do the expansion, then the expanded code will get -- analyzed with range checks suppressed and we miss the check. -- WARNING: The capture of the range bounds with xxx_FIRST/_LAST and -- the temporaries generated by routine Remove_Side_Effects by means -- of validity checks must use the same names. When a range appears -- in the parent of a generic, the range is processed with checks -- disabled as part of the generic context and with checks enabled -- for code generation purposes. This leads to link issues as the -- generic contains references to xxx_FIRST/_LAST, but the inlined -- template sees the temporaries generated by Remove_Side_Effects. else Validity_Check_Range (R, Subtyp); end if; -- If there were errors in the declaration, try and patch up some -- common mistakes in the bounds. The cases handled are literals -- which are Integer where the expected type is Real and vice versa. -- These corrections allow the compilation process to proceed further -- along since some basic assumptions of the format of the bounds -- are guaranteed. if Etype (R) = Any_Type then if Nkind (Lo) = N_Integer_Literal and then Is_Real_Type (T) then Rewrite (Lo, Make_Real_Literal (Sloc (Lo), UR_From_Uint (Intval (Lo)))); elsif Nkind (Hi) = N_Integer_Literal and then Is_Real_Type (T) then Rewrite (Hi, Make_Real_Literal (Sloc (Hi), UR_From_Uint (Intval (Hi)))); elsif Nkind (Lo) = N_Real_Literal and then Is_Integer_Type (T) then Rewrite (Lo, Make_Integer_Literal (Sloc (Lo), UR_To_Uint (Realval (Lo)))); elsif Nkind (Hi) = N_Real_Literal and then Is_Integer_Type (T) then Rewrite (Hi, Make_Integer_Literal (Sloc (Hi), UR_To_Uint (Realval (Hi)))); end if; Set_Etype (Lo, T); Set_Etype (Hi, T); end if; -- If the bounds of the range have been mistakenly given as string -- literals (perhaps in place of character literals), then an error -- has already been reported, but we rewrite the string literal as a -- bound of the range's type to avoid blowups in later processing -- that looks at static values. if Nkind (Lo) = N_String_Literal then Rewrite (Lo, Make_Attribute_Reference (Sloc (Lo), Prefix => New_Occurrence_Of (T, Sloc (Lo)), Attribute_Name => Name_First)); Analyze_And_Resolve (Lo); end if; if Nkind (Hi) = N_String_Literal then Rewrite (Hi, Make_Attribute_Reference (Sloc (Hi), Prefix => New_Occurrence_Of (T, Sloc (Hi)), Attribute_Name => Name_First)); Analyze_And_Resolve (Hi); end if; -- If bounds aren't scalar at this point then exit, avoiding -- problems with further processing of the range in this procedure. if not Is_Scalar_Type (Etype (Lo)) then return; end if; -- Resolve (actually Sem_Eval) has checked that the bounds are in -- then range of the base type. Here we check whether the bounds -- are in the range of the subtype itself. Note that if the bounds -- represent the null range the Constraint_Error exception should -- not be raised. -- ??? The following code should be cleaned up as follows -- 1. The Is_Null_Range (Lo, Hi) test should disappear since it -- is done in the call to Range_Check (R, T); below -- 2. The use of R_Check_Off should be investigated and possibly -- removed, this would clean up things a bit. if Is_Null_Range (Lo, Hi) then null; else -- Capture values of bounds and generate temporaries for them -- if needed, before applying checks, since checks may cause -- duplication of the expression without forcing evaluation. -- The forced evaluation removes side effects from expressions, -- which should occur also in GNATprove mode. Otherwise, we end up -- with unexpected insertions of actions at places where this is -- not supposed to occur, e.g. on default parameters of a call. if Expander_Active or GNATprove_Mode then -- Call Force_Evaluation to create declarations as needed to -- deal with side effects, and also create typ_FIRST/LAST -- entities for bounds if we have a subtype name. -- Note: we do this transformation even if expansion is not -- active if we are in GNATprove_Mode since the transformation -- is in general required to ensure that the resulting tree has -- proper Ada semantics. Force_Evaluation (Lo, Related_Id => Subtyp, Is_Low_Bound => True); Force_Evaluation (Hi, Related_Id => Subtyp, Is_High_Bound => True); end if; -- We use a flag here instead of suppressing checks on the type -- because the type we check against isn't necessarily the place -- where we put the check. if not R_Check_Off then R_Checks := Get_Range_Checks (R, T); -- Look up tree to find an appropriate insertion point. We -- can't just use insert_actions because later processing -- depends on the insertion node. Prior to Ada 2012 the -- insertion point could only be a declaration or a loop, but -- quantified expressions can appear within any context in an -- expression, and the insertion point can be any statement, -- pragma, or declaration. Insert_Node := Parent (R); while Present (Insert_Node) loop exit when Nkind (Insert_Node) in N_Declaration and then not Nkind_In (Insert_Node, N_Component_Declaration, N_Loop_Parameter_Specification, N_Function_Specification, N_Procedure_Specification); exit when Nkind (Insert_Node) in N_Later_Decl_Item or else Nkind (Insert_Node) in N_Statement_Other_Than_Procedure_Call or else Nkind_In (Insert_Node, N_Procedure_Call_Statement, N_Pragma); Insert_Node := Parent (Insert_Node); end loop; -- Why would Type_Decl not be present??? Without this test, -- short regression tests fail. if Present (Insert_Node) then -- Case of loop statement. Verify that the range is part -- of the subtype indication of the iteration scheme. if Nkind (Insert_Node) = N_Loop_Statement then declare Indic : Node_Id; begin Indic := Parent (R); while Present (Indic) and then Nkind (Indic) /= N_Subtype_Indication loop Indic := Parent (Indic); end loop; if Present (Indic) then Def_Id := Etype (Subtype_Mark (Indic)); Insert_Range_Checks (R_Checks, Insert_Node, Def_Id, Sloc (Insert_Node), R, Do_Before => True); end if; end; -- Insertion before a declaration. If the declaration -- includes discriminants, the list of applicable checks -- is given by the caller. elsif Nkind (Insert_Node) in N_Declaration then Def_Id := Defining_Identifier (Insert_Node); if (Ekind (Def_Id) = E_Record_Type and then Depends_On_Discriminant (R)) or else (Ekind (Def_Id) = E_Protected_Type and then Has_Discriminants (Def_Id)) then Append_Range_Checks (R_Checks, Check_List, Def_Id, Sloc (Insert_Node), R); else Insert_Range_Checks (R_Checks, Insert_Node, Def_Id, Sloc (Insert_Node), R); end if; -- Insertion before a statement. Range appears in the -- context of a quantified expression. Insertion will -- take place when expression is expanded. else null; end if; end if; end if; end if; -- Case of other than an explicit N_Range node -- The forced evaluation removes side effects from expressions, which -- should occur also in GNATprove mode. Otherwise, we end up with -- unexpected insertions of actions at places where this is not -- supposed to occur, e.g. on default parameters of a call. elsif Expander_Active or GNATprove_Mode then Get_Index_Bounds (R, Lo, Hi); Force_Evaluation (Lo); Force_Evaluation (Hi); end if; end Process_Range_Expr_In_Decl; -------------------------------------- -- Process_Real_Range_Specification -- -------------------------------------- procedure Process_Real_Range_Specification (Def : Node_Id) is Spec : constant Node_Id := Real_Range_Specification (Def); Lo : Node_Id; Hi : Node_Id; Err : Boolean := False; procedure Analyze_Bound (N : Node_Id); -- Analyze and check one bound ------------------- -- Analyze_Bound -- ------------------- procedure Analyze_Bound (N : Node_Id) is begin Analyze_And_Resolve (N, Any_Real); if not Is_OK_Static_Expression (N) then Flag_Non_Static_Expr ("bound in real type definition is not static!", N); Err := True; end if; end Analyze_Bound; -- Start of processing for Process_Real_Range_Specification begin if Present (Spec) then Lo := Low_Bound (Spec); Hi := High_Bound (Spec); Analyze_Bound (Lo); Analyze_Bound (Hi); -- If error, clear away junk range specification if Err then Set_Real_Range_Specification (Def, Empty); end if; end if; end Process_Real_Range_Specification; --------------------- -- Process_Subtype -- --------------------- function Process_Subtype (S : Node_Id; Related_Nod : Node_Id; Related_Id : Entity_Id := Empty; Suffix : Character := ' ') return Entity_Id is P : Node_Id; Def_Id : Entity_Id; Error_Node : Node_Id; Full_View_Id : Entity_Id; Subtype_Mark_Id : Entity_Id; May_Have_Null_Exclusion : Boolean; procedure Check_Incomplete (T : Node_Id); -- Called to verify that an incomplete type is not used prematurely ---------------------- -- Check_Incomplete -- ---------------------- procedure Check_Incomplete (T : Node_Id) is begin -- Ada 2005 (AI-412): Incomplete subtypes are legal if Ekind (Root_Type (Entity (T))) = E_Incomplete_Type and then not (Ada_Version >= Ada_2005 and then (Nkind (Parent (T)) = N_Subtype_Declaration or else (Nkind (Parent (T)) = N_Subtype_Indication and then Nkind (Parent (Parent (T))) = N_Subtype_Declaration))) then Error_Msg_N ("invalid use of type before its full declaration", T); end if; end Check_Incomplete; -- Start of processing for Process_Subtype begin -- Case of no constraints present if Nkind (S) /= N_Subtype_Indication then Find_Type (S); Check_Incomplete (S); P := Parent (S); -- Ada 2005 (AI-231): Static check if Ada_Version >= Ada_2005 and then Present (P) and then Null_Exclusion_Present (P) and then Nkind (P) /= N_Access_To_Object_Definition and then not Is_Access_Type (Entity (S)) then Error_Msg_N ("`NOT NULL` only allowed for an access type", S); end if; -- The following is ugly, can't we have a range or even a flag??? May_Have_Null_Exclusion := Nkind_In (P, N_Access_Definition, N_Access_Function_Definition, N_Access_Procedure_Definition, N_Access_To_Object_Definition, N_Allocator, N_Component_Definition) or else Nkind_In (P, N_Derived_Type_Definition, N_Discriminant_Specification, N_Formal_Object_Declaration, N_Object_Declaration, N_Object_Renaming_Declaration, N_Parameter_Specification, N_Subtype_Declaration); -- Create an Itype that is a duplicate of Entity (S) but with the -- null-exclusion attribute. if May_Have_Null_Exclusion and then Is_Access_Type (Entity (S)) and then Null_Exclusion_Present (P) -- No need to check the case of an access to object definition. -- It is correct to define double not-null pointers. -- Example: -- type Not_Null_Int_Ptr is not null access Integer; -- type Acc is not null access Not_Null_Int_Ptr; and then Nkind (P) /= N_Access_To_Object_Definition then if Can_Never_Be_Null (Entity (S)) then case Nkind (Related_Nod) is when N_Full_Type_Declaration => if Nkind (Type_Definition (Related_Nod)) in N_Array_Type_Definition then Error_Node := Subtype_Indication (Component_Definition (Type_Definition (Related_Nod))); else Error_Node := Subtype_Indication (Type_Definition (Related_Nod)); end if; when N_Subtype_Declaration => Error_Node := Subtype_Indication (Related_Nod); when N_Object_Declaration => Error_Node := Object_Definition (Related_Nod); when N_Component_Declaration => Error_Node := Subtype_Indication (Component_Definition (Related_Nod)); when N_Allocator => Error_Node := Expression (Related_Nod); when others => pragma Assert (False); Error_Node := Related_Nod; end case; Error_Msg_NE ("`NOT NULL` not allowed (& already excludes null)", Error_Node, Entity (S)); end if; Set_Etype (S, Create_Null_Excluding_Itype (T => Entity (S), Related_Nod => P)); Set_Entity (S, Etype (S)); end if; return Entity (S); -- Case of constraint present, so that we have an N_Subtype_Indication -- node (this node is created only if constraints are present). else Find_Type (Subtype_Mark (S)); if Nkind (Parent (S)) /= N_Access_To_Object_Definition and then not (Nkind (Parent (S)) = N_Subtype_Declaration and then Is_Itype (Defining_Identifier (Parent (S)))) then Check_Incomplete (Subtype_Mark (S)); end if; P := Parent (S); Subtype_Mark_Id := Entity (Subtype_Mark (S)); -- Explicit subtype declaration case if Nkind (P) = N_Subtype_Declaration then Def_Id := Defining_Identifier (P); -- Explicit derived type definition case elsif Nkind (P) = N_Derived_Type_Definition then Def_Id := Defining_Identifier (Parent (P)); -- Implicit case, the Def_Id must be created as an implicit type. -- The one exception arises in the case of concurrent types, array -- and access types, where other subsidiary implicit types may be -- created and must appear before the main implicit type. In these -- cases we leave Def_Id set to Empty as a signal that Create_Itype -- has not yet been called to create Def_Id. else if Is_Array_Type (Subtype_Mark_Id) or else Is_Concurrent_Type (Subtype_Mark_Id) or else Is_Access_Type (Subtype_Mark_Id) then Def_Id := Empty; -- For the other cases, we create a new unattached Itype, -- and set the indication to ensure it gets attached later. else Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix); end if; end if; -- If the kind of constraint is invalid for this kind of type, -- then give an error, and then pretend no constraint was given. if not Is_Valid_Constraint_Kind (Ekind (Subtype_Mark_Id), Nkind (Constraint (S))) then Error_Msg_N ("incorrect constraint for this kind of type", Constraint (S)); Rewrite (S, New_Copy_Tree (Subtype_Mark (S))); -- Set Ekind of orphan itype, to prevent cascaded errors if Present (Def_Id) then Set_Ekind (Def_Id, Ekind (Any_Type)); end if; -- Make recursive call, having got rid of the bogus constraint return Process_Subtype (S, Related_Nod, Related_Id, Suffix); end if; -- Remaining processing depends on type. Select on Base_Type kind to -- ensure getting to the concrete type kind in the case of a private -- subtype (needed when only doing semantic analysis). case Ekind (Base_Type (Subtype_Mark_Id)) is when Access_Kind => -- If this is a constraint on a class-wide type, discard it. -- There is currently no way to express a partial discriminant -- constraint on a type with unknown discriminants. This is -- a pathology that the ACATS wisely decides not to test. if Is_Class_Wide_Type (Designated_Type (Subtype_Mark_Id)) then if Comes_From_Source (S) then Error_Msg_N ("constraint on class-wide type ignored??", Constraint (S)); end if; if Nkind (P) = N_Subtype_Declaration then Set_Subtype_Indication (P, New_Occurrence_Of (Subtype_Mark_Id, Sloc (S))); end if; return Subtype_Mark_Id; end if; Constrain_Access (Def_Id, S, Related_Nod); if Expander_Active and then Is_Itype (Designated_Type (Def_Id)) and then Nkind (Related_Nod) = N_Subtype_Declaration and then not Is_Incomplete_Type (Designated_Type (Def_Id)) then Build_Itype_Reference (Designated_Type (Def_Id), Related_Nod); end if; when Array_Kind => Constrain_Array (Def_Id, S, Related_Nod, Related_Id, Suffix); when Decimal_Fixed_Point_Kind => Constrain_Decimal (Def_Id, S); when Enumeration_Kind => Constrain_Enumeration (Def_Id, S); Inherit_Predicate_Flags (Def_Id, Subtype_Mark_Id); when Ordinary_Fixed_Point_Kind => Constrain_Ordinary_Fixed (Def_Id, S); when Float_Kind => Constrain_Float (Def_Id, S); when Integer_Kind => Constrain_Integer (Def_Id, S); Inherit_Predicate_Flags (Def_Id, Subtype_Mark_Id); when Class_Wide_Kind | E_Incomplete_Type | E_Record_Subtype | E_Record_Type => Constrain_Discriminated_Type (Def_Id, S, Related_Nod); if Ekind (Def_Id) = E_Incomplete_Type then Set_Private_Dependents (Def_Id, New_Elmt_List); end if; when Private_Kind => Constrain_Discriminated_Type (Def_Id, S, Related_Nod); -- The base type may be private but Def_Id may be a full view -- in an instance. if Is_Private_Type (Def_Id) then Set_Private_Dependents (Def_Id, New_Elmt_List); end if; -- In case of an invalid constraint prevent further processing -- since the type constructed is missing expected fields. if Etype (Def_Id) = Any_Type then return Def_Id; end if; -- If the full view is that of a task with discriminants, -- we must constrain both the concurrent type and its -- corresponding record type. Otherwise we will just propagate -- the constraint to the full view, if available. if Present (Full_View (Subtype_Mark_Id)) and then Has_Discriminants (Subtype_Mark_Id) and then Is_Concurrent_Type (Full_View (Subtype_Mark_Id)) then Full_View_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix); Set_Entity (Subtype_Mark (S), Full_View (Subtype_Mark_Id)); Constrain_Concurrent (Full_View_Id, S, Related_Nod, Related_Id, Suffix); Set_Entity (Subtype_Mark (S), Subtype_Mark_Id); Set_Full_View (Def_Id, Full_View_Id); -- Introduce an explicit reference to the private subtype, -- to prevent scope anomalies in gigi if first use appears -- in a nested context, e.g. a later function body. -- Should this be generated in other contexts than a full -- type declaration? if Is_Itype (Def_Id) and then Nkind (Parent (P)) = N_Full_Type_Declaration then Build_Itype_Reference (Def_Id, Parent (P)); end if; else Prepare_Private_Subtype_Completion (Def_Id, Related_Nod); end if; when Concurrent_Kind => Constrain_Concurrent (Def_Id, S, Related_Nod, Related_Id, Suffix); when others => Error_Msg_N ("invalid subtype mark in subtype indication", S); end case; -- Size and Convention are always inherited from the base type Set_Size_Info (Def_Id, (Subtype_Mark_Id)); Set_Convention (Def_Id, Convention (Subtype_Mark_Id)); return Def_Id; end if; end Process_Subtype; ----------------------------- -- Record_Type_Declaration -- ----------------------------- procedure Record_Type_Declaration (T : Entity_Id; N : Node_Id; Prev : Entity_Id) is Def : constant Node_Id := Type_Definition (N); Is_Tagged : Boolean; Tag_Comp : Entity_Id; begin -- These flags must be initialized before calling Process_Discriminants -- because this routine makes use of them. Set_Ekind (T, E_Record_Type); Set_Etype (T, T); Init_Size_Align (T); Set_Interfaces (T, No_Elist); Set_Stored_Constraint (T, No_Elist); Set_Default_SSO (T); -- Normal case if Ada_Version < Ada_2005 or else not Interface_Present (Def) then if Limited_Present (Def) then Check_SPARK_05_Restriction ("limited is not allowed", N); end if; if Abstract_Present (Def) then Check_SPARK_05_Restriction ("abstract is not allowed", N); end if; -- The flag Is_Tagged_Type might have already been set by -- Find_Type_Name if it detected an error for declaration T. This -- arises in the case of private tagged types where the full view -- omits the word tagged. Is_Tagged := Tagged_Present (Def) or else (Serious_Errors_Detected > 0 and then Is_Tagged_Type (T)); Set_Is_Limited_Record (T, Limited_Present (Def)); if Is_Tagged then Set_Is_Tagged_Type (T, True); Set_No_Tagged_Streams_Pragma (T, No_Tagged_Streams); end if; -- Type is abstract if full declaration carries keyword, or if -- previous partial view did. Set_Is_Abstract_Type (T, Is_Abstract_Type (T) or else Abstract_Present (Def)); else Check_SPARK_05_Restriction ("interface is not allowed", N); Is_Tagged := True; Analyze_Interface_Declaration (T, Def); if Present (Discriminant_Specifications (N)) then Error_Msg_N ("interface types cannot have discriminants", Defining_Identifier (First (Discriminant_Specifications (N)))); end if; end if; -- First pass: if there are self-referential access components, -- create the required anonymous access type declarations, and if -- need be an incomplete type declaration for T itself. Check_Anonymous_Access_Components (N, T, Prev, Component_List (Def)); if Ada_Version >= Ada_2005 and then Present (Interface_List (Def)) then Check_Interfaces (N, Def); declare Ifaces_List : Elist_Id; begin -- Ada 2005 (AI-251): Collect the list of progenitors that are not -- already in the parents. Collect_Interfaces (T => T, Ifaces_List => Ifaces_List, Exclude_Parents => True); Set_Interfaces (T, Ifaces_List); end; end if; -- Records constitute a scope for the component declarations within. -- The scope is created prior to the processing of these declarations. -- Discriminants are processed first, so that they are visible when -- processing the other components. The Ekind of the record type itself -- is set to E_Record_Type (subtypes appear as E_Record_Subtype). -- Enter record scope Push_Scope (T); -- If an incomplete or private type declaration was already given for -- the type, then this scope already exists, and the discriminants have -- been declared within. We must verify that the full declaration -- matches the incomplete one. Check_Or_Process_Discriminants (N, T, Prev); Set_Is_Constrained (T, not Has_Discriminants (T)); Set_Has_Delayed_Freeze (T, True); -- For tagged types add a manually analyzed component corresponding -- to the component _tag, the corresponding piece of tree will be -- expanded as part of the freezing actions if it is not a CPP_Class. if Is_Tagged then -- Do not add the tag unless we are in expansion mode if Expander_Active then Tag_Comp := Make_Defining_Identifier (Sloc (Def), Name_uTag); Enter_Name (Tag_Comp); Set_Ekind (Tag_Comp, E_Component); Set_Is_Tag (Tag_Comp); Set_Is_Aliased (Tag_Comp); Set_Etype (Tag_Comp, RTE (RE_Tag)); Set_DT_Entry_Count (Tag_Comp, No_Uint); Set_Original_Record_Component (Tag_Comp, Tag_Comp); Init_Component_Location (Tag_Comp); -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the -- implemented interfaces. if Has_Interfaces (T) then Add_Interface_Tag_Components (N, T); end if; end if; Make_Class_Wide_Type (T); Set_Direct_Primitive_Operations (T, New_Elmt_List); end if; -- We must suppress range checks when processing record components in -- the presence of discriminants, since we don't want spurious checks to -- be generated during their analysis, but Suppress_Range_Checks flags -- must be reset the after processing the record definition. -- Note: this is the only use of Kill_Range_Checks, and is a bit odd, -- couldn't we just use the normal range check suppression method here. -- That would seem cleaner ??? if Has_Discriminants (T) and then not Range_Checks_Suppressed (T) then Set_Kill_Range_Checks (T, True); Record_Type_Definition (Def, Prev); Set_Kill_Range_Checks (T, False); else Record_Type_Definition (Def, Prev); end if; -- Exit from record scope End_Scope; -- Ada 2005 (AI-251 and AI-345): Derive the interface subprograms of all -- the implemented interfaces and associate them an aliased entity. if Is_Tagged and then not Is_Empty_List (Interface_List (Def)) then Derive_Progenitor_Subprograms (T, T); end if; Check_Function_Writable_Actuals (N); end Record_Type_Declaration; ---------------------------- -- Record_Type_Definition -- ---------------------------- procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id) is Component : Entity_Id; Ctrl_Components : Boolean := False; Final_Storage_Only : Boolean; T : Entity_Id; begin if Ekind (Prev_T) = E_Incomplete_Type then T := Full_View (Prev_T); else T := Prev_T; end if; -- In SPARK, tagged types and type extensions may only be declared in -- the specification of library unit packages. if Present (Def) and then Is_Tagged_Type (T) then declare Typ : Node_Id; Ctxt : Node_Id; begin if Nkind (Parent (Def)) = N_Full_Type_Declaration then Typ := Parent (Def); else pragma Assert (Nkind (Parent (Def)) = N_Derived_Type_Definition); Typ := Parent (Parent (Def)); end if; Ctxt := Parent (Typ); if Nkind (Ctxt) = N_Package_Body and then Nkind (Parent (Ctxt)) = N_Compilation_Unit then Check_SPARK_05_Restriction ("type should be defined in package specification", Typ); elsif Nkind (Ctxt) /= N_Package_Specification or else Nkind (Parent (Parent (Ctxt))) /= N_Compilation_Unit then Check_SPARK_05_Restriction ("type should be defined in library unit package", Typ); end if; end; end if; Final_Storage_Only := not Is_Controlled_Active (T); -- Ada 2005: Check whether an explicit Limited is present in a derived -- type declaration. if Nkind (Parent (Def)) = N_Derived_Type_Definition and then Limited_Present (Parent (Def)) then Set_Is_Limited_Record (T); end if; -- If the component list of a record type is defined by the reserved -- word null and there is no discriminant part, then the record type has -- no components and all records of the type are null records (RM 3.7) -- This procedure is also called to process the extension part of a -- record extension, in which case the current scope may have inherited -- components. if No (Def) or else No (Component_List (Def)) or else Null_Present (Component_List (Def)) then if not Is_Tagged_Type (T) then Check_SPARK_05_Restriction ("untagged record cannot be null", Def); end if; else Analyze_Declarations (Component_Items (Component_List (Def))); if Present (Variant_Part (Component_List (Def))) then Check_SPARK_05_Restriction ("variant part is not allowed", Def); Analyze (Variant_Part (Component_List (Def))); end if; end if; -- After completing the semantic analysis of the record definition, -- record components, both new and inherited, are accessible. Set their -- kind accordingly. Exclude malformed itypes from illegal declarations, -- whose Ekind may be void. Component := First_Entity (Current_Scope); while Present (Component) loop if Ekind (Component) = E_Void and then not Is_Itype (Component) then Set_Ekind (Component, E_Component); Init_Component_Location (Component); end if; Propagate_Concurrent_Flags (T, Etype (Component)); if Ekind (Component) /= E_Component then null; -- Do not set Has_Controlled_Component on a class-wide equivalent -- type. See Make_CW_Equivalent_Type. elsif not Is_Class_Wide_Equivalent_Type (T) and then (Has_Controlled_Component (Etype (Component)) or else (Chars (Component) /= Name_uParent and then Is_Controlled_Active (Etype (Component)))) then Set_Has_Controlled_Component (T, True); Final_Storage_Only := Final_Storage_Only and then Finalize_Storage_Only (Etype (Component)); Ctrl_Components := True; end if; Next_Entity (Component); end loop; -- A Type is Finalize_Storage_Only only if all its controlled components -- are also. if Ctrl_Components then Set_Finalize_Storage_Only (T, Final_Storage_Only); end if; -- Place reference to end record on the proper entity, which may -- be a partial view. if Present (Def) then Process_End_Label (Def, 'e', Prev_T); end if; end Record_Type_Definition; ------------------------ -- Replace_Components -- ------------------------ procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id) is function Process (N : Node_Id) return Traverse_Result; ------------- -- Process -- ------------- function Process (N : Node_Id) return Traverse_Result is Comp : Entity_Id; begin if Nkind (N) = N_Discriminant_Specification then Comp := First_Discriminant (Typ); while Present (Comp) loop if Chars (Comp) = Chars (Defining_Identifier (N)) then Set_Defining_Identifier (N, Comp); exit; end if; Next_Discriminant (Comp); end loop; elsif Nkind (N) = N_Component_Declaration then Comp := First_Component (Typ); while Present (Comp) loop if Chars (Comp) = Chars (Defining_Identifier (N)) then Set_Defining_Identifier (N, Comp); exit; end if; Next_Component (Comp); end loop; end if; return OK; end Process; procedure Replace is new Traverse_Proc (Process); -- Start of processing for Replace_Components begin Replace (Decl); end Replace_Components; ------------------------------- -- Set_Completion_Referenced -- ------------------------------- procedure Set_Completion_Referenced (E : Entity_Id) is begin -- If in main unit, mark entity that is a completion as referenced, -- warnings go on the partial view when needed. if In_Extended_Main_Source_Unit (E) then Set_Referenced (E); end if; end Set_Completion_Referenced; --------------------- -- Set_Default_SSO -- --------------------- procedure Set_Default_SSO (T : Entity_Id) is begin case Opt.Default_SSO is when ' ' => null; when 'L' => Set_SSO_Set_Low_By_Default (T, True); when 'H' => Set_SSO_Set_High_By_Default (T, True); when others => raise Program_Error; end case; end Set_Default_SSO; --------------------- -- Set_Fixed_Range -- --------------------- -- The range for fixed-point types is complicated by the fact that we -- do not know the exact end points at the time of the declaration. This -- is true for three reasons: -- A size clause may affect the fudging of the end-points. -- A small clause may affect the values of the end-points. -- We try to include the end-points if it does not affect the size. -- This means that the actual end-points must be established at the -- point when the type is frozen. Meanwhile, we first narrow the range -- as permitted (so that it will fit if necessary in a small specified -- size), and then build a range subtree with these narrowed bounds. -- Set_Fixed_Range constructs the range from real literal values, and -- sets the range as the Scalar_Range of the given fixed-point type entity. -- The parent of this range is set to point to the entity so that it is -- properly hooked into the tree (unlike normal Scalar_Range entries for -- other scalar types, which are just pointers to the range in the -- original tree, this would otherwise be an orphan). -- The tree is left unanalyzed. When the type is frozen, the processing -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not -- analyzed, and uses this as an indication that it should complete -- work on the range (it will know the final small and size values). procedure Set_Fixed_Range (E : Entity_Id; Loc : Source_Ptr; Lo : Ureal; Hi : Ureal) is S : constant Node_Id := Make_Range (Loc, Low_Bound => Make_Real_Literal (Loc, Lo), High_Bound => Make_Real_Literal (Loc, Hi)); begin Set_Scalar_Range (E, S); Set_Parent (S, E); -- Before the freeze point, the bounds of a fixed point are universal -- and carry the corresponding type. Set_Etype (Low_Bound (S), Universal_Real); Set_Etype (High_Bound (S), Universal_Real); end Set_Fixed_Range; ---------------------------------- -- Set_Scalar_Range_For_Subtype -- ---------------------------------- procedure Set_Scalar_Range_For_Subtype (Def_Id : Entity_Id; R : Node_Id; Subt : Entity_Id) is Kind : constant Entity_Kind := Ekind (Def_Id); begin -- Defend against previous error if Nkind (R) = N_Error then return; end if; Set_Scalar_Range (Def_Id, R); -- We need to link the range into the tree before resolving it so -- that types that are referenced, including importantly the subtype -- itself, are properly frozen (Freeze_Expression requires that the -- expression be properly linked into the tree). Of course if it is -- already linked in, then we do not disturb the current link. if No (Parent (R)) then Set_Parent (R, Def_Id); end if; -- Reset the kind of the subtype during analysis of the range, to -- catch possible premature use in the bounds themselves. Set_Ekind (Def_Id, E_Void); Process_Range_Expr_In_Decl (R, Subt, Subtyp => Def_Id); Set_Ekind (Def_Id, Kind); end Set_Scalar_Range_For_Subtype; -------------------------------------------------------- -- Set_Stored_Constraint_From_Discriminant_Constraint -- -------------------------------------------------------- procedure Set_Stored_Constraint_From_Discriminant_Constraint (E : Entity_Id) is begin -- Make sure set if encountered during Expand_To_Stored_Constraint Set_Stored_Constraint (E, No_Elist); -- Give it the right value if Is_Constrained (E) and then Has_Discriminants (E) then Set_Stored_Constraint (E, Expand_To_Stored_Constraint (E, Discriminant_Constraint (E))); end if; end Set_Stored_Constraint_From_Discriminant_Constraint; ------------------------------------- -- Signed_Integer_Type_Declaration -- ------------------------------------- procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id) is Implicit_Base : Entity_Id; Base_Typ : Entity_Id; Lo_Val : Uint; Hi_Val : Uint; Errs : Boolean := False; Lo : Node_Id; Hi : Node_Id; function Can_Derive_From (E : Entity_Id) return Boolean; -- Determine whether given bounds allow derivation from specified type procedure Check_Bound (Expr : Node_Id); -- Check bound to make sure it is integral and static. If not, post -- appropriate error message and set Errs flag --------------------- -- Can_Derive_From -- --------------------- -- Note we check both bounds against both end values, to deal with -- strange types like ones with a range of 0 .. -12341234. function Can_Derive_From (E : Entity_Id) return Boolean is Lo : constant Uint := Expr_Value (Type_Low_Bound (E)); Hi : constant Uint := Expr_Value (Type_High_Bound (E)); begin return Lo <= Lo_Val and then Lo_Val <= Hi and then Lo <= Hi_Val and then Hi_Val <= Hi; end Can_Derive_From; ----------------- -- Check_Bound -- ----------------- procedure Check_Bound (Expr : Node_Id) is begin -- If a range constraint is used as an integer type definition, each -- bound of the range must be defined by a static expression of some -- integer type, but the two bounds need not have the same integer -- type (Negative bounds are allowed.) (RM 3.5.4) if not Is_Integer_Type (Etype (Expr)) then Error_Msg_N ("integer type definition bounds must be of integer type", Expr); Errs := True; elsif not Is_OK_Static_Expression (Expr) then Flag_Non_Static_Expr ("non-static expression used for integer type bound!", Expr); Errs := True; -- The bounds are folded into literals, and we set their type to be -- universal, to avoid typing difficulties: we cannot set the type -- of the literal to the new type, because this would be a forward -- reference for the back end, and if the original type is user- -- defined this can lead to spurious semantic errors (e.g. 2928-003). else if Is_Entity_Name (Expr) then Fold_Uint (Expr, Expr_Value (Expr), True); end if; Set_Etype (Expr, Universal_Integer); end if; end Check_Bound; -- Start of processing for Signed_Integer_Type_Declaration begin -- Create an anonymous base type Implicit_Base := Create_Itype (E_Signed_Integer_Type, Parent (Def), T, 'B'); -- Analyze and check the bounds, they can be of any integer type Lo := Low_Bound (Def); Hi := High_Bound (Def); -- Arbitrarily use Integer as the type if either bound had an error if Hi = Error or else Lo = Error then Base_Typ := Any_Integer; Set_Error_Posted (T, True); -- Here both bounds are OK expressions else Analyze_And_Resolve (Lo, Any_Integer); Analyze_And_Resolve (Hi, Any_Integer); Check_Bound (Lo); Check_Bound (Hi); if Errs then Hi := Type_High_Bound (Standard_Long_Long_Integer); Lo := Type_Low_Bound (Standard_Long_Long_Integer); end if; -- Find type to derive from Lo_Val := Expr_Value (Lo); Hi_Val := Expr_Value (Hi); if Can_Derive_From (Standard_Short_Short_Integer) then Base_Typ := Base_Type (Standard_Short_Short_Integer); elsif Can_Derive_From (Standard_Short_Integer) then Base_Typ := Base_Type (Standard_Short_Integer); elsif Can_Derive_From (Standard_Integer) then Base_Typ := Base_Type (Standard_Integer); elsif Can_Derive_From (Standard_Long_Integer) then Base_Typ := Base_Type (Standard_Long_Integer); elsif Can_Derive_From (Standard_Long_Long_Integer) then Check_Restriction (No_Long_Long_Integers, Def); Base_Typ := Base_Type (Standard_Long_Long_Integer); else Base_Typ := Base_Type (Standard_Long_Long_Integer); Error_Msg_N ("integer type definition bounds out of range", Def); Hi := Type_High_Bound (Standard_Long_Long_Integer); Lo := Type_Low_Bound (Standard_Long_Long_Integer); end if; end if; -- Complete both implicit base and declared first subtype entities. The -- inheritance of the rep item chain ensures that SPARK-related pragmas -- are not clobbered when the signed integer type acts as a full view of -- a private type. Set_Etype (Implicit_Base, Base_Typ); Set_Size_Info (Implicit_Base, Base_Typ); Set_RM_Size (Implicit_Base, RM_Size (Base_Typ)); Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ)); Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ)); Set_Ekind (T, E_Signed_Integer_Subtype); Set_Etype (T, Implicit_Base); Set_Size_Info (T, Implicit_Base); Inherit_Rep_Item_Chain (T, Implicit_Base); Set_Scalar_Range (T, Def); Set_RM_Size (T, UI_From_Int (Minimum_Size (T))); Set_Is_Constrained (T); end Signed_Integer_Type_Declaration; end Sem_Ch3;
shintakezou/drake
Ada
15,238
adb
with Ada.Exceptions.Finally; with Ada.Unchecked_Conversion; with Ada.Unchecked_Deallocation; with System; package body Ada.Containers.Limited_Ordered_Maps is use type Binary_Trees.Node_Access; -- diff function Upcast is new Unchecked_Conversion (Cursor, Binary_Trees.Node_Access); function Downcast is new Unchecked_Conversion (Binary_Trees.Node_Access, Cursor); -- diff (Upcast) -- -- diff (Downcast) -- procedure Free is new Unchecked_Deallocation (Key_Type, Key_Access); procedure Free is new Unchecked_Deallocation (Element_Type, Element_Access); procedure Free is new Unchecked_Deallocation (Node, Cursor); function Compare_Keys (Left, Right : Key_Type) return Integer; function Compare_Keys (Left, Right : Key_Type) return Integer is begin if Left < Right then return -1; elsif Right < Left then return 1; else return 0; end if; end Compare_Keys; type Context_Type is limited record Left : not null access Key_Type; end record; pragma Suppress_Initialization (Context_Type); function Compare_Key ( Position : not null Binary_Trees.Node_Access; Params : System.Address) return Integer; function Compare_Key ( Position : not null Binary_Trees.Node_Access; Params : System.Address) return Integer is Context : Context_Type; for Context'Address use Params; begin return Compare_Keys (Context.Left.all, Downcast (Position).Key.all); end Compare_Key; -- diff (Allocate_Element) -- -- -- -- -- -- -- -- -- diff (Allocate_Node) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- diff (Copy_Node) -- -- -- -- -- -- -- -- -- -- -- -- procedure Free_Node (Object : in out Binary_Trees.Node_Access); procedure Free_Node (Object : in out Binary_Trees.Node_Access) is X : Cursor := Downcast (Object); begin Free (X.Key); Free (X.Element); Free (X); Object := null; end Free_Node; -- diff (Allocate_Data) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- diff (Copy_Data) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- diff (Free) procedure Free_Data (Data : in out Map); procedure Free_Data (Data : in out Map) is -- diff begin Binary_Trees.Free (Data.Root, Data.Length, Free => Free_Node'Access); -- diff -- diff end Free_Data; -- diff (Unique) -- -- -- -- -- -- -- -- -- -- -- -- -- implementation function Equivalent_Keys (Left, Right : Key_Type) return Boolean is begin return Compare_Keys (Left, Right) = 0; end Equivalent_Keys; function Empty_Map return Map is begin return (Finalization.Limited_Controlled with Root => null, Length => 0); end Empty_Map; function Has_Element (Position : Cursor) return Boolean is begin return Position /= No_Element; end Has_Element; -- diff ("=") -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function Length (Container : Map) return Count_Type is -- diff begin -- diff -- diff -- diff return Container.Length; -- diff end Length; function Is_Empty (Container : Map) return Boolean is -- diff begin return Container.Root = null; end Is_Empty; procedure Clear (Container : in out Map) is begin Free_Data (Container); end Clear; function Key (Position : Cursor) return Key_Reference_Type is begin return (Element => Position.Key.all'Access); end Key; -- diff (Element) -- -- -- -- diff (Replace_Element) -- -- -- -- -- -- -- -- procedure Query_Element ( Position : Cursor; Process : not null access procedure ( Key : Key_Type; Element : Element_Type)) is begin Process (Position.Key.all, Position.Element.all); end Query_Element; procedure Update_Element ( Container : in out Map'Class; Position : Cursor; Process : not null access procedure ( Key : Key_Type; Element : in out Element_Type)) is begin Process ( Position.Key.all, Reference (Map (Container), Position).Element.all); end Update_Element; function Constant_Reference (Container : aliased Map; Position : Cursor) return Constant_Reference_Type is pragma Unreferenced (Container); begin return (Element => Position.Element.all'Access); end Constant_Reference; function Reference (Container : aliased in out Map; Position : Cursor) return Reference_Type is pragma Unreferenced (Container); begin return (Element => Position.Element.all'Access); end Reference; function Constant_Reference (Container : aliased Map; Key : Key_Type) return Constant_Reference_Type is begin return Constant_Reference (Container, Find (Container, Key)); end Constant_Reference; function Reference (Container : aliased in out Map; Key : Key_Type) return Reference_Type is begin return Reference (Container, Find (Container, Key)); end Reference; -- diff (Assign) -- -- -- -- -- -- -- diff (Copy) -- -- -- -- -- -- -- -- -- procedure Move (Target : in out Map; Source : in out Map) is begin if Target.Root /= Source.Root then Clear (Target); Target.Root := Source.Root; Target.Length := Source.Length; Source.Root := null; Source.Length := 0; end if; end Move; procedure Insert ( Container : in out Map'Class; New_Key : not null access function return Key_Type; New_Item : not null access function return Element_Type; Position : out Cursor; Inserted : out Boolean) is type Pair is record Key : Key_Access; Node : Cursor; end record; pragma Suppress_Initialization (Pair); procedure Finally (X : in out Pair); procedure Finally (X : in out Pair) is begin Free (X.Key); Free (X.Node); end Finally; package Holder is new Exceptions.Finally.Scoped_Holder (Pair, Finally); New_Pair : aliased Pair := (new Key_Type'(New_Key.all), null); Before : constant Cursor := Ceiling (Map (Container), New_Pair.Key.all); begin Holder.Assign (New_Pair); Inserted := Before = null or else New_Pair.Key.all < Before.Key.all; if Inserted then New_Pair.Node := new Node; New_Pair.Node.Key := New_Pair.Key; New_Pair.Node.Element := new Element_Type'(New_Item.all); Holder.Clear; Position := New_Pair.Node; Base.Insert ( Container.Root, Container.Length, Upcast (Before), Upcast (Position)); -- diff else Position := Before; end if; end Insert; -- diff (Insert) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- procedure Insert ( Container : in out Map'Class; Key : not null access function return Key_Type; New_Item : not null access function return Element_Type) is Position : Cursor; Inserted : Boolean; begin Insert (Container, Key, New_Item, Position, Inserted); if not Inserted then raise Constraint_Error; end if; end Insert; -- diff (Include) -- -- -- -- -- -- -- -- -- -- -- -- -- diff (Replace) -- -- -- -- -- -- procedure Exclude (Container : in out Map; Key : Key_Type) is Position : Cursor := Find (Container, Key); begin if Position /= null then Delete (Container, Position); end if; end Exclude; procedure Delete (Container : in out Map; Key : Key_Type) is Position : Cursor := Find (Container, Key); begin Delete (Container, Position); end Delete; procedure Delete (Container : in out Map; Position : in out Cursor) is Position_2 : Binary_Trees.Node_Access := Upcast (Position); begin -- diff -- diff -- diff -- diff Base.Remove (Container.Root, Container.Length, Position_2); -- diff Free_Node (Position_2); Position := null; end Delete; procedure Delete_First (Container : in out Map'Class) is Position : Cursor := First (Map (Container)); begin Delete (Map (Container), Position); end Delete_First; procedure Delete_Last (Container : in out Map'Class) is Position : Cursor := Last (Map (Container)); begin Delete (Map (Container), Position); end Delete_Last; function First (Container : Map) return Cursor is begin -- diff -- diff -- diff -- diff return Downcast (Binary_Trees.First ( Container.Root)); -- diff end First; -- diff (First_Element) -- -- -- -- -- diff (First_Key) -- -- -- -- function Last (Container : Map) return Cursor is begin return Downcast (Binary_Trees.Last (Container.Root)); -- diff -- diff -- diff -- diff -- diff -- diff end Last; -- diff (Last_Element) -- -- -- -- -- diff (Last_Key) -- -- -- -- function Next (Position : Cursor) return Cursor is begin return Downcast (Binary_Trees.Next (Upcast (Position))); end Next; procedure Next (Position : in out Cursor) is begin Position := Downcast (Binary_Trees.Next (Upcast (Position))); end Next; function Previous (Position : Cursor) return Cursor is begin return Downcast (Binary_Trees.Previous (Upcast (Position))); end Previous; procedure Previous (Position : in out Cursor) is begin Position := Downcast (Binary_Trees.Previous (Upcast (Position))); end Previous; function Find (Container : Map; Key : Key_Type) return Cursor is begin -- diff -- diff -- diff -- diff declare Context : Context_Type := (Left => Key'Unrestricted_Access); begin return Downcast (Binary_Trees.Find ( Container.Root, Binary_Trees.Just, Context'Address, Compare => Compare_Key'Access)); end; -- diff end Find; -- diff (Element) -- -- -- -- -- -- function Floor (Container : Map; Key : Key_Type) return Cursor is begin -- diff -- diff -- diff -- diff declare Context : Context_Type := (Left => Key'Unrestricted_Access); begin return Downcast (Binary_Trees.Find ( Container.Root, Binary_Trees.Floor, Context'Address, Compare => Compare_Key'Access)); end; -- diff end Floor; function Ceiling (Container : Map; Key : Key_Type) return Cursor is begin -- diff -- diff -- diff -- diff declare Context : Context_Type := (Left => Key'Unrestricted_Access); begin return Downcast (Binary_Trees.Find ( Container.Root, Binary_Trees.Ceiling, Context'Address, Compare => Compare_Key'Access)); end; -- diff end Ceiling; function Contains (Container : Map; Key : Key_Type) return Boolean is begin return Find (Container, Key) /= null; end Contains; function "<" (Left, Right : Cursor) return Boolean is begin return Left /= Right and then Left.Key.all < Right.Key.all; end "<"; function ">" (Left, Right : Cursor) return Boolean is begin return Right < Left; end ">"; function "<" (Left : Cursor; Right : Key_Type) return Boolean is begin return Left.Key.all < Right; end "<"; function ">" (Left : Cursor; Right : Key_Type) return Boolean is begin return Right < Left; end ">"; function "<" (Left : Key_Type; Right : Cursor) return Boolean is begin return Left < Right.Key.all; end "<"; function ">" (Left : Key_Type; Right : Cursor) return Boolean is begin return Right < Left; end ">"; procedure Iterate ( Container : Map'Class; Process : not null access procedure (Position : Cursor)) is type P1 is access procedure (Position : Cursor); type P2 is access procedure (Position : Binary_Trees.Node_Access); function Cast is new Unchecked_Conversion (P1, P2); begin -- diff -- diff Binary_Trees.Iterate ( Container.Root, Cast (Process)); -- diff end Iterate; procedure Reverse_Iterate ( Container : Map'Class; Process : not null access procedure (Position : Cursor)) is type P1 is access procedure (Position : Cursor); type P2 is access procedure (Position : Binary_Trees.Node_Access); function Cast is new Unchecked_Conversion (P1, P2); begin -- diff -- diff Binary_Trees.Reverse_Iterate ( Container.Root, Cast (Process)); -- diff end Reverse_Iterate; function Iterate (Container : Map'Class) return Map_Iterator_Interfaces.Reversible_Iterator'Class is begin return Map_Iterator'( First => First (Map (Container)), Last => Last (Map (Container))); end Iterate; function Iterate (Container : Map'Class; First, Last : Cursor) return Map_Iterator_Interfaces.Reversible_Iterator'Class is pragma Unreferenced (Container); Actual_First : Cursor := First; Actual_Last : Cursor := Last; begin if Actual_First = No_Element or else Actual_Last = No_Element or else Actual_Last < Actual_First then Actual_First := No_Element; Actual_Last := No_Element; end if; return Map_Iterator'(First => Actual_First, Last => Actual_Last); end Iterate; -- diff (Adjust) -- -- -- overriding function First (Object : Map_Iterator) return Cursor is begin return Object.First; end First; overriding function Next (Object : Map_Iterator; Position : Cursor) return Cursor is begin if Position = Object.Last then return No_Element; else return Next (Position); end if; end Next; overriding function Last (Object : Map_Iterator) return Cursor is begin return Object.Last; end Last; overriding function Previous (Object : Map_Iterator; Position : Cursor) return Cursor is begin if Position = Object.First then return No_Element; else return Previous (Position); end if; end Previous; package body Equivalents is function "=" (Left, Right : Map) return Boolean is function Equivalent (Left, Right : not null Binary_Trees.Node_Access) return Boolean; function Equivalent (Left, Right : not null Binary_Trees.Node_Access) return Boolean is begin return Equivalent_Keys ( Downcast (Left).Key.all, Downcast (Right).Key.all) and then Downcast (Left).Element.all = Downcast (Right).Element.all; end Equivalent; begin return Left.Length = Right.Length and then Binary_Trees.Equivalent ( Left.Root, Right.Root, Equivalent => Equivalent'Access); end "="; end Equivalents; end Ada.Containers.Limited_Ordered_Maps;
onox/orka
Ada
2,750
ads
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2022 onox <[email protected]> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. private with Ada.Containers.Indefinite_Holders; with Orka.Numerics.Tensors; generic with package Tensors is new Orka.Numerics.Tensors (<>); type Tensor (<>) is new Tensors.Tensor with private; package Orka.Numerics.Kalman is pragma Preelaborate; use type Tensors.Tensor_Shape; subtype Vector is Tensor; subtype Matrix is Tensor; type Update_Phase is (Time_Update, Measurement_Update); type Filter_Kind is (Filter_UKF, Filter_CDKF); type State_Covariance is private; type Weights_Type (N : Positive; Kind : Filter_Kind) is private; type Filter (Kind : Filter_Kind; Dimension_X, Dimension_Z : Positive) is tagged private; function State (Object : Filter) return Vector with Post => State'Result.Shape = (1 => Object.Dimension_X); procedure Set_State (Object : in out Filter; State : Vector) with Pre => State.Shape = (1 => Object.Dimension_X); private subtype Element_Type is Tensors.Element_Type; package Tensor_Holders is new Ada.Containers.Indefinite_Holders (Tensor); -- These predicates cannot be applied to the formal types above subtype Vector_Holder is Tensor_Holders.Holder; subtype Matrix_Holder is Tensor_Holders.Holder; type Weights_Type (N : Positive; Kind : Filter_Kind) is record Mean : Vector_Holder; Scaling_Factor : Element_Type; case Kind is when Filter_UKF => Covariance : Vector_Holder; when Filter_CDKF => Covariance_1 : Element_Type; Covariance_2 : Element_Type; end case; end record; type State_Covariance is record State : Vector_Holder; Covariance : Matrix_Holder; end record; type Filter (Kind : Filter_Kind; Dimension_X, Dimension_Z : Positive) is tagged record Process_Noise : Matrix_Holder; Measurement_Noise : Matrix_Holder; Weights : Weights_Type (Dimension_X, Kind); Estimate : State_Covariance; end record; function State (Object : Filter) return Vector is (Object.Estimate.State.Element); end Orka.Numerics.Kalman;
BrickBot/Bound-T-H8-300
Ada
3,479
ads
-- Storage.Reserved_Names -- -- Reserved (ie. forbidden) names of cells. -- -- Cell names are used in some contexts (eg. Calculator.Formulas) in -- which they must not be confused with the names of other, cell-like -- things (eg. synthetic iteration counter identifiers). Here we list -- all the reserved names. When a new cell is created, its Name is -- checked against these reserved names, and a Fault is emitted if -- there is a conflict. -- -- A component of the Bound-T Worst-Case Execution Time Tool. -- ------------------------------------------------------------------------------- -- Copyright (c) 1999 .. 2015 Tidorum Ltd -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met: -- -- 1. Redistributions of source code must retain the above copyright notice, this -- list of conditions and the following disclaimer. -- 2. Redistributions in binary form must reproduce the above copyright notice, -- this list of conditions and the following disclaimer in the documentation -- and/or other materials provided with the distribution. -- -- This software is provided by the copyright holders and contributors "as is" and -- any express or implied warranties, including, but not limited to, the implied -- warranties of merchantability and fitness for a particular purpose are -- disclaimed. In no event shall the copyright owner or contributors be liable for -- any direct, indirect, incidental, special, exemplary, or consequential damages -- (including, but not limited to, procurement of substitute goods or services; -- loss of use, data, or profits; or business interruption) however caused and -- on any theory of liability, whether in contract, strict liability, or tort -- (including negligence or otherwise) arising in any way out of the use of this -- software, even if advised of the possibility of such damage. -- -- Other modules (files) of this software composition should contain their -- own copyright statements, which may have different copyright and usage -- conditions. The above conditions apply to this file. ------------------------------------------------------------------------------- -- -- $Revision: 1.3 $ -- $Date: 2015/10/24 19:36:52 $ -- -- $Log: storage-reserved_names.ads,v $ -- Revision 1.3 2015/10/24 19:36:52 niklas -- Moved to free licence. -- -- Revision 1.2 2009-11-27 11:28:08 niklas -- BT-CH-0184: Bit-widths, Word_T, failed modular analysis. -- -- Revision 1.1 2008/04/26 19:19:45 niklas -- BT-CH-0124: Joint loop counters and induction variables. -- package Storage.Reserved_Names is type Item_T is (Iter_Count, Mod_Factor1, Mod_Factor2); -- -- Listing all the reserved names. -- -- Iter_Count -- The identifier for a synthetic, joint loop-iteration -- counter, used in Calculator.Formulas for modelling the -- values of induction variables. -- Mod_Factor1, 2 -- The identifieds for existentially quantified variables -- used to compute "mod 2**W" when modelling comparisons of -- W-bit numbers using modular arithmetic. type Name_Ref is access String; -- -- Refers to a reserved name. Name : constant array (Item_T) of Name_Ref := ( Iter_Count => new String'("n_"), Mod_Factor1 => new String'("m1_"), Mod_Factor2 => new String'("m2_")); -- -- All the reserved names. end Storage.Reserved_Names;
reznikmm/matreshka
Ada
3,774
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- 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.Internals.Files; package League.Directories.Internals is pragma Preelaborate; function Internal (Self : League.Directories.Directory_Information'Class) return Matreshka.Internals.Files.Shared_File_Information_Access; function Create (Self : Matreshka.Internals.Files.Shared_File_Information_Access) return League.Directories.Directory_Information; end League.Directories.Internals;
AaronC98/PlaneSystem
Ada
10,191
adb
------------------------------------------------------------------------------ -- Ada Web Server -- -- -- -- Copyright (C) 2000-2014, AdaCore -- -- -- -- This library is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by the -- -- Free Software Foundation; either version 3, or (at your option) any -- -- later version. This library is distributed in the hope that it will be -- -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- -- -- -- -- -- -- -- -- 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/>. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ------------------------------------------------------------------------------ pragma Ada_2012; with Ada.Unchecked_Deallocation; with GNAT.Regpat; with AWS.Dispatchers.Callback; with AWS.Messages; package body AWS.Services.Dispatchers.URI is use AWS.Dispatchers; use GNAT; type Regpat_Access is access all Regpat.Pattern_Matcher; type Reg_URI is new Std_URI with record Reg_URI : Regpat_Access; end record; overriding function Clone (URI : Reg_URI) return Reg_URI; -- Returns a deep copy of URI overriding function Match (URI : Reg_URI; Value : String) return Boolean; procedure Unchecked_Free is new Ada.Unchecked_Deallocation (Std_URI'Class, URI_Class_Access); ---------- -- Copy -- ---------- overriding function Clone (Dispatcher : Handler) return Handler is New_Dispatcher : Handler; Item : URI_Class_Access; begin if Dispatcher.Action /= null then New_Dispatcher.Action := new AWS.Dispatchers.Handler'Class' (AWS.Dispatchers.Handler'Class (Dispatcher.Action.Clone)); end if; for J in Dispatcher.Table.First_Index .. Dispatcher.Table.Last_Index loop -- Could not use "for Item of Dispatcher.Table" because this -- construction is not thread safe, at least in -- GNAT Pro 7.3.0w (20140401-47) Item := Dispatcher.Table.Element (J); URI_Table.Append (New_Dispatcher.Table, new Std_URI'Class'(Std_URI'Class (Item.Clone))); end loop; return New_Dispatcher; end Clone; ----------- -- Clone -- ----------- overriding function Clone (URI : Std_URI) return Std_URI is New_URI : Std_URI := URI; begin if URI.Action /= null then New_URI.Action := new AWS.Dispatchers.Handler'Class' (AWS.Dispatchers.Handler'Class (URI.Action.Clone)); end if; return New_URI; end Clone; ----------- -- Clone -- ----------- overriding function Clone (URI : Reg_URI) return Reg_URI is New_URI : Reg_URI := URI; begin if URI.Action /= null then New_URI.Action := new AWS.Dispatchers.Handler'Class' (AWS.Dispatchers.Handler'Class (URI.Action.Clone)); end if; New_URI.Reg_URI := new Regpat.Pattern_Matcher'(URI.Reg_URI.all); return New_URI; end Clone; -------------- -- Dispatch -- -------------- overriding function Dispatch (Dispatcher : Handler; Request : Status.Data) return Response.Data is use type Response.Data_Mode; URI : constant String := Status.URI (Request); Result : Response.Data; Item : URI_Class_Access; begin for J in Dispatcher.Table.First_Index .. Dispatcher.Table.Last_Index loop -- Could not use "for Item of Dispatcher.Table" because this -- construction is not thread safe, at least in -- GNAT Pro 7.3.0w (20140401-47) Item := Dispatcher.Table.Element (J); if Match (Item.all, URI) then Result := Dispatch (Item.Action.all, Request); -- Returns response if dispatcher did return something, -- otherwise continue to next handler. if Response.Mode (Result) /= Response.No_Data then return Result; end if; end if; end loop; -- No rule found, try the default dispatcher if Dispatcher.Action /= null then return Dispatch (Dispatcher.Action.all, Request); end if; return Response.Acknowledge (Messages.S404, "<p>AWS " & Version & "<p> No rule found for '" & URI & "' in dispatch URI call and no " & "default dispatcher defined."); end Dispatch; -------------- -- Finalize -- -------------- overriding procedure Finalize (Dispatcher : in out Handler) is procedure Unchecked_Free is new Ada.Unchecked_Deallocation (Regpat.Pattern_Matcher, Regpat_Access); Ref_Counter : constant Natural := Dispatcher.Ref_Counter; Item : URI_Class_Access; begin Finalize (AWS.Dispatchers.Handler (Dispatcher)); if Ref_Counter = 1 then while not Dispatcher.Table.Is_Empty loop Item := Dispatcher.Table.Last_Element; Dispatcher.Table.Delete_Last; Free (Item.Action); if Item.all in Reg_URI then Unchecked_Free (Reg_URI (Item.all).Reg_URI); end if; Unchecked_Free (Item); end loop; Free (Dispatcher.Action); end if; end Finalize; ----------- -- Match -- ----------- function Match (URI : Std_URI; Value : String) return Boolean is U : constant String := To_String (URI.URI); begin if URI.Prefix then if U'Length <= Value'Length then return Value (Value'First .. Value'First + U'Length - 1) = U; else return False; end if; else return U = Value; end if; end Match; overriding function Match (URI : Reg_URI; Value : String) return Boolean is begin return Regpat.Match (URI.Reg_URI.all, Value) = Value'First; end Match; -------------- -- Register -- -------------- procedure Register (Dispatcher : in out Handler; URI : String; Action : AWS.Dispatchers.Handler'Class; Prefix : Boolean := False) is Value : constant URI_Class_Access := new Std_URI'(new AWS.Dispatchers.Handler'Class'(Action), To_Unbounded_String (URI), Prefix); begin URI_Table.Append (Dispatcher.Table, Value); end Register; procedure Register (Dispatcher : in out Handler; URI : String; Action : Response.Callback; Prefix : Boolean := False) is begin Register (Dispatcher, URI, AWS.Dispatchers.Callback.Create (Action), Prefix); end Register; ------------------------------- -- Register_Default_Callback -- ------------------------------- procedure Register_Default_Callback (Dispatcher : in out Handler; Action : AWS.Dispatchers.Handler'Class) is begin if Dispatcher.Action /= null then Free (Dispatcher.Action); end if; Dispatcher.Action := new AWS.Dispatchers.Handler'Class'(Action); end Register_Default_Callback; --------------------- -- Register_Regexp -- --------------------- procedure Register_Regexp (Dispatcher : in out Handler; URI : String; Action : AWS.Dispatchers.Handler'Class) is Value : constant URI_Class_Access := new Reg_URI' (new AWS.Dispatchers.Handler'Class'(Action), To_Unbounded_String (URI), False, new Regpat.Pattern_Matcher'(Regpat.Compile (URI))); begin URI_Table.Append (Dispatcher.Table, Value); end Register_Regexp; procedure Register_Regexp (Dispatcher : in out Handler; URI : String; Action : Response.Callback) is begin Register_Regexp (Dispatcher, URI, AWS.Dispatchers.Callback.Create (Action)); end Register_Regexp; ---------------- -- Unregister -- ---------------- procedure Unregister (Dispatcher : in out Handler; URI : String) is begin for K in 1 .. Natural (URI_Table.Length (Dispatcher.Table)) loop declare Item : URI_Class_Access := URI_Table.Element (Dispatcher.Table, K); begin if To_String (Item.URI) = URI then Free (Item.Action); Unchecked_Free (Item); URI_Table.Delete (Dispatcher.Table, K); return; end if; end; end loop; raise Constraint_Error with "URI distpatcher " & URI & " not found"; end Unregister; end AWS.Services.Dispatchers.URI;
io7m/coreland-posix-ada
Ada
5,914
adb
with POSIX.C_Types; use type POSIX.C_Types.Int_t; with System; package body POSIX.File_Status is function Is_Valid (Status : in Status_t) return Boolean is begin return Status.Valid; end Is_Valid; procedure C_FStat_Boundary (Descriptor : in File.Valid_Descriptor_t; Status : out Status_t; Return_Value : out Error.Return_Value_t) --# global in Errno.Errno_Value; --# derives Status, Return_Value from Descriptor, Errno.Errno_Value; --# post ((Return_Value = -1) -> (Error.Get_Error (Errno.Errno_Value) /= Error.Error_None)) --# or ((Return_Value = 0) -> (Error.Get_Error (Errno.Errno_Value) = Error.Error_None)); is --# hide C_FStat_Boundary function C_fstat (Descriptor : in File.Valid_Descriptor_t; Status : in System.Address) return Error.Return_Value_t; pragma Import (C, C_fstat, "fstat"); begin Return_Value := C_fstat (Descriptor => Descriptor, Status => Status.C_Data (Status.C_Data'First)'Address); end C_FStat_Boundary; procedure Get_Descriptor_Status (Descriptor : in File.Valid_Descriptor_t; Status : out Status_t; Error_Value : out Error.Error_t) is Return_Value : Error.Return_Value_t; begin C_FStat_Boundary (Descriptor => Descriptor, Status => Status, Return_Value => Return_Value); case Return_Value is when -1 => Error_Value := Error.Get_Error; Status.Valid := False; when 0 => Error_Value := Error.Error_None; Status.Valid := True; end case; end Get_Descriptor_Status; procedure Get_Status (File_Name : in String; Status : out Status_t; Error_Value : out Error.Error_t) is Descriptor : File.Descriptor_t; begin File.Open_Read_Only (File_Name => File_Name, Non_Blocking => False, Descriptor => Descriptor, Error_Value => Error_Value); if Error_Value = Error.Error_None then Get_Descriptor_Status (Descriptor => Descriptor, Status => Status, Error_Value => Error_Value); else Status := Status_t' (Valid => False, C_Data => C_Status_t'(C_Status_Element_Index_t => 0)); end if; end Get_Status; -- -- Status accessor functions. -- function C_Get_Device_ID (Status : in Status_t) return Device_ID_t is --# hide C_Get_Device_ID function C_posix_stat_st_dev (Status : in System.Address) return Device_ID_t; pragma Import (C, C_posix_stat_st_dev, "posix_stat_st_dev"); begin return C_posix_stat_st_dev (Status.C_Data (Status.C_Data'First)'Address); end C_Get_Device_ID; function Get_Device_ID (Status : in Status_t) return Device_ID_t is begin return C_Get_Device_ID (Status); end Get_Device_ID; function C_Get_INode (Status : in Status_t) return INode_t is --# hide C_Get_INode function C_posix_stat_st_ino (Status : in System.Address) return INode_t; pragma Import (C, C_posix_stat_st_ino, "posix_stat_st_ino"); begin return C_posix_stat_st_ino (Status.C_Data (Status.C_Data'First)'Address); end C_Get_INode; function Get_INode (Status : in Status_t) return INode_t is begin return C_Get_INode (Status); end Get_INode; function C_Get_Mode (Status : in Status_t) return Permissions.Mode_Integer_t is --# hide C_Get_Mode function C_posix_stat_st_mode (Status : in System.Address) return Permissions.Mode_Integer_t; pragma Import (C, C_posix_stat_st_mode, "posix_stat_st_mode"); begin return C_posix_stat_st_mode (Status.C_Data (Status.C_Data'First)'Address); end C_Get_Mode; function Get_Mode (Status : in Status_t) return Permissions.Mode_t is begin return Permissions.Mode_Integer_To_Mode (C_Get_Mode (Status)); end Get_Mode; function C_Get_Number_Of_Links (Status : in Status_t) return Link_Count_t is --# hide C_Get_Number_Of_Links function C_posix_stat_st_nlink (Status : in System.Address) return Link_Count_t; pragma Import (C, C_posix_stat_st_nlink, "posix_stat_st_nlink"); begin return C_posix_stat_st_nlink (Status.C_Data (Status.C_Data'First)'Address); end C_Get_Number_Of_Links; function Get_Number_Of_Links (Status : in Status_t) return Link_Count_t is begin return C_Get_Number_Of_Links (Status); end Get_Number_Of_Links; function C_Get_User_ID (Status : in Status_t) return User_DB.User_ID_t is --# hide C_Get_User_ID function C_posix_stat_st_uid (Status : in System.Address) return User_DB.User_ID_t; pragma Import (C, C_posix_stat_st_uid, "posix_stat_st_uid"); begin return C_posix_stat_st_uid (Status.C_Data (Status.C_Data'First)'Address); end C_Get_User_ID; function Get_User_ID (Status : in Status_t) return User_DB.User_ID_t is begin return C_Get_User_ID (Status); end Get_User_ID; function C_Get_Group_ID (Status : in Status_t) return User_DB.Group_ID_t is --# hide C_Get_Group_ID function C_posix_stat_st_gid (Status : in System.Address) return User_DB.Group_ID_t; pragma Import (C, C_posix_stat_st_gid, "posix_stat_st_gid"); begin return C_posix_stat_st_gid (Status.C_Data (Status.C_Data'First)'Address); end C_Get_Group_ID; function Get_Group_ID (Status : in Status_t) return User_DB.Group_ID_t is begin return C_Get_Group_ID (Status); end Get_Group_ID; function C_Get_Size (Status : in Status_t) return File.Offset_t is --# hide C_Get_Size function C_posix_stat_st_size (Status : in System.Address) return File.Offset_t; pragma Import (C, C_posix_stat_st_size, "posix_stat_st_size"); begin return C_posix_stat_st_size (Status.C_Data (Status.C_Data'First)'Address); end C_Get_Size; function Get_Size (Status : in Status_t) return File.Offset_t is begin return C_Get_Size (Status); end Get_Size; end POSIX.File_Status;
twdroeger/ada-awa
Ada
5,089
ads
----------------------------------------------------------------------- -- awa-components-wikis -- Wiki rendering component -- Copyright (C) 2011, 2015, 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.Strings.Wide_Wide_Unbounded; with Util.Beans.Basic; with Util.Beans.Objects; with ASF.Contexts.Faces; with ASF.Components; with ASF.Components.Html; with Wiki.Strings; with Wiki.Render; with Wiki.Plugins; with Wiki.Render.Links; package AWA.Components.Wikis is use ASF.Contexts.Faces; -- The wiki format of the wiki text. The valid values are: -- dotclear, google, creole, phpbb, mediawiki FORMAT_NAME : constant String := "format"; VALUE_NAME : constant String := ASF.Components.VALUE_NAME; -- The link renderer bean that controls the generation of page and image links. LINKS_NAME : constant String := "links"; -- The plugin factory bean that must be used for Wiki plugins. PLUGINS_NAME : constant String := "plugins"; -- Whether the TOC is rendered in the document. TOC_NAME : constant String := "toc"; -- ------------------------------ -- Wiki component -- ------------------------------ -- -- <awa:wiki value="wiki-text" format="dotclear|google|creole|phpbb" styleClass="class"/> -- type UIWiki is new ASF.Components.Html.UIHtmlComponent with null record; type UIWiki_Access is access all UIWiki'Class; -- Get the wiki format style. The format style is obtained from the <b>format</b> -- attribute name. function Get_Wiki_Style (UI : in UIWiki; Context : in Faces_Context'Class) return Wiki.Wiki_Syntax; -- Get the links renderer that must be used to render image and page links. function Get_Links_Renderer (UI : in UIWiki; Context : in Faces_Context'Class) return Wiki.Render.Links.Link_Renderer_Access; -- Get the plugin factory that must be used by the Wiki parser. function Get_Plugin_Factory (UI : in UIWiki; Context : in Faces_Context'Class) return Wiki.Plugins.Plugin_Factory_Access; -- Render the wiki text overriding procedure Encode_Begin (UI : in UIWiki; Context : in out Faces_Context'Class); use Ada.Strings.Wide_Wide_Unbounded; IMAGE_PREFIX_ATTR : constant String := "image_prefix"; PAGE_PREFIX_ATTR : constant String := "page_prefix"; type Link_Renderer_Bean is new Util.Beans.Basic.Bean and Wiki.Render.Links.Link_Renderer with record Page_Prefix : Unbounded_Wide_Wide_String; Image_Prefix : Unbounded_Wide_Wide_String; end record; -- Make a link adding a prefix unless the link is already absolute. procedure Make_Link (Renderer : in Link_Renderer_Bean; Link : in Wiki.Strings.WString; Prefix : in Unbounded_Wide_Wide_String; URI : out Unbounded_Wide_Wide_String); -- Get the value identified by the name. overriding function Get_Value (From : in Link_Renderer_Bean; Name : in String) return Util.Beans.Objects.Object; -- Set the value identified by the name. overriding procedure Set_Value (From : in out Link_Renderer_Bean; Name : in String; Value : in Util.Beans.Objects.Object); -- Get the image link that must be rendered from the wiki image link. overriding procedure Make_Image_Link (Renderer : in out Link_Renderer_Bean; Link : in Wiki.Strings.WString; URI : out Unbounded_Wide_Wide_String; Width : in out Natural; Height : in out Natural); -- Get the page link that must be rendered from the wiki page link. overriding procedure Make_Page_Link (Renderer : in out Link_Renderer_Bean; Link : in Wiki.Strings.WString; URI : out Unbounded_Wide_Wide_String; Exists : out Boolean); private function Starts_With (Content : in Unbounded_Wide_Wide_String; Item : in String) return Boolean; end AWA.Components.Wikis;
ekoeppen/STM32_Generic_Ada_Drivers
Ada
15,093
ads
-- This spec has been automatically generated from STM32F303xE.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with System; package STM32_SVD.DAC is pragma Preelaborate; --------------- -- Registers -- --------------- subtype CR_EN1_Field is STM32_SVD.Bit; subtype CR_BOFF1_Field is STM32_SVD.Bit; subtype CR_TEN1_Field is STM32_SVD.Bit; subtype CR_TSEL1_Field is STM32_SVD.UInt3; subtype CR_WAVE1_Field is STM32_SVD.UInt2; subtype CR_MAMP1_Field is STM32_SVD.UInt4; subtype CR_DMAEN1_Field is STM32_SVD.Bit; subtype CR_DMAUDRIE1_Field is STM32_SVD.Bit; subtype CR_EN2_Field is STM32_SVD.Bit; subtype CR_BOFF2_Field is STM32_SVD.Bit; subtype CR_TEN2_Field is STM32_SVD.Bit; subtype CR_TSEL2_Field is STM32_SVD.UInt3; subtype CR_WAVE2_Field is STM32_SVD.UInt2; subtype CR_MAMP2_Field is STM32_SVD.UInt4; subtype CR_DMAEN2_Field is STM32_SVD.Bit; subtype CR_DMAUDRIE2_Field is STM32_SVD.Bit; -- control register type CR_Register is record -- DAC channel1 enable EN1 : CR_EN1_Field := 16#0#; -- DAC channel1 output buffer disable BOFF1 : CR_BOFF1_Field := 16#0#; -- DAC channel1 trigger enable TEN1 : CR_TEN1_Field := 16#0#; -- DAC channel1 trigger selection TSEL1 : CR_TSEL1_Field := 16#0#; -- DAC channel1 noise/triangle wave generation enable WAVE1 : CR_WAVE1_Field := 16#0#; -- DAC channel1 mask/amplitude selector MAMP1 : CR_MAMP1_Field := 16#0#; -- DAC channel1 DMA enable DMAEN1 : CR_DMAEN1_Field := 16#0#; -- DAC channel1 DMA Underrun Interrupt enable DMAUDRIE1 : CR_DMAUDRIE1_Field := 16#0#; -- unspecified Reserved_14_15 : STM32_SVD.UInt2 := 16#0#; -- DAC channel2 enable EN2 : CR_EN2_Field := 16#0#; -- DAC channel2 output buffer disable BOFF2 : CR_BOFF2_Field := 16#0#; -- DAC channel2 trigger enable TEN2 : CR_TEN2_Field := 16#0#; -- DAC channel2 trigger selection TSEL2 : CR_TSEL2_Field := 16#0#; -- DAC channel2 noise/triangle wave generation enable WAVE2 : CR_WAVE2_Field := 16#0#; -- DAC channel2 mask/amplitude selector MAMP2 : CR_MAMP2_Field := 16#0#; -- DAC channel2 DMA enable DMAEN2 : CR_DMAEN2_Field := 16#0#; -- DAC channel2 DMA underrun interrupt enable DMAUDRIE2 : CR_DMAUDRIE2_Field := 16#0#; -- unspecified Reserved_30_31 : STM32_SVD.UInt2 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR_Register use record EN1 at 0 range 0 .. 0; BOFF1 at 0 range 1 .. 1; TEN1 at 0 range 2 .. 2; TSEL1 at 0 range 3 .. 5; WAVE1 at 0 range 6 .. 7; MAMP1 at 0 range 8 .. 11; DMAEN1 at 0 range 12 .. 12; DMAUDRIE1 at 0 range 13 .. 13; Reserved_14_15 at 0 range 14 .. 15; EN2 at 0 range 16 .. 16; BOFF2 at 0 range 17 .. 17; TEN2 at 0 range 18 .. 18; TSEL2 at 0 range 19 .. 21; WAVE2 at 0 range 22 .. 23; MAMP2 at 0 range 24 .. 27; DMAEN2 at 0 range 28 .. 28; DMAUDRIE2 at 0 range 29 .. 29; Reserved_30_31 at 0 range 30 .. 31; end record; -- SWTRIGR_SWTRIG array element subtype SWTRIGR_SWTRIG_Element is STM32_SVD.Bit; -- SWTRIGR_SWTRIG array type SWTRIGR_SWTRIG_Field_Array is array (1 .. 2) of SWTRIGR_SWTRIG_Element with Component_Size => 1, Size => 2; -- Type definition for SWTRIGR_SWTRIG type SWTRIGR_SWTRIG_Field (As_Array : Boolean := False) is record case As_Array is when False => -- SWTRIG as a value Val : STM32_SVD.UInt2; when True => -- SWTRIG as an array Arr : SWTRIGR_SWTRIG_Field_Array; end case; end record with Unchecked_Union, Size => 2; for SWTRIGR_SWTRIG_Field use record Val at 0 range 0 .. 1; Arr at 0 range 0 .. 1; end record; -- software trigger register type SWTRIGR_Register is record -- Write-only. DAC channel1 software trigger SWTRIG : SWTRIGR_SWTRIG_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_2_31 : STM32_SVD.UInt30 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SWTRIGR_Register use record SWTRIG at 0 range 0 .. 1; Reserved_2_31 at 0 range 2 .. 31; end record; subtype DHR12R1_DACC1DHR_Field is STM32_SVD.UInt12; -- channel1 12-bit right-aligned data holding register type DHR12R1_Register is record -- DAC channel1 12-bit right-aligned data DACC1DHR : DHR12R1_DACC1DHR_Field := 16#0#; -- unspecified Reserved_12_31 : STM32_SVD.UInt20 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DHR12R1_Register use record DACC1DHR at 0 range 0 .. 11; Reserved_12_31 at 0 range 12 .. 31; end record; subtype DHR12L1_DACC1DHR_Field is STM32_SVD.UInt12; -- channel1 12-bit left aligned data holding register type DHR12L1_Register is record -- unspecified Reserved_0_3 : STM32_SVD.UInt4 := 16#0#; -- DAC channel1 12-bit left-aligned data DACC1DHR : DHR12L1_DACC1DHR_Field := 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 DHR12L1_Register use record Reserved_0_3 at 0 range 0 .. 3; DACC1DHR at 0 range 4 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype DHR8R1_DACC1DHR_Field is STM32_SVD.Byte; -- channel1 8-bit right aligned data holding register type DHR8R1_Register is record -- DAC channel1 8-bit right-aligned data DACC1DHR : DHR8R1_DACC1DHR_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 DHR8R1_Register use record DACC1DHR at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype DHR12R2_DACC2DHR_Field is STM32_SVD.UInt12; -- channel2 12-bit right aligned data holding register type DHR12R2_Register is record -- DAC channel2 12-bit right-aligned data DACC2DHR : DHR12R2_DACC2DHR_Field := 16#0#; -- unspecified Reserved_12_31 : STM32_SVD.UInt20 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DHR12R2_Register use record DACC2DHR at 0 range 0 .. 11; Reserved_12_31 at 0 range 12 .. 31; end record; subtype DHR12L2_DACC2DHR_Field is STM32_SVD.UInt12; -- channel2 12-bit left aligned data holding register type DHR12L2_Register is record -- unspecified Reserved_0_3 : STM32_SVD.UInt4 := 16#0#; -- DAC channel2 12-bit left-aligned data DACC2DHR : DHR12L2_DACC2DHR_Field := 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 DHR12L2_Register use record Reserved_0_3 at 0 range 0 .. 3; DACC2DHR at 0 range 4 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype DHR8R2_DACC2DHR_Field is STM32_SVD.Byte; -- channel2 8-bit right-aligned data holding register type DHR8R2_Register is record -- DAC channel2 8-bit right-aligned data DACC2DHR : DHR8R2_DACC2DHR_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 DHR8R2_Register use record DACC2DHR at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype DHR12RD_DACC1DHR_Field is STM32_SVD.UInt12; subtype DHR12RD_DACC2DHR_Field is STM32_SVD.UInt12; -- Dual DAC 12-bit right-aligned data holding register type DHR12RD_Register is record -- DAC channel1 12-bit right-aligned data DACC1DHR : DHR12RD_DACC1DHR_Field := 16#0#; -- unspecified Reserved_12_15 : STM32_SVD.UInt4 := 16#0#; -- DAC channel2 12-bit right-aligned data DACC2DHR : DHR12RD_DACC2DHR_Field := 16#0#; -- unspecified Reserved_28_31 : STM32_SVD.UInt4 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DHR12RD_Register use record DACC1DHR at 0 range 0 .. 11; Reserved_12_15 at 0 range 12 .. 15; DACC2DHR at 0 range 16 .. 27; Reserved_28_31 at 0 range 28 .. 31; end record; subtype DHR12LD_DACC1DHR_Field is STM32_SVD.UInt12; subtype DHR12LD_DACC2DHR_Field is STM32_SVD.UInt12; -- DUAL DAC 12-bit left aligned data holding register type DHR12LD_Register is record -- unspecified Reserved_0_3 : STM32_SVD.UInt4 := 16#0#; -- DAC channel1 12-bit left-aligned data DACC1DHR : DHR12LD_DACC1DHR_Field := 16#0#; -- unspecified Reserved_16_19 : STM32_SVD.UInt4 := 16#0#; -- DAC channel2 12-bit left-aligned data DACC2DHR : DHR12LD_DACC2DHR_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DHR12LD_Register use record Reserved_0_3 at 0 range 0 .. 3; DACC1DHR at 0 range 4 .. 15; Reserved_16_19 at 0 range 16 .. 19; DACC2DHR at 0 range 20 .. 31; end record; subtype DHR8RD_DACC1DHR_Field is STM32_SVD.Byte; subtype DHR8RD_DACC2DHR_Field is STM32_SVD.Byte; -- DUAL DAC 8-bit right aligned data holding register type DHR8RD_Register is record -- DAC channel1 8-bit right-aligned data DACC1DHR : DHR8RD_DACC1DHR_Field := 16#0#; -- DAC channel2 8-bit right-aligned data DACC2DHR : DHR8RD_DACC2DHR_Field := 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 DHR8RD_Register use record DACC1DHR at 0 range 0 .. 7; DACC2DHR at 0 range 8 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype DOR1_DACC1DOR_Field is STM32_SVD.UInt12; -- channel1 data output register type DOR1_Register is record -- Read-only. DAC channel1 data output DACC1DOR : DOR1_DACC1DOR_Field; -- unspecified Reserved_12_31 : STM32_SVD.UInt20; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DOR1_Register use record DACC1DOR at 0 range 0 .. 11; Reserved_12_31 at 0 range 12 .. 31; end record; subtype DOR2_DACC2DOR_Field is STM32_SVD.UInt12; -- channel2 data output register type DOR2_Register is record -- Read-only. DAC channel2 data output DACC2DOR : DOR2_DACC2DOR_Field; -- unspecified Reserved_12_31 : STM32_SVD.UInt20; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DOR2_Register use record DACC2DOR at 0 range 0 .. 11; Reserved_12_31 at 0 range 12 .. 31; end record; subtype SR_DMAUDR1_Field is STM32_SVD.Bit; subtype SR_DMAUDR2_Field is STM32_SVD.Bit; -- status register type SR_Register is record -- unspecified Reserved_0_12 : STM32_SVD.UInt13 := 16#0#; -- DAC channel1 DMA underrun flag DMAUDR1 : SR_DMAUDR1_Field := 16#0#; -- unspecified Reserved_14_28 : STM32_SVD.UInt15 := 16#0#; -- DAC channel2 DMA underrun flag DMAUDR2 : SR_DMAUDR2_Field := 16#0#; -- unspecified Reserved_30_31 : STM32_SVD.UInt2 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SR_Register use record Reserved_0_12 at 0 range 0 .. 12; DMAUDR1 at 0 range 13 .. 13; Reserved_14_28 at 0 range 14 .. 28; DMAUDR2 at 0 range 29 .. 29; Reserved_30_31 at 0 range 30 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Digital-to-analog converter type DAC_Peripheral is record -- control register CR : aliased CR_Register; -- software trigger register SWTRIGR : aliased SWTRIGR_Register; -- channel1 12-bit right-aligned data holding register DHR12R1 : aliased DHR12R1_Register; -- channel1 12-bit left aligned data holding register DHR12L1 : aliased DHR12L1_Register; -- channel1 8-bit right aligned data holding register DHR8R1 : aliased DHR8R1_Register; -- channel2 12-bit right aligned data holding register DHR12R2 : aliased DHR12R2_Register; -- channel2 12-bit left aligned data holding register DHR12L2 : aliased DHR12L2_Register; -- channel2 8-bit right-aligned data holding register DHR8R2 : aliased DHR8R2_Register; -- Dual DAC 12-bit right-aligned data holding register DHR12RD : aliased DHR12RD_Register; -- DUAL DAC 12-bit left aligned data holding register DHR12LD : aliased DHR12LD_Register; -- DUAL DAC 8-bit right aligned data holding register DHR8RD : aliased DHR8RD_Register; -- channel1 data output register DOR1 : aliased DOR1_Register; -- channel2 data output register DOR2 : aliased DOR2_Register; -- status register SR : aliased SR_Register; end record with Volatile; for DAC_Peripheral use record CR at 16#0# range 0 .. 31; SWTRIGR at 16#4# range 0 .. 31; DHR12R1 at 16#8# range 0 .. 31; DHR12L1 at 16#C# range 0 .. 31; DHR8R1 at 16#10# range 0 .. 31; DHR12R2 at 16#14# range 0 .. 31; DHR12L2 at 16#18# range 0 .. 31; DHR8R2 at 16#1C# range 0 .. 31; DHR12RD at 16#20# range 0 .. 31; DHR12LD at 16#24# range 0 .. 31; DHR8RD at 16#28# range 0 .. 31; DOR1 at 16#2C# range 0 .. 31; DOR2 at 16#30# range 0 .. 31; SR at 16#34# range 0 .. 31; end record; -- Digital-to-analog converter DAC_Periph : aliased DAC_Peripheral with Import, Address => System'To_Address (16#40007400#); end STM32_SVD.DAC;
Tim-Tom/project-euler
Ada
58
ads
package Problem_46 is procedure Solve; end Problem_46;
AaronC98/PlaneSystem
Ada
4,158
ads
------------------------------------------------------------------------------ -- Templates Parser -- -- -- -- Copyright (C) 2004-2014, AdaCore -- -- -- -- This library is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by the -- -- Free Software Foundation; either version 3, or (at your option) any -- -- later version. This library is distributed in the hope that it will be -- -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- -- -- -- -- -- -- -- -- 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/>. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ------------------------------------------------------------------------------ pragma Ada_2012; with Ada.Environment_Variables; package Templates_Parser.Utils is use Ada; function Image (N : Integer) return String with Inline => True, Post => Image'Result'Length > 0; -- Returns N image without leading blank function Image (T : Tag) return String; -- Returns a string representation for this tag function Value (T : String) return Tag; -- Give a string representation of a tag (as encoded with Image above), -- build the corresponding Tag object. Raises Constraint_Error if T is -- not a valid tag representation. function Get_Program_Directory return String; -- Returns the directory full path name for the current running program Is_Windows : constant Boolean := Environment_Variables.Exists ("OS") and then Environment_Variables.Value ("OS") = "Windows_NT"; Directory_Separator : constant Character; Path_Separator : constant Character; function Executable_Extension return String; -- Return the executable exetension for the running host function Web_Escape (S : String) return String with Post => Web_Escape'Result'Length >= S'Length; -- Encode all characters that cannot be used as-is into an HTML page function Is_Number (S : String) return Boolean; -- Returns true if S is composed of digits only -- Byte Order Mark BOM_Utf8 : constant String := Character'Val (16#EF#) & Character'Val (16#BB#) & Character'Val (16#BF#); private subtype Windows_Host is Boolean; type C_Array is array (Windows_Host) of Character; DS : C_Array := C_Array'(True => '\', False => '/'); PS : C_Array := C_Array'(True => ';', False => ':'); Directory_Separator : constant Character := DS (Is_Windows); Path_Separator : constant Character := PS (Is_Windows); end Templates_Parser.Utils;
ytomino/yaml-ada
Ada
35,976
adb
with Ada.Unchecked_Conversion; with Ada.Unchecked_Deallocation; with System; with C.stdlib; with C.string; package body YAML is use type C.signed_int; use type C.ptrdiff_t; use type C.size_t; use type C.yaml.yaml_char_t_ptr; use type C.yaml.yaml_emitter_state_t; use type C.yaml.yaml_event_type_t; use type C.yaml.yaml_parser_state_t; use type C.yaml.yaml_tag_directive_t_ptr; use type C.yaml.yaml_version_directive_t_ptr; function strdup (S : access constant String) return C.yaml.yaml_char_t_ptr is begin if S = null then return null; else declare function Cast is new Ada.Unchecked_Conversion (C.void_ptr, C.yaml.yaml_char_t_ptr); function Cast is new Ada.Unchecked_Conversion (C.yaml.yaml_char_t_ptr, C.ptrdiff_t); function Cast is new Ada.Unchecked_Conversion (C.ptrdiff_t, C.yaml.yaml_char_t_ptr); Length : constant C.size_t := S'Length; p : constant C.void_ptr := C.stdlib.malloc (Length + 1); begin declare Dest : String (S'Range); for Dest'Address use System.Address (p); begin Dest := S.all; end; Cast (Cast (Cast (p)) + C.ptrdiff_t (Length)).all := C.yaml.yaml_char_t'Val (0); return Cast (p); end; end if; end strdup; type String_Access is access String; procedure Free is new Ada.Unchecked_Deallocation (String, String_Access); function To_char_const_ptr is new Ada.Unchecked_Conversion (C.yaml.yaml_char_t_ptr, C.char_const_ptr); function To_Address is new Ada.Unchecked_Conversion (C.char_const_ptr, System.Address); function Length (S : access constant C.char) return Natural is begin if S = null then return 0; else return Natural (C.string.strlen (S)); end if; end Length; function To_String (S : access constant C.char) return String is Result : String (1 .. Length (S)); for Result'Address use To_Address (C.char_const_ptr (S)); begin return Result; end To_String; function New_String (S : C.yaml.yaml_char_t_ptr) return String_Access is begin if S = null then return null; else declare Length : constant Natural := Natural (C.string.strlen (To_char_const_ptr (S))); begin return Result : constant String_Access := new String (1 .. Length) do declare Source : String (1 .. Length); for Source'Address use S.all'Address; begin Result.all := Source; end; end return; end; end if; end New_String; -- dirty trick function Copy_String_Access ( S : not null String_Access; Constraint : not null access String_Constraint) return String_Access is type Fat_Type is record Data : System.Address; Constraints : System.Address; end record; Fat : Fat_Type; Result : aliased String_Access; for Fat'Address use Result'Address; begin Fat.Data := S.all'Address; Fat.Constraints := Constraint.all'Address; Constraint.First := S'First; Constraint.Last := S'Last; return Result; end Copy_String_Access; type String_Constant_Access is access constant String; function Remove_Constant is new Ada.Unchecked_Conversion (String_Constant_Access, String_Access); -- implementation function Version return String is P : constant C.char_const_ptr := C.yaml.yaml_get_version_string; begin return To_String (P); end Version; -- parser type Version_Directive_Access is access all Version_Directive; type Tag_Directive_Array_Access is access Tag_Directive_Array; procedure Free is new Ada.Unchecked_Deallocation ( Tag_Directive_Array, Tag_Directive_Array_Access); type Tag_Directive_Array_Constant_Access is access constant Tag_Directive_Array; function Remove_Constant is new Ada.Unchecked_Conversion ( Tag_Directive_Array_Constant_Access, Tag_Directive_Array_Access); function Read_Handler ( data : C.void_ptr; buffer : access C.unsigned_char; size : C.size_t; size_read : access C.size_t) return C.signed_int with Convention => C; function Read_Handler ( data : C.void_ptr; buffer : access C.unsigned_char; size : C.size_t; size_read : access C.size_t) return C.signed_int is type I is access procedure (Item : out String; Last : out Natural); function To_Input is new Ada.Unchecked_Conversion (C.void_ptr, I); Ada_Data : String (1 .. Natural (size)); for Ada_Data'Address use buffer.all'Address; Last : Natural; begin To_Input (data) (Ada_Data, Last); size_read.all := C.size_t (Last); return 1; end Read_Handler; procedure Delete_Event (Parsed_Data : in out Parsed_Data_Type) is begin C.yaml.yaml_event_delete (Parsed_Data.U.yaml_event'Access); end Delete_Event; procedure Delete_Document_Start_Event ( Parsed_Data : in out Parsed_Data_Type) is begin declare Tag_Directives : Tag_Directive_Array_Access := Remove_Constant ( Tag_Directive_Array_Constant_Access (Parsed_Data.U.Event.Tag_Directives)); begin if Tag_Directives /= null then for I in Tag_Directives'Range loop declare S : String_Access; begin S := Remove_Constant (String_Constant_Access (Tag_Directives (I).Prefix)); Free (S); S := Remove_Constant (String_Constant_Access (Tag_Directives (I).Handle)); Free (S); end; end loop; Free (Tag_Directives); end if; end; C.yaml.yaml_event_delete (Parsed_Data.U.yaml_event'Access); end Delete_Document_Start_Event; procedure Parse ( Raw_Object : not null access C.yaml.yaml_parser_t; Parsed_Data : out Parsed_Data_Type) is Ev : C.yaml.yaml_event_t renames Parsed_Data.U.yaml_event; begin if C.yaml.yaml_parser_parse (Raw_Object, Ev'Access) = 0 then Raise_Error (Raw_Object.error, Raw_Object.problem, Raw_Object.mark'Access); end if; Parsed_Data.U.Start_Mark.Index := Integer (Ev.start_mark.index); Parsed_Data.U.Start_Mark.Line := Integer (Ev.start_mark.line); Parsed_Data.U.Start_Mark.Column := Integer (Ev.start_mark.column); Parsed_Data.U.End_Mark.Index := Integer (Ev.end_mark.index); Parsed_Data.U.End_Mark.Line := Integer (Ev.end_mark.line); Parsed_Data.U.End_Mark.Column := Integer (Ev.end_mark.column); case Ev.F_type is when C.yaml.YAML_NO_EVENT => Parsed_Data.U.Event := Event'(Event_Type => No_Event); Parsed_Data.Delete := Delete_Event'Access; when C.yaml.YAML_STREAM_START_EVENT => Parsed_Data.U.Event := Event'( Event_Type => Stream_Start, Encoding => Encoding'Enum_Val ( C.yaml.yaml_encoding_t'Enum_Rep (Ev.data.stream_start.encoding))); Parsed_Data.Delete := Delete_Event'Access; when C.yaml.YAML_STREAM_END_EVENT => Parsed_Data.U.Event := Event'(Event_Type => Stream_End); Parsed_Data.Delete := Delete_Event'Access; when C.yaml.YAML_DOCUMENT_START_EVENT => declare Version_Directive : Version_Directive_Access; begin if Ev.data.document_start.version_directive = null then Version_Directive := null; else Version_Directive := Parsed_Data.U.Version_Directive'Unchecked_Access; Version_Directive.Major := Integer (Ev.data.document_start.version_directive.major); Version_Directive.Minor := Integer (Ev.data.document_start.version_directive.minor); end if; Parsed_Data.U.Event := Event'( Event_Type => Document_Start, Version_Directive => Version_Directive, Tag_Directives => null, Implicit_Indicator => Ev.data.document_start.implicit /= 0); end; Parsed_Data.Delete := Delete_Document_Start_Event'Access; -- allocating Tag_Directives if Ev.data.document_start.tag_directives.start /= null then declare function Cast is new Ada.Unchecked_Conversion (C.yaml.yaml_tag_directive_t_ptr, C.ptrdiff_t); function Cast is new Ada.Unchecked_Conversion (C.ptrdiff_t, C.yaml.yaml_tag_directive_t_ptr); sizeof_yaml_tag_directive_t : constant C.ptrdiff_t := C.yaml.yaml_tag_directive_t'Size / Standard'Storage_Unit; Length : constant Natural := Natural ( (Cast (Ev.data.document_start.tag_directives.F_end) - Cast (Ev.data.document_start.tag_directives.start)) / sizeof_yaml_tag_directive_t); Tag_Directives : Tag_Directive_Array_Access; P : C.yaml.yaml_tag_directive_t_ptr; begin Tag_Directives := new Tag_Directive_Array (1 .. Length); Parsed_Data.U.Event.Tag_Directives := Tag_Directives; -- hold into RAII P := Ev.data.document_start.tag_directives.start; for I in 1 .. Length loop Tag_Directives (I).Handle := New_String (P.handle); Tag_Directives (I).Prefix := New_String (P.prefix); P := Cast (Cast (P) + sizeof_yaml_tag_directive_t); end loop; end; end if; when C.yaml.YAML_DOCUMENT_END_EVENT => Parsed_Data.U.Event := Event'( Event_Type => Document_End, Implicit_Indicator => Ev.data.document_end.implicit /= 0); Parsed_Data.Delete := Delete_Event'Access; when C.yaml.YAML_ALIAS_EVENT => declare -- anchor Anchor_S : aliased String (1 .. Length (To_char_const_ptr (Ev.data.alias.anchor))); for Anchor_S'Address use To_Address (To_char_const_ptr (Ev.data.alias.anchor)); Anchor_A : constant String_Access := Copy_String_Access ( Anchor_S'Unrestricted_Access, Parsed_Data.U.Anchor_Constraint'Access); begin Parsed_Data.U.Event := Event'(Event_Type => Alias, Anchor => Anchor_A); end; Parsed_Data.Delete := Delete_Event'Access; when C.yaml.YAML_SCALAR_EVENT => declare -- anchor Anchor_S : aliased String (1 .. Length (To_char_const_ptr (Ev.data.scalar.anchor))); for Anchor_S'Address use To_Address (To_char_const_ptr (Ev.data.scalar.anchor)); Anchor_A : constant String_Access := Copy_String_Access ( Anchor_S'Unrestricted_Access, Parsed_Data.U.Anchor_Constraint'Access); -- tag Tag_S : aliased String (1 .. Length (To_char_const_ptr (Ev.data.scalar.tag))); for Tag_S'Address use To_Address (To_char_const_ptr (Ev.data.scalar.tag)); Tag_A : constant String_Access := Copy_String_Access ( Tag_S'Unrestricted_Access, Parsed_Data.U.Tag_Constraint'Access); -- value Value_S : aliased String (1 .. Natural (Ev.data.scalar.length)); for Value_S'Address use To_Address (To_char_const_ptr (Ev.data.scalar.value)); Value_A : constant String_Access := Copy_String_Access ( Value_S'Unrestricted_Access, Parsed_Data.U.Value_Constraint'Access); begin Parsed_Data.U.Event := Event'( Event_Type => Scalar, Anchor => Anchor_A, Tag => Tag_A, Value => Value_A, Plain_Implicit_Tag => Ev.data.scalar.plain_implicit /= 0, Quoted_Implicit_Tag => Ev.data.scalar.quoted_implicit /= 0, Scalar_Style => Scalar_Style'Enum_Val ( C.yaml.yaml_scalar_style_t'Enum_Rep (Ev.data.scalar.style))); end; Parsed_Data.Delete := Delete_Event'Access; when C.yaml.YAML_SEQUENCE_START_EVENT => declare -- anchor Anchor_S : aliased String (1 .. Length (To_char_const_ptr (Ev.data.sequence_start.anchor))); for Anchor_S'Address use To_Address (To_char_const_ptr (Ev.data.sequence_start.anchor)); Anchor_A : constant String_Access := Copy_String_Access ( Anchor_S'Unrestricted_Access, Parsed_Data.U.Anchor_Constraint'Access); -- tag Tag_S : aliased String (1 .. Length (To_char_const_ptr (Ev.data.sequence_start.tag))); for Tag_S'Address use To_Address (To_char_const_ptr (Ev.data.sequence_start.tag)); Tag_A : constant String_Access := Copy_String_Access ( Tag_S'Unrestricted_Access, Parsed_Data.U.Tag_Constraint'Access); begin Parsed_Data.U.Event := Event'( Event_Type => Sequence_Start, Anchor => Anchor_A, Tag => Tag_A, Implicit_Tag => Ev.data.sequence_start.implicit /= 0, Sequence_Style => Sequence_Style'Enum_Val ( C.yaml.yaml_sequence_style_t'Enum_Rep (Ev.data.sequence_start.style))); end; Parsed_Data.Delete := Delete_Event'Access; when C.yaml.YAML_SEQUENCE_END_EVENT => Parsed_Data.U.Event := Event'(Event_Type => Sequence_End); Parsed_Data.Delete := Delete_Event'Access; when C.yaml.YAML_MAPPING_START_EVENT => declare -- anchor Anchor_S : aliased String (1 .. Length (To_char_const_ptr (Ev.data.mapping_start.anchor))); for Anchor_S'Address use To_Address (To_char_const_ptr (Ev.data.mapping_start.anchor)); Anchor_A : constant String_Access := Copy_String_Access ( Anchor_S'Unrestricted_Access, Parsed_Data.U.Anchor_Constraint'Access); -- tag Tag_S : aliased String (1 .. Length (To_char_const_ptr (Ev.data.mapping_start.tag))); for Tag_S'Address use To_Address (To_char_const_ptr (Ev.data.mapping_start.tag)); Tag_A : constant String_Access := Copy_String_Access ( Tag_S'Unrestricted_Access, Parsed_Data.U.Tag_Constraint'Access); begin Parsed_Data.U.Event := Event'( Event_Type => Mapping_Start, Anchor => Anchor_A, Tag => Tag_A, Implicit_Tag => Ev.data.mapping_start.implicit /= 0, Mapping_Style => Mapping_Style'Enum_Val ( C.yaml.yaml_mapping_style_t'Enum_Rep (Ev.data.mapping_start.style))); end; Parsed_Data.Delete := Delete_Event'Access; when C.yaml.YAML_MAPPING_END_EVENT => Parsed_Data.U.Event := Event'(Event_Type => Mapping_End); Parsed_Data.Delete := Delete_Event'Access; end case; end Parse; procedure Parse_Expection ( Raw_Object : not null access C.yaml.yaml_parser_t; Expected : C.yaml.yaml_event_type_t) is Ev : aliased C.yaml.yaml_event_t; pragma Suppress_Initialization (Ev); T : C.yaml.yaml_event_type_t; begin if C.yaml.yaml_parser_parse (Raw_Object, Ev'Access) = 0 then Raise_Error (Raw_Object.error, Raw_Object.problem, Raw_Object.mark'Access); end if; T := Ev.F_type; C.yaml.yaml_event_delete (Ev'Access); if T /= Expected then raise Data_Error; end if; end Parse_Expection; -- parser: wrappers procedure Parse (Object : in out Parser; Parsed_Data : out Parsed_Data_Type) is procedure Process (Raw_Object : not null access C.yaml.yaml_parser_t) is begin Parse (Raw_Object, Parsed_Data); end Process; procedure Do_Parse is new Controlled_Parsers.Update (Process); begin Do_Parse (Object); end Parse; procedure Parse_Expection ( Object : in out Parser; Expected : C.yaml.yaml_event_type_t) is procedure Process (Raw_Object : not null access C.yaml.yaml_parser_t) is begin Parse_Expection (Raw_Object, Expected); end Process; procedure Do_Parse_Expection is new Controlled_Parsers.Update (Process); begin Do_Parse_Expection (Object); end Parse_Expection; -- implementation of parser function Is_Assigned (Parsing_Entry : Parsing_Entry_Type) return Boolean is function Process (Raw_Data : Parsed_Data_Type) return Boolean is begin return Raw_Data.Delete /= null; end Process; function Do_Is_Assigned is new Controlled_Parsing_Entries.Query (Boolean, Process); begin return Do_Is_Assigned (Parsing_Entry); end Is_Assigned; function Value (Parsing_Entry : aliased Parsing_Entry_Type) return Event_Reference_Type is pragma Check (Pre, Check => Is_Assigned (Parsing_Entry) or else raise Status_Error); begin return (Element => Controlled_Parsing_Entries.Constant_Reference (Parsing_Entry).U.Event'Access); end Value; function Start_Mark (Parsing_Entry : aliased Parsing_Entry_Type) return Mark_Reference_Type is pragma Check (Pre, Check => Is_Assigned (Parsing_Entry) or else raise Status_Error); begin return (Element => Controlled_Parsing_Entries.Constant_Reference (Parsing_Entry).U .Start_Mark'Access); end Start_Mark; function End_Mark (Parsing_Entry : aliased Parsing_Entry_Type) return Mark_Reference_Type is pragma Check (Pre, Check => Is_Assigned (Parsing_Entry) or else raise Status_Error); begin return (Element => Controlled_Parsing_Entries.Constant_Reference (Parsing_Entry).U .End_Mark'Access); end End_Mark; function Create ( Input : not null access procedure (Item : out String; Last : out Natural)) return Parser is type I is access procedure (Item : out String; Last : out Natural); function To_void_ptr is new Ada.Unchecked_Conversion (I, C.void_ptr); begin return Result : Parser do declare procedure Process (Raw_Result : not null access C.yaml.yaml_parser_t) is begin if C.yaml.yaml_parser_initialize (Raw_Result) = 0 then Raise_Error (Raw_Result.error, Raw_Result.problem, null); end if; C.yaml.yaml_parser_set_input ( Raw_Result, Read_Handler'Access, To_void_ptr (Input)); end Process; procedure Do_Create is new Controlled_Parsers.Update (Process); begin Do_Create (Result); end; end return; end Create; procedure Set_Encoding (Object : in out Parser; Encoding : in YAML.Encoding) is procedure Process (Raw_Object : not null access C.yaml.yaml_parser_t) is begin C.yaml.yaml_parser_set_encoding ( Raw_Object, C.yaml.yaml_encoding_t'Enum_Val (YAML.Encoding'Enum_Rep (Encoding))); end Process; procedure Do_Set_Encoding is new Controlled_Parsers.Update (Process); begin Do_Set_Encoding (Object); end Set_Encoding; procedure Get ( Object : in out Parser; Process : not null access procedure ( Event : in YAML.Event; Start_Mark, End_Mark : in Mark)) is Parsing_Entry : aliased Parsing_Entry_Type; begin Get (Object, Parsing_Entry); Process ( Value (Parsing_Entry).Element.all, Start_Mark => Start_Mark (Parsing_Entry).Element.all, End_Mark => End_Mark (Parsing_Entry).Element.all); end Get; procedure Get ( Object : in out Parser; Parsing_Entry : out Parsing_Entry_Type) is procedure Process (Raw_Data : in out Parsed_Data_Type) is begin if Raw_Data.Delete /= null then Raw_Data.Delete (Raw_Data); Raw_Data.Delete := null; end if; Parse (Object, Raw_Data); end Process; procedure Do_Get is new Controlled_Parsing_Entries.Update (Process); begin Do_Get (Parsing_Entry); end Get; procedure Get_Document_Start (Object : in out Parser) is procedure Process (Raw_Object : not null access C.yaml.yaml_parser_t) is begin if Raw_Object.state = C.yaml.YAML_PARSE_STREAM_START_STATE then Parse_Expection (Raw_Object, C.yaml.YAML_STREAM_START_EVENT); end if; Parse_Expection (Raw_Object, C.yaml.YAML_DOCUMENT_START_EVENT); end Process; procedure Do_Get_Document_Start is new Controlled_Parsers.Update (Process); begin Do_Get_Document_Start (Object); end Get_Document_Start; procedure Get_Document_End (Object : in out Parser) is begin Parse_Expection (Object, C.yaml.YAML_DOCUMENT_END_EVENT); end Get_Document_End; procedure Finish (Object : in out Parser) is begin Parse_Expection (Object, C.yaml.YAML_STREAM_END_EVENT); end Finish; function Last_Error_Mark (Object : Parser) return Mark is function Process (Raw_Object : not null access constant C.yaml.yaml_parser_t) return Mark is begin return (Index => Integer (Raw_Object.problem_mark.index), Line => Integer (Raw_Object.problem_mark.line), Column => Integer (Raw_Object.problem_mark.column)); end Process; function Do_Last_Error_Mark is new Controlled_Parsers.Query (Mark, Process); begin return Do_Last_Error_Mark (Object); end Last_Error_Mark; function Last_Error_Message (Object : Parser) return String is function Process (Raw_Object : not null access constant C.yaml.yaml_parser_t) return String is begin return To_String (Raw_Object.problem); end Process; function Do_Last_Error_Message is new Controlled_Parsers.Query (String, Process); begin return Do_Last_Error_Message (Object); end Last_Error_Message; -- private implementation of parser package body Controlled_Parsing_Entries is function Constant_Reference (Object : aliased Parsing_Entry_Type) return not null access constant Parsed_Data_Type; pragma Inline (Constant_Reference); function Constant_Reference (Object : aliased Parsing_Entry_Type) return not null access constant Parsed_Data_Type is begin return Object.Data'Access; end Constant_Reference; -- implementation function Constant_Reference (Object : aliased YAML.Parsing_Entry_Type) return not null access constant Parsed_Data_Type is begin return Constant_Reference (Parsing_Entry_Type (Object)); end Constant_Reference; function Query (Object : YAML.Parsing_Entry_Type) return Result_Type is function Query (Object : Parsing_Entry_Type) return Result_Type; pragma Inline (Query); function Query (Object : Parsing_Entry_Type) return Result_Type is begin return Process (Object.Data); end Query; begin return Query (Parsing_Entry_Type (Object)); end Query; procedure Update (Object : in out YAML.Parsing_Entry_Type) is procedure Update (Object : in out Parsing_Entry_Type); pragma Inline (Update); procedure Update (Object : in out Parsing_Entry_Type) is begin Process (Object.Data); end Update; begin Update (Parsing_Entry_Type (Object)); end Update; overriding procedure Finalize (Object : in out Parsing_Entry_Type) is begin if Object.Data.Delete /= null then Object.Data.Delete (Object.Data); end if; end Finalize; end Controlled_Parsing_Entries; package body Controlled_Parsers is function Query (Object : YAML.Parser) return Result_Type is function Query (Object : Parser) return Result_Type; pragma Inline (Query); function Query (Object : Parser) return Result_Type is begin return Process (Object.Raw.X'Access); end Query; begin return Query (Parser (Object)); end Query; procedure Update (Object : in out YAML.Parser) is procedure Update (Object : in out Parser); pragma Inline (Update); procedure Update (Object : in out Parser) is begin Process (Object.Raw.X'Access); end Update; begin Update (Parser (Object)); end Update; overriding procedure Finalize (Object : in out Parser) is begin C.yaml.yaml_parser_delete (Object.Raw.X'Access); end Finalize; end Controlled_Parsers; -- emitter type yaml_tag_directive_t_array is array (C.size_t range <>) of aliased C.yaml.yaml_tag_directive_t; pragma Suppress_Initialization (yaml_tag_directive_t_array); type yaml_tag_directive_t_array_access is access yaml_tag_directive_t_array; procedure Free is new Ada.Unchecked_Deallocation ( yaml_tag_directive_t_array, yaml_tag_directive_t_array_access); function Write_Handler ( data : C.void_ptr; buffer : access C.unsigned_char; size : C.size_t) return C.signed_int with Convention => C; function Write_Handler ( data : C.void_ptr; buffer : access C.unsigned_char; size : C.size_t) return C.signed_int is type O is access procedure (Item : in String); function To_Output is new Ada.Unchecked_Conversion (C.void_ptr, O); Ada_Data : String (1 .. Natural (size)); for Ada_Data'Address use buffer.all'Address; begin To_Output (data) (Ada_Data); return 1; end Write_Handler; procedure Emit ( Raw_Object : not null access C.yaml.yaml_emitter_t; Event : in YAML.Event) is Ev : aliased C.yaml.yaml_event_t; pragma Suppress_Initialization (Ev); begin case Event.Event_Type is when No_Event => raise Constraint_Error; when Stream_Start => if C.yaml.yaml_stream_start_event_initialize ( Ev'Access, C.yaml.yaml_encoding_t'Enum_Val (YAML.Encoding'Enum_Rep (Event.Encoding))) = 0 then raise Storage_Error; -- maybe ... end if; when Stream_End => if C.yaml.yaml_stream_end_event_initialize (Ev'Access) = 0 then raise Storage_Error; -- maybe ... end if; when Document_Start => declare Version_Directive : C.yaml.yaml_version_directive_t_ptr; VD_Body : aliased C.yaml.yaml_version_directive_t; Tag_Directives_Start : C.yaml.yaml_tag_directive_t_ptr; Tag_Directives_End : C.yaml.yaml_tag_directive_t_ptr; TD_Length : C.size_t; TD_Body : yaml_tag_directive_t_array_access; Error : Boolean; begin if Event.Version_Directive = null then Version_Directive := null; else VD_Body.major := C.signed_int (Event.Version_Directive.Major); VD_Body.major := C.signed_int (Event.Version_Directive.Minor); Version_Directive := VD_Body'Unchecked_Access; end if; if Event.Tag_Directives = null or else Event.Tag_Directives'Length = 0 then Tag_Directives_Start := null; Tag_Directives_End := null; else TD_Length := Event.Tag_Directives'Length; TD_Body := new yaml_tag_directive_t_array (0 .. TD_Length + 1); -- extra +1 for I in 0 .. TD_Length - 1 loop declare Item : Tag_Directive renames Event.Tag_Directives (Event.Tag_Directives'First + Integer (I)); begin TD_Body (I).handle := strdup (Item.Handle); TD_Body (I).prefix := strdup (Item.Prefix); end; end loop; Tag_Directives_Start := TD_Body (0)'Unchecked_Access; Tag_Directives_End := TD_Body (TD_Length)'Unchecked_Access; end if; Error := C.yaml.yaml_document_start_event_initialize ( Ev'Access, Version_Directive, Tag_Directives_Start, Tag_Directives_End, Boolean'Pos (Event.Implicit_Indicator)) = 0; if Tag_Directives_Start /= null then for I in 0 .. TD_Length - 1 loop C.stdlib.free (C.void_ptr (TD_Body (I).handle.all'Address)); C.stdlib.free (C.void_ptr (TD_Body (I).prefix.all'Address)); end loop; Free (TD_Body); end if; if Error then raise Storage_Error; -- maybe ... end if; end; when Document_End => if C.yaml.yaml_document_end_event_initialize ( Ev'Access, Boolean'Pos (Event.Implicit_Indicator)) = 0 then raise Storage_Error; -- maybe ... end if; when Alias => declare Anchor : C.yaml.yaml_char_t_ptr; Error : Boolean; begin Anchor := strdup (Event.Anchor); Error := C.yaml.yaml_alias_event_initialize (Ev'Access, Anchor) = 0; if Anchor /= null then C.stdlib.free (C.void_ptr (Anchor.all'Address)); end if; if Error then raise Storage_Error; -- maybe ... end if; end; when Scalar => declare Anchor : C.yaml.yaml_char_t_ptr; Tag : C.yaml.yaml_char_t_ptr; Ada_Value : String renames Event.Value.all; Length : constant C.signed_int := Ada_Value'Length; C_Value : array (0 .. C.size_t (C.signed_int'Max (Length - 1, 0))) of aliased C.yaml.yaml_char_t; for C_Value'Address use Ada_Value'Address; Error : Boolean; begin Anchor := strdup (Event.Anchor); Tag := strdup (Event.Tag); Error := C.yaml.yaml_scalar_event_initialize ( Ev'Access, Anchor, Tag, C_Value (C_Value'First)'Access, Length, Boolean'Pos (Event.Plain_Implicit_Tag), Boolean'Pos (Event.Quoted_Implicit_Tag), C.yaml.yaml_scalar_style_t'Enum_Val ( Scalar_Style'Enum_Rep (Event.Scalar_Style))) = 0; if Anchor /= null then C.stdlib.free (C.void_ptr (Anchor.all'Address)); end if; if Tag /= null then C.stdlib.free (C.void_ptr (Tag.all'Address)); end if; if Error then raise Storage_Error; -- maybe ... end if; end; when Sequence_Start => declare Anchor : C.yaml.yaml_char_t_ptr; Tag : C.yaml.yaml_char_t_ptr; Error : Boolean; begin Anchor := strdup (Event.Anchor); Tag := strdup (Event.Tag); Error := C.yaml.yaml_sequence_start_event_initialize ( Ev'Access, Anchor, Tag, Boolean'Pos (Event.Implicit_Tag), C.yaml.yaml_sequence_style_t'Enum_Val ( Sequence_Style'Enum_Rep (Event.Sequence_Style))) = 0; if Anchor /= null then C.stdlib.free (C.void_ptr (Anchor.all'Address)); end if; if Tag /= null then C.stdlib.free (C.void_ptr (Tag.all'Address)); end if; if Error then raise Storage_Error; -- maybe ... end if; end; when Sequence_End => if C.yaml.yaml_sequence_end_event_initialize (Ev'Access) = 0 then raise Storage_Error; -- maybe ... end if; when Mapping_Start => declare Anchor : C.yaml.yaml_char_t_ptr; Tag : C.yaml.yaml_char_t_ptr; Error : Boolean; begin Anchor := strdup (Event.Anchor); Tag := strdup (Event.Tag); Error := C.yaml.yaml_mapping_start_event_initialize ( Ev'Access, Anchor, Tag, Boolean'Pos (Event.Implicit_Tag), C.yaml.yaml_mapping_style_t'Enum_Val ( Mapping_Style'Enum_Rep (Event.Mapping_Style))) = 0; if Anchor /= null then C.stdlib.free (C.void_ptr (Anchor.all'Address)); end if; if Tag /= null then C.stdlib.free (C.void_ptr (Tag.all'Address)); end if; if Error then raise Storage_Error; -- maybe ... end if; end; when Mapping_End => if C.yaml.yaml_mapping_end_event_initialize (Ev'Access) = 0 then raise Storage_Error; -- maybe ... end if; end case; if C.yaml.yaml_emitter_emit (Raw_Object, Ev'Access) = 0 then Raise_Error (Raw_Object.error, Raw_Object.problem, null); end if; end Emit; -- implementation of emitter function Create (Output : not null access procedure (Item : in String)) return Emitter is type O is access procedure (Item : in String); function To_void_ptr is new Ada.Unchecked_Conversion (O, C.void_ptr); begin return Result : Emitter do declare procedure Process (Raw_Result : not null access C.yaml.yaml_emitter_t) is begin if C.yaml.yaml_emitter_initialize (Raw_Result) = 0 then Raise_Error (Raw_Result.error, Raw_Result.problem, null); end if; C.yaml.yaml_emitter_set_output ( Raw_Result, Write_Handler'Access, To_void_ptr (Output)); end Process; procedure Do_Create is new Controlled_Emitters.Update (Process); begin Do_Create (Result); end; end return; end Create; procedure Flush (Object : in out Emitter) is procedure Process (Raw_Object : not null access C.yaml.yaml_emitter_t) is begin if C.yaml.yaml_emitter_flush (Raw_Object) = 0 then Raise_Error (Raw_Object.error, Raw_Object.problem, null); end if; end Process; procedure Do_Flush is new Controlled_Emitters.Update (Process); begin Do_Flush (Object); end Flush; procedure Set_Encoding ( Object : in out Emitter; Encoding : in YAML.Encoding) is procedure Process (Raw_Object : not null access C.yaml.yaml_emitter_t) is begin C.yaml.yaml_emitter_set_encoding ( Raw_Object, C.yaml.yaml_encoding_t'Enum_Val (YAML.Encoding'Enum_Rep (Encoding))); end Process; procedure Do_Set_Encoding is new Controlled_Emitters.Update (Process); begin Do_Set_Encoding (Object); end Set_Encoding; procedure Set_Canonical (Object : in out Emitter; Canonical : in Boolean) is procedure Process (Raw_Object : not null access C.yaml.yaml_emitter_t) is begin C.yaml.yaml_emitter_set_canonical (Raw_Object, Boolean'Pos (Canonical)); end Process; procedure Do_Set_Canonical is new Controlled_Emitters.Update (Process); begin Do_Set_Canonical (Object); end Set_Canonical; procedure Set_Indent (Object : in out Emitter; Indent : in Indent_Width) is procedure Process (Raw_Object : not null access C.yaml.yaml_emitter_t) is begin C.yaml.yaml_emitter_set_indent (Raw_Object, C.signed_int (Indent)); end Process; procedure Do_Set_Indent is new Controlled_Emitters.Update (Process); begin Do_Set_Indent (Object); end Set_Indent; procedure Set_Width (Object : in out Emitter; Width : in Line_Width) is procedure Process (Raw_Object : not null access C.yaml.yaml_emitter_t) is begin C.yaml.yaml_emitter_set_width (Raw_Object, C.signed_int (Width)); end Process; procedure Do_Set_Width is new Controlled_Emitters.Update (Process); begin Do_Set_Width (Object); end Set_Width; procedure Set_Unicode (Object : in out Emitter; Unicode : in Boolean) is procedure Process (Raw_Object : not null access C.yaml.yaml_emitter_t) is begin C.yaml.yaml_emitter_set_unicode (Raw_Object, Boolean'Pos (Unicode)); end Process; procedure Do_Set_Unicode is new Controlled_Emitters.Update (Process); begin Do_Set_Unicode (Object); end Set_Unicode; procedure Set_Break (Object : in out Emitter; Break : in Line_Break) is procedure Process (Raw_Object : not null access C.yaml.yaml_emitter_t) is begin C.yaml.yaml_emitter_set_break ( Raw_Object, C.yaml.yaml_break_t'Enum_Val (Line_Break'Enum_Rep (Break))); end Process; procedure Do_Set_Break is new Controlled_Emitters.Update (Process); begin Do_Set_Break (Object); end Set_Break; procedure Put (Object : in out Emitter; Event : in YAML.Event) is procedure Process (Raw_Object : not null access C.yaml.yaml_emitter_t) is begin Emit (Raw_Object, Event); end Process; procedure Do_Put is new Controlled_Emitters.Update (Process); begin Do_Put (Object); end Put; procedure Put_Document_Start ( Object : in out Emitter; Implicit_Indicator : in Boolean := False; Version_Directive : access constant YAML.Version_Directive := null; Tag_Directives : access constant YAML.Tag_Directive_Array := null) is procedure Process (Raw_Object : not null access C.yaml.yaml_emitter_t) is begin if Raw_Object.state = C.yaml.YAML_EMIT_STREAM_START_STATE then Emit (Raw_Object, (Event_Type => Stream_Start, Encoding => Any)); end if; Emit ( Raw_Object, (Event_Type => Document_Start, Implicit_Indicator => Implicit_Indicator, Version_Directive => Version_Directive, Tag_Directives => Tag_Directives)); end Process; procedure Do_Put_Document_Start is new Controlled_Emitters.Update (Process); begin Do_Put_Document_Start (Object); end Put_Document_Start; procedure Put_Document_End ( Object : in out Emitter; Implicit_Indicator : in Boolean := True) is begin Put ( Object, (Event_Type => Document_End, Implicit_Indicator => Implicit_Indicator)); end Put_Document_End; procedure Finish (Object : in out Emitter) is begin Put (Object, (Event_Type => Stream_End)); Flush (Object); end Finish; -- private implementation of emitter package body Controlled_Emitters is procedure Update (Object : in out YAML.Emitter) is procedure Update (Object : in out Emitter); pragma Inline (Update); procedure Update (Object : in out Emitter) is begin Process (Object.Raw.X'Access); end Update; begin Update (Emitter (Object)); end Update; overriding procedure Finalize (Object : in out Emitter) is begin C.yaml.yaml_emitter_delete (Object.Raw.X'Access); end Finalize; end Controlled_Emitters; -- private implementation of exceptions procedure Raise_Error ( Error : in C.yaml.yaml_error_type_t; Problem : access constant C.char; Mark : access constant C.yaml.yaml_mark_t) is function Image (Mark : access constant C.yaml.yaml_mark_t) return String is begin if Mark = null then return ""; else return "line" & C.size_t'Image (Mark.line) & ": "; end if; end Image; Ada_Problem : String (1 .. Length (Problem)); for Ada_Problem'Address use To_Address (C.char_const_ptr (Problem)); Message : constant String := Image (Mark) & Ada_Problem; begin case Error is when C.yaml.YAML_MEMORY_ERROR => raise Storage_Error with Message; when C.yaml.YAML_SCANNER_ERROR | C.yaml.YAML_PARSER_ERROR => raise Data_Error with Message; when others => raise Use_Error with Message; end case; end Raise_Error; end YAML;
reznikmm/markdown
Ada
2,399
ads
-- SPDX-FileCopyrightText: 2020 Max Reznik <[email protected]> -- -- SPDX-License-Identifier: MIT ---------------------------------------------------------------- with League.Strings; with XML.SAX.Attributes; with XML.SAX.Output_Destinations; with XML.SAX.Writers; package Custom_Writers is type SAX_Output_Destination_Access is access all XML.SAX.Output_Destinations.SAX_Output_Destination'Class; type Writer is limited new XML.SAX.Writers.SAX_Writer with private; procedure Set_Output_Destination (Self : in out Writer'Class; Output : not null SAX_Output_Destination_Access); not overriding procedure Unescaped_Characters (Self : in out Writer; Text : League.Strings.Universal_String); private type Writer is limited new XML.SAX.Writers.SAX_Writer with record Output : SAX_Output_Destination_Access; Tag : League.Strings.Universal_String; CDATA : Boolean := False; end record; overriding function Error_String (Self : Writer) return League.Strings.Universal_String; overriding procedure Characters (Self : in out Writer; Text : League.Strings.Universal_String; Success : in out Boolean); overriding procedure End_Element (Self : in out Writer; Namespace_URI : League.Strings.Universal_String; Local_Name : League.Strings.Universal_String; Qualified_Name : League.Strings.Universal_String; Success : in out Boolean); overriding procedure Start_Element (Self : in out Writer; Namespace_URI : League.Strings.Universal_String; Local_Name : League.Strings.Universal_String; Qualified_Name : League.Strings.Universal_String; Attributes : XML.SAX.Attributes.SAX_Attributes; Success : in out Boolean); overriding procedure Comment (Self : in out Writer; Text : League.Strings.Universal_String; Success : in out Boolean); overriding procedure Processing_Instruction (Self : in out Writer; Target : League.Strings.Universal_String; Data : League.Strings.Universal_String; Success : in out Boolean); overriding procedure Start_CDATA (Self : in out Writer; Success : in out Boolean); overriding procedure End_CDATA (Self : in out Writer; Success : in out Boolean); end Custom_Writers;
ekoeppen/STM32_Generic_Ada_Drivers
Ada
85,396
ads
-- This spec has been automatically generated from STM32F072x.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with System; package STM32_SVD.TIM is pragma Preelaborate; --------------- -- Registers -- --------------- subtype CR1_CEN_Field is STM32_SVD.Bit; subtype CR1_UDIS_Field is STM32_SVD.Bit; subtype CR1_URS_Field is STM32_SVD.Bit; subtype CR1_OPM_Field is STM32_SVD.Bit; subtype CR1_DIR_Field is STM32_SVD.Bit; subtype CR1_CMS_Field is STM32_SVD.UInt2; subtype CR1_ARPE_Field is STM32_SVD.Bit; subtype CR1_CKD_Field is STM32_SVD.UInt2; -- control register 1 type CR1_Register is record -- Counter enable CEN : CR1_CEN_Field := 16#0#; -- Update disable UDIS : CR1_UDIS_Field := 16#0#; -- Update request source URS : CR1_URS_Field := 16#0#; -- One-pulse mode OPM : CR1_OPM_Field := 16#0#; -- Direction DIR : CR1_DIR_Field := 16#0#; -- Center-aligned mode selection CMS : CR1_CMS_Field := 16#0#; -- Auto-reload preload enable ARPE : CR1_ARPE_Field := 16#0#; -- Clock division CKD : CR1_CKD_Field := 16#0#; -- unspecified Reserved_10_31 : STM32_SVD.UInt22 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR1_Register use record CEN at 0 range 0 .. 0; UDIS at 0 range 1 .. 1; URS at 0 range 2 .. 2; OPM at 0 range 3 .. 3; DIR at 0 range 4 .. 4; CMS at 0 range 5 .. 6; ARPE at 0 range 7 .. 7; CKD at 0 range 8 .. 9; Reserved_10_31 at 0 range 10 .. 31; end record; subtype CR2_CCPC_Field is STM32_SVD.Bit; subtype CR2_CCUS_Field is STM32_SVD.Bit; subtype CR2_CCDS_Field is STM32_SVD.Bit; subtype CR2_MMS_Field is STM32_SVD.UInt3; subtype CR2_TI1S_Field is STM32_SVD.Bit; subtype CR2_OIS1_Field is STM32_SVD.Bit; subtype CR2_OIS1N_Field is STM32_SVD.Bit; subtype CR2_OIS2_Field is STM32_SVD.Bit; subtype CR2_OIS2N_Field is STM32_SVD.Bit; subtype CR2_OIS3_Field is STM32_SVD.Bit; subtype CR2_OIS3N_Field is STM32_SVD.Bit; subtype CR2_OIS4_Field is STM32_SVD.Bit; -- control register 2 type CR2_Register is record -- Capture/compare preloaded control CCPC : CR2_CCPC_Field := 16#0#; -- unspecified Reserved_1_1 : STM32_SVD.Bit := 16#0#; -- Capture/compare control update selection CCUS : CR2_CCUS_Field := 16#0#; -- Capture/compare DMA selection CCDS : CR2_CCDS_Field := 16#0#; -- Master mode selection MMS : CR2_MMS_Field := 16#0#; -- TI1 selection TI1S : CR2_TI1S_Field := 16#0#; -- Output Idle state 1 OIS1 : CR2_OIS1_Field := 16#0#; -- Output Idle state 1 OIS1N : CR2_OIS1N_Field := 16#0#; -- Output Idle state 2 OIS2 : CR2_OIS2_Field := 16#0#; -- Output Idle state 2 OIS2N : CR2_OIS2N_Field := 16#0#; -- Output Idle state 3 OIS3 : CR2_OIS3_Field := 16#0#; -- Output Idle state 3 OIS3N : CR2_OIS3N_Field := 16#0#; -- Output Idle state 4 OIS4 : CR2_OIS4_Field := 16#0#; -- unspecified Reserved_15_31 : STM32_SVD.UInt17 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR2_Register use record CCPC at 0 range 0 .. 0; Reserved_1_1 at 0 range 1 .. 1; CCUS at 0 range 2 .. 2; CCDS at 0 range 3 .. 3; MMS at 0 range 4 .. 6; TI1S at 0 range 7 .. 7; OIS1 at 0 range 8 .. 8; OIS1N at 0 range 9 .. 9; OIS2 at 0 range 10 .. 10; OIS2N at 0 range 11 .. 11; OIS3 at 0 range 12 .. 12; OIS3N at 0 range 13 .. 13; OIS4 at 0 range 14 .. 14; Reserved_15_31 at 0 range 15 .. 31; end record; subtype SMCR_SMS_Field is STM32_SVD.UInt3; subtype SMCR_TS_Field is STM32_SVD.UInt3; subtype SMCR_MSM_Field is STM32_SVD.Bit; subtype SMCR_ETF_Field is STM32_SVD.UInt4; subtype SMCR_ETPS_Field is STM32_SVD.UInt2; subtype SMCR_ECE_Field is STM32_SVD.Bit; subtype SMCR_ETP_Field is STM32_SVD.Bit; -- slave mode control register type SMCR_Register is record -- Slave mode selection SMS : SMCR_SMS_Field := 16#0#; -- unspecified Reserved_3_3 : STM32_SVD.Bit := 16#0#; -- Trigger selection TS : SMCR_TS_Field := 16#0#; -- Master/Slave mode MSM : SMCR_MSM_Field := 16#0#; -- External trigger filter ETF : SMCR_ETF_Field := 16#0#; -- External trigger prescaler ETPS : SMCR_ETPS_Field := 16#0#; -- External clock enable ECE : SMCR_ECE_Field := 16#0#; -- External trigger polarity ETP : SMCR_ETP_Field := 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 SMCR_Register use record SMS at 0 range 0 .. 2; Reserved_3_3 at 0 range 3 .. 3; TS at 0 range 4 .. 6; MSM at 0 range 7 .. 7; ETF at 0 range 8 .. 11; ETPS at 0 range 12 .. 13; ECE at 0 range 14 .. 14; ETP at 0 range 15 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype DIER_UIE_Field is STM32_SVD.Bit; subtype DIER_CC1IE_Field is STM32_SVD.Bit; subtype DIER_CC2IE_Field is STM32_SVD.Bit; subtype DIER_CC3IE_Field is STM32_SVD.Bit; subtype DIER_CC4IE_Field is STM32_SVD.Bit; subtype DIER_COMIE_Field is STM32_SVD.Bit; subtype DIER_TIE_Field is STM32_SVD.Bit; subtype DIER_BIE_Field is STM32_SVD.Bit; subtype DIER_UDE_Field is STM32_SVD.Bit; subtype DIER_CC1DE_Field is STM32_SVD.Bit; subtype DIER_CC2DE_Field is STM32_SVD.Bit; subtype DIER_CC3DE_Field is STM32_SVD.Bit; subtype DIER_CC4DE_Field is STM32_SVD.Bit; subtype DIER_COMDE_Field is STM32_SVD.Bit; subtype DIER_TDE_Field is STM32_SVD.Bit; -- DMA/Interrupt enable register type DIER_Register is record -- Update interrupt enable UIE : DIER_UIE_Field := 16#0#; -- Capture/Compare 1 interrupt enable CC1IE : DIER_CC1IE_Field := 16#0#; -- Capture/Compare 2 interrupt enable CC2IE : DIER_CC2IE_Field := 16#0#; -- Capture/Compare 3 interrupt enable CC3IE : DIER_CC3IE_Field := 16#0#; -- Capture/Compare 4 interrupt enable CC4IE : DIER_CC4IE_Field := 16#0#; -- COM interrupt enable COMIE : DIER_COMIE_Field := 16#0#; -- Trigger interrupt enable TIE : DIER_TIE_Field := 16#0#; -- Break interrupt enable BIE : DIER_BIE_Field := 16#0#; -- Update DMA request enable UDE : DIER_UDE_Field := 16#0#; -- Capture/Compare 1 DMA request enable CC1DE : DIER_CC1DE_Field := 16#0#; -- Capture/Compare 2 DMA request enable CC2DE : DIER_CC2DE_Field := 16#0#; -- Capture/Compare 3 DMA request enable CC3DE : DIER_CC3DE_Field := 16#0#; -- Capture/Compare 4 DMA request enable CC4DE : DIER_CC4DE_Field := 16#0#; -- Reserved COMDE : DIER_COMDE_Field := 16#0#; -- Trigger DMA request enable TDE : DIER_TDE_Field := 16#0#; -- unspecified Reserved_15_31 : STM32_SVD.UInt17 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DIER_Register use record UIE at 0 range 0 .. 0; CC1IE at 0 range 1 .. 1; CC2IE at 0 range 2 .. 2; CC3IE at 0 range 3 .. 3; CC4IE at 0 range 4 .. 4; COMIE at 0 range 5 .. 5; TIE at 0 range 6 .. 6; BIE at 0 range 7 .. 7; UDE at 0 range 8 .. 8; CC1DE at 0 range 9 .. 9; CC2DE at 0 range 10 .. 10; CC3DE at 0 range 11 .. 11; CC4DE at 0 range 12 .. 12; COMDE at 0 range 13 .. 13; TDE at 0 range 14 .. 14; Reserved_15_31 at 0 range 15 .. 31; end record; subtype SR_UIF_Field is STM32_SVD.Bit; subtype SR_CC1IF_Field is STM32_SVD.Bit; subtype SR_CC2IF_Field is STM32_SVD.Bit; subtype SR_CC3IF_Field is STM32_SVD.Bit; subtype SR_CC4IF_Field is STM32_SVD.Bit; subtype SR_COMIF_Field is STM32_SVD.Bit; subtype SR_TIF_Field is STM32_SVD.Bit; subtype SR_BIF_Field is STM32_SVD.Bit; subtype SR_CC1OF_Field is STM32_SVD.Bit; subtype SR_CC2OF_Field is STM32_SVD.Bit; subtype SR_CC3OF_Field is STM32_SVD.Bit; subtype SR_CC4OF_Field is STM32_SVD.Bit; -- status register type SR_Register is record -- Update interrupt flag UIF : SR_UIF_Field := 16#0#; -- Capture/compare 1 interrupt flag CC1IF : SR_CC1IF_Field := 16#0#; -- Capture/Compare 2 interrupt flag CC2IF : SR_CC2IF_Field := 16#0#; -- Capture/Compare 3 interrupt flag CC3IF : SR_CC3IF_Field := 16#0#; -- Capture/Compare 4 interrupt flag CC4IF : SR_CC4IF_Field := 16#0#; -- COM interrupt flag COMIF : SR_COMIF_Field := 16#0#; -- Trigger interrupt flag TIF : SR_TIF_Field := 16#0#; -- Break interrupt flag BIF : SR_BIF_Field := 16#0#; -- unspecified Reserved_8_8 : STM32_SVD.Bit := 16#0#; -- Capture/Compare 1 overcapture flag CC1OF : SR_CC1OF_Field := 16#0#; -- Capture/compare 2 overcapture flag CC2OF : SR_CC2OF_Field := 16#0#; -- Capture/Compare 3 overcapture flag CC3OF : SR_CC3OF_Field := 16#0#; -- Capture/Compare 4 overcapture flag CC4OF : SR_CC4OF_Field := 16#0#; -- unspecified Reserved_13_31 : STM32_SVD.UInt19 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SR_Register use record UIF at 0 range 0 .. 0; CC1IF at 0 range 1 .. 1; CC2IF at 0 range 2 .. 2; CC3IF at 0 range 3 .. 3; CC4IF at 0 range 4 .. 4; COMIF at 0 range 5 .. 5; TIF at 0 range 6 .. 6; BIF at 0 range 7 .. 7; Reserved_8_8 at 0 range 8 .. 8; CC1OF at 0 range 9 .. 9; CC2OF at 0 range 10 .. 10; CC3OF at 0 range 11 .. 11; CC4OF at 0 range 12 .. 12; Reserved_13_31 at 0 range 13 .. 31; end record; subtype EGR_UG_Field is STM32_SVD.Bit; subtype EGR_CC1G_Field is STM32_SVD.Bit; subtype EGR_CC2G_Field is STM32_SVD.Bit; subtype EGR_CC3G_Field is STM32_SVD.Bit; subtype EGR_CC4G_Field is STM32_SVD.Bit; subtype EGR_COMG_Field is STM32_SVD.Bit; subtype EGR_TG_Field is STM32_SVD.Bit; subtype EGR_BG_Field is STM32_SVD.Bit; -- event generation register type EGR_Register is record -- Write-only. Update generation UG : EGR_UG_Field := 16#0#; -- Write-only. Capture/compare 1 generation CC1G : EGR_CC1G_Field := 16#0#; -- Write-only. Capture/compare 2 generation CC2G : EGR_CC2G_Field := 16#0#; -- Write-only. Capture/compare 3 generation CC3G : EGR_CC3G_Field := 16#0#; -- Write-only. Capture/compare 4 generation CC4G : EGR_CC4G_Field := 16#0#; -- Write-only. Capture/Compare control update generation COMG : EGR_COMG_Field := 16#0#; -- Write-only. Trigger generation TG : EGR_TG_Field := 16#0#; -- Write-only. Break generation BG : EGR_BG_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 EGR_Register use record UG at 0 range 0 .. 0; CC1G at 0 range 1 .. 1; CC2G at 0 range 2 .. 2; CC3G at 0 range 3 .. 3; CC4G at 0 range 4 .. 4; COMG at 0 range 5 .. 5; TG at 0 range 6 .. 6; BG at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype CCMR1_Output_CC1S_Field is STM32_SVD.UInt2; subtype CCMR1_Output_OC1FE_Field is STM32_SVD.Bit; subtype CCMR1_Output_OC1PE_Field is STM32_SVD.Bit; subtype CCMR1_Output_OC1M_Field is STM32_SVD.UInt3; subtype CCMR1_Output_OC1CE_Field is STM32_SVD.Bit; subtype CCMR1_Output_CC2S_Field is STM32_SVD.UInt2; subtype CCMR1_Output_OC2FE_Field is STM32_SVD.Bit; subtype CCMR1_Output_OC2PE_Field is STM32_SVD.Bit; subtype CCMR1_Output_OC2M_Field is STM32_SVD.UInt3; subtype CCMR1_Output_OC2CE_Field is STM32_SVD.Bit; -- capture/compare mode register (output mode) type CCMR1_Output_Register is record -- Capture/Compare 1 selection CC1S : CCMR1_Output_CC1S_Field := 16#0#; -- Output Compare 1 fast enable OC1FE : CCMR1_Output_OC1FE_Field := 16#0#; -- Output Compare 1 preload enable OC1PE : CCMR1_Output_OC1PE_Field := 16#0#; -- Output Compare 1 mode OC1M : CCMR1_Output_OC1M_Field := 16#0#; -- Output Compare 1 clear enable OC1CE : CCMR1_Output_OC1CE_Field := 16#0#; -- Capture/Compare 2 selection CC2S : CCMR1_Output_CC2S_Field := 16#0#; -- Output Compare 2 fast enable OC2FE : CCMR1_Output_OC2FE_Field := 16#0#; -- Output Compare 2 preload enable OC2PE : CCMR1_Output_OC2PE_Field := 16#0#; -- Output Compare 2 mode OC2M : CCMR1_Output_OC2M_Field := 16#0#; -- Output Compare 2 clear enable OC2CE : CCMR1_Output_OC2CE_Field := 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 CCMR1_Output_Register use record CC1S at 0 range 0 .. 1; OC1FE at 0 range 2 .. 2; OC1PE at 0 range 3 .. 3; OC1M at 0 range 4 .. 6; OC1CE at 0 range 7 .. 7; CC2S at 0 range 8 .. 9; OC2FE at 0 range 10 .. 10; OC2PE at 0 range 11 .. 11; OC2M at 0 range 12 .. 14; OC2CE at 0 range 15 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype CCMR1_Input_CC1S_Field is STM32_SVD.UInt2; subtype CCMR1_Input_IC1PCS_Field is STM32_SVD.UInt2; subtype CCMR1_Input_IC1F_Field is STM32_SVD.UInt4; subtype CCMR1_Input_CC2S_Field is STM32_SVD.UInt2; subtype CCMR1_Input_IC2PCS_Field is STM32_SVD.UInt2; subtype CCMR1_Input_IC2F_Field is STM32_SVD.UInt4; -- capture/compare mode register 1 (input mode) type CCMR1_Input_Register is record -- Capture/Compare 1 selection CC1S : CCMR1_Input_CC1S_Field := 16#0#; -- Input capture 1 prescaler IC1PCS : CCMR1_Input_IC1PCS_Field := 16#0#; -- Input capture 1 filter IC1F : CCMR1_Input_IC1F_Field := 16#0#; -- Capture/Compare 2 selection CC2S : CCMR1_Input_CC2S_Field := 16#0#; -- Input capture 2 prescaler IC2PCS : CCMR1_Input_IC2PCS_Field := 16#0#; -- Input capture 2 filter IC2F : CCMR1_Input_IC2F_Field := 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 CCMR1_Input_Register use record CC1S at 0 range 0 .. 1; IC1PCS at 0 range 2 .. 3; IC1F at 0 range 4 .. 7; CC2S at 0 range 8 .. 9; IC2PCS at 0 range 10 .. 11; IC2F at 0 range 12 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype CCMR2_Output_CC3S_Field is STM32_SVD.UInt2; subtype CCMR2_Output_OC3FE_Field is STM32_SVD.Bit; subtype CCMR2_Output_OC3PE_Field is STM32_SVD.Bit; subtype CCMR2_Output_OC3M_Field is STM32_SVD.UInt3; subtype CCMR2_Output_OC3CE_Field is STM32_SVD.Bit; subtype CCMR2_Output_CC4S_Field is STM32_SVD.UInt2; subtype CCMR2_Output_OC4FE_Field is STM32_SVD.Bit; subtype CCMR2_Output_OC4PE_Field is STM32_SVD.Bit; subtype CCMR2_Output_OC4M_Field is STM32_SVD.UInt3; subtype CCMR2_Output_OC4CE_Field is STM32_SVD.Bit; -- capture/compare mode register (output mode) type CCMR2_Output_Register is record -- Capture/Compare 3 selection CC3S : CCMR2_Output_CC3S_Field := 16#0#; -- Output compare 3 fast enable OC3FE : CCMR2_Output_OC3FE_Field := 16#0#; -- Output compare 3 preload enable OC3PE : CCMR2_Output_OC3PE_Field := 16#0#; -- Output compare 3 mode OC3M : CCMR2_Output_OC3M_Field := 16#0#; -- Output compare 3 clear enable OC3CE : CCMR2_Output_OC3CE_Field := 16#0#; -- Capture/Compare 4 selection CC4S : CCMR2_Output_CC4S_Field := 16#0#; -- Output compare 4 fast enable OC4FE : CCMR2_Output_OC4FE_Field := 16#0#; -- Output compare 4 preload enable OC4PE : CCMR2_Output_OC4PE_Field := 16#0#; -- Output compare 4 mode OC4M : CCMR2_Output_OC4M_Field := 16#0#; -- Output compare 4 clear enable OC4CE : CCMR2_Output_OC4CE_Field := 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 CCMR2_Output_Register use record CC3S at 0 range 0 .. 1; OC3FE at 0 range 2 .. 2; OC3PE at 0 range 3 .. 3; OC3M at 0 range 4 .. 6; OC3CE at 0 range 7 .. 7; CC4S at 0 range 8 .. 9; OC4FE at 0 range 10 .. 10; OC4PE at 0 range 11 .. 11; OC4M at 0 range 12 .. 14; OC4CE at 0 range 15 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype CCMR2_Input_CC3S_Field is STM32_SVD.UInt2; subtype CCMR2_Input_IC3PSC_Field is STM32_SVD.UInt2; subtype CCMR2_Input_IC3F_Field is STM32_SVD.UInt4; subtype CCMR2_Input_CC4S_Field is STM32_SVD.UInt2; subtype CCMR2_Input_IC4PSC_Field is STM32_SVD.UInt2; subtype CCMR2_Input_IC4F_Field is STM32_SVD.UInt4; -- capture/compare mode register 2 (input mode) type CCMR2_Input_Register is record -- Capture/compare 3 selection CC3S : CCMR2_Input_CC3S_Field := 16#0#; -- Input capture 3 prescaler IC3PSC : CCMR2_Input_IC3PSC_Field := 16#0#; -- Input capture 3 filter IC3F : CCMR2_Input_IC3F_Field := 16#0#; -- Capture/Compare 4 selection CC4S : CCMR2_Input_CC4S_Field := 16#0#; -- Input capture 4 prescaler IC4PSC : CCMR2_Input_IC4PSC_Field := 16#0#; -- Input capture 4 filter IC4F : CCMR2_Input_IC4F_Field := 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 CCMR2_Input_Register use record CC3S at 0 range 0 .. 1; IC3PSC at 0 range 2 .. 3; IC3F at 0 range 4 .. 7; CC4S at 0 range 8 .. 9; IC4PSC at 0 range 10 .. 11; IC4F at 0 range 12 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype CCER_CC1E_Field is STM32_SVD.Bit; subtype CCER_CC1P_Field is STM32_SVD.Bit; subtype CCER_CC1NE_Field is STM32_SVD.Bit; subtype CCER_CC1NP_Field is STM32_SVD.Bit; subtype CCER_CC2E_Field is STM32_SVD.Bit; subtype CCER_CC2P_Field is STM32_SVD.Bit; subtype CCER_CC2NE_Field is STM32_SVD.Bit; subtype CCER_CC2NP_Field is STM32_SVD.Bit; subtype CCER_CC3E_Field is STM32_SVD.Bit; subtype CCER_CC3P_Field is STM32_SVD.Bit; subtype CCER_CC3NE_Field is STM32_SVD.Bit; subtype CCER_CC3NP_Field is STM32_SVD.Bit; subtype CCER_CC4E_Field is STM32_SVD.Bit; subtype CCER_CC4P_Field is STM32_SVD.Bit; -- capture/compare enable register type CCER_Register is record -- Capture/Compare 1 output enable CC1E : CCER_CC1E_Field := 16#0#; -- Capture/Compare 1 output Polarity CC1P : CCER_CC1P_Field := 16#0#; -- Capture/Compare 1 complementary output enable CC1NE : CCER_CC1NE_Field := 16#0#; -- Capture/Compare 1 output Polarity CC1NP : CCER_CC1NP_Field := 16#0#; -- Capture/Compare 2 output enable CC2E : CCER_CC2E_Field := 16#0#; -- Capture/Compare 2 output Polarity CC2P : CCER_CC2P_Field := 16#0#; -- Capture/Compare 2 complementary output enable CC2NE : CCER_CC2NE_Field := 16#0#; -- Capture/Compare 2 output Polarity CC2NP : CCER_CC2NP_Field := 16#0#; -- Capture/Compare 3 output enable CC3E : CCER_CC3E_Field := 16#0#; -- Capture/Compare 3 output Polarity CC3P : CCER_CC3P_Field := 16#0#; -- Capture/Compare 3 complementary output enable CC3NE : CCER_CC3NE_Field := 16#0#; -- Capture/Compare 3 output Polarity CC3NP : CCER_CC3NP_Field := 16#0#; -- Capture/Compare 4 output enable CC4E : CCER_CC4E_Field := 16#0#; -- Capture/Compare 3 output Polarity CC4P : CCER_CC4P_Field := 16#0#; -- unspecified Reserved_14_31 : STM32_SVD.UInt18 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CCER_Register use record CC1E at 0 range 0 .. 0; CC1P at 0 range 1 .. 1; CC1NE at 0 range 2 .. 2; CC1NP at 0 range 3 .. 3; CC2E at 0 range 4 .. 4; CC2P at 0 range 5 .. 5; CC2NE at 0 range 6 .. 6; CC2NP at 0 range 7 .. 7; CC3E at 0 range 8 .. 8; CC3P at 0 range 9 .. 9; CC3NE at 0 range 10 .. 10; CC3NP at 0 range 11 .. 11; CC4E at 0 range 12 .. 12; CC4P at 0 range 13 .. 13; Reserved_14_31 at 0 range 14 .. 31; end record; subtype CNT_CNT_Field is STM32_SVD.UInt16; -- counter type CNT_Register is record -- counter value CNT : CNT_CNT_Field := 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 CNT_Register use record CNT at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype PSC_PSC_Field is STM32_SVD.UInt16; -- prescaler type PSC_Register is record -- Prescaler value PSC : PSC_PSC_Field := 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 PSC_Register use record PSC at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype ARR_ARR_Field is STM32_SVD.UInt16; -- auto-reload register type ARR_Register is record -- Auto-reload value ARR : ARR_ARR_Field := 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 ARR_Register use record ARR at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype RCR_REP_Field is STM32_SVD.Byte; -- repetition counter register type RCR_Register is record -- Repetition counter value REP : RCR_REP_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 RCR_Register use record REP at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype CCR1_CCR1_Field is STM32_SVD.UInt16; -- capture/compare register 1 type CCR1_Register is record -- Capture/Compare 1 value CCR1 : CCR1_CCR1_Field := 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 CCR1_Register use record CCR1 at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype CCR2_CCR2_Field is STM32_SVD.UInt16; -- capture/compare register 2 type CCR2_Register is record -- Capture/Compare 2 value CCR2 : CCR2_CCR2_Field := 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 CCR2_Register use record CCR2 at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype CCR3_CCR3_Field is STM32_SVD.UInt16; -- capture/compare register 3 type CCR3_Register is record -- Capture/Compare 3 value CCR3 : CCR3_CCR3_Field := 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 CCR3_Register use record CCR3 at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype CCR4_CCR4_Field is STM32_SVD.UInt16; -- capture/compare register 4 type CCR4_Register is record -- Capture/Compare 3 value CCR4 : CCR4_CCR4_Field := 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 CCR4_Register use record CCR4 at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype BDTR_DTG_Field is STM32_SVD.Byte; subtype BDTR_LOCK_Field is STM32_SVD.UInt2; subtype BDTR_OSSI_Field is STM32_SVD.Bit; subtype BDTR_OSSR_Field is STM32_SVD.Bit; subtype BDTR_BKE_Field is STM32_SVD.Bit; subtype BDTR_BKP_Field is STM32_SVD.Bit; subtype BDTR_AOE_Field is STM32_SVD.Bit; subtype BDTR_MOE_Field is STM32_SVD.Bit; -- break and dead-time register type BDTR_Register is record -- Dead-time generator setup DTG : BDTR_DTG_Field := 16#0#; -- Lock configuration LOCK : BDTR_LOCK_Field := 16#0#; -- Off-state selection for Idle mode OSSI : BDTR_OSSI_Field := 16#0#; -- Off-state selection for Run mode OSSR : BDTR_OSSR_Field := 16#0#; -- Break enable BKE : BDTR_BKE_Field := 16#0#; -- Break polarity BKP : BDTR_BKP_Field := 16#0#; -- Automatic output enable AOE : BDTR_AOE_Field := 16#0#; -- Main output enable MOE : BDTR_MOE_Field := 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 BDTR_Register use record DTG at 0 range 0 .. 7; LOCK at 0 range 8 .. 9; OSSI at 0 range 10 .. 10; OSSR at 0 range 11 .. 11; BKE at 0 range 12 .. 12; BKP at 0 range 13 .. 13; AOE at 0 range 14 .. 14; MOE at 0 range 15 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype DCR_DBA_Field is STM32_SVD.UInt5; subtype DCR_DBL_Field is STM32_SVD.UInt5; -- DMA control register type DCR_Register is record -- DMA base address DBA : DCR_DBA_Field := 16#0#; -- unspecified Reserved_5_7 : STM32_SVD.UInt3 := 16#0#; -- DMA burst length DBL : DCR_DBL_Field := 16#0#; -- unspecified Reserved_13_31 : STM32_SVD.UInt19 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DCR_Register use record DBA at 0 range 0 .. 4; Reserved_5_7 at 0 range 5 .. 7; DBL at 0 range 8 .. 12; Reserved_13_31 at 0 range 13 .. 31; end record; subtype DMAR_DMAB_Field is STM32_SVD.UInt16; -- DMA address for full transfer type DMAR_Register is record -- DMA register for burst accesses DMAB : DMAR_DMAB_Field := 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 DMAR_Register use record DMAB at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- control register 2 type CR2_Register_1 is record -- unspecified Reserved_0_2 : STM32_SVD.UInt3 := 16#0#; -- Capture/compare DMA selection CCDS : CR2_CCDS_Field := 16#0#; -- Master mode selection MMS : CR2_MMS_Field := 16#0#; -- TI1 selection TI1S : CR2_TI1S_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 CR2_Register_1 use record Reserved_0_2 at 0 range 0 .. 2; CCDS at 0 range 3 .. 3; MMS at 0 range 4 .. 6; TI1S at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- DMA/Interrupt enable register type DIER_Register_1 is record -- Update interrupt enable UIE : DIER_UIE_Field := 16#0#; -- Capture/Compare 1 interrupt enable CC1IE : DIER_CC1IE_Field := 16#0#; -- Capture/Compare 2 interrupt enable CC2IE : DIER_CC2IE_Field := 16#0#; -- Capture/Compare 3 interrupt enable CC3IE : DIER_CC3IE_Field := 16#0#; -- Capture/Compare 4 interrupt enable CC4IE : DIER_CC4IE_Field := 16#0#; -- unspecified Reserved_5_5 : STM32_SVD.Bit := 16#0#; -- Trigger interrupt enable TIE : DIER_TIE_Field := 16#0#; -- unspecified Reserved_7_7 : STM32_SVD.Bit := 16#0#; -- Update DMA request enable UDE : DIER_UDE_Field := 16#0#; -- Capture/Compare 1 DMA request enable CC1DE : DIER_CC1DE_Field := 16#0#; -- Capture/Compare 2 DMA request enable CC2DE : DIER_CC2DE_Field := 16#0#; -- Capture/Compare 3 DMA request enable CC3DE : DIER_CC3DE_Field := 16#0#; -- Capture/Compare 4 DMA request enable CC4DE : DIER_CC4DE_Field := 16#0#; -- Reserved COMDE : DIER_COMDE_Field := 16#0#; -- Trigger DMA request enable TDE : DIER_TDE_Field := 16#0#; -- unspecified Reserved_15_31 : STM32_SVD.UInt17 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DIER_Register_1 use record UIE at 0 range 0 .. 0; CC1IE at 0 range 1 .. 1; CC2IE at 0 range 2 .. 2; CC3IE at 0 range 3 .. 3; CC4IE at 0 range 4 .. 4; Reserved_5_5 at 0 range 5 .. 5; TIE at 0 range 6 .. 6; Reserved_7_7 at 0 range 7 .. 7; UDE at 0 range 8 .. 8; CC1DE at 0 range 9 .. 9; CC2DE at 0 range 10 .. 10; CC3DE at 0 range 11 .. 11; CC4DE at 0 range 12 .. 12; COMDE at 0 range 13 .. 13; TDE at 0 range 14 .. 14; Reserved_15_31 at 0 range 15 .. 31; end record; -- status register type SR_Register_1 is record -- Update interrupt flag UIF : SR_UIF_Field := 16#0#; -- Capture/compare 1 interrupt flag CC1IF : SR_CC1IF_Field := 16#0#; -- Capture/Compare 2 interrupt flag CC2IF : SR_CC2IF_Field := 16#0#; -- Capture/Compare 3 interrupt flag CC3IF : SR_CC3IF_Field := 16#0#; -- Capture/Compare 4 interrupt flag CC4IF : SR_CC4IF_Field := 16#0#; -- unspecified Reserved_5_5 : STM32_SVD.Bit := 16#0#; -- Trigger interrupt flag TIF : SR_TIF_Field := 16#0#; -- unspecified Reserved_7_8 : STM32_SVD.UInt2 := 16#0#; -- Capture/Compare 1 overcapture flag CC1OF : SR_CC1OF_Field := 16#0#; -- Capture/compare 2 overcapture flag CC2OF : SR_CC2OF_Field := 16#0#; -- Capture/Compare 3 overcapture flag CC3OF : SR_CC3OF_Field := 16#0#; -- Capture/Compare 4 overcapture flag CC4OF : SR_CC4OF_Field := 16#0#; -- unspecified Reserved_13_31 : STM32_SVD.UInt19 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SR_Register_1 use record UIF at 0 range 0 .. 0; CC1IF at 0 range 1 .. 1; CC2IF at 0 range 2 .. 2; CC3IF at 0 range 3 .. 3; CC4IF at 0 range 4 .. 4; Reserved_5_5 at 0 range 5 .. 5; TIF at 0 range 6 .. 6; Reserved_7_8 at 0 range 7 .. 8; CC1OF at 0 range 9 .. 9; CC2OF at 0 range 10 .. 10; CC3OF at 0 range 11 .. 11; CC4OF at 0 range 12 .. 12; Reserved_13_31 at 0 range 13 .. 31; end record; -- event generation register type EGR_Register_1 is record -- Write-only. Update generation UG : EGR_UG_Field := 16#0#; -- Write-only. Capture/compare 1 generation CC1G : EGR_CC1G_Field := 16#0#; -- Write-only. Capture/compare 2 generation CC2G : EGR_CC2G_Field := 16#0#; -- Write-only. Capture/compare 3 generation CC3G : EGR_CC3G_Field := 16#0#; -- Write-only. Capture/compare 4 generation CC4G : EGR_CC4G_Field := 16#0#; -- unspecified Reserved_5_5 : STM32_SVD.Bit := 16#0#; -- Write-only. Trigger generation TG : EGR_TG_Field := 16#0#; -- unspecified Reserved_7_31 : STM32_SVD.UInt25 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for EGR_Register_1 use record UG at 0 range 0 .. 0; CC1G at 0 range 1 .. 1; CC2G at 0 range 2 .. 2; CC3G at 0 range 3 .. 3; CC4G at 0 range 4 .. 4; Reserved_5_5 at 0 range 5 .. 5; TG at 0 range 6 .. 6; Reserved_7_31 at 0 range 7 .. 31; end record; subtype CCMR1_Input_IC1PSC_Field is STM32_SVD.UInt2; subtype CCMR1_Input_IC2PSC_Field is STM32_SVD.UInt2; -- capture/compare mode register 1 (input mode) type CCMR1_Input_Register_1 is record -- Capture/Compare 1 selection CC1S : CCMR1_Input_CC1S_Field := 16#0#; -- Input capture 1 prescaler IC1PSC : CCMR1_Input_IC1PSC_Field := 16#0#; -- Input capture 1 filter IC1F : CCMR1_Input_IC1F_Field := 16#0#; -- Capture/compare 2 selection CC2S : CCMR1_Input_CC2S_Field := 16#0#; -- Input capture 2 prescaler IC2PSC : CCMR1_Input_IC2PSC_Field := 16#0#; -- Input capture 2 filter IC2F : CCMR1_Input_IC2F_Field := 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 CCMR1_Input_Register_1 use record CC1S at 0 range 0 .. 1; IC1PSC at 0 range 2 .. 3; IC1F at 0 range 4 .. 7; CC2S at 0 range 8 .. 9; IC2PSC at 0 range 10 .. 11; IC2F at 0 range 12 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype CCER_CC4NP_Field is STM32_SVD.Bit; -- capture/compare enable register type CCER_Register_1 is record -- Capture/Compare 1 output enable CC1E : CCER_CC1E_Field := 16#0#; -- Capture/Compare 1 output Polarity CC1P : CCER_CC1P_Field := 16#0#; -- unspecified Reserved_2_2 : STM32_SVD.Bit := 16#0#; -- Capture/Compare 1 output Polarity CC1NP : CCER_CC1NP_Field := 16#0#; -- Capture/Compare 2 output enable CC2E : CCER_CC2E_Field := 16#0#; -- Capture/Compare 2 output Polarity CC2P : CCER_CC2P_Field := 16#0#; -- unspecified Reserved_6_6 : STM32_SVD.Bit := 16#0#; -- Capture/Compare 2 output Polarity CC2NP : CCER_CC2NP_Field := 16#0#; -- Capture/Compare 3 output enable CC3E : CCER_CC3E_Field := 16#0#; -- Capture/Compare 3 output Polarity CC3P : CCER_CC3P_Field := 16#0#; -- unspecified Reserved_10_10 : STM32_SVD.Bit := 16#0#; -- Capture/Compare 3 output Polarity CC3NP : CCER_CC3NP_Field := 16#0#; -- Capture/Compare 4 output enable CC4E : CCER_CC4E_Field := 16#0#; -- Capture/Compare 3 output Polarity CC4P : CCER_CC4P_Field := 16#0#; -- unspecified Reserved_14_14 : STM32_SVD.Bit := 16#0#; -- Capture/Compare 4 output Polarity CC4NP : CCER_CC4NP_Field := 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 CCER_Register_1 use record CC1E at 0 range 0 .. 0; CC1P at 0 range 1 .. 1; Reserved_2_2 at 0 range 2 .. 2; CC1NP at 0 range 3 .. 3; CC2E at 0 range 4 .. 4; CC2P at 0 range 5 .. 5; Reserved_6_6 at 0 range 6 .. 6; CC2NP at 0 range 7 .. 7; CC3E at 0 range 8 .. 8; CC3P at 0 range 9 .. 9; Reserved_10_10 at 0 range 10 .. 10; CC3NP at 0 range 11 .. 11; CC4E at 0 range 12 .. 12; CC4P at 0 range 13 .. 13; Reserved_14_14 at 0 range 14 .. 14; CC4NP at 0 range 15 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype CNT_CNT_L_Field is STM32_SVD.UInt16; subtype CNT_CNT_H_Field is STM32_SVD.UInt16; -- counter type CNT_Register_1 is record -- Low counter value CNT_L : CNT_CNT_L_Field := 16#0#; -- High counter value (TIM2 only) CNT_H : CNT_CNT_H_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CNT_Register_1 use record CNT_L at 0 range 0 .. 15; CNT_H at 0 range 16 .. 31; end record; subtype ARR_ARR_L_Field is STM32_SVD.UInt16; subtype ARR_ARR_H_Field is STM32_SVD.UInt16; -- auto-reload register type ARR_Register_1 is record -- Low Auto-reload value ARR_L : ARR_ARR_L_Field := 16#0#; -- High Auto-reload value (TIM2 only) ARR_H : ARR_ARR_H_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for ARR_Register_1 use record ARR_L at 0 range 0 .. 15; ARR_H at 0 range 16 .. 31; end record; subtype CCR1_CCR1_L_Field is STM32_SVD.UInt16; subtype CCR1_CCR1_H_Field is STM32_SVD.UInt16; -- capture/compare register 1 type CCR1_Register_1 is record -- Low Capture/Compare 1 value CCR1_L : CCR1_CCR1_L_Field := 16#0#; -- High Capture/Compare 1 value (TIM2 only) CCR1_H : CCR1_CCR1_H_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CCR1_Register_1 use record CCR1_L at 0 range 0 .. 15; CCR1_H at 0 range 16 .. 31; end record; subtype CCR2_CCR2_L_Field is STM32_SVD.UInt16; subtype CCR2_CCR2_H_Field is STM32_SVD.UInt16; -- capture/compare register 2 type CCR2_Register_1 is record -- Low Capture/Compare 2 value CCR2_L : CCR2_CCR2_L_Field := 16#0#; -- High Capture/Compare 2 value (TIM2 only) CCR2_H : CCR2_CCR2_H_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CCR2_Register_1 use record CCR2_L at 0 range 0 .. 15; CCR2_H at 0 range 16 .. 31; end record; subtype CCR3_CCR3_L_Field is STM32_SVD.UInt16; subtype CCR3_CCR3_H_Field is STM32_SVD.UInt16; -- capture/compare register 3 type CCR3_Register_1 is record -- Low Capture/Compare value CCR3_L : CCR3_CCR3_L_Field := 16#0#; -- High Capture/Compare value (TIM2 only) CCR3_H : CCR3_CCR3_H_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CCR3_Register_1 use record CCR3_L at 0 range 0 .. 15; CCR3_H at 0 range 16 .. 31; end record; subtype CCR4_CCR4_L_Field is STM32_SVD.UInt16; subtype CCR4_CCR4_H_Field is STM32_SVD.UInt16; -- capture/compare register 4 type CCR4_Register_1 is record -- Low Capture/Compare value CCR4_L : CCR4_CCR4_L_Field := 16#0#; -- High Capture/Compare value (TIM2 only) CCR4_H : CCR4_CCR4_H_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CCR4_Register_1 use record CCR4_L at 0 range 0 .. 15; CCR4_H at 0 range 16 .. 31; end record; subtype DMAR_DMAR_Field is STM32_SVD.UInt16; -- DMA address for full transfer type DMAR_Register_1 is record -- DMA register for burst accesses DMAR : DMAR_DMAR_Field := 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 DMAR_Register_1 use record DMAR at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- control register 1 type CR1_Register_1 is record -- Counter enable CEN : CR1_CEN_Field := 16#0#; -- Update disable UDIS : CR1_UDIS_Field := 16#0#; -- Update request source URS : CR1_URS_Field := 16#0#; -- One-pulse mode OPM : CR1_OPM_Field := 16#0#; -- unspecified Reserved_4_6 : STM32_SVD.UInt3 := 16#0#; -- Auto-reload preload enable ARPE : CR1_ARPE_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 CR1_Register_1 use record CEN at 0 range 0 .. 0; UDIS at 0 range 1 .. 1; URS at 0 range 2 .. 2; OPM at 0 range 3 .. 3; Reserved_4_6 at 0 range 4 .. 6; ARPE at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- control register 2 type CR2_Register_2 is record -- unspecified Reserved_0_3 : STM32_SVD.UInt4 := 16#0#; -- Master mode selection MMS : CR2_MMS_Field := 16#0#; -- unspecified Reserved_7_31 : STM32_SVD.UInt25 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR2_Register_2 use record Reserved_0_3 at 0 range 0 .. 3; MMS at 0 range 4 .. 6; Reserved_7_31 at 0 range 7 .. 31; end record; -- DMA/Interrupt enable register type DIER_Register_2 is record -- Update interrupt enable UIE : DIER_UIE_Field := 16#0#; -- unspecified Reserved_1_7 : STM32_SVD.UInt7 := 16#0#; -- Update DMA request enable UDE : DIER_UDE_Field := 16#0#; -- unspecified Reserved_9_31 : STM32_SVD.UInt23 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DIER_Register_2 use record UIE at 0 range 0 .. 0; Reserved_1_7 at 0 range 1 .. 7; UDE at 0 range 8 .. 8; Reserved_9_31 at 0 range 9 .. 31; end record; -- status register type SR_Register_2 is record -- Update interrupt flag UIF : SR_UIF_Field := 16#0#; -- unspecified Reserved_1_31 : STM32_SVD.UInt31 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SR_Register_2 use record UIF at 0 range 0 .. 0; Reserved_1_31 at 0 range 1 .. 31; end record; -- event generation register type EGR_Register_2 is record -- Write-only. Update generation UG : EGR_UG_Field := 16#0#; -- unspecified Reserved_1_31 : STM32_SVD.UInt31 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for EGR_Register_2 use record UG at 0 range 0 .. 0; Reserved_1_31 at 0 range 1 .. 31; end record; -- control register 1 type CR1_Register_2 is record -- Counter enable CEN : CR1_CEN_Field := 16#0#; -- Update disable UDIS : CR1_UDIS_Field := 16#0#; -- Update request source URS : CR1_URS_Field := 16#0#; -- unspecified Reserved_3_6 : STM32_SVD.UInt4 := 16#0#; -- Auto-reload preload enable ARPE : CR1_ARPE_Field := 16#0#; -- Clock division CKD : CR1_CKD_Field := 16#0#; -- unspecified Reserved_10_31 : STM32_SVD.UInt22 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR1_Register_2 use record CEN at 0 range 0 .. 0; UDIS at 0 range 1 .. 1; URS at 0 range 2 .. 2; Reserved_3_6 at 0 range 3 .. 6; ARPE at 0 range 7 .. 7; CKD at 0 range 8 .. 9; Reserved_10_31 at 0 range 10 .. 31; end record; -- DMA/Interrupt enable register type DIER_Register_3 is record -- Update interrupt enable UIE : DIER_UIE_Field := 16#0#; -- Capture/Compare 1 interrupt enable CC1IE : DIER_CC1IE_Field := 16#0#; -- unspecified Reserved_2_31 : STM32_SVD.UInt30 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DIER_Register_3 use record UIE at 0 range 0 .. 0; CC1IE at 0 range 1 .. 1; Reserved_2_31 at 0 range 2 .. 31; end record; -- status register type SR_Register_3 is record -- Update interrupt flag UIF : SR_UIF_Field := 16#0#; -- Capture/compare 1 interrupt flag CC1IF : SR_CC1IF_Field := 16#0#; -- unspecified Reserved_2_8 : STM32_SVD.UInt7 := 16#0#; -- Capture/Compare 1 overcapture flag CC1OF : SR_CC1OF_Field := 16#0#; -- unspecified Reserved_10_31 : STM32_SVD.UInt22 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SR_Register_3 use record UIF at 0 range 0 .. 0; CC1IF at 0 range 1 .. 1; Reserved_2_8 at 0 range 2 .. 8; CC1OF at 0 range 9 .. 9; Reserved_10_31 at 0 range 10 .. 31; end record; -- event generation register type EGR_Register_3 is record -- Write-only. Update generation UG : EGR_UG_Field := 16#0#; -- Write-only. Capture/compare 1 generation CC1G : EGR_CC1G_Field := 16#0#; -- unspecified Reserved_2_31 : STM32_SVD.UInt30 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for EGR_Register_3 use record UG at 0 range 0 .. 0; CC1G at 0 range 1 .. 1; Reserved_2_31 at 0 range 2 .. 31; end record; -- capture/compare mode register (output mode) type CCMR1_Output_Register_1 is record -- Capture/Compare 1 selection CC1S : CCMR1_Output_CC1S_Field := 16#0#; -- Output compare 1 fast enable OC1FE : CCMR1_Output_OC1FE_Field := 16#0#; -- Output Compare 1 preload enable OC1PE : CCMR1_Output_OC1PE_Field := 16#0#; -- Output Compare 1 mode OC1M : CCMR1_Output_OC1M_Field := 16#0#; -- unspecified Reserved_7_31 : STM32_SVD.UInt25 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CCMR1_Output_Register_1 use record CC1S at 0 range 0 .. 1; OC1FE at 0 range 2 .. 2; OC1PE at 0 range 3 .. 3; OC1M at 0 range 4 .. 6; Reserved_7_31 at 0 range 7 .. 31; end record; -- capture/compare mode register (input mode) type CCMR1_Input_Register_2 is record -- Capture/Compare 1 selection CC1S : CCMR1_Input_CC1S_Field := 16#0#; -- Input capture 1 prescaler IC1PSC : CCMR1_Input_IC1PSC_Field := 16#0#; -- Input capture 1 filter IC1F : CCMR1_Input_IC1F_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 CCMR1_Input_Register_2 use record CC1S at 0 range 0 .. 1; IC1PSC at 0 range 2 .. 3; IC1F at 0 range 4 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- capture/compare enable register type CCER_Register_2 is record -- Capture/Compare 1 output enable CC1E : CCER_CC1E_Field := 16#0#; -- Capture/Compare 1 output Polarity CC1P : CCER_CC1P_Field := 16#0#; -- unspecified Reserved_2_2 : STM32_SVD.Bit := 16#0#; -- Capture/Compare 1 output Polarity CC1NP : CCER_CC1NP_Field := 16#0#; -- unspecified Reserved_4_31 : STM32_SVD.UInt28 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CCER_Register_2 use record CC1E at 0 range 0 .. 0; CC1P at 0 range 1 .. 1; Reserved_2_2 at 0 range 2 .. 2; CC1NP at 0 range 3 .. 3; Reserved_4_31 at 0 range 4 .. 31; end record; subtype OR_RMP_Field is STM32_SVD.UInt2; -- option register type OR_Register is record -- Timer input 1 remap RMP : OR_RMP_Field := 16#0#; -- unspecified Reserved_2_31 : STM32_SVD.UInt30 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for OR_Register use record RMP at 0 range 0 .. 1; Reserved_2_31 at 0 range 2 .. 31; end record; -- control register 1 type CR1_Register_3 is record -- Counter enable CEN : CR1_CEN_Field := 16#0#; -- Update disable UDIS : CR1_UDIS_Field := 16#0#; -- Update request source URS : CR1_URS_Field := 16#0#; -- One-pulse mode OPM : CR1_OPM_Field := 16#0#; -- unspecified Reserved_4_6 : STM32_SVD.UInt3 := 16#0#; -- Auto-reload preload enable ARPE : CR1_ARPE_Field := 16#0#; -- Clock division CKD : CR1_CKD_Field := 16#0#; -- unspecified Reserved_10_31 : STM32_SVD.UInt22 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR1_Register_3 use record CEN at 0 range 0 .. 0; UDIS at 0 range 1 .. 1; URS at 0 range 2 .. 2; OPM at 0 range 3 .. 3; Reserved_4_6 at 0 range 4 .. 6; ARPE at 0 range 7 .. 7; CKD at 0 range 8 .. 9; Reserved_10_31 at 0 range 10 .. 31; end record; -- control register 2 type CR2_Register_3 is record -- Capture/compare preloaded control CCPC : CR2_CCPC_Field := 16#0#; -- unspecified Reserved_1_1 : STM32_SVD.Bit := 16#0#; -- Capture/compare control update selection CCUS : CR2_CCUS_Field := 16#0#; -- Capture/compare DMA selection CCDS : CR2_CCDS_Field := 16#0#; -- Master mode selection MMS : CR2_MMS_Field := 16#0#; -- unspecified Reserved_7_7 : STM32_SVD.Bit := 16#0#; -- Output Idle state 1 OIS1 : CR2_OIS1_Field := 16#0#; -- Output Idle state 1 OIS1N : CR2_OIS1N_Field := 16#0#; -- Output Idle state 2 OIS2 : CR2_OIS2_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 CR2_Register_3 use record CCPC at 0 range 0 .. 0; Reserved_1_1 at 0 range 1 .. 1; CCUS at 0 range 2 .. 2; CCDS at 0 range 3 .. 3; MMS at 0 range 4 .. 6; Reserved_7_7 at 0 range 7 .. 7; OIS1 at 0 range 8 .. 8; OIS1N at 0 range 9 .. 9; OIS2 at 0 range 10 .. 10; Reserved_11_31 at 0 range 11 .. 31; end record; -- slave mode control register type SMCR_Register_1 is record -- Slave mode selection SMS : SMCR_SMS_Field := 16#0#; -- unspecified Reserved_3_3 : STM32_SVD.Bit := 16#0#; -- Trigger selection TS : SMCR_TS_Field := 16#0#; -- Master/Slave mode MSM : SMCR_MSM_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 SMCR_Register_1 use record SMS at 0 range 0 .. 2; Reserved_3_3 at 0 range 3 .. 3; TS at 0 range 4 .. 6; MSM at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- DMA/Interrupt enable register type DIER_Register_4 is record -- Update interrupt enable UIE : DIER_UIE_Field := 16#0#; -- Capture/Compare 1 interrupt enable CC1IE : DIER_CC1IE_Field := 16#0#; -- Capture/Compare 2 interrupt enable CC2IE : DIER_CC2IE_Field := 16#0#; -- unspecified Reserved_3_4 : STM32_SVD.UInt2 := 16#0#; -- COM interrupt enable COMIE : DIER_COMIE_Field := 16#0#; -- Trigger interrupt enable TIE : DIER_TIE_Field := 16#0#; -- Break interrupt enable BIE : DIER_BIE_Field := 16#0#; -- Update DMA request enable UDE : DIER_UDE_Field := 16#0#; -- Capture/Compare 1 DMA request enable CC1DE : DIER_CC1DE_Field := 16#0#; -- Capture/Compare 2 DMA request enable CC2DE : DIER_CC2DE_Field := 16#0#; -- unspecified Reserved_11_13 : STM32_SVD.UInt3 := 16#0#; -- Trigger DMA request enable TDE : DIER_TDE_Field := 16#0#; -- unspecified Reserved_15_31 : STM32_SVD.UInt17 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DIER_Register_4 use record UIE at 0 range 0 .. 0; CC1IE at 0 range 1 .. 1; CC2IE at 0 range 2 .. 2; Reserved_3_4 at 0 range 3 .. 4; COMIE at 0 range 5 .. 5; TIE at 0 range 6 .. 6; BIE at 0 range 7 .. 7; UDE at 0 range 8 .. 8; CC1DE at 0 range 9 .. 9; CC2DE at 0 range 10 .. 10; Reserved_11_13 at 0 range 11 .. 13; TDE at 0 range 14 .. 14; Reserved_15_31 at 0 range 15 .. 31; end record; -- status register type SR_Register_4 is record -- Update interrupt flag UIF : SR_UIF_Field := 16#0#; -- Capture/compare 1 interrupt flag CC1IF : SR_CC1IF_Field := 16#0#; -- Capture/Compare 2 interrupt flag CC2IF : SR_CC2IF_Field := 16#0#; -- unspecified Reserved_3_4 : STM32_SVD.UInt2 := 16#0#; -- COM interrupt flag COMIF : SR_COMIF_Field := 16#0#; -- Trigger interrupt flag TIF : SR_TIF_Field := 16#0#; -- Break interrupt flag BIF : SR_BIF_Field := 16#0#; -- unspecified Reserved_8_8 : STM32_SVD.Bit := 16#0#; -- Capture/Compare 1 overcapture flag CC1OF : SR_CC1OF_Field := 16#0#; -- Capture/compare 2 overcapture flag CC2OF : SR_CC2OF_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 SR_Register_4 use record UIF at 0 range 0 .. 0; CC1IF at 0 range 1 .. 1; CC2IF at 0 range 2 .. 2; Reserved_3_4 at 0 range 3 .. 4; COMIF at 0 range 5 .. 5; TIF at 0 range 6 .. 6; BIF at 0 range 7 .. 7; Reserved_8_8 at 0 range 8 .. 8; CC1OF at 0 range 9 .. 9; CC2OF at 0 range 10 .. 10; Reserved_11_31 at 0 range 11 .. 31; end record; -- event generation register type EGR_Register_4 is record -- Write-only. Update generation UG : EGR_UG_Field := 16#0#; -- Write-only. Capture/compare 1 generation CC1G : EGR_CC1G_Field := 16#0#; -- Write-only. Capture/compare 2 generation CC2G : EGR_CC2G_Field := 16#0#; -- unspecified Reserved_3_4 : STM32_SVD.UInt2 := 16#0#; -- Write-only. Capture/Compare control update generation COMG : EGR_COMG_Field := 16#0#; -- Write-only. Trigger generation TG : EGR_TG_Field := 16#0#; -- Write-only. Break generation BG : EGR_BG_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 EGR_Register_4 use record UG at 0 range 0 .. 0; CC1G at 0 range 1 .. 1; CC2G at 0 range 2 .. 2; Reserved_3_4 at 0 range 3 .. 4; COMG at 0 range 5 .. 5; TG at 0 range 6 .. 6; BG at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- capture/compare mode register (output mode) type CCMR1_Output_Register_2 is record -- Capture/Compare 1 selection CC1S : CCMR1_Output_CC1S_Field := 16#0#; -- Output Compare 1 fast enable OC1FE : CCMR1_Output_OC1FE_Field := 16#0#; -- Output Compare 1 preload enable OC1PE : CCMR1_Output_OC1PE_Field := 16#0#; -- Output Compare 1 mode OC1M : CCMR1_Output_OC1M_Field := 16#0#; -- unspecified Reserved_7_7 : STM32_SVD.Bit := 16#0#; -- Capture/Compare 2 selection CC2S : CCMR1_Output_CC2S_Field := 16#0#; -- Output Compare 2 fast enable OC2FE : CCMR1_Output_OC2FE_Field := 16#0#; -- Output Compare 2 preload enable OC2PE : CCMR1_Output_OC2PE_Field := 16#0#; -- Output Compare 2 mode OC2M : CCMR1_Output_OC2M_Field := 16#0#; -- unspecified Reserved_15_31 : STM32_SVD.UInt17 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CCMR1_Output_Register_2 use record CC1S at 0 range 0 .. 1; OC1FE at 0 range 2 .. 2; OC1PE at 0 range 3 .. 3; OC1M at 0 range 4 .. 6; Reserved_7_7 at 0 range 7 .. 7; CC2S at 0 range 8 .. 9; OC2FE at 0 range 10 .. 10; OC2PE at 0 range 11 .. 11; OC2M at 0 range 12 .. 14; Reserved_15_31 at 0 range 15 .. 31; end record; -- capture/compare enable register type CCER_Register_3 is record -- Capture/Compare 1 output enable CC1E : CCER_CC1E_Field := 16#0#; -- Capture/Compare 1 output Polarity CC1P : CCER_CC1P_Field := 16#0#; -- Capture/Compare 1 complementary output enable CC1NE : CCER_CC1NE_Field := 16#0#; -- Capture/Compare 1 output Polarity CC1NP : CCER_CC1NP_Field := 16#0#; -- Capture/Compare 2 output enable CC2E : CCER_CC2E_Field := 16#0#; -- Capture/Compare 2 output Polarity CC2P : CCER_CC2P_Field := 16#0#; -- unspecified Reserved_6_6 : STM32_SVD.Bit := 16#0#; -- Capture/Compare 2 output Polarity CC2NP : CCER_CC2NP_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 CCER_Register_3 use record CC1E at 0 range 0 .. 0; CC1P at 0 range 1 .. 1; CC1NE at 0 range 2 .. 2; CC1NP at 0 range 3 .. 3; CC2E at 0 range 4 .. 4; CC2P at 0 range 5 .. 5; Reserved_6_6 at 0 range 6 .. 6; CC2NP at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- control register 2 type CR2_Register_4 is record -- Capture/compare preloaded control CCPC : CR2_CCPC_Field := 16#0#; -- unspecified Reserved_1_1 : STM32_SVD.Bit := 16#0#; -- Capture/compare control update selection CCUS : CR2_CCUS_Field := 16#0#; -- Capture/compare DMA selection CCDS : CR2_CCDS_Field := 16#0#; -- unspecified Reserved_4_7 : STM32_SVD.UInt4 := 16#0#; -- Output Idle state 1 OIS1 : CR2_OIS1_Field := 16#0#; -- Output Idle state 1 OIS1N : CR2_OIS1N_Field := 16#0#; -- unspecified Reserved_10_31 : STM32_SVD.UInt22 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR2_Register_4 use record CCPC at 0 range 0 .. 0; Reserved_1_1 at 0 range 1 .. 1; CCUS at 0 range 2 .. 2; CCDS at 0 range 3 .. 3; Reserved_4_7 at 0 range 4 .. 7; OIS1 at 0 range 8 .. 8; OIS1N at 0 range 9 .. 9; Reserved_10_31 at 0 range 10 .. 31; end record; -- DMA/Interrupt enable register type DIER_Register_5 is record -- Update interrupt enable UIE : DIER_UIE_Field := 16#0#; -- Capture/Compare 1 interrupt enable CC1IE : DIER_CC1IE_Field := 16#0#; -- unspecified Reserved_2_4 : STM32_SVD.UInt3 := 16#0#; -- COM interrupt enable COMIE : DIER_COMIE_Field := 16#0#; -- Trigger interrupt enable TIE : DIER_TIE_Field := 16#0#; -- Break interrupt enable BIE : DIER_BIE_Field := 16#0#; -- Update DMA request enable UDE : DIER_UDE_Field := 16#0#; -- Capture/Compare 1 DMA request enable CC1DE : DIER_CC1DE_Field := 16#0#; -- unspecified Reserved_10_13 : STM32_SVD.UInt4 := 16#0#; -- Trigger DMA request enable TDE : DIER_TDE_Field := 16#0#; -- unspecified Reserved_15_31 : STM32_SVD.UInt17 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DIER_Register_5 use record UIE at 0 range 0 .. 0; CC1IE at 0 range 1 .. 1; Reserved_2_4 at 0 range 2 .. 4; COMIE at 0 range 5 .. 5; TIE at 0 range 6 .. 6; BIE at 0 range 7 .. 7; UDE at 0 range 8 .. 8; CC1DE at 0 range 9 .. 9; Reserved_10_13 at 0 range 10 .. 13; TDE at 0 range 14 .. 14; Reserved_15_31 at 0 range 15 .. 31; end record; -- status register type SR_Register_5 is record -- Update interrupt flag UIF : SR_UIF_Field := 16#0#; -- Capture/compare 1 interrupt flag CC1IF : SR_CC1IF_Field := 16#0#; -- unspecified Reserved_2_4 : STM32_SVD.UInt3 := 16#0#; -- COM interrupt flag COMIF : SR_COMIF_Field := 16#0#; -- Trigger interrupt flag TIF : SR_TIF_Field := 16#0#; -- Break interrupt flag BIF : SR_BIF_Field := 16#0#; -- unspecified Reserved_8_8 : STM32_SVD.Bit := 16#0#; -- Capture/Compare 1 overcapture flag CC1OF : SR_CC1OF_Field := 16#0#; -- unspecified Reserved_10_31 : STM32_SVD.UInt22 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SR_Register_5 use record UIF at 0 range 0 .. 0; CC1IF at 0 range 1 .. 1; Reserved_2_4 at 0 range 2 .. 4; COMIF at 0 range 5 .. 5; TIF at 0 range 6 .. 6; BIF at 0 range 7 .. 7; Reserved_8_8 at 0 range 8 .. 8; CC1OF at 0 range 9 .. 9; Reserved_10_31 at 0 range 10 .. 31; end record; -- event generation register type EGR_Register_5 is record -- Write-only. Update generation UG : EGR_UG_Field := 16#0#; -- Write-only. Capture/compare 1 generation CC1G : EGR_CC1G_Field := 16#0#; -- unspecified Reserved_2_4 : STM32_SVD.UInt3 := 16#0#; -- Write-only. Capture/Compare control update generation COMG : EGR_COMG_Field := 16#0#; -- Write-only. Trigger generation TG : EGR_TG_Field := 16#0#; -- Write-only. Break generation BG : EGR_BG_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 EGR_Register_5 use record UG at 0 range 0 .. 0; CC1G at 0 range 1 .. 1; Reserved_2_4 at 0 range 2 .. 4; COMG at 0 range 5 .. 5; TG at 0 range 6 .. 6; BG at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- capture/compare enable register type CCER_Register_4 is record -- Capture/Compare 1 output enable CC1E : CCER_CC1E_Field := 16#0#; -- Capture/Compare 1 output Polarity CC1P : CCER_CC1P_Field := 16#0#; -- Capture/Compare 1 complementary output enable CC1NE : CCER_CC1NE_Field := 16#0#; -- Capture/Compare 1 output Polarity CC1NP : CCER_CC1NP_Field := 16#0#; -- unspecified Reserved_4_31 : STM32_SVD.UInt28 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CCER_Register_4 use record CC1E at 0 range 0 .. 0; CC1P at 0 range 1 .. 1; CC1NE at 0 range 2 .. 2; CC1NP at 0 range 3 .. 3; Reserved_4_31 at 0 range 4 .. 31; end record; ----------------- -- Peripherals -- ----------------- type TIM1_Disc is ( Output, Input); -- Advanced-timers type TIM1_Peripheral (Discriminent : TIM1_Disc := Output) is record -- control register 1 CR1 : aliased CR1_Register; -- control register 2 CR2 : aliased CR2_Register; -- slave mode control register SMCR : aliased SMCR_Register; -- DMA/Interrupt enable register DIER : aliased DIER_Register; -- status register SR : aliased SR_Register; -- event generation register EGR : aliased EGR_Register; -- capture/compare enable register CCER : aliased CCER_Register; -- counter CNT : aliased CNT_Register; -- prescaler PSC : aliased PSC_Register; -- auto-reload register ARR : aliased ARR_Register; -- repetition counter register RCR : aliased RCR_Register; -- capture/compare register 1 CCR1 : aliased CCR1_Register; -- capture/compare register 2 CCR2 : aliased CCR2_Register; -- capture/compare register 3 CCR3 : aliased CCR3_Register; -- capture/compare register 4 CCR4 : aliased CCR4_Register; -- break and dead-time register BDTR : aliased BDTR_Register; -- DMA control register DCR : aliased DCR_Register; -- DMA address for full transfer DMAR : aliased DMAR_Register; case Discriminent is when Output => -- capture/compare mode register (output mode) CCMR1_Output : aliased CCMR1_Output_Register; -- capture/compare mode register (output mode) CCMR2_Output : aliased CCMR2_Output_Register; when Input => -- capture/compare mode register 1 (input mode) CCMR1_Input : aliased CCMR1_Input_Register; -- capture/compare mode register 2 (input mode) CCMR2_Input : aliased CCMR2_Input_Register; end case; end record with Unchecked_Union, Volatile; for TIM1_Peripheral use record CR1 at 16#0# range 0 .. 31; CR2 at 16#4# range 0 .. 31; SMCR at 16#8# range 0 .. 31; DIER at 16#C# range 0 .. 31; SR at 16#10# range 0 .. 31; EGR at 16#14# range 0 .. 31; CCER at 16#20# range 0 .. 31; CNT at 16#24# range 0 .. 31; PSC at 16#28# range 0 .. 31; ARR at 16#2C# range 0 .. 31; RCR at 16#30# range 0 .. 31; CCR1 at 16#34# range 0 .. 31; CCR2 at 16#38# range 0 .. 31; CCR3 at 16#3C# range 0 .. 31; CCR4 at 16#40# range 0 .. 31; BDTR at 16#44# range 0 .. 31; DCR at 16#48# range 0 .. 31; DMAR at 16#4C# range 0 .. 31; CCMR1_Output at 16#18# range 0 .. 31; CCMR2_Output at 16#1C# range 0 .. 31; CCMR1_Input at 16#18# range 0 .. 31; CCMR2_Input at 16#1C# range 0 .. 31; end record; -- Advanced-timers TIM1_Periph : aliased TIM1_Peripheral with Import, Address => System'To_Address (16#40012C00#); type TIM2_Disc is ( Output, Input); -- General-purpose-timers type TIM2_Peripheral (Discriminent : TIM2_Disc := Output) is record -- control register 1 CR1 : aliased CR1_Register; -- control register 2 CR2 : aliased CR2_Register_1; -- slave mode control register SMCR : aliased SMCR_Register; -- DMA/Interrupt enable register DIER : aliased DIER_Register_1; -- status register SR : aliased SR_Register_1; -- event generation register EGR : aliased EGR_Register_1; -- capture/compare enable register CCER : aliased CCER_Register_1; -- counter CNT : aliased CNT_Register_1; -- prescaler PSC : aliased PSC_Register; -- auto-reload register ARR : aliased ARR_Register_1; -- capture/compare register 1 CCR1 : aliased CCR1_Register_1; -- capture/compare register 2 CCR2 : aliased CCR2_Register_1; -- capture/compare register 3 CCR3 : aliased CCR3_Register_1; -- capture/compare register 4 CCR4 : aliased CCR4_Register_1; -- DMA control register DCR : aliased DCR_Register; -- DMA address for full transfer DMAR : aliased DMAR_Register_1; case Discriminent is when Output => -- capture/compare mode register 1 (output mode) CCMR1_Output : aliased CCMR1_Output_Register; -- capture/compare mode register 2 (output mode) CCMR2_Output : aliased CCMR2_Output_Register; when Input => -- capture/compare mode register 1 (input mode) CCMR1_Input : aliased CCMR1_Input_Register_1; -- capture/compare mode register 2 (input mode) CCMR2_Input : aliased CCMR2_Input_Register; end case; end record with Unchecked_Union, Volatile; for TIM2_Peripheral use record CR1 at 16#0# range 0 .. 31; CR2 at 16#4# range 0 .. 31; SMCR at 16#8# range 0 .. 31; DIER at 16#C# range 0 .. 31; SR at 16#10# range 0 .. 31; EGR at 16#14# range 0 .. 31; CCER at 16#20# range 0 .. 31; CNT at 16#24# range 0 .. 31; PSC at 16#28# range 0 .. 31; ARR at 16#2C# range 0 .. 31; CCR1 at 16#34# range 0 .. 31; CCR2 at 16#38# range 0 .. 31; CCR3 at 16#3C# range 0 .. 31; CCR4 at 16#40# range 0 .. 31; DCR at 16#48# range 0 .. 31; DMAR at 16#4C# range 0 .. 31; CCMR1_Output at 16#18# range 0 .. 31; CCMR2_Output at 16#1C# range 0 .. 31; CCMR1_Input at 16#18# range 0 .. 31; CCMR2_Input at 16#1C# range 0 .. 31; end record; -- General-purpose-timers TIM2_Periph : aliased TIM2_Peripheral with Import, Address => System'To_Address (16#40000000#); -- General-purpose-timers TIM3_Periph : aliased TIM2_Peripheral with Import, Address => System'To_Address (16#40000400#); -- Basic-timers type TIM6_Peripheral is record -- control register 1 CR1 : aliased CR1_Register_1; -- control register 2 CR2 : aliased CR2_Register_2; -- DMA/Interrupt enable register DIER : aliased DIER_Register_2; -- status register SR : aliased SR_Register_2; -- event generation register EGR : aliased EGR_Register_2; -- counter CNT : aliased CNT_Register; -- prescaler PSC : aliased PSC_Register; -- auto-reload register ARR : aliased ARR_Register; end record with Volatile; for TIM6_Peripheral use record CR1 at 16#0# range 0 .. 31; CR2 at 16#4# range 0 .. 31; DIER at 16#C# range 0 .. 31; SR at 16#10# range 0 .. 31; EGR at 16#14# range 0 .. 31; CNT at 16#24# range 0 .. 31; PSC at 16#28# range 0 .. 31; ARR at 16#2C# range 0 .. 31; end record; -- Basic-timers TIM6_Periph : aliased TIM6_Peripheral with Import, Address => System'To_Address (16#40001000#); -- Basic-timers TIM7_Periph : aliased TIM6_Peripheral with Import, Address => System'To_Address (16#40001400#); type TIM14_Disc is ( Output, Input); -- General-purpose-timers type TIM14_Peripheral (Discriminent : TIM14_Disc := Output) is record -- control register 1 CR1 : aliased CR1_Register_2; -- DMA/Interrupt enable register DIER : aliased DIER_Register_3; -- status register SR : aliased SR_Register_3; -- event generation register EGR : aliased EGR_Register_3; -- capture/compare enable register CCER : aliased CCER_Register_2; -- counter CNT : aliased CNT_Register; -- prescaler PSC : aliased PSC_Register; -- auto-reload register ARR : aliased ARR_Register; -- capture/compare register 1 CCR1 : aliased CCR1_Register; -- option register OR_k : aliased OR_Register; case Discriminent is when Output => -- capture/compare mode register (output mode) CCMR1_Output : aliased CCMR1_Output_Register_1; when Input => -- capture/compare mode register (input mode) CCMR1_Input : aliased CCMR1_Input_Register_2; end case; end record with Unchecked_Union, Volatile; for TIM14_Peripheral use record CR1 at 16#0# range 0 .. 31; DIER at 16#C# range 0 .. 31; SR at 16#10# range 0 .. 31; EGR at 16#14# range 0 .. 31; CCER at 16#20# range 0 .. 31; CNT at 16#24# range 0 .. 31; PSC at 16#28# range 0 .. 31; ARR at 16#2C# range 0 .. 31; CCR1 at 16#34# range 0 .. 31; OR_k at 16#50# range 0 .. 31; CCMR1_Output at 16#18# range 0 .. 31; CCMR1_Input at 16#18# range 0 .. 31; end record; -- General-purpose-timers TIM14_Periph : aliased TIM14_Peripheral with Import, Address => System'To_Address (16#40002000#); type TIM15_Disc is ( Output, Input); -- General-purpose-timers type TIM15_Peripheral (Discriminent : TIM15_Disc := Output) is record -- control register 1 CR1 : aliased CR1_Register_3; -- control register 2 CR2 : aliased CR2_Register_3; -- slave mode control register SMCR : aliased SMCR_Register_1; -- DMA/Interrupt enable register DIER : aliased DIER_Register_4; -- status register SR : aliased SR_Register_4; -- event generation register EGR : aliased EGR_Register_4; -- capture/compare enable register CCER : aliased CCER_Register_3; -- counter CNT : aliased CNT_Register; -- prescaler PSC : aliased PSC_Register; -- auto-reload register ARR : aliased ARR_Register; -- repetition counter register RCR : aliased RCR_Register; -- capture/compare register 1 CCR1 : aliased CCR1_Register; -- capture/compare register 2 CCR2 : aliased CCR2_Register; -- break and dead-time register BDTR : aliased BDTR_Register; -- DMA control register DCR : aliased DCR_Register; -- DMA address for full transfer DMAR : aliased DMAR_Register; case Discriminent is when Output => -- capture/compare mode register (output mode) CCMR1_Output : aliased CCMR1_Output_Register_2; when Input => -- capture/compare mode register 1 (input mode) CCMR1_Input : aliased CCMR1_Input_Register_1; end case; end record with Unchecked_Union, Volatile; for TIM15_Peripheral use record CR1 at 16#0# range 0 .. 31; CR2 at 16#4# range 0 .. 31; SMCR at 16#8# range 0 .. 31; DIER at 16#C# range 0 .. 31; SR at 16#10# range 0 .. 31; EGR at 16#14# range 0 .. 31; CCER at 16#20# range 0 .. 31; CNT at 16#24# range 0 .. 31; PSC at 16#28# range 0 .. 31; ARR at 16#2C# range 0 .. 31; RCR at 16#30# range 0 .. 31; CCR1 at 16#34# range 0 .. 31; CCR2 at 16#38# range 0 .. 31; BDTR at 16#44# range 0 .. 31; DCR at 16#48# range 0 .. 31; DMAR at 16#4C# range 0 .. 31; CCMR1_Output at 16#18# range 0 .. 31; CCMR1_Input at 16#18# range 0 .. 31; end record; -- General-purpose-timers TIM15_Periph : aliased TIM15_Peripheral with Import, Address => System'To_Address (16#40014000#); type TIM16_Disc is ( Output, Input); -- General-purpose-timers type TIM16_Peripheral (Discriminent : TIM16_Disc := Output) is record -- control register 1 CR1 : aliased CR1_Register_3; -- control register 2 CR2 : aliased CR2_Register_4; -- DMA/Interrupt enable register DIER : aliased DIER_Register_5; -- status register SR : aliased SR_Register_5; -- event generation register EGR : aliased EGR_Register_5; -- capture/compare enable register CCER : aliased CCER_Register_4; -- counter CNT : aliased CNT_Register; -- prescaler PSC : aliased PSC_Register; -- auto-reload register ARR : aliased ARR_Register; -- repetition counter register RCR : aliased RCR_Register; -- capture/compare register 1 CCR1 : aliased CCR1_Register; -- break and dead-time register BDTR : aliased BDTR_Register; -- DMA control register DCR : aliased DCR_Register; -- DMA address for full transfer DMAR : aliased DMAR_Register; case Discriminent is when Output => -- capture/compare mode register (output mode) CCMR1_Output : aliased CCMR1_Output_Register_1; when Input => -- capture/compare mode register 1 (input mode) CCMR1_Input : aliased CCMR1_Input_Register_2; end case; end record with Unchecked_Union, Volatile; for TIM16_Peripheral use record CR1 at 16#0# range 0 .. 31; CR2 at 16#4# range 0 .. 31; DIER at 16#C# range 0 .. 31; SR at 16#10# range 0 .. 31; EGR at 16#14# range 0 .. 31; CCER at 16#20# range 0 .. 31; CNT at 16#24# range 0 .. 31; PSC at 16#28# range 0 .. 31; ARR at 16#2C# range 0 .. 31; RCR at 16#30# range 0 .. 31; CCR1 at 16#34# range 0 .. 31; BDTR at 16#44# range 0 .. 31; DCR at 16#48# range 0 .. 31; DMAR at 16#4C# range 0 .. 31; CCMR1_Output at 16#18# range 0 .. 31; CCMR1_Input at 16#18# range 0 .. 31; end record; -- General-purpose-timers TIM16_Periph : aliased TIM16_Peripheral with Import, Address => System'To_Address (16#40014400#); -- General-purpose-timers TIM17_Periph : aliased TIM16_Peripheral with Import, Address => System'To_Address (16#40014800#); end STM32_SVD.TIM;
bkold/Terminal-Chess
Ada
4,469
adb
with NCurses; use NCurses; with Board; use Board; with Ada.exceptions; with Ada.Text_IO; with Ada.Strings.Fixed; use Ada.Strings.Fixed; with GNAT.Command_Line; use GNAT.Command_Line; with GNAT.Sockets; use GNAT.Sockets; procedure Chess is -- pragma Suppress(All_Checks); type Game_Options is (None, Network, Local); procedure Print_and_Clear (Item : in String) with Inline is begin Attribute_On(3); Pretty_Print_Line_Window(Item); Refresh; delay 1.0; Print_Board; end Print_and_Clear; Player_Select_Request : Cordinate_Type; Player_Move_Request : Cordinate_Type; Temp : Byte; Game_Status : Game_Options := None; Port : Port_Type := 0; Is_Host : Boolean := False; -- Address_String : String (1..15) := (others=>' '); Address_String : String := "192.168.1.53"; Client : Socket_Type; Address : Sock_Addr_Type; Channel : Stream_Access; Receiver : Socket_Type; Connection : Socket_Type; Initial_Move : Boolean := True; begin loop case Getopt ("l n h p: i:") is when 'l' => if Game_Status = None then Game_Status := Local; else Ada.Text_IO.Put_Line("Conflicting agument : '-l'"); return; end if; when 'n' => if Game_Status = None then Game_Status := Network; else Ada.Text_IO.Put_Line("Conflicting agument : '-n'"); return; end if; when 'p' => Port := Port_Type'Value(Parameter); when 'h' => Is_Host := True; when 'i' => Move(Parameter, Address_String); when others => exit; end case; end loop; if Game_Status = Network then if (Port = 0 or Address_String = 15*' ') then Ada.Text_IO.Put_Line("Argument Error"); return; end if; if Is_Host then Create_Socket (Receiver); Set_Socket_Option (Socket => Receiver, Option => (Name=>Reuse_Address, Enabled => True)); Bind_Socket (Socket => Receiver, Address => (Family=>Family_Inet, Addr=>Inet_Addr (Address_String), Port=>Port)); Listen_Socket (Socket => Receiver); Accept_Socket (Server => Receiver, Socket => Connection, Address => Address); -- Put_Line("Client connected from " & Image (Address)); Channel := Stream (Connection); else Create_Socket (Client); Address.Addr := Inet_Addr(Address_String); Address.Port := Port; Connect_Socket (Client, Address); Channel := Stream (Client); end if; end if; Init_Scr; Start_Color_Init; Reset_Board; Print_Board; Game_Loop : loop if Initial_Move then Initial_Move := False; if Is_Host then goto HOST_START; end if; end if; Wait_For_Input : loop begin if Game_Status = Network then Get_Variables(Channel); end if; Print_Board; if Is_Winner in 1..2 then Print_and_Clear("Player" & Integer'Image(Is_Winner) & " is the winner"); goto FINISH; end if; exit; exception when others => Print_Board; end; end loop Wait_For_Input; <<HOST_START>> Move_Loop : loop begin Temp := Get_Input; if Temp /= 16#FF# then Player_Select_Request := (Y=>Position(Temp / 2**4), X=>Position(Temp and 16#0F#)); Pretty_Print_Line_Window("Selected " & Character'Val(Character'Pos('A') + Integer(Player_Select_Request.X)) & " -" & Integer'Image(Integer(Player_Select_Request.Y) + 1)); Temp := Get_Input; if Temp /= 16#FF# then Player_Move_Request := (Y=>Position(Temp / 2**4), X=>Position(Temp and 16#0F#)); if Player_Select_Request /= Player_Move_Request then Move(Player_Select_Request, Player_Move_Request); End_Turn; Print_Board; if Game_Status = Network then Set_Variables(Channel); end if; if Is_Winner in 1..2 then Print_and_Clear("Player" & Integer'Image(Is_Winner) & " is the winner"); goto FINISH; end if; exit; else Print_and_Clear("Same Position"); end if; else Print_and_Clear("Input not in range"); end if; else Print_and_Clear("Input not in range"); end if; exception when Collision => Print_and_Clear("Piece in the way"); when Empty_Zone => Print_and_Clear("No piece there"); when Not_Allowed => Print_and_Clear("Move is illegal"); when Error : Others => End_Win; Ada.Text_IO.Put("Unexpected Exception : " & Ada.Exceptions.Exception_Information(Error)); exit; end; end loop Move_Loop; end loop Game_Loop; <<FINISH>> End_Win; end Chess;
reznikmm/matreshka
Ada
6,738
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_Db.Column_Elements is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Db_Column_Element_Node is begin return Self : Db_Column_Element_Node do Matreshka.ODF_Db.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Db_Prefix); end return; end Create; ---------------- -- Enter_Node -- ---------------- overriding procedure Enter_Node (Self : not null access Db_Column_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Enter_Db_Column (ODF.DOM.Db_Column_Elements.ODF_Db_Column_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Enter_Node (Visitor, Control); end if; end Enter_Node; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Db_Column_Element_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Column_Element; end Get_Local_Name; ---------------- -- Leave_Node -- ---------------- overriding procedure Leave_Node (Self : not null access Db_Column_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Leave_Db_Column (ODF.DOM.Db_Column_Elements.ODF_Db_Column_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Leave_Node (Visitor, Control); end if; end Leave_Node; ---------------- -- Visit_Node -- ---------------- overriding procedure Visit_Node (Self : not null access Db_Column_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then ODF.DOM.Iterators.Abstract_ODF_Iterator'Class (Iterator).Visit_Db_Column (Visitor, ODF.DOM.Db_Column_Elements.ODF_Db_Column_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Visit_Node (Iterator, Visitor, Control); end if; end Visit_Node; begin Matreshka.DOM_Documents.Register_Element (Matreshka.ODF_String_Constants.Db_URI, Matreshka.ODF_String_Constants.Column_Element, Db_Column_Element_Node'Tag); end Matreshka.ODF_Db.Column_Elements;
ekoeppen/STM32_Generic_Ada_Drivers
Ada
405
adb
package body STM32GD.SPI.Peripheral is procedure Init is begin null; end Init; procedure Transfer (Data : in out SPI_Data_8b) is begin while SPI.SR.TXE = 0 loop null; end loop; SPI.DR.DR := UInt16 (Data (0)); while SPI.SR.RXNE = 0 loop null; end loop; Data (0) := Byte (SPI.DR.DR); end Transfer; end STM32GD.SPI.Peripheral;
stcarrez/dynamo
Ada
6,526
adb
----------------------------------------------------------------------- -- gen-xmi-tests -- Tests for xmi -- Copyright (C) 2012, 2021, 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.Test_Caller; with Gen.Configs; with Gen.Generator; package body Gen.Artifacts.XMI.Tests is package Caller is new Util.Test_Caller (Test, "Gen.XMI"); procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is begin Caller.Add_Test (Suite, "Test Gen.XMI.Read_UML_Configuration", Test_Read_XMI'Access); Caller.Add_Test (Suite, "Test Gen.XMI.Find_Element", Test_Find_Element'Access); Caller.Add_Test (Suite, "Test Gen.XMI.Find_Element", Test_Find_Tag_Definition'Access); end Add_Tests; -- ------------------------------ -- Test reading the XMI files defines in the Dynamo UML configuration repository. -- ------------------------------ procedure Test_Read_XMI (T : in out Test) is procedure Check (Namespace : in String; Name : in String; Id : in String); A : Artifact; G : Gen.Generator.Handler; C : constant String := Util.Tests.Get_Parameter ("config_dir", "config"); use type Gen.Model.XMI.Model_Element_Access; procedure Check (Namespace : in String; Name : in String; Id : in String) is Empty : Gen.Model.XMI.Model_Map.Map; XMI_Id : constant UString := To_UString (Namespace & "#" & Id); N : constant Gen.Model.XMI.Model_Element_Access := Gen.Model.XMI.Find (A.Nodes, Empty, XMI_Id); begin T.Assert (N /= null, "Cannot find UML element " & To_String (XMI_Id)); Util.Tests.Assert_Equals (T, Name, To_String (N.Name), "Invalid element name"); end Check; begin Gen.Generator.Initialize (G, To_UString (C), False); A.Read_Model (G.Get_Parameter (Gen.Configs.GEN_UML_DIR) & "/Dynamo.xmi", "", G); -- ArgoUML Integer DataType Check ("default-uml14.xmi", "Integer", "-84-17--56-5-43645a83:11466542d86:-8000:000000000000087C"); -- ArgoUML String DataType Check ("default-uml14.xmi", "String", "-84-17--56-5-43645a83:11466542d86:-8000:000000000000087E"); -- ArgoUML documentation TagDefinition Check ("default-uml14.xmi", "documentation", ".:000000000000087C"); -- ArgoUML type Stereotype Check ("default-uml14.xmi", "type", ".:0000000000000842"); -- Persistence Table Stereotype Check ("Dynamo.xmi", "Table", "127-0-1-1--44304ba0:139c0f2a59c:-8000:0000000000001D4F"); Check ("Dynamo.xmi", "PK", "127-0-1-1--44304ba0:139c0f2a59c:-8000:0000000000001D50"); Check ("Dynamo.xmi", "FK", "127-0-1-1--44304ba0:139c0f2a59c:-8000:0000000000001F70"); Check ("Dynamo.xmi", "Bean", "127-0-1-1--44304ba0:139c0f2a59c:-8000:0000000000001F72"); end Test_Read_XMI; -- ------------------------------ -- Test searching an XMI element by using a qualified name. -- ------------------------------ procedure Test_Find_Element (T : in out Test) is A : Artifact; G : Gen.Generator.Handler; C : constant String := Util.Tests.Get_Parameter ("config_dir", "config"); use Gen.Model.XMI; function Find_Stereotype is new Gen.Model.XMI.Find_Element (Element_Type => Stereotype_Element, Element_Type_Access => Stereotype_Element_Access); begin Gen.Generator.Initialize (G, To_UString (C), False); A.Read_Model (G.Get_Parameter (Gen.Configs.GEN_UML_DIR) & "/Dynamo.xmi", "", G); declare S : Gen.Model.XMI.Stereotype_Element_Access; begin S := Find_Stereotype (A.Nodes, "Dynamo.xmi", "ADO.Table", Gen.Model.XMI.BY_NAME); T.Assert (S /= null, "Stereotype not found"); S := Find_Stereotype (A.Nodes, "Dynamo.xmi", "ADO.PK", Gen.Model.XMI.BY_NAME); T.Assert (S /= null, "Stereotype not found"); S := Find_Stereotype (A.Nodes, "Dynamo.xmi", "ADO.FK", Gen.Model.XMI.BY_NAME); T.Assert (S /= null, "Stereotype not found"); S := Find_Stereotype (A.Nodes, "Dynamo.xmi", "ADO.DataModel", Gen.Model.XMI.BY_NAME); T.Assert (S /= null, "Stereotype not found"); S := Find_Stereotype (A.Nodes, "Dynamo.xmi", "AWA.Bean", Gen.Model.XMI.BY_NAME); T.Assert (S /= null, "Stereotype not found"); end; end Test_Find_Element; -- Test searching an XMI Tag definition element by using its name. procedure Test_Find_Tag_Definition (T : in out Test) is A : Artifact; G : Gen.Generator.Handler; C : constant String := Util.Tests.Get_Parameter ("config_dir", "config"); use Gen.Model.XMI; function Find_Tag_Definition is new Gen.Model.XMI.Find_Element (Element_Type => Tag_Definition_Element, Element_Type_Access => Tag_Definition_Element_Access); begin Gen.Generator.Initialize (G, To_UString (C), False); A.Read_Model (G.Get_Parameter (Gen.Configs.GEN_UML_DIR) & "/Dynamo.xmi", "", G); declare Tag : Tag_Definition_Element_Access; begin Tag := Find_Tag_Definition (A.Nodes, "Dynamo.xmi", "[email protected]", Gen.Model.XMI.BY_NAME); T.Assert (Tag /= null, "Tag definition not found"); end; end Test_Find_Tag_Definition; end Gen.Artifacts.XMI.Tests;
redparavoz/ada-wiki
Ada
6,595
ads
----------------------------------------------------------------------- -- wiki-filters -- Wiki filters -- Copyright (C) 2015, 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.Finalization; with Wiki.Attributes; with Wiki.Documents; with Wiki.Nodes; with Wiki.Strings; -- == Filters == -- The <b>Wiki.Filters</b> package provides a simple filter framework that allows to plug -- specific filters when a wiki document is parsed and processed. The <tt>Filter_Type</tt> -- implements the <tt>Document_Reader</tt> interface to catch all the wiki document operations -- and it forwards the different calls to a next wiki document instance. A filter can do some -- operations while calls are made so that it can: -- -- * Get the text content and filter it by looking at forbidden words in some dictionary, -- * Ignore some formatting construct (for example to forbid the use of links), -- * Verify and do some corrections on HTML content embedded in wiki text, -- * Expand some plugins, specific links to complex content. -- -- To implement a new filter, the <tt>Filter_Type</tt> type must be used as a base type -- and some of the operations have to be overriden. The default <tt>Filter_Type</tt> operations -- just propagate the call to the attached wiki document instance (ie, a kind of pass -- through filter). -- -- @include wiki-filters-toc.ads -- @include wiki-filters-html.ads -- @include wiki-filters-collectors.ads -- @include wiki-filters-autolink.ads package Wiki.Filters is pragma Preelaborate; -- ------------------------------ -- Filter type -- ------------------------------ type Filter_Type is limited new Ada.Finalization.Limited_Controlled with private; type Filter_Type_Access is access all Filter_Type'Class; -- Add a simple node such as N_LINE_BREAK, N_HORIZONTAL_RULE or N_PARAGRAPH to the document. procedure Add_Node (Filter : in out Filter_Type; Document : in out Wiki.Documents.Document; Kind : in Wiki.Nodes.Simple_Node_Kind); -- Add a text content with the given format to the document. procedure Add_Text (Filter : in out Filter_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 Filter_Type; Document : in out Wiki.Documents.Document; Header : in Wiki.Strings.WString; Level : in Natural); -- Push a HTML node with the given tag to the document. procedure Push_Node (Filter : in out Filter_Type; Document : in out Wiki.Documents.Document; Tag : in Wiki.Html_Tag; Attributes : in out Wiki.Attributes.Attribute_List); -- Pop a HTML node with the given tag. procedure Pop_Node (Filter : in out Filter_Type; Document : in out Wiki.Documents.Document; Tag : in Wiki.Html_Tag); -- Add a blockquote (<blockquote>). The level indicates the blockquote nested level. -- The blockquote must be closed at the next header. procedure Add_Blockquote (Filter : in out Filter_Type; Document : in out Wiki.Documents.Document; Level : in Natural); -- Add a list item (<li>). Close the previous paragraph and list item if any. -- The list item will be closed at the next list item, next paragraph or next header. procedure Add_List_Item (Filter : in out Filter_Type; Document : in out Wiki.Documents.Document; Level : in Positive; Ordered : in Boolean); -- Add a link. procedure Add_Link (Filter : in out Filter_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 Filter_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 Filter_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 Filter_Type; Document : in out Wiki.Documents.Document; Text : in Wiki.Strings.WString; Format : in Wiki.Strings.WString); -- Finish the document after complete wiki text has been parsed. procedure Finish (Filter : in out Filter_Type; Document : in out Wiki.Documents.Document); type Filter_Chain is new Filter_Type with private; -- Add the filter at beginning of the filter chain. procedure Add_Filter (Chain : in out Filter_Chain; Filter : in Filter_Type_Access); -- Internal operation to copy the filter chain. procedure Set_Chain (Chain : in out Filter_Chain; From : in Filter_Chain'Class); private type Filter_Type is limited new Ada.Finalization.Limited_Controlled with record Next : Filter_Type_Access; end record; type Filter_Chain is new Filter_Type with null record; end Wiki.Filters;
zhmu/ananas
Ada
16,648
adb
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- S Y S T E M . W C H _ C N V -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2022, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Interfaces; use Interfaces; with System.WCh_Con; use System.WCh_Con; with System.WCh_JIS; use System.WCh_JIS; package body System.WCh_Cnv is ----------------------------- -- Char_Sequence_To_UTF_32 -- ----------------------------- function Char_Sequence_To_UTF_32 (C : Character; EM : System.WCh_Con.WC_Encoding_Method) return UTF_32_Code is B1 : Unsigned_32; C1 : Character; U : Unsigned_32; W : Unsigned_32; procedure Get_Hex (N : Character); -- If N is a hex character, then set B1 to 16 * B1 + character N. -- Raise Constraint_Error if character N is not a hex character. procedure Get_UTF_Byte; pragma Inline (Get_UTF_Byte); -- Used to interpret a 2#10xxxxxx# continuation byte in UTF-8 mode. -- Reads a byte, and raises CE if the first two bits are not 10. -- Otherwise shifts W 6 bits left and or's in the 6 xxxxxx bits. ------------- -- Get_Hex -- ------------- procedure Get_Hex (N : Character) is B2 : constant Unsigned_32 := Character'Pos (N); begin if B2 in Character'Pos ('0') .. Character'Pos ('9') then B1 := B1 * 16 + B2 - Character'Pos ('0'); elsif B2 in Character'Pos ('A') .. Character'Pos ('F') then B1 := B1 * 16 + B2 - (Character'Pos ('A') - 10); elsif B2 in Character'Pos ('a') .. Character'Pos ('f') then B1 := B1 * 16 + B2 - (Character'Pos ('a') - 10); else raise Constraint_Error; end if; end Get_Hex; ------------------ -- Get_UTF_Byte -- ------------------ procedure Get_UTF_Byte is begin U := Unsigned_32 (Character'Pos (In_Char)); if (U and 2#11000000#) /= 2#10_000000# then raise Constraint_Error; end if; W := Shift_Left (W, 6) or (U and 2#00111111#); end Get_UTF_Byte; -- Start of processing for Char_Sequence_To_UTF_32 begin case EM is when WCEM_Hex => if C /= ASCII.ESC then return Character'Pos (C); else B1 := 0; Get_Hex (In_Char); Get_Hex (In_Char); Get_Hex (In_Char); Get_Hex (In_Char); return UTF_32_Code (B1); end if; when WCEM_Upper => if C > ASCII.DEL then return 256 * Character'Pos (C) + Character'Pos (In_Char); else return Character'Pos (C); end if; when WCEM_Shift_JIS => if C > ASCII.DEL then return Wide_Character'Pos (Shift_JIS_To_JIS (C, In_Char)); else return Character'Pos (C); end if; when WCEM_EUC => if C > ASCII.DEL then return Wide_Character'Pos (EUC_To_JIS (C, In_Char)); else return Character'Pos (C); end if; when WCEM_UTF8 => -- Note: for details of UTF8 encoding see RFC 3629 U := Unsigned_32 (Character'Pos (C)); -- 16#00_0000#-16#00_007F#: 0xxxxxxx if (U and 2#10000000#) = 2#00000000# then return Character'Pos (C); -- 16#00_0080#-16#00_07FF#: 110xxxxx 10xxxxxx elsif (U and 2#11100000#) = 2#110_00000# then W := U and 2#00011111#; Get_UTF_Byte; return UTF_32_Code (W); -- 16#00_0800#-16#00_ffff#: 1110xxxx 10xxxxxx 10xxxxxx elsif (U and 2#11110000#) = 2#1110_0000# then W := U and 2#00001111#; Get_UTF_Byte; Get_UTF_Byte; return UTF_32_Code (W); -- 16#01_0000#-16#10_FFFF#: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx elsif (U and 2#11111000#) = 2#11110_000# then W := U and 2#00000111#; for K in 1 .. 3 loop Get_UTF_Byte; end loop; return UTF_32_Code (W); -- 16#0020_0000#-16#03FF_FFFF#: 111110xx 10xxxxxx 10xxxxxx -- 10xxxxxx 10xxxxxx elsif (U and 2#11111100#) = 2#111110_00# then W := U and 2#00000011#; for K in 1 .. 4 loop Get_UTF_Byte; end loop; return UTF_32_Code (W); -- 16#0400_0000#-16#7FFF_FFFF#: 1111110x 10xxxxxx 10xxxxxx -- 10xxxxxx 10xxxxxx 10xxxxxx elsif (U and 2#11111110#) = 2#1111110_0# then W := U and 2#00000001#; for K in 1 .. 5 loop Get_UTF_Byte; end loop; return UTF_32_Code (W); else raise Constraint_Error; end if; when WCEM_Brackets => if C /= '[' then return Character'Pos (C); end if; if In_Char /= '"' then raise Constraint_Error; end if; B1 := 0; Get_Hex (In_Char); Get_Hex (In_Char); C1 := In_Char; if C1 /= '"' then Get_Hex (C1); Get_Hex (In_Char); C1 := In_Char; if C1 /= '"' then Get_Hex (C1); Get_Hex (In_Char); C1 := In_Char; if C1 /= '"' then Get_Hex (C1); Get_Hex (In_Char); if B1 > Unsigned_32 (UTF_32_Code'Last) then raise Constraint_Error; end if; if In_Char /= '"' then raise Constraint_Error; end if; end if; end if; end if; if In_Char /= ']' then raise Constraint_Error; end if; return UTF_32_Code (B1); end case; end Char_Sequence_To_UTF_32; -------------------------------- -- Char_Sequence_To_Wide_Char -- -------------------------------- function Char_Sequence_To_Wide_Char (C : Character; EM : System.WCh_Con.WC_Encoding_Method) return Wide_Character is function Char_Sequence_To_UTF is new Char_Sequence_To_UTF_32 (In_Char); U : constant UTF_32_Code := Char_Sequence_To_UTF (C, EM); begin if U > 16#FFFF# then raise Constraint_Error; else return Wide_Character'Val (U); end if; end Char_Sequence_To_Wide_Char; ----------------------------- -- UTF_32_To_Char_Sequence -- ----------------------------- procedure UTF_32_To_Char_Sequence (Val : UTF_32_Code; EM : System.WCh_Con.WC_Encoding_Method) is Hexc : constant array (UTF_32_Code range 0 .. 15) of Character := "0123456789ABCDEF"; C1, C2 : Character; U : Unsigned_32; begin -- Raise CE for invalid UTF_32_Code if not Val'Valid then raise Constraint_Error; end if; -- Processing depends on encoding mode case EM is when WCEM_Hex => if Val < 256 then Out_Char (Character'Val (Val)); elsif Val <= 16#FFFF# then Out_Char (ASCII.ESC); Out_Char (Hexc (Val / (16**3))); Out_Char (Hexc ((Val / (16**2)) mod 16)); Out_Char (Hexc ((Val / 16) mod 16)); Out_Char (Hexc (Val mod 16)); else raise Constraint_Error; end if; when WCEM_Upper => if Val < 128 then Out_Char (Character'Val (Val)); elsif Val < 16#8000# or else Val > 16#FFFF# then raise Constraint_Error; else Out_Char (Character'Val (Val / 256)); Out_Char (Character'Val (Val mod 256)); end if; when WCEM_Shift_JIS => if Val < 128 then Out_Char (Character'Val (Val)); elsif Val <= 16#FFFF# then JIS_To_Shift_JIS (Wide_Character'Val (Val), C1, C2); Out_Char (C1); Out_Char (C2); else raise Constraint_Error; end if; when WCEM_EUC => if Val < 128 then Out_Char (Character'Val (Val)); elsif Val <= 16#FFFF# then JIS_To_EUC (Wide_Character'Val (Val), C1, C2); Out_Char (C1); Out_Char (C2); else raise Constraint_Error; end if; when WCEM_UTF8 => -- Note: for details of UTF8 encoding see RFC 3629 U := Unsigned_32 (Val); -- 16#00_0000#-16#00_007F#: 0xxxxxxx if U <= 16#00_007F# then Out_Char (Character'Val (U)); -- 16#00_0080#-16#00_07FF#: 110xxxxx 10xxxxxx elsif U <= 16#00_07FF# then Out_Char (Character'Val (2#11000000# or Shift_Right (U, 6))); Out_Char (Character'Val (2#10000000# or (U and 2#00111111#))); -- 16#00_0800#-16#00_FFFF#: 1110xxxx 10xxxxxx 10xxxxxx elsif U <= 16#00_FFFF# then Out_Char (Character'Val (2#11100000# or Shift_Right (U, 12))); Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 6) and 2#00111111#))); Out_Char (Character'Val (2#10000000# or (U and 2#00111111#))); -- 16#01_0000#-16#10_FFFF#: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx elsif U <= 16#10_FFFF# then Out_Char (Character'Val (2#11110000# or Shift_Right (U, 18))); Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 12) and 2#00111111#))); Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 6) and 2#00111111#))); Out_Char (Character'Val (2#10000000# or (U and 2#00111111#))); -- 16#0020_0000#-16#03FF_FFFF#: 111110xx 10xxxxxx 10xxxxxx -- 10xxxxxx 10xxxxxx elsif U <= 16#03FF_FFFF# then Out_Char (Character'Val (2#11111000# or Shift_Right (U, 24))); Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 18) and 2#00111111#))); Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 12) and 2#00111111#))); Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 6) and 2#00111111#))); Out_Char (Character'Val (2#10000000# or (U and 2#00111111#))); -- 16#0400_0000#-16#7FFF_FFFF#: 1111110x 10xxxxxx 10xxxxxx -- 10xxxxxx 10xxxxxx 10xxxxxx elsif U <= 16#7FFF_FFFF# then Out_Char (Character'Val (2#11111100# or Shift_Right (U, 30))); Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 24) and 2#00111111#))); Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 18) and 2#00111111#))); Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 12) and 2#00111111#))); Out_Char (Character'Val (2#10000000# or (Shift_Right (U, 6) and 2#00111111#))); Out_Char (Character'Val (2#10000000# or (U and 2#00111111#))); else raise Constraint_Error; end if; when WCEM_Brackets => -- Values in the range 0-255 are directly output. Note that there -- is an issue with [ (16#5B#) since this will cause confusion -- if the resulting string is interpreted using brackets encoding. -- One possibility would be to always output [ as ["5B"] but in -- practice this is undesirable, since for example normal use of -- Wide_Text_IO for output (much more common than input), really -- does want to be able to say something like -- Put_Line ("Start of output [first run]"); -- and have it come out as intended, rather than contaminated by -- a ["5B"] sequence in place of the left bracket. if Val < 256 then Out_Char (Character'Val (Val)); -- Otherwise use brackets notation for vales greater than 255 else Out_Char ('['); Out_Char ('"'); if Val > 16#FFFF# then if Val > 16#00FF_FFFF# then Out_Char (Hexc (Val / 16 ** 7)); Out_Char (Hexc ((Val / 16 ** 6) mod 16)); end if; Out_Char (Hexc ((Val / 16 ** 5) mod 16)); Out_Char (Hexc ((Val / 16 ** 4) mod 16)); end if; Out_Char (Hexc ((Val / 16 ** 3) mod 16)); Out_Char (Hexc ((Val / 16 ** 2) mod 16)); Out_Char (Hexc ((Val / 16) mod 16)); Out_Char (Hexc (Val mod 16)); Out_Char ('"'); Out_Char (']'); end if; end case; end UTF_32_To_Char_Sequence; -------------------------------- -- Wide_Char_To_Char_Sequence -- -------------------------------- procedure Wide_Char_To_Char_Sequence (WC : Wide_Character; EM : System.WCh_Con.WC_Encoding_Method) is procedure UTF_To_Char_Sequence is new UTF_32_To_Char_Sequence (Out_Char); begin UTF_To_Char_Sequence (Wide_Character'Pos (WC), EM); end Wide_Char_To_Char_Sequence; end System.WCh_Cnv;
reznikmm/matreshka
Ada
3,993
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_Is_Hidden_Attributes; package Matreshka.ODF_Text.Is_Hidden_Attributes is type Text_Is_Hidden_Attribute_Node is new Matreshka.ODF_Text.Abstract_Text_Attribute_Node and ODF.DOM.Text_Is_Hidden_Attributes.ODF_Text_Is_Hidden_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Text_Is_Hidden_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Text_Is_Hidden_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Text.Is_Hidden_Attributes;
kontena/ruby-packer
Ada
8,471
adb
------------------------------------------------------------------------------ -- -- -- GNAT ncurses Binding Samples -- -- -- -- Sample -- -- -- -- B O D Y -- -- -- ------------------------------------------------------------------------------ -- Copyright (c) 1998-2008,2011 Free Software Foundation, Inc. -- -- -- -- Permission is hereby granted, free of charge, to any person obtaining a -- -- copy of this software and associated documentation files (the -- -- "Software"), to deal in the Software without restriction, including -- -- without limitation the rights to use, copy, modify, merge, publish, -- -- distribute, distribute with modifications, sublicense, and/or sell -- -- copies of the Software, and to permit persons to whom the Software is -- -- furnished to do so, subject to the following conditions: -- -- -- -- The above copyright notice and this permission notice shall be included -- -- in all copies or substantial portions of the Software. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -- -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- -- -- -- Except as contained in this notice, the name(s) of the above copyright -- -- holders shall not be used in advertising or otherwise to promote the -- -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------ -- Author: Juergen Pfeifer, 1996 -- Version Control -- $Revision: 1.18 $ -- $Date: 2011/03/23 00:44:12 $ -- Binding Version 01.00 ------------------------------------------------------------------------------ with Text_IO; with Ada.Exceptions; use Ada.Exceptions; with Terminal_Interface.Curses; use Terminal_Interface.Curses; with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels; with Terminal_Interface.Curses.Menus; use Terminal_Interface.Curses.Menus; with Terminal_Interface.Curses.Menus.Menu_User_Data; with Terminal_Interface.Curses.Menus.Item_User_Data; with Sample.Manifest; use Sample.Manifest; with Sample.Function_Key_Setting; use Sample.Function_Key_Setting; with Sample.Keyboard_Handler; use Sample.Keyboard_Handler; with Sample.Header_Handler; use Sample.Header_Handler; with Sample.Explanation; use Sample.Explanation; with Sample.Menu_Demo.Handler; with Sample.Curses_Demo; with Sample.Form_Demo; with Sample.Menu_Demo; with Sample.Text_IO_Demo; with GNAT.OS_Lib; package body Sample is type User_Data is record Data : Integer; end record; type User_Access is access User_Data; package Ud is new Terminal_Interface.Curses.Menus.Menu_User_Data (User_Data, User_Access); package Id is new Terminal_Interface.Curses.Menus.Item_User_Data (User_Data, User_Access); procedure Whow is procedure Main_Menu; procedure Main_Menu is function My_Driver (M : Menu; K : Key_Code; Pan : Panel) return Boolean; package Mh is new Sample.Menu_Demo.Handler (My_Driver); I : Item_Array_Access := new Item_Array' (New_Item ("Curses Core Demo"), New_Item ("Menu Demo"), New_Item ("Form Demo"), New_Item ("Text IO Demo"), Null_Item); M : Menu := New_Menu (I); D1, D2 : User_Access; I1, I2 : User_Access; function My_Driver (M : Menu; K : Key_Code; Pan : Panel) return Boolean is Idx : constant Positive := Get_Index (Current (M)); begin if K in User_Key_Code'Range then if K = QUIT then return True; elsif K = SELECT_ITEM then if Idx <= 4 then Hide (Pan); Update_Panels; end if; case Idx is when 1 => Sample.Curses_Demo.Demo; when 2 => Sample.Menu_Demo.Demo; when 3 => Sample.Form_Demo.Demo; when 4 => Sample.Text_IO_Demo.Demo; when others => null; end case; if Idx <= 4 then Top (Pan); Show (Pan); Update_Panels; Update_Screen; end if; end if; end if; return False; end My_Driver; begin if (1 + Item_Count (M)) /= I'Length then raise Constraint_Error; end if; D1 := new User_Data'(Data => 4711); Ud.Set_User_Data (M, D1); I1 := new User_Data'(Data => 1174); Id.Set_User_Data (I.all (1), I1); Set_Spacing (Men => M, Row => 2); Default_Labels; Notepad ("MAINPAD"); Mh.Drive_Me (M, " Demo "); Ud.Get_User_Data (M, D2); pragma Assert (D1 = D2); pragma Assert (D1.Data = D2.Data); Id.Get_User_Data (I.all (1), I2); pragma Assert (I1 = I2); pragma Assert (I1.Data = I2.Data); Delete (M); Free (I, True); end Main_Menu; begin Initialize (PC_Style_With_Index); Init_Header_Handler; Init_Screen; if Has_Colors then Start_Color; Init_Pair (Pair => Default_Colors, Fore => Black, Back => White); Init_Pair (Pair => Menu_Back_Color, Fore => Black, Back => Cyan); Init_Pair (Pair => Menu_Fore_Color, Fore => Red, Back => Cyan); Init_Pair (Pair => Menu_Grey_Color, Fore => White, Back => Cyan); Init_Pair (Pair => Notepad_Color, Fore => Black, Back => Yellow); Init_Pair (Pair => Help_Color, Fore => Blue, Back => Cyan); Init_Pair (Pair => Form_Back_Color, Fore => Black, Back => Cyan); Init_Pair (Pair => Form_Fore_Color, Fore => Red, Back => Cyan); Init_Pair (Pair => Header_Color, Fore => Black, Back => Green); Set_Background (Ch => (Color => Default_Colors, Attr => Normal_Video, Ch => ' ')); Set_Character_Attributes (Attr => Normal_Video, Color => Default_Colors); Erase; Set_Soft_Label_Key_Attributes (Color => Header_Color); -- This propagates the attributes to the label window Refresh_Soft_Label_Keys; end if; Init_Keyboard_Handler; Set_Echo_Mode (False); Set_Raw_Mode; Set_Meta_Mode; Set_KeyPad_Mode; -- Initialize the Function Key Environment -- We have some fixed key throughout this sample Main_Menu; End_Windows; Curses_Free_All; exception when Event : others => Terminal_Interface.Curses.End_Windows; Text_IO.Put ("Exception: "); Text_IO.Put (Exception_Name (Event)); Text_IO.New_Line; GNAT.OS_Lib.OS_Exit (1); end Whow; end Sample;
stcarrez/sql-benchmark
Ada
5,466
adb
----------------------------------------------------------------------- -- sqlbench-simple -- Simple SQL benchmark -- Copyright (C) 2018 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.Strings.Unbounded; with ADO.Statements; with Util.Files; package body Sqlbench.Simple is use Ada.Strings.Unbounded; generic LIMIT : Positive; procedure Select_Table_N (Context : in out Context_Type); procedure Select_Table_N (Context : in out Context_Type) is DB : constant ADO.Sessions.Master_Session := Context.Get_Session; Count : Natural; Stmt : ADO.Statements.Query_Statement := DB.Create_Statement ("SELECT * FROM test_simple LIMIT " & Positive'Image (LIMIT)); begin for I in 1 .. Context.Repeat loop Stmt.Execute; Count := 0; while Stmt.Has_Elements loop Count := Count + 1; Stmt.Next; end loop; if Count /= LIMIT then raise Benchmark_Error with "Invalid result count:" & Natural'Image (Count); end if; end loop; end Select_Table_N; procedure Do_Static (Context : in out Context_Type); procedure Select_Static (Context : in out Context_Type); procedure Connect_Select_Static (Context : in out Context_Type); procedure Drop_Create (Context : in out Context_Type); procedure Insert (Context : in out Context_Type); procedure Select_Table_1 is new Select_Table_N (1); procedure Select_Table_10 is new Select_Table_N (10); procedure Select_Table_100 is new Select_Table_N (100); procedure Select_Table_500 is new Select_Table_N (500); procedure Select_Table_1000 is new Select_Table_N (1000); Create_SQL : Ada.Strings.Unbounded.Unbounded_String; procedure Register (Tests : in out Context_Type) is Driver : constant String := Tests.Get_Driver_Name; begin if Driver /= "sqlite" and Driver /= "postgresql" then Tests.Register (Do_Static'Access, "DO 1"); end if; Tests.Register (Select_Static'Access, "SELECT 1"); Tests.Register (Connect_Select_Static'Access, "CONNECT; SELECT 1; CLOSE"); Tests.Register (Drop_Create'Access, "DROP table; CREATE table", 1); Tests.Register (Insert'Access, "INSERT INTO table", 10); Tests.Register (Select_Table_1'Access, "SELECT * FROM table LIMIT 1"); Tests.Register (Select_Table_10'Access, "SELECT * FROM table LIMIT 10"); Tests.Register (Select_Table_100'Access, "SELECT * FROM table LIMIT 100"); Tests.Register (Select_Table_500'Access, "SELECT * FROM table LIMIT 500"); Tests.Register (Select_Table_1000'Access, "SELECT * FROM table LIMIT 1000"); Util.Files.Read_File (Tests.Get_Config_Path ("create-table.sql"), Create_SQL); end Register; procedure Do_Static (Context : in out Context_Type) is Stmt : ADO.Statements.Query_Statement := Context.Session.Create_Statement ("DO 1"); begin for I in 1 .. Context.Repeat loop Stmt.Execute; end loop; end Do_Static; procedure Select_Static (Context : in out Context_Type) is Stmt : ADO.Statements.Query_Statement := Context.Session.Create_Statement ("SELECT 1"); begin for I in 1 .. Context.Repeat loop Stmt.Execute; end loop; end Select_Static; procedure Connect_Select_Static (Context : in out Context_Type) is begin for I in 1 .. Context.Repeat loop declare DB : constant ADO.Sessions.Session := Context.Factory.Get_Session; Stmt : ADO.Statements.Query_Statement := DB.Create_Statement ("SELECT 1"); begin Stmt.Execute; end; end loop; end Connect_Select_Static; procedure Drop_Create (Context : in out Context_Type) is Drop_Stmt : ADO.Statements.Query_Statement := Context.Session.Create_Statement ("DROP TABLE test_simple"); Create_Stmt : ADO.Statements.Query_Statement := Context.Session.Create_Statement (To_String (Create_SQL)); begin for I in 1 .. Context.Repeat loop begin Drop_Stmt.Execute; Context.Session.Commit; exception when ADO.Statements.SQL_Error => Context.Session.Rollback; end; Context.Session.Begin_Transaction; Create_Stmt.Execute; Context.Session.Commit; Context.Session.Begin_Transaction; end loop; end Drop_Create; procedure Insert (Context : in out Context_Type) is Stmt : ADO.Statements.Query_Statement := Context.Session.Create_Statement ("INSERT INTO test_simple (value) VALUES (1)"); begin for I in 1 .. Context.Repeat loop Stmt.Execute; end loop; Context.Session.Commit; end Insert; end Sqlbench.Simple;
joakim-strandberg/wayland_ada_binding
Ada
933
ads
package C_Binding.Linux.Udev.List_Entries is type List_Entry; procedure Get_By_Name ( Current : List_Entry; -- current entry Name : String; -- name string to match Found_Entry : out List_Entry -- The entry where name matched ) with Pre => List_Entries.Exists (Current); -- On success, Found_Entry.Exists = True -- On failure, Found_Entry.Exists = False type List_Entry is new List_Entry_Base with private; function Exists (List_Entry : List_Entries.List_Entry) return Boolean; procedure Next (List_Entry : in out List_Entries.List_Entry) with Pre => List_Entry.Exists; function Name (List_Entry : List_Entries.List_Entry) return String_Result; function Value (List_Entry : List_Entries.List_Entry) return String_Result; private type List_Entry is new List_Entry_Base with null record; end C_Binding.Linux.Udev.List_Entries;
osannolik/Ada_Drivers_Library
Ada
6,779
ads
-- This spec has been automatically generated from STM32F446x.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package STM32_SVD.NVIC is pragma Preelaborate; --------------- -- Registers -- --------------- subtype ICTR_INTLINESNUM_Field is HAL.UInt4; -- Interrupt Controller Type Register type ICTR_Register is record -- Read-only. Total number of interrupt lines in groups INTLINESNUM : ICTR_INTLINESNUM_Field; -- unspecified Reserved_4_31 : HAL.UInt28; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for ICTR_Register use record INTLINESNUM at 0 range 0 .. 3; Reserved_4_31 at 0 range 4 .. 31; end record; -- IPR_IPR_N array element subtype IPR_IPR_N_Element is HAL.UInt8; -- IPR_IPR_N array type IPR_IPR_N_Field_Array is array (0 .. 3) of IPR_IPR_N_Element with Component_Size => 8, Size => 32; -- Interrupt Priority Register type IPR_Register (As_Array : Boolean := False) is record case As_Array is when False => -- IPR_N as a value Val : HAL.UInt32; when True => -- IPR_N as an array Arr : IPR_IPR_N_Field_Array; end case; end record with Unchecked_Union, Size => 32, Volatile_Full_Access, Bit_Order => System.Low_Order_First; for IPR_Register use record Val at 0 range 0 .. 31; Arr at 0 range 0 .. 31; end record; subtype STIR_INTID_Field is HAL.UInt9; -- Software Triggered Interrupt Register type STIR_Register is record -- Write-only. interrupt to be triggered INTID : STIR_INTID_Field := 16#0#; -- unspecified Reserved_9_31 : HAL.UInt23 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for STIR_Register use record INTID at 0 range 0 .. 8; Reserved_9_31 at 0 range 9 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Nested Vectored Interrupt Controller type NVIC_Peripheral is record -- Interrupt Controller Type Register ICTR : aliased ICTR_Register; -- Interrupt Set-Enable Register ISER0 : aliased HAL.UInt32; -- Interrupt Set-Enable Register ISER1 : aliased HAL.UInt32; -- Interrupt Set-Enable Register ISER2 : aliased HAL.UInt32; -- Interrupt Clear-Enable Register ICER0 : aliased HAL.UInt32; -- Interrupt Clear-Enable Register ICER1 : aliased HAL.UInt32; -- Interrupt Clear-Enable Register ICER2 : aliased HAL.UInt32; -- Interrupt Set-Pending Register ISPR0 : aliased HAL.UInt32; -- Interrupt Set-Pending Register ISPR1 : aliased HAL.UInt32; -- Interrupt Set-Pending Register ISPR2 : aliased HAL.UInt32; -- Interrupt Clear-Pending Register ICPR0 : aliased HAL.UInt32; -- Interrupt Clear-Pending Register ICPR1 : aliased HAL.UInt32; -- Interrupt Clear-Pending Register ICPR2 : aliased HAL.UInt32; -- Interrupt Active Bit Register IABR0 : aliased HAL.UInt32; -- Interrupt Active Bit Register IABR1 : aliased HAL.UInt32; -- Interrupt Active Bit Register IABR2 : aliased HAL.UInt32; -- Interrupt Priority Register IPR0 : aliased IPR_Register; -- Interrupt Priority Register IPR1 : aliased IPR_Register; -- Interrupt Priority Register IPR2 : aliased IPR_Register; -- Interrupt Priority Register IPR3 : aliased IPR_Register; -- Interrupt Priority Register IPR4 : aliased IPR_Register; -- Interrupt Priority Register IPR5 : aliased IPR_Register; -- Interrupt Priority Register IPR6 : aliased IPR_Register; -- Interrupt Priority Register IPR7 : aliased IPR_Register; -- Interrupt Priority Register IPR8 : aliased IPR_Register; -- Interrupt Priority Register IPR9 : aliased IPR_Register; -- Interrupt Priority Register IPR10 : aliased IPR_Register; -- Interrupt Priority Register IPR11 : aliased IPR_Register; -- Interrupt Priority Register IPR12 : aliased IPR_Register; -- Interrupt Priority Register IPR13 : aliased IPR_Register; -- Interrupt Priority Register IPR14 : aliased IPR_Register; -- Interrupt Priority Register IPR15 : aliased IPR_Register; -- Interrupt Priority Register IPR16 : aliased IPR_Register; -- Interrupt Priority Register IPR17 : aliased IPR_Register; -- Interrupt Priority Register IPR18 : aliased IPR_Register; -- Interrupt Priority Register IPR19 : aliased IPR_Register; -- Interrupt Priority Register IPR20 : aliased IPR_Register; -- Software Triggered Interrupt Register STIR : aliased STIR_Register; end record with Volatile; for NVIC_Peripheral use record ICTR at 16#4# range 0 .. 31; ISER0 at 16#100# range 0 .. 31; ISER1 at 16#104# range 0 .. 31; ISER2 at 16#108# range 0 .. 31; ICER0 at 16#180# range 0 .. 31; ICER1 at 16#184# range 0 .. 31; ICER2 at 16#188# range 0 .. 31; ISPR0 at 16#200# range 0 .. 31; ISPR1 at 16#204# range 0 .. 31; ISPR2 at 16#208# range 0 .. 31; ICPR0 at 16#280# range 0 .. 31; ICPR1 at 16#284# range 0 .. 31; ICPR2 at 16#288# range 0 .. 31; IABR0 at 16#300# range 0 .. 31; IABR1 at 16#304# range 0 .. 31; IABR2 at 16#308# range 0 .. 31; IPR0 at 16#400# range 0 .. 31; IPR1 at 16#404# range 0 .. 31; IPR2 at 16#408# range 0 .. 31; IPR3 at 16#40C# range 0 .. 31; IPR4 at 16#410# range 0 .. 31; IPR5 at 16#414# range 0 .. 31; IPR6 at 16#418# range 0 .. 31; IPR7 at 16#41C# range 0 .. 31; IPR8 at 16#420# range 0 .. 31; IPR9 at 16#424# range 0 .. 31; IPR10 at 16#428# range 0 .. 31; IPR11 at 16#42C# range 0 .. 31; IPR12 at 16#430# range 0 .. 31; IPR13 at 16#434# range 0 .. 31; IPR14 at 16#438# range 0 .. 31; IPR15 at 16#43C# range 0 .. 31; IPR16 at 16#440# range 0 .. 31; IPR17 at 16#444# range 0 .. 31; IPR18 at 16#448# range 0 .. 31; IPR19 at 16#44C# range 0 .. 31; IPR20 at 16#450# range 0 .. 31; STIR at 16#F00# range 0 .. 31; end record; -- Nested Vectored Interrupt Controller NVIC_Periph : aliased NVIC_Peripheral with Import, Address => System'To_Address (16#E000E000#); end STM32_SVD.NVIC;
kraileth/ravensource
Ada
782
adb
From 158d754604c284b4c23b4e4793ce969366a1dffb Mon Sep 17 00:00:00 2001 From: Anthony Leonardo Gracio <[email protected]> Date: Fri, 29 Apr 2022 15:38:18 +0000 Subject: [PATCH] V429-030: Adapt to new Format_Vector API Change-Id: I737ad812fc4c85617bb71fc49a3dde1547967b8e --- lal/core/lal-ada_languages.adb | 2 -- 1 file changed, 2 deletions(-) --- lal/core/lal-ada_languages.adb.orig +++ lal/core/lal-ada_languages.adb @@ -130,9 +130,7 @@ package body LAL.Ada_Languages is (Cmd => Lang.Pp_Command_Line, Input => Input, Node => Root, - In_Range => From_Range, Output => Output, - Out_Range => To_Range, Messages => Errors); exception when E : others =>
MinimSecure/unum-sdk
Ada
813
ads
-- Copyright 2013-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/>. package Caller is procedure Verbose_Increment (Val : in out Float; Msg : String); end Caller;
reznikmm/matreshka
Ada
5,228
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011, 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 package provides proxy settings storage which implements fallbacks -- mechanism on top of several underling settings storages. ------------------------------------------------------------------------------ private with Ada.Containers.Vectors; package Matreshka.Internals.Settings.Fallbacks is type Fallback_Settings is new Abstract_Settings with private; function Create (Manager : not null access Abstract_Manager'Class) return not null Settings_Access; -- Creates fallbacks proxy. procedure Add (Self : not null access Fallback_Settings'Class; Storage : not null Settings_Access); -- Adds specified settings storage to be used to retrieve settings. First -- added storage is used to modify settings also. private package Vectors is new Ada.Containers.Vectors (Positive, Settings_Access); type Fallback_Settings is new Abstract_Settings with record Storages : Vectors.Vector; end record; overriding function Contains (Self : Fallback_Settings; Key : League.Strings.Universal_String) return Boolean; overriding procedure Finalize (Self : not null access Fallback_Settings); overriding function Name (Self : not null access Fallback_Settings) return League.Strings.Universal_String; -- Returns name of the first underling settings storage. overriding procedure Remove (Self : in out Fallback_Settings; Key : League.Strings.Universal_String); overriding procedure Set_Value (Self : in out Fallback_Settings; Key : League.Strings.Universal_String; Value : League.Holders.Holder); overriding procedure Sync (Self : in out Fallback_Settings); overriding function Value (Self : Fallback_Settings; Key : League.Strings.Universal_String) return League.Holders.Holder; end Matreshka.Internals.Settings.Fallbacks;