content
stringlengths
23
1.05M
with C.mpfr; package MPFR.Root_FR.Inside is pragma Preelaborate; function Reference (X : in out MP_Float) return not null access C.mpfr.mpfr_struct; function Constant_Reference (X : MP_Float) return not null access constant C.mpfr.mpfr_struct; pragma Inline (Reference); -- renamed pragma Inline (Constant_Reference); -- renamed private function Reference (X : in out MP_Float) return not null access C.mpfr.mpfr_struct renames Controlled.Reference; function Constant_Reference (X : MP_Float) return not null access constant C.mpfr.mpfr_struct renames Controlled.Constant_Reference; end MPFR.Root_FR.Inside;
package body Signal is protected body Handler is function Triggered return Boolean is (Signal_Received); procedure Handle_Int is begin Signal_Received := True; end Handle_Int; procedure Handle_Quit is begin Signal_Received := True; end Handle_Quit; procedure Handle_Term is begin Signal_Received := True; end Handle_Term; end Handler; end Signal;
-- -- Copyright (C) 2022, AdaCore -- pragma Style_Checks (Off); -- This spec has been automatically generated from STM32F3x4.svd -- This is a version for the STM32F3x4 MCU package Ada.Interrupts.Names is -- All identifiers in this unit are implementation defined pragma Implementation_Defined; ---------------- -- Interrupts -- ---------------- -- System tick Sys_Tick_Interrupt : constant Interrupt_ID := -1; -- Window Watchdog interrupt WWDG_Interrupt : constant Interrupt_ID := 0; -- PVD through EXTI line detection interrupt PVD_Interrupt : constant Interrupt_ID := 1; -- Tamper and TimeStamp interrupts TAMP_STAMP_Interrupt : constant Interrupt_ID := 2; -- RTC Wakeup interrupt through the EXTI line RTC_WKUP_Interrupt : constant Interrupt_ID := 3; -- Flash global interrupt FLASH_Interrupt : constant Interrupt_ID := 4; -- RCC global interrupt RCC_Interrupt : constant Interrupt_ID := 5; -- EXTI Line0 interrupt EXTI0_Interrupt : constant Interrupt_ID := 6; -- EXTI Line3 interrupt EXTI1_Interrupt : constant Interrupt_ID := 7; -- EXTI Line2 and Touch sensing interrupts EXTI2_TSC_Interrupt : constant Interrupt_ID := 8; -- EXTI Line3 interrupt EXTI3_Interrupt : constant Interrupt_ID := 9; -- EXTI Line4 interrupt EXTI4_Interrupt : constant Interrupt_ID := 10; -- DMA1 channel 1 interrupt DMA1_CH1_Interrupt : constant Interrupt_ID := 11; -- DMA1 channel 2 interrupt DMA1_CH2_Interrupt : constant Interrupt_ID := 12; -- DMA1 channel 3 interrupt DMA1_CH3_Interrupt : constant Interrupt_ID := 13; -- DMA1 channel 4 interrupt DMA1_CH4_Interrupt : constant Interrupt_ID := 14; -- DMA1 channel 5 interrupt DMA1_CH5_Interrupt : constant Interrupt_ID := 15; -- DMA1 channel 6 interrupt DMA1_CH6_Interrupt : constant Interrupt_ID := 16; -- DMA1 channel 7interrupt DMA1_CH7_Interrupt : constant Interrupt_ID := 17; -- ADC1 and ADC2 global interrupt ADC1_2_Interrupt : constant Interrupt_ID := 18; -- USB High Priority/CAN_TX interrupts USB_HP_CAN_TX_Interrupt : constant Interrupt_ID := 19; -- USB Low Priority/CAN_RX0 interrupts USB_LP_CAN_RX0_Interrupt : constant Interrupt_ID := 20; -- CAN_RX1 interrupt CAN_RX1_Interrupt : constant Interrupt_ID := 21; -- CAN_SCE interrupt CAN_SCE_Interrupt : constant Interrupt_ID := 22; -- EXTI Line5 to Line9 interrupts EXTI9_5_Interrupt : constant Interrupt_ID := 23; -- TIM1 Break/TIM15 global interruts TIM1_BRK_TIM15_Interrupt : constant Interrupt_ID := 24; -- TIM1 Update/TIM16 global interrupts TIM1_UP_TIM16_Interrupt : constant Interrupt_ID := 25; -- TIM1 trigger and commutation/TIM17 interrupts TIM1_TRG_COM_TIM17_Interrupt : constant Interrupt_ID := 26; -- TIM1 capture compare interrupt TIM1_CC_Interrupt : constant Interrupt_ID := 27; -- TIM2 global interrupt TIM2_Interrupt : constant Interrupt_ID := 28; -- Timer 3 global interrupt TIM3_Interrupt : constant Interrupt_ID := 29; -- I2C1 event interrupt and EXTI Line23 interrupt I2C1_EV_EXTI23_Interrupt : constant Interrupt_ID := 31; -- I2C1 error interrupt I2C1_ER_Interrupt : constant Interrupt_ID := 32; -- SPI1 global interrupt SPI1_Interrupt : constant Interrupt_ID := 35; -- USART1 global interrupt and EXTI Line 25 interrupt USART1_EXTI25_Interrupt : constant Interrupt_ID := 37; -- USART2 global interrupt and EXTI Line 26 interrupt USART2_EXTI26_Interrupt : constant Interrupt_ID := 38; -- USART3 global interrupt and EXTI Line 28 interrupt USART3_EXTI28_Interrupt : constant Interrupt_ID := 39; -- EXTI Line15 to Line10 interrupts EXTI15_10_Interrupt : constant Interrupt_ID := 40; -- RTC alarm interrupt RTC_Alarm_Interrupt : constant Interrupt_ID := 41; -- TIM6 global and DAC12 underrun interrupts TIM6_DAC1_Interrupt : constant Interrupt_ID := 54; -- TIM7 global interrupt TIM7_DAC2_Interrupt : constant Interrupt_ID := 55; -- HRTIM1 master timer interrupt HRTIM1_MST_Interrupt : constant Interrupt_ID := 67; -- HRTIM1 timer A interrupt HRTIM1_TIMA_Interrupt : constant Interrupt_ID := 68; -- HRTIM1 timer B interrupt HRTIM_TIMB_Interrupt : constant Interrupt_ID := 69; -- HRTIM1 timer C interrupt HRTIM1_TIMC_Interrupt : constant Interrupt_ID := 70; -- HRTIM1 timer D interrupt HRTIM1_TIMD_Interrupt : constant Interrupt_ID := 71; -- HRTIM1 timer E interrupt HRTIM_TIME_Interrupt : constant Interrupt_ID := 72; -- HRTIM1 fault interrupt HRTIM1_FLT_Interrupt : constant Interrupt_ID := 73; -- FPU global interrupt FPU_Interrupt : constant Interrupt_ID := 81; end Ada.Interrupts.Names;
with AAA.Strings; with GNAT.Strings; with GNAT.Command_Line; private with Ada.Strings.Unbounded; private with Ada.Containers.Vectors; package CLIC.Subcommand is -- This root package defines the interface types to be used in the -- Subcommand. See CLIC.Subcommand.Instance to create the parser/executor. type Switches_Configuration is limited private; -- This is a wrapper around GNAT.Command_Line.Command_Line_Configuration -- to provide extra features such as duplicate switch detection and custom -- usage format. The "Define_Switch" procedure below work exactly like the -- GNAT.Command_Line ones. procedure Define_Switch (Config : in out Switches_Configuration; Switch : String := ""; Long_Switch : String := ""; Help : String := ""; Section : String := ""; Argument : String := "ARG"); procedure Define_Switch (Config : in out Switches_Configuration; Output : access Boolean; Switch : String := ""; Long_Switch : String := ""; Help : String := ""; Section : String := ""; Value : Boolean := True); procedure Define_Switch (Config : in out Switches_Configuration; Output : access Integer; Switch : String := ""; Long_Switch : String := ""; Help : String := ""; Section : String := ""; Initial : Integer := 0; Default : Integer := 1; Argument : String := "ARG"); procedure Define_Switch (Config : in out Switches_Configuration; Output : access GNAT.Strings.String_Access; Switch : String := ""; Long_Switch : String := ""; Help : String := ""; Section : String := ""; Argument : String := "ARG"); procedure Define_Switch (Config : in out Switches_Configuration; Callback : not null GNAT.Command_Line.Value_Callback; Switch : String := ""; Long_Switch : String := ""; Help : String := ""; Section : String := ""; Argument : String := "ARG"); subtype Identifier is String with Predicate => (for all C of Identifier => C in 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '-' | '.' | '_'); ------------- -- Command -- ------------- type Command is limited interface; -- This type encapsulates configuration and execution of a specific -- command. It also has help-related subprograms. type Command_Access is access all Command'Class; function Name (Cmd : Command) return Identifier is abstract; -- Commands must override this procedure to provide the sub-command name. -- This name is used to identify the sub-command in usage and command line. -- E.g. "my_app <name>" will exectute the <name> command. procedure Execute (Cmd : in out Command; Args : AAA.Strings.Vector) is abstract; -- Commands must override this procedure to provide the command -- functionality. function Long_Description (Cmd : Command) return AAA.Strings.Vector is abstract; -- Return a detailed description of the command. Each string in the vector -- is a paragraph that will be reformatted into appropriate length lines. procedure Setup_Switches (Cmd : in out Command; Config : in out Switches_Configuration) is null; -- Gets called once the command has been identified, but before the call to -- Execute. Config must be set up with the switches used by the command. function Short_Description (Cmd : Command) return String is abstract; -- One-liner displayed in the list of commands that alr understands that -- gets shown when no command or unknown command is given. Also shown as -- SUMMARY in the help of a specific command. function Usage_Custom_Parameters (Cmd : Command) return String is abstract; -- The part after "<main> [global options] command [command options] " that -- gets shown in USAGE in the command help summary. That is, it is the -- specific command-line part that is not managed via Gnat.Command_Line ----------------- -- Help_Topic -- ----------------- type Help_Topic is limited interface; -- This type encapsulate the content of an "help topic", i.e. a piece of -- documentation that can displayed from the command line. type Help_Topic_Access is access all Help_Topic'Class; function Name (This : Help_Topic) return Identifier is abstract; -- This name is used to identify the topic in usage and command line. -- E.g. "my_app help <name>" will display the content of the <name> topic. function Title (This : Help_Topic) return String is abstract; -- Descriptive title for the topic content. Unlike the Name, the Title can -- containt whitespaces. function Content (This : Help_Topic) return AAA.Strings.Vector is abstract; -- Return the content of the help topic. Each string in the vector is a -- paragraph that will be reformatted into appropriate length lines. ----------- -- Utils -- ----------- function No_TTY (Str : String) return String is (Str); -- Use this function for the TTY_* generic parameters of -- CLIC.Subcommand.Instance if you don't want or need TTY formating. private type Switch_Info is record Switch : Ada.Strings.Unbounded.Unbounded_String; Long_Switch : Ada.Strings.Unbounded.Unbounded_String; Help : Ada.Strings.Unbounded.Unbounded_String; Argument : Ada.Strings.Unbounded.Unbounded_String; end record; -- Used internaly to store informations about the switches package Switch_Info_Vectors is new Ada.Containers.Vectors (Natural, Switch_Info); procedure Add (Vect : in out Switch_Info_Vectors.Vector; Switch, Long_Switch, Help, Argument : String); type Switches_Configuration is limited record GNAT_Cfg : GNAT.Command_Line.Command_Line_Configuration; -- Still use GNAT.Command_Line to do the actual parsing Info : Switch_Info_Vectors.Vector; end record; function Verify_No_Duplicates (A, B : Switches_Configuration) return Boolean; -- Returns True if there are no duplicates. -- Check that no switch is given twice in Config. This is used to ensure -- that command switches are not stepping on global switches, which would -- lead to some undefined behavior. This manual check is necessary because -- the GNAT library does not perform it. end CLIC.Subcommand;
package body myarray is -- Vector addition function "+" (Left : in Vector; Right : in Vector) return Vector is Result : Vector (Left'Range) := Left; begin for I in Result'Range loop Result (I) := Result (I) + Right (I); end loop; return Result; end "+"; -- Matrix addition function "+" (Left : in Matrix; Right : in Matrix) return Matrix is Result : Matrix (Left'Range (1), Left'Range (2)) := Left; begin for Row in Result'Range (1) loop Loop_Column: for Column in Result'Range (2) loop Result (Row, Column) := Result (Row, Column) + Right (Row, Column); end loop Loop_Column; end loop; return Result; end "+"; end myarray;
-- { dg-do run } with Text_IO; use Text_IO; procedure Named_Test is type Base is tagged limited record Flag : boolean; Value : integer; end record; -- function Build (X : Integer; Y : Integer) return Base is begin return Result : Base do Result.Flag := (X = Y); Result.Value := X * Y; end return; end; -- type Table is array (1..1) of Base; It : Table := (1 => Build ( Y => 17, X => 11)); begin if It (1).Flag or else It (1).Value /= 187 then raise Program_Error; end if; end;
-------------------------------------------------------------------------------- -- Copyright (C) 2020 by Heisenbug Ltd. (gh+owm@heisenbug.eu) -- -- This work is free. You can redistribute it and/or modify it under the -- terms of the Do What The Fuck You Want To Public License, Version 2, -- as published by Sam Hocevar. See the LICENSE file for more details. -------------------------------------------------------------------------------- pragma License (Unrestricted); package body Open_Weather_Map.API.Query is My_Debug : constant not null GNATCOLL.Traces.Trace_Handle := GNATCOLL.Traces.Create (Unit_Name => "OWM.API.QUERY"); ----------------------------------------------------------------------------- -- Initialize ----------------------------------------------------------------------------- procedure Initialize (Self : out T) is begin My_Debug.all.Trace (Message => "Initialize"); Self.Last_Query := Ada.Real_Time.Time_First; end Initialize; ----------------------------------------------------------------------------- -- Set_Last_Query ----------------------------------------------------------------------------- procedure Set_Last_Query (Self : in out T; Value : in Ada.Real_Time.Time) is begin My_Debug.all.Trace (Message => "Set_Last_Query"); Self.Last_Query := Value; end Set_Last_Query; end Open_Weather_Map.API.Query;
-- Lua.Lib -- Supporting the Lua standard libraries -- Copyright (c) 2015, James Humphry - see LICENSE for terms with Interfaces; use Interfaces; with Interfaces.C; with Interfaces.C.Strings; use Interfaces.C.Strings; with Ada.Strings, Ada.Strings.Fixed; with Lua.Internal, Lua.AuxInternal, Lua.LibInternal; use Lua.LibInternal; package body Lua.Libs is subtype Lib_Name is String(1..9); LibNames : constant array (Lua_Standard_Library) of Lib_Name := ( Base_Lib => " ", Package_Lib => "package ", Coroutine_Lib => "coroutine", String_Lib => "string ", UTF8_Lib => "utf8 ", Table_Lib => "table ", Math_Lib => "math ", IO_Lib => "io ", OS_Lib => "os ", Debug_Lib => "debug ", Bit32_Lib => "bit32 " ); LibFunctions : constant array (Lua_Standard_Library) of Lua.Internal.lua_CFunction := ( Base_Lib => luaopen_base'Access, Package_Lib => luaopen_package'Access, Coroutine_Lib => luaopen_coroutine'Access, String_Lib => luaopen_string'Access, UTF8_Lib => luaopen_utf8'Access, Table_Lib => luaopen_table'Access, Math_Lib => luaopen_math'Access, IO_Lib => luaopen_io'Access, OS_Lib => luaopen_os'Access, Debug_Lib => luaopen_debug'Access, Bit32_Lib => luaopen_bit32'Access ); procedure OpenLibs (L : in Lua_State) is begin LibInternal.luaL_openlibs(L.L); end OpenLibs; procedure Require_Standard_Library (L : in Lua_State; Library : in Lua_Standard_Library; Set_Global : in Boolean := True) is glb : constant C.int := C.int((if Set_Global then 1 else 0)); C_libname : C.Strings.chars_ptr := C.Strings.New_String(Ada.Strings.Fixed.Trim(LibNames(Library), Ada.Strings.Right)); begin Lua.AuxInternal.luaL_requiref(L.L, C_libname, LibFunctions(Library), glb); C.Strings.Free(C_libname); end Require_Standard_Library; procedure Add_Yield_Function (L : in Lua_State) is Func_Name : C.Strings.chars_ptr := C.Strings.New_String("yield"); begin Internal.lua_pushcclosure(L.L, Yield_CFunction'Access, 0); Internal.lua_setglobal(L.L, Func_Name); C.Strings.Free(Func_Name); end Add_Yield_Function; function Yield_CFunction (L : System.Address) return Interfaces.C.int is begin return Internal.lua_yieldk(L, Internal.lua_gettop(L), 0, null); end Yield_CFunction; end Lua.Libs;
------------------------------------------------------------------------------ -- Copyright (c) 2016, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ package body Natools.Smaz_Generic is use type Ada.Streams.Stream_Element_Offset; procedure Find_Entry (Dict : in Dictionary; Template : in String; Code : out Dictionary_Code; Length : out Natural); -- Try to find the longest entry in Dict that is a prefix of Template, -- setting Length to 0 when no such entry exists. function Verbatim_Size (Dict : in Dictionary; Length : in Positive) return Ada.Streams.Stream_Element_Count is (Verbatim_Size (Length, Dict.Last_Code, Dict.Variable_Length_Verbatim)); -- Wrapper around the formal Verbatim_Size ------------------------------ -- Local Helper Subprograms -- ------------------------------ procedure Find_Entry (Dict : in Dictionary; Template : in String; Code : out Dictionary_Code; Length : out Natural) is N : Natural; Is_Valid : Boolean; begin Length := 0; for Last in reverse Template'Range loop Is_Valid := False; N := Dict.Hash (Template (Template'First .. Last)); To_Code : begin Code := Dictionary_Code'Val (N); if Is_Valid_Code (Dict, Code) then Is_Valid := True; end if; exception when Constraint_Error => null; end To_Code; if Is_Valid and then Template (Template'First .. Last) = Dict.Values (Code_First (Dict.Offsets, Code, Dict.Values'First) .. Code_Last (Dict.Offsets, Code, Dict.Values'Last)) then Length := 1 + Last - Template'First; return; end if; end loop; end Find_Entry; ---------------------- -- Public Interface -- ---------------------- function Compressed_Upper_Bound (Dict : in Dictionary; Input : in String) return Ada.Streams.Stream_Element_Count is begin return Verbatim_Size (Input'Length, Dict.Last_Code, Dict.Variable_Length_Verbatim); end Compressed_Upper_Bound; procedure Compress (Dict : in Dictionary; Input : in String; Output_Buffer : out Ada.Streams.Stream_Element_Array; Output_Last : out Ada.Streams.Stream_Element_Offset) is procedure Find_Current_Entry; Input_Index : Positive := Input'First; Length : Natural; Code : Dictionary_Code; Output_Index : Ada.Streams.Stream_Element_Offset; procedure Find_Current_Entry is begin Find_Entry (Dict, Input (Input_Index .. Natural'Min (Input_Index + Dict.Max_Word_Length - 1, Input'Last)), Code, Length); end Find_Current_Entry; Previous_Verbatim_Beginning : Natural := 0; Previous_Verbatim_Index : Ada.Streams.Stream_Element_Offset := 0; begin Output_Index := Output_Buffer'First; Find_Current_Entry; Main_Loop : while Input_Index in Input'Range loop Data_In_Dict : while Length > 0 loop Write_Code (Output_Buffer, Output_Index, Code); Input_Index := Input_Index + Length; exit Main_Loop when Input_Index not in Input'Range; Find_Current_Entry; end loop Data_In_Dict; Verbatim_Block : declare Beginning : Positive := Input_Index; Verbatim_Length : Natural; begin Verbatim_Scan : while Length = 0 and Input_Index in Input'Range loop Input_Index := Input_Index + 1; Find_Current_Entry; end loop Verbatim_Scan; Verbatim_Length := Input_Index - Beginning; if Previous_Verbatim_Beginning > 0 and then Output_Index + Verbatim_Size (Dict, Verbatim_Length) >= Previous_Verbatim_Index + Verbatim_Size (Dict, Input_Index - Previous_Verbatim_Beginning) then Beginning := Previous_Verbatim_Beginning; Output_Index := Previous_Verbatim_Index; Verbatim_Length := Input_Index - Beginning; else Previous_Verbatim_Beginning := Beginning; Previous_Verbatim_Index := Output_Index; end if; Write_Verbatim (Output_Buffer, Output_Index, Input (Beginning .. Input_Index - 1), Dict.Last_Code, Dict.Variable_Length_Verbatim); end Verbatim_Block; end loop Main_Loop; Output_Last := Output_Index - 1; end Compress; function Compress (Dict : in Dictionary; Input : in String) return Ada.Streams.Stream_Element_Array is Result : Ada.Streams.Stream_Element_Array (1 .. Compressed_Upper_Bound (Dict, Input)); Last : Ada.Streams.Stream_Element_Offset; begin Compress (Dict, Input, Result, Last); return Result (Result'First .. Last); end Compress; function Decompressed_Length (Dict : in Dictionary; Input : in Ada.Streams.Stream_Element_Array) return Natural is Result : Natural := 0; Input_Index : Ada.Streams.Stream_Element_Offset := Input'First; Code : Dictionary_Code; Verbatim_Length : Natural; begin while Input_Index in Input'Range loop Read_Code (Input, Input_Index, Code, Verbatim_Length, Dict.Last_Code, Dict.Variable_Length_Verbatim); if Verbatim_Length > 0 then Skip_Verbatim (Input, Input_Index, Verbatim_Length); Result := Result + Verbatim_Length; else exit when not Is_Valid_Code (Dict, Code); Result := Result + Dict_Entry_Length (Dict, Code); end if; end loop; return Result; end Decompressed_Length; procedure Decompress (Dict : in Dictionary; Input : in Ada.Streams.Stream_Element_Array; Output_Buffer : out String; Output_Last : out Natural) is Input_Index : Ada.Streams.Stream_Element_Offset := Input'First; Code : Dictionary_Code; Verbatim_Length : Natural; begin Output_Last := Output_Buffer'First - 1; while Input_Index in Input'Range loop Read_Code (Input, Input_Index, Code, Verbatim_Length, Dict.Last_Code, Dict.Variable_Length_Verbatim); if Verbatim_Length > 0 then Read_Verbatim (Input, Input_Index, Output_Buffer (Output_Last + 1 .. Output_Last + Verbatim_Length)); Output_Last := Output_Last + Verbatim_Length; else exit when not Is_Valid_Code (Dict, Code); declare Decoded : constant String := Dict_Entry (Dict, Code); begin Output_Buffer (Output_Last + 1 .. Output_Last + Decoded'Length) := Decoded; Output_Last := Output_Last + Decoded'Length; end; end if; end loop; end Decompress; function Decompress (Dict : in Dictionary; Input : in Ada.Streams.Stream_Element_Array) return String is Result : String (1 .. Decompressed_Length (Dict, Input)); Last : Natural; begin Decompress (Dict, Input, Result, Last); pragma Assert (Last = Result'Last); return Result; end Decompress; end Natools.Smaz_Generic;
----------------------------------------------------------------------- -- ado-connections -- Database connections -- Copyright (C) 2010, 2011, 2012, 2013, 2015, 2016, 2017, 2018, 2019 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Util.Log.Loggers; with Util.Systems.DLLs; with System; with Ada.Exceptions; package body ADO.Connections is Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("ADO.Connections"); type Driver_Array_Access is array (Driver_Index) of Driver_Access; Driver_List : Driver_Array_Access; -- Load the database driver. procedure Load_Driver (Name : in String); -- ------------------------------ -- Get the driver index that corresponds to the driver for this database connection string. -- ------------------------------ function Get_Driver (Config : in Configuration) return Driver_Index is Name : constant String := Config.Get_Driver; Driver : constant Driver_Access := Get_Driver (Name); begin if Driver = null then raise ADO.Configs.Connection_Error with "Database driver '" & Name & "' not found"; else return Driver.Get_Driver_Index; end if; end Get_Driver; -- ------------------------------ -- Create a new connection using the configuration parameters. -- ------------------------------ procedure Create_Connection (Config : in Configuration'Class; Result : in out Ref.Ref'Class) is Driver : Driver_Access; Log_URI : constant String := Config.Get_Log_URI; begin Driver := Get_Driver (Config.Get_Driver); if Driver = null then Log.Error ("No driver found for connection {0}", Log_URI); raise ADO.Configs.Connection_Error with "Data source is not initialized: driver '" & Config.Get_Driver & "' not found"; end if; Driver.Create_Connection (Config, Result); Log.Info ("Created connection to '{0}' -> {1}", Log_URI, Result.Value.Ident); exception when others => Log.Info ("Failed to create connection to '{0}'", Log_URI); raise; end Create_Connection; -- ------------------------------ -- Get the database driver index. -- ------------------------------ function Get_Driver_Index (Database : in Database_Connection) return Driver_Index is Driver : constant Driver_Access := Database_Connection'Class (Database).Get_Driver; begin return Driver.Get_Driver_Index; end Get_Driver_Index; -- ------------------------------ -- Get the driver unique index. -- ------------------------------ function Get_Driver_Index (D : in Driver) return Driver_Index is begin return D.Index; end Get_Driver_Index; -- ------------------------------ -- Get the driver name. -- ------------------------------ function Get_Driver_Name (D : in Driver) return String is begin return D.Name.all; end Get_Driver_Name; -- ------------------------------ -- Register a database driver. -- ------------------------------ procedure Register (Driver : in Driver_Access) is begin Log.Info ("Register driver {0}", Driver.Name.all); for I in Driver_List'Range loop if Driver_List (I) = Driver then return; end if; if Driver_List (I) = null then Driver_List (I) := Driver; Driver.Index := I; return; end if; end loop; Log.Error ("The ADO driver table is full: increase ADO.Configs.MAX_DRIVER"); end Register; -- ------------------------------ -- Load the database driver. -- ------------------------------ procedure Load_Driver (Name : in String) is Lib : constant String := "libado_" & Name & Util.Systems.DLLs.Extension; Symbol : constant String := "ado__connections__" & Name & "__initialize"; Handle : Util.Systems.DLLs.Handle; Addr : System.Address; begin if not ADO.Configs.Is_On (ADO.Configs.DYNAMIC_DRIVER_LOAD) then Log.Warn ("Dynamic loading of driver '{0}' is disabled", Name); return; end if; Log.Debug ("Loading driver '{0}' from {1}", Name, Lib); Handle := Util.Systems.DLLs.Load (Lib); Addr := Util.Systems.DLLs.Get_Symbol (Handle, Symbol); declare procedure Init; pragma Import (C, Init); for Init'Address use Addr; begin Log.Info ("Initialising driver {0}", Lib); Init; end; exception when Util.Systems.DLLs.Not_Found => Log.Error ("Driver for {0} was loaded but does not define the initialization symbol", Name); when E : Util.Systems.DLLs.Load_Error => Log.Error ("Driver for {0} was not found: {1}", Name, Ada.Exceptions.Exception_Message (E)); end Load_Driver; -- ------------------------------ -- Get a database driver given its name. -- ------------------------------ function Get_Driver (Name : in String) return Driver_Access is begin Log.Debug ("Get driver {0}", Name); if Name'Length = 0 then return null; end if; for Retry in 0 .. 1 loop if Retry = 1 then Load_Driver (Name); end if; for D of Driver_List loop exit when D = null; if Name = D.Name.all then return D; end if; end loop; end loop; return null; end Get_Driver; end ADO.Connections;
-- This spec has been automatically generated from STM32F103.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with System; package STM32_SVD.ETHERNET is pragma Preelaborate; --------------- -- Registers -- --------------- subtype DMABMR_SR_Field is STM32_SVD.Bit; subtype DMABMR_DA_Field is STM32_SVD.Bit; subtype DMABMR_DSL_Field is STM32_SVD.UInt5; subtype DMABMR_PBL_Field is STM32_SVD.UInt6; subtype DMABMR_RTPR_Field is STM32_SVD.UInt2; subtype DMABMR_FB_Field is STM32_SVD.Bit; subtype DMABMR_RDP_Field is STM32_SVD.UInt6; subtype DMABMR_USP_Field is STM32_SVD.Bit; subtype DMABMR_FPM_Field is STM32_SVD.Bit; subtype DMABMR_AAB_Field is STM32_SVD.Bit; -- Ethernet DMA bus mode register type DMABMR_Register is record -- Software reset SR : DMABMR_SR_Field := 16#1#; -- DMA Arbitration DA : DMABMR_DA_Field := 16#0#; -- Descriptor skip length DSL : DMABMR_DSL_Field := 16#0#; -- unspecified Reserved_7_7 : STM32_SVD.Bit := 16#0#; -- Programmable burst length PBL : DMABMR_PBL_Field := 16#1#; -- Rx Tx priority ratio RTPR : DMABMR_RTPR_Field := 16#0#; -- Fixed burst FB : DMABMR_FB_Field := 16#0#; -- Rx DMA PBL RDP : DMABMR_RDP_Field := 16#1#; -- Use separate PBL USP : DMABMR_USP_Field := 16#0#; -- 4xPBL mode FPM : DMABMR_FPM_Field := 16#0#; -- Address-aligned beats AAB : DMABMR_AAB_Field := 16#0#; -- unspecified Reserved_26_31 : STM32_SVD.UInt6 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DMABMR_Register use record SR at 0 range 0 .. 0; DA at 0 range 1 .. 1; DSL at 0 range 2 .. 6; Reserved_7_7 at 0 range 7 .. 7; PBL at 0 range 8 .. 13; RTPR at 0 range 14 .. 15; FB at 0 range 16 .. 16; RDP at 0 range 17 .. 22; USP at 0 range 23 .. 23; FPM at 0 range 24 .. 24; AAB at 0 range 25 .. 25; Reserved_26_31 at 0 range 26 .. 31; end record; subtype DMASR_TS_Field is STM32_SVD.Bit; subtype DMASR_TPSS_Field is STM32_SVD.Bit; subtype DMASR_TBUS_Field is STM32_SVD.Bit; subtype DMASR_TJTS_Field is STM32_SVD.Bit; subtype DMASR_ROS_Field is STM32_SVD.Bit; subtype DMASR_TUS_Field is STM32_SVD.Bit; subtype DMASR_RS_Field is STM32_SVD.Bit; subtype DMASR_RBUS_Field is STM32_SVD.Bit; subtype DMASR_RPSS_Field is STM32_SVD.Bit; subtype DMASR_PWTS_Field is STM32_SVD.Bit; subtype DMASR_ETS_Field is STM32_SVD.Bit; subtype DMASR_FBES_Field is STM32_SVD.Bit; subtype DMASR_ERS_Field is STM32_SVD.Bit; subtype DMASR_AIS_Field is STM32_SVD.Bit; subtype DMASR_NIS_Field is STM32_SVD.Bit; subtype DMASR_RPS_Field is STM32_SVD.UInt3; subtype DMASR_TPS_Field is STM32_SVD.UInt3; subtype DMASR_EBS_Field is STM32_SVD.UInt3; subtype DMASR_MMCS_Field is STM32_SVD.Bit; subtype DMASR_PMTS_Field is STM32_SVD.Bit; subtype DMASR_TSTS_Field is STM32_SVD.Bit; -- Ethernet DMA status register type DMASR_Register is record -- Transmit status TS : DMASR_TS_Field := 16#0#; -- Transmit process stopped status TPSS : DMASR_TPSS_Field := 16#0#; -- Transmit buffer unavailable status TBUS : DMASR_TBUS_Field := 16#0#; -- Transmit jabber timeout status TJTS : DMASR_TJTS_Field := 16#0#; -- Receive overflow status ROS : DMASR_ROS_Field := 16#0#; -- Transmit underflow status TUS : DMASR_TUS_Field := 16#0#; -- Receive status RS : DMASR_RS_Field := 16#0#; -- Receive buffer unavailable status RBUS : DMASR_RBUS_Field := 16#0#; -- Receive process stopped status RPSS : DMASR_RPSS_Field := 16#0#; -- Receive watchdog timeout status PWTS : DMASR_PWTS_Field := 16#0#; -- Early transmit status ETS : DMASR_ETS_Field := 16#0#; -- unspecified Reserved_11_12 : STM32_SVD.UInt2 := 16#0#; -- Fatal bus error status FBES : DMASR_FBES_Field := 16#0#; -- Early receive status ERS : DMASR_ERS_Field := 16#0#; -- Abnormal interrupt summary AIS : DMASR_AIS_Field := 16#0#; -- Normal interrupt summary NIS : DMASR_NIS_Field := 16#0#; -- Read-only. Receive process state RPS : DMASR_RPS_Field := 16#0#; -- Read-only. Transmit process state TPS : DMASR_TPS_Field := 16#0#; -- Read-only. Error bits status EBS : DMASR_EBS_Field := 16#0#; -- unspecified Reserved_26_26 : STM32_SVD.Bit := 16#0#; -- Read-only. MMC status MMCS : DMASR_MMCS_Field := 16#0#; -- Read-only. PMT status PMTS : DMASR_PMTS_Field := 16#0#; -- Read-only. Time stamp trigger status TSTS : DMASR_TSTS_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 DMASR_Register use record TS at 0 range 0 .. 0; TPSS at 0 range 1 .. 1; TBUS at 0 range 2 .. 2; TJTS at 0 range 3 .. 3; ROS at 0 range 4 .. 4; TUS at 0 range 5 .. 5; RS at 0 range 6 .. 6; RBUS at 0 range 7 .. 7; RPSS at 0 range 8 .. 8; PWTS at 0 range 9 .. 9; ETS at 0 range 10 .. 10; Reserved_11_12 at 0 range 11 .. 12; FBES at 0 range 13 .. 13; ERS at 0 range 14 .. 14; AIS at 0 range 15 .. 15; NIS at 0 range 16 .. 16; RPS at 0 range 17 .. 19; TPS at 0 range 20 .. 22; EBS at 0 range 23 .. 25; Reserved_26_26 at 0 range 26 .. 26; MMCS at 0 range 27 .. 27; PMTS at 0 range 28 .. 28; TSTS at 0 range 29 .. 29; Reserved_30_31 at 0 range 30 .. 31; end record; subtype DMAOMR_SR_Field is STM32_SVD.Bit; subtype DMAOMR_OSF_Field is STM32_SVD.Bit; subtype DMAOMR_RTC_Field is STM32_SVD.UInt2; subtype DMAOMR_FUGF_Field is STM32_SVD.Bit; subtype DMAOMR_FEF_Field is STM32_SVD.Bit; subtype DMAOMR_ST_Field is STM32_SVD.Bit; subtype DMAOMR_TTC_Field is STM32_SVD.UInt3; subtype DMAOMR_FTF_Field is STM32_SVD.Bit; subtype DMAOMR_TSF_Field is STM32_SVD.Bit; subtype DMAOMR_DFRF_Field is STM32_SVD.Bit; subtype DMAOMR_RSF_Field is STM32_SVD.Bit; subtype DMAOMR_DTCEFD_Field is STM32_SVD.Bit; -- Ethernet DMA operation mode register type DMAOMR_Register is record -- unspecified Reserved_0_0 : STM32_SVD.Bit := 16#0#; -- SR SR : DMAOMR_SR_Field := 16#0#; -- OSF OSF : DMAOMR_OSF_Field := 16#0#; -- RTC RTC : DMAOMR_RTC_Field := 16#0#; -- unspecified Reserved_5_5 : STM32_SVD.Bit := 16#0#; -- FUGF FUGF : DMAOMR_FUGF_Field := 16#0#; -- FEF FEF : DMAOMR_FEF_Field := 16#0#; -- unspecified Reserved_8_12 : STM32_SVD.UInt5 := 16#0#; -- ST ST : DMAOMR_ST_Field := 16#0#; -- TTC TTC : DMAOMR_TTC_Field := 16#0#; -- unspecified Reserved_17_19 : STM32_SVD.UInt3 := 16#0#; -- FTF FTF : DMAOMR_FTF_Field := 16#0#; -- TSF TSF : DMAOMR_TSF_Field := 16#0#; -- unspecified Reserved_22_23 : STM32_SVD.UInt2 := 16#0#; -- DFRF DFRF : DMAOMR_DFRF_Field := 16#0#; -- RSF RSF : DMAOMR_RSF_Field := 16#0#; -- DTCEFD DTCEFD : DMAOMR_DTCEFD_Field := 16#0#; -- unspecified Reserved_27_31 : STM32_SVD.UInt5 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DMAOMR_Register use record Reserved_0_0 at 0 range 0 .. 0; SR at 0 range 1 .. 1; OSF at 0 range 2 .. 2; RTC at 0 range 3 .. 4; Reserved_5_5 at 0 range 5 .. 5; FUGF at 0 range 6 .. 6; FEF at 0 range 7 .. 7; Reserved_8_12 at 0 range 8 .. 12; ST at 0 range 13 .. 13; TTC at 0 range 14 .. 16; Reserved_17_19 at 0 range 17 .. 19; FTF at 0 range 20 .. 20; TSF at 0 range 21 .. 21; Reserved_22_23 at 0 range 22 .. 23; DFRF at 0 range 24 .. 24; RSF at 0 range 25 .. 25; DTCEFD at 0 range 26 .. 26; Reserved_27_31 at 0 range 27 .. 31; end record; subtype DMAIER_TIE_Field is STM32_SVD.Bit; subtype DMAIER_TPSIE_Field is STM32_SVD.Bit; subtype DMAIER_TBUIE_Field is STM32_SVD.Bit; subtype DMAIER_TJTIE_Field is STM32_SVD.Bit; subtype DMAIER_ROIE_Field is STM32_SVD.Bit; subtype DMAIER_TUIE_Field is STM32_SVD.Bit; subtype DMAIER_RIE_Field is STM32_SVD.Bit; subtype DMAIER_RBUIE_Field is STM32_SVD.Bit; subtype DMAIER_RPSIE_Field is STM32_SVD.Bit; subtype DMAIER_RWTIE_Field is STM32_SVD.Bit; subtype DMAIER_ETIE_Field is STM32_SVD.Bit; subtype DMAIER_FBEIE_Field is STM32_SVD.Bit; subtype DMAIER_ERIE_Field is STM32_SVD.Bit; subtype DMAIER_AISE_Field is STM32_SVD.Bit; subtype DMAIER_NISE_Field is STM32_SVD.Bit; -- Ethernet DMA interrupt enable register type DMAIER_Register is record -- Transmit interrupt enable TIE : DMAIER_TIE_Field := 16#0#; -- Transmit process stopped interrupt enable TPSIE : DMAIER_TPSIE_Field := 16#0#; -- Transmit buffer unavailable interrupt enable TBUIE : DMAIER_TBUIE_Field := 16#0#; -- Transmit jabber timeout interrupt enable TJTIE : DMAIER_TJTIE_Field := 16#0#; -- Overflow interrupt enable ROIE : DMAIER_ROIE_Field := 16#0#; -- Underflow interrupt enable TUIE : DMAIER_TUIE_Field := 16#0#; -- Receive interrupt enable RIE : DMAIER_RIE_Field := 16#0#; -- Receive buffer unavailable interrupt enable RBUIE : DMAIER_RBUIE_Field := 16#0#; -- Receive process stopped interrupt enable RPSIE : DMAIER_RPSIE_Field := 16#0#; -- receive watchdog timeout interrupt enable RWTIE : DMAIER_RWTIE_Field := 16#0#; -- Early transmit interrupt enable ETIE : DMAIER_ETIE_Field := 16#0#; -- unspecified Reserved_11_12 : STM32_SVD.UInt2 := 16#0#; -- Fatal bus error interrupt enable FBEIE : DMAIER_FBEIE_Field := 16#0#; -- Early receive interrupt enable ERIE : DMAIER_ERIE_Field := 16#0#; -- Abnormal interrupt summary enable AISE : DMAIER_AISE_Field := 16#0#; -- Normal interrupt summary enable NISE : DMAIER_NISE_Field := 16#0#; -- unspecified Reserved_17_31 : STM32_SVD.UInt15 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DMAIER_Register use record TIE at 0 range 0 .. 0; TPSIE at 0 range 1 .. 1; TBUIE at 0 range 2 .. 2; TJTIE at 0 range 3 .. 3; ROIE at 0 range 4 .. 4; TUIE at 0 range 5 .. 5; RIE at 0 range 6 .. 6; RBUIE at 0 range 7 .. 7; RPSIE at 0 range 8 .. 8; RWTIE at 0 range 9 .. 9; ETIE at 0 range 10 .. 10; Reserved_11_12 at 0 range 11 .. 12; FBEIE at 0 range 13 .. 13; ERIE at 0 range 14 .. 14; AISE at 0 range 15 .. 15; NISE at 0 range 16 .. 16; Reserved_17_31 at 0 range 17 .. 31; end record; subtype DMAMFBOCR_MFC_Field is STM32_SVD.UInt16; subtype DMAMFBOCR_OMFC_Field is STM32_SVD.Bit; subtype DMAMFBOCR_MFA_Field is STM32_SVD.UInt11; subtype DMAMFBOCR_OFOC_Field is STM32_SVD.Bit; -- Ethernet DMA missed frame and buffer overflow counter register type DMAMFBOCR_Register is record -- Read-only. Missed frames by the controller MFC : DMAMFBOCR_MFC_Field; -- Read-only. Overflow bit for missed frame counter OMFC : DMAMFBOCR_OMFC_Field; -- Read-only. Missed frames by the application MFA : DMAMFBOCR_MFA_Field; -- Read-only. Overflow bit for FIFO overflow counter OFOC : DMAMFBOCR_OFOC_Field; -- unspecified Reserved_29_31 : STM32_SVD.UInt3; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DMAMFBOCR_Register use record MFC at 0 range 0 .. 15; OMFC at 0 range 16 .. 16; MFA at 0 range 17 .. 27; OFOC at 0 range 28 .. 28; Reserved_29_31 at 0 range 29 .. 31; end record; subtype MACCR_RE_Field is STM32_SVD.Bit; subtype MACCR_TE_Field is STM32_SVD.Bit; subtype MACCR_DC_Field is STM32_SVD.Bit; subtype MACCR_BL_Field is STM32_SVD.UInt2; subtype MACCR_APCS_Field is STM32_SVD.Bit; subtype MACCR_RD_Field is STM32_SVD.Bit; subtype MACCR_IPCO_Field is STM32_SVD.Bit; subtype MACCR_DM_Field is STM32_SVD.Bit; subtype MACCR_LM_Field is STM32_SVD.Bit; subtype MACCR_ROD_Field is STM32_SVD.Bit; subtype MACCR_FES_Field is STM32_SVD.Bit; subtype MACCR_CSD_Field is STM32_SVD.Bit; subtype MACCR_IFG_Field is STM32_SVD.UInt3; subtype MACCR_JD_Field is STM32_SVD.Bit; subtype MACCR_WD_Field is STM32_SVD.Bit; -- Ethernet MAC configuration register (ETH_MACCR) type MACCR_Register is record -- unspecified Reserved_0_1 : STM32_SVD.UInt2 := 16#0#; -- Receiver enable RE : MACCR_RE_Field := 16#0#; -- Transmitter enable TE : MACCR_TE_Field := 16#0#; -- Deferral check DC : MACCR_DC_Field := 16#0#; -- Back-off limit BL : MACCR_BL_Field := 16#0#; -- Automatic pad/CRC stripping APCS : MACCR_APCS_Field := 16#0#; -- unspecified Reserved_8_8 : STM32_SVD.Bit := 16#0#; -- Retry disable RD : MACCR_RD_Field := 16#0#; -- IPv4 checksum offload IPCO : MACCR_IPCO_Field := 16#0#; -- Duplex mode DM : MACCR_DM_Field := 16#0#; -- Loopback mode LM : MACCR_LM_Field := 16#0#; -- Receive own disable ROD : MACCR_ROD_Field := 16#0#; -- Fast Ethernet speed FES : MACCR_FES_Field := 16#0#; -- unspecified Reserved_15_15 : STM32_SVD.Bit := 16#1#; -- Carrier sense disable CSD : MACCR_CSD_Field := 16#0#; -- Interframe gap IFG : MACCR_IFG_Field := 16#0#; -- unspecified Reserved_20_21 : STM32_SVD.UInt2 := 16#0#; -- Jabber disable JD : MACCR_JD_Field := 16#0#; -- Watchdog disable WD : MACCR_WD_Field := 16#0#; -- unspecified Reserved_24_31 : STM32_SVD.Byte := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MACCR_Register use record Reserved_0_1 at 0 range 0 .. 1; RE at 0 range 2 .. 2; TE at 0 range 3 .. 3; DC at 0 range 4 .. 4; BL at 0 range 5 .. 6; APCS at 0 range 7 .. 7; Reserved_8_8 at 0 range 8 .. 8; RD at 0 range 9 .. 9; IPCO at 0 range 10 .. 10; DM at 0 range 11 .. 11; LM at 0 range 12 .. 12; ROD at 0 range 13 .. 13; FES at 0 range 14 .. 14; Reserved_15_15 at 0 range 15 .. 15; CSD at 0 range 16 .. 16; IFG at 0 range 17 .. 19; Reserved_20_21 at 0 range 20 .. 21; JD at 0 range 22 .. 22; WD at 0 range 23 .. 23; Reserved_24_31 at 0 range 24 .. 31; end record; subtype MACFFR_PM_Field is STM32_SVD.Bit; subtype MACFFR_HU_Field is STM32_SVD.Bit; subtype MACFFR_HM_Field is STM32_SVD.Bit; subtype MACFFR_DAIF_Field is STM32_SVD.Bit; subtype MACFFR_PAM_Field is STM32_SVD.Bit; subtype MACFFR_BFD_Field is STM32_SVD.Bit; subtype MACFFR_PCF_Field is STM32_SVD.UInt2; subtype MACFFR_SAIF_Field is STM32_SVD.Bit; subtype MACFFR_SAF_Field is STM32_SVD.Bit; subtype MACFFR_HPF_Field is STM32_SVD.Bit; subtype MACFFR_RA_Field is STM32_SVD.Bit; -- Ethernet MAC frame filter register (ETH_MACCFFR) type MACFFR_Register is record -- Promiscuous mode PM : MACFFR_PM_Field := 16#0#; -- Hash unicast HU : MACFFR_HU_Field := 16#0#; -- Hash multicast HM : MACFFR_HM_Field := 16#0#; -- Destination address inverse filtering DAIF : MACFFR_DAIF_Field := 16#0#; -- Pass all multicast PAM : MACFFR_PAM_Field := 16#0#; -- Broadcast frames disable BFD : MACFFR_BFD_Field := 16#0#; -- Pass control frames PCF : MACFFR_PCF_Field := 16#0#; -- Source address inverse filtering SAIF : MACFFR_SAIF_Field := 16#0#; -- Source address filter SAF : MACFFR_SAF_Field := 16#0#; -- Hash or perfect filter HPF : MACFFR_HPF_Field := 16#0#; -- unspecified Reserved_11_30 : STM32_SVD.UInt20 := 16#0#; -- Receive all RA : MACFFR_RA_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MACFFR_Register use record PM at 0 range 0 .. 0; HU at 0 range 1 .. 1; HM at 0 range 2 .. 2; DAIF at 0 range 3 .. 3; PAM at 0 range 4 .. 4; BFD at 0 range 5 .. 5; PCF at 0 range 6 .. 7; SAIF at 0 range 8 .. 8; SAF at 0 range 9 .. 9; HPF at 0 range 10 .. 10; Reserved_11_30 at 0 range 11 .. 30; RA at 0 range 31 .. 31; end record; subtype MACMIIAR_MB_Field is STM32_SVD.Bit; subtype MACMIIAR_MW_Field is STM32_SVD.Bit; subtype MACMIIAR_CR_Field is STM32_SVD.UInt3; subtype MACMIIAR_MR_Field is STM32_SVD.UInt5; subtype MACMIIAR_PA_Field is STM32_SVD.UInt5; -- Ethernet MAC MII address register (ETH_MACMIIAR) type MACMIIAR_Register is record -- MII busy MB : MACMIIAR_MB_Field := 16#0#; -- MII write MW : MACMIIAR_MW_Field := 16#0#; -- Clock range CR : MACMIIAR_CR_Field := 16#0#; -- unspecified Reserved_5_5 : STM32_SVD.Bit := 16#0#; -- MII register MR : MACMIIAR_MR_Field := 16#0#; -- PHY address PA : MACMIIAR_PA_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 MACMIIAR_Register use record MB at 0 range 0 .. 0; MW at 0 range 1 .. 1; CR at 0 range 2 .. 4; Reserved_5_5 at 0 range 5 .. 5; MR at 0 range 6 .. 10; PA at 0 range 11 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype MACMIIDR_MD_Field is STM32_SVD.UInt16; -- Ethernet MAC MII data register (ETH_MACMIIDR) type MACMIIDR_Register is record -- MII data MD : MACMIIDR_MD_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 MACMIIDR_Register use record MD at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype MACFCR_FCB_BPA_Field is STM32_SVD.Bit; subtype MACFCR_TFCE_Field is STM32_SVD.Bit; subtype MACFCR_RFCE_Field is STM32_SVD.Bit; subtype MACFCR_UPFD_Field is STM32_SVD.Bit; subtype MACFCR_PLT_Field is STM32_SVD.UInt2; subtype MACFCR_ZQPD_Field is STM32_SVD.Bit; subtype MACFCR_PT_Field is STM32_SVD.UInt16; -- Ethernet MAC flow control register (ETH_MACFCR) type MACFCR_Register is record -- Flow control busy/back pressure activate FCB_BPA : MACFCR_FCB_BPA_Field := 16#0#; -- Transmit flow control enable TFCE : MACFCR_TFCE_Field := 16#0#; -- Receive flow control enable RFCE : MACFCR_RFCE_Field := 16#0#; -- Unicast pause frame detect UPFD : MACFCR_UPFD_Field := 16#0#; -- Pause low threshold PLT : MACFCR_PLT_Field := 16#0#; -- unspecified Reserved_6_6 : STM32_SVD.Bit := 16#0#; -- Zero-quanta pause disable ZQPD : MACFCR_ZQPD_Field := 16#0#; -- unspecified Reserved_8_15 : STM32_SVD.Byte := 16#0#; -- Pass control frames PT : MACFCR_PT_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MACFCR_Register use record FCB_BPA at 0 range 0 .. 0; TFCE at 0 range 1 .. 1; RFCE at 0 range 2 .. 2; UPFD at 0 range 3 .. 3; PLT at 0 range 4 .. 5; Reserved_6_6 at 0 range 6 .. 6; ZQPD at 0 range 7 .. 7; Reserved_8_15 at 0 range 8 .. 15; PT at 0 range 16 .. 31; end record; subtype MACVLANTR_VLANTI_Field is STM32_SVD.UInt16; subtype MACVLANTR_VLANTC_Field is STM32_SVD.Bit; -- Ethernet MAC VLAN tag register (ETH_MACVLANTR) type MACVLANTR_Register is record -- VLAN tag identifier (for receive frames) VLANTI : MACVLANTR_VLANTI_Field := 16#0#; -- 12-bit VLAN tag comparison VLANTC : MACVLANTR_VLANTC_Field := 16#0#; -- unspecified Reserved_17_31 : STM32_SVD.UInt15 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MACVLANTR_Register use record VLANTI at 0 range 0 .. 15; VLANTC at 0 range 16 .. 16; Reserved_17_31 at 0 range 17 .. 31; end record; subtype MACPMTCSR_PD_Field is STM32_SVD.Bit; subtype MACPMTCSR_MPE_Field is STM32_SVD.Bit; subtype MACPMTCSR_WFE_Field is STM32_SVD.Bit; subtype MACPMTCSR_MPR_Field is STM32_SVD.Bit; subtype MACPMTCSR_WFR_Field is STM32_SVD.Bit; subtype MACPMTCSR_GU_Field is STM32_SVD.Bit; subtype MACPMTCSR_WFFRPR_Field is STM32_SVD.Bit; -- Ethernet MAC PMT control and status register (ETH_MACPMTCSR) type MACPMTCSR_Register is record -- Power down PD : MACPMTCSR_PD_Field := 16#0#; -- Magic Packet enable MPE : MACPMTCSR_MPE_Field := 16#0#; -- Wakeup frame enable WFE : MACPMTCSR_WFE_Field := 16#0#; -- unspecified Reserved_3_4 : STM32_SVD.UInt2 := 16#0#; -- Magic packet received MPR : MACPMTCSR_MPR_Field := 16#0#; -- Wakeup frame received WFR : MACPMTCSR_WFR_Field := 16#0#; -- unspecified Reserved_7_8 : STM32_SVD.UInt2 := 16#0#; -- Global unicast GU : MACPMTCSR_GU_Field := 16#0#; -- unspecified Reserved_10_30 : STM32_SVD.UInt21 := 16#0#; -- Wakeup frame filter register pointer reset WFFRPR : MACPMTCSR_WFFRPR_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MACPMTCSR_Register use record PD at 0 range 0 .. 0; MPE at 0 range 1 .. 1; WFE at 0 range 2 .. 2; Reserved_3_4 at 0 range 3 .. 4; MPR at 0 range 5 .. 5; WFR at 0 range 6 .. 6; Reserved_7_8 at 0 range 7 .. 8; GU at 0 range 9 .. 9; Reserved_10_30 at 0 range 10 .. 30; WFFRPR at 0 range 31 .. 31; end record; subtype MACSR_PMTS_Field is STM32_SVD.Bit; subtype MACSR_MMCS_Field is STM32_SVD.Bit; subtype MACSR_MMCRS_Field is STM32_SVD.Bit; subtype MACSR_MMCTS_Field is STM32_SVD.Bit; subtype MACSR_TSTS_Field is STM32_SVD.Bit; -- Ethernet MAC interrupt status register (ETH_MACSR) type MACSR_Register is record -- unspecified Reserved_0_2 : STM32_SVD.UInt3 := 16#0#; -- PMT status PMTS : MACSR_PMTS_Field := 16#0#; -- MMC status MMCS : MACSR_MMCS_Field := 16#0#; -- MMC receive status MMCRS : MACSR_MMCRS_Field := 16#0#; -- MMC transmit status MMCTS : MACSR_MMCTS_Field := 16#0#; -- unspecified Reserved_7_8 : STM32_SVD.UInt2 := 16#0#; -- Time stamp trigger status TSTS : MACSR_TSTS_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 MACSR_Register use record Reserved_0_2 at 0 range 0 .. 2; PMTS at 0 range 3 .. 3; MMCS at 0 range 4 .. 4; MMCRS at 0 range 5 .. 5; MMCTS at 0 range 6 .. 6; Reserved_7_8 at 0 range 7 .. 8; TSTS at 0 range 9 .. 9; Reserved_10_31 at 0 range 10 .. 31; end record; subtype MACIMR_PMTIM_Field is STM32_SVD.Bit; subtype MACIMR_TSTIM_Field is STM32_SVD.Bit; -- Ethernet MAC interrupt mask register (ETH_MACIMR) type MACIMR_Register is record -- unspecified Reserved_0_2 : STM32_SVD.UInt3 := 16#0#; -- PMT interrupt mask PMTIM : MACIMR_PMTIM_Field := 16#0#; -- unspecified Reserved_4_8 : STM32_SVD.UInt5 := 16#0#; -- Time stamp trigger interrupt mask TSTIM : MACIMR_TSTIM_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 MACIMR_Register use record Reserved_0_2 at 0 range 0 .. 2; PMTIM at 0 range 3 .. 3; Reserved_4_8 at 0 range 4 .. 8; TSTIM at 0 range 9 .. 9; Reserved_10_31 at 0 range 10 .. 31; end record; subtype MACA0HR_MACA0H_Field is STM32_SVD.UInt16; subtype MACA0HR_MO_Field is STM32_SVD.Bit; -- Ethernet MAC address 0 high register (ETH_MACA0HR) type MACA0HR_Register is record -- MAC address0 high MACA0H : MACA0HR_MACA0H_Field := 16#FFFF#; -- unspecified Reserved_16_30 : STM32_SVD.UInt15 := 16#10#; -- Read-only. Always 1 MO : MACA0HR_MO_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MACA0HR_Register use record MACA0H at 0 range 0 .. 15; Reserved_16_30 at 0 range 16 .. 30; MO at 0 range 31 .. 31; end record; subtype MACA1HR_MACA1H_Field is STM32_SVD.UInt16; subtype MACA1HR_MBC_Field is STM32_SVD.UInt6; subtype MACA1HR_SA_Field is STM32_SVD.Bit; subtype MACA1HR_AE_Field is STM32_SVD.Bit; -- Ethernet MAC address 1 high register (ETH_MACA1HR) type MACA1HR_Register is record -- MAC address1 high MACA1H : MACA1HR_MACA1H_Field := 16#FFFF#; -- unspecified Reserved_16_23 : STM32_SVD.Byte := 16#0#; -- Mask byte control MBC : MACA1HR_MBC_Field := 16#0#; -- Source address SA : MACA1HR_SA_Field := 16#0#; -- Address enable AE : MACA1HR_AE_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MACA1HR_Register use record MACA1H at 0 range 0 .. 15; Reserved_16_23 at 0 range 16 .. 23; MBC at 0 range 24 .. 29; SA at 0 range 30 .. 30; AE at 0 range 31 .. 31; end record; subtype MACA2HR_ETH_MACA2HR_Field is STM32_SVD.UInt16; subtype MACA2HR_MBC_Field is STM32_SVD.UInt6; subtype MACA2HR_SA_Field is STM32_SVD.Bit; subtype MACA2HR_AE_Field is STM32_SVD.Bit; -- Ethernet MAC address 2 high register (ETH_MACA2HR) type MACA2HR_Register is record -- Ethernet MAC address 2 high register ETH_MACA2HR : MACA2HR_ETH_MACA2HR_Field := 16#50#; -- unspecified Reserved_16_23 : STM32_SVD.Byte := 16#0#; -- Mask byte control MBC : MACA2HR_MBC_Field := 16#0#; -- Source address SA : MACA2HR_SA_Field := 16#0#; -- Address enable AE : MACA2HR_AE_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MACA2HR_Register use record ETH_MACA2HR at 0 range 0 .. 15; Reserved_16_23 at 0 range 16 .. 23; MBC at 0 range 24 .. 29; SA at 0 range 30 .. 30; AE at 0 range 31 .. 31; end record; subtype MACA2LR_MACA2L_Field is STM32_SVD.UInt31; -- Ethernet MAC address 2 low register type MACA2LR_Register is record -- MAC address2 low MACA2L : MACA2LR_MACA2L_Field := 16#7FFFFFFF#; -- unspecified Reserved_31_31 : STM32_SVD.Bit := 16#1#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MACA2LR_Register use record MACA2L at 0 range 0 .. 30; Reserved_31_31 at 0 range 31 .. 31; end record; subtype MACA3HR_MACA3H_Field is STM32_SVD.UInt16; subtype MACA3HR_MBC_Field is STM32_SVD.UInt6; subtype MACA3HR_SA_Field is STM32_SVD.Bit; subtype MACA3HR_AE_Field is STM32_SVD.Bit; -- Ethernet MAC address 3 high register (ETH_MACA3HR) type MACA3HR_Register is record -- MAC address3 high MACA3H : MACA3HR_MACA3H_Field := 16#FFFF#; -- unspecified Reserved_16_23 : STM32_SVD.Byte := 16#0#; -- Mask byte control MBC : MACA3HR_MBC_Field := 16#0#; -- Source address SA : MACA3HR_SA_Field := 16#0#; -- Address enable AE : MACA3HR_AE_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MACA3HR_Register use record MACA3H at 0 range 0 .. 15; Reserved_16_23 at 0 range 16 .. 23; MBC at 0 range 24 .. 29; SA at 0 range 30 .. 30; AE at 0 range 31 .. 31; end record; subtype MMCCR_CR_Field is STM32_SVD.Bit; subtype MMCCR_CSR_Field is STM32_SVD.Bit; subtype MMCCR_ROR_Field is STM32_SVD.Bit; subtype MMCCR_MCF_Field is STM32_SVD.Bit; -- Ethernet MMC control register (ETH_MMCCR) type MMCCR_Register is record -- Counter reset CR : MMCCR_CR_Field := 16#0#; -- Counter stop rollover CSR : MMCCR_CSR_Field := 16#0#; -- Reset on read ROR : MMCCR_ROR_Field := 16#0#; -- unspecified Reserved_3_30 : STM32_SVD.UInt28 := 16#0#; -- MMC counter freeze MCF : MMCCR_MCF_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MMCCR_Register use record CR at 0 range 0 .. 0; CSR at 0 range 1 .. 1; ROR at 0 range 2 .. 2; Reserved_3_30 at 0 range 3 .. 30; MCF at 0 range 31 .. 31; end record; subtype MMCRIR_RFCES_Field is STM32_SVD.Bit; subtype MMCRIR_RFAES_Field is STM32_SVD.Bit; subtype MMCRIR_RGUFS_Field is STM32_SVD.Bit; -- Ethernet MMC receive interrupt register (ETH_MMCRIR) type MMCRIR_Register is record -- unspecified Reserved_0_4 : STM32_SVD.UInt5 := 16#0#; -- Received frames CRC error status RFCES : MMCRIR_RFCES_Field := 16#0#; -- Received frames alignment error status RFAES : MMCRIR_RFAES_Field := 16#0#; -- unspecified Reserved_7_16 : STM32_SVD.UInt10 := 16#0#; -- Received Good Unicast Frames Status RGUFS : MMCRIR_RGUFS_Field := 16#0#; -- unspecified Reserved_18_31 : STM32_SVD.UInt14 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MMCRIR_Register use record Reserved_0_4 at 0 range 0 .. 4; RFCES at 0 range 5 .. 5; RFAES at 0 range 6 .. 6; Reserved_7_16 at 0 range 7 .. 16; RGUFS at 0 range 17 .. 17; Reserved_18_31 at 0 range 18 .. 31; end record; subtype MMCTIR_TGFSCS_Field is STM32_SVD.Bit; subtype MMCTIR_TGFMSCS_Field is STM32_SVD.Bit; subtype MMCTIR_TGFS_Field is STM32_SVD.Bit; -- Ethernet MMC transmit interrupt register (ETH_MMCTIR) type MMCTIR_Register is record -- unspecified Reserved_0_13 : STM32_SVD.UInt14 := 16#0#; -- Transmitted good frames single collision status TGFSCS : MMCTIR_TGFSCS_Field := 16#0#; -- Transmitted good frames more single collision status TGFMSCS : MMCTIR_TGFMSCS_Field := 16#0#; -- unspecified Reserved_16_20 : STM32_SVD.UInt5 := 16#0#; -- Transmitted good frames status TGFS : MMCTIR_TGFS_Field := 16#0#; -- unspecified Reserved_22_31 : STM32_SVD.UInt10 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MMCTIR_Register use record Reserved_0_13 at 0 range 0 .. 13; TGFSCS at 0 range 14 .. 14; TGFMSCS at 0 range 15 .. 15; Reserved_16_20 at 0 range 16 .. 20; TGFS at 0 range 21 .. 21; Reserved_22_31 at 0 range 22 .. 31; end record; subtype MMCRIMR_RFCEM_Field is STM32_SVD.Bit; subtype MMCRIMR_RFAEM_Field is STM32_SVD.Bit; subtype MMCRIMR_RGUFM_Field is STM32_SVD.Bit; -- Ethernet MMC receive interrupt mask register (ETH_MMCRIMR) type MMCRIMR_Register is record -- unspecified Reserved_0_4 : STM32_SVD.UInt5 := 16#0#; -- Received frame CRC error mask RFCEM : MMCRIMR_RFCEM_Field := 16#0#; -- Received frames alignment error mask RFAEM : MMCRIMR_RFAEM_Field := 16#0#; -- unspecified Reserved_7_16 : STM32_SVD.UInt10 := 16#0#; -- Received good unicast frames mask RGUFM : MMCRIMR_RGUFM_Field := 16#0#; -- unspecified Reserved_18_31 : STM32_SVD.UInt14 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MMCRIMR_Register use record Reserved_0_4 at 0 range 0 .. 4; RFCEM at 0 range 5 .. 5; RFAEM at 0 range 6 .. 6; Reserved_7_16 at 0 range 7 .. 16; RGUFM at 0 range 17 .. 17; Reserved_18_31 at 0 range 18 .. 31; end record; subtype MMCTIMR_TGFSCM_Field is STM32_SVD.Bit; subtype MMCTIMR_TGFMSCM_Field is STM32_SVD.Bit; subtype MMCTIMR_TGFM_Field is STM32_SVD.Bit; -- Ethernet MMC transmit interrupt mask register (ETH_MMCTIMR) type MMCTIMR_Register is record -- unspecified Reserved_0_13 : STM32_SVD.UInt14 := 16#0#; -- Transmitted good frames single collision mask TGFSCM : MMCTIMR_TGFSCM_Field := 16#0#; -- Transmitted good frames more single collision mask TGFMSCM : MMCTIMR_TGFMSCM_Field := 16#0#; -- unspecified Reserved_16_20 : STM32_SVD.UInt5 := 16#0#; -- Transmitted good frames mask TGFM : MMCTIMR_TGFM_Field := 16#0#; -- unspecified Reserved_22_31 : STM32_SVD.UInt10 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MMCTIMR_Register use record Reserved_0_13 at 0 range 0 .. 13; TGFSCM at 0 range 14 .. 14; TGFMSCM at 0 range 15 .. 15; Reserved_16_20 at 0 range 16 .. 20; TGFM at 0 range 21 .. 21; Reserved_22_31 at 0 range 22 .. 31; end record; subtype PTPTSCR_TSE_Field is STM32_SVD.Bit; subtype PTPTSCR_TSFCU_Field is STM32_SVD.Bit; subtype PTPTSCR_TSSTI_Field is STM32_SVD.Bit; subtype PTPTSCR_TSSTU_Field is STM32_SVD.Bit; subtype PTPTSCR_TSITE_Field is STM32_SVD.Bit; subtype PTPTSCR_TSARU_Field is STM32_SVD.Bit; -- Ethernet PTP time stamp control register (ETH_PTPTSCR) type PTPTSCR_Register is record -- Time stamp enable TSE : PTPTSCR_TSE_Field := 16#0#; -- Time stamp fine or coarse update TSFCU : PTPTSCR_TSFCU_Field := 16#0#; -- Time stamp system time initialize TSSTI : PTPTSCR_TSSTI_Field := 16#0#; -- Time stamp system time update TSSTU : PTPTSCR_TSSTU_Field := 16#0#; -- Time stamp interrupt trigger enable TSITE : PTPTSCR_TSITE_Field := 16#0#; -- Time stamp addend register update TSARU : PTPTSCR_TSARU_Field := 16#0#; -- unspecified Reserved_6_31 : STM32_SVD.UInt26 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PTPTSCR_Register use record TSE at 0 range 0 .. 0; TSFCU at 0 range 1 .. 1; TSSTI at 0 range 2 .. 2; TSSTU at 0 range 3 .. 3; TSITE at 0 range 4 .. 4; TSARU at 0 range 5 .. 5; Reserved_6_31 at 0 range 6 .. 31; end record; subtype PTPSSIR_STSSI_Field is STM32_SVD.Byte; -- Ethernet PTP subsecond increment register type PTPSSIR_Register is record -- System time subsecond increment STSSI : PTPSSIR_STSSI_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 PTPSSIR_Register use record STSSI at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype PTPTSLR_STSS_Field is STM32_SVD.UInt31; subtype PTPTSLR_STPNS_Field is STM32_SVD.Bit; -- Ethernet PTP time stamp low register (ETH_PTPTSLR) type PTPTSLR_Register is record -- Read-only. System time subseconds STSS : PTPTSLR_STSS_Field; -- Read-only. System time positive or negative sign STPNS : PTPTSLR_STPNS_Field; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PTPTSLR_Register use record STSS at 0 range 0 .. 30; STPNS at 0 range 31 .. 31; end record; subtype PTPTSLUR_TSUSS_Field is STM32_SVD.UInt31; subtype PTPTSLUR_TSUPNS_Field is STM32_SVD.Bit; -- Ethernet PTP time stamp low update register (ETH_PTPTSLUR) type PTPTSLUR_Register is record -- Time stamp update subseconds TSUSS : PTPTSLUR_TSUSS_Field := 16#0#; -- Time stamp update positive or negative sign TSUPNS : PTPTSLUR_TSUPNS_Field := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PTPTSLUR_Register use record TSUSS at 0 range 0 .. 30; TSUPNS at 0 range 31 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Ethernet: DMA controller operation type ETHERNET_DMA_Peripheral is record -- Ethernet DMA bus mode register DMABMR : aliased DMABMR_Register; -- Ethernet DMA transmit poll demand register DMATPDR : aliased STM32_SVD.UInt32; -- EHERNET DMA receive poll demand register DMARPDR : aliased STM32_SVD.UInt32; -- Ethernet DMA receive descriptor list address register DMARDLAR : aliased STM32_SVD.UInt32; -- Ethernet DMA transmit descriptor list address register DMATDLAR : aliased STM32_SVD.UInt32; -- Ethernet DMA status register DMASR : aliased DMASR_Register; -- Ethernet DMA operation mode register DMAOMR : aliased DMAOMR_Register; -- Ethernet DMA interrupt enable register DMAIER : aliased DMAIER_Register; -- Ethernet DMA missed frame and buffer overflow counter register DMAMFBOCR : aliased DMAMFBOCR_Register; -- Ethernet DMA current host transmit descriptor register DMACHTDR : aliased STM32_SVD.UInt32; -- Ethernet DMA current host receive descriptor register DMACHRDR : aliased STM32_SVD.UInt32; -- Ethernet DMA current host transmit buffer address register DMACHTBAR : aliased STM32_SVD.UInt32; -- Ethernet DMA current host receive buffer address register DMACHRBAR : aliased STM32_SVD.UInt32; end record with Volatile; for ETHERNET_DMA_Peripheral use record DMABMR at 16#0# range 0 .. 31; DMATPDR at 16#4# range 0 .. 31; DMARPDR at 16#8# range 0 .. 31; DMARDLAR at 16#C# range 0 .. 31; DMATDLAR at 16#10# range 0 .. 31; DMASR at 16#14# range 0 .. 31; DMAOMR at 16#18# range 0 .. 31; DMAIER at 16#1C# range 0 .. 31; DMAMFBOCR at 16#20# range 0 .. 31; DMACHTDR at 16#48# range 0 .. 31; DMACHRDR at 16#4C# range 0 .. 31; DMACHTBAR at 16#50# range 0 .. 31; DMACHRBAR at 16#54# range 0 .. 31; end record; -- Ethernet: DMA controller operation ETHERNET_DMA_Periph : aliased ETHERNET_DMA_Peripheral with Import, Address => System'To_Address (16#40029000#); -- Ethernet: media access control type ETHERNET_MAC_Peripheral is record -- Ethernet MAC configuration register (ETH_MACCR) MACCR : aliased MACCR_Register; -- Ethernet MAC frame filter register (ETH_MACCFFR) MACFFR : aliased MACFFR_Register; -- Ethernet MAC hash table high register MACHTHR : aliased STM32_SVD.UInt32; -- Ethernet MAC hash table low register MACHTLR : aliased STM32_SVD.UInt32; -- Ethernet MAC MII address register (ETH_MACMIIAR) MACMIIAR : aliased MACMIIAR_Register; -- Ethernet MAC MII data register (ETH_MACMIIDR) MACMIIDR : aliased MACMIIDR_Register; -- Ethernet MAC flow control register (ETH_MACFCR) MACFCR : aliased MACFCR_Register; -- Ethernet MAC VLAN tag register (ETH_MACVLANTR) MACVLANTR : aliased MACVLANTR_Register; -- Ethernet MAC remote wakeup frame filter register (ETH_MACRWUFFR) MACRWUFFR : aliased STM32_SVD.UInt32; -- Ethernet MAC PMT control and status register (ETH_MACPMTCSR) MACPMTCSR : aliased MACPMTCSR_Register; -- Ethernet MAC interrupt status register (ETH_MACSR) MACSR : aliased MACSR_Register; -- Ethernet MAC interrupt mask register (ETH_MACIMR) MACIMR : aliased MACIMR_Register; -- Ethernet MAC address 0 high register (ETH_MACA0HR) MACA0HR : aliased MACA0HR_Register; -- Ethernet MAC address 0 low register MACA0LR : aliased STM32_SVD.UInt32; -- Ethernet MAC address 1 high register (ETH_MACA1HR) MACA1HR : aliased MACA1HR_Register; -- Ethernet MAC address1 low register MACA1LR : aliased STM32_SVD.UInt32; -- Ethernet MAC address 2 high register (ETH_MACA2HR) MACA2HR : aliased MACA2HR_Register; -- Ethernet MAC address 2 low register MACA2LR : aliased MACA2LR_Register; -- Ethernet MAC address 3 high register (ETH_MACA3HR) MACA3HR : aliased MACA3HR_Register; -- Ethernet MAC address 3 low register MACA3LR : aliased STM32_SVD.UInt32; end record with Volatile; for ETHERNET_MAC_Peripheral use record MACCR at 16#0# range 0 .. 31; MACFFR at 16#4# range 0 .. 31; MACHTHR at 16#8# range 0 .. 31; MACHTLR at 16#C# range 0 .. 31; MACMIIAR at 16#10# range 0 .. 31; MACMIIDR at 16#14# range 0 .. 31; MACFCR at 16#18# range 0 .. 31; MACVLANTR at 16#1C# range 0 .. 31; MACRWUFFR at 16#28# range 0 .. 31; MACPMTCSR at 16#2C# range 0 .. 31; MACSR at 16#38# range 0 .. 31; MACIMR at 16#3C# range 0 .. 31; MACA0HR at 16#40# range 0 .. 31; MACA0LR at 16#44# range 0 .. 31; MACA1HR at 16#48# range 0 .. 31; MACA1LR at 16#4C# range 0 .. 31; MACA2HR at 16#50# range 0 .. 31; MACA2LR at 16#54# range 0 .. 31; MACA3HR at 16#58# range 0 .. 31; MACA3LR at 16#5C# range 0 .. 31; end record; -- Ethernet: media access control ETHERNET_MAC_Periph : aliased ETHERNET_MAC_Peripheral with Import, Address => System'To_Address (16#40028000#); -- Ethernet: MAC management counters type ETHERNET_MMC_Peripheral is record -- Ethernet MMC control register (ETH_MMCCR) MMCCR : aliased MMCCR_Register; -- Ethernet MMC receive interrupt register (ETH_MMCRIR) MMCRIR : aliased MMCRIR_Register; -- Ethernet MMC transmit interrupt register (ETH_MMCTIR) MMCTIR : aliased MMCTIR_Register; -- Ethernet MMC receive interrupt mask register (ETH_MMCRIMR) MMCRIMR : aliased MMCRIMR_Register; -- Ethernet MMC transmit interrupt mask register (ETH_MMCTIMR) MMCTIMR : aliased MMCTIMR_Register; -- Ethernet MMC transmitted good frames after a single collision counter MMCTGFSCCR : aliased STM32_SVD.UInt32; -- Ethernet MMC transmitted good frames after more than a single -- collision MMCTGFMSCCR : aliased STM32_SVD.UInt32; -- Ethernet MMC transmitted good frames counter register MMCTGFCR : aliased STM32_SVD.UInt32; -- Ethernet MMC received frames with CRC error counter register MMCRFCECR : aliased STM32_SVD.UInt32; -- Ethernet MMC received frames with alignment error counter register MMCRFAECR : aliased STM32_SVD.UInt32; -- MMC received good unicast frames counter register MMCRGUFCR : aliased STM32_SVD.UInt32; end record with Volatile; for ETHERNET_MMC_Peripheral use record MMCCR at 16#0# range 0 .. 31; MMCRIR at 16#4# range 0 .. 31; MMCTIR at 16#8# range 0 .. 31; MMCRIMR at 16#C# range 0 .. 31; MMCTIMR at 16#10# range 0 .. 31; MMCTGFSCCR at 16#4C# range 0 .. 31; MMCTGFMSCCR at 16#50# range 0 .. 31; MMCTGFCR at 16#68# range 0 .. 31; MMCRFCECR at 16#94# range 0 .. 31; MMCRFAECR at 16#98# range 0 .. 31; MMCRGUFCR at 16#C4# range 0 .. 31; end record; -- Ethernet: MAC management counters ETHERNET_MMC_Periph : aliased ETHERNET_MMC_Peripheral with Import, Address => System'To_Address (16#40028100#); -- Ethernet: Precision time protocol type ETHERNET_PTP_Peripheral is record -- Ethernet PTP time stamp control register (ETH_PTPTSCR) PTPTSCR : aliased PTPTSCR_Register; -- Ethernet PTP subsecond increment register PTPSSIR : aliased PTPSSIR_Register; -- Ethernet PTP time stamp high register PTPTSHR : aliased STM32_SVD.UInt32; -- Ethernet PTP time stamp low register (ETH_PTPTSLR) PTPTSLR : aliased PTPTSLR_Register; -- Ethernet PTP time stamp high update register PTPTSHUR : aliased STM32_SVD.UInt32; -- Ethernet PTP time stamp low update register (ETH_PTPTSLUR) PTPTSLUR : aliased PTPTSLUR_Register; -- Ethernet PTP time stamp addend register PTPTSAR : aliased STM32_SVD.UInt32; -- Ethernet PTP target time high register PTPTTHR : aliased STM32_SVD.UInt32; -- Ethernet PTP target time low register PTPTTLR : aliased STM32_SVD.UInt32; end record with Volatile; for ETHERNET_PTP_Peripheral use record PTPTSCR at 16#0# range 0 .. 31; PTPSSIR at 16#4# range 0 .. 31; PTPTSHR at 16#8# range 0 .. 31; PTPTSLR at 16#C# range 0 .. 31; PTPTSHUR at 16#10# range 0 .. 31; PTPTSLUR at 16#14# range 0 .. 31; PTPTSAR at 16#18# range 0 .. 31; PTPTTHR at 16#1C# range 0 .. 31; PTPTTLR at 16#20# range 0 .. 31; end record; -- Ethernet: Precision time protocol ETHERNET_PTP_Periph : aliased ETHERNET_PTP_Peripheral with Import, Address => System'To_Address (16#40028700#); end STM32_SVD.ETHERNET;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E M _ R E S -- -- -- -- S p e c -- -- -- -- Copyright (C) 1992-2016, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- Resolution processing for all subexpression nodes. Note that the separate -- package Sem_Aggr contains the actual resolution routines for aggregates, -- which are separated off since aggregate processing is complex. with Types; use Types; package Sem_Res is -- As described in Sem_Ch4, the type resolution proceeds in two phases. -- The first phase is a bottom up pass that is achieved during the -- recursive traversal performed by the Analyze procedures. This phase -- determines unambiguous types, and collects sets of possible types -- where the interpretation is potentially ambiguous. -- On completing this bottom up pass, which corresponds to a call to -- Analyze on a complete context, the Resolve routine is called which -- performs a top down resolution with recursive calls to itself to -- resolve operands. -- Since in practice a lot of semantic analysis has to be postponed until -- types are known (e.g. static folding, setting of suppress flags), the -- Resolve routines also complete the semantic analysis, and call the -- expander for possible expansion of the completely type resolved node. procedure Ambiguous_Character (C : Node_Id); -- Give list of candidate interpretations when a character literal cannot -- be resolved, for example in a (useless) comparison such as 'A' = 'B'. -- In Ada 95 the literals in question can be of type Character or Wide_ -- Character. In Ada 2005 Wide_Wide_Character is also a candidate. The -- node may also be overloaded with user-defined character types. procedure Analyze_And_Resolve (N : Node_Id); procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id); procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id); procedure Analyze_And_Resolve (N : Node_Id; Suppress : Check_Id); -- These routines combine the effect of Analyze and Resolve. If a Suppress -- argument is present, then the analysis is done with the specified check -- suppressed (can be All_Checks to suppress all checks). These checks are -- suppressed for both the analysis and resolution. If the type argument -- is not present, then the Etype of the expression after the Analyze -- call is used for the Resolve. procedure Check_Parameterless_Call (N : Node_Id); -- Several forms of names can denote calls to entities without parameters. -- The context determines whether the name denotes the entity or a call to -- it. When it is a call, the node must be rebuilt accordingly and -- reanalyzed to obtain possible interpretations. -- -- The name may be that of an overloadable construct, or it can be an -- explicit dereference of a prefix that denotes an access to subprogram. -- In that case, we want to convert the name into a call only if the -- context requires the return type of the subprogram. Finally, a -- parameterless protected subprogram appears as a selected component. -- -- The parameter T is the Typ for the corresponding resolve call. procedure Preanalyze_And_Resolve (N : Node_Id; T : Entity_Id); -- Performs a pre-analysis of expression node N. During pre-analysis, N is -- analyzed and then resolved against type T, but no expansion is carried -- out for N or its children. For more info on pre-analysis read the spec -- of Sem. procedure Preanalyze_And_Resolve (N : Node_Id); -- Same, but use type of node because context does not impose a single type procedure Resolve (N : Node_Id; Typ : Entity_Id); procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id); -- Top-level type-checking procedure, called in a complete context. The -- construct N, which is a subexpression, has already been analyzed, and -- is required to be of type Typ given the analysis of the context (which -- uses the information gathered on the bottom-up phase in Analyze). The -- resolve routines do various other processing, e.g. static evaluation. -- If a Suppress argument is present, then the resolution is done with the -- specified check suppressed (can be All_Checks to suppress all checks). procedure Resolve (N : Node_Id); -- A version of Resolve where the type to be used for resolution is taken -- from the Etype (N). This is commonly used in cases where the context -- does not add anything and the first pass of analysis found the correct -- expected type. procedure Resolve_Discrete_Subtype_Indication (N : Node_Id; Typ : Entity_Id); -- Resolve subtype indications in choices (case statements and aggregates) -- and in index constraints. Note that the resulting Etype of the subtype_ -- indication node is set to the Etype of the contained range (i.e. an -- Itype is not constructed for the actual subtype). procedure Resolve_Entry (Entry_Name : Node_Id); -- Find name of entry being called, and resolve prefix of name with its -- own type. For now we assume that the prefix cannot be overloaded and -- the name of the entry plays no role in the resolution. function Valid_Conversion (N : Node_Id; Target : Entity_Id; Operand : Node_Id; Report_Errs : Boolean := True) return Boolean; -- Verify legality rules given in 4.6 (8-23). Target is the target type -- of the conversion, which may be an implicit conversion of an actual -- parameter to an anonymous access type (in which case N denotes the -- actual parameter and N = Operand). Returns a Boolean result indicating -- whether the conversion is legal. Reports errors in the case of illegal -- conversions, unless Report_Errs is False. private procedure Resolve_Implicit_Type (N : Node_Id) renames Resolve; pragma Inline (Resolve_Implicit_Type); -- We use this renaming to make the application of Inline very explicit to -- this version, since other versions of Resolve are not inlined. end Sem_Res;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S E M _ W A R N -- -- -- -- B o d y -- -- -- -- Copyright (C) 1999-2020, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING3. If not, go to -- -- http://www.gnu.org/licenses for a complete copy of the license. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Atree; use Atree; with Debug; use Debug; with Einfo; use Einfo; with Errout; use Errout; with Exp_Code; use Exp_Code; with Lib; use Lib; with Lib.Xref; use Lib.Xref; with Namet; use Namet; with Nlists; use Nlists; with Opt; use Opt; with Par_SCO; use Par_SCO; with Rtsfind; use Rtsfind; with Sem; use Sem; with Sem_Ch8; use Sem_Ch8; with Sem_Aux; use Sem_Aux; with Sem_Eval; use Sem_Eval; with Sem_Prag; use Sem_Prag; with Sem_Util; use Sem_Util; with Sinfo; use Sinfo; with Sinput; use Sinput; with Snames; use Snames; with Stand; use Stand; with Stringt; use Stringt; with Tbuild; use Tbuild; with Uintp; use Uintp; package body Sem_Warn is -- The following table collects Id's of entities that are potentially -- unreferenced. See Check_Unset_Reference for further details. -- ??? Check_Unset_Reference has zero information about this table. package Unreferenced_Entities is new Table.Table ( Table_Component_Type => Entity_Id, Table_Index_Type => Nat, Table_Low_Bound => 1, Table_Initial => Alloc.Unreferenced_Entities_Initial, Table_Increment => Alloc.Unreferenced_Entities_Increment, Table_Name => "Unreferenced_Entities"); -- The following table collects potential warnings for IN OUT parameters -- that are referenced but not modified. These warnings are processed when -- the front end calls the procedure Output_Non_Modified_In_Out_Warnings. -- The reason that we defer output of these messages is that we want to -- detect the case where the relevant procedure is used as a generic actual -- in an instantiation, since we suppress the warnings in this case. The -- flag Used_As_Generic_Actual will be set in this case, but only at the -- point of usage. Similarly, we suppress the message if the address of the -- procedure is taken, where the flag Address_Taken may be set later. package In_Out_Warnings is new Table.Table ( Table_Component_Type => Entity_Id, Table_Index_Type => Nat, Table_Low_Bound => 1, Table_Initial => Alloc.In_Out_Warnings_Initial, Table_Increment => Alloc.In_Out_Warnings_Increment, Table_Name => "In_Out_Warnings"); -------------------------------------------------------- -- Handling of Warnings Off, Unmodified, Unreferenced -- -------------------------------------------------------- -- The functions Has_Warnings_Off, Has_Unmodified, Has_Unreferenced must -- generally be used instead of Warnings_Off, Has_Pragma_Unmodified and -- Has_Pragma_Unreferenced, as noted in the specs in Einfo. -- In order to avoid losing warnings in -gnatw.w (warn on unnecessary -- warnings off pragma) mode, i.e. to avoid false negatives, the code -- must follow some important rules. -- Call these functions as late as possible, after completing all other -- tests, just before the warnings is given. For example, don't write: -- if not Has_Warnings_Off (E) -- and then some-other-predicate-on-E then .. -- Instead the following is preferred -- if some-other-predicate-on-E -- and then Has_Warnings_Off (E) -- This way if some-other-predicate is false, we avoid a false indication -- that a Warnings (Off, E) pragma was useful in preventing a warning. -- The second rule is that if both Has_Unmodified and Has_Warnings_Off, or -- Has_Unreferenced and Has_Warnings_Off are called, make sure that the -- call to Has_Unmodified/Has_Unreferenced comes first, this way we record -- that the Warnings (Off) could have been Unreferenced or Unmodified. In -- fact Has_Unmodified/Has_Unreferenced includes a test for Warnings Off, -- and so a subsequent test is not needed anyway (though it is harmless). ----------------------- -- Local Subprograms -- ----------------------- function Generic_Package_Spec_Entity (E : Entity_Id) return Boolean; -- This returns true if the entity E is declared within a generic package. -- The point of this is to detect variables which are not assigned within -- the generic, but might be assigned outside the package for any given -- instance. These are cases where we leave the warnings to be posted for -- the instance, when we will know more. function Goto_Spec_Entity (E : Entity_Id) return Entity_Id; -- If E is a parameter entity for a subprogram body, then this function -- returns the corresponding spec entity, if not, E is returned unchanged. function Has_Pragma_Unmodified_Check_Spec (E : Entity_Id) return Boolean; -- Tests Has_Pragma_Unmodified flag for entity E. If E is not a formal, -- this is simply the setting of the flag Has_Pragma_Unmodified. If E is -- a body formal, the setting of the flag in the corresponding spec is -- also checked (and True returned if either flag is True). function Has_Pragma_Unreferenced_Check_Spec (E : Entity_Id) return Boolean; -- Tests Has_Pragma_Unreferenced flag for entity E. If E is not a formal, -- this is simply the setting of the flag Has_Pragma_Unreferenced. If E is -- a body formal, the setting of the flag in the corresponding spec is -- also checked (and True returned if either flag is True). function Is_Attribute_And_Known_Value_Comparison (Op : Node_Id) return Boolean; -- Determine whether operator Op denotes a comparison where the left -- operand is an attribute reference and the value of the right operand is -- known at compile time. function Never_Set_In_Source_Check_Spec (E : Entity_Id) return Boolean; -- Tests Never_Set_In_Source status for entity E. If E is not a formal, -- this is simply the setting of the flag Never_Set_In_Source. If E is -- a body formal, the setting of the flag in the corresponding spec is -- also checked (and False returned if either flag is False). function Operand_Has_Warnings_Suppressed (N : Node_Id) return Boolean; -- This function traverses the expression tree represented by the node N -- and determines if any sub-operand is a reference to an entity for which -- the Warnings_Off flag is set. True is returned if such an entity is -- encountered, and False otherwise. function Referenced_Check_Spec (E : Entity_Id) return Boolean; -- Tests Referenced status for entity E. If E is not a formal, this is -- simply the setting of the flag Referenced. If E is a body formal, the -- setting of the flag in the corresponding spec is also checked (and True -- returned if either flag is True). function Referenced_As_LHS_Check_Spec (E : Entity_Id) return Boolean; -- Tests Referenced_As_LHS status for entity E. If E is not a formal, this -- is simply the setting of the flag Referenced_As_LHS. If E is a body -- formal, the setting of the flag in the corresponding spec is also -- checked (and True returned if either flag is True). function Referenced_As_Out_Parameter_Check_Spec (E : Entity_Id) return Boolean; -- Tests Referenced_As_Out_Parameter status for entity E. If E is not a -- formal, this is simply the setting of Referenced_As_Out_Parameter. If E -- is a body formal, the setting of the flag in the corresponding spec is -- also checked (and True returned if either flag is True). procedure Warn_On_Unreferenced_Entity (Spec_E : Entity_Id; Body_E : Entity_Id := Empty); -- Output warnings for unreferenced entity E. For the case of an entry -- formal, Body_E is the corresponding body entity for a particular -- accept statement, and the message is posted on Body_E. In all other -- cases, Body_E is ignored and must be Empty. function Warnings_Off_Check_Spec (E : Entity_Id) return Boolean; -- Returns True if Warnings_Off is set for the entity E or (in the case -- where there is a Spec_Entity), Warnings_Off is set for the Spec_Entity. -------------------------- -- Check_Code_Statement -- -------------------------- procedure Check_Code_Statement (N : Node_Id) is begin -- If volatile, nothing to worry about if Is_Asm_Volatile (N) then return; end if; -- Warn if no input or no output Setup_Asm_Inputs (N); if No (Asm_Input_Value) then Error_Msg_F ("??code statement with no inputs should usually be Volatile!", N); return; end if; Setup_Asm_Outputs (N); if No (Asm_Output_Variable) then Error_Msg_F ("??code statement with no outputs should usually be Volatile!", N); return; end if; end Check_Code_Statement; --------------------------------- -- Check_Infinite_Loop_Warning -- --------------------------------- -- The case we look for is a while loop which tests a local variable, where -- there is no obvious direct or possible indirect update of the variable -- within the body of the loop. procedure Check_Infinite_Loop_Warning (Loop_Statement : Node_Id) is Expression : Node_Id := Empty; -- Set to WHILE or EXIT WHEN condition to be tested Ref : Node_Id := Empty; -- Reference in Expression to variable that might not be modified -- in loop, indicating a possible infinite loop. Var : Entity_Id := Empty; -- Corresponding entity (entity of Ref) Function_Call_Found : Boolean := False; -- True if Find_Var found a function call in the condition procedure Find_Var (N : Node_Id); -- Inspect condition to see if it depends on a single entity reference. -- If so, Ref is set to point to the reference node, and Var is set to -- the referenced Entity. function Has_Condition_Actions (Iter : Node_Id) return Boolean; -- Determine whether iteration scheme Iter has meaningful condition -- actions. function Has_Indirection (T : Entity_Id) return Boolean; -- If the controlling variable is an access type, or is a record type -- with access components, assume that it is changed indirectly and -- suppress the warning. As a concession to low-level programming, in -- particular within Declib, we also suppress warnings on a record -- type that contains components of type Address or Short_Address. function Is_Suspicious_Function_Name (E : Entity_Id) return Boolean; -- Given an entity name, see if the name appears to have something to -- do with I/O or network stuff, and if so, return True. Used to kill -- some false positives on a heuristic basis that such functions will -- likely have some strange side effect dependencies. A rather strange -- test, but warning messages are in the heuristics business. function Test_Ref (N : Node_Id) return Traverse_Result; -- Test for reference to variable in question. Returns Abandon if -- matching reference found. Used in instantiation of No_Ref_Found. function No_Ref_Found is new Traverse_Func (Test_Ref); -- Function to traverse body of procedure. Returns Abandon if matching -- reference found. -------------- -- Find_Var -- -------------- procedure Find_Var (N : Node_Id) is begin -- Condition is a direct variable reference if Is_Entity_Name (N) then Ref := N; Var := Entity (Ref); -- Case of condition is a comparison with compile time known value elsif Nkind (N) in N_Op_Compare then if Compile_Time_Known_Value (Right_Opnd (N)) then Find_Var (Left_Opnd (N)); elsif Compile_Time_Known_Value (Left_Opnd (N)) then Find_Var (Right_Opnd (N)); -- Ignore any other comparison else return; end if; -- If condition is a negation, check its operand elsif Nkind (N) = N_Op_Not then Find_Var (Right_Opnd (N)); -- Case of condition is function call elsif Nkind (N) = N_Function_Call then Function_Call_Found := True; -- Forget it if function name is not entity, who knows what -- we might be calling? if not Is_Entity_Name (Name (N)) then return; -- Forget it if function name is suspicious. A strange test -- but warning generation is in the heuristics business. elsif Is_Suspicious_Function_Name (Entity (Name (N))) then return; -- Forget it if function is marked Volatile_Function elsif Is_Volatile_Function (Entity (Name (N))) then return; -- Forget it if warnings are suppressed on function entity elsif Has_Warnings_Off (Entity (Name (N))) then return; -- Forget it if the parameter is not In elsif Has_Out_Or_In_Out_Parameter (Entity (Name (N))) then return; end if; -- OK, see if we have one argument declare PA : constant List_Id := Parameter_Associations (N); begin -- One argument, so check the argument if Present (PA) and then List_Length (PA) = 1 then if Nkind (First (PA)) = N_Parameter_Association then Find_Var (Explicit_Actual_Parameter (First (PA))); else Find_Var (First (PA)); end if; -- Not one argument else return; end if; end; -- Any other kind of node is not something we warn for else return; end if; end Find_Var; --------------------------- -- Has_Condition_Actions -- --------------------------- function Has_Condition_Actions (Iter : Node_Id) return Boolean is Action : Node_Id; begin -- A call marker is not considered a meaningful action because it -- acts as an annotation and has no runtime semantics. Action := First (Condition_Actions (Iter)); while Present (Action) loop if Nkind (Action) /= N_Call_Marker then return True; end if; Next (Action); end loop; return False; end Has_Condition_Actions; --------------------- -- Has_Indirection -- --------------------- function Has_Indirection (T : Entity_Id) return Boolean is Comp : Entity_Id; Rec : Entity_Id; begin if Is_Access_Type (T) then return True; elsif Is_Private_Type (T) and then Present (Full_View (T)) and then Is_Access_Type (Full_View (T)) then return True; elsif Is_Record_Type (T) then Rec := T; elsif Is_Private_Type (T) and then Present (Full_View (T)) and then Is_Record_Type (Full_View (T)) then Rec := Full_View (T); else return False; end if; Comp := First_Component (Rec); while Present (Comp) loop if Is_Access_Type (Etype (Comp)) or else Is_Descendant_Of_Address (Etype (Comp)) then return True; end if; Next_Component (Comp); end loop; return False; end Has_Indirection; --------------------------------- -- Is_Suspicious_Function_Name -- --------------------------------- function Is_Suspicious_Function_Name (E : Entity_Id) return Boolean is S : Entity_Id; function Substring_Present (S : String) return Boolean; -- Returns True if name buffer has given string delimited by non- -- alphabetic characters or by end of string. S is lower case. ----------------------- -- Substring_Present -- ----------------------- function Substring_Present (S : String) return Boolean is Len : constant Natural := S'Length; begin for J in 1 .. Name_Len - (Len - 1) loop if Name_Buffer (J .. J + (Len - 1)) = S and then (J = 1 or else Name_Buffer (J - 1) not in 'a' .. 'z') and then (J + Len > Name_Len or else Name_Buffer (J + Len) not in 'a' .. 'z') then return True; end if; end loop; return False; end Substring_Present; -- Start of processing for Is_Suspicious_Function_Name begin S := E; while Present (S) and then S /= Standard_Standard loop Get_Name_String (Chars (S)); if Substring_Present ("io") or else Substring_Present ("file") or else Substring_Present ("network") then return True; else S := Scope (S); end if; end loop; return False; end Is_Suspicious_Function_Name; -------------- -- Test_Ref -- -------------- function Test_Ref (N : Node_Id) return Traverse_Result is begin -- Waste of time to look at the expression we are testing if N = Expression then return Skip; -- Direct reference to variable in question elsif Is_Entity_Name (N) and then Present (Entity (N)) and then Entity (N) = Var then -- If this is an lvalue, then definitely abandon, since -- this could be a direct modification of the variable. if May_Be_Lvalue (N) then return Abandon; end if; -- If the condition contains a function call, we consider it may -- be modified by side effects from a procedure call. Otherwise, -- we consider the condition may not be modified, although that -- might happen if Variable is itself a by-reference parameter, -- and the procedure called modifies the global object referred to -- by Variable, but we actually prefer to issue a warning in this -- odd case. Note that the case where the procedure called has -- visibility over Variable is treated in another case below. if Function_Call_Found then declare P : Node_Id; begin P := N; loop P := Parent (P); exit when P = Loop_Statement; -- Abandon if at procedure call, or something strange is -- going on (perhaps a node with no parent that should -- have one but does not?) As always, for a warning we -- prefer to just abandon the warning than get into the -- business of complaining about the tree structure here. if No (P) or else Nkind (P) = N_Procedure_Call_Statement then return Abandon; end if; end loop; end; end if; -- Reference to variable renaming variable in question elsif Is_Entity_Name (N) and then Present (Entity (N)) and then Ekind (Entity (N)) = E_Variable and then Present (Renamed_Object (Entity (N))) and then Is_Entity_Name (Renamed_Object (Entity (N))) and then Entity (Renamed_Object (Entity (N))) = Var and then May_Be_Lvalue (N) then return Abandon; -- Call to subprogram elsif Nkind (N) in N_Subprogram_Call then -- If subprogram is within the scope of the entity we are dealing -- with as the loop variable, then it could modify this parameter, -- so we abandon in this case. In the case of a subprogram that is -- not an entity we also abandon. The check for no entity being -- present is a defense against previous errors. if not Is_Entity_Name (Name (N)) or else No (Entity (Name (N))) or else Scope_Within (Entity (Name (N)), Scope (Var)) then return Abandon; end if; -- If any of the arguments are of type access to subprogram, then -- we may have funny side effects, so no warning in this case. declare Actual : Node_Id; begin Actual := First_Actual (N); while Present (Actual) loop if Is_Access_Subprogram_Type (Etype (Actual)) then return Abandon; else Next_Actual (Actual); end if; end loop; end; -- Declaration of the variable in question elsif Nkind (N) = N_Object_Declaration and then Defining_Identifier (N) = Var then return Abandon; end if; -- All OK, continue scan return OK; end Test_Ref; -- Start of processing for Check_Infinite_Loop_Warning begin -- Skip processing if debug flag gnatd.w is set if Debug_Flag_Dot_W then return; end if; -- Deal with Iteration scheme present declare Iter : constant Node_Id := Iteration_Scheme (Loop_Statement); begin if Present (Iter) then -- While iteration if Present (Condition (Iter)) then -- Skip processing for while iteration with conditions actions, -- since they make it too complicated to get the warning right. if Has_Condition_Actions (Iter) then return; end if; -- Capture WHILE condition Expression := Condition (Iter); -- For Loop_Parameter_Specification, do not process, since loop -- will always terminate. For Iterator_Specification, also do not -- process. Either it will always terminate (e.g. "for X of -- Some_Array ..."), or we can't tell if it's going to terminate -- without looking at the iterator, so any warning here would be -- noise. elsif Present (Loop_Parameter_Specification (Iter)) or else Present (Iterator_Specification (Iter)) then return; end if; end if; end; -- Check chain of EXIT statements, we only process loops that have a -- single exit condition (either a single EXIT WHEN statement, or a -- WHILE loop not containing any EXIT WHEN statements). declare Ident : constant Node_Id := Identifier (Loop_Statement); Exit_Stmt : Node_Id; begin -- If we don't have a proper chain set, ignore call entirely. This -- happens because of previous errors. if No (Entity (Ident)) or else Ekind (Entity (Ident)) /= E_Loop then Check_Error_Detected; return; end if; -- Otherwise prepare to scan list of EXIT statements Exit_Stmt := First_Exit_Statement (Entity (Ident)); while Present (Exit_Stmt) loop -- Check for EXIT WHEN if Present (Condition (Exit_Stmt)) then -- Quit processing if EXIT WHEN in WHILE loop, or more than -- one EXIT WHEN statement present in the loop. if Present (Expression) then return; -- Otherwise capture condition from EXIT WHEN statement else Expression := Condition (Exit_Stmt); end if; -- If an unconditional exit statement is the last statement in the -- loop, assume that no warning is needed, without any attempt at -- checking whether the exit is reachable. elsif Exit_Stmt = Last (Statements (Loop_Statement)) then return; end if; Exit_Stmt := Next_Exit_Statement (Exit_Stmt); end loop; end; -- Return if no condition to test if No (Expression) then return; end if; -- Initial conditions met, see if condition is of right form Find_Var (Expression); -- Nothing to do if local variable from source not found. If it's a -- renaming, it is probably renaming something too complicated to deal -- with here. if No (Var) or else Ekind (Var) /= E_Variable or else Is_Library_Level_Entity (Var) or else not Comes_From_Source (Var) or else Nkind (Parent (Var)) = N_Object_Renaming_Declaration then return; -- Nothing to do if there is some indirection involved (assume that the -- designated variable might be modified in some way we don't see). -- However, if no function call was found, then we don't care about -- indirections, because the condition must be something like "while X -- /= null loop", so we don't care if X.all is modified in the loop. elsif Function_Call_Found and then Has_Indirection (Etype (Var)) then return; -- Same sort of thing for volatile variable, might be modified by -- some other task or by the operating system in some way. elsif Is_Volatile (Var) then return; end if; -- Filter out case of original statement sequence starting with delay. -- We assume this is a multi-tasking program and that the condition -- is affected by other threads (some kind of busy wait). declare Fstm : constant Node_Id := Original_Node (First (Statements (Loop_Statement))); begin if Nkind (Fstm) = N_Delay_Relative_Statement or else Nkind (Fstm) = N_Delay_Until_Statement then return; end if; end; -- We have a variable reference of the right form, now we scan the loop -- body to see if it looks like it might not be modified if No_Ref_Found (Loop_Statement) = OK then Error_Msg_NE ("??variable& is not modified in loop body!", Ref, Var); Error_Msg_N ("\??possible infinite loop!", Ref); end if; end Check_Infinite_Loop_Warning; ---------------------------- -- Check_Low_Bound_Tested -- ---------------------------- procedure Check_Low_Bound_Tested (Expr : Node_Id) is procedure Check_Low_Bound_Tested_For (Opnd : Node_Id); -- Determine whether operand Opnd denotes attribute 'First whose prefix -- is a formal parameter. If this is the case, mark the entity of the -- prefix as having its low bound tested. -------------------------------- -- Check_Low_Bound_Tested_For -- -------------------------------- procedure Check_Low_Bound_Tested_For (Opnd : Node_Id) is begin if Nkind (Opnd) = N_Attribute_Reference and then Attribute_Name (Opnd) = Name_First and then Is_Entity_Name (Prefix (Opnd)) and then Present (Entity (Prefix (Opnd))) and then Is_Formal (Entity (Prefix (Opnd))) then Set_Low_Bound_Tested (Entity (Prefix (Opnd))); end if; end Check_Low_Bound_Tested_For; -- Start of processing for Check_Low_Bound_Tested begin if Comes_From_Source (Expr) then Check_Low_Bound_Tested_For (Left_Opnd (Expr)); Check_Low_Bound_Tested_For (Right_Opnd (Expr)); end if; end Check_Low_Bound_Tested; ---------------------- -- Check_References -- ---------------------- procedure Check_References (E : Entity_Id; Anod : Node_Id := Empty) is E1 : Entity_Id; E1T : Entity_Id; UR : Node_Id; function Body_Formal (E : Entity_Id; Accept_Statement : Node_Id) return Entity_Id; -- For an entry formal entity from an entry declaration, find the -- corresponding body formal from the given accept statement. function Generic_Body_Formal (E : Entity_Id) return Entity_Id; -- Warnings on unused formals of subprograms are placed on the entity -- in the subprogram body, which seems preferable because it suggests -- a better codefix for GNAT Studio. The analysis of generic subprogram -- bodies uses a different circuitry, so the choice for the proper -- placement of the warning in the generic case takes place here, by -- finding the body entity that corresponds to a formal in a spec. procedure May_Need_Initialized_Actual (Ent : Entity_Id); -- If an entity of a generic type has default initialization, then the -- corresponding actual type should be fully initialized, or else there -- will be uninitialized components in the instantiation, that might go -- unreported. This routine marks the type of the uninitialized variable -- appropriately to allow the compiler to emit an appropriate warning -- in the instance. In a sense, the use of a type that requires full -- initialization is a weak part of the generic contract. function Missing_Subunits return Boolean; -- We suppress warnings when there are missing subunits, because this -- may generate too many false positives: entities in a parent may only -- be referenced in one of the subunits. We make an exception for -- subunits that contain no other stubs. procedure Output_Reference_Error (M : String); -- Used to output an error message. Deals with posting the error on the -- body formal in the accept case. function Publicly_Referenceable (Ent : Entity_Id) return Boolean; -- This is true if the entity in question is potentially referenceable -- from another unit. This is true for entities in packages that are at -- the library level. function Warnings_Off_E1 return Boolean; -- Return True if Warnings_Off is set for E1, or for its Etype (E1T), -- or for the base type of E1T. ----------------- -- Body_Formal -- ----------------- function Body_Formal (E : Entity_Id; Accept_Statement : Node_Id) return Entity_Id is Body_Param : Node_Id; Body_E : Entity_Id; begin -- Loop to find matching parameter in accept statement Body_Param := First (Parameter_Specifications (Accept_Statement)); while Present (Body_Param) loop Body_E := Defining_Identifier (Body_Param); if Chars (Body_E) = Chars (E) then return Body_E; end if; Next (Body_Param); end loop; -- Should never fall through, should always find a match raise Program_Error; end Body_Formal; ------------------------- -- Generic_Body_Formal -- ------------------------- function Generic_Body_Formal (E : Entity_Id) return Entity_Id is Gen_Decl : constant Node_Id := Unit_Declaration_Node (Scope (E)); Gen_Body : constant Entity_Id := Corresponding_Body (Gen_Decl); Form : Entity_Id; begin if No (Gen_Body) then return E; else Form := First_Entity (Gen_Body); while Present (Form) loop if Chars (Form) = Chars (E) then return Form; end if; Next_Entity (Form); end loop; end if; -- Should never fall through, should always find a match raise Program_Error; end Generic_Body_Formal; --------------------------------- -- May_Need_Initialized_Actual -- --------------------------------- procedure May_Need_Initialized_Actual (Ent : Entity_Id) is T : constant Entity_Id := Etype (Ent); Par : constant Node_Id := Parent (T); begin if not Is_Generic_Type (T) then null; elsif (Nkind (Par)) = N_Private_Extension_Declaration then -- We only indicate the first such variable in the generic. if No (Uninitialized_Variable (Par)) then Set_Uninitialized_Variable (Par, Ent); end if; elsif (Nkind (Par)) = N_Formal_Type_Declaration and then Nkind (Formal_Type_Definition (Par)) = N_Formal_Private_Type_Definition then if No (Uninitialized_Variable (Formal_Type_Definition (Par))) then Set_Uninitialized_Variable (Formal_Type_Definition (Par), Ent); end if; end if; end May_Need_Initialized_Actual; ---------------------- -- Missing_Subunits -- ---------------------- function Missing_Subunits return Boolean is D : Node_Id; begin if not Unloaded_Subunits then -- Normal compilation, all subunits are present return False; elsif E /= Main_Unit_Entity then -- No warnings on a stub that is not the main unit return True; elsif Nkind (Unit_Declaration_Node (E)) in N_Proper_Body then D := First (Declarations (Unit_Declaration_Node (E))); while Present (D) loop -- No warnings if the proper body contains nested stubs if Nkind (D) in N_Body_Stub then return True; end if; Next (D); end loop; return False; else -- Missing stubs elsewhere return True; end if; end Missing_Subunits; ---------------------------- -- Output_Reference_Error -- ---------------------------- procedure Output_Reference_Error (M : String) is begin -- Never issue messages for internal names or renamings if Is_Internal_Name (Chars (E1)) or else Nkind (Parent (E1)) = N_Object_Renaming_Declaration then return; end if; -- Don't output message for IN OUT formal unless we have the warning -- flag specifically set. It is a bit odd to distinguish IN OUT -- formals from other cases. This distinction is historical in -- nature. Warnings for IN OUT formals were added fairly late. if Ekind (E1) = E_In_Out_Parameter and then not Check_Unreferenced_Formals then return; end if; -- Other than accept case, post error on defining identifier if No (Anod) then Error_Msg_N (M, E1); -- Accept case, find body formal to post the message else Error_Msg_NE (M, Body_Formal (E1, Accept_Statement => Anod), E1); end if; end Output_Reference_Error; ---------------------------- -- Publicly_Referenceable -- ---------------------------- function Publicly_Referenceable (Ent : Entity_Id) return Boolean is P : Node_Id; Prev : Node_Id; begin -- A formal parameter is never referenceable outside the body of its -- subprogram or entry. if Is_Formal (Ent) then return False; end if; -- Examine parents to look for a library level package spec. But if -- we find a body or block or other similar construct along the way, -- we cannot be referenced. Prev := Ent; P := Parent (Ent); loop case Nkind (P) is -- If we get to top of tree, then publicly referenceable when N_Empty => return True; -- If we reach a generic package declaration, then always -- consider this referenceable, since any instantiation will -- have access to the entities in the generic package. Note -- that the package itself may not be instantiated, but then -- we will get a warning for the package entity. -- Note that generic formal parameters are themselves not -- publicly referenceable in an instance, and warnings on them -- are useful. when N_Generic_Package_Declaration => return not Is_List_Member (Prev) or else List_Containing (Prev) /= Generic_Formal_Declarations (P); -- Similarly, the generic formals of a generic subprogram are -- not accessible. when N_Generic_Subprogram_Declaration => if Is_List_Member (Prev) and then List_Containing (Prev) = Generic_Formal_Declarations (P) then return False; else P := Parent (P); end if; -- If we reach a subprogram body, entity is not referenceable -- unless it is the defining entity of the body. This will -- happen, e.g. when a function is an attribute renaming that -- is rewritten as a body. when N_Subprogram_Body => if Ent /= Defining_Entity (P) then return False; else P := Parent (P); end if; -- If we reach any other body, definitely not referenceable when N_Block_Statement | N_Entry_Body | N_Package_Body | N_Protected_Body | N_Subunit | N_Task_Body => return False; -- For all other cases, keep looking up tree when others => Prev := P; P := Parent (P); end case; end loop; end Publicly_Referenceable; --------------------- -- Warnings_Off_E1 -- --------------------- function Warnings_Off_E1 return Boolean is begin return Has_Warnings_Off (E1T) or else Has_Warnings_Off (Base_Type (E1T)) or else Warnings_Off_Check_Spec (E1); end Warnings_Off_E1; -- Start of processing for Check_References begin Process_Deferred_References; -- No messages if warnings are suppressed, or if we have detected any -- real errors so far (this last check avoids junk messages resulting -- from errors, e.g. a subunit that is not loaded). if Warning_Mode = Suppress or else Serious_Errors_Detected /= 0 then return; end if; -- We also skip the messages if any subunits were not loaded (see -- comment in Sem_Ch10 to understand how this is set, and why it is -- necessary to suppress the warnings in this case). if Missing_Subunits then return; end if; -- Otherwise loop through entities, looking for suspicious stuff E1 := First_Entity (E); while Present (E1) loop E1T := Etype (E1); -- We are only interested in source entities. We also don't issue -- warnings within instances, since the proper place for such -- warnings is on the template when it is compiled, and we don't -- issue warnings for variables with names like Junk, Discard etc. if Comes_From_Source (E1) and then Instantiation_Location (Sloc (E1)) = No_Location then -- We are interested in variables and out/in-out parameters, but -- we exclude protected types, too complicated to worry about. if Ekind (E1) = E_Variable or else (Ekind (E1) in E_Out_Parameter | E_In_Out_Parameter and then not Is_Protected_Type (Current_Scope)) then -- If the formal has a class-wide type, retrieve its type -- because checks below depend on its private nature. if Is_Class_Wide_Type (E1T) then E1T := Etype (E1T); end if; -- Case of an unassigned variable -- First gather any Unset_Reference indication for E1. In the -- case of a parameter, it is the Spec_Entity that is relevant. if Ekind (E1) = E_Out_Parameter and then Present (Spec_Entity (E1)) then UR := Unset_Reference (Spec_Entity (E1)); else UR := Unset_Reference (E1); end if; -- Special processing for access types if Present (UR) and then Is_Access_Type (E1T) then -- For access types, the only time we made a UR entry was -- for a dereference, and so we post the appropriate warning -- here (note that the dereference may not be explicit in -- the source, for example in the case of a dispatching call -- with an anonymous access controlling formal, or of an -- assignment of a pointer involving discriminant check on -- the designated object). if not Warnings_Off_E1 then Error_Msg_NE ("??& may be null!", UR, E1); end if; goto Continue; -- Case of variable that could be a constant. Note that we -- never signal such messages for generic package entities, -- since a given instance could have modifications outside -- the package. -- Note that we used to check Address_Taken here, but we don't -- want to do that since it can be set for non-source cases, -- e.g. the Unrestricted_Access from a valid attribute, and -- the wanted effect is included in Never_Set_In_Source. elsif Warn_On_Constant and then (Ekind (E1) = E_Variable and then Has_Initial_Value (E1)) and then Never_Set_In_Source_Check_Spec (E1) and then not Generic_Package_Spec_Entity (E1) then -- A special case, if this variable is volatile and not -- imported, it is not helpful to tell the programmer -- to mark the variable as constant, since this would be -- illegal by virtue of RM C.6(13). Instead we suggest -- using pragma Export (can't be Import because of the -- initial value). if (Is_Volatile (E1) or else Has_Volatile_Components (E1)) and then not Is_Imported (E1) then Error_Msg_N ("?k?& is not modified, consider pragma Export for " & "volatile variable!", E1); -- Another special case, Exception_Occurrence, this catches -- the case of exception choice (and a bit more too, but not -- worth doing more investigation here). elsif Is_RTE (E1T, RE_Exception_Occurrence) then null; -- Here we give the warning if referenced and no pragma -- Unreferenced or Unmodified is present. else -- Variable case if Ekind (E1) = E_Variable then if Referenced_Check_Spec (E1) and then not Has_Pragma_Unreferenced_Check_Spec (E1) and then not Has_Pragma_Unmodified_Check_Spec (E1) then if not Warnings_Off_E1 and then not Has_Junk_Name (E1) then Error_Msg_N -- CODEFIX ("?k?& is not modified, " & "could be declared constant!", E1); end if; end if; end if; end if; -- Other cases of a variable or parameter never set in source elsif Never_Set_In_Source_Check_Spec (E1) -- No warning if warning for this case turned off and then Warn_On_No_Value_Assigned -- No warning if address taken somewhere and then not Address_Taken (E1) -- No warning if explicit initial value and then not Has_Initial_Value (E1) -- No warning for generic package spec entities, since we -- might set them in a child unit or something like that and then not Generic_Package_Spec_Entity (E1) -- No warning if fully initialized type, except that for -- this purpose we do not consider access types to qualify -- as fully initialized types (relying on an access type -- variable being null when it is never set is a bit odd). -- Also we generate warning for an out parameter that is -- never referenced, since again it seems odd to rely on -- default initialization to set an out parameter value. and then (Is_Access_Type (E1T) or else Ekind (E1) = E_Out_Parameter or else not Is_Fully_Initialized_Type (E1T)) then -- Do not output complaint about never being assigned a -- value if a pragma Unmodified applies to the variable -- we are examining, or if it is a parameter, if there is -- a pragma Unreferenced for the corresponding spec, or -- if the type is marked as having unreferenced objects. -- The last is a little peculiar, but better too few than -- too many warnings in this situation. if Has_Pragma_Unreferenced_Objects (E1T) or else Has_Pragma_Unmodified_Check_Spec (E1) then null; -- IN OUT parameter case where parameter is referenced. We -- separate this out, since this is the case where we delay -- output of the warning until more information is available -- (about use in an instantiation or address being taken). elsif Ekind (E1) = E_In_Out_Parameter and then Referenced_Check_Spec (E1) then -- Suppress warning if private type, and the procedure -- has a separate declaration in a different unit. This -- is the case where the client of a package sees only -- the private type, and it may be quite reasonable -- for the logical view to be IN OUT, even if the -- implementation ends up using access types or some -- other method to achieve the local effect of a -- modification. On the other hand if the spec and body -- are in the same unit, we are in the package body and -- there we have less excuse for a junk IN OUT parameter. if Has_Private_Declaration (E1T) and then Present (Spec_Entity (E1)) and then not In_Same_Source_Unit (E1, Spec_Entity (E1)) then null; -- Suppress warning for any parameter of a dispatching -- operation, since it is quite reasonable to have an -- operation that is overridden, and for some subclasses -- needs the formal to be IN OUT and for others happens -- not to assign it. elsif Is_Dispatching_Operation (Scope (Goto_Spec_Entity (E1))) then null; -- Suppress warning if composite type contains any access -- component, since the logical effect of modifying a -- parameter may be achieved by modifying a referenced -- object. elsif Is_Composite_Type (E1T) and then Has_Access_Values (E1T) then null; -- Suppress warning on formals of an entry body. All -- references are attached to the formal in the entry -- declaration, which are marked Is_Entry_Formal. elsif Ekind (Scope (E1)) = E_Entry and then not Is_Entry_Formal (E1) then null; -- OK, looks like warning for an IN OUT parameter that -- could be IN makes sense, but we delay the output of -- the warning, pending possibly finding out later on -- that the associated subprogram is used as a generic -- actual, or its address/access is taken. In these two -- cases, we suppress the warning because the context may -- force use of IN OUT, even if in this particular case -- the formal is not modified. else -- Suppress the warnings for a junk name if not Has_Junk_Name (E1) then In_Out_Warnings.Append (E1); end if; end if; -- Other cases of formals elsif Is_Formal (E1) then if not Is_Trivial_Subprogram (Scope (E1)) then if Referenced_Check_Spec (E1) then if not Has_Pragma_Unmodified_Check_Spec (E1) and then not Warnings_Off_E1 and then not Has_Junk_Name (E1) then Output_Reference_Error ("?f?formal parameter& is read but " & "never assigned!"); end if; elsif not Has_Pragma_Unreferenced_Check_Spec (E1) and then not Warnings_Off_E1 and then not Has_Junk_Name (E1) then Output_Reference_Error ("?f?formal parameter& is not referenced!"); end if; end if; -- Case of variable else if Referenced (E1) then if not Has_Unmodified (E1) and then not Warnings_Off_E1 and then not Has_Junk_Name (E1) then if Is_Access_Type (E1T) or else not Is_Partially_Initialized_Type (E1T, False) then Output_Reference_Error ("?v?variable& is read but never assigned!"); end if; May_Need_Initialized_Actual (E1); end if; elsif not Has_Unreferenced (E1) and then not Warnings_Off_E1 and then not Has_Junk_Name (E1) then Output_Reference_Error -- CODEFIX ("?v?variable& is never read and never assigned!"); end if; -- Deal with special case where this variable is hidden -- by a loop variable. if Ekind (E1) = E_Variable and then Present (Hiding_Loop_Variable (E1)) and then not Warnings_Off_E1 then Error_Msg_N ("?v?for loop implicitly declares loop variable!", Hiding_Loop_Variable (E1)); Error_Msg_Sloc := Sloc (E1); Error_Msg_N ("\?v?declaration hides & declared#!", Hiding_Loop_Variable (E1)); end if; end if; goto Continue; end if; -- Check for unset reference. If type of object has -- preelaborable initialization, warning is misleading. if Warn_On_No_Value_Assigned and then Present (UR) and then not Known_To_Have_Preelab_Init (Etype (E1)) then -- For other than access type, go back to original node to -- deal with case where original unset reference has been -- rewritten during expansion. -- In some cases, the original node may be a type -- conversion, a qualification or an attribute reference and -- in this case we want the object entity inside. Same for -- an expression with actions. UR := Original_Node (UR); loop if Nkind (UR) in N_Expression_With_Actions | N_Qualified_Expression | N_Type_Conversion then UR := Expression (UR); elsif Nkind (UR) = N_Attribute_Reference then UR := Prefix (UR); else exit; end if; end loop; -- Don't issue warning if appearing inside Initial_Condition -- pragma or aspect, since that expression is not evaluated -- at the point where it occurs in the source. if In_Pragma_Expression (UR, Name_Initial_Condition) then goto Continue; end if; -- Here we issue the warning, all checks completed -- If we have a return statement, this was a case of an OUT -- parameter not being set at the time of the return. (Note: -- it can't be N_Extended_Return_Statement, because those -- are only for functions, and functions do not allow OUT -- parameters.) if not Is_Trivial_Subprogram (Scope (E1)) then if Nkind (UR) = N_Simple_Return_Statement and then not Has_Pragma_Unmodified_Check_Spec (E1) then if not Warnings_Off_E1 and then not Has_Junk_Name (E1) then Error_Msg_NE ("?v?OUT parameter& not set before return", UR, E1); end if; -- If the unset reference is a selected component -- prefix from source, mention the component as well. -- If the selected component comes from expansion, all -- we know is that the entity is not fully initialized -- at the point of the reference. Locate a random -- uninitialized component to get a better message. elsif Nkind (Parent (UR)) = N_Selected_Component then Error_Msg_Node_2 := Selector_Name (Parent (UR)); if not Comes_From_Source (Parent (UR)) then declare Comp : Entity_Id; begin Comp := First_Entity (E1T); while Present (Comp) loop if Ekind (Comp) = E_Component and then Nkind (Parent (Comp)) = N_Component_Declaration and then No (Expression (Parent (Comp))) then Error_Msg_Node_2 := Comp; exit; end if; Next_Entity (Comp); end loop; end; end if; -- Issue proper warning. This is a case of referencing -- a variable before it has been explicitly assigned. -- For access types, UR was only set for dereferences, -- so the issue is that the value may be null. if not Is_Trivial_Subprogram (Scope (E1)) then if not Warnings_Off_E1 then if Is_Access_Type (Etype (Parent (UR))) then Error_Msg_N ("??`&.&` may be null!", UR); else Error_Msg_N ("??`&.&` may be referenced before " & "it has a value!", UR); end if; end if; end if; -- All other cases of unset reference active elsif not Warnings_Off_E1 then Error_Msg_N ("??& may be referenced before it has a value!", UR); end if; end if; goto Continue; end if; end if; -- Then check for unreferenced entities. Note that we are only -- interested in entities whose Referenced flag is not set. if not Referenced_Check_Spec (E1) -- If Referenced_As_LHS is set, then that's still interesting -- (potential "assigned but never read" case), but not if we -- have pragma Unreferenced, which cancels this warning. and then (not Referenced_As_LHS_Check_Spec (E1) or else not Has_Unreferenced (E1)) -- Check that warnings on unreferenced entities are enabled and then ((Check_Unreferenced and then not Is_Formal (E1)) -- Case of warning on unreferenced formal or else (Check_Unreferenced_Formals and then Is_Formal (E1)) -- Case of warning on unread variables modified by an -- assignment, or an OUT parameter if it is the only one. or else (Warn_On_Modified_Unread and then Referenced_As_LHS_Check_Spec (E1)) -- Case of warning on any unread OUT parameter (note such -- indications are only set if the appropriate warning -- options were set, so no need to recheck here.) or else Referenced_As_Out_Parameter_Check_Spec (E1)) -- All other entities, including local packages that cannot be -- referenced from elsewhere, including those declared within a -- package body. and then (Is_Object (E1) or else Is_Type (E1) or else Ekind (E1) = E_Label or else Ekind (E1) in E_Exception | E_Named_Integer | E_Named_Real or else Is_Overloadable (E1) -- Package case, if the main unit is a package spec -- or generic package spec, then there may be a -- corresponding body that references this package -- in some other file. Otherwise we can be sure -- that there is no other reference. or else (Ekind (E1) = E_Package and then not Is_Package_Or_Generic_Package (Cunit_Entity (Current_Sem_Unit)))) -- Exclude instantiations, since there is no reason why every -- entity in an instantiation should be referenced. and then Instantiation_Location (Sloc (E1)) = No_Location -- Exclude formal parameters from bodies if the corresponding -- spec entity has been referenced in the case where there is -- a separate spec. and then not (Is_Formal (E1) and then Ekind (Scope (E1)) = E_Subprogram_Body and then Present (Spec_Entity (E1)) and then Referenced (Spec_Entity (E1))) -- Consider private type referenced if full view is referenced. -- If there is not full view, this is a generic type on which -- warnings are also useful. and then not (Is_Private_Type (E1) and then Present (Full_View (E1)) and then Referenced (Full_View (E1))) -- Don't worry about full view, only about private type and then not Has_Private_Declaration (E1) -- Eliminate dispatching operations from consideration, we -- cannot tell if these are referenced or not in any easy -- manner (note this also catches Adjust/Finalize/Initialize). and then not Is_Dispatching_Operation (E1) -- Check entity that can be publicly referenced (we do not give -- messages for such entities, since there could be other -- units, not involved in this compilation, that contain -- relevant references. and then not Publicly_Referenceable (E1) -- Class wide types are marked as source entities, but they are -- not really source entities, and are always created, so we do -- not care if they are not referenced. and then Ekind (E1) /= E_Class_Wide_Type -- Objects other than parameters of task types are allowed to -- be non-referenced, since they start up tasks. and then ((Ekind (E1) /= E_Variable and then Ekind (E1) /= E_Constant and then Ekind (E1) /= E_Component) or else not Is_Task_Type (E1T)) -- For subunits, only place warnings on the main unit itself, -- since parent units are not completely compiled. and then (Nkind (Unit (Cunit (Main_Unit))) /= N_Subunit or else Get_Source_Unit (E1) = Main_Unit) -- No warning on a return object, because these are often -- created with a single expression and an implicit return. -- If the object is a variable there will be a warning -- indicating that it could be declared constant. and then not (Ekind (E1) = E_Constant and then Is_Return_Object (E1)) then -- Suppress warnings in internal units if not in -gnatg mode -- (these would be junk warnings for an applications program, -- since they refer to problems in internal units). if GNAT_Mode or else not In_Internal_Unit (E1) then -- We do not immediately flag the error. This is because we -- have not expanded generic bodies yet, and they may have -- the missing reference. So instead we park the entity on a -- list, for later processing. However for the case of an -- accept statement we want to output messages now, since -- we know we already have all information at hand, and we -- also want to have separate warnings for each accept -- statement for the same entry. if Present (Anod) then pragma Assert (Is_Formal (E1)); -- The unreferenced entity is E1, but post the warning -- on the body entity for this accept statement. if not Warnings_Off_E1 then Warn_On_Unreferenced_Entity (E1, Body_Formal (E1, Accept_Statement => Anod)); end if; elsif not Warnings_Off_E1 and then not Has_Junk_Name (E1) then if Is_Formal (E1) and then Nkind (Unit_Declaration_Node (Scope (E1))) = N_Generic_Subprogram_Declaration then Unreferenced_Entities.Append (Generic_Body_Formal (E1)); else Unreferenced_Entities.Append (E1); end if; end if; end if; -- Generic units are referenced in the generic body, but if they -- are not public and never instantiated we want to force a -- warning on them. We treat them as redundant constructs to -- minimize noise. elsif Is_Generic_Subprogram (E1) and then not Is_Instantiated (E1) and then not Publicly_Referenceable (E1) and then Instantiation_Depth (Sloc (E1)) = 0 and then Warn_On_Redundant_Constructs then if not Warnings_Off_E1 and then not Has_Junk_Name (E1) then Unreferenced_Entities.Append (E1); -- Force warning on entity Set_Referenced (E1, False); end if; end if; end if; -- Recurse into nested package or block. Do not recurse into a formal -- package, because the corresponding body is not analyzed. <<Continue>> if (Is_Package_Or_Generic_Package (E1) and then Nkind (Parent (E1)) = N_Package_Specification and then Nkind (Original_Node (Unit_Declaration_Node (E1))) /= N_Formal_Package_Declaration) or else Ekind (E1) = E_Block then Check_References (E1); end if; Next_Entity (E1); end loop; end Check_References; --------------------------- -- Check_Unset_Reference -- --------------------------- procedure Check_Unset_Reference (N : Node_Id) is Typ : constant Entity_Id := Etype (N); function Is_OK_Fully_Initialized return Boolean; -- This function returns true if the given node N is fully initialized -- so that the reference is safe as far as this routine is concerned. -- Safe generally means that the type of N is a fully initialized type. -- The one special case is that for access types, which are always fully -- initialized, we don't consider a dereference OK since it will surely -- be dereferencing a null value, which won't do. function Prefix_Has_Dereference (Pref : Node_Id) return Boolean; -- Used to test indexed or selected component or slice to see if the -- evaluation of the prefix depends on a dereference, and if so, returns -- True, in which case we always check the prefix, even if we know that -- the referenced component is initialized. Pref is the prefix to test. ----------------------------- -- Is_OK_Fully_Initialized -- ----------------------------- function Is_OK_Fully_Initialized return Boolean is begin if Is_Access_Type (Typ) and then Is_Dereferenced (N) then return False; -- A type subject to pragma Default_Initial_Condition may be fully -- default initialized depending on inheritance and the argument of -- the pragma (SPARK RM 3.1 and SPARK RM 7.3.3). elsif Has_Fully_Default_Initializing_DIC_Pragma (Typ) then return True; else return Is_Fully_Initialized_Type (Typ); end if; end Is_OK_Fully_Initialized; ---------------------------- -- Prefix_Has_Dereference -- ---------------------------- function Prefix_Has_Dereference (Pref : Node_Id) return Boolean is begin -- If prefix is of an access type, it certainly needs a dereference if Is_Access_Type (Etype (Pref)) then return True; -- If prefix is explicit dereference, that's a dereference for sure elsif Nkind (Pref) = N_Explicit_Dereference then return True; -- If prefix is itself a component reference or slice check prefix elsif Nkind (Pref) = N_Slice or else Nkind (Pref) = N_Indexed_Component or else Nkind (Pref) = N_Selected_Component then return Prefix_Has_Dereference (Prefix (Pref)); -- All other cases do not involve a dereference else return False; end if; end Prefix_Has_Dereference; -- Start of processing for Check_Unset_Reference begin -- Nothing to do if warnings suppressed if Warning_Mode = Suppress then return; end if; -- Nothing to do for numeric or string literal. Do this test early to -- save time in a common case (it does not matter that we do not include -- character literal here, since that will be caught later on in the -- when others branch of the case statement). if Nkind (N) in N_Numeric_Or_String_Literal then return; end if; -- Ignore reference unless it comes from source. Almost always if we -- have a reference from generated code, it is bogus (e.g. calls to init -- procs to set default discriminant values). if not Comes_From_Source (Original_Node (N)) then return; end if; -- Otherwise see what kind of node we have. If the entity already has an -- unset reference, it is not necessarily the earliest in the text, -- because resolution of the prefix of selected components is completed -- before the resolution of the selected component itself. As a result, -- given (R /= null and then R.X > 0), the occurrences of R are examined -- in right-to-left order. If there is already an unset reference, we -- check whether N is earlier before proceeding. case Nkind (N) is -- For identifier or expanded name, examine the entity involved when N_Expanded_Name | N_Identifier => declare E : constant Entity_Id := Entity (N); begin if Ekind (E) in E_Variable | E_Out_Parameter and then Never_Set_In_Source_Check_Spec (E) and then not Has_Initial_Value (E) and then (No (Unset_Reference (E)) or else Earlier_In_Extended_Unit (Sloc (N), Sloc (Unset_Reference (E)))) and then not Has_Pragma_Unmodified_Check_Spec (E) and then not Warnings_Off_Check_Spec (E) and then not Has_Junk_Name (E) then -- We may have an unset reference. The first test is whether -- this is an access to a discriminant of a record or a -- component with default initialization. Both of these -- cases can be ignored, since the actual object that is -- referenced is definitely initialized. Note that this -- covers the case of reading discriminants of an OUT -- parameter, which is OK even in Ada 83. -- Note that we are only interested in a direct reference to -- a record component here. If the reference is through an -- access type, then the access object is being referenced, -- not the record, and still deserves an unset reference. if Nkind (Parent (N)) = N_Selected_Component and not Is_Access_Type (Typ) then declare ES : constant Entity_Id := Entity (Selector_Name (Parent (N))); begin if Ekind (ES) = E_Discriminant or else (Present (Declaration_Node (ES)) and then Present (Expression (Declaration_Node (ES)))) then return; end if; end; end if; -- Exclude fully initialized types if Is_OK_Fully_Initialized then return; end if; -- Here we have a potential unset reference. But before we -- get worried about it, we have to make sure that the -- entity declaration is in the same procedure as the -- reference, since if they are in separate procedures, then -- we have no idea about sequential execution. -- The tests in the loop below catch all such cases, but do -- allow the reference to appear in a loop, block, or -- package spec that is nested within the declaring scope. -- As always, it is possible to construct cases where the -- warning is wrong, that is why it is a warning. Potential_Unset_Reference : declare SR : Entity_Id; SE : constant Entity_Id := Scope (E); function Within_Postcondition return Boolean; -- Returns True if N is within a Postcondition, a -- Refined_Post, an Ensures component in a Test_Case, -- or a Contract_Cases. -------------------------- -- Within_Postcondition -- -------------------------- function Within_Postcondition return Boolean is Nod, P : Node_Id; begin Nod := Parent (N); while Present (Nod) loop if Nkind (Nod) = N_Pragma and then Pragma_Name_Unmapped (Nod) in Name_Postcondition | Name_Refined_Post | Name_Contract_Cases then return True; elsif Present (Parent (Nod)) then P := Parent (Nod); if Nkind (P) = N_Pragma and then Pragma_Name (P) = Name_Test_Case and then Nod = Test_Case_Arg (P, Name_Ensures) then return True; end if; end if; Nod := Parent (Nod); end loop; return False; end Within_Postcondition; -- Start of processing for Potential_Unset_Reference begin SR := Current_Scope; while SR /= SE loop if SR = Standard_Standard or else Is_Subprogram (SR) or else Is_Concurrent_Body (SR) or else Is_Concurrent_Type (SR) then return; end if; SR := Scope (SR); end loop; -- Case of reference has an access type. This is a -- special case since access types are always set to null -- so cannot be truly uninitialized, but we still want to -- warn about cases of obvious null dereference. if Is_Access_Type (Typ) then Access_Type_Case : declare P : Node_Id; function Process (N : Node_Id) return Traverse_Result; -- Process function for instantiation of Traverse -- below. Checks if N contains reference to E other -- than a dereference. function Ref_In (Nod : Node_Id) return Boolean; -- Determines whether Nod contains a reference to -- the entity E that is not a dereference. ------------- -- Process -- ------------- function Process (N : Node_Id) return Traverse_Result is begin if Is_Entity_Name (N) and then Entity (N) = E and then not Is_Dereferenced (N) then return Abandon; else return OK; end if; end Process; ------------ -- Ref_In -- ------------ function Ref_In (Nod : Node_Id) return Boolean is function Traverse is new Traverse_Func (Process); begin return Traverse (Nod) = Abandon; end Ref_In; -- Start of processing for Access_Type_Case begin -- Don't bother if we are inside an instance, since -- the compilation of the generic template is where -- the warning should be issued. if In_Instance then return; end if; -- Don't bother if this is not the main unit. If we -- try to give this warning for with'ed units, we -- get some false positives, since we do not record -- references in other units. if not In_Extended_Main_Source_Unit (E) or else not In_Extended_Main_Source_Unit (N) then return; end if; -- We are only interested in dereferences if not Is_Dereferenced (N) then return; end if; -- One more check, don't bother with references -- that are inside conditional statements or WHILE -- loops if the condition references the entity in -- question. This avoids most false positives. P := Parent (N); loop P := Parent (P); exit when No (P); if Nkind (P) in N_If_Statement | N_Elsif_Part and then Ref_In (Condition (P)) then return; elsif Nkind (P) = N_Loop_Statement and then Present (Iteration_Scheme (P)) and then Ref_In (Condition (Iteration_Scheme (P))) then return; end if; end loop; end Access_Type_Case; end if; -- One more check, don't bother if we are within a -- postcondition, since the expression occurs in a -- place unrelated to the actual test. if not Within_Postcondition then -- Here we definitely have a case for giving a warning -- for a reference to an unset value. But we don't -- give the warning now. Instead set Unset_Reference -- in the identifier involved. The reason for this is -- that if we find the variable is never ever assigned -- a value then that warning is more important and -- there is no point in giving the reference warning. -- If this is an identifier, set the field directly if Nkind (N) = N_Identifier then Set_Unset_Reference (E, N); -- Otherwise it is an expanded name, so set the field -- of the actual identifier for the reference. else Set_Unset_Reference (E, Selector_Name (N)); end if; end if; end Potential_Unset_Reference; end if; end; -- Indexed component or slice when N_Indexed_Component | N_Slice => -- If prefix does not involve dereferencing an access type, then -- we know we are OK if the component type is fully initialized, -- since the component will have been set as part of the default -- initialization. if not Prefix_Has_Dereference (Prefix (N)) and then Is_OK_Fully_Initialized then return; -- Look at prefix in access type case, or if the component is not -- fully initialized. else Check_Unset_Reference (Prefix (N)); end if; -- Record component when N_Selected_Component => declare Pref : constant Node_Id := Prefix (N); Ent : constant Entity_Id := Entity (Selector_Name (N)); begin -- If prefix involves dereferencing an access type, always -- check the prefix, since the issue then is whether this -- access value is null. if Prefix_Has_Dereference (Pref) then null; -- Always go to prefix if no selector entity is set. Can this -- happen in the normal case? Not clear, but it definitely can -- happen in error cases. elsif No (Ent) then null; -- For a record component, check some cases where we have -- reasonable cause to consider that the component is known to -- be or probably is initialized. In this case, we don't care -- if the prefix itself was explicitly initialized. -- Discriminants are always considered initialized elsif Ekind (Ent) = E_Discriminant then return; -- An explicitly initialized component is certainly initialized elsif Nkind (Parent (Ent)) = N_Component_Declaration and then Present (Expression (Parent (Ent))) then return; -- A fully initialized component is initialized elsif Is_OK_Fully_Initialized then return; end if; -- If none of those cases apply, check the record type prefix Check_Unset_Reference (Pref); end; -- For type conversions, qualifications, or expressions with actions, -- examine the expression. when N_Expression_With_Actions | N_Qualified_Expression | N_Type_Conversion => Check_Unset_Reference (Expression (N)); -- For explicit dereference, always check prefix, which will generate -- an unset reference (since this is a case of dereferencing null). when N_Explicit_Dereference => Check_Unset_Reference (Prefix (N)); -- All other cases are not cases of an unset reference when others => null; end case; end Check_Unset_Reference; ------------------------ -- Check_Unused_Withs -- ------------------------ procedure Check_Unused_Withs (Spec_Unit : Unit_Number_Type := No_Unit) is Cnode : Node_Id; Item : Node_Id; Lunit : Node_Id; Ent : Entity_Id; Munite : constant Entity_Id := Cunit_Entity (Main_Unit); -- This is needed for checking the special renaming case procedure Check_One_Unit (Unit : Unit_Number_Type); -- Subsidiary procedure, performs checks for specified unit -------------------- -- Check_One_Unit -- -------------------- procedure Check_One_Unit (Unit : Unit_Number_Type) is Is_Visible_Renaming : Boolean := False; Pack : Entity_Id; procedure Check_Inner_Package (Pack : Entity_Id); -- Pack is a package local to a unit in a with_clause. Both the unit -- and Pack are referenced. If none of the entities in Pack are -- referenced, then the only occurrence of Pack is in a USE clause -- or a pragma, and a warning is worthwhile as well. function Check_System_Aux return Boolean; -- Before giving a warning on a with_clause for System, check whether -- a system extension is present. function Find_Package_Renaming (P : Entity_Id; L : Entity_Id) return Entity_Id; -- The only reference to a context unit may be in a renaming -- declaration. If this renaming declares a visible entity, do not -- warn that the context clause could be moved to the body, because -- the renaming may be intended to re-export the unit. function Has_Visible_Entities (P : Entity_Id) return Boolean; -- This function determines if a package has any visible entities. -- True is returned if there is at least one declared visible entity, -- otherwise False is returned (e.g. case of only pragmas present). ------------------------- -- Check_Inner_Package -- ------------------------- procedure Check_Inner_Package (Pack : Entity_Id) is E : Entity_Id; Un : constant Node_Id := Sinfo.Unit (Cnode); function Check_Use_Clause (N : Node_Id) return Traverse_Result; -- If N is a use_clause for Pack, emit warning procedure Check_Use_Clauses is new Traverse_Proc (Check_Use_Clause); ---------------------- -- Check_Use_Clause -- ---------------------- function Check_Use_Clause (N : Node_Id) return Traverse_Result is begin if Nkind (N) = N_Use_Package_Clause and then Entity (Name (N)) = Pack then -- Suppress message if any serious errors detected that turn -- off expansion, and thus result in false positives for -- this warning. if Serious_Errors_Detected = 0 then Error_Msg_Qual_Level := 1; Error_Msg_NE -- CODEFIX ("?u?no entities of package& are referenced!", Name (N), Pack); Error_Msg_Qual_Level := 0; end if; end if; return OK; end Check_Use_Clause; -- Start of processing for Check_Inner_Package begin E := First_Entity (Pack); while Present (E) loop if Referenced_Check_Spec (E) then return; end if; Next_Entity (E); end loop; -- No entities of the package are referenced. Check whether the -- reference to the package itself is a use clause, and if so -- place a warning on it. Check_Use_Clauses (Un); end Check_Inner_Package; ---------------------- -- Check_System_Aux -- ---------------------- function Check_System_Aux return Boolean is Ent : Entity_Id; begin if Chars (Lunit) = Name_System and then Scope (Lunit) = Standard_Standard and then Present_System_Aux then Ent := First_Entity (System_Aux_Id); while Present (Ent) loop if Referenced_Check_Spec (Ent) then return True; end if; Next_Entity (Ent); end loop; end if; return False; end Check_System_Aux; --------------------------- -- Find_Package_Renaming -- --------------------------- function Find_Package_Renaming (P : Entity_Id; L : Entity_Id) return Entity_Id is E1 : Entity_Id; R : Entity_Id; begin Is_Visible_Renaming := False; E1 := First_Entity (P); while Present (E1) loop if Ekind (E1) = E_Package and then Renamed_Object (E1) = L then Is_Visible_Renaming := not Is_Hidden (E1); return E1; elsif Ekind (E1) = E_Package and then No (Renamed_Object (E1)) and then not Is_Generic_Instance (E1) then R := Find_Package_Renaming (E1, L); if Present (R) then Is_Visible_Renaming := not Is_Hidden (R); return R; end if; end if; Next_Entity (E1); end loop; return Empty; end Find_Package_Renaming; -------------------------- -- Has_Visible_Entities -- -------------------------- function Has_Visible_Entities (P : Entity_Id) return Boolean is E : Entity_Id; begin -- If unit in context is not a package, it is a subprogram that -- is not called or a generic unit that is not instantiated -- in the current unit, and warning is appropriate. if Ekind (P) /= E_Package then return True; end if; -- If unit comes from a limited_with clause, look for declaration -- of shadow entities. if Present (Limited_View (P)) then E := First_Entity (Limited_View (P)); else E := First_Entity (P); end if; while Present (E) and then E /= First_Private_Entity (P) loop if Comes_From_Source (E) or else Present (Limited_View (P)) then return True; end if; Next_Entity (E); end loop; return False; end Has_Visible_Entities; -- Start of processing for Check_One_Unit begin Cnode := Cunit (Unit); -- Only do check in units that are part of the extended main unit. -- This is actually a necessary restriction, because in the case of -- subprogram acting as its own specification, there can be with's in -- subunits that we will not see. if not In_Extended_Main_Source_Unit (Cnode) then return; end if; -- Loop through context items in this unit Item := First (Context_Items (Cnode)); while Present (Item) loop if Nkind (Item) = N_With_Clause and then not Implicit_With (Item) and then In_Extended_Main_Source_Unit (Item) -- Guard for no entity present. Not clear under what conditions -- this happens, but it does occur, and since this is only a -- warning, we just suppress the warning in this case. and then Nkind (Name (Item)) in N_Has_Entity and then Present (Entity (Name (Item))) then Lunit := Entity (Name (Item)); -- Check if this unit is referenced (skip the check if this -- is explicitly marked by a pragma Unreferenced). if not Referenced (Lunit) and then not Has_Unreferenced (Lunit) then -- Suppress warnings in internal units if not in -gnatg mode -- (these would be junk warnings for an application program, -- since they refer to problems in internal units). if GNAT_Mode or else not Is_Internal_Unit (Unit) then -- Here we definitely have a non-referenced unit. If it -- is the special call for a spec unit, then just set the -- flag to be read later. if Unit = Spec_Unit then Set_Unreferenced_In_Spec (Item); -- Otherwise simple unreferenced message, but skip this -- if no visible entities, because that is most likely a -- case where warning would be false positive (e.g. a -- package with only a linker options pragma and nothing -- else or a pragma elaborate with a body library task). elsif Has_Visible_Entities (Entity (Name (Item))) then Error_Msg_N -- CODEFIX ("?u?unit& is not referenced!", Name (Item)); end if; end if; -- If main unit is a renaming of this unit, then we consider -- the with to be OK (obviously it is needed in this case). -- This may be transitive: the unit in the with_clause may -- itself be a renaming, in which case both it and the main -- unit rename the same ultimate package. elsif Present (Renamed_Entity (Munite)) and then (Renamed_Entity (Munite) = Lunit or else Renamed_Entity (Munite) = Renamed_Entity (Lunit)) then null; -- If this unit is referenced, and it is a package, we do -- another test, to see if any of the entities in the package -- are referenced. If none of the entities are referenced, we -- still post a warning. This occurs if the only use of the -- package is in a use clause, or in a package renaming -- declaration. This check is skipped for packages that are -- renamed in a spec, since the entities in such a package are -- visible to clients via the renaming. elsif Ekind (Lunit) = E_Package and then not Renamed_In_Spec (Lunit) then -- If Is_Instantiated is set, it means that the package is -- implicitly instantiated (this is the case of parent -- instance or an actual for a generic package formal), and -- this counts as a reference. if Is_Instantiated (Lunit) then null; -- If no entities in package, and there is a pragma -- Elaborate_Body present, then assume that this with is -- done for purposes of this elaboration. elsif No (First_Entity (Lunit)) and then Has_Pragma_Elaborate_Body (Lunit) then null; -- Otherwise see if any entities have been referenced else if Limited_Present (Item) then Ent := First_Entity (Limited_View (Lunit)); else Ent := First_Entity (Lunit); end if; loop -- No more entities, and we did not find one that was -- referenced. Means we have a definite case of a with -- none of whose entities was referenced. if No (Ent) then -- If in spec, just set the flag if Unit = Spec_Unit then Set_No_Entities_Ref_In_Spec (Item); elsif Check_System_Aux then null; -- Else the warning may be needed else declare Eitem : constant Entity_Id := Entity (Name (Item)); begin -- Warn if we unreferenced flag set and we -- have not had serious errors. The reason we -- inhibit the message if there are errors is -- to prevent false positives from disabling -- expansion. if not Has_Unreferenced (Eitem) and then Serious_Errors_Detected = 0 then -- Get possible package renaming Pack := Find_Package_Renaming (Munite, Lunit); -- No warning if either the package or its -- renaming is used as a generic actual. if Used_As_Generic_Actual (Eitem) or else (Present (Pack) and then Used_As_Generic_Actual (Pack)) then exit; end if; -- Here we give the warning Error_Msg_N -- CODEFIX ("?u?no entities of & are referenced!", Name (Item)); -- Flag renaming of package as well. If -- the original package has warnings off, -- we suppress the warning on the renaming -- as well. if Present (Pack) and then not Has_Warnings_Off (Lunit) and then not Has_Unreferenced (Pack) then Error_Msg_NE -- CODEFIX ("?u?no entities of& are referenced!", Unit_Declaration_Node (Pack), Pack); end if; end if; end; end if; exit; -- Case of entity being referenced. The reference may -- come from a limited_with_clause, in which case the -- limited view of the entity carries the flag. elsif Referenced_Check_Spec (Ent) or else Referenced_As_LHS_Check_Spec (Ent) or else Referenced_As_Out_Parameter_Check_Spec (Ent) or else (From_Limited_With (Ent) and then Is_Incomplete_Type (Ent) and then Present (Non_Limited_View (Ent)) and then Referenced (Non_Limited_View (Ent))) then -- This means that the with is indeed fine, in that -- it is definitely needed somewhere, and we can -- quit worrying about this one... -- Except for one little detail: if either of the -- flags was set during spec processing, this is -- where we complain that the with could be moved -- from the spec. If the spec contains a visible -- renaming of the package, inhibit warning to move -- with_clause to body. if Ekind (Munite) = E_Package_Body then Pack := Find_Package_Renaming (Spec_Entity (Munite), Lunit); else Pack := Empty; end if; -- If a renaming is present in the spec do not warn -- because the body or child unit may depend on it. if Present (Pack) and then Renamed_Entity (Pack) = Lunit then exit; elsif Unreferenced_In_Spec (Item) then Error_Msg_N -- CODEFIX ("?u?unit& is not referenced in spec!", Name (Item)); elsif No_Entities_Ref_In_Spec (Item) then Error_Msg_N -- CODEFIX ("?u?no entities of & are referenced in spec!", Name (Item)); else if Ekind (Ent) = E_Package then Check_Inner_Package (Ent); end if; exit; end if; if not Is_Visible_Renaming then Error_Msg_N -- CODEFIX ("\?u?with clause might be moved to body!", Name (Item)); end if; exit; -- Move to next entity to continue search else Next_Entity (Ent); end if; end loop; end if; -- For a generic package, the only interesting kind of -- reference is an instantiation, since entities cannot be -- referenced directly. elsif Is_Generic_Unit (Lunit) then -- Unit was never instantiated, set flag for case of spec -- call, or give warning for normal call. if not Is_Instantiated (Lunit) then if Unit = Spec_Unit then Set_Unreferenced_In_Spec (Item); else Error_Msg_N -- CODEFIX ("?u?unit& is never instantiated!", Name (Item)); end if; -- If unit was indeed instantiated, make sure that flag is -- not set showing it was uninstantiated in the spec, and if -- so, give warning. elsif Unreferenced_In_Spec (Item) then Error_Msg_N ("?u?unit& is not instantiated in spec!", Name (Item)); Error_Msg_N -- CODEFIX ("\?u?with clause can be moved to body!", Name (Item)); end if; end if; end if; Next (Item); end loop; end Check_One_Unit; -- Start of processing for Check_Unused_Withs begin -- Immediate return if no semantics or warning flag not set if not Opt.Check_Withs or else Operating_Mode = Check_Syntax then return; end if; Process_Deferred_References; -- Flag any unused with clauses. For a subunit, check only the units -- in its context, not those of the parent, which may be needed by other -- subunits. We will get the full warnings when we compile the parent, -- but the following is helpful when compiling a subunit by itself. if Nkind (Unit (Cunit (Main_Unit))) = N_Subunit then if Current_Sem_Unit = Main_Unit then Check_One_Unit (Main_Unit); end if; return; end if; -- Process specified units if Spec_Unit = No_Unit then -- For main call, check all units for Unit in Main_Unit .. Last_Unit loop Check_One_Unit (Unit); end loop; else -- For call for spec, check only the spec Check_One_Unit (Spec_Unit); end if; end Check_Unused_Withs; --------------------------------- -- Generic_Package_Spec_Entity -- --------------------------------- function Generic_Package_Spec_Entity (E : Entity_Id) return Boolean is S : Entity_Id; begin if Is_Package_Body_Entity (E) then return False; else S := Scope (E); loop if S = Standard_Standard then return False; elsif Ekind (S) = E_Generic_Package then return True; elsif Ekind (S) = E_Package then S := Scope (S); else return False; end if; end loop; end if; end Generic_Package_Spec_Entity; ---------------------- -- Goto_Spec_Entity -- ---------------------- function Goto_Spec_Entity (E : Entity_Id) return Entity_Id is begin if Is_Formal (E) and then Present (Spec_Entity (E)) then return Spec_Entity (E); else return E; end if; end Goto_Spec_Entity; ------------------- -- Has_Junk_Name -- ------------------- function Has_Junk_Name (E : Entity_Id) return Boolean is function Match (S : String) return Boolean; -- Return true if substring S is found in Name_Buffer (1 .. Name_Len) ----------- -- Match -- ----------- function Match (S : String) return Boolean is Slen1 : constant Integer := S'Length - 1; begin for J in 1 .. Name_Len - S'Length + 1 loop if Name_Buffer (J .. J + Slen1) = S then return True; end if; end loop; return False; end Match; -- Start of processing for Has_Junk_Name begin Get_Unqualified_Decoded_Name_String (Chars (E)); return Match ("discard") or else Match ("dummy") or else Match ("ignore") or else Match ("junk") or else Match ("unused"); end Has_Junk_Name; -------------------------------------- -- Has_Pragma_Unmodified_Check_Spec -- -------------------------------------- function Has_Pragma_Unmodified_Check_Spec (E : Entity_Id) return Boolean is begin if Is_Formal (E) and then Present (Spec_Entity (E)) then -- Note: use of OR instead of OR ELSE here is deliberate, we want -- to mess with Unmodified flags on both body and spec entities. -- Has_Unmodified has side effects! return Has_Unmodified (E) or Has_Unmodified (Spec_Entity (E)); else return Has_Unmodified (E); end if; end Has_Pragma_Unmodified_Check_Spec; ---------------------------------------- -- Has_Pragma_Unreferenced_Check_Spec -- ---------------------------------------- function Has_Pragma_Unreferenced_Check_Spec (E : Entity_Id) return Boolean is begin if Is_Formal (E) and then Present (Spec_Entity (E)) then -- Note: use of OR here instead of OR ELSE is deliberate, we want -- to mess with flags on both entities. return Has_Unreferenced (E) or Has_Unreferenced (Spec_Entity (E)); else return Has_Unreferenced (E); end if; end Has_Pragma_Unreferenced_Check_Spec; ---------------- -- Initialize -- ---------------- procedure Initialize is begin Warnings_Off_Pragmas.Init; Unreferenced_Entities.Init; In_Out_Warnings.Init; end Initialize; --------------------------------------------- -- Is_Attribute_And_Known_Value_Comparison -- --------------------------------------------- function Is_Attribute_And_Known_Value_Comparison (Op : Node_Id) return Boolean is Orig_Op : constant Node_Id := Original_Node (Op); begin return Nkind (Orig_Op) in N_Op_Compare and then Nkind (Original_Node (Left_Opnd (Orig_Op))) = N_Attribute_Reference and then Compile_Time_Known_Value (Right_Opnd (Orig_Op)); end Is_Attribute_And_Known_Value_Comparison; ------------------------------------ -- Never_Set_In_Source_Check_Spec -- ------------------------------------ function Never_Set_In_Source_Check_Spec (E : Entity_Id) return Boolean is begin if Is_Formal (E) and then Present (Spec_Entity (E)) then return Never_Set_In_Source (E) and then Never_Set_In_Source (Spec_Entity (E)); else return Never_Set_In_Source (E); end if; end Never_Set_In_Source_Check_Spec; ------------------------------------- -- Operand_Has_Warnings_Suppressed -- ------------------------------------- function Operand_Has_Warnings_Suppressed (N : Node_Id) return Boolean is function Check_For_Warnings (N : Node_Id) return Traverse_Result; -- Function used to check one node to see if it is or was originally -- a reference to an entity for which Warnings are off. If so, Abandon -- is returned, otherwise OK_Orig is returned to continue the traversal -- of the original expression. function Traverse is new Traverse_Func (Check_For_Warnings); -- Function used to traverse tree looking for warnings ------------------------ -- Check_For_Warnings -- ------------------------ function Check_For_Warnings (N : Node_Id) return Traverse_Result is R : constant Node_Id := Original_Node (N); begin if Nkind (R) in N_Has_Entity and then Present (Entity (R)) and then Has_Warnings_Off (Entity (R)) then return Abandon; else return OK_Orig; end if; end Check_For_Warnings; -- Start of processing for Operand_Has_Warnings_Suppressed begin return Traverse (N) = Abandon; -- If any exception occurs, then something has gone wrong, and this is -- only a minor aesthetic issue anyway, so just say we did not find what -- we are looking for, rather than blow up. exception when others => -- With debug flag K we will get an exception unless an error has -- already occurred (useful for debugging). if Debug_Flag_K then Check_Error_Detected; end if; return False; end Operand_Has_Warnings_Suppressed; ----------------------------------------- -- Output_Non_Modified_In_Out_Warnings -- ----------------------------------------- procedure Output_Non_Modified_In_Out_Warnings is function No_Warn_On_In_Out (E : Entity_Id) return Boolean; -- Given a formal parameter entity E, determines if there is a reason to -- suppress IN OUT warnings (not modified, could be IN) for formals of -- the subprogram. We suppress these warnings if Warnings Off is set, or -- if we have seen the address of the subprogram being taken, or if the -- subprogram is used as a generic actual (in the latter cases the -- context may force use of IN OUT, even if the parameter is not -- modifies for this particular case. ----------------------- -- No_Warn_On_In_Out -- ----------------------- function No_Warn_On_In_Out (E : Entity_Id) return Boolean is S : constant Entity_Id := Scope (E); SE : constant Entity_Id := Spec_Entity (E); begin -- Do not warn if address is taken, since funny business may be going -- on in treating the parameter indirectly as IN OUT. if Address_Taken (S) or else (Present (SE) and then Address_Taken (Scope (SE))) then return True; -- Do not warn if used as a generic actual, since the generic may be -- what is forcing the use of an "unnecessary" IN OUT. elsif Used_As_Generic_Actual (S) or else (Present (SE) and then Used_As_Generic_Actual (Scope (SE))) then return True; -- Else test warnings off elsif Warnings_Off_Check_Spec (S) then return True; -- All tests for suppressing warning failed else return False; end if; end No_Warn_On_In_Out; -- Start of processing for Output_Non_Modified_In_Out_Warnings begin -- Loop through entities for which a warning may be needed for J in In_Out_Warnings.First .. In_Out_Warnings.Last loop declare E1 : constant Entity_Id := In_Out_Warnings.Table (J); begin -- Suppress warning in specific cases (see details in comments for -- No_Warn_On_In_Out), or if there is a pragma Unmodified. if Has_Pragma_Unmodified_Check_Spec (E1) or else No_Warn_On_In_Out (E1) then null; -- Here we generate the warning else -- If -gnatwc is set then output message that we could be IN if not Is_Trivial_Subprogram (Scope (E1)) then if Warn_On_Constant then Error_Msg_N ("?u?formal parameter & is not modified!", E1); Error_Msg_N ("\?u?mode could be IN instead of `IN OUT`!", E1); -- We do not generate warnings for IN OUT parameters -- unless we have at least -gnatwu. This is deliberately -- inconsistent with the treatment of variables, but -- otherwise we get too many unexpected warnings in -- default mode. elsif Check_Unreferenced then Error_Msg_N ("?u?formal parameter& is read but " & "never assigned!", E1); end if; end if; -- Kill any other warnings on this entity, since this is the -- one that should dominate any other unreferenced warning. Set_Warnings_Off (E1); end if; end; end loop; end Output_Non_Modified_In_Out_Warnings; ---------------------------------------- -- Output_Obsolescent_Entity_Warnings -- ---------------------------------------- procedure Output_Obsolescent_Entity_Warnings (N : Node_Id; E : Entity_Id) is P : constant Node_Id := Parent (N); S : Entity_Id; begin S := Current_Scope; -- Do not output message if we are the scope of standard. This means -- we have a reference from a context clause from when it is originally -- processed, and that's too early to tell whether it is an obsolescent -- unit doing the with'ing. In Sem_Ch10.Analyze_Compilation_Unit we make -- sure that we have a later call when the scope is available. This test -- also eliminates all messages for use clauses, which is fine (we do -- not want messages for use clauses, since they are always redundant -- with respect to the associated with clause). if S = Standard_Standard then return; end if; -- Do not output message if we are in scope of an obsolescent package -- or subprogram. loop if Is_Obsolescent (S) then return; end if; S := Scope (S); exit when S = Standard_Standard; end loop; -- Here we will output the message Error_Msg_Sloc := Sloc (E); -- Case of with clause if Nkind (P) = N_With_Clause then if Ekind (E) = E_Package then Error_Msg_NE ("?j?with of obsolescent package& declared#", N, E); elsif Ekind (E) = E_Procedure then Error_Msg_NE ("?j?with of obsolescent procedure& declared#", N, E); else Error_Msg_NE ("??with of obsolescent function& declared#", N, E); end if; -- If we do not have a with clause, then ignore any reference to an -- obsolescent package name. We only want to give the one warning of -- withing the package, not one each time it is used to qualify. elsif Ekind (E) = E_Package then return; -- Procedure call statement elsif Nkind (P) = N_Procedure_Call_Statement then Error_Msg_NE ("??call to obsolescent procedure& declared#", N, E); -- Function call elsif Nkind (P) = N_Function_Call then Error_Msg_NE ("??call to obsolescent function& declared#", N, E); -- Reference to obsolescent type elsif Is_Type (E) then Error_Msg_NE ("??reference to obsolescent type& declared#", N, E); -- Reference to obsolescent component elsif Ekind (E) in E_Component | E_Discriminant then Error_Msg_NE ("??reference to obsolescent component& declared#", N, E); -- Reference to obsolescent variable elsif Ekind (E) = E_Variable then Error_Msg_NE ("??reference to obsolescent variable& declared#", N, E); -- Reference to obsolescent constant elsif Ekind (E) = E_Constant or else Ekind (E) in Named_Kind then Error_Msg_NE ("??reference to obsolescent constant& declared#", N, E); -- Reference to obsolescent enumeration literal elsif Ekind (E) = E_Enumeration_Literal then Error_Msg_NE ("??reference to obsolescent enumeration literal& declared#", N, E); -- Generic message for any other case we missed else Error_Msg_NE ("??reference to obsolescent entity& declared#", N, E); end if; -- Output additional warning if present for J in Obsolescent_Warnings.First .. Obsolescent_Warnings.Last loop if Obsolescent_Warnings.Table (J).Ent = E then String_To_Name_Buffer (Obsolescent_Warnings.Table (J).Msg); Error_Msg_Strlen := Name_Len; Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); Error_Msg_N ("\\??~", N); exit; end if; end loop; end Output_Obsolescent_Entity_Warnings; ---------------------------------- -- Output_Unreferenced_Messages -- ---------------------------------- procedure Output_Unreferenced_Messages is begin for J in Unreferenced_Entities.First .. Unreferenced_Entities.Last loop Warn_On_Unreferenced_Entity (Unreferenced_Entities.Table (J)); end loop; end Output_Unreferenced_Messages; ----------------------------------------- -- Output_Unused_Warnings_Off_Warnings -- ----------------------------------------- procedure Output_Unused_Warnings_Off_Warnings is begin for J in Warnings_Off_Pragmas.First .. Warnings_Off_Pragmas.Last loop declare Wentry : Warnings_Off_Entry renames Warnings_Off_Pragmas.Table (J); N : Node_Id renames Wentry.N; E : Node_Id renames Wentry.E; begin -- Turn off Warnings_Off, or we won't get the warning Set_Warnings_Off (E, False); -- Nothing to do if pragma was used to suppress a general warning if Warnings_Off_Used (E) then null; -- If pragma was used both in unmodified and unreferenced contexts -- then that's as good as the general case, no warning. elsif Warnings_Off_Used_Unmodified (E) and Warnings_Off_Used_Unreferenced (E) then null; -- Used only in context where Unmodified would have worked elsif Warnings_Off_Used_Unmodified (E) then Error_Msg_NE ("?W?could use Unmodified instead of " & "Warnings Off for &", Pragma_Identifier (N), E); -- Used only in context where Unreferenced would have worked elsif Warnings_Off_Used_Unreferenced (E) then Error_Msg_NE ("?W?could use Unreferenced instead of " & "Warnings Off for &", Pragma_Identifier (N), E); -- Not used at all else Error_Msg_NE ("?W?pragma Warnings Off for & unused, " & "could be omitted", N, E); end if; end; end loop; end Output_Unused_Warnings_Off_Warnings; --------------------------- -- Referenced_Check_Spec -- --------------------------- function Referenced_Check_Spec (E : Entity_Id) return Boolean is begin if Is_Formal (E) and then Present (Spec_Entity (E)) then return Referenced (E) or else Referenced (Spec_Entity (E)); else return Referenced (E); end if; end Referenced_Check_Spec; ---------------------------------- -- Referenced_As_LHS_Check_Spec -- ---------------------------------- function Referenced_As_LHS_Check_Spec (E : Entity_Id) return Boolean is begin if Is_Formal (E) and then Present (Spec_Entity (E)) then return Referenced_As_LHS (E) or else Referenced_As_LHS (Spec_Entity (E)); else return Referenced_As_LHS (E); end if; end Referenced_As_LHS_Check_Spec; -------------------------------------------- -- Referenced_As_Out_Parameter_Check_Spec -- -------------------------------------------- function Referenced_As_Out_Parameter_Check_Spec (E : Entity_Id) return Boolean is begin if Is_Formal (E) and then Present (Spec_Entity (E)) then return Referenced_As_Out_Parameter (E) or else Referenced_As_Out_Parameter (Spec_Entity (E)); else return Referenced_As_Out_Parameter (E); end if; end Referenced_As_Out_Parameter_Check_Spec; -------------------------------------- -- Warn_On_Constant_Valid_Condition -- -------------------------------------- procedure Warn_On_Constant_Valid_Condition (Op : Node_Id) is Left : constant Node_Id := Left_Opnd (Op); Right : constant Node_Id := Right_Opnd (Op); True_Result : Boolean; False_Result : Boolean; begin -- Determine the potential outcome of the comparison assuming that the -- scalar operands are valid. if Constant_Condition_Warnings and then Comes_From_Source (Original_Node (Op)) and then Is_Scalar_Type (Etype (Left)) and then Is_Scalar_Type (Etype (Right)) -- Do not consider instances because the check was already performed -- in the generic. and then not In_Instance -- Do not consider comparisons between two static expressions such as -- constants or literals because those values cannot be invalidated. and then not (Is_Static_Expression (Left) and then Is_Static_Expression (Right)) -- Do not consider comparison between an attribute reference and a -- compile-time known value since this is most likely a conditional -- compilation. and then not Is_Attribute_And_Known_Value_Comparison (Op) -- Do not consider internal files to allow for various assertions and -- safeguards within our runtime. and then not In_Internal_Unit (Op) then Test_Comparison (Op => Op, Assume_Valid => True, True_Result => True_Result, False_Result => False_Result); -- Warn on a possible evaluation to False / True in the presence of -- invalid values. if True_Result then Error_Msg_N ("condition can only be False if invalid values present?c?", Op); elsif False_Result then Error_Msg_N ("condition can only be True if invalid values present?c?", Op); end if; end if; end Warn_On_Constant_Valid_Condition; ----------------------------- -- Warn_On_Known_Condition -- ----------------------------- procedure Warn_On_Known_Condition (C : Node_Id) is Test_Result : Boolean := False; -- Force initialization to facilitate static analysis function Is_Known_Branch return Boolean; -- If the type of the condition is Boolean, the constant value of the -- condition is a boolean literal. If the type is a derived boolean -- type, the constant is wrapped in a type conversion of the derived -- literal. If the value of the condition is not a literal, no warnings -- can be produced. This function returns True if the result can be -- determined, and Test_Result is set True/False accordingly. Otherwise -- False is returned, and Test_Result is unchanged. procedure Track (N : Node_Id; Loc : Node_Id); -- Adds continuation warning(s) pointing to reason (assignment or test) -- for the operand of the conditional having a known value (or at least -- enough is known about the value to issue the warning). N is the node -- which is judged to have a known value. Loc is the warning location. --------------------- -- Is_Known_Branch -- --------------------- function Is_Known_Branch return Boolean is begin if Etype (C) = Standard_Boolean and then Is_Entity_Name (C) and then (Entity (C) = Standard_False or else Entity (C) = Standard_True) then Test_Result := Entity (C) = Standard_True; return True; elsif Is_Boolean_Type (Etype (C)) and then Nkind (C) = N_Unchecked_Type_Conversion and then Is_Entity_Name (Expression (C)) and then Ekind (Entity (Expression (C))) = E_Enumeration_Literal then Test_Result := Chars (Entity (Expression (C))) = Chars (Standard_True); return True; else return False; end if; end Is_Known_Branch; ----------- -- Track -- ----------- procedure Track (N : Node_Id; Loc : Node_Id) is Nod : constant Node_Id := Original_Node (N); begin if Nkind (Nod) in N_Op_Compare then Track (Left_Opnd (Nod), Loc); Track (Right_Opnd (Nod), Loc); elsif Is_Entity_Name (Nod) and then Is_Object (Entity (Nod)) then declare CV : constant Node_Id := Current_Value (Entity (Nod)); begin if Present (CV) then Error_Msg_Sloc := Sloc (CV); if Nkind (CV) not in N_Subexpr then Error_Msg_N ("\\??(see test #)", Loc); elsif Nkind (Parent (CV)) = N_Case_Statement_Alternative then Error_Msg_N ("\\??(see case alternative #)", Loc); else Error_Msg_N ("\\??(see assignment #)", Loc); end if; end if; end; end if; end Track; -- Local variables Orig : constant Node_Id := Original_Node (C); P : Node_Id; -- Start of processing for Warn_On_Known_Condition begin -- Adjust SCO condition if from source if Generate_SCO and then Comes_From_Source (Orig) and then Is_Known_Branch then declare Atrue : Boolean; begin Atrue := Test_Result; if Present (Parent (C)) and then Nkind (Parent (C)) = N_Op_Not then Atrue := not Atrue; end if; Set_SCO_Condition (Orig, Atrue); end; end if; -- Argument replacement in an inlined body can make conditions static. -- Do not emit warnings in this case. if In_Inlined_Body then return; end if; if Constant_Condition_Warnings and then Is_Known_Branch and then Comes_From_Source (Orig) and then Nkind (Orig) in N_Has_Entity and then not In_Instance then -- Don't warn if comparison of result of attribute against a constant -- value, since this is likely legitimate conditional compilation. if Is_Attribute_And_Known_Value_Comparison (C) then return; end if; -- See if this is in a statement or a declaration P := Parent (C); loop -- If tree is not attached, do not issue warning (this is very -- peculiar, and probably arises from some other error condition). if No (P) then return; -- If we are in a declaration, then no warning, since in practice -- conditionals in declarations are used for intended tests which -- may be known at compile time, e.g. things like -- x : constant Integer := 2 + (Word'Size = 32); -- And a warning is annoying in such cases elsif Nkind (P) in N_Declaration or else Nkind (P) in N_Later_Decl_Item then return; -- Don't warn in assert or check pragma, since presumably tests in -- such a context are very definitely intended, and might well be -- known at compile time. Note that we have to test the original -- node, since assert pragmas get rewritten at analysis time. elsif Nkind (Original_Node (P)) = N_Pragma and then Pragma_Name_Unmapped (Original_Node (P)) in Name_Assert | Name_Check then return; end if; exit when Is_Statement (P); P := Parent (P); end loop; -- Here we issue the warning unless some sub-operand has warnings -- set off, in which case we suppress the warning for the node. If -- the original expression is an inequality, it has been expanded -- into a negation, and the value of the original expression is the -- negation of the equality. If the expression is an entity that -- appears within a negation, it is clearer to flag the negation -- itself, and report on its constant value. if not Operand_Has_Warnings_Suppressed (C) then declare True_Branch : Boolean := Test_Result; Cond : Node_Id := C; begin if Present (Parent (C)) and then Nkind (Parent (C)) = N_Op_Not then True_Branch := not True_Branch; Cond := Parent (C); end if; -- Condition always True if True_Branch then if Is_Entity_Name (Original_Node (C)) and then Nkind (Cond) /= N_Op_Not then Error_Msg_NE ("object & is always True at this point?c?", Cond, Original_Node (C)); Track (Original_Node (C), Cond); else Error_Msg_N ("condition is always True?c?", Cond); Track (Cond, Cond); end if; -- Condition always False else if Is_Entity_Name (Original_Node (C)) and then Nkind (Cond) /= N_Op_Not then Error_Msg_NE ("object & is always False at this point?c?", Cond, Original_Node (C)); Track (Original_Node (C), Cond); else Error_Msg_N ("condition is always False?c?", Cond); Track (Cond, Cond); end if; end if; end; end if; end if; end Warn_On_Known_Condition; --------------------------------------- -- Warn_On_Modified_As_Out_Parameter -- --------------------------------------- function Warn_On_Modified_As_Out_Parameter (E : Entity_Id) return Boolean is begin return (Warn_On_Modified_Unread and then Is_Only_Out_Parameter (E)) or else Warn_On_All_Unread_Out_Parameters; end Warn_On_Modified_As_Out_Parameter; --------------------------------- -- Warn_On_Overlapping_Actuals -- --------------------------------- procedure Warn_On_Overlapping_Actuals (Subp : Entity_Id; N : Node_Id) is function Refer_Same_Object (Act1 : Node_Id; Act2 : Node_Id) return Boolean; -- Two names are known to refer to the same object if the two names -- are known to denote the same object; or one of the names is a -- selected_component, indexed_component, or slice and its prefix is -- known to refer to the same object as the other name; or one of the -- two names statically denotes a renaming declaration whose renamed -- object_name is known to refer to the same object as the other name -- (RM 6.4.1(6.11/3)) ----------------------- -- Refer_Same_Object -- ----------------------- function Refer_Same_Object (Act1 : Node_Id; Act2 : Node_Id) return Boolean is begin return Denotes_Same_Object (Act1, Act2) or else Denotes_Same_Prefix (Act1, Act2); end Refer_Same_Object; -- Local variables Act1 : Node_Id; Act2 : Node_Id; Form1 : Entity_Id; Form2 : Entity_Id; -- Start of processing for Warn_On_Overlapping_Actuals begin if Ada_Version < Ada_2012 and then not Warn_On_Overlap then return; end if; -- Exclude calls rewritten as enumeration literals if Nkind (N) not in N_Subprogram_Call and then Nkind (N) /= N_Entry_Call_Statement then return; end if; -- If a call C has two or more parameters of mode in out or out that are -- of an elementary type, then the call is legal only if for each name -- N that is passed as a parameter of mode in out or out to the call C, -- there is no other name among the other parameters of mode in out or -- out to C that is known to denote the same object (RM 6.4.1(6.15/3)) -- This has been clarified in AI12-0216 to indicate that the illegality -- only occurs if both formals are of an elementary type, because of the -- nondeterminism on the write-back of the corresponding actuals. -- Earlier versions of the language made it illegal if only one of the -- actuals was an elementary parameter that overlapped a composite -- actual, and both were writable. -- If appropriate warning switch is set, we also report warnings on -- overlapping parameters that are composite types. Users find these -- warnings useful, and they are used in style guides. -- It is also worthwhile to warn on overlaps of composite objects when -- only one of the formals is (in)-out. Note that the RM rule above is -- a legality rule. We choose to implement this check as a warning to -- avoid major incompatibilities with legacy code. -- Note also that the rule in 6.4.1 (6.17/3), introduced by AI12-0324, -- is potentially more expensive to verify, and is not yet implemented. Form1 := First_Formal (Subp); Act1 := First_Actual (N); while Present (Form1) and then Present (Act1) loop if Is_Generic_Type (Etype (Act1)) then return; end if; -- One of the formals must be either (in)-out or composite. -- The other must be (in)-out. if Is_Elementary_Type (Etype (Act1)) and then Ekind (Form1) = E_In_Parameter then null; else Form2 := Next_Formal (Form1); Act2 := Next_Actual (Act1); while Present (Form2) and then Present (Act2) loop if Refer_Same_Object (Act1, Act2) then if Is_Generic_Type (Etype (Act2)) then return; end if; -- First case : two writable elementary parameters -- that overlap. if (Is_Elementary_Type (Etype (Form1)) and then Is_Elementary_Type (Etype (Form2)) and then Ekind (Form1) /= E_In_Parameter and then Ekind (Form2) /= E_In_Parameter) -- Second case : two composite parameters that overlap, -- one of which is writable. or else (Is_Composite_Type (Etype (Form1)) and then Is_Composite_Type (Etype (Form2)) and then (Ekind (Form1) /= E_In_Parameter or else Ekind (Form2) /= E_In_Parameter)) -- Third case : an elementary writable parameter that -- overlaps a composite one. or else (Is_Elementary_Type (Etype (Form1)) and then Ekind (Form1) /= E_In_Parameter and then Is_Composite_Type (Etype (Form2))) or else (Is_Elementary_Type (Etype (Form2)) and then Ekind (Form2) /= E_In_Parameter and then Is_Composite_Type (Etype (Form1))) then -- Guard against previous errors if Error_Posted (N) or else No (Etype (Act1)) or else No (Etype (Act2)) then null; -- If the actual is a function call in prefix notation, -- there is no real overlap. elsif Nkind (Act2) = N_Function_Call then null; -- If type is explicitly not by-copy, assume that -- aliasing is intended. elsif Present (Underlying_Type (Etype (Form1))) and then (Is_By_Reference_Type (Underlying_Type (Etype (Form1))) or else Convention (Underlying_Type (Etype (Form1))) = Convention_Ada_Pass_By_Reference) then null; -- Under Ada 2012 we only report warnings on overlapping -- arrays and record types if switch is set. elsif Ada_Version >= Ada_2012 and then not Is_Elementary_Type (Etype (Form1)) and then not Warn_On_Overlap then null; -- Here we may need to issue overlap message else Error_Msg_Warn := -- Overlap checking is an error only in Ada 2012. -- For earlier versions of Ada, this is a warning. Ada_Version < Ada_2012 -- Overlap is only illegal in Ada 2012 in the case -- of elementary types (passed by copy). For other -- types we always have a warning in all versions. -- This is clarified by AI12-0216. or else not (Is_Elementary_Type (Etype (Form1)) and then Is_Elementary_Type (Etype (Form2))) -- debug flag -gnatd.E changes the error to a -- warning even in Ada 2012 mode. or else Error_To_Warning; if Is_Elementary_Type (Etype (Act1)) and then Ekind (Form2) = E_In_Parameter then null; -- No real aliasing elsif Is_Elementary_Type (Etype (Act2)) and then Ekind (Form2) = E_In_Parameter then null; -- Ditto -- If the call was written in prefix notation, and -- thus its prefix before rewriting was a selected -- component, count only visible actuals in call. elsif Is_Entity_Name (First_Actual (N)) and then Nkind (Original_Node (N)) = Nkind (N) and then Nkind (Name (Original_Node (N))) = N_Selected_Component and then Is_Entity_Name (Prefix (Name (Original_Node (N)))) and then Entity (Prefix (Name (Original_Node (N)))) = Entity (First_Actual (N)) then if Act1 = First_Actual (N) then Error_Msg_FE ("<I<`IN OUT` prefix overlaps with " & "actual for&", Act1, Form2); else -- For greater clarity, give name of formal Error_Msg_Node_2 := Form2; Error_Msg_FE ("<I<writable actual for & overlaps with " & "actual for&", Act1, Form2); end if; else -- For greater clarity, give name of formal Error_Msg_Node_2 := Form2; -- This is one of the messages Error_Msg_FE ("<I<writable actual for & overlaps with " & "actual for&", Act1, Form1); end if; end if; end if; return; end if; Next_Formal (Form2); Next_Actual (Act2); end loop; end if; Next_Formal (Form1); Next_Actual (Act1); end loop; end Warn_On_Overlapping_Actuals; ------------------------------ -- Warn_On_Suspicious_Index -- ------------------------------ procedure Warn_On_Suspicious_Index (Name : Entity_Id; X : Node_Id) is Low_Bound : Uint; -- Set to lower bound for a suspicious type Ent : Entity_Id; -- Entity for array reference Typ : Entity_Id; -- Array type function Is_Suspicious_Type (Typ : Entity_Id) return Boolean; -- Tests to see if Typ is a type for which we may have a suspicious -- index, namely an unconstrained array type, whose lower bound is -- either zero or one. If so, True is returned, and Low_Bound is set -- to this lower bound. If not, False is returned, and Low_Bound is -- undefined on return. -- -- For now, we limit this to standard string types, so any other -- unconstrained types return False. We may change our minds on this -- later on, but strings seem the most important case. procedure Test_Suspicious_Index; -- Test if index is of suspicious type and if so, generate warning ------------------------ -- Is_Suspicious_Type -- ------------------------ function Is_Suspicious_Type (Typ : Entity_Id) return Boolean is LB : Node_Id; begin if Is_Array_Type (Typ) and then not Is_Constrained (Typ) and then Number_Dimensions (Typ) = 1 and then Is_Standard_String_Type (Typ) and then not Has_Warnings_Off (Typ) then LB := Type_Low_Bound (Etype (First_Index (Typ))); if Compile_Time_Known_Value (LB) then Low_Bound := Expr_Value (LB); return Low_Bound = Uint_0 or else Low_Bound = Uint_1; end if; end if; return False; end Is_Suspicious_Type; --------------------------- -- Test_Suspicious_Index -- --------------------------- procedure Test_Suspicious_Index is function Length_Reference (N : Node_Id) return Boolean; -- Check if node N is of the form Name'Length procedure Warn1; -- Generate first warning line procedure Warn_On_Index_Below_Lower_Bound; -- Generate a warning on indexing the array with a literal value -- below the lower bound of the index type. procedure Warn_On_Literal_Index; -- Generate a warning on indexing the array with a literal value ---------------------- -- Length_Reference -- ---------------------- function Length_Reference (N : Node_Id) return Boolean is R : constant Node_Id := Original_Node (N); begin return Nkind (R) = N_Attribute_Reference and then Attribute_Name (R) = Name_Length and then Is_Entity_Name (Prefix (R)) and then Entity (Prefix (R)) = Ent; end Length_Reference; ----------- -- Warn1 -- ----------- procedure Warn1 is begin Error_Msg_Uint_1 := Low_Bound; Error_Msg_FE -- CODEFIX ("?w?index for& may assume lower bound of^", X, Ent); end Warn1; ------------------------------------- -- Warn_On_Index_Below_Lower_Bound -- ------------------------------------- procedure Warn_On_Index_Below_Lower_Bound is begin if Is_Standard_String_Type (Typ) then Discard_Node (Compile_Time_Constraint_Error (N => X, Msg => "?w?string index should be positive")); else Discard_Node (Compile_Time_Constraint_Error (N => X, Msg => "?w?index out of the allowed range")); end if; end Warn_On_Index_Below_Lower_Bound; --------------------------- -- Warn_On_Literal_Index -- --------------------------- procedure Warn_On_Literal_Index is begin Warn1; -- Case where original form of subscript is an integer literal if Nkind (Original_Node (X)) = N_Integer_Literal then if Intval (X) = Low_Bound then Error_Msg_FE -- CODEFIX ("\?w?suggested replacement: `&''First`", X, Ent); else Error_Msg_Uint_1 := Intval (X) - Low_Bound; Error_Msg_FE -- CODEFIX ("\?w?suggested replacement: `&''First + ^`", X, Ent); end if; -- Case where original form of subscript is more complex else -- Build string X'First - 1 + expression where the expression -- is the original subscript. If the expression starts with "1 -- + ", then the "- 1 + 1" is elided. Error_Msg_String (1 .. 13) := "'First - 1 + "; Error_Msg_Strlen := 13; declare Sref : Source_Ptr := Sloc (First_Node (Original_Node (X))); Tref : constant Source_Buffer_Ptr := Source_Text (Get_Source_File_Index (Sref)); -- Tref (Sref) is used to scan the subscript Pctr : Natural; -- Parentheses counter when scanning subscript begin -- Tref (Sref) points to start of subscript -- Elide - 1 if subscript starts with 1 + if Tref (Sref .. Sref + 2) = "1 +" then Error_Msg_Strlen := Error_Msg_Strlen - 6; Sref := Sref + 2; elsif Tref (Sref .. Sref + 1) = "1+" then Error_Msg_Strlen := Error_Msg_Strlen - 6; Sref := Sref + 1; end if; -- Now we will copy the subscript to the string buffer Pctr := 0; loop -- Count parens, exit if terminating right paren. Note -- check to ignore paren appearing as character literal. if Tref (Sref + 1) = ''' and then Tref (Sref - 1) = ''' then null; else if Tref (Sref) = '(' then Pctr := Pctr + 1; elsif Tref (Sref) = ')' then exit when Pctr = 0; Pctr := Pctr - 1; end if; end if; -- Done if terminating double dot (slice case) exit when Pctr = 0 and then (Tref (Sref .. Sref + 1) = ".." or else Tref (Sref .. Sref + 2) = " .."); -- Quit if we have hit EOF character, something wrong if Tref (Sref) = EOF then return; end if; -- String literals are too much of a pain to handle if Tref (Sref) = '"' or else Tref (Sref) = '%' then return; end if; -- If we have a 'Range reference, then this is a case -- where we cannot easily give a replacement. Don't try. if Tref (Sref .. Sref + 4) = "range" and then Tref (Sref - 1) < 'A' and then Tref (Sref + 5) < 'A' then return; end if; -- Else store next character Error_Msg_Strlen := Error_Msg_Strlen + 1; Error_Msg_String (Error_Msg_Strlen) := Tref (Sref); Sref := Sref + 1; -- If we get more than 40 characters then the expression -- is too long to copy, or something has gone wrong. In -- either case, just skip the attempt at a suggested fix. if Error_Msg_Strlen > 40 then return; end if; end loop; end; -- Replacement subscript is now in string buffer Error_Msg_FE -- CODEFIX ("\?w?suggested replacement: `&~`", Original_Node (X), Ent); end if; end Warn_On_Literal_Index; -- Start of processing for Test_Suspicious_Index begin -- Nothing to do if subscript does not come from source (we don't -- want to give garbage warnings on compiler expanded code, e.g. the -- loops generated for slice assignments. Such junk warnings would -- be placed on source constructs with no subscript in sight). if not Comes_From_Source (Original_Node (X)) then return; end if; -- Case where subscript is a constant integer if Nkind (X) = N_Integer_Literal then -- Case where subscript is lower than the lowest possible bound. -- This might be the case for example when programmers try to -- access a string at index 0, as they are used to in other -- programming languages like C. if Intval (X) < Low_Bound then Warn_On_Index_Below_Lower_Bound; else Warn_On_Literal_Index; end if; -- Case where subscript is of the form X'Length elsif Length_Reference (X) then Warn1; Error_Msg_Node_2 := Ent; Error_Msg_FE ("\?w?suggest replacement of `&''Length` by `&''Last`", X, Ent); -- Case where subscript is of the form X'Length - expression elsif Nkind (X) = N_Op_Subtract and then Length_Reference (Left_Opnd (X)) then Warn1; Error_Msg_Node_2 := Ent; Error_Msg_FE ("\?w?suggest replacement of `&''Length` by `&''Last`", Left_Opnd (X), Ent); end if; end Test_Suspicious_Index; -- Start of processing for Warn_On_Suspicious_Index begin -- Only process if warnings activated if Warn_On_Assumed_Low_Bound then -- Test if array is simple entity name if Is_Entity_Name (Name) then -- Test if array is parameter of unconstrained string type Ent := Entity (Name); Typ := Etype (Ent); if Is_Formal (Ent) and then Is_Suspicious_Type (Typ) and then not Low_Bound_Tested (Ent) then Test_Suspicious_Index; end if; end if; end if; end Warn_On_Suspicious_Index; ------------------------------- -- Warn_On_Suspicious_Update -- ------------------------------- procedure Warn_On_Suspicious_Update (N : Node_Id) is Par : constant Node_Id := Parent (N); Arg : Node_Id; begin -- Only process if warnings activated if Warn_On_Suspicious_Contract then if Nkind (Par) in N_Op_Eq | N_Op_Ne then if N = Left_Opnd (Par) then Arg := Right_Opnd (Par); else Arg := Left_Opnd (Par); end if; if Same_Object (Prefix (N), Arg) then if Nkind (Par) = N_Op_Eq then Error_Msg_N ("suspicious equality test with modified version of " & "same object?T?", Par); else Error_Msg_N ("suspicious inequality test with modified version of " & "same object?T?", Par); end if; end if; end if; end if; end Warn_On_Suspicious_Update; -------------------------------------- -- Warn_On_Unassigned_Out_Parameter -- -------------------------------------- procedure Warn_On_Unassigned_Out_Parameter (Return_Node : Node_Id; Scope_Id : Entity_Id) is Form : Entity_Id; Form2 : Entity_Id; begin -- Ignore if procedure or return statement does not come from source if not Comes_From_Source (Scope_Id) or else not Comes_From_Source (Return_Node) then return; end if; -- Loop through formals Form := First_Formal (Scope_Id); while Present (Form) loop -- We are only interested in OUT parameters that come from source -- and are never set in the source, and furthermore only in scalars -- since non-scalars generate too many false positives. if Ekind (Form) = E_Out_Parameter and then Never_Set_In_Source_Check_Spec (Form) and then Is_Scalar_Type (Etype (Form)) and then not Present (Unset_Reference (Form)) then -- Before we issue the warning, an add ad hoc defence against the -- most common case of false positives with this warning which is -- the case where there is a Boolean OUT parameter that has been -- set, and whose meaning is "ignore the values of the other -- parameters". We can't of course reliably tell this case at -- compile time, but the following test kills a lot of false -- positives, without generating a significant number of false -- negatives (missed real warnings). Form2 := First_Formal (Scope_Id); while Present (Form2) loop if Ekind (Form2) = E_Out_Parameter and then Root_Type (Etype (Form2)) = Standard_Boolean and then not Never_Set_In_Source_Check_Spec (Form2) then return; end if; Next_Formal (Form2); end loop; -- Here all conditions are met, record possible unset reference Set_Unset_Reference (Form, Return_Node); end if; Next_Formal (Form); end loop; end Warn_On_Unassigned_Out_Parameter; --------------------------------- -- Warn_On_Unreferenced_Entity -- --------------------------------- procedure Warn_On_Unreferenced_Entity (Spec_E : Entity_Id; Body_E : Entity_Id := Empty) is E : Entity_Id := Spec_E; begin if not Referenced_Check_Spec (E) and then not Has_Pragma_Unreferenced_Check_Spec (E) and then not Warnings_Off_Check_Spec (E) and then not Has_Junk_Name (Spec_E) and then not Is_Exported (Spec_E) then case Ekind (E) is when E_Variable => -- Case of variable that is assigned but not read. We suppress -- the message if the variable is volatile, has an address -- clause, is aliased, or is a renaming, or is imported. if Referenced_As_LHS_Check_Spec (E) then if Warn_On_Modified_Unread and then No (Address_Clause (E)) and then not Is_Volatile (E) and then not Is_Imported (E) and then not Is_Aliased (E) and then No (Renamed_Object (E)) then if not Has_Pragma_Unmodified_Check_Spec (E) then Error_Msg_N -- CODEFIX ("?m?variable & is assigned but never read!", E); end if; Set_Last_Assignment (E, Empty); end if; -- Normal case of neither assigned nor read (exclude variables -- referenced as out parameters, since we already generated -- appropriate warnings at the call point in this case). elsif not Referenced_As_Out_Parameter (E) then -- We suppress the message for types for which a valid -- pragma Unreferenced_Objects has been given, otherwise -- we go ahead and give the message. if not Has_Pragma_Unreferenced_Objects (Etype (E)) then -- Distinguish renamed case in message if Present (Renamed_Object (E)) and then Comes_From_Source (Renamed_Object (E)) then Error_Msg_N -- CODEFIX ("?u?renamed variable & is not referenced!", E); else Error_Msg_N -- CODEFIX ("?u?variable & is not referenced!", E); end if; end if; end if; when E_Constant => if not Has_Pragma_Unreferenced_Objects (Etype (E)) then if Present (Renamed_Object (E)) and then Comes_From_Source (Renamed_Object (E)) then Error_Msg_N -- CODEFIX ("?u?renamed constant & is not referenced!", E); else Error_Msg_N -- CODEFIX ("?u?constant & is not referenced!", E); end if; end if; when E_In_Out_Parameter | E_In_Parameter => -- Do not emit message for formals of a renaming, because they -- are never referenced explicitly. if Nkind (Original_Node (Unit_Declaration_Node (Scope (E)))) /= N_Subprogram_Renaming_Declaration then -- Suppress this message for an IN OUT parameter of a -- non-scalar type, since it is normal to have only an -- assignment in such a case. if Ekind (E) = E_In_Parameter or else not Referenced_As_LHS_Check_Spec (E) or else Is_Scalar_Type (Etype (E)) then if Present (Body_E) then E := Body_E; end if; declare B : constant Node_Id := Parent (Parent (Scope (E))); S : Entity_Id := Empty; begin if Nkind (B) in N_Expression_Function | N_Subprogram_Body | N_Subprogram_Renaming_Declaration then S := Corresponding_Spec (B); end if; -- Do not warn for dispatching operations, because -- that causes too much noise. Also do not warn for -- trivial subprograms. if (not Present (S) or else not Is_Dispatching_Operation (S)) and then not Is_Trivial_Subprogram (Scope (E)) then Error_Msg_NE -- CODEFIX ("?u?formal parameter & is not referenced!", E, Spec_E); end if; end; end if; end if; when E_Out_Parameter => null; when E_Discriminant => Error_Msg_N ("?u?discriminant & is not referenced!", E); when E_Named_Integer | E_Named_Real => Error_Msg_N -- CODEFIX ("?u?named number & is not referenced!", E); when Formal_Object_Kind => Error_Msg_N -- CODEFIX ("?u?formal object & is not referenced!", E); when E_Enumeration_Literal => Error_Msg_N -- CODEFIX ("?u?literal & is not referenced!", E); when E_Function => Error_Msg_N -- CODEFIX ("?u?function & is not referenced!", E); when E_Procedure => Error_Msg_N -- CODEFIX ("?u?procedure & is not referenced!", E); when E_Package => Error_Msg_N -- CODEFIX ("?u?package & is not referenced!", E); when E_Exception => Error_Msg_N -- CODEFIX ("?u?exception & is not referenced!", E); when E_Label => Error_Msg_N -- CODEFIX ("?u?label & is not referenced!", E); when E_Generic_Procedure => Error_Msg_N -- CODEFIX ("?u?generic procedure & is never instantiated!", E); when E_Generic_Function => Error_Msg_N -- CODEFIX ("?u?generic function & is never instantiated!", E); when Type_Kind => Error_Msg_N -- CODEFIX ("?u?type & is not referenced!", E); when others => Error_Msg_N -- CODEFIX ("?u?& is not referenced!", E); end case; -- Kill warnings on the entity on which the message has been posted -- (nothing is posted on out parameters because back end might be -- able to uncover an uninitialized path, and warn accordingly). if Ekind (E) /= E_Out_Parameter then Set_Warnings_Off (E); end if; end if; end Warn_On_Unreferenced_Entity; -------------------------------- -- Warn_On_Useless_Assignment -- -------------------------------- procedure Warn_On_Useless_Assignment (Ent : Entity_Id; N : Node_Id := Empty) is P : Node_Id; X : Node_Id; function Check_Ref (N : Node_Id) return Traverse_Result; -- Used to instantiate Traverse_Func. Returns Abandon if a reference to -- the entity in question is found. function Test_No_Refs is new Traverse_Func (Check_Ref); --------------- -- Check_Ref -- --------------- function Check_Ref (N : Node_Id) return Traverse_Result is begin -- Check reference to our identifier. We use name equality here -- because the exception handlers have not yet been analyzed. This -- is not quite right, but it really does not matter that we fail -- to output the warning in some obscure cases of name clashes. if Nkind (N) = N_Identifier and then Chars (N) = Chars (Ent) then return Abandon; else return OK; end if; end Check_Ref; -- Start of processing for Warn_On_Useless_Assignment begin -- Check if this is a case we want to warn on, a scalar or access -- variable with the last assignment field set, with warnings enabled, -- and which is not imported or exported. We also check that it is OK -- to capture the value. We are not going to capture any value, but -- the warning message depends on the same kind of conditions. -- If the assignment appears as an out-parameter in a call within an -- expression function it may be detected twice: once when expression -- itself is analyzed, and once when the constructed body is analyzed. -- We don't want to emit a spurious warning in this case. if Is_Assignable (Ent) and then not Is_Return_Object (Ent) and then Present (Last_Assignment (Ent)) and then Last_Assignment (Ent) /= N and then not Is_Imported (Ent) and then not Is_Exported (Ent) and then Safe_To_Capture_Value (N, Ent) and then not Has_Pragma_Unreferenced_Check_Spec (Ent) and then not Has_Junk_Name (Ent) then -- Before we issue the message, check covering exception handlers. -- Search up tree for enclosing statement sequences and handlers. P := Parent (Last_Assignment (Ent)); while Present (P) loop -- Something is really wrong if we don't find a handled statement -- sequence, so just suppress the warning. if No (P) then Set_Last_Assignment (Ent, Empty); return; -- When we hit a package/subprogram body, issue warning and exit elsif Nkind (P) in N_Entry_Body | N_Package_Body | N_Subprogram_Body | N_Task_Body then -- Case of assigned value never referenced if No (N) then declare LA : constant Node_Id := Last_Assignment (Ent); begin -- Don't give this for OUT and IN OUT formals, since -- clearly caller may reference the assigned value. Also -- never give such warnings for internal variables. In -- either case, word the warning in a conditional way, -- because in the case of a component of a controlled -- type, the assigned value might be referenced in the -- Finalize operation, so we can't make a definitive -- statement that it's never referenced. if Ekind (Ent) = E_Variable and then not Is_Internal_Name (Chars (Ent)) then -- Give appropriate message, distinguishing between -- assignment statements and out parameters. if Nkind (Parent (LA)) in N_Parameter_Association | N_Procedure_Call_Statement then Error_Msg_NE ("?m?& modified by call, but value might not be " & "referenced", LA, Ent); else Error_Msg_NE -- CODEFIX ("?m?possibly useless assignment to&, value " & "might not be referenced!", LA, Ent); end if; end if; end; -- Case of assigned value overwritten else declare LA : constant Node_Id := Last_Assignment (Ent); begin Error_Msg_Sloc := Sloc (N); -- Give appropriate message, distinguishing between -- assignment statements and out parameters. if Nkind (Parent (LA)) in N_Procedure_Call_Statement | N_Parameter_Association then Error_Msg_NE ("?m?& modified by call, but value overwritten #!", LA, Ent); else Error_Msg_NE -- CODEFIX ("?m?useless assignment to&, value overwritten #!", LA, Ent); end if; end; end if; -- Clear last assignment indication and we are done Set_Last_Assignment (Ent, Empty); return; -- Enclosing handled sequence of statements elsif Nkind (P) = N_Handled_Sequence_Of_Statements then -- Check exception handlers present if Present (Exception_Handlers (P)) then -- If we are not at the top level, we regard an inner -- exception handler as a decisive indicator that we should -- not generate the warning, since the variable in question -- may be accessed after an exception in the outer block. if Nkind (Parent (P)) not in N_Entry_Body | N_Package_Body | N_Subprogram_Body | N_Task_Body then Set_Last_Assignment (Ent, Empty); return; -- Otherwise we are at the outer level. An exception -- handler is significant only if it references the -- variable in question, or if the entity in question -- is an OUT or IN OUT parameter, in which case -- the caller can reference it after the exception -- handler completes. else if Is_Formal (Ent) then Set_Last_Assignment (Ent, Empty); return; else X := First (Exception_Handlers (P)); while Present (X) loop if Test_No_Refs (X) = Abandon then Set_Last_Assignment (Ent, Empty); return; end if; Next (X); end loop; end if; end if; end if; end if; P := Parent (P); end loop; end if; end Warn_On_Useless_Assignment; --------------------------------- -- Warn_On_Useless_Assignments -- --------------------------------- procedure Warn_On_Useless_Assignments (E : Entity_Id) is Ent : Entity_Id; begin Process_Deferred_References; if Warn_On_Modified_Unread and then In_Extended_Main_Source_Unit (E) then Ent := First_Entity (E); while Present (Ent) loop Warn_On_Useless_Assignment (Ent); Next_Entity (Ent); end loop; end if; end Warn_On_Useless_Assignments; ----------------------------- -- Warnings_Off_Check_Spec -- ----------------------------- function Warnings_Off_Check_Spec (E : Entity_Id) return Boolean is begin if Is_Formal (E) and then Present (Spec_Entity (E)) then -- Note: use of OR here instead of OR ELSE is deliberate, we want -- to mess with flags on both entities. return Has_Warnings_Off (E) or Has_Warnings_Off (Spec_Entity (E)); else return Has_Warnings_Off (E); end if; end Warnings_Off_Check_Spec; end Sem_Warn;
with lace.Event; package lace_demo_Events -- -- Provides a simple derived lace 'event'. -- is pragma remote_Types; type keyboard_Event is new lace.Event.item with record Key : Character; end record; end lace_demo_Events;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2017, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ with NRF51_SVD.TIMER; with HAL; use HAL; package nRF51.Timers is type Timer (Periph : not null access NRF51_SVD.TIMER.TIMER_Peripheral) is tagged private; type Timer_Channel is range 0 .. 3; ------------------- -- Configuration -- ------------------- procedure Set_Prescaler (This : in out Timer; Prescaler : UInt4); -- Set timer prescaler value -- -- Timer frequency = HFCLK / (2**Prescaler) -- -- This procedure should only be called when the timer is stopped. type Timer_Mode is (Mode_Timer, Mode_Counter); procedure Set_Mode (This : in out Timer; Mode : Timer_Mode); -- Set timer mode: -- - Mode_Counter: Timer internal count register is incremented everytime -- the count task is triggered. -- - Mode_Timer: Timer internal count register is incremented for every -- tick of the timer clock. The frequency of the timer clock depends on -- the prescaler value (see procedure Set_Prescaler). type Timer_Bitmode is (Bitmode_8bit, Bitmode_16bit, Bitmode_24bit, Bitmode_32bit); procedure Set_Bitmode (This : in out Timer; Mode : Timer_Bitmode) with Post => Bitmode (This) = Mode; -- Set bit width of the timer internal count register. -- -- This procedure should only be called when the timer is stopped. function Bitmode (This : Timer) return Timer_Bitmode; procedure Compare_Interrupt (This : in out Timer; Chan : Timer_Channel; Enable : Boolean); -- Enable timer interupt for given compare channel ------------- -- Control -- ------------- procedure Start (This : in out Timer); -- Start the timer procedure Stop (This : in out Timer); -- Stop the timer procedure Clear (This : in out Timer); -- Clear timer internal counter --------------- -- Shortcuts -- --------------- procedure Compare_Shortcut (This : in out Timer; Chan : Timer_Channel; Stop : Boolean; Clear : Boolean); -- Clear : clear timer internal counter when compare event is triggered for -- given channel. -- Stop : stop the timer when compare envet N is triggered for given channel ----------------------- -- Capture / Compare -- ----------------------- procedure Set_Compare (This : in out Timer; Chan : Timer_Channel; Compare : UInt32); -- Set compare/capture register of given channel procedure Capture (This : in out Timer; Chan : Timer_Channel); -- Capture value of timer internal counter in the compare/capture register -- of given channel. function Capture (This : in out Timer; Chan : Timer_Channel) return UInt32; -- Capture value of timer internal counter in the compare/capture register -- of given channel and return the value of this register. function CC_Register (This : in out Timer; Chan : Timer_Channel) return UInt32; -- Return the value of compare/capture register of given channel ---------------------- -- Tasks and Events -- ---------------------- function Start_Task (This : Timer) return Task_Type; function Stop_Task (This : Timer) return Task_Type; function Count_Task (This : Timer) return Task_Type; function Clear_Task (This : Timer) return Task_Type; function Capture_Task (This : Timer; Chan : Timer_Channel) return Task_Type; function Compare_Event (This : Timer; Chan : Timer_Channel) return Event_Type; private type Timer (Periph : not null access NRF51_SVD.TIMER.TIMER_Peripheral) is tagged null record; end nRF51.Timers;
package Opt20_Pkg is procedure Write_Str (S : String); type Fail_Proc is access procedure (S : String); procedure My_Fail (S : String); Fail : Fail_Proc := My_Fail'Access; function Get_Name_String (Id : Integer) return String; end Opt20_Pkg;
-- Copyright (c) 2017 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Ada_Pretty.Definitions; package body Ada_Pretty.Declarations is -------------- -- Document -- -------------- overriding function Document (Self : Package_Body; Printer : not null access League.Pretty_Printers.Printer'Class; Pad : Natural) return League.Pretty_Printers.Document is Result : League.Pretty_Printers.Document := Printer.New_Document; Content : League.Pretty_Printers.Document := Printer.New_Document; Name : constant League.Pretty_Printers.Document := Self.Name.Document (Printer, Pad); begin Result.New_Line; Result.Put ("package body "); Result.Append (Name); Result.Put (" is"); if Self.List /= null then Content := Printer.New_Document; Content.New_Line; Content.Append (Self.List.Document (Printer, Pad)); Content.Nest (3); Result.Append (Content); end if; Result.New_Line; Result.New_Line; Result.Put ("end "); Result.Append (Name); Result.Put (";"); return Result; end Document; -------------- -- Document -- -------------- overriding function Document (Self : Package_Instantiation; Printer : not null access League.Pretty_Printers.Printer'Class; Pad : Natural) return League.Pretty_Printers.Document is Result : League.Pretty_Printers.Document := Printer.New_Document; Definition : League.Pretty_Printers.Document := Printer.New_Document; Actual_Part : League.Pretty_Printers.Document := Printer.New_Document; Name : constant League.Pretty_Printers.Document := Self.Name.Document (Printer, Pad); begin Actual_Part.New_Line; Actual_Part.Put ("("); Actual_Part.Append (Self.Actual_Part.Document (Printer, 0).Nest (1)); Actual_Part.Put (");"); Actual_Part.Nest (2); Actual_Part.Group; Definition.New_Line; Definition.Put ("new "); Definition.Append (Self.Template.Document (Printer, 0).Nest (2)); Definition.Append (Actual_Part); Definition.Nest (2); Definition.Group; Result.New_Line; Result.Put ("package "); Result.Append (Name); Result.Put (" is"); Result.Append (Definition); return Result; end Document; -------------- -- Document -- -------------- overriding function Document (Self : Package_Spec; Printer : not null access League.Pretty_Printers.Printer'Class; Pad : Natural) return League.Pretty_Printers.Document is Result : League.Pretty_Printers.Document := Printer.New_Document; Content : League.Pretty_Printers.Document := Printer.New_Document; Name : constant League.Pretty_Printers.Document := Self.Name.Document (Printer, Pad); begin Result.New_Line; Result.Put ("package "); Result.Append (Name); Result.Put (" is"); if not Self.Comment.Is_Empty or Self.Public_Part /= null then Content := Printer.New_Document; Content.New_Line; if not Self.Comment.Is_Empty then Content.Put ("-- "); Content.Put (Self.Comment); end if; if Self.Public_Part /= null then Content.Append (Self.Public_Part.Document (Printer, Pad)); end if; Content.Nest (3); Result.Append (Content); end if; if Self.Private_Part /= null then Content := Printer.New_Document; Content.Append (Self.Private_Part.Document (Printer, Pad)); Content.Nest (3); Result.New_Line; Result.Put_Line ("private"); Result.Append (Content); end if; Result.New_Line; Result.New_Line; Result.Put ("end "); Result.Append (Name); Result.Put (";"); return Result; end Document; -------------- -- Document -- -------------- overriding function Document (Self : Parameter; Printer : not null access League.Pretty_Printers.Printer'Class; Pad : Natural) return League.Pretty_Printers.Document is Result : League.Pretty_Printers.Document := Printer.New_Document; begin Result.Append (Self.Name.Document (Printer, Pad)); Result.Put (" :"); if Self.Is_Aliased then Result.Put (" aliased"); end if; if Self.Is_In then Result.Put (" in"); end if; if Self.Is_Out then Result.Put (" out"); end if; Result.Put (" "); Result.Append (Self.Type_Definition.Document (Printer, 0).Nest (2)); if Self.Initialization /= null then Result.Put (" := "); Result.Append (Self.Initialization.Document (Printer, 0)); end if; return Result; end Document; -------------- -- Document -- -------------- overriding function Document (Self : Subprogram_Body; Printer : not null access League.Pretty_Printers.Printer'Class; Pad : Natural) return League.Pretty_Printers.Document is pragma Unreferenced (Pad); Result : League.Pretty_Printers.Document := Printer.New_Document; begin Result.New_Line; Result.Append (Self.Specification.Document (Printer, 0)); Result.Put (" is"); if Self.Declarations /= null then Result.Append (Self.Declarations.Document (Printer, 0).Nest (3)); end if; Result.New_Line; Result.Put ("begin"); if Self.Statements /= null then Result.Append (Self.Statements.Document (Printer, 0).Nest (3)); end if; if Self.Exceptions /= null then Result.Put ("exception"); Result.Append (Self.Exceptions.Document (Printer, 0).Nest (3)); end if; Result.New_Line; Result.Put ("end "); Result.Append (Ada_Pretty.Definitions.Subprogram (Self.Specification.all).Name.Document (Printer, 0)); Result.Put (";"); return Result; end Document; -------------- -- Document -- -------------- overriding function Document (Self : Subprogram_Declaration; Printer : not null access League.Pretty_Printers.Printer'Class; Pad : Natural) return League.Pretty_Printers.Document is Result : League.Pretty_Printers.Document := Printer.New_Document; begin Result.New_Line; Result.Append (Self.Specification.Document (Printer, Pad)); if Self.Is_Abstract or Self.Is_Null then declare Tail : League.Pretty_Printers.Document := Printer.New_Document; begin Tail.New_Line; if Self.Is_Abstract then Tail.Put ("is abstract"); else Tail.Put ("is null"); end if; Tail.Nest (2); Tail.Group; Result.Append (Tail); end; elsif Self.Expression /= null then declare Tail : League.Pretty_Printers.Document := Printer.New_Document; Expr : League.Pretty_Printers.Document := Printer.New_Document; begin Expr.Put ("is ("); Expr.Append (Self.Expression.Document (Printer, Pad).Nest (4)); Expr.Put (")"); Tail.New_Line; Tail.Append (Expr); Tail.Nest (2); Tail.Group; Result.Append (Tail); end; elsif Self.Renamed /= null then declare Tail : League.Pretty_Printers.Document := Printer.New_Document; Expr : League.Pretty_Printers.Document := Printer.New_Document; begin Expr.Put ("renames "); Expr.Append (Self.Renamed.Document (Printer, Pad).Nest (2)); Tail.New_Line; Tail.Append (Expr); Tail.Nest (2); Tail.Group; Result.Append (Tail); end; end if; if Self.Aspects /= null then Result.Append (Print_Aspect (Self.Aspects, Printer)); end if; Result.Put (";"); return Result; end Document; -------------- -- Document -- -------------- overriding function Document (Self : Type_Declaration; Printer : not null access League.Pretty_Printers.Printer'Class; Pad : Natural) return League.Pretty_Printers.Document is pragma Unreferenced (Pad); Result : League.Pretty_Printers.Document := Printer.New_Document; Params : League.Pretty_Printers.Document := Printer.New_Document; begin Result.New_Line; Result.Put ("type "); Result.Append (Self.Name.Document (Printer, 0)); if Self.Discriminants /= null then Params.New_Line; Params.Put (" ("); Params.Append (Self.Discriminants.Document (Printer, 0).Nest (1)); Params.Put (")"); Params.Nest (1); Params.Group; Result.Append (Params); end if; if Self.Definition /= null then declare Def : League.Pretty_Printers.Document := Printer.New_Document; begin Def.New_Line; Def.Append (Self.Definition.Document (Printer, 0)); Def.Nest (2); Def.Group; Result.Put (" is"); Result.Append (Def); end; end if; Result.Append (Print_Aspect (Self.Aspects, Printer)); Result.Put (";"); return Result; end Document; -------------- -- Document -- -------------- overriding function Document (Self : Variable; Printer : not null access League.Pretty_Printers.Printer'Class; Pad : Natural) return League.Pretty_Printers.Document is Result : League.Pretty_Printers.Document := Printer.New_Document; begin Result.New_Line; Result.Append (Self.Name.Document (Printer, Pad)); Result.Put (" :"); if Self.Is_Aliased then Result.Put (" aliased"); end if; if Self.Is_Constant then Result.Put (" constant"); end if; if Self.Type_Definition /= null then Result.Put (" "); Result.Append (Self.Type_Definition.Document (Printer, 0)); end if; if Self.Initialization /= null then declare Init : League.Pretty_Printers.Document := Printer.New_Document; begin Init.New_Line; Init.Append (Self.Initialization.Document (Printer, 0)); Init.Nest (2); Init.Group; Result.Put (" :="); Result.Append (Init); end; elsif Self.Rename /= null then declare Init : League.Pretty_Printers.Document := Printer.New_Document; begin Init.New_Line; Init.Append (Self.Rename.Document (Printer, 0)); Init.Nest (2); Init.Group; Result.Put (" renames"); Result.Append (Init); end; end if; Result.Append (Print_Aspect (Self.Aspects, Printer)); Result.Put (";"); return Result; end Document; ---------- -- Join -- ---------- overriding function Join (Self : Parameter; List : Node_Access_Array; Pad : Natural; Printer : not null access League.Pretty_Printers.Printer'Class) return League.Pretty_Printers.Document is Result : League.Pretty_Printers.Document := Printer.New_Document; begin Result.Append (Self.Document (Printer, Pad)); for J in List'Range loop Result.Put (";"); Result.New_Line; Result.Append (List (J).Document (Printer, Pad)); end loop; return Result; end Join; ----------------- -- New_Package -- ----------------- function New_Package (Name : not null Node_Access; Public_Part : Node_Access; Private_Part : Node_Access; Comment : League.Strings.Universal_String) return Node'Class is begin return Package_Spec'(Name, Public_Part, Private_Part, Comment); end New_Package; ---------------------- -- New_Package_Body -- ---------------------- function New_Package_Body (Name : not null Node_Access; List : Node_Access) return Node'Class is begin return Package_Body'(Name, List); end New_Package_Body; ------------------------------- -- New_Package_Instantiation -- ------------------------------- function New_Package_Instantiation (Name : not null Node_Access; Template : not null Node_Access; Actual_Part : Node_Access; Comment : League.Strings.Universal_String) return Node'Class is begin return Package_Instantiation'(Name, Template, Actual_Part, Comment); end New_Package_Instantiation; ------------------- -- New_Parameter -- ------------------- function New_Parameter (Name : not null Node_Access; Type_Definition : Node_Access; Initialization : Node_Access; Is_In : Boolean; Is_Out : Boolean; Is_Aliased : Boolean; Comment : League.Strings.Universal_String) return Node'Class is begin return Parameter'(Name, Type_Definition, Initialization, Is_In, Is_Out, Is_Aliased, Comment); end New_Parameter; ------------------------- -- New_Subprogram_Body -- ------------------------- function New_Subprogram_Body (Specification : not null Node_Access; Declarations : Node_Access; Statements : Node_Access; Exceptions : Node_Access) return Node'Class is begin return Subprogram_Body' (Specification, Declarations, Statements, Exceptions); end New_Subprogram_Body; -------------------------------- -- New_Subprogram_Declaration -- -------------------------------- function New_Subprogram_Declaration (Specification : not null Node_Access; Aspects : Node_Access := null; Is_Abstract : Boolean; Is_Null : Boolean; Expression : Node_Access; Renamed : Node_Access; Comment : League.Strings.Universal_String) return Node'Class is begin return Subprogram_Declaration' (Specification, Aspects, Is_Abstract, Is_Null, Expression, Renamed, Comment); end New_Subprogram_Declaration; -------------- -- New_Type -- -------------- function New_Type (Name : not null Node_Access; Discriminants : Node_Access; Definition : Node_Access; Aspects : Node_Access; Comment : League.Strings.Universal_String) return Node'Class is begin return Type_Declaration' (Name, Discriminants, Definition, Aspects, Comment); end New_Type; ------------------ -- New_Variable -- ------------------ function New_Variable (Name : not null Node_Access; Type_Definition : Node_Access; Initialization : Node_Access; Rename : Node_Access; Is_Constant : Boolean; Is_Aliased : Boolean; Aspects : Node_Access; Comment : League.Strings.Universal_String) return Node'Class is begin return Variable' (Name, Type_Definition, Initialization, Rename, Is_Constant, Is_Aliased, Aspects, Comment); end New_Variable; end Ada_Pretty.Declarations;
with Ada.Text_IO; procedure double_1_20 is package T_IO renames Ada.Text_IO; package I_IO is new Ada.Text_IO.Integer_IO(Integer); procedure Power(Item : in out Integer)is begin Item:=Item*2; end Power; X:Integer := 1; begin for i in Integer range 1..30 loop I_IO.Put(X); T_IO.New_Line; Power(X); end loop; end double_1_20;
with P_StructuralTypes; use P_StructuralTypes; with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Sequential_IO; with Ada.Strings.Unbounded; package body P_StepHandler.ReverseIPHandler is function Make (Handler : in out ReverseIPHandler) return ReverseIPHandler is begin return Handler; end; overriding procedure Handle (Self : in out ReverseIPHandler) is TmpBlock : T_BinaryBlock; begin -- Looping through the 64-bits blocks of the BinaryText for BlockIndex in Self.Get_BinaryContainer'Range loop TmpBlock := Process_Block(Self, Self.Ptr_BinaryContainer.all(BlockIndex)); Replace_Block(Self.Get_BinaryContainer,BlockIndex,TmpBlock); end loop; if Self.NextHandler /= null then Self.NextHandler.Handle; end if; end; function Process_Block (Self : ReverseIPHandler ; Block : T_BinaryBlock) return T_BinaryBlock is -- PermIndex is the position of the next bit in the block PermIndex : Integer; -- TmpBlock is the binary block permuted TmpBlock : T_BinaryBlock; begin PermIndex := 40; for BitIndex in TmpBlock'Range loop -- Permuting the the bit at BitIndex, replacing it by the one at TmpBlock(BitIndex) := Block(PermIndex); -- Updating the PermIndex for the next bit permutation if (PermIndex-32 > 0) then PermIndex := PermIndex-32; elsif BitIndex mod 8 = 0 then PermIndex := PermIndex+7; else PermIndex := PermIndex+40; end if; end loop; return TmpBlock; end; end P_StepHandler.ReverseIPHandler;
with Interfaces.C, System; use type System.Address; package body FLTK.Images.Pixmaps.XPM is function new_fl_xpm_image (F : in Interfaces.C.char_array) return System.Address; pragma Import (C, new_fl_xpm_image, "new_fl_xpm_image"); pragma Inline (new_fl_xpm_image); procedure free_fl_xpm_image (P : in System.Address); pragma Import (C, free_fl_xpm_image, "free_fl_xpm_image"); pragma Inline (free_fl_xpm_image); overriding procedure Finalize (This : in out XPM_Image) is begin if This.Void_Ptr /= System.Null_Address and then This in XPM_Image'Class then free_fl_xpm_image (This.Void_Ptr); This.Void_Ptr := System.Null_Address; end if; Finalize (Pixmap (This)); end Finalize; package body Forge is function Create (Filename : in String) return XPM_Image is begin return This : XPM_Image do This.Void_Ptr := new_fl_xpm_image (Interfaces.C.To_C (Filename)); case fl_image_fail (This.Void_Ptr) is when 1 => raise No_Image_Error; when 2 => raise File_Access_Error; when 3 => raise Format_Error; when others => null; end case; end return; end Create; end Forge; end FLTK.Images.Pixmaps.XPM;
pragma License (Unrestricted); -- implementation unit package System.Formatting.Decimal is pragma Pure; procedure Image ( Value : Long_Long_Integer; Item : out String; -- To'Length >= T'Fore + T'Aft + 1 (.) Fore_Last, Last : out Natural; Scale : Integer; Signs : Sign_Marks := ('-', ' ', ' '); Fore_Digits_Width : Positive := 1; Fore_Digits_Fill : Character := '0'; Aft_Width : Natural); end System.Formatting.Decimal;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- S Y S T E M . V A L U E _ N -- -- -- -- S p e c -- -- -- -- Copyright (C) 2021, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- -- -- -- -- -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This package is used to compute the Value attribute for enumeration types -- other than those in packages Standard and System. See unit Exp_Imgv for -- details of the format of constructed image tables. generic type Index_Type is range <>; package System.Value_N is pragma Preelaborate; type Hash_Function_Ptr is access function (S : String) return Natural; function Value_Enumeration (Names : String; Indexes : System.Address; Hash : Hash_Function_Ptr; Num : Natural; Str : String) return Natural with Inline; -- Used to compute Enum'Value (Str) where Enum is some enumeration type -- other than those defined in package Standard. Names is a string with -- a lower bound of 1 containing the characters of all the enumeration -- literals concatenated together in sequence. Indexes is the address -- of an array of type array (0 .. N) of Index_Type, where N is the -- number of enumeration literals in the type. The Indexes values are -- the starting subscript of each enumeration literal, indexed by Pos -- values, with an extra entry at the end containing Names'Length + 1. -- The parameter Hash is a (perfect) hash function for Names and Indexes. -- The parameter Num is the value N - 1 (i.e. Enum'Pos (Enum'Last)). -- The reason that Indexes is passed by address is that the actual type -- is created on the fly by the expander. -- -- Str is the argument of the attribute function, and may have leading -- and trailing spaces, and letters can be upper or lower case or mixed. -- If the image is found in Names, then the corresponding Pos value is -- returned. If not, Constraint_Error is raised. function Valid_Value_Enumeration (Names : String; Indexes : System.Address; Hash : Hash_Function_Ptr; Num : Natural; Str : String) return Boolean with Inline; -- Returns True if Str is a valid Image of some enumeration literal, False -- otherwise. That is, returns False if and only if Value_Enumeration would -- raise Constraint_Error. The parameters have the same meaning as for -- Value_Enumeration. end System.Value_N;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2010-2017, Vadim Godunko <vgodunko@gmail.com> -- -- 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 Matreshka.Internals.Strings; package AMF.Internals.Tables.OCL_String_Data_00 is -- "referredAssociationClass" MS_0000 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 31, Unused => 24, Length => 24, Value => (16#0072#, 16#0065#, 16#0066#, 16#0065#, 16#0072#, 16#0072#, 16#0065#, 16#0064#, 16#0041#, 16#0073#, 16#0073#, 16#006F#, 16#0063#, 16#0069#, 16#0061#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, 16#0043#, 16#006C#, 16#0061#, 16#0073#, 16#0073#, others => 16#0000#), others => <>); -- "BooleanLiteralExp" MS_0001 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 17, Length => 17, Value => (16#0042#, 16#006F#, 16#006F#, 16#006C#, 16#0065#, 16#0061#, 16#006E#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "OCL" MS_0002 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 3, Length => 3, Value => (16#004F#, 16#0043#, 16#004C#, others => 16#0000#), others => <>); -- "calledOperation" MS_0003 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 15, Length => 15, Value => (16#0063#, 16#0061#, 16#006C#, 16#006C#, 16#0065#, 16#0064#, 16#004F#, 16#0070#, 16#0065#, 16#0072#, 16#0061#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, others => 16#0000#), others => <>); -- "resultOwner" MS_0004 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 11, Length => 11, Value => (16#0072#, 16#0065#, 16#0073#, 16#0075#, 16#006C#, 16#0074#, 16#004F#, 16#0077#, 16#006E#, 16#0065#, 16#0072#, others => 16#0000#), others => <>); -- "parentCall" MS_0005 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 10, Length => 10, Value => (16#0070#, 16#0061#, 16#0072#, 16#0065#, 16#006E#, 16#0074#, 16#0043#, 16#0061#, 16#006C#, 16#006C#, others => 16#0000#), others => <>); -- "LiteralExp" MS_0006 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 10, Length => 10, Value => (16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "TypeExp" MS_0007 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 7, Length => 7, Value => (16#0054#, 16#0079#, 16#0070#, 16#0065#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "literalExp" MS_0008 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 10, Length => 10, Value => (16#006C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "exp1" MS_0009 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#0065#, 16#0078#, 16#0070#, 16#0031#, others => 16#0000#), others => <>); -- "InvalidType" MS_000A : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 11, Length => 11, Value => (16#0049#, 16#006E#, 16#0076#, 16#0061#, 16#006C#, 16#0069#, 16#0064#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "exp9" MS_000B : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#0065#, 16#0078#, 16#0070#, 16#0039#, others => 16#0000#), others => <>); -- "VariableExp" MS_000C : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 11, Length => 11, Value => (16#0056#, 16#0061#, 16#0072#, 16#0069#, 16#0061#, 16#0062#, 16#006C#, 16#0065#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "referringExp" MS_000D : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 12, Length => 12, Value => (16#0072#, 16#0065#, 16#0066#, 16#0065#, 16#0072#, 16#0072#, 16#0069#, 16#006E#, 16#0067#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "PropertyCallExp" MS_000E : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 15, Length => 15, Value => (16#0050#, 16#0072#, 16#006F#, 16#0070#, 16#0065#, 16#0072#, 16#0074#, 16#0079#, 16#0043#, 16#0061#, 16#006C#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "representedParameter" MS_000F : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 20, Length => 20, Value => (16#0072#, 16#0065#, 16#0070#, 16#0072#, 16#0065#, 16#0073#, 16#0065#, 16#006E#, 16#0074#, 16#0065#, 16#0064#, 16#0050#, 16#0061#, 16#0072#, 16#0061#, 16#006D#, 16#0065#, 16#0074#, 16#0065#, 16#0072#, others => 16#0000#), others => <>); -- "realSymbol" MS_0010 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 10, Length => 10, Value => (16#0072#, 16#0065#, 16#0061#, 16#006C#, 16#0053#, 16#0079#, 16#006D#, 16#0062#, 16#006F#, 16#006C#, others => 16#0000#), others => <>); -- "Variable" MS_0011 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 8, Length => 8, Value => (16#0056#, 16#0061#, 16#0072#, 16#0069#, 16#0061#, 16#0062#, 16#006C#, 16#0065#, others => 16#0000#), others => <>); -- "referredSignal" MS_0012 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#0072#, 16#0065#, 16#0066#, 16#0065#, 16#0072#, 16#0072#, 16#0065#, 16#0064#, 16#0053#, 16#0069#, 16#0067#, 16#006E#, 16#0061#, 16#006C#, others => 16#0000#), others => <>); -- "argument" MS_0013 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 8, Length => 8, Value => (16#0061#, 16#0072#, 16#0067#, 16#0075#, 16#006D#, 16#0065#, 16#006E#, 16#0074#, others => 16#0000#), others => <>); -- "thenOwner" MS_0014 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 9, Length => 9, Value => (16#0074#, 16#0068#, 16#0065#, 16#006E#, 16#004F#, 16#0077#, 16#006E#, 16#0065#, 16#0072#, others => 16#0000#), others => <>); -- "owningClassifier" MS_0015 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 16, Length => 16, Value => (16#006F#, 16#0077#, 16#006E#, 16#0069#, 16#006E#, 16#0067#, 16#0043#, 16#006C#, 16#0061#, 16#0073#, 16#0073#, 16#0069#, 16#0066#, 16#0069#, 16#0065#, 16#0072#, others => 16#0000#), others => <>); -- "item" MS_0016 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#0069#, 16#0074#, 16#0065#, 16#006D#, others => 16#0000#), others => <>); -- "referredProperty" MS_0017 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 16, Length => 16, Value => (16#0072#, 16#0065#, 16#0066#, 16#0065#, 16#0072#, 16#0072#, 16#0065#, 16#0064#, 16#0050#, 16#0072#, 16#006F#, 16#0070#, 16#0065#, 16#0072#, 16#0074#, 16#0079#, others => 16#0000#), others => <>); -- "exp11" MS_0018 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 5, Length => 5, Value => (16#0065#, 16#0078#, 16#0070#, 16#0031#, 16#0031#, others => 16#0000#), others => <>); -- "TupleLiteralPart" MS_0019 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 16, Length => 16, Value => (16#0054#, 16#0075#, 16#0070#, 16#006C#, 16#0065#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0050#, 16#0061#, 16#0072#, 16#0074#, others => 16#0000#), others => <>); -- "CollectionRange" MS_001A : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 15, Length => 15, Value => (16#0043#, 16#006F#, 16#006C#, 16#006C#, 16#0065#, 16#0063#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, 16#0052#, 16#0061#, 16#006E#, 16#0067#, 16#0065#, others => 16#0000#), others => <>); -- "integerSymbol" MS_001B : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 13, Length => 13, Value => (16#0069#, 16#006E#, 16#0074#, 16#0065#, 16#0067#, 16#0065#, 16#0072#, 16#0053#, 16#0079#, 16#006D#, 16#0062#, 16#006F#, 16#006C#, others => 16#0000#), others => <>); -- "referredOperation" MS_001C : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 17, Length => 17, Value => (16#0072#, 16#0065#, 16#0066#, 16#0065#, 16#0072#, 16#0072#, 16#0065#, 16#0064#, 16#004F#, 16#0070#, 16#0065#, 16#0072#, 16#0061#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, others => 16#0000#), others => <>); -- "EnumLiteralExp" MS_001D : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#0045#, 16#006E#, 16#0075#, 16#006D#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "stringSymbol" MS_001E : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 12, Length => 12, Value => (16#0073#, 16#0074#, 16#0072#, 16#0069#, 16#006E#, 16#0067#, 16#0053#, 16#0079#, 16#006D#, 16#0062#, 16#006F#, 16#006C#, others => 16#0000#), others => <>); -- "AnyType" MS_001F : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 7, Length => 7, Value => (16#0041#, 16#006E#, 16#0079#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "InvalidLiteralExp" MS_0020 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 17, Length => 17, Value => (16#0049#, 16#006E#, 16#0076#, 16#0061#, 16#006C#, 16#0069#, 16#0064#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "Bag" MS_0021 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 3, Length => 3, Value => (16#0042#, 16#0061#, 16#0067#, others => 16#0000#), others => <>); -- "bodyExpression" MS_0022 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#0062#, 16#006F#, 16#0064#, 16#0079#, 16#0045#, 16#0078#, 16#0070#, 16#0072#, 16#0065#, 16#0073#, 16#0073#, 16#0069#, 16#006F#, 16#006E#, others => 16#0000#), others => <>); -- "ExpressionInOcl" MS_0023 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 15, Length => 15, Value => (16#0045#, 16#0078#, 16#0070#, 16#0072#, 16#0065#, 16#0073#, 16#0073#, 16#0069#, 16#006F#, 16#006E#, 16#0049#, 16#006E#, 16#004F#, 16#0063#, 16#006C#, others => 16#0000#), others => <>); -- "CollectionKind" MS_0024 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#0043#, 16#006F#, 16#006C#, 16#006C#, 16#0065#, 16#0063#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, 16#004B#, 16#0069#, 16#006E#, 16#0064#, others => 16#0000#), others => <>); -- "resultVariable" MS_0025 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#0072#, 16#0065#, 16#0073#, 16#0075#, 16#006C#, 16#0074#, 16#0056#, 16#0061#, 16#0072#, 16#0069#, 16#0061#, 16#0062#, 16#006C#, 16#0065#, others => 16#0000#), others => <>); -- "result" MS_0026 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 6, Length => 6, Value => (16#0072#, 16#0065#, 16#0073#, 16#0075#, 16#006C#, 16#0074#, others => 16#0000#), others => <>); -- "initExpression" MS_0027 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#0069#, 16#006E#, 16#0069#, 16#0074#, 16#0045#, 16#0078#, 16#0070#, 16#0072#, 16#0065#, 16#0073#, 16#0073#, 16#0069#, 16#006F#, 16#006E#, others => 16#0000#), others => <>); -- "thenExpression" MS_0028 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#0074#, 16#0068#, 16#0065#, 16#006E#, 16#0045#, 16#0078#, 16#0070#, 16#0072#, 16#0065#, 16#0073#, 16#0073#, 16#0069#, 16#006F#, 16#006E#, others => 16#0000#), others => <>); -- "NullLiteralExp" MS_0029 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#004E#, 16#0075#, 16#006C#, 16#006C#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "attribute" MS_002A : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 9, Length => 9, Value => (16#0061#, 16#0074#, 16#0074#, 16#0072#, 16#0069#, 16#0062#, 16#0075#, 16#0074#, 16#0065#, others => 16#0000#), others => <>); -- "varOwner" MS_002B : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 8, Length => 8, Value => (16#0076#, 16#0061#, 16#0072#, 16#004F#, 16#0077#, 16#006E#, 16#0065#, 16#0072#, others => 16#0000#), others => <>); -- "MessageType" MS_002C : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 11, Length => 11, Value => (16#004D#, 16#0065#, 16#0073#, 16#0073#, 16#0061#, 16#0067#, 16#0065#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "generatedType" MS_002D : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 13, Length => 13, Value => (16#0067#, 16#0065#, 16#006E#, 16#0065#, 16#0072#, 16#0061#, 16#0074#, 16#0065#, 16#0064#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "appliedElement" MS_002E : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#0061#, 16#0070#, 16#0070#, 16#006C#, 16#0069#, 16#0065#, 16#0064#, 16#0045#, 16#006C#, 16#0065#, 16#006D#, 16#0065#, 16#006E#, 16#0074#, others => 16#0000#), others => <>); -- "booleanSymbol" MS_002F : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 13, Length => 13, Value => (16#0062#, 16#006F#, 16#006F#, 16#006C#, 16#0065#, 16#0061#, 16#006E#, 16#0053#, 16#0079#, 16#006D#, 16#0062#, 16#006F#, 16#006C#, others => 16#0000#), others => <>); -- "CollectionLiteralPart" MS_0030 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 21, Length => 21, Value => (16#0043#, 16#006F#, 16#006C#, 16#006C#, 16#0065#, 16#0063#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0050#, 16#0061#, 16#0072#, 16#0074#, others => 16#0000#), others => <>); -- "navigationSource" MS_0031 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 16, Length => 16, Value => (16#006E#, 16#0061#, 16#0076#, 16#0069#, 16#0067#, 16#0061#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, 16#0053#, 16#006F#, 16#0075#, 16#0072#, 16#0063#, 16#0065#, others => 16#0000#), others => <>); -- "IterateExp" MS_0032 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 10, Length => 10, Value => (16#0049#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#0074#, 16#0065#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "type1" MS_0033 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 5, Length => 5, Value => (16#0074#, 16#0079#, 16#0070#, 16#0065#, 16#0031#, others => 16#0000#), others => <>); -- "condition" MS_0034 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 9, Length => 9, Value => (16#0063#, 16#006F#, 16#006E#, 16#0064#, 16#0069#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, others => 16#0000#), others => <>); -- "firstOwner" MS_0035 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 10, Length => 10, Value => (16#0066#, 16#0069#, 16#0072#, 16#0073#, 16#0074#, 16#004F#, 16#0077#, 16#006E#, 16#0065#, 16#0072#, others => 16#0000#), others => <>); -- "parameterVariable" MS_0036 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 17, Length => 17, Value => (16#0070#, 16#0061#, 16#0072#, 16#0061#, 16#006D#, 16#0065#, 16#0074#, 16#0065#, 16#0072#, 16#0056#, 16#0061#, 16#0072#, 16#0069#, 16#0061#, 16#0062#, 16#006C#, 16#0065#, others => 16#0000#), others => <>); -- "exp2" MS_0037 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#0065#, 16#0078#, 16#0070#, 16#0032#, others => 16#0000#), others => <>); -- "specification" MS_0038 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 13, Length => 13, Value => (16#0073#, 16#0070#, 16#0065#, 16#0063#, 16#0069#, 16#0066#, 16#0069#, 16#0063#, 16#0061#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, others => 16#0000#), others => <>); -- "VoidType" MS_0039 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 8, Length => 8, Value => (16#0056#, 16#006F#, 16#0069#, 16#0064#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "BagType" MS_003A : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 7, Length => 7, Value => (16#0042#, 16#0061#, 16#0067#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "IntegerLiteralExp" MS_003B : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 17, Length => 17, Value => (16#0049#, 16#006E#, 16#0074#, 16#0065#, 16#0067#, 16#0065#, 16#0072#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "elseExpression" MS_003C : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#0065#, 16#006C#, 16#0073#, 16#0065#, 16#0045#, 16#0078#, 16#0070#, 16#0072#, 16#0065#, 16#0073#, 16#0073#, 16#0069#, 16#006F#, 16#006E#, others => 16#0000#), others => <>); -- "target" MS_003D : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 6, Length => 6, Value => (16#0074#, 16#0061#, 16#0072#, 16#0067#, 16#0065#, 16#0074#, others => 16#0000#), others => <>); -- "CollectionLiteralExp" MS_003E : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 20, Length => 20, Value => (16#0043#, 16#006F#, 16#006C#, 16#006C#, 16#0065#, 16#0063#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "exp3" MS_003F : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#0065#, 16#0078#, 16#0070#, 16#0033#, others => 16#0000#), others => <>); -- "FeatureCallExp" MS_0040 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#0046#, 16#0065#, 16#0061#, 16#0074#, 16#0075#, 16#0072#, 16#0065#, 16#0043#, 16#0061#, 16#006C#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "OrderedSetType" MS_0041 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#004F#, 16#0072#, 16#0064#, 16#0065#, 16#0072#, 16#0065#, 16#0064#, 16#0053#, 16#0065#, 16#0074#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "item1" MS_0042 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 5, Length => 5, Value => (16#0069#, 16#0074#, 16#0065#, 16#006D#, 16#0031#, others => 16#0000#), others => <>); -- "exp4" MS_0043 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#0065#, 16#0078#, 16#0070#, 16#0034#, others => 16#0000#), others => <>); -- "contextVariable" MS_0044 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 15, Length => 15, Value => (16#0063#, 16#006F#, 16#006E#, 16#0074#, 16#0065#, 16#0078#, 16#0074#, 16#0056#, 16#0061#, 16#0072#, 16#0069#, 16#0061#, 16#0062#, 16#006C#, 16#0065#, others => 16#0000#), others => <>); -- "unlimitedNaturalSymbol" MS_0045 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 22, Length => 22, Value => (16#0075#, 16#006E#, 16#006C#, 16#0069#, 16#006D#, 16#0069#, 16#0074#, 16#0065#, 16#0064#, 16#004E#, 16#0061#, 16#0074#, 16#0075#, 16#0072#, 16#0061#, 16#006C#, 16#0053#, 16#0079#, 16#006D#, 16#0062#, 16#006F#, 16#006C#, others => 16#0000#), others => <>); -- "AssociationClassCallExp" MS_0046 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 31, Unused => 23, Length => 23, Value => (16#0041#, 16#0073#, 16#0073#, 16#006F#, 16#0063#, 16#0069#, 16#0061#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, 16#0043#, 16#006C#, 16#0061#, 16#0073#, 16#0073#, 16#0043#, 16#0061#, 16#006C#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "http://www.omg.org/spec/OCL/20090501" MS_0047 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 39, Unused => 36, Length => 36, Value => (16#0068#, 16#0074#, 16#0074#, 16#0070#, 16#003A#, 16#002F#, 16#002F#, 16#0077#, 16#0077#, 16#0077#, 16#002E#, 16#006F#, 16#006D#, 16#0067#, 16#002E#, 16#006F#, 16#0072#, 16#0067#, 16#002F#, 16#0073#, 16#0070#, 16#0065#, 16#0063#, 16#002F#, 16#004F#, 16#0043#, 16#004C#, 16#002F#, 16#0032#, 16#0030#, 16#0030#, 16#0039#, 16#0030#, 16#0035#, 16#0030#, 16#0031#, others => 16#0000#), others => <>); -- "IfExp" MS_0048 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 5, Length => 5, Value => (16#0049#, 16#0066#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "OclExpression" MS_0049 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 13, Length => 13, Value => (16#004F#, 16#0063#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, 16#0072#, 16#0065#, 16#0073#, 16#0073#, 16#0069#, 16#006F#, 16#006E#, others => 16#0000#), others => <>); -- "loopExp" MS_004A : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 7, Length => 7, Value => (16#006C#, 16#006F#, 16#006F#, 16#0070#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "NavigationCallExp" MS_004B : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 17, Length => 17, Value => (16#004E#, 16#0061#, 16#0076#, 16#0069#, 16#0067#, 16#0061#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, 16#0043#, 16#0061#, 16#006C#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "CollectionItem" MS_004C : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#0043#, 16#006F#, 16#006C#, 16#006C#, 16#0065#, 16#0063#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, 16#0049#, 16#0074#, 16#0065#, 16#006D#, others => 16#0000#), others => <>); -- "CollectionType" MS_004D : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#0043#, 16#006F#, 16#006C#, 16#006C#, 16#0065#, 16#0063#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "OrderedSet" MS_004E : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 10, Length => 10, Value => (16#004F#, 16#0072#, 16#0064#, 16#0065#, 16#0072#, 16#0065#, 16#0064#, 16#0053#, 16#0065#, 16#0074#, others => 16#0000#), others => <>); -- "in" MS_004F : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 2, Length => 2, Value => (16#0069#, 16#006E#, others => 16#0000#), others => <>); -- "topExpression" MS_0050 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 13, Length => 13, Value => (16#0074#, 16#006F#, 16#0070#, 16#0045#, 16#0078#, 16#0070#, 16#0072#, 16#0065#, 16#0073#, 16#0073#, 16#0069#, 16#006F#, 16#006E#, others => 16#0000#), others => <>); -- "StateExp" MS_0051 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 8, Length => 8, Value => (16#0053#, 16#0074#, 16#0061#, 16#0074#, 16#0065#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "TupleType" MS_0052 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 9, Length => 9, Value => (16#0054#, 16#0075#, 16#0070#, 16#006C#, 16#0065#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "sentSignal" MS_0053 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 10, Length => 10, Value => (16#0073#, 16#0065#, 16#006E#, 16#0074#, 16#0053#, 16#0069#, 16#0067#, 16#006E#, 16#0061#, 16#006C#, others => 16#0000#), others => <>); -- "OperationCallExp" MS_0054 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 16, Length => 16, Value => (16#004F#, 16#0070#, 16#0065#, 16#0072#, 16#0061#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, 16#0043#, 16#0061#, 16#006C#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "referredType" MS_0055 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 12, Length => 12, Value => (16#0072#, 16#0065#, 16#0066#, 16#0065#, 16#0072#, 16#0072#, 16#0065#, 16#0064#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "body" MS_0056 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#0062#, 16#006F#, 16#0064#, 16#0079#, others => 16#0000#), others => <>); -- "kind" MS_0057 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#006B#, 16#0069#, 16#006E#, 16#0064#, others => 16#0000#), others => <>); -- "RealLiteralExp" MS_0058 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 14, Length => 14, Value => (16#0052#, 16#0065#, 16#0061#, 16#006C#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "loopBodyOwner" MS_0059 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 13, Length => 13, Value => (16#006C#, 16#006F#, 16#006F#, 16#0070#, 16#0042#, 16#006F#, 16#0064#, 16#0079#, 16#004F#, 16#0077#, 16#006E#, 16#0065#, 16#0072#, others => 16#0000#), others => <>); -- "Sequence" MS_005A : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 8, Length => 8, Value => (16#0053#, 16#0065#, 16#0071#, 16#0075#, 16#0065#, 16#006E#, 16#0063#, 16#0065#, others => 16#0000#), others => <>); -- "variable" MS_005B : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 8, Length => 8, Value => (16#0076#, 16#0061#, 16#0072#, 16#0069#, 16#0061#, 16#0062#, 16#006C#, 16#0065#, others => 16#0000#), others => <>); -- "TupleLiteralExp" MS_005C : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 15, Length => 15, Value => (16#0054#, 16#0075#, 16#0070#, 16#006C#, 16#0065#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "PrimitiveLiteralExp" MS_005D : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 19, Length => 19, Value => (16#0050#, 16#0072#, 16#0069#, 16#006D#, 16#0069#, 16#0074#, 16#0069#, 16#0076#, 16#0065#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "UnspecifiedValueExp" MS_005E : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 19, Length => 19, Value => (16#0055#, 16#006E#, 16#0073#, 16#0070#, 16#0065#, 16#0063#, 16#0069#, 16#0066#, 16#0069#, 16#0065#, 16#0064#, 16#0056#, 16#0061#, 16#006C#, 16#0075#, 16#0065#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "iterator" MS_005F : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 8, Length => 8, Value => (16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#0074#, 16#006F#, 16#0072#, others => 16#0000#), others => <>); -- "StringLiteralExp" MS_0060 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 16, Length => 16, Value => (16#0053#, 16#0074#, 16#0072#, 16#0069#, 16#006E#, 16#0067#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "TemplateParameterType" MS_0061 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 21, Length => 21, Value => (16#0054#, 16#0065#, 16#006D#, 16#0070#, 16#006C#, 16#0061#, 16#0074#, 16#0065#, 16#0050#, 16#0061#, 16#0072#, 16#0061#, 16#006D#, 16#0065#, 16#0074#, 16#0065#, 16#0072#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "LetExp" MS_0062 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 6, Length => 6, Value => (16#004C#, 16#0065#, 16#0074#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "exp6" MS_0063 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#0065#, 16#0078#, 16#0070#, 16#0036#, others => 16#0000#), others => <>); -- "elementType" MS_0064 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 11, Length => 11, Value => (16#0065#, 16#006C#, 16#0065#, 16#006D#, 16#0065#, 16#006E#, 16#0074#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "part" MS_0065 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#0070#, 16#0061#, 16#0072#, 16#0074#, others => 16#0000#), others => <>); -- "Collection" MS_0066 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 10, Length => 10, Value => (16#0043#, 16#006F#, 16#006C#, 16#006C#, 16#0065#, 16#0063#, 16#0074#, 16#0069#, 16#006F#, 16#006E#, others => 16#0000#), others => <>); -- "type2" MS_0067 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 5, Length => 5, Value => (16#0074#, 16#0079#, 16#0070#, 16#0065#, 16#0032#, others => 16#0000#), others => <>); -- "referredState" MS_0068 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 13, Length => 13, Value => (16#0072#, 16#0065#, 16#0066#, 16#0065#, 16#0072#, 16#0072#, 16#0065#, 16#0064#, 16#0053#, 16#0074#, 16#0061#, 16#0074#, 16#0065#, others => 16#0000#), others => <>); -- "elseOwner" MS_0069 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 9, Length => 9, Value => (16#0065#, 16#006C#, 16#0073#, 16#0065#, 16#004F#, 16#0077#, 16#006E#, 16#0065#, 16#0072#, others => 16#0000#), others => <>); -- "parentNav" MS_006A : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 9, Length => 9, Value => (16#0070#, 16#0061#, 16#0072#, 16#0065#, 16#006E#, 16#0074#, 16#004E#, 16#0061#, 16#0076#, others => 16#0000#), others => <>); -- "qualifier" MS_006B : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 9, Length => 9, Value => (16#0071#, 16#0075#, 16#0061#, 16#006C#, 16#0069#, 16#0066#, 16#0069#, 16#0065#, 16#0072#, others => 16#0000#), others => <>); -- "ifOwner" MS_006C : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 7, Length => 7, Value => (16#0069#, 16#0066#, 16#004F#, 16#0077#, 16#006E#, 16#0065#, 16#0072#, others => 16#0000#), others => <>); -- "last" MS_006D : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#006C#, 16#0061#, 16#0073#, 16#0074#, others => 16#0000#), others => <>); -- "first" MS_006E : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 5, Length => 5, Value => (16#0066#, 16#0069#, 16#0072#, 16#0073#, 16#0074#, others => 16#0000#), others => <>); -- "NumericLiteralExp" MS_006F : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 17, Length => 17, Value => (16#004E#, 16#0075#, 16#006D#, 16#0065#, 16#0072#, 16#0069#, 16#0063#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "baseExp" MS_0070 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 7, Length => 7, Value => (16#0062#, 16#0061#, 16#0073#, 16#0065#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "part2" MS_0071 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 5, Length => 5, Value => (16#0070#, 16#0061#, 16#0072#, 16#0074#, 16#0032#, others => 16#0000#), others => <>); -- "lastOwner" MS_0072 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 9, Length => 9, Value => (16#006C#, 16#0061#, 16#0073#, 16#0074#, 16#004F#, 16#0077#, 16#006E#, 16#0065#, 16#0072#, others => 16#0000#), others => <>); -- "SequenceType" MS_0073 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 12, Length => 12, Value => (16#0053#, 16#0065#, 16#0071#, 16#0075#, 16#0065#, 16#006E#, 16#0063#, 16#0065#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "IteratorExp" MS_0074 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 11, Length => 11, Value => (16#0049#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#0074#, 16#006F#, 16#0072#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "UnlimitedNaturalLiteralExp" MS_0075 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 31, Unused => 26, Length => 26, Value => (16#0055#, 16#006E#, 16#006C#, 16#0069#, 16#006D#, 16#0069#, 16#0074#, 16#0065#, 16#0064#, 16#004E#, 16#0061#, 16#0074#, 16#0075#, 16#0072#, 16#0061#, 16#006C#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "exp7" MS_0076 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#0065#, 16#0078#, 16#0070#, 16#0037#, others => 16#0000#), others => <>); -- "type3" MS_0077 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 5, Length => 5, Value => (16#0074#, 16#0079#, 16#0070#, 16#0065#, 16#0033#, others => 16#0000#), others => <>); -- "selfOwner" MS_0078 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 9, Length => 9, Value => (16#0073#, 16#0065#, 16#006C#, 16#0066#, 16#004F#, 16#0077#, 16#006E#, 16#0065#, 16#0072#, others => 16#0000#), others => <>); -- "LoopExp" MS_0079 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 7, Length => 7, Value => (16#004C#, 16#006F#, 16#006F#, 16#0070#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "referredVariable" MS_007A : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 16, Length => 16, Value => (16#0072#, 16#0065#, 16#0066#, 16#0065#, 16#0072#, 16#0072#, 16#0065#, 16#0064#, 16#0056#, 16#0061#, 16#0072#, 16#0069#, 16#0061#, 16#0062#, 16#006C#, 16#0065#, others => 16#0000#), others => <>); -- "initializedElement" MS_007B : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 18, Length => 18, Value => (16#0069#, 16#006E#, 16#0069#, 16#0074#, 16#0069#, 16#0061#, 16#006C#, 16#0069#, 16#007A#, 16#0065#, 16#0064#, 16#0045#, 16#006C#, 16#0065#, 16#006D#, 16#0065#, 16#006E#, 16#0074#, others => 16#0000#), others => <>); -- "exp8" MS_007C : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#0065#, 16#0078#, 16#0070#, 16#0038#, others => 16#0000#), others => <>); -- "MessageExp" MS_007D : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 10, Length => 10, Value => (16#004D#, 16#0065#, 16#0073#, 16#0073#, 16#0061#, 16#0067#, 16#0065#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "source" MS_007E : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 6, Length => 6, Value => (16#0073#, 16#006F#, 16#0075#, 16#0072#, 16#0063#, 16#0065#, others => 16#0000#), others => <>); -- "referingExp" MS_007F : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 11, Length => 11, Value => (16#0072#, 16#0065#, 16#0066#, 16#0065#, 16#0072#, 16#0069#, 16#006E#, 16#0067#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "CallExp" MS_0080 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 7, Length => 7, Value => (16#0043#, 16#0061#, 16#006C#, 16#006C#, 16#0045#, 16#0078#, 16#0070#, others => 16#0000#), others => <>); -- "SetType" MS_0081 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 15, Unused => 7, Length => 7, Value => (16#0053#, 16#0065#, 16#0074#, 16#0054#, 16#0079#, 16#0070#, 16#0065#, others => 16#0000#), others => <>); -- "exp5" MS_0082 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 4, Length => 4, Value => (16#0065#, 16#0078#, 16#0070#, 16#0035#, others => 16#0000#), others => <>); -- "referredEnumLiteral" MS_0083 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 23, Unused => 19, Length => 19, Value => (16#0072#, 16#0065#, 16#0066#, 16#0065#, 16#0072#, 16#0072#, 16#0065#, 16#0064#, 16#0045#, 16#006E#, 16#0075#, 16#006D#, 16#004C#, 16#0069#, 16#0074#, 16#0065#, 16#0072#, 16#0061#, 16#006C#, others => 16#0000#), others => <>); -- "Set" MS_0084 : aliased Matreshka.Internals.Strings.Shared_String := (Capacity => 7, Unused => 3, Length => 3, Value => (16#0053#, 16#0065#, 16#0074#, others => 16#0000#), others => <>); end AMF.Internals.Tables.OCL_String_Data_00;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- I N T E R F A C E S . C . E X T E N S I O N S -- -- -- -- S p e c -- -- -- -- Copyright (C) 1992-2010, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- -- -- -- -- -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This package contains additional C-related definitions, intended for use -- with either manually or automatically generated bindings to C libraries. with System; package Interfaces.C.Extensions is pragma Pure; -- Definitions for C "void" and "void *" types subtype void is System.Address; subtype void_ptr is System.Address; -- Definitions for C incomplete/unknown structs subtype opaque_structure_def is System.Address; type opaque_structure_def_ptr is access opaque_structure_def; for opaque_structure_def_ptr'Storage_Size use 0; -- Definitions for C++ incomplete/unknown classes subtype incomplete_class_def is System.Address; type incomplete_class_def_ptr is access incomplete_class_def; for incomplete_class_def_ptr'Storage_Size use 0; -- C bool subtype bool is plain_char; -- 64-bit integer types subtype long_long is Long_Long_Integer; type unsigned_long_long is mod 2 ** 64; -- 128-bit integer type available on 64-bit platforms: -- typedef int signed_128 __attribute__ ((mode (TI))); type Signed_128 is record low, high : unsigned_long_long; end record; pragma Convention (C_Pass_By_Copy, Signed_128); for Signed_128'Alignment use unsigned_long_long'Alignment * 2; -- Types for bitfields type Unsigned_1 is mod 2 ** 1; for Unsigned_1'Size use 1; type Unsigned_2 is mod 2 ** 2; for Unsigned_2'Size use 2; type Unsigned_3 is mod 2 ** 3; for Unsigned_3'Size use 3; type Unsigned_4 is mod 2 ** 4; for Unsigned_4'Size use 4; type Unsigned_5 is mod 2 ** 5; for Unsigned_5'Size use 5; type Unsigned_6 is mod 2 ** 6; for Unsigned_6'Size use 6; type Unsigned_7 is mod 2 ** 7; for Unsigned_7'Size use 7; type Unsigned_8 is mod 2 ** 8; for Unsigned_8'Size use 8; type Unsigned_9 is mod 2 ** 9; for Unsigned_9'Size use 9; type Unsigned_10 is mod 2 ** 10; for Unsigned_10'Size use 10; type Unsigned_11 is mod 2 ** 11; for Unsigned_11'Size use 11; type Unsigned_12 is mod 2 ** 12; for Unsigned_12'Size use 12; type Unsigned_13 is mod 2 ** 13; for Unsigned_13'Size use 13; type Unsigned_14 is mod 2 ** 14; for Unsigned_14'Size use 14; type Unsigned_15 is mod 2 ** 15; for Unsigned_15'Size use 15; type Unsigned_16 is mod 2 ** 16; for Unsigned_16'Size use 16; type Unsigned_17 is mod 2 ** 17; for Unsigned_17'Size use 17; type Unsigned_18 is mod 2 ** 18; for Unsigned_18'Size use 18; type Unsigned_19 is mod 2 ** 19; for Unsigned_19'Size use 19; type Unsigned_20 is mod 2 ** 20; for Unsigned_20'Size use 20; type Unsigned_21 is mod 2 ** 21; for Unsigned_21'Size use 21; type Unsigned_22 is mod 2 ** 22; for Unsigned_22'Size use 22; type Unsigned_23 is mod 2 ** 23; for Unsigned_23'Size use 23; type Unsigned_24 is mod 2 ** 24; for Unsigned_24'Size use 24; type Unsigned_25 is mod 2 ** 25; for Unsigned_25'Size use 25; type Unsigned_26 is mod 2 ** 26; for Unsigned_26'Size use 26; type Unsigned_27 is mod 2 ** 27; for Unsigned_27'Size use 27; type Unsigned_28 is mod 2 ** 28; for Unsigned_28'Size use 28; type Unsigned_29 is mod 2 ** 29; for Unsigned_29'Size use 29; type Unsigned_30 is mod 2 ** 30; for Unsigned_30'Size use 30; type Unsigned_31 is mod 2 ** 31; for Unsigned_31'Size use 31; type Unsigned_32 is mod 2 ** 32; for Unsigned_32'Size use 32; type Signed_2 is range -2 ** 1 .. 2 ** 1 - 1; for Signed_2'Size use 2; type Signed_3 is range -2 ** 2 .. 2 ** 2 - 1; for Signed_3'Size use 3; type Signed_4 is range -2 ** 3 .. 2 ** 3 - 1; for Signed_4'Size use 4; type Signed_5 is range -2 ** 4 .. 2 ** 4 - 1; for Signed_5'Size use 5; type Signed_6 is range -2 ** 5 .. 2 ** 5 - 1; for Signed_6'Size use 6; type Signed_7 is range -2 ** 6 .. 2 ** 6 - 1; for Signed_7'Size use 7; type Signed_8 is range -2 ** 7 .. 2 ** 7 - 1; for Signed_8'Size use 8; type Signed_9 is range -2 ** 8 .. 2 ** 8 - 1; for Signed_9'Size use 9; type Signed_10 is range -2 ** 9 .. 2 ** 9 - 1; for Signed_10'Size use 10; type Signed_11 is range -2 ** 10 .. 2 ** 10 - 1; for Signed_11'Size use 11; type Signed_12 is range -2 ** 11 .. 2 ** 11 - 1; for Signed_12'Size use 12; type Signed_13 is range -2 ** 12 .. 2 ** 12 - 1; for Signed_13'Size use 13; type Signed_14 is range -2 ** 13 .. 2 ** 13 - 1; for Signed_14'Size use 14; type Signed_15 is range -2 ** 14 .. 2 ** 14 - 1; for Signed_15'Size use 15; type Signed_16 is range -2 ** 15 .. 2 ** 15 - 1; for Signed_16'Size use 16; type Signed_17 is range -2 ** 16 .. 2 ** 16 - 1; for Signed_17'Size use 17; type Signed_18 is range -2 ** 17 .. 2 ** 17 - 1; for Signed_18'Size use 18; type Signed_19 is range -2 ** 18 .. 2 ** 18 - 1; for Signed_19'Size use 19; type Signed_20 is range -2 ** 19 .. 2 ** 19 - 1; for Signed_20'Size use 20; type Signed_21 is range -2 ** 20 .. 2 ** 20 - 1; for Signed_21'Size use 21; type Signed_22 is range -2 ** 21 .. 2 ** 21 - 1; for Signed_22'Size use 22; type Signed_23 is range -2 ** 22 .. 2 ** 22 - 1; for Signed_23'Size use 23; type Signed_24 is range -2 ** 23 .. 2 ** 23 - 1; for Signed_24'Size use 24; type Signed_25 is range -2 ** 24 .. 2 ** 24 - 1; for Signed_25'Size use 25; type Signed_26 is range -2 ** 25 .. 2 ** 25 - 1; for Signed_26'Size use 26; type Signed_27 is range -2 ** 26 .. 2 ** 26 - 1; for Signed_27'Size use 27; type Signed_28 is range -2 ** 27 .. 2 ** 27 - 1; for Signed_28'Size use 28; type Signed_29 is range -2 ** 28 .. 2 ** 28 - 1; for Signed_29'Size use 29; type Signed_30 is range -2 ** 29 .. 2 ** 29 - 1; for Signed_30'Size use 30; type Signed_31 is range -2 ** 30 .. 2 ** 30 - 1; for Signed_31'Size use 31; type Signed_32 is range -2 ** 31 .. 2 ** 31 - 1; for Signed_32'Size use 32; end Interfaces.C.Extensions;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- I N L I N E -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2020, 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 Alloc; with Aspects; use Aspects; with Atree; use Atree; with Debug; use Debug; with Einfo; use Einfo; with Elists; use Elists; with Errout; use Errout; with Expander; use Expander; with Exp_Ch6; use Exp_Ch6; with Exp_Ch7; use Exp_Ch7; with Exp_Tss; use Exp_Tss; with Exp_Util; use Exp_Util; with Fname; use Fname; with Fname.UF; use Fname.UF; with Lib; use Lib; with Namet; use Namet; with Nmake; use Nmake; with Nlists; use Nlists; with Output; use Output; with Sem_Aux; use Sem_Aux; with Sem_Ch8; use Sem_Ch8; with Sem_Ch10; use Sem_Ch10; with Sem_Ch12; use Sem_Ch12; with Sem_Prag; use Sem_Prag; with Sem_Res; use Sem_Res; with Sem_Util; use Sem_Util; with Sinfo; use Sinfo; with Sinput; use Sinput; with Snames; use Snames; with Stand; use Stand; with Table; with Tbuild; use Tbuild; with Uintp; use Uintp; with Uname; use Uname; with GNAT.HTable; package body Inline is Check_Inlining_Restrictions : constant Boolean := True; -- In the following cases the frontend rejects inlining because they -- are not handled well by the backend. This variable facilitates -- disabling these restrictions to evaluate future versions of the -- GCC backend in which some of the restrictions may be supported. -- -- - subprograms that have: -- - nested subprograms -- - instantiations -- - package declarations -- - task or protected object declarations -- - some of the following statements: -- - abort -- - asynchronous-select -- - conditional-entry-call -- - delay-relative -- - delay-until -- - selective-accept -- - timed-entry-call Inlined_Calls : Elist_Id; -- List of frontend inlined calls Backend_Calls : Elist_Id; -- List of inline calls passed to the backend Backend_Instances : Elist_Id; -- List of instances inlined for the backend Backend_Inlined_Subps : Elist_Id; -- List of subprograms inlined by the backend Backend_Not_Inlined_Subps : Elist_Id; -- List of subprograms that cannot be inlined by the backend ----------------------------- -- Pending_Instantiations -- ----------------------------- -- We make entries in this table for the pending instantiations of generic -- bodies that are created during semantic analysis. After the analysis is -- complete, calling Instantiate_Bodies performs the actual instantiations. package Pending_Instantiations is new Table.Table ( Table_Component_Type => Pending_Body_Info, Table_Index_Type => Int, Table_Low_Bound => 0, Table_Initial => Alloc.Pending_Instantiations_Initial, Table_Increment => Alloc.Pending_Instantiations_Increment, Table_Name => "Pending_Instantiations"); ------------------------------------- -- Called_Pending_Instantiations -- ------------------------------------- -- With back-end inlining, the pending instantiations that are not in the -- main unit or subunit are performed only after a call to the subprogram -- instance, or to a subprogram within the package instance, is inlined. -- Since such a call can be within a subsequent pending instantiation, -- we make entries in this table that stores the index of these "called" -- pending instantiations and perform them when the table is populated. package Called_Pending_Instantiations is new Table.Table ( Table_Component_Type => Int, Table_Index_Type => Int, Table_Low_Bound => 0, Table_Initial => Alloc.Pending_Instantiations_Initial, Table_Increment => Alloc.Pending_Instantiations_Increment, Table_Name => "Called_Pending_Instantiations"); --------------------------------- -- To_Pending_Instantiations -- --------------------------------- -- With back-end inlining, we also need to have a map from the pending -- instantiations to their index in the Pending_Instantiations table. Node_Table_Size : constant := 257; -- Number of headers in hash table subtype Node_Header_Num is Integer range 0 .. Node_Table_Size - 1; -- Range of headers in hash table function Node_Hash (Id : Node_Id) return Node_Header_Num; -- Simple hash function for Node_Ids package To_Pending_Instantiations is new GNAT.Htable.Simple_HTable (Header_Num => Node_Header_Num, Element => Int, No_Element => -1, Key => Node_Id, Hash => Node_Hash, Equal => "="); ----------------- -- Node_Hash -- ----------------- function Node_Hash (Id : Node_Id) return Node_Header_Num is begin return Node_Header_Num (Id mod Node_Table_Size); end Node_Hash; -------------------- -- Inlined Bodies -- -------------------- -- Inlined functions are actually placed in line by the backend if the -- corresponding bodies are available (i.e. compiled). Whenever we find -- a call to an inlined subprogram, we add the name of the enclosing -- compilation unit to a worklist. After all compilation, and after -- expansion of generic bodies, we traverse the list of pending bodies -- and compile them as well. package Inlined_Bodies is new Table.Table ( Table_Component_Type => Entity_Id, Table_Index_Type => Int, Table_Low_Bound => 0, Table_Initial => Alloc.Inlined_Bodies_Initial, Table_Increment => Alloc.Inlined_Bodies_Increment, Table_Name => "Inlined_Bodies"); ----------------------- -- Inline Processing -- ----------------------- -- For each call to an inlined subprogram, we make entries in a table -- that stores caller and callee, and indicates the call direction from -- one to the other. We also record the compilation unit that contains -- the callee. After analyzing the bodies of all such compilation units, -- we compute the transitive closure of inlined subprograms called from -- the main compilation unit and make it available to the code generator -- in no particular order, thus allowing cycles in the call graph. Last_Inlined : Entity_Id := Empty; -- For each entry in the table we keep a list of successors in topological -- order, i.e. callers of the current subprogram. type Subp_Index is new Nat; No_Subp : constant Subp_Index := 0; -- The subprogram entities are hashed into the Inlined table Num_Hash_Headers : constant := 512; Hash_Headers : array (Subp_Index range 0 .. Num_Hash_Headers - 1) of Subp_Index; type Succ_Index is new Nat; No_Succ : constant Succ_Index := 0; type Succ_Info is record Subp : Subp_Index; Next : Succ_Index; end record; -- The following table stores list elements for the successor lists. These -- lists cannot be chained directly through entries in the Inlined table, -- because a given subprogram can appear in several such lists. package Successors is new Table.Table ( Table_Component_Type => Succ_Info, Table_Index_Type => Succ_Index, Table_Low_Bound => 1, Table_Initial => Alloc.Successors_Initial, Table_Increment => Alloc.Successors_Increment, Table_Name => "Successors"); type Subp_Info is record Name : Entity_Id := Empty; Next : Subp_Index := No_Subp; First_Succ : Succ_Index := No_Succ; Main_Call : Boolean := False; Processed : Boolean := False; end record; package Inlined is new Table.Table ( Table_Component_Type => Subp_Info, Table_Index_Type => Subp_Index, Table_Low_Bound => 1, Table_Initial => Alloc.Inlined_Initial, Table_Increment => Alloc.Inlined_Increment, Table_Name => "Inlined"); ----------------------- -- Local Subprograms -- ----------------------- procedure Add_Call (Called : Entity_Id; Caller : Entity_Id := Empty); -- Make two entries in Inlined table, for an inlined subprogram being -- called, and for the inlined subprogram that contains the call. If -- the call is in the main compilation unit, Caller is Empty. procedure Add_Inlined_Instance (E : Entity_Id); -- Add instance E to the list of inlined instances for the unit procedure Add_Inlined_Subprogram (E : Entity_Id); -- Add subprogram E to the list of inlined subprograms for the unit function Add_Subp (E : Entity_Id) return Subp_Index; -- Make entry in Inlined table for subprogram E, or return table index -- that already holds E. procedure Establish_Actual_Mapping_For_Inlined_Call (N : Node_Id; Subp : Entity_Id; Decls : List_Id; Body_Or_Expr_To_Check : Node_Id); -- Establish a mapping from formals to actuals in the call N for the target -- subprogram Subp, and create temporaries or renamings when needed for the -- actuals that are expressions (except for actuals given by simple entity -- names or literals) or that are scalars that require copying to preserve -- semantics. Any temporary objects that are created are inserted in Decls. -- Body_Or_Expr_To_Check indicates the target body (or possibly expression -- of an expression function), which may be traversed to count formal uses. function Get_Code_Unit_Entity (E : Entity_Id) return Entity_Id; pragma Inline (Get_Code_Unit_Entity); -- Return the entity node for the unit containing E. Always return the spec -- for a package. function Has_Initialized_Type (E : Entity_Id) return Boolean; -- If a candidate for inlining contains type declarations for types with -- nontrivial initialization procedures, they are not worth inlining. function Has_Single_Return (N : Node_Id) return Boolean; -- In general we cannot inline functions that return unconstrained type. -- However, we can handle such functions if all return statements return -- a local variable that is the first declaration in the body of the -- function. In that case the call can be replaced by that local -- variable as is done for other inlined calls. function In_Main_Unit_Or_Subunit (E : Entity_Id) return Boolean; -- Return True if E is in the main unit or its spec or in a subunit function Is_Nested (E : Entity_Id) return Boolean; -- If the function is nested inside some other function, it will always -- be compiled if that function is, so don't add it to the inline list. -- We cannot compile a nested function outside the scope of the containing -- function anyway. This is also the case if the function is defined in a -- task body or within an entry (for example, an initialization procedure). procedure Remove_Aspects_And_Pragmas (Body_Decl : Node_Id); -- Remove all aspects and/or pragmas that have no meaning in inlined body -- Body_Decl. The analysis of these items is performed on the non-inlined -- body. The items currently removed are: -- Contract_Cases -- Global -- Depends -- Postcondition -- Precondition -- Refined_Global -- Refined_Depends -- Refined_Post -- Subprogram_Variant -- Test_Case -- Unmodified -- Unreferenced procedure Reset_Actual_Mapping_For_Inlined_Call (Subp : Entity_Id); -- Reset the Renamed_Object flags on the formals of Subp, which can be set -- by a call to Establish_Actual_Mapping_For_Inlined_Call. ------------------------------ -- Deferred Cleanup Actions -- ------------------------------ -- The cleanup actions for scopes that contain instantiations is delayed -- until after expansion of those instantiations, because they may contain -- finalizable objects or tasks that affect the cleanup code. A scope -- that contains instantiations only needs to be finalized once, even -- if it contains more than one instance. We keep a list of scopes -- that must still be finalized, and call cleanup_actions after all -- the instantiations have been completed. To_Clean : Elist_Id; procedure Add_Scope_To_Clean (Inst : Entity_Id); -- Build set of scopes on which cleanup actions must be performed procedure Cleanup_Scopes; -- Complete cleanup actions on scopes that need it -------------- -- Add_Call -- -------------- procedure Add_Call (Called : Entity_Id; Caller : Entity_Id := Empty) is P1 : constant Subp_Index := Add_Subp (Called); P2 : Subp_Index; J : Succ_Index; begin if Present (Caller) then P2 := Add_Subp (Caller); -- Add P1 to the list of successors of P2, if not already there. -- Note that P2 may contain more than one call to P1, and only -- one needs to be recorded. J := Inlined.Table (P2).First_Succ; while J /= No_Succ loop if Successors.Table (J).Subp = P1 then return; end if; J := Successors.Table (J).Next; end loop; -- On exit, make a successor entry for P1 Successors.Increment_Last; Successors.Table (Successors.Last).Subp := P1; Successors.Table (Successors.Last).Next := Inlined.Table (P2).First_Succ; Inlined.Table (P2).First_Succ := Successors.Last; else Inlined.Table (P1).Main_Call := True; end if; end Add_Call; ---------------------- -- Add_Inlined_Body -- ---------------------- procedure Add_Inlined_Body (E : Entity_Id; N : Node_Id) is type Inline_Level_Type is (Dont_Inline, Inline_Call, Inline_Package); -- Level of inlining for the call: Dont_Inline means no inlining, -- Inline_Call means that only the call is considered for inlining, -- Inline_Package means that the call is considered for inlining and -- its package compiled and scanned for more inlining opportunities. function Is_Non_Loading_Expression_Function (Id : Entity_Id) return Boolean; -- Determine whether arbitrary entity Id denotes a subprogram which is -- either -- -- * An expression function -- -- * A function completed by an expression function where both the -- spec and body are in the same context. function Must_Inline return Inline_Level_Type; -- Inlining is only done if the call statement N is in the main unit, -- or within the body of another inlined subprogram. ---------------------------------------- -- Is_Non_Loading_Expression_Function -- ---------------------------------------- function Is_Non_Loading_Expression_Function (Id : Entity_Id) return Boolean is Body_Decl : Node_Id; Body_Id : Entity_Id; Spec_Decl : Node_Id; begin -- A stand-alone expression function is transformed into a spec-body -- pair in-place. Since both the spec and body are in the same list, -- the inlining of such an expression function does not need to load -- anything extra. if Is_Expression_Function (Id) then return True; -- A function may be completed by an expression function elsif Ekind (Id) = E_Function then Spec_Decl := Unit_Declaration_Node (Id); if Nkind (Spec_Decl) = N_Subprogram_Declaration then Body_Id := Corresponding_Body (Spec_Decl); if Present (Body_Id) then Body_Decl := Unit_Declaration_Node (Body_Id); -- The inlining of a completing expression function does -- not need to load anything extra when both the spec and -- body are in the same context. return Was_Expression_Function (Body_Decl) and then Parent (Spec_Decl) = Parent (Body_Decl); end if; end if; end if; return False; end Is_Non_Loading_Expression_Function; ----------------- -- Must_Inline -- ----------------- function Must_Inline return Inline_Level_Type is Scop : Entity_Id; Comp : Node_Id; begin -- Check if call is in main unit Scop := Current_Scope; -- Do not try to inline if scope is standard. This could happen, for -- example, for a call to Add_Global_Declaration, and it causes -- trouble to try to inline at this level. if Scop = Standard_Standard then return Dont_Inline; end if; -- Otherwise lookup scope stack to outer scope while Scope (Scop) /= Standard_Standard and then not Is_Child_Unit (Scop) loop Scop := Scope (Scop); end loop; Comp := Parent (Scop); while Nkind (Comp) /= N_Compilation_Unit loop Comp := Parent (Comp); end loop; -- If the call is in the main unit, inline the call and compile the -- package of the subprogram to find more calls to be inlined. if Comp = Cunit (Main_Unit) or else Comp = Library_Unit (Cunit (Main_Unit)) then Add_Call (E); return Inline_Package; end if; -- The call is not in the main unit. See if it is in some subprogram -- that can be inlined outside its unit. If so, inline the call and, -- if the inlining level is set to 1, stop there; otherwise also -- compile the package as above. Scop := Current_Scope; while Scope (Scop) /= Standard_Standard and then not Is_Child_Unit (Scop) loop if Is_Overloadable (Scop) and then Is_Inlined (Scop) and then not Is_Nested (Scop) then Add_Call (E, Scop); if Inline_Level = 1 then return Inline_Call; else return Inline_Package; end if; end if; Scop := Scope (Scop); end loop; return Dont_Inline; end Must_Inline; Inst : Entity_Id; Inst_Decl : Node_Id; Level : Inline_Level_Type; -- Start of processing for Add_Inlined_Body begin Append_New_Elmt (N, To => Backend_Calls); -- Skip subprograms that cannot or need not be inlined outside their -- unit or parent subprogram. if Is_Abstract_Subprogram (E) or else Convention (E) = Convention_Protected or else In_Main_Unit_Or_Subunit (E) or else Is_Nested (E) then return; end if; -- Find out whether the call must be inlined. Unless the result is -- Dont_Inline, Must_Inline also creates an edge for the call in the -- callgraph; however, it will not be activated until after Is_Called -- is set on the subprogram. Level := Must_Inline; if Level = Dont_Inline then return; end if; -- If a previous call to the subprogram has been inlined, nothing to do if Is_Called (E) then return; end if; -- If the subprogram is an instance, then inline the instance if Is_Generic_Instance (E) then Add_Inlined_Instance (E); end if; -- Mark the subprogram as called Set_Is_Called (E); -- If the call was generated by the compiler and is to a subprogram in -- a run-time unit, we need to suppress debugging information for it, -- so that the code that is eventually inlined will not affect the -- debugging of the program. We do not do it if the call comes from -- source because, even if the call is inlined, the user may expect it -- to be present in the debugging information. if not Comes_From_Source (N) and then In_Extended_Main_Source_Unit (N) and then Is_Predefined_Unit (Get_Source_Unit (E)) then Set_Needs_Debug_Info (E, False); end if; -- If the subprogram is an expression function, or is completed by one -- where both the spec and body are in the same context, then there is -- no need to load any package body since the body of the function is -- in the spec. if Is_Non_Loading_Expression_Function (E) then return; end if; -- Find unit containing E, and add to list of inlined bodies if needed. -- Library-level functions must be handled specially, because there is -- no enclosing package to retrieve. In this case, it is the body of -- the function that will have to be loaded. declare Pack : constant Entity_Id := Get_Code_Unit_Entity (E); begin if Pack = E then Inlined_Bodies.Increment_Last; Inlined_Bodies.Table (Inlined_Bodies.Last) := E; else pragma Assert (Ekind (Pack) = E_Package); -- If the subprogram is within an instance, inline the instance if Comes_From_Source (E) then Inst := Scope (E); while Present (Inst) and then Inst /= Standard_Standard loop exit when Is_Generic_Instance (Inst); Inst := Scope (Inst); end loop; if Present (Inst) and then Is_Generic_Instance (Inst) and then not Is_Called (Inst) then Inst_Decl := Unit_Declaration_Node (Inst); -- Do not inline the instance if the body already exists, -- or the instance node is simply missing. if Present (Corresponding_Body (Inst_Decl)) or else (Nkind (Parent (Inst_Decl)) /= N_Compilation_Unit and then No (Next (Inst_Decl))) then Set_Is_Called (Inst); else Add_Inlined_Instance (Inst); end if; end if; end if; -- If the unit containing E is an instance, nothing more to do if Is_Generic_Instance (Pack) then null; -- Do not inline the package if the subprogram is an init proc -- or other internally generated subprogram, because in that -- case the subprogram body appears in the same unit that -- declares the type, and that body is visible to the back end. -- Do not inline it either if it is in the main unit. -- Extend the -gnatn2 processing to -gnatn1 for Inline_Always -- calls if the back end takes care of inlining the call. -- Note that Level is in Inline_Call | Inline_Package here. elsif ((Level = Inline_Call and then Has_Pragma_Inline_Always (E) and then Back_End_Inlining) or else Level = Inline_Package) and then not Is_Inlined (Pack) and then not Is_Internal (E) and then not In_Main_Unit_Or_Subunit (Pack) then Set_Is_Inlined (Pack); Inlined_Bodies.Increment_Last; Inlined_Bodies.Table (Inlined_Bodies.Last) := Pack; end if; end if; -- Ensure that Analyze_Inlined_Bodies will be invoked after -- completing the analysis of the current unit. Inline_Processing_Required := True; end; end Add_Inlined_Body; -------------------------- -- Add_Inlined_Instance -- -------------------------- procedure Add_Inlined_Instance (E : Entity_Id) is Decl_Node : constant Node_Id := Unit_Declaration_Node (E); Index : Int; begin -- This machinery is only used with back-end inlining if not Back_End_Inlining then return; end if; -- Register the instance in the list Append_New_Elmt (Decl_Node, To => Backend_Instances); -- Retrieve the index of its corresponding pending instantiation -- and mark this corresponding pending instantiation as needed. Index := To_Pending_Instantiations.Get (Decl_Node); if Index >= 0 then Called_Pending_Instantiations.Append (Index); else pragma Assert (False); null; end if; Set_Is_Called (E); end Add_Inlined_Instance; ---------------------------- -- Add_Inlined_Subprogram -- ---------------------------- procedure Add_Inlined_Subprogram (E : Entity_Id) is Decl : constant Node_Id := Parent (Declaration_Node (E)); Pack : constant Entity_Id := Get_Code_Unit_Entity (E); procedure Register_Backend_Inlined_Subprogram (Subp : Entity_Id); -- Append Subp to the list of subprograms inlined by the backend procedure Register_Backend_Not_Inlined_Subprogram (Subp : Entity_Id); -- Append Subp to the list of subprograms that cannot be inlined by -- the backend. ----------------------------------------- -- Register_Backend_Inlined_Subprogram -- ----------------------------------------- procedure Register_Backend_Inlined_Subprogram (Subp : Entity_Id) is begin Append_New_Elmt (Subp, To => Backend_Inlined_Subps); end Register_Backend_Inlined_Subprogram; --------------------------------------------- -- Register_Backend_Not_Inlined_Subprogram -- --------------------------------------------- procedure Register_Backend_Not_Inlined_Subprogram (Subp : Entity_Id) is begin Append_New_Elmt (Subp, To => Backend_Not_Inlined_Subps); end Register_Backend_Not_Inlined_Subprogram; -- Start of processing for Add_Inlined_Subprogram begin -- We can inline the subprogram if its unit is known to be inlined or is -- an instance whose body will be analyzed anyway or the subprogram was -- generated as a body by the compiler (for example an initialization -- procedure) or its declaration was provided along with the body (for -- example an expression function) and it does not declare types with -- nontrivial initialization procedures. if (Is_Inlined (Pack) or else Is_Generic_Instance (Pack) or else Nkind (Decl) = N_Subprogram_Body or else Present (Corresponding_Body (Decl))) and then not Has_Initialized_Type (E) then Register_Backend_Inlined_Subprogram (E); if No (Last_Inlined) then Set_First_Inlined_Subprogram (Cunit (Main_Unit), E); else Set_Next_Inlined_Subprogram (Last_Inlined, E); end if; Last_Inlined := E; else Register_Backend_Not_Inlined_Subprogram (E); end if; end Add_Inlined_Subprogram; -------------------------------- -- Add_Pending_Instantiation -- -------------------------------- procedure Add_Pending_Instantiation (Inst : Node_Id; Act_Decl : Node_Id) is Act_Decl_Id : Entity_Id; Index : Int; begin -- Here is a defense against a ludicrous number of instantiations -- caused by a circular set of instantiation attempts. if Pending_Instantiations.Last + 1 >= Maximum_Instantiations then Error_Msg_Uint_1 := UI_From_Int (Maximum_Instantiations); Error_Msg_N ("too many instantiations, exceeds max of^", Inst); Error_Msg_N ("\limit can be changed using -gnateinn switch", Inst); raise Unrecoverable_Error; end if; -- Capture the body of the generic instantiation along with its context -- for later processing by Instantiate_Bodies. Pending_Instantiations.Append ((Act_Decl => Act_Decl, Config_Switches => Save_Config_Switches, Current_Sem_Unit => Current_Sem_Unit, Expander_Status => Expander_Active, Inst_Node => Inst, Local_Suppress_Stack_Top => Local_Suppress_Stack_Top, Scope_Suppress => Scope_Suppress, Warnings => Save_Warnings)); -- With back-end inlining, also associate the index to the instantiation if Back_End_Inlining then Act_Decl_Id := Defining_Entity (Act_Decl); Index := Pending_Instantiations.Last; To_Pending_Instantiations.Set (Act_Decl, Index); -- If an instantiation is in the main unit or subunit, or is a nested -- subprogram, then its body is needed as per the analysis done in -- Analyze_Package_Instantiation & Analyze_Subprogram_Instantiation. if In_Main_Unit_Or_Subunit (Act_Decl_Id) or else (Is_Subprogram (Act_Decl_Id) and then Is_Nested (Act_Decl_Id)) then Called_Pending_Instantiations.Append (Index); Set_Is_Called (Act_Decl_Id); end if; end if; end Add_Pending_Instantiation; ------------------------ -- Add_Scope_To_Clean -- ------------------------ procedure Add_Scope_To_Clean (Inst : Entity_Id) is Scop : constant Entity_Id := Enclosing_Dynamic_Scope (Inst); Elmt : Elmt_Id; begin -- If the instance appears in a library-level package declaration, -- all finalization is global, and nothing needs doing here. if Scop = Standard_Standard then return; end if; -- If the instance is within a generic unit, no finalization code -- can be generated. Note that at this point all bodies have been -- analyzed, and the scope stack itself is not present, and the flag -- Inside_A_Generic is not set. declare S : Entity_Id; begin S := Scope (Inst); while Present (S) and then S /= Standard_Standard loop if Is_Generic_Unit (S) then return; end if; S := Scope (S); end loop; end; Elmt := First_Elmt (To_Clean); while Present (Elmt) loop if Node (Elmt) = Scop then return; end if; Next_Elmt (Elmt); end loop; Append_Elmt (Scop, To_Clean); end Add_Scope_To_Clean; -------------- -- Add_Subp -- -------------- function Add_Subp (E : Entity_Id) return Subp_Index is Index : Subp_Index := Subp_Index (E) mod Num_Hash_Headers; J : Subp_Index; procedure New_Entry; -- Initialize entry in Inlined table procedure New_Entry is begin Inlined.Increment_Last; Inlined.Table (Inlined.Last).Name := E; Inlined.Table (Inlined.Last).Next := No_Subp; Inlined.Table (Inlined.Last).First_Succ := No_Succ; Inlined.Table (Inlined.Last).Main_Call := False; Inlined.Table (Inlined.Last).Processed := False; end New_Entry; -- Start of processing for Add_Subp begin if Hash_Headers (Index) = No_Subp then New_Entry; Hash_Headers (Index) := Inlined.Last; return Inlined.Last; else J := Hash_Headers (Index); while J /= No_Subp loop if Inlined.Table (J).Name = E then return J; else Index := J; J := Inlined.Table (J).Next; end if; end loop; -- On exit, subprogram was not found. Enter in table. Index is -- the current last entry on the hash chain. New_Entry; Inlined.Table (Index).Next := Inlined.Last; return Inlined.Last; end if; end Add_Subp; ---------------------------- -- Analyze_Inlined_Bodies -- ---------------------------- procedure Analyze_Inlined_Bodies is Comp_Unit : Node_Id; J : Int; Pack : Entity_Id; Subp : Subp_Index; S : Succ_Index; type Pending_Index is new Nat; package Pending_Inlined is new Table.Table ( Table_Component_Type => Subp_Index, Table_Index_Type => Pending_Index, Table_Low_Bound => 1, Table_Initial => Alloc.Inlined_Initial, Table_Increment => Alloc.Inlined_Increment, Table_Name => "Pending_Inlined"); -- The workpile used to compute the transitive closure -- Start of processing for Analyze_Inlined_Bodies begin if Serious_Errors_Detected = 0 then Push_Scope (Standard_Standard); J := 0; while J <= Inlined_Bodies.Last and then Serious_Errors_Detected = 0 loop Pack := Inlined_Bodies.Table (J); while Present (Pack) and then Scope (Pack) /= Standard_Standard and then not Is_Child_Unit (Pack) loop Pack := Scope (Pack); end loop; Comp_Unit := Parent (Pack); while Present (Comp_Unit) and then Nkind (Comp_Unit) /= N_Compilation_Unit loop Comp_Unit := Parent (Comp_Unit); end loop; -- Load the body if it exists and contains inlineable entities, -- unless it is the main unit, or is an instance whose body has -- already been analyzed. if Present (Comp_Unit) and then Comp_Unit /= Cunit (Main_Unit) and then Body_Required (Comp_Unit) and then (Nkind (Unit (Comp_Unit)) /= N_Package_Declaration or else (No (Corresponding_Body (Unit (Comp_Unit))) and then Body_Needed_For_Inlining (Defining_Entity (Unit (Comp_Unit))))) then declare Bname : constant Unit_Name_Type := Get_Body_Name (Get_Unit_Name (Unit (Comp_Unit))); OK : Boolean; begin if not Is_Loaded (Bname) then Style_Check := False; Load_Needed_Body (Comp_Unit, OK); if not OK then -- Warn that a body was not available for inlining -- by the back-end. Error_Msg_Unit_1 := Bname; Error_Msg_N ("one or more inlined subprograms accessed in $!??", Comp_Unit); Error_Msg_File_1 := Get_File_Name (Bname, Subunit => False); Error_Msg_N ("\but file{ was not found!??", Comp_Unit); end if; end if; end; end if; J := J + 1; if J > Inlined_Bodies.Last then -- The analysis of required bodies may have produced additional -- generic instantiations. To obtain further inlining, we need -- to perform another round of generic body instantiations. Instantiate_Bodies; -- Symmetrically, the instantiation of required generic bodies -- may have caused additional bodies to be inlined. To obtain -- further inlining, we keep looping over the inlined bodies. end if; end loop; -- The list of inlined subprograms is an overestimate, because it -- includes inlined functions called from functions that are compiled -- as part of an inlined package, but are not themselves called. An -- accurate computation of just those subprograms that are needed -- requires that we perform a transitive closure over the call graph, -- starting from calls in the main compilation unit. for Index in Inlined.First .. Inlined.Last loop if not Is_Called (Inlined.Table (Index).Name) then -- This means that Add_Inlined_Body added the subprogram to the -- table but wasn't able to handle its code unit. Do nothing. Inlined.Table (Index).Processed := True; elsif Inlined.Table (Index).Main_Call then Pending_Inlined.Increment_Last; Pending_Inlined.Table (Pending_Inlined.Last) := Index; Inlined.Table (Index).Processed := True; else Set_Is_Called (Inlined.Table (Index).Name, False); end if; end loop; -- Iterate over the workpile until it is emptied, propagating the -- Is_Called flag to the successors of the processed subprogram. while Pending_Inlined.Last >= Pending_Inlined.First loop Subp := Pending_Inlined.Table (Pending_Inlined.Last); Pending_Inlined.Decrement_Last; S := Inlined.Table (Subp).First_Succ; while S /= No_Succ loop Subp := Successors.Table (S).Subp; if not Inlined.Table (Subp).Processed then Set_Is_Called (Inlined.Table (Subp).Name); Pending_Inlined.Increment_Last; Pending_Inlined.Table (Pending_Inlined.Last) := Subp; Inlined.Table (Subp).Processed := True; end if; S := Successors.Table (S).Next; end loop; end loop; -- Finally add the called subprograms to the list of inlined -- subprograms for the unit. for Index in Inlined.First .. Inlined.Last loop if Is_Called (Inlined.Table (Index).Name) then Add_Inlined_Subprogram (Inlined.Table (Index).Name); end if; end loop; Pop_Scope; end if; end Analyze_Inlined_Bodies; -------------------------- -- Build_Body_To_Inline -- -------------------------- procedure Build_Body_To_Inline (N : Node_Id; Spec_Id : Entity_Id) is Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id); Analysis_Status : constant Boolean := Full_Analysis; Original_Body : Node_Id; Body_To_Analyze : Node_Id; Max_Size : constant := 10; function Has_Extended_Return return Boolean; -- This function returns True if the subprogram has an extended return -- statement. function Has_Pending_Instantiation return Boolean; -- If some enclosing body contains instantiations that appear before -- the corresponding generic body, the enclosing body has a freeze node -- so that it can be elaborated after the generic itself. This might -- conflict with subsequent inlinings, so that it is unsafe to try to -- inline in such a case. function Has_Single_Return_In_GNATprove_Mode return Boolean; -- This function is called only in GNATprove mode, and it returns -- True if the subprogram has no return statement or a single return -- statement as last statement. It returns False for subprogram with -- a single return as last statement inside one or more blocks, as -- inlining would generate gotos in that case as well (although the -- goto is useless in that case). function Uses_Secondary_Stack (Bod : Node_Id) return Boolean; -- If the body of the subprogram includes a call that returns an -- unconstrained type, the secondary stack is involved, and it is -- not worth inlining. ------------------------- -- Has_Extended_Return -- ------------------------- function Has_Extended_Return return Boolean is Body_To_Inline : constant Node_Id := N; function Check_Return (N : Node_Id) return Traverse_Result; -- Returns OK on node N if this is not an extended return statement ------------------ -- Check_Return -- ------------------ function Check_Return (N : Node_Id) return Traverse_Result is begin case Nkind (N) is when N_Extended_Return_Statement => return Abandon; -- Skip locally declared subprogram bodies inside the body to -- inline, as the return statements inside those do not count. when N_Subprogram_Body => if N = Body_To_Inline then return OK; else return Skip; end if; when others => return OK; end case; end Check_Return; function Check_All_Returns is new Traverse_Func (Check_Return); -- Start of processing for Has_Extended_Return begin return Check_All_Returns (N) /= OK; end Has_Extended_Return; ------------------------------- -- Has_Pending_Instantiation -- ------------------------------- function Has_Pending_Instantiation return Boolean is S : Entity_Id; begin S := Current_Scope; while Present (S) loop if Is_Compilation_Unit (S) or else Is_Child_Unit (S) then return False; elsif Ekind (S) = E_Package and then Has_Forward_Instantiation (S) then return True; end if; S := Scope (S); end loop; return False; end Has_Pending_Instantiation; ----------------------------------------- -- Has_Single_Return_In_GNATprove_Mode -- ----------------------------------------- function Has_Single_Return_In_GNATprove_Mode return Boolean is Body_To_Inline : constant Node_Id := N; Last_Statement : Node_Id := Empty; function Check_Return (N : Node_Id) return Traverse_Result; -- Returns OK on node N if this is not a return statement different -- from the last statement in the subprogram. ------------------ -- Check_Return -- ------------------ function Check_Return (N : Node_Id) return Traverse_Result is begin case Nkind (N) is when N_Extended_Return_Statement | N_Simple_Return_Statement => if N = Last_Statement then return OK; else return Abandon; end if; -- Skip locally declared subprogram bodies inside the body to -- inline, as the return statements inside those do not count. when N_Subprogram_Body => if N = Body_To_Inline then return OK; else return Skip; end if; when others => return OK; end case; end Check_Return; function Check_All_Returns is new Traverse_Func (Check_Return); -- Start of processing for Has_Single_Return_In_GNATprove_Mode begin -- Retrieve the last statement Last_Statement := Last (Statements (Handled_Statement_Sequence (N))); -- Check that the last statement is the only possible return -- statement in the subprogram. return Check_All_Returns (N) = OK; end Has_Single_Return_In_GNATprove_Mode; -------------------------- -- Uses_Secondary_Stack -- -------------------------- function Uses_Secondary_Stack (Bod : Node_Id) return Boolean is function Check_Call (N : Node_Id) return Traverse_Result; -- Look for function calls that return an unconstrained type ---------------- -- Check_Call -- ---------------- function Check_Call (N : Node_Id) return Traverse_Result is begin if Nkind (N) = N_Function_Call and then Is_Entity_Name (Name (N)) and then Is_Composite_Type (Etype (Entity (Name (N)))) and then not Is_Constrained (Etype (Entity (Name (N)))) then Cannot_Inline ("cannot inline & (call returns unconstrained type)?", N, Spec_Id); return Abandon; else return OK; end if; end Check_Call; function Check_Calls is new Traverse_Func (Check_Call); begin return Check_Calls (Bod) = Abandon; end Uses_Secondary_Stack; -- Start of processing for Build_Body_To_Inline begin -- Return immediately if done already if Nkind (Decl) = N_Subprogram_Declaration and then Present (Body_To_Inline (Decl)) then return; -- Subprograms that have return statements in the middle of the body are -- inlined with gotos. GNATprove does not currently support gotos, so -- we prevent such inlining. elsif GNATprove_Mode and then not Has_Single_Return_In_GNATprove_Mode then Cannot_Inline ("cannot inline & (multiple returns)?", N, Spec_Id); return; -- Functions that return controlled types cannot currently be inlined -- because they require secondary stack handling; controlled actions -- may also interfere in complex ways with inlining. elsif Ekind (Spec_Id) = E_Function and then Needs_Finalization (Etype (Spec_Id)) then Cannot_Inline ("cannot inline & (controlled return type)?", N, Spec_Id); return; end if; if Present (Declarations (N)) and then Has_Excluded_Declaration (Spec_Id, Declarations (N)) then return; end if; if Present (Handled_Statement_Sequence (N)) then if Present (Exception_Handlers (Handled_Statement_Sequence (N))) then Cannot_Inline ("cannot inline& (exception handler)?", First (Exception_Handlers (Handled_Statement_Sequence (N))), Spec_Id); return; elsif Has_Excluded_Statement (Spec_Id, Statements (Handled_Statement_Sequence (N))) then return; end if; end if; -- We do not inline a subprogram that is too large, unless it is marked -- Inline_Always or we are in GNATprove mode. This pragma does not -- suppress the other checks on inlining (forbidden declarations, -- handlers, etc). if not (Has_Pragma_Inline_Always (Spec_Id) or else GNATprove_Mode) and then List_Length (Statements (Handled_Statement_Sequence (N))) > Max_Size then Cannot_Inline ("cannot inline& (body too large)?", N, Spec_Id); return; end if; if Has_Pending_Instantiation then Cannot_Inline ("cannot inline& (forward instance within enclosing body)?", N, Spec_Id); return; end if; -- Within an instance, the body to inline must be treated as a nested -- generic, so that the proper global references are preserved. -- Note that we do not do this at the library level, because it is not -- needed, and furthermore this causes trouble if front-end inlining -- is activated (-gnatN). if In_Instance and then Scope (Current_Scope) /= Standard_Standard then Save_Env (Scope (Current_Scope), Scope (Current_Scope)); Original_Body := Copy_Generic_Node (N, Empty, Instantiating => True); else Original_Body := Copy_Separate_Tree (N); end if; -- We need to capture references to the formals in order to substitute -- the actuals at the point of inlining, i.e. instantiation. To treat -- the formals as globals to the body to inline, we nest it within a -- dummy parameterless subprogram, declared within the real one. To -- avoid generating an internal name (which is never public, and which -- affects serial numbers of other generated names), we use an internal -- symbol that cannot conflict with user declarations. Set_Parameter_Specifications (Specification (Original_Body), No_List); Set_Defining_Unit_Name (Specification (Original_Body), Make_Defining_Identifier (Sloc (N), Name_uParent)); Set_Corresponding_Spec (Original_Body, Empty); -- Remove all aspects/pragmas that have no meaning in an inlined body Remove_Aspects_And_Pragmas (Original_Body); Body_To_Analyze := Copy_Generic_Node (Original_Body, Empty, Instantiating => False); -- Set return type of function, which is also global and does not need -- to be resolved. if Ekind (Spec_Id) = E_Function then Set_Result_Definition (Specification (Body_To_Analyze), New_Occurrence_Of (Etype (Spec_Id), Sloc (N))); end if; if No (Declarations (N)) then Set_Declarations (N, New_List (Body_To_Analyze)); else Append (Body_To_Analyze, Declarations (N)); end if; -- The body to inline is preanalyzed. In GNATprove mode we must disable -- full analysis as well so that light expansion does not take place -- either, and name resolution is unaffected. Expander_Mode_Save_And_Set (False); Full_Analysis := False; Analyze (Body_To_Analyze); Push_Scope (Defining_Entity (Body_To_Analyze)); Save_Global_References (Original_Body); End_Scope; Remove (Body_To_Analyze); Expander_Mode_Restore; Full_Analysis := Analysis_Status; -- Restore environment if previously saved if In_Instance and then Scope (Current_Scope) /= Standard_Standard then Restore_Env; end if; -- Functions that return unconstrained composite types require -- secondary stack handling, and cannot currently be inlined, unless -- all return statements return a local variable that is the first -- local declaration in the body. We had to delay this check until -- the body of the function is analyzed since Has_Single_Return() -- requires a minimum decoration. if Ekind (Spec_Id) = E_Function and then not Is_Scalar_Type (Etype (Spec_Id)) and then not Is_Access_Type (Etype (Spec_Id)) and then not Is_Constrained (Etype (Spec_Id)) then if not Has_Single_Return (Body_To_Analyze) -- Skip inlining if the function returns an unconstrained type -- using an extended return statement, since this part of the -- new inlining model is not yet supported by the current -- implementation. ??? or else (Returns_Unconstrained_Type (Spec_Id) and then Has_Extended_Return) then Cannot_Inline ("cannot inline & (unconstrained return type)?", N, Spec_Id); return; end if; -- If secondary stack is used, there is no point in inlining. We have -- already issued the warning in this case, so nothing to do. elsif Uses_Secondary_Stack (Body_To_Analyze) then return; end if; Set_Body_To_Inline (Decl, Original_Body); Set_Ekind (Defining_Entity (Original_Body), Ekind (Spec_Id)); Set_Is_Inlined (Spec_Id); end Build_Body_To_Inline; ------------------------------------------- -- Call_Can_Be_Inlined_In_GNATprove_Mode -- ------------------------------------------- function Call_Can_Be_Inlined_In_GNATprove_Mode (N : Node_Id; Subp : Entity_Id) return Boolean is F : Entity_Id; A : Node_Id; begin F := First_Formal (Subp); A := First_Actual (N); while Present (F) loop if Ekind (F) /= E_Out_Parameter and then not Same_Type (Etype (F), Etype (A)) and then (Is_By_Reference_Type (Etype (A)) or else Is_Limited_Type (Etype (A))) then return False; end if; Next_Formal (F); Next_Actual (A); end loop; return True; end Call_Can_Be_Inlined_In_GNATprove_Mode; -------------------------------------- -- Can_Be_Inlined_In_GNATprove_Mode -- -------------------------------------- function Can_Be_Inlined_In_GNATprove_Mode (Spec_Id : Entity_Id; Body_Id : Entity_Id) return Boolean is function Has_Formal_Or_Result_Of_Deep_Type (Id : Entity_Id) return Boolean; -- Returns true if the subprogram has at least one formal parameter or -- a return type of a deep type: either an access type or a composite -- type containing an access type. function Has_Formal_With_Discriminant_Dependent_Fields (Id : Entity_Id) return Boolean; -- Returns true if the subprogram has at least one formal parameter of -- an unconstrained record type with per-object constraints on component -- types. function Has_Some_Contract (Id : Entity_Id) return Boolean; -- Return True if subprogram Id has any contract. The presence of -- Extensions_Visible or Volatile_Function is also considered as a -- contract here. function Is_Unit_Subprogram (Id : Entity_Id) return Boolean; -- Return True if subprogram Id defines a compilation unit -- Shouldn't this be in Sem_Aux??? function In_Package_Spec (Id : Entity_Id) return Boolean; -- Return True if subprogram Id is defined in the package specification, -- either its visible or private part. function Maybe_Traversal_Function (Id : Entity_Id) return Boolean; -- Return True if subprogram Id could be a traversal function, as -- defined in SPARK RM 3.10. This is only a safe approximation, as the -- knowledge of the SPARK boundary is needed to determine exactly -- traversal functions. --------------------------------------- -- Has_Formal_Or_Result_Of_Deep_Type -- --------------------------------------- function Has_Formal_Or_Result_Of_Deep_Type (Id : Entity_Id) return Boolean is function Is_Deep (Typ : Entity_Id) return Boolean; -- Return True if Typ is deep: either an access type or a composite -- type containing an access type. ------------- -- Is_Deep -- ------------- function Is_Deep (Typ : Entity_Id) return Boolean is begin case Type_Kind'(Ekind (Typ)) is when Access_Kind => return True; when E_Array_Type | E_Array_Subtype => return Is_Deep (Component_Type (Typ)); when Record_Kind => declare Comp : Entity_Id := First_Component_Or_Discriminant (Typ); begin while Present (Comp) loop if Is_Deep (Etype (Comp)) then return True; end if; Next_Component_Or_Discriminant (Comp); end loop; end; return False; when Scalar_Kind | E_String_Literal_Subtype | Concurrent_Kind | Incomplete_Kind | E_Exception_Type | E_Subprogram_Type => return False; when E_Private_Type | E_Private_Subtype | E_Limited_Private_Type | E_Limited_Private_Subtype => -- Conservatively consider that the type might be deep if -- its completion has not been seen yet. if No (Underlying_Type (Typ)) then return True; -- Do not peek under a private type if its completion has -- SPARK_Mode Off. In such a case, a deep type is considered -- by GNATprove to be not deep. elsif Present (Full_View (Typ)) and then Present (SPARK_Pragma (Full_View (Typ))) and then Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Full_View (Typ))) = Off then return False; -- Otherwise peek under the private type. else return Is_Deep (Underlying_Type (Typ)); end if; end case; end Is_Deep; -- Local variables Subp_Id : constant Entity_Id := Ultimate_Alias (Id); Formal : Entity_Id; Formal_Typ : Entity_Id; -- Start of processing for Has_Formal_Or_Result_Of_Deep_Type begin -- Inspect all parameters of the subprogram looking for a formal -- of a deep type. Formal := First_Formal (Subp_Id); while Present (Formal) loop Formal_Typ := Etype (Formal); if Is_Deep (Formal_Typ) then return True; end if; Next_Formal (Formal); end loop; -- Check whether this is a function whose return type is deep if Ekind (Subp_Id) = E_Function and then Is_Deep (Etype (Subp_Id)) then return True; end if; return False; end Has_Formal_Or_Result_Of_Deep_Type; --------------------------------------------------- -- Has_Formal_With_Discriminant_Dependent_Fields -- --------------------------------------------------- function Has_Formal_With_Discriminant_Dependent_Fields (Id : Entity_Id) return Boolean is function Has_Discriminant_Dependent_Component (Typ : Entity_Id) return Boolean; -- Determine whether unconstrained record type Typ has at least one -- component that depends on a discriminant. ------------------------------------------ -- Has_Discriminant_Dependent_Component -- ------------------------------------------ function Has_Discriminant_Dependent_Component (Typ : Entity_Id) return Boolean is Comp : Entity_Id; begin -- Inspect all components of the record type looking for one that -- depends on a discriminant. Comp := First_Component (Typ); while Present (Comp) loop if Has_Discriminant_Dependent_Constraint (Comp) then return True; end if; Next_Component (Comp); end loop; return False; end Has_Discriminant_Dependent_Component; -- Local variables Subp_Id : constant Entity_Id := Ultimate_Alias (Id); Formal : Entity_Id; Formal_Typ : Entity_Id; -- Start of processing for -- Has_Formal_With_Discriminant_Dependent_Fields begin -- Inspect all parameters of the subprogram looking for a formal -- of an unconstrained record type with at least one discriminant -- dependent component. Formal := First_Formal (Subp_Id); while Present (Formal) loop Formal_Typ := Etype (Formal); if Is_Record_Type (Formal_Typ) and then not Is_Constrained (Formal_Typ) and then Has_Discriminant_Dependent_Component (Formal_Typ) then return True; end if; Next_Formal (Formal); end loop; return False; end Has_Formal_With_Discriminant_Dependent_Fields; ----------------------- -- Has_Some_Contract -- ----------------------- function Has_Some_Contract (Id : Entity_Id) return Boolean is Items : Node_Id; begin -- A call to an expression function may precede the actual body which -- is inserted at the end of the enclosing declarations. Ensure that -- the related entity is decorated before inspecting the contract. if Is_Subprogram_Or_Generic_Subprogram (Id) then Items := Contract (Id); -- Note that Classifications is not Empty when Extensions_Visible -- or Volatile_Function is present, which causes such subprograms -- to be considered to have a contract here. This is fine as we -- want to avoid inlining these too. return Present (Items) and then (Present (Pre_Post_Conditions (Items)) or else Present (Contract_Test_Cases (Items)) or else Present (Classifications (Items))); end if; return False; end Has_Some_Contract; --------------------- -- In_Package_Spec -- --------------------- function In_Package_Spec (Id : Entity_Id) return Boolean is P : constant Node_Id := Parent (Subprogram_Spec (Id)); -- Parent of the subprogram's declaration begin return Nkind (Enclosing_Declaration (P)) = N_Package_Declaration; end In_Package_Spec; ------------------------ -- Is_Unit_Subprogram -- ------------------------ function Is_Unit_Subprogram (Id : Entity_Id) return Boolean is Decl : Node_Id := Parent (Parent (Id)); begin if Nkind (Parent (Id)) = N_Defining_Program_Unit_Name then Decl := Parent (Decl); end if; return Nkind (Parent (Decl)) = N_Compilation_Unit; end Is_Unit_Subprogram; ------------------------------ -- Maybe_Traversal_Function -- ------------------------------ function Maybe_Traversal_Function (Id : Entity_Id) return Boolean is begin return Ekind (Id) = E_Function -- Only traversal functions return an anonymous access-to-object -- type in SPARK. and then Is_Anonymous_Access_Type (Etype (Id)); end Maybe_Traversal_Function; -- Local declarations Id : Entity_Id; -- Procedure or function entity for the subprogram -- Start of processing for Can_Be_Inlined_In_GNATprove_Mode begin pragma Assert (Present (Spec_Id) or else Present (Body_Id)); if Present (Spec_Id) then Id := Spec_Id; else Id := Body_Id; end if; -- Only local subprograms without contracts are inlined in GNATprove -- mode, as these are the subprograms which a user is not interested in -- analyzing in isolation, but rather in the context of their call. This -- is a convenient convention, that could be changed for an explicit -- pragma/aspect one day. -- In a number of special cases, inlining is not desirable or not -- possible, see below. -- Do not inline unit-level subprograms if Is_Unit_Subprogram (Id) then return False; -- Do not inline subprograms declared in package specs, because they are -- not local, i.e. can be called either from anywhere (if declared in -- visible part) or from the child units (if declared in private part). elsif In_Package_Spec (Id) then return False; -- Do not inline subprograms declared in other units. This is important -- in particular for subprograms defined in the private part of a -- package spec, when analyzing one of its child packages, as otherwise -- we issue spurious messages about the impossibility to inline such -- calls. elsif not In_Extended_Main_Code_Unit (Id) then return False; -- Do not inline dispatching operations, as only their static calls -- can be analyzed in context, and not their dispatching calls. elsif Is_Dispatching_Operation (Id) then return False; -- Do not inline subprograms marked No_Return, possibly used for -- signaling errors, which GNATprove handles specially. elsif No_Return (Id) then return False; -- Do not inline subprograms that have a contract on the spec or the -- body. Use the contract(s) instead in GNATprove. This also prevents -- inlining of subprograms with Extensions_Visible or Volatile_Function. elsif (Present (Spec_Id) and then Has_Some_Contract (Spec_Id)) or else (Present (Body_Id) and then Has_Some_Contract (Body_Id)) then return False; -- Do not inline expression functions, which are directly inlined at the -- prover level. elsif (Present (Spec_Id) and then Is_Expression_Function (Spec_Id)) or else (Present (Body_Id) and then Is_Expression_Function (Body_Id)) then return False; -- Do not inline generic subprogram instances. The visibility rules of -- generic instances plays badly with inlining. elsif Is_Generic_Instance (Spec_Id) then return False; -- Only inline subprograms whose spec is marked SPARK_Mode On. For -- the subprogram body, a similar check is performed after the body -- is analyzed, as this is where a pragma SPARK_Mode might be inserted. elsif Present (Spec_Id) and then (No (SPARK_Pragma (Spec_Id)) or else Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Spec_Id)) /= On) then return False; -- Subprograms in generic instances are currently not inlined, to avoid -- problems with inlining of standard library subprograms. elsif Instantiation_Location (Sloc (Id)) /= No_Location then return False; -- Do not inline subprograms and entries defined inside protected types, -- which typically are not helper subprograms, which also avoids getting -- spurious messages on calls that cannot be inlined. elsif Within_Protected_Type (Id) then return False; -- Do not inline predicate functions (treated specially by GNATprove) elsif Is_Predicate_Function (Id) then return False; -- Do not inline subprograms with a parameter of an unconstrained -- record type if it has discrimiant dependent fields. Indeed, with -- such parameters, the frontend cannot always ensure type compliance -- in record component accesses (in particular with records containing -- packed arrays). elsif Has_Formal_With_Discriminant_Dependent_Fields (Id) then return False; -- Do not inline subprograms with a formal parameter or return type of -- a deep type, as in that case inlining might generate code that -- violates borrow-checking rules of SPARK 3.10 even if the original -- code did not. elsif Has_Formal_Or_Result_Of_Deep_Type (Id) then return False; -- Do not inline subprograms which may be traversal functions. Such -- inlining introduces temporary variables of named access type for -- which assignments are move instead of borrow/observe, possibly -- leading to spurious errors when checking SPARK rules related to -- pointer usage. elsif Maybe_Traversal_Function (Id) then return False; -- Otherwise, this is a subprogram declared inside the private part of a -- package, or inside a package body, or locally in a subprogram, and it -- does not have any contract. Inline it. else return True; end if; end Can_Be_Inlined_In_GNATprove_Mode; ------------------- -- Cannot_Inline -- ------------------- procedure Cannot_Inline (Msg : String; N : Node_Id; Subp : Entity_Id; Is_Serious : Boolean := False) is begin -- In GNATprove mode, inlining is the technical means by which the -- higher-level goal of contextual analysis is reached, so issue -- messages about failure to apply contextual analysis to a -- subprogram, rather than failure to inline it. if GNATprove_Mode and then Msg (Msg'First .. Msg'First + 12) = "cannot inline" then declare Len1 : constant Positive := String (String'("cannot inline"))'Length; Len2 : constant Positive := String (String'("info: no contextual analysis of"))'Length; New_Msg : String (1 .. Msg'Length + Len2 - Len1); begin New_Msg (1 .. Len2) := "info: no contextual analysis of"; New_Msg (Len2 + 1 .. Msg'Length + Len2 - Len1) := Msg (Msg'First + Len1 .. Msg'Last); Cannot_Inline (New_Msg, N, Subp, Is_Serious); return; end; end if; pragma Assert (Msg (Msg'Last) = '?'); -- Legacy front-end inlining model if not Back_End_Inlining then -- Do not emit warning if this is a predefined unit which is not -- the main unit. With validity checks enabled, some predefined -- subprograms may contain nested subprograms and become ineligible -- for inlining. if Is_Predefined_Unit (Get_Source_Unit (Subp)) and then not In_Extended_Main_Source_Unit (Subp) then null; -- In GNATprove mode, issue a warning when -gnatd_f is set, and -- indicate that the subprogram is not always inlined by setting -- flag Is_Inlined_Always to False. elsif GNATprove_Mode then Set_Is_Inlined_Always (Subp, False); if Debug_Flag_Underscore_F then Error_Msg_NE (Msg, N, Subp); end if; elsif Has_Pragma_Inline_Always (Subp) then -- Remove last character (question mark) to make this into an -- error, because the Inline_Always pragma cannot be obeyed. Error_Msg_NE (Msg (Msg'First .. Msg'Last - 1), N, Subp); elsif Ineffective_Inline_Warnings then Error_Msg_NE (Msg & "p?", N, Subp); end if; -- New semantics relying on back-end inlining elsif Is_Serious then -- Remove last character (question mark) to make this into an error. Error_Msg_NE (Msg (Msg'First .. Msg'Last - 1), N, Subp); -- In GNATprove mode, issue a warning when -gnatd_f is set, and -- indicate that the subprogram is not always inlined by setting -- flag Is_Inlined_Always to False. elsif GNATprove_Mode then Set_Is_Inlined_Always (Subp, False); if Debug_Flag_Underscore_F then Error_Msg_NE (Msg, N, Subp); end if; else -- Do not emit warning if this is a predefined unit which is not -- the main unit. This behavior is currently provided for backward -- compatibility but it will be removed when we enforce the -- strictness of the new rules. if Is_Predefined_Unit (Get_Source_Unit (Subp)) and then not In_Extended_Main_Source_Unit (Subp) then null; elsif Has_Pragma_Inline_Always (Subp) then -- Emit a warning if this is a call to a runtime subprogram -- which is located inside a generic. Previously this call -- was silently skipped. if Is_Generic_Instance (Subp) then declare Gen_P : constant Entity_Id := Generic_Parent (Parent (Subp)); begin if Is_Predefined_Unit (Get_Source_Unit (Gen_P)) then Set_Is_Inlined (Subp, False); Error_Msg_NE (Msg & "p?", N, Subp); return; end if; end; end if; -- Remove last character (question mark) to make this into an -- error, because the Inline_Always pragma cannot be obeyed. Error_Msg_NE (Msg (Msg'First .. Msg'Last - 1), N, Subp); else Set_Is_Inlined (Subp, False); if Ineffective_Inline_Warnings then Error_Msg_NE (Msg & "p?", N, Subp); end if; end if; end if; end Cannot_Inline; -------------------------------------------- -- Check_And_Split_Unconstrained_Function -- -------------------------------------------- procedure Check_And_Split_Unconstrained_Function (N : Node_Id; Spec_Id : Entity_Id; Body_Id : Entity_Id) is procedure Build_Body_To_Inline (N : Node_Id; Spec_Id : Entity_Id); -- Use generic machinery to build an unexpanded body for the subprogram. -- This body is subsequently used for inline expansions at call sites. procedure Build_Return_Object_Formal (Loc : Source_Ptr; Obj_Decl : Node_Id; Formals : List_Id); -- Create a formal parameter for return object declaration Obj_Decl of -- an extended return statement and add it to list Formals. function Can_Split_Unconstrained_Function (N : Node_Id) return Boolean; -- Return true if we generate code for the function body N, the function -- body N has no local declarations and its unique statement is a single -- extended return statement with a handled statements sequence. procedure Copy_Formals (Loc : Source_Ptr; Subp_Id : Entity_Id; Formals : List_Id); -- Create new formal parameters from the formal parameters of subprogram -- Subp_Id and add them to list Formals. function Copy_Return_Object (Obj_Decl : Node_Id) return Node_Id; -- Create a copy of return object declaration Obj_Decl of an extended -- return statement. procedure Split_Unconstrained_Function (N : Node_Id; Spec_Id : Entity_Id); -- N is an inlined function body that returns an unconstrained type and -- has a single extended return statement. Split N in two subprograms: -- a procedure P' and a function F'. The formals of P' duplicate the -- formals of N plus an extra formal which is used to return a value; -- its body is composed by the declarations and list of statements -- of the extended return statement of N. -------------------------- -- Build_Body_To_Inline -- -------------------------- procedure Build_Body_To_Inline (N : Node_Id; Spec_Id : Entity_Id) is procedure Generate_Subprogram_Body (N : Node_Id; Body_To_Inline : out Node_Id); -- Generate a parameterless duplicate of subprogram body N. Note that -- occurrences of pragmas referencing the formals are removed since -- they have no meaning when the body is inlined and the formals are -- rewritten (the analysis of the non-inlined body will handle these -- pragmas). A new internal name is associated with Body_To_Inline. ------------------------------ -- Generate_Subprogram_Body -- ------------------------------ procedure Generate_Subprogram_Body (N : Node_Id; Body_To_Inline : out Node_Id) is begin -- Within an instance, the body to inline must be treated as a -- nested generic so that proper global references are preserved. -- Note that we do not do this at the library level, because it -- is not needed, and furthermore this causes trouble if front -- end inlining is activated (-gnatN). if In_Instance and then Scope (Current_Scope) /= Standard_Standard then Body_To_Inline := Copy_Generic_Node (N, Empty, Instantiating => True); else -- ??? Shouldn't this use New_Copy_Tree? What about global -- references captured in the body to inline? Body_To_Inline := Copy_Separate_Tree (N); end if; -- Remove aspects/pragmas that have no meaning in an inlined body Remove_Aspects_And_Pragmas (Body_To_Inline); -- We need to capture references to the formals in order -- to substitute the actuals at the point of inlining, i.e. -- instantiation. To treat the formals as globals to the body to -- inline, we nest it within a dummy parameterless subprogram, -- declared within the real one. Set_Parameter_Specifications (Specification (Body_To_Inline), No_List); -- A new internal name is associated with Body_To_Inline to avoid -- conflicts when the non-inlined body N is analyzed. Set_Defining_Unit_Name (Specification (Body_To_Inline), Make_Defining_Identifier (Sloc (N), New_Internal_Name ('P'))); Set_Corresponding_Spec (Body_To_Inline, Empty); end Generate_Subprogram_Body; -- Local variables Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id); Original_Body : Node_Id; Body_To_Analyze : Node_Id; -- Start of processing for Build_Body_To_Inline begin pragma Assert (Current_Scope = Spec_Id); -- Within an instance, the body to inline must be treated as a nested -- generic, so that the proper global references are preserved. We -- do not do this at the library level, because it is not needed, and -- furthermore this causes trouble if front-end inlining is activated -- (-gnatN). if In_Instance and then Scope (Current_Scope) /= Standard_Standard then Save_Env (Scope (Current_Scope), Scope (Current_Scope)); end if; -- Capture references to formals in order to substitute the actuals -- at the point of inlining or instantiation. To treat the formals -- as globals to the body to inline, nest the body within a dummy -- parameterless subprogram, declared within the real one. Generate_Subprogram_Body (N, Original_Body); Body_To_Analyze := Copy_Generic_Node (Original_Body, Empty, Instantiating => False); -- Set return type of function, which is also global and does not -- need to be resolved. if Ekind (Spec_Id) = E_Function then Set_Result_Definition (Specification (Body_To_Analyze), New_Occurrence_Of (Etype (Spec_Id), Sloc (N))); end if; if No (Declarations (N)) then Set_Declarations (N, New_List (Body_To_Analyze)); else Append_To (Declarations (N), Body_To_Analyze); end if; Preanalyze (Body_To_Analyze); Push_Scope (Defining_Entity (Body_To_Analyze)); Save_Global_References (Original_Body); End_Scope; Remove (Body_To_Analyze); -- Restore environment if previously saved if In_Instance and then Scope (Current_Scope) /= Standard_Standard then Restore_Env; end if; pragma Assert (No (Body_To_Inline (Decl))); Set_Body_To_Inline (Decl, Original_Body); Set_Ekind (Defining_Entity (Original_Body), Ekind (Spec_Id)); end Build_Body_To_Inline; -------------------------------- -- Build_Return_Object_Formal -- -------------------------------- procedure Build_Return_Object_Formal (Loc : Source_Ptr; Obj_Decl : Node_Id; Formals : List_Id) is Obj_Def : constant Node_Id := Object_Definition (Obj_Decl); Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl); Typ_Def : Node_Id; begin -- Build the type definition of the formal parameter. The use of -- New_Copy_Tree ensures that global references preserved in the -- case of generics. if Is_Entity_Name (Obj_Def) then Typ_Def := New_Copy_Tree (Obj_Def); else Typ_Def := New_Copy_Tree (Subtype_Mark (Obj_Def)); end if; -- Generate: -- -- Obj_Id : [out] Typ_Def -- Mode OUT should not be used when the return object is declared as -- a constant. Check the definition of the object declaration because -- the object has not been analyzed yet. Append_To (Formals, Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Chars (Obj_Id)), In_Present => False, Out_Present => not Constant_Present (Obj_Decl), Null_Exclusion_Present => False, Parameter_Type => Typ_Def)); end Build_Return_Object_Formal; -------------------------------------- -- Can_Split_Unconstrained_Function -- -------------------------------------- function Can_Split_Unconstrained_Function (N : Node_Id) return Boolean is Stmt : constant Node_Id := First (Statements (Handled_Statement_Sequence (N))); Decl : Node_Id; begin -- No user defined declarations allowed in the function except inside -- the unique return statement; implicit labels are the only allowed -- declarations. Decl := First (Declarations (N)); while Present (Decl) loop if Nkind (Decl) /= N_Implicit_Label_Declaration then return False; end if; Next (Decl); end loop; -- We only split the inlined function when we are generating the code -- of its body; otherwise we leave duplicated split subprograms in -- the tree which (if referenced) generate wrong references at link -- time. return In_Extended_Main_Code_Unit (N) and then Present (Stmt) and then Nkind (Stmt) = N_Extended_Return_Statement and then No (Next (Stmt)) and then Present (Handled_Statement_Sequence (Stmt)); end Can_Split_Unconstrained_Function; ------------------ -- Copy_Formals -- ------------------ procedure Copy_Formals (Loc : Source_Ptr; Subp_Id : Entity_Id; Formals : List_Id) is Formal : Entity_Id; Spec : Node_Id; begin Formal := First_Formal (Subp_Id); while Present (Formal) loop Spec := Parent (Formal); -- Create an exact copy of the formal parameter. The use of -- New_Copy_Tree ensures that global references are preserved -- in case of generics. Append_To (Formals, Make_Parameter_Specification (Loc, Defining_Identifier => Make_Defining_Identifier (Sloc (Formal), Chars (Formal)), In_Present => In_Present (Spec), Out_Present => Out_Present (Spec), Null_Exclusion_Present => Null_Exclusion_Present (Spec), Parameter_Type => New_Copy_Tree (Parameter_Type (Spec)), Expression => New_Copy_Tree (Expression (Spec)))); Next_Formal (Formal); end loop; end Copy_Formals; ------------------------ -- Copy_Return_Object -- ------------------------ function Copy_Return_Object (Obj_Decl : Node_Id) return Node_Id is Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl); begin -- The use of New_Copy_Tree ensures that global references are -- preserved in case of generics. return Make_Object_Declaration (Sloc (Obj_Decl), Defining_Identifier => Make_Defining_Identifier (Sloc (Obj_Id), Chars (Obj_Id)), Aliased_Present => Aliased_Present (Obj_Decl), Constant_Present => Constant_Present (Obj_Decl), Null_Exclusion_Present => Null_Exclusion_Present (Obj_Decl), Object_Definition => New_Copy_Tree (Object_Definition (Obj_Decl)), Expression => New_Copy_Tree (Expression (Obj_Decl))); end Copy_Return_Object; ---------------------------------- -- Split_Unconstrained_Function -- ---------------------------------- procedure Split_Unconstrained_Function (N : Node_Id; Spec_Id : Entity_Id) is Loc : constant Source_Ptr := Sloc (N); Ret_Stmt : constant Node_Id := First (Statements (Handled_Statement_Sequence (N))); Ret_Obj : constant Node_Id := First (Return_Object_Declarations (Ret_Stmt)); procedure Build_Procedure (Proc_Id : out Entity_Id; Decl_List : out List_Id); -- Build a procedure containing the statements found in the extended -- return statement of the unconstrained function body N. --------------------- -- Build_Procedure -- --------------------- procedure Build_Procedure (Proc_Id : out Entity_Id; Decl_List : out List_Id) is Formals : constant List_Id := New_List; Subp_Name : constant Name_Id := New_Internal_Name ('F'); Body_Decls : List_Id := No_List; Decl : Node_Id; Proc_Body : Node_Id; Proc_Spec : Node_Id; begin -- Create formal parameters for the return object and all formals -- of the unconstrained function in order to pass their values to -- the procedure. Build_Return_Object_Formal (Loc => Loc, Obj_Decl => Ret_Obj, Formals => Formals); Copy_Formals (Loc => Loc, Subp_Id => Spec_Id, Formals => Formals); Proc_Id := Make_Defining_Identifier (Loc, Chars => Subp_Name); Proc_Spec := Make_Procedure_Specification (Loc, Defining_Unit_Name => Proc_Id, Parameter_Specifications => Formals); Decl_List := New_List; Append_To (Decl_List, Make_Subprogram_Declaration (Loc, Proc_Spec)); -- Can_Convert_Unconstrained_Function checked that the function -- has no local declarations except implicit label declarations. -- Copy these declarations to the built procedure. if Present (Declarations (N)) then Body_Decls := New_List; Decl := First (Declarations (N)); while Present (Decl) loop pragma Assert (Nkind (Decl) = N_Implicit_Label_Declaration); Append_To (Body_Decls, Make_Implicit_Label_Declaration (Loc, Make_Defining_Identifier (Loc, Chars => Chars (Defining_Identifier (Decl))), Label_Construct => Empty)); Next (Decl); end loop; end if; pragma Assert (Present (Handled_Statement_Sequence (Ret_Stmt))); Proc_Body := Make_Subprogram_Body (Loc, Specification => Copy_Subprogram_Spec (Proc_Spec), Declarations => Body_Decls, Handled_Statement_Sequence => New_Copy_Tree (Handled_Statement_Sequence (Ret_Stmt))); Set_Defining_Unit_Name (Specification (Proc_Body), Make_Defining_Identifier (Loc, Subp_Name)); Append_To (Decl_List, Proc_Body); end Build_Procedure; -- Local variables New_Obj : constant Node_Id := Copy_Return_Object (Ret_Obj); Blk_Stmt : Node_Id; Proc_Call : Node_Id; Proc_Id : Entity_Id; -- Start of processing for Split_Unconstrained_Function begin -- Build the associated procedure, analyze it and insert it before -- the function body N. declare Scope : constant Entity_Id := Current_Scope; Decl_List : List_Id; begin Pop_Scope; Build_Procedure (Proc_Id, Decl_List); Insert_Actions (N, Decl_List); Set_Is_Inlined (Proc_Id); Push_Scope (Scope); end; -- Build the call to the generated procedure declare Actual_List : constant List_Id := New_List; Formal : Entity_Id; begin Append_To (Actual_List, New_Occurrence_Of (Defining_Identifier (New_Obj), Loc)); Formal := First_Formal (Spec_Id); while Present (Formal) loop Append_To (Actual_List, New_Occurrence_Of (Formal, Loc)); -- Avoid spurious warning on unreferenced formals Set_Referenced (Formal); Next_Formal (Formal); end loop; Proc_Call := Make_Procedure_Call_Statement (Loc, Name => New_Occurrence_Of (Proc_Id, Loc), Parameter_Associations => Actual_List); end; -- Generate: -- declare -- New_Obj : ... -- begin -- Proc (New_Obj, ...); -- return New_Obj; -- end; Blk_Stmt := Make_Block_Statement (Loc, Declarations => New_List (New_Obj), Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List ( Proc_Call, Make_Simple_Return_Statement (Loc, Expression => New_Occurrence_Of (Defining_Identifier (New_Obj), Loc))))); Rewrite (Ret_Stmt, Blk_Stmt); end Split_Unconstrained_Function; -- Local variables Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id); -- Start of processing for Check_And_Split_Unconstrained_Function begin pragma Assert (Back_End_Inlining and then Ekind (Spec_Id) = E_Function and then Returns_Unconstrained_Type (Spec_Id) and then Comes_From_Source (Body_Id) and then (Has_Pragma_Inline_Always (Spec_Id) or else Optimization_Level > 0)); -- This routine must not be used in GNATprove mode since GNATprove -- relies on frontend inlining pragma Assert (not GNATprove_Mode); -- No need to split the function if we cannot generate the code if Serious_Errors_Detected /= 0 then return; end if; -- No action needed in stubs since the attribute Body_To_Inline -- is not available if Nkind (Decl) = N_Subprogram_Body_Stub then return; -- Cannot build the body to inline if the attribute is already set. -- This attribute may have been set if this is a subprogram renaming -- declarations (see Freeze.Build_Renamed_Body). elsif Present (Body_To_Inline (Decl)) then return; -- Do not generate a body to inline for protected functions, because the -- transformation generates a call to a protected procedure, causing -- spurious errors. We don't inline protected operations anyway, so -- this is no loss. We might as well ignore intrinsics and foreign -- conventions as well -- just allow Ada conventions. elsif not (Convention (Spec_Id) = Convention_Ada or else Convention (Spec_Id) = Convention_Ada_Pass_By_Copy or else Convention (Spec_Id) = Convention_Ada_Pass_By_Reference) then return; -- Check excluded declarations elsif Present (Declarations (N)) and then Has_Excluded_Declaration (Spec_Id, Declarations (N)) then return; -- Check excluded statements. There is no need to protect us against -- exception handlers since they are supported by the GCC backend. elsif Present (Handled_Statement_Sequence (N)) and then Has_Excluded_Statement (Spec_Id, Statements (Handled_Statement_Sequence (N))) then return; end if; -- Build the body to inline only if really needed if Can_Split_Unconstrained_Function (N) then Split_Unconstrained_Function (N, Spec_Id); Build_Body_To_Inline (N, Spec_Id); Set_Is_Inlined (Spec_Id); end if; end Check_And_Split_Unconstrained_Function; ------------------------------------- -- Check_Package_Body_For_Inlining -- ------------------------------------- procedure Check_Package_Body_For_Inlining (N : Node_Id; P : Entity_Id) is Bname : Unit_Name_Type; E : Entity_Id; OK : Boolean; begin -- Legacy implementation (relying on frontend inlining) if not Back_End_Inlining and then Is_Compilation_Unit (P) and then not Is_Generic_Instance (P) then Bname := Get_Body_Name (Get_Unit_Name (Unit (N))); E := First_Entity (P); while Present (E) loop if Has_Pragma_Inline_Always (E) or else (Has_Pragma_Inline (E) and Front_End_Inlining) then if not Is_Loaded (Bname) then Load_Needed_Body (N, OK); if OK then -- Check we are not trying to inline a parent whose body -- depends on a child, when we are compiling the body of -- the child. Otherwise we have a potential elaboration -- circularity with inlined subprograms and with -- Taft-Amendment types. declare Comp : Node_Id; -- Body just compiled Child_Spec : Entity_Id; -- Spec of main unit Ent : Entity_Id; -- For iteration With_Clause : Node_Id; -- Context of body. begin if Nkind (Unit (Cunit (Main_Unit))) = N_Package_Body and then Present (Body_Entity (P)) then Child_Spec := Defining_Entity ((Unit (Library_Unit (Cunit (Main_Unit))))); Comp := Parent (Unit_Declaration_Node (Body_Entity (P))); -- Check whether the context of the body just -- compiled includes a child of itself, and that -- child is the spec of the main compilation. With_Clause := First (Context_Items (Comp)); while Present (With_Clause) loop if Nkind (With_Clause) = N_With_Clause and then Scope (Entity (Name (With_Clause))) = P and then Entity (Name (With_Clause)) = Child_Spec then Error_Msg_Node_2 := Child_Spec; Error_Msg_NE ("body of & depends on child unit&??", With_Clause, P); Error_Msg_N ("\subprograms in body cannot be inlined??", With_Clause); -- Disable further inlining from this unit, -- and keep Taft-amendment types incomplete. Ent := First_Entity (P); while Present (Ent) loop if Is_Type (Ent) and then Has_Completion_In_Body (Ent) then Set_Full_View (Ent, Empty); elsif Is_Subprogram (Ent) then Set_Is_Inlined (Ent, False); end if; Next_Entity (Ent); end loop; return; end if; Next (With_Clause); end loop; end if; end; elsif Ineffective_Inline_Warnings then Error_Msg_Unit_1 := Bname; Error_Msg_N ("unable to inline subprograms defined in $??", P); Error_Msg_N ("\body not found??", P); return; end if; end if; return; end if; Next_Entity (E); end loop; end if; end Check_Package_Body_For_Inlining; -------------------- -- Cleanup_Scopes -- -------------------- procedure Cleanup_Scopes is Elmt : Elmt_Id; Decl : Node_Id; Scop : Entity_Id; begin Elmt := First_Elmt (To_Clean); while Present (Elmt) loop Scop := Node (Elmt); if Ekind (Scop) = E_Entry then Scop := Protected_Body_Subprogram (Scop); elsif Is_Subprogram (Scop) and then Is_Protected_Type (Scope (Scop)) and then Present (Protected_Body_Subprogram (Scop)) then -- If a protected operation contains an instance, its cleanup -- operations have been delayed, and the subprogram has been -- rewritten in the expansion of the enclosing protected body. It -- is the corresponding subprogram that may require the cleanup -- operations, so propagate the information that triggers cleanup -- activity. Set_Uses_Sec_Stack (Protected_Body_Subprogram (Scop), Uses_Sec_Stack (Scop)); Scop := Protected_Body_Subprogram (Scop); end if; if Ekind (Scop) = E_Block then Decl := Parent (Block_Node (Scop)); else Decl := Unit_Declaration_Node (Scop); if Nkind (Decl) in N_Subprogram_Declaration | N_Task_Type_Declaration | N_Subprogram_Body_Stub then Decl := Unit_Declaration_Node (Corresponding_Body (Decl)); end if; end if; Push_Scope (Scop); Expand_Cleanup_Actions (Decl); End_Scope; Next_Elmt (Elmt); end loop; end Cleanup_Scopes; procedure Establish_Actual_Mapping_For_Inlined_Call (N : Node_Id; Subp : Entity_Id; Decls : List_Id; Body_Or_Expr_To_Check : Node_Id) is function Formal_Is_Used_Once (Formal : Entity_Id) return Boolean; -- Determine whether a formal parameter is used only once in -- Body_Or_Expr_To_Check. ------------------------- -- Formal_Is_Used_Once -- ------------------------- function Formal_Is_Used_Once (Formal : Entity_Id) return Boolean is Use_Counter : Int := 0; function Count_Uses (N : Node_Id) return Traverse_Result; -- Traverse the tree and count the uses of the formal parameter. -- In this case, for optimization purposes, we do not need to -- continue the traversal once more than one use is encountered. ---------------- -- Count_Uses -- ---------------- function Count_Uses (N : Node_Id) return Traverse_Result is begin -- The original node is an identifier if Nkind (N) = N_Identifier and then Present (Entity (N)) -- Original node's entity points to the one in the copied body and then Nkind (Entity (N)) = N_Identifier and then Present (Entity (Entity (N))) -- The entity of the copied node is the formal parameter and then Entity (Entity (N)) = Formal then Use_Counter := Use_Counter + 1; if Use_Counter > 1 then -- Denote more than one use and abandon the traversal Use_Counter := 2; return Abandon; end if; end if; return OK; end Count_Uses; procedure Count_Formal_Uses is new Traverse_Proc (Count_Uses); -- Start of processing for Formal_Is_Used_Once begin Count_Formal_Uses (Body_Or_Expr_To_Check); return Use_Counter = 1; end Formal_Is_Used_Once; -- Local Data -- F : Entity_Id; A : Node_Id; Decl : Node_Id; Loc : constant Source_Ptr := Sloc (N); New_A : Node_Id; Temp : Entity_Id; Temp_Typ : Entity_Id; -- Start of processing for Establish_Actual_Mapping_For_Inlined_Call begin F := First_Formal (Subp); A := First_Actual (N); while Present (F) loop if Present (Renamed_Object (F)) then -- If expander is active, it is an error to try to inline a -- recursive program. In GNATprove mode, just indicate that the -- inlining will not happen, and mark the subprogram as not always -- inlined. if GNATprove_Mode then Cannot_Inline ("cannot inline call to recursive subprogram?", N, Subp); Set_Is_Inlined_Always (Subp, False); else Error_Msg_N ("cannot inline call to recursive subprogram", N); end if; return; end if; -- Reset Last_Assignment for any parameters of mode out or in out, to -- prevent spurious warnings about overwriting for assignments to the -- formal in the inlined code. if Is_Entity_Name (A) and then Ekind (F) /= E_In_Parameter then Set_Last_Assignment (Entity (A), Empty); end if; -- If the argument may be a controlling argument in a call within -- the inlined body, we must preserve its class-wide nature to ensure -- that dynamic dispatching will take place subsequently. If the -- formal has a constraint, then it must be preserved to retain the -- semantics of the body. if Is_Class_Wide_Type (Etype (F)) or else (Is_Access_Type (Etype (F)) and then Is_Class_Wide_Type (Designated_Type (Etype (F)))) then Temp_Typ := Etype (F); elsif Base_Type (Etype (F)) = Base_Type (Etype (A)) and then Etype (F) /= Base_Type (Etype (F)) and then Is_Constrained (Etype (F)) then Temp_Typ := Etype (F); else Temp_Typ := Etype (A); end if; -- If the actual is a simple name or a literal, no need to -- create a temporary, object can be used directly. -- If the actual is a literal and the formal has its address taken, -- we cannot pass the literal itself as an argument, so its value -- must be captured in a temporary. Skip this optimization in -- GNATprove mode, to make sure any check on a type conversion -- will be issued. if (Is_Entity_Name (A) and then (not Is_Scalar_Type (Etype (A)) or else Ekind (Entity (A)) = E_Enumeration_Literal) and then not GNATprove_Mode) -- When the actual is an identifier and the corresponding formal is -- used only once in the original body, the formal can be substituted -- directly with the actual parameter. Skip this optimization in -- GNATprove mode, to make sure any check on a type conversion -- will be issued. or else (Nkind (A) = N_Identifier and then Formal_Is_Used_Once (F) and then not GNATprove_Mode) or else (Nkind (A) in N_Real_Literal | N_Integer_Literal | N_Character_Literal and then not Address_Taken (F)) then if Etype (F) /= Etype (A) then Set_Renamed_Object (F, Unchecked_Convert_To (Etype (F), Relocate_Node (A))); else Set_Renamed_Object (F, A); end if; else Temp := Make_Temporary (Loc, 'C'); -- If the actual for an in/in-out parameter is a view conversion, -- make it into an unchecked conversion, given that an untagged -- type conversion is not a proper object for a renaming. -- In-out conversions that involve real conversions have already -- been transformed in Expand_Actuals. if Nkind (A) = N_Type_Conversion and then Ekind (F) /= E_In_Parameter then New_A := Make_Unchecked_Type_Conversion (Loc, Subtype_Mark => New_Occurrence_Of (Etype (F), Loc), Expression => Relocate_Node (Expression (A))); -- In GNATprove mode, keep the most precise type of the actual for -- the temporary variable, when the formal type is unconstrained. -- Otherwise, the AST may contain unexpected assignment statements -- to a temporary variable of unconstrained type renaming a local -- variable of constrained type, which is not expected by -- GNATprove. elsif Etype (F) /= Etype (A) and then (not GNATprove_Mode or else Is_Constrained (Etype (F))) then New_A := Unchecked_Convert_To (Etype (F), Relocate_Node (A)); Temp_Typ := Etype (F); else New_A := Relocate_Node (A); end if; Set_Sloc (New_A, Sloc (N)); -- If the actual has a by-reference type, it cannot be copied, -- so its value is captured in a renaming declaration. Otherwise -- declare a local constant initialized with the actual. -- We also use a renaming declaration for expressions of an array -- type that is not bit-packed, both for efficiency reasons and to -- respect the semantics of the call: in most cases the original -- call will pass the parameter by reference, and thus the inlined -- code will have the same semantics. -- Finally, we need a renaming declaration in the case of limited -- types for which initialization cannot be by copy either. if Ekind (F) = E_In_Parameter and then not Is_By_Reference_Type (Etype (A)) and then not Is_Limited_Type (Etype (A)) and then (not Is_Array_Type (Etype (A)) or else not Is_Object_Reference (A) or else Is_Bit_Packed_Array (Etype (A))) then Decl := Make_Object_Declaration (Loc, Defining_Identifier => Temp, Constant_Present => True, Object_Definition => New_Occurrence_Of (Temp_Typ, Loc), Expression => New_A); else -- In GNATprove mode, make an explicit copy of input -- parameters when formal and actual types differ, to make -- sure any check on the type conversion will be issued. -- The legality of the copy is ensured by calling first -- Call_Can_Be_Inlined_In_GNATprove_Mode. if GNATprove_Mode and then Ekind (F) /= E_Out_Parameter and then not Same_Type (Etype (F), Etype (A)) then pragma Assert (not Is_By_Reference_Type (Etype (A))); pragma Assert (not Is_Limited_Type (Etype (A))); Append_To (Decls, Make_Object_Declaration (Loc, Defining_Identifier => Make_Temporary (Loc, 'C'), Constant_Present => True, Object_Definition => New_Occurrence_Of (Temp_Typ, Loc), Expression => New_Copy_Tree (New_A))); end if; Decl := Make_Object_Renaming_Declaration (Loc, Defining_Identifier => Temp, Subtype_Mark => New_Occurrence_Of (Temp_Typ, Loc), Name => New_A); end if; Append (Decl, Decls); Set_Renamed_Object (F, Temp); end if; Next_Formal (F); Next_Actual (A); end loop; end Establish_Actual_Mapping_For_Inlined_Call; ------------------------- -- Expand_Inlined_Call -- ------------------------- procedure Expand_Inlined_Call (N : Node_Id; Subp : Entity_Id; Orig_Subp : Entity_Id) is Decls : constant List_Id := New_List; Is_Predef : constant Boolean := Is_Predefined_Unit (Get_Source_Unit (Subp)); Loc : constant Source_Ptr := Sloc (N); Orig_Bod : constant Node_Id := Body_To_Inline (Unit_Declaration_Node (Subp)); Uses_Back_End : constant Boolean := Back_End_Inlining and then Optimization_Level > 0; -- The back-end expansion is used if the target supports back-end -- inlining and some level of optimixation is required; otherwise -- the inlining takes place fully as a tree expansion. Blk : Node_Id; Decl : Node_Id; Exit_Lab : Entity_Id := Empty; Lab_Decl : Node_Id := Empty; Lab_Id : Node_Id; Num_Ret : Nat := 0; Ret_Type : Entity_Id; Temp : Entity_Id; Is_Unc : Boolean; Is_Unc_Decl : Boolean; -- If the type returned by the function is unconstrained and the call -- can be inlined, special processing is required. Return_Object : Entity_Id := Empty; -- Entity in declaration in an extended_return_statement Targ : Node_Id := Empty; -- The target of the call. If context is an assignment statement then -- this is the left-hand side of the assignment, else it is a temporary -- to which the return value is assigned prior to rewriting the call. Targ1 : Node_Id := Empty; -- A separate target used when the return type is unconstrained procedure Declare_Postconditions_Result; -- When generating C code, declare _Result, which may be used in the -- inlined _Postconditions procedure to verify the return value. procedure Make_Exit_Label; -- Build declaration for exit label to be used in Return statements, -- sets Exit_Lab (the label node) and Lab_Decl (corresponding implicit -- declaration). Does nothing if Exit_Lab already set. procedure Make_Loop_Labels_Unique (HSS : Node_Id); -- When compiling for CCG and performing front-end inlining, replace -- loop names and references to them so that they do not conflict with -- homographs in the current subprogram. function Process_Formals (N : Node_Id) return Traverse_Result; -- Replace occurrence of a formal with the corresponding actual, or the -- thunk generated for it. Replace a return statement with an assignment -- to the target of the call, with appropriate conversions if needed. function Process_Formals_In_Aspects (N : Node_Id) return Traverse_Result; -- Because aspects are linked indirectly to the rest of the tree, -- replacement of formals appearing in aspect specifications must -- be performed in a separate pass, using an instantiation of the -- previous subprogram over aspect specifications reachable from N. function Process_Sloc (Nod : Node_Id) return Traverse_Result; -- If the call being expanded is that of an internal subprogram, set the -- sloc of the generated block to that of the call itself, so that the -- expansion is skipped by the "next" command in gdb. Same processing -- for a subprogram in a predefined file, e.g. Ada.Tags. If -- Debug_Generated_Code is true, suppress this change to simplify our -- own development. Same in GNATprove mode, to ensure that warnings and -- diagnostics point to the proper location. procedure Reset_Dispatching_Calls (N : Node_Id); -- In subtree N search for occurrences of dispatching calls that use the -- Ada 2005 Object.Operation notation and the object is a formal of the -- inlined subprogram. Reset the entity associated with Operation in all -- the found occurrences. procedure Rewrite_Function_Call (N : Node_Id; Blk : Node_Id); -- If the function body is a single expression, replace call with -- expression, else insert block appropriately. procedure Rewrite_Procedure_Call (N : Node_Id; Blk : Node_Id); -- If procedure body has no local variables, inline body without -- creating block, otherwise rewrite call with block. ----------------------------------- -- Declare_Postconditions_Result -- ----------------------------------- procedure Declare_Postconditions_Result is Enclosing_Subp : constant Entity_Id := Scope (Subp); begin pragma Assert (Modify_Tree_For_C and then Is_Subprogram (Enclosing_Subp) and then Present (Postconditions_Proc (Enclosing_Subp))); if Ekind (Enclosing_Subp) = E_Function then if Nkind (First (Parameter_Associations (N))) in N_Numeric_Or_String_Literal then Append_To (Declarations (Blk), Make_Object_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uResult), Constant_Present => True, Object_Definition => New_Occurrence_Of (Etype (Enclosing_Subp), Loc), Expression => New_Copy_Tree (First (Parameter_Associations (N))))); else Append_To (Declarations (Blk), Make_Object_Renaming_Declaration (Loc, Defining_Identifier => Make_Defining_Identifier (Loc, Name_uResult), Subtype_Mark => New_Occurrence_Of (Etype (Enclosing_Subp), Loc), Name => New_Copy_Tree (First (Parameter_Associations (N))))); end if; end if; end Declare_Postconditions_Result; --------------------- -- Make_Exit_Label -- --------------------- procedure Make_Exit_Label is Lab_Ent : Entity_Id; begin if No (Exit_Lab) then Lab_Ent := Make_Temporary (Loc, 'L'); Lab_Id := New_Occurrence_Of (Lab_Ent, Loc); Exit_Lab := Make_Label (Loc, Lab_Id); Lab_Decl := Make_Implicit_Label_Declaration (Loc, Defining_Identifier => Lab_Ent, Label_Construct => Exit_Lab); end if; end Make_Exit_Label; ----------------------------- -- Make_Loop_Labels_Unique -- ----------------------------- procedure Make_Loop_Labels_Unique (HSS : Node_Id) is function Process_Loop (N : Node_Id) return Traverse_Result; ------------------ -- Process_Loop -- ------------------ function Process_Loop (N : Node_Id) return Traverse_Result is Id : Entity_Id; begin if Nkind (N) = N_Loop_Statement and then Present (Identifier (N)) then -- Create new external name for loop and update the -- corresponding entity. Id := Entity (Identifier (N)); Set_Chars (Id, New_External_Name (Chars (Id), 'L', -1)); Set_Chars (Identifier (N), Chars (Id)); elsif Nkind (N) = N_Exit_Statement and then Present (Name (N)) then -- The exit statement must name an enclosing loop, whose name -- has already been updated. Set_Chars (Name (N), Chars (Entity (Name (N)))); end if; return OK; end Process_Loop; procedure Update_Loop_Names is new Traverse_Proc (Process_Loop); -- Local variables Stmt : Node_Id; -- Start of processing for Make_Loop_Labels_Unique begin if Modify_Tree_For_C then Stmt := First (Statements (HSS)); while Present (Stmt) loop Update_Loop_Names (Stmt); Next (Stmt); end loop; end if; end Make_Loop_Labels_Unique; --------------------- -- Process_Formals -- --------------------- function Process_Formals (N : Node_Id) return Traverse_Result is A : Entity_Id; E : Entity_Id; Ret : Node_Id; begin if Is_Entity_Name (N) and then Present (Entity (N)) then E := Entity (N); if Is_Formal (E) and then Scope (E) = Subp then A := Renamed_Object (E); -- Rewrite the occurrence of the formal into an occurrence of -- the actual. Also establish visibility on the proper view of -- the actual's subtype for the body's context (if the actual's -- subtype is private at the call point but its full view is -- visible to the body, then the inlined tree here must be -- analyzed with the full view). if Is_Entity_Name (A) then Rewrite (N, New_Occurrence_Of (Entity (A), Sloc (N))); Check_Private_View (N); elsif Nkind (A) = N_Defining_Identifier then Rewrite (N, New_Occurrence_Of (A, Sloc (N))); Check_Private_View (N); -- Numeric literal else Rewrite (N, New_Copy (A)); end if; end if; return Skip; elsif Is_Entity_Name (N) and then Present (Return_Object) and then Chars (N) = Chars (Return_Object) then -- Occurrence within an extended return statement. The return -- object is local to the body been inlined, and thus the generic -- copy is not analyzed yet, so we match by name, and replace it -- with target of call. if Nkind (Targ) = N_Defining_Identifier then Rewrite (N, New_Occurrence_Of (Targ, Loc)); else Rewrite (N, New_Copy_Tree (Targ)); end if; return Skip; elsif Nkind (N) = N_Simple_Return_Statement then if No (Expression (N)) then Num_Ret := Num_Ret + 1; Make_Exit_Label; Rewrite (N, Make_Goto_Statement (Loc, Name => New_Copy (Lab_Id))); else if Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements and then Nkind (Parent (Parent (N))) = N_Subprogram_Body then -- Function body is a single expression. No need for -- exit label. null; else Num_Ret := Num_Ret + 1; Make_Exit_Label; end if; -- Because of the presence of private types, the views of the -- expression and the context may be different, so place -- a type conversion to the context type to avoid spurious -- errors, e.g. when the expression is a numeric literal and -- the context is private. If the expression is an aggregate, -- use a qualified expression, because an aggregate is not a -- legal argument of a conversion. Ditto for numeric, character -- and string literals, and attributes that yield a universal -- type, because those must be resolved to a specific type. if Nkind (Expression (N)) in N_Aggregate | N_Character_Literal | N_Null | N_String_Literal or else Yields_Universal_Type (Expression (N)) then Ret := Make_Qualified_Expression (Sloc (N), Subtype_Mark => New_Occurrence_Of (Ret_Type, Sloc (N)), Expression => Relocate_Node (Expression (N))); -- Use an unchecked type conversion between access types, for -- which a type conversion would not always be valid, as no -- check may result from the conversion. elsif Is_Access_Type (Ret_Type) then Ret := Unchecked_Convert_To (Ret_Type, Relocate_Node (Expression (N))); -- Otherwise use a type conversion, which may trigger a check else Ret := Make_Type_Conversion (Sloc (N), Subtype_Mark => New_Occurrence_Of (Ret_Type, Sloc (N)), Expression => Relocate_Node (Expression (N))); end if; if Nkind (Targ) = N_Defining_Identifier then Rewrite (N, Make_Assignment_Statement (Loc, Name => New_Occurrence_Of (Targ, Loc), Expression => Ret)); else Rewrite (N, Make_Assignment_Statement (Loc, Name => New_Copy (Targ), Expression => Ret)); end if; Set_Assignment_OK (Name (N)); if Present (Exit_Lab) then Insert_After (N, Make_Goto_Statement (Loc, Name => New_Copy (Lab_Id))); end if; end if; return OK; -- An extended return becomes a block whose first statement is the -- assignment of the initial expression of the return object to the -- target of the call itself. elsif Nkind (N) = N_Extended_Return_Statement then declare Return_Decl : constant Entity_Id := First (Return_Object_Declarations (N)); Assign : Node_Id; begin Return_Object := Defining_Identifier (Return_Decl); if Present (Expression (Return_Decl)) then if Nkind (Targ) = N_Defining_Identifier then Assign := Make_Assignment_Statement (Loc, Name => New_Occurrence_Of (Targ, Loc), Expression => Expression (Return_Decl)); else Assign := Make_Assignment_Statement (Loc, Name => New_Copy (Targ), Expression => Expression (Return_Decl)); end if; Set_Assignment_OK (Name (Assign)); if No (Handled_Statement_Sequence (N)) then Set_Handled_Statement_Sequence (N, Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List)); end if; Prepend (Assign, Statements (Handled_Statement_Sequence (N))); end if; Rewrite (N, Make_Block_Statement (Loc, Handled_Statement_Sequence => Handled_Statement_Sequence (N))); return OK; end; -- Remove pragma Unreferenced since it may refer to formals that -- are not visible in the inlined body, and in any case we will -- not be posting warnings on the inlined body so it is unneeded. elsif Nkind (N) = N_Pragma and then Pragma_Name (N) = Name_Unreferenced then Rewrite (N, Make_Null_Statement (Sloc (N))); return OK; else return OK; end if; end Process_Formals; procedure Replace_Formals is new Traverse_Proc (Process_Formals); -------------------------------- -- Process_Formals_In_Aspects -- -------------------------------- function Process_Formals_In_Aspects (N : Node_Id) return Traverse_Result is A : Node_Id; begin if Has_Aspects (N) then A := First (Aspect_Specifications (N)); while Present (A) loop Replace_Formals (Expression (A)); Next (A); end loop; end if; return OK; end Process_Formals_In_Aspects; procedure Replace_Formals_In_Aspects is new Traverse_Proc (Process_Formals_In_Aspects); ------------------ -- Process_Sloc -- ------------------ function Process_Sloc (Nod : Node_Id) return Traverse_Result is begin if not Debug_Generated_Code then Set_Sloc (Nod, Sloc (N)); Set_Comes_From_Source (Nod, False); end if; return OK; end Process_Sloc; procedure Reset_Slocs is new Traverse_Proc (Process_Sloc); ------------------------------ -- Reset_Dispatching_Calls -- ------------------------------ procedure Reset_Dispatching_Calls (N : Node_Id) is function Do_Reset (N : Node_Id) return Traverse_Result; -- Comment required ??? -------------- -- Do_Reset -- -------------- function Do_Reset (N : Node_Id) return Traverse_Result is begin if Nkind (N) = N_Procedure_Call_Statement and then Nkind (Name (N)) = N_Selected_Component and then Nkind (Prefix (Name (N))) = N_Identifier and then Is_Formal (Entity (Prefix (Name (N)))) and then Is_Dispatching_Operation (Entity (Selector_Name (Name (N)))) then Set_Entity (Selector_Name (Name (N)), Empty); end if; return OK; end Do_Reset; function Do_Reset_Calls is new Traverse_Func (Do_Reset); -- Local variables Dummy : constant Traverse_Result := Do_Reset_Calls (N); pragma Unreferenced (Dummy); -- Start of processing for Reset_Dispatching_Calls begin null; end Reset_Dispatching_Calls; --------------------------- -- Rewrite_Function_Call -- --------------------------- procedure Rewrite_Function_Call (N : Node_Id; Blk : Node_Id) is HSS : constant Node_Id := Handled_Statement_Sequence (Blk); Fst : constant Node_Id := First (Statements (HSS)); begin Make_Loop_Labels_Unique (HSS); -- Optimize simple case: function body is a single return statement, -- which has been expanded into an assignment. if Is_Empty_List (Declarations (Blk)) and then Nkind (Fst) = N_Assignment_Statement and then No (Next (Fst)) then -- The function call may have been rewritten as the temporary -- that holds the result of the call, in which case remove the -- now useless declaration. if Nkind (N) = N_Identifier and then Nkind (Parent (Entity (N))) = N_Object_Declaration then Rewrite (Parent (Entity (N)), Make_Null_Statement (Loc)); end if; Rewrite (N, Expression (Fst)); elsif Nkind (N) = N_Identifier and then Nkind (Parent (Entity (N))) = N_Object_Declaration then -- The block assigns the result of the call to the temporary Insert_After (Parent (Entity (N)), Blk); -- If the context is an assignment, and the left-hand side is free of -- side-effects, the replacement is also safe. -- Can this be generalized further??? elsif Nkind (Parent (N)) = N_Assignment_Statement and then (Is_Entity_Name (Name (Parent (N))) or else (Nkind (Name (Parent (N))) = N_Explicit_Dereference and then Is_Entity_Name (Prefix (Name (Parent (N))))) or else (Nkind (Name (Parent (N))) = N_Selected_Component and then Is_Entity_Name (Prefix (Name (Parent (N)))))) then -- Replace assignment with the block declare Original_Assignment : constant Node_Id := Parent (N); begin -- Preserve the original assignment node to keep the complete -- assignment subtree consistent enough for Analyze_Assignment -- to proceed (specifically, the original Lhs node must still -- have an assignment statement as its parent). -- We cannot rely on Original_Node to go back from the block -- node to the assignment node, because the assignment might -- already be a rewrite substitution. Discard_Node (Relocate_Node (Original_Assignment)); Rewrite (Original_Assignment, Blk); end; elsif Nkind (Parent (N)) = N_Object_Declaration then -- A call to a function which returns an unconstrained type -- found in the expression initializing an object-declaration is -- expanded into a procedure call which must be added after the -- object declaration. if Is_Unc_Decl and Back_End_Inlining then Insert_Action_After (Parent (N), Blk); else Set_Expression (Parent (N), Empty); Insert_After (Parent (N), Blk); end if; elsif Is_Unc and then not Back_End_Inlining then Insert_Before (Parent (N), Blk); end if; end Rewrite_Function_Call; ---------------------------- -- Rewrite_Procedure_Call -- ---------------------------- procedure Rewrite_Procedure_Call (N : Node_Id; Blk : Node_Id) is HSS : constant Node_Id := Handled_Statement_Sequence (Blk); begin Make_Loop_Labels_Unique (HSS); -- If there is a transient scope for N, this will be the scope of the -- actions for N, and the statements in Blk need to be within this -- scope. For example, they need to have visibility on the constant -- declarations created for the formals. -- If N needs no transient scope, and if there are no declarations in -- the inlined body, we can do a little optimization and insert the -- statements for the body directly after N, and rewrite N to a -- null statement, instead of rewriting N into a full-blown block -- statement. if not Scope_Is_Transient and then Is_Empty_List (Declarations (Blk)) then Insert_List_After (N, Statements (HSS)); Rewrite (N, Make_Null_Statement (Loc)); else Rewrite (N, Blk); end if; end Rewrite_Procedure_Call; -- Start of processing for Expand_Inlined_Call begin -- Initializations for old/new semantics if not Uses_Back_End then Is_Unc := Is_Array_Type (Etype (Subp)) and then not Is_Constrained (Etype (Subp)); Is_Unc_Decl := False; else Is_Unc := Returns_Unconstrained_Type (Subp) and then Optimization_Level > 0; Is_Unc_Decl := Nkind (Parent (N)) = N_Object_Declaration and then Is_Unc; end if; -- Check for an illegal attempt to inline a recursive procedure. If the -- subprogram has parameters this is detected when trying to supply a -- binding for parameters that already have one. For parameterless -- subprograms this must be done explicitly. if In_Open_Scopes (Subp) then Cannot_Inline ("cannot inline call to recursive subprogram?", N, Subp); Set_Is_Inlined (Subp, False); return; -- Skip inlining if this is not a true inlining since the attribute -- Body_To_Inline is also set for renamings (see sinfo.ads). For a -- true inlining, Orig_Bod has code rather than being an entity. elsif Nkind (Orig_Bod) in N_Entity then return; end if; if Nkind (Orig_Bod) in N_Defining_Identifier | N_Defining_Operator_Symbol then -- Subprogram is renaming_as_body. Calls occurring after the renaming -- can be replaced with calls to the renamed entity directly, because -- the subprograms are subtype conformant. If the renamed subprogram -- is an inherited operation, we must redo the expansion because -- implicit conversions may be needed. Similarly, if the renamed -- entity is inlined, expand the call for further optimizations. Set_Name (N, New_Occurrence_Of (Orig_Bod, Loc)); if Present (Alias (Orig_Bod)) or else Is_Inlined (Orig_Bod) then Expand_Call (N); end if; return; end if; -- Register the call in the list of inlined calls Append_New_Elmt (N, To => Inlined_Calls); -- Use generic machinery to copy body of inlined subprogram, as if it -- were an instantiation, resetting source locations appropriately, so -- that nested inlined calls appear in the main unit. Save_Env (Subp, Empty); Set_Copied_Sloc_For_Inlined_Body (N, Defining_Entity (Orig_Bod)); -- Old semantics if not Uses_Back_End then declare Bod : Node_Id; begin Bod := Copy_Generic_Node (Orig_Bod, Empty, Instantiating => True); Blk := Make_Block_Statement (Loc, Declarations => Declarations (Bod), Handled_Statement_Sequence => Handled_Statement_Sequence (Bod)); if No (Declarations (Bod)) then Set_Declarations (Blk, New_List); end if; -- When generating C code, declare _Result, which may be used to -- verify the return value. if Modify_Tree_For_C and then Nkind (N) = N_Procedure_Call_Statement and then Chars (Name (N)) = Name_uPostconditions then Declare_Postconditions_Result; end if; -- For the unconstrained case, capture the name of the local -- variable that holds the result. This must be the first -- declaration in the block, because its bounds cannot depend -- on local variables. Otherwise there is no way to declare the -- result outside of the block. Needless to say, in general the -- bounds will depend on the actuals in the call. -- If the context is an assignment statement, as is the case -- for the expansion of an extended return, the left-hand side -- provides bounds even if the return type is unconstrained. if Is_Unc then declare First_Decl : Node_Id; begin First_Decl := First (Declarations (Blk)); -- If the body is a single extended return statement,the -- resulting block is a nested block. if No (First_Decl) then First_Decl := First (Statements (Handled_Statement_Sequence (Blk))); if Nkind (First_Decl) = N_Block_Statement then First_Decl := First (Declarations (First_Decl)); end if; end if; -- No front-end inlining possible if Nkind (First_Decl) /= N_Object_Declaration then return; end if; if Nkind (Parent (N)) /= N_Assignment_Statement then Targ1 := Defining_Identifier (First_Decl); else Targ1 := Name (Parent (N)); end if; end; end if; end; -- New semantics else declare Bod : Node_Id; begin -- General case if not Is_Unc then Bod := Copy_Generic_Node (Orig_Bod, Empty, Instantiating => True); Blk := Make_Block_Statement (Loc, Declarations => Declarations (Bod), Handled_Statement_Sequence => Handled_Statement_Sequence (Bod)); -- Inline a call to a function that returns an unconstrained type. -- The semantic analyzer checked that frontend-inlined functions -- returning unconstrained types have no declarations and have -- a single extended return statement. As part of its processing -- the function was split into two subprograms: a procedure P' and -- a function F' that has a block with a call to procedure P' (see -- Split_Unconstrained_Function). else pragma Assert (Nkind (First (Statements (Handled_Statement_Sequence (Orig_Bod)))) = N_Block_Statement); declare Blk_Stmt : constant Node_Id := First (Statements (Handled_Statement_Sequence (Orig_Bod))); First_Stmt : constant Node_Id := First (Statements (Handled_Statement_Sequence (Blk_Stmt))); Second_Stmt : constant Node_Id := Next (First_Stmt); begin pragma Assert (Nkind (First_Stmt) = N_Procedure_Call_Statement and then Nkind (Second_Stmt) = N_Simple_Return_Statement and then No (Next (Second_Stmt))); Bod := Copy_Generic_Node (First (Statements (Handled_Statement_Sequence (Orig_Bod))), Empty, Instantiating => True); Blk := Bod; -- Capture the name of the local variable that holds the -- result. This must be the first declaration in the block, -- because its bounds cannot depend on local variables. -- Otherwise there is no way to declare the result outside -- of the block. Needless to say, in general the bounds will -- depend on the actuals in the call. if Nkind (Parent (N)) /= N_Assignment_Statement then Targ1 := Defining_Identifier (First (Declarations (Blk))); -- If the context is an assignment statement, as is the case -- for the expansion of an extended return, the left-hand -- side provides bounds even if the return type is -- unconstrained. else Targ1 := Name (Parent (N)); end if; end; end if; if No (Declarations (Bod)) then Set_Declarations (Blk, New_List); end if; end; end if; -- If this is a derived function, establish the proper return type if Present (Orig_Subp) and then Orig_Subp /= Subp then Ret_Type := Etype (Orig_Subp); else Ret_Type := Etype (Subp); end if; -- Create temporaries for the actuals that are expressions, or that are -- scalars and require copying to preserve semantics. Establish_Actual_Mapping_For_Inlined_Call (N, Subp, Decls, Orig_Bod); -- Establish target of function call. If context is not assignment or -- declaration, create a temporary as a target. The declaration for the -- temporary may be subsequently optimized away if the body is a single -- expression, or if the left-hand side of the assignment is simple -- enough, i.e. an entity or an explicit dereference of one. if Ekind (Subp) = E_Function then if Nkind (Parent (N)) = N_Assignment_Statement and then Is_Entity_Name (Name (Parent (N))) then Targ := Name (Parent (N)); elsif Nkind (Parent (N)) = N_Assignment_Statement and then Nkind (Name (Parent (N))) = N_Explicit_Dereference and then Is_Entity_Name (Prefix (Name (Parent (N)))) then Targ := Name (Parent (N)); elsif Nkind (Parent (N)) = N_Assignment_Statement and then Nkind (Name (Parent (N))) = N_Selected_Component and then Is_Entity_Name (Prefix (Name (Parent (N)))) then Targ := New_Copy_Tree (Name (Parent (N))); elsif Nkind (Parent (N)) = N_Object_Declaration and then Is_Limited_Type (Etype (Subp)) then Targ := Defining_Identifier (Parent (N)); -- New semantics: In an object declaration avoid an extra copy -- of the result of a call to an inlined function that returns -- an unconstrained type elsif Uses_Back_End and then Nkind (Parent (N)) = N_Object_Declaration and then Is_Unc then Targ := Defining_Identifier (Parent (N)); else -- Replace call with temporary and create its declaration Temp := Make_Temporary (Loc, 'C'); Set_Is_Internal (Temp); -- For the unconstrained case, the generated temporary has the -- same constrained declaration as the result variable. It may -- eventually be possible to remove that temporary and use the -- result variable directly. if Is_Unc and then Nkind (Parent (N)) /= N_Assignment_Statement then Decl := Make_Object_Declaration (Loc, Defining_Identifier => Temp, Object_Definition => New_Copy_Tree (Object_Definition (Parent (Targ1)))); Replace_Formals (Decl); else Decl := Make_Object_Declaration (Loc, Defining_Identifier => Temp, Object_Definition => New_Occurrence_Of (Ret_Type, Loc)); Set_Etype (Temp, Ret_Type); end if; Set_No_Initialization (Decl); Append (Decl, Decls); Rewrite (N, New_Occurrence_Of (Temp, Loc)); Targ := Temp; end if; end if; Insert_Actions (N, Decls); if Is_Unc_Decl then -- Special management for inlining a call to a function that returns -- an unconstrained type and initializes an object declaration: we -- avoid generating undesired extra calls and goto statements. -- Given: -- function Func (...) return String is -- begin -- declare -- Result : String (1 .. 4); -- begin -- Proc (Result, ...); -- return Result; -- end; -- end Func; -- Result : String := Func (...); -- Replace this object declaration by: -- Result : String (1 .. 4); -- Proc (Result, ...); Remove_Homonym (Targ); Decl := Make_Object_Declaration (Loc, Defining_Identifier => Targ, Object_Definition => New_Copy_Tree (Object_Definition (Parent (Targ1)))); Replace_Formals (Decl); Rewrite (Parent (N), Decl); Analyze (Parent (N)); -- Avoid spurious warnings since we know that this declaration is -- referenced by the procedure call. Set_Never_Set_In_Source (Targ, False); -- Remove the local declaration of the extended return stmt from the -- inlined code Remove (Parent (Targ1)); -- Update the reference to the result (since we have rewriten the -- object declaration) declare Blk_Call_Stmt : Node_Id; begin -- Capture the call to the procedure Blk_Call_Stmt := First (Statements (Handled_Statement_Sequence (Blk))); pragma Assert (Nkind (Blk_Call_Stmt) = N_Procedure_Call_Statement); Remove (First (Parameter_Associations (Blk_Call_Stmt))); Prepend_To (Parameter_Associations (Blk_Call_Stmt), New_Occurrence_Of (Targ, Loc)); end; -- Remove the return statement pragma Assert (Nkind (Last (Statements (Handled_Statement_Sequence (Blk)))) = N_Simple_Return_Statement); Remove (Last (Statements (Handled_Statement_Sequence (Blk)))); end if; -- Traverse the tree and replace formals with actuals or their thunks. -- Attach block to tree before analysis and rewriting. Replace_Formals (Blk); Replace_Formals_In_Aspects (Blk); Set_Parent (Blk, N); if GNATprove_Mode then null; elsif not Comes_From_Source (Subp) or else Is_Predef then Reset_Slocs (Blk); end if; if Is_Unc_Decl then -- No action needed since return statement has been already removed null; elsif Present (Exit_Lab) then -- If there's a single return statement at the end of the subprogram, -- the corresponding goto statement and the corresponding label are -- useless. if Num_Ret = 1 and then Nkind (Last (Statements (Handled_Statement_Sequence (Blk)))) = N_Goto_Statement then Remove (Last (Statements (Handled_Statement_Sequence (Blk)))); else Append (Lab_Decl, (Declarations (Blk))); Append (Exit_Lab, Statements (Handled_Statement_Sequence (Blk))); end if; end if; -- Analyze Blk with In_Inlined_Body set, to avoid spurious errors -- on conflicting private views that Gigi would ignore. If this is a -- predefined unit, analyze with checks off, as is done in the non- -- inlined run-time units. declare I_Flag : constant Boolean := In_Inlined_Body; begin In_Inlined_Body := True; if Is_Predef then declare Style : constant Boolean := Style_Check; begin Style_Check := False; -- Search for dispatching calls that use the Object.Operation -- notation using an Object that is a parameter of the inlined -- function. We reset the decoration of Operation to force -- the reanalysis of the inlined dispatching call because -- the actual object has been inlined. Reset_Dispatching_Calls (Blk); -- In GNATprove mode, always consider checks on, even for -- predefined units. if GNATprove_Mode then Analyze (Blk); else Analyze (Blk, Suppress => All_Checks); end if; Style_Check := Style; end; else Analyze (Blk); end if; In_Inlined_Body := I_Flag; end; if Ekind (Subp) = E_Procedure then Rewrite_Procedure_Call (N, Blk); else Rewrite_Function_Call (N, Blk); if Is_Unc_Decl then null; -- For the unconstrained case, the replacement of the call has been -- made prior to the complete analysis of the generated declarations. -- Propagate the proper type now. elsif Is_Unc then if Nkind (N) = N_Identifier then Set_Etype (N, Etype (Entity (N))); else Set_Etype (N, Etype (Targ1)); end if; end if; end if; Restore_Env; -- Cleanup mapping between formals and actuals for other expansions Reset_Actual_Mapping_For_Inlined_Call (Subp); end Expand_Inlined_Call; -------------------------- -- Get_Code_Unit_Entity -- -------------------------- function Get_Code_Unit_Entity (E : Entity_Id) return Entity_Id is Unit : Entity_Id := Cunit_Entity (Get_Code_Unit (E)); begin if Ekind (Unit) = E_Package_Body then Unit := Spec_Entity (Unit); end if; return Unit; end Get_Code_Unit_Entity; ------------------------------ -- Has_Excluded_Declaration -- ------------------------------ function Has_Excluded_Declaration (Subp : Entity_Id; Decls : List_Id) return Boolean is D : Node_Id; function Is_Unchecked_Conversion (D : Node_Id) return Boolean; -- Nested subprograms make a given body ineligible for inlining, but -- we make an exception for instantiations of unchecked conversion. -- The body has not been analyzed yet, so check the name, and verify -- that the visible entity with that name is the predefined unit. ----------------------------- -- Is_Unchecked_Conversion -- ----------------------------- function Is_Unchecked_Conversion (D : Node_Id) return Boolean is Id : constant Node_Id := Name (D); Conv : Entity_Id; begin if Nkind (Id) = N_Identifier and then Chars (Id) = Name_Unchecked_Conversion then Conv := Current_Entity (Id); elsif Nkind (Id) in N_Selected_Component | N_Expanded_Name and then Chars (Selector_Name (Id)) = Name_Unchecked_Conversion then Conv := Current_Entity (Selector_Name (Id)); else return False; end if; return Present (Conv) and then Is_Predefined_Unit (Get_Source_Unit (Conv)) and then Is_Intrinsic_Subprogram (Conv); end Is_Unchecked_Conversion; -- Start of processing for Has_Excluded_Declaration begin -- No action needed if the check is not needed if not Check_Inlining_Restrictions then return False; end if; D := First (Decls); while Present (D) loop -- First declarations universally excluded if Nkind (D) = N_Package_Declaration then Cannot_Inline ("cannot inline & (nested package declaration)?", D, Subp); return True; elsif Nkind (D) = N_Package_Instantiation then Cannot_Inline ("cannot inline & (nested package instantiation)?", D, Subp); return True; end if; -- Then declarations excluded only for front-end inlining if Back_End_Inlining then null; elsif Nkind (D) = N_Task_Type_Declaration or else Nkind (D) = N_Single_Task_Declaration then Cannot_Inline ("cannot inline & (nested task type declaration)?", D, Subp); return True; elsif Nkind (D) = N_Protected_Type_Declaration or else Nkind (D) = N_Single_Protected_Declaration then Cannot_Inline ("cannot inline & (nested protected type declaration)?", D, Subp); return True; elsif Nkind (D) = N_Subprogram_Body then Cannot_Inline ("cannot inline & (nested subprogram)?", D, Subp); return True; elsif Nkind (D) = N_Function_Instantiation and then not Is_Unchecked_Conversion (D) then Cannot_Inline ("cannot inline & (nested function instantiation)?", D, Subp); return True; elsif Nkind (D) = N_Procedure_Instantiation then Cannot_Inline ("cannot inline & (nested procedure instantiation)?", D, Subp); return True; -- Subtype declarations with predicates will generate predicate -- functions, i.e. nested subprogram bodies, so inlining is not -- possible. elsif Nkind (D) = N_Subtype_Declaration and then Present (Aspect_Specifications (D)) then declare A : Node_Id; A_Id : Aspect_Id; begin A := First (Aspect_Specifications (D)); while Present (A) loop A_Id := Get_Aspect_Id (Chars (Identifier (A))); if A_Id = Aspect_Predicate or else A_Id = Aspect_Static_Predicate or else A_Id = Aspect_Dynamic_Predicate then Cannot_Inline ("cannot inline & (subtype declaration with " & "predicate)?", D, Subp); return True; end if; Next (A); end loop; end; end if; Next (D); end loop; return False; end Has_Excluded_Declaration; ---------------------------- -- Has_Excluded_Statement -- ---------------------------- function Has_Excluded_Statement (Subp : Entity_Id; Stats : List_Id) return Boolean is S : Node_Id; E : Node_Id; begin -- No action needed if the check is not needed if not Check_Inlining_Restrictions then return False; end if; S := First (Stats); while Present (S) loop if Nkind (S) in N_Abort_Statement | N_Asynchronous_Select | N_Conditional_Entry_Call | N_Delay_Relative_Statement | N_Delay_Until_Statement | N_Selective_Accept | N_Timed_Entry_Call then Cannot_Inline ("cannot inline & (non-allowed statement)?", S, Subp); return True; elsif Nkind (S) = N_Block_Statement then if Present (Declarations (S)) and then Has_Excluded_Declaration (Subp, Declarations (S)) then return True; elsif Present (Handled_Statement_Sequence (S)) then if not Back_End_Inlining and then Present (Exception_Handlers (Handled_Statement_Sequence (S))) then Cannot_Inline ("cannot inline& (exception handler)?", First (Exception_Handlers (Handled_Statement_Sequence (S))), Subp); return True; elsif Has_Excluded_Statement (Subp, Statements (Handled_Statement_Sequence (S))) then return True; end if; end if; elsif Nkind (S) = N_Case_Statement then E := First (Alternatives (S)); while Present (E) loop if Has_Excluded_Statement (Subp, Statements (E)) then return True; end if; Next (E); end loop; elsif Nkind (S) = N_If_Statement then if Has_Excluded_Statement (Subp, Then_Statements (S)) then return True; end if; if Present (Elsif_Parts (S)) then E := First (Elsif_Parts (S)); while Present (E) loop if Has_Excluded_Statement (Subp, Then_Statements (E)) then return True; end if; Next (E); end loop; end if; if Present (Else_Statements (S)) and then Has_Excluded_Statement (Subp, Else_Statements (S)) then return True; end if; elsif Nkind (S) = N_Loop_Statement and then Has_Excluded_Statement (Subp, Statements (S)) then return True; elsif Nkind (S) = N_Extended_Return_Statement then if Present (Handled_Statement_Sequence (S)) and then Has_Excluded_Statement (Subp, Statements (Handled_Statement_Sequence (S))) then return True; elsif not Back_End_Inlining and then Present (Handled_Statement_Sequence (S)) and then Present (Exception_Handlers (Handled_Statement_Sequence (S))) then Cannot_Inline ("cannot inline& (exception handler)?", First (Exception_Handlers (Handled_Statement_Sequence (S))), Subp); return True; end if; end if; Next (S); end loop; return False; end Has_Excluded_Statement; -------------------------- -- Has_Initialized_Type -- -------------------------- function Has_Initialized_Type (E : Entity_Id) return Boolean is E_Body : constant Node_Id := Subprogram_Body (E); Decl : Node_Id; begin if No (E_Body) then -- imported subprogram return False; else Decl := First (Declarations (E_Body)); while Present (Decl) loop if Nkind (Decl) = N_Full_Type_Declaration and then Present (Init_Proc (Defining_Identifier (Decl))) then return True; end if; Next (Decl); end loop; end if; return False; end Has_Initialized_Type; ----------------------- -- Has_Single_Return -- ----------------------- function Has_Single_Return (N : Node_Id) return Boolean is Return_Statement : Node_Id := Empty; function Check_Return (N : Node_Id) return Traverse_Result; ------------------ -- Check_Return -- ------------------ function Check_Return (N : Node_Id) return Traverse_Result is begin if Nkind (N) = N_Simple_Return_Statement then if Present (Expression (N)) and then Is_Entity_Name (Expression (N)) then pragma Assert (Present (Entity (Expression (N)))); if No (Return_Statement) then Return_Statement := N; return OK; else pragma Assert (Present (Entity (Expression (Return_Statement)))); if Entity (Expression (N)) = Entity (Expression (Return_Statement)) then return OK; else return Abandon; end if; end if; -- A return statement within an extended return is a noop after -- inlining. elsif No (Expression (N)) and then Nkind (Parent (Parent (N))) = N_Extended_Return_Statement then return OK; else -- Expression has wrong form return Abandon; end if; -- We can only inline a build-in-place function if it has a single -- extended return. elsif Nkind (N) = N_Extended_Return_Statement then if No (Return_Statement) then Return_Statement := N; return OK; else return Abandon; end if; else return OK; end if; end Check_Return; function Check_All_Returns is new Traverse_Func (Check_Return); -- Start of processing for Has_Single_Return begin if Check_All_Returns (N) /= OK then return False; elsif Nkind (Return_Statement) = N_Extended_Return_Statement then return True; else return Present (Declarations (N)) and then Present (First (Declarations (N))) and then Entity (Expression (Return_Statement)) = Defining_Identifier (First (Declarations (N))); end if; end Has_Single_Return; ----------------------------- -- In_Main_Unit_Or_Subunit -- ----------------------------- function In_Main_Unit_Or_Subunit (E : Entity_Id) return Boolean is Comp : Node_Id := Cunit (Get_Code_Unit (E)); begin -- Check whether the subprogram or package to inline is within the main -- unit or its spec or within a subunit. In either case there are no -- additional bodies to process. If the subprogram appears in a parent -- of the current unit, the check on whether inlining is possible is -- done in Analyze_Inlined_Bodies. while Nkind (Unit (Comp)) = N_Subunit loop Comp := Library_Unit (Comp); end loop; return Comp = Cunit (Main_Unit) or else Comp = Library_Unit (Cunit (Main_Unit)); end In_Main_Unit_Or_Subunit; ---------------- -- Initialize -- ---------------- procedure Initialize is begin Pending_Instantiations.Init; Called_Pending_Instantiations.Init; Inlined_Bodies.Init; Successors.Init; Inlined.Init; for J in Hash_Headers'Range loop Hash_Headers (J) := No_Subp; end loop; Inlined_Calls := No_Elist; Backend_Calls := No_Elist; Backend_Instances := No_Elist; Backend_Inlined_Subps := No_Elist; Backend_Not_Inlined_Subps := No_Elist; end Initialize; --------------------------------- -- Inline_Static_Function_Call -- --------------------------------- procedure Inline_Static_Function_Call (N : Node_Id; Subp : Entity_Id) is function Replace_Formal (N : Node_Id) return Traverse_Result; -- Replace each occurrence of a formal with the corresponding actual, -- using the mapping created by Establish_Mapping_For_Inlined_Call. function Reset_Sloc (Nod : Node_Id) return Traverse_Result; -- Reset the Sloc of a node to that of the call itself, so that errors -- will be flagged on the call to the static expression function itself -- rather than on the expression of the function's declaration. -------------------- -- Replace_Formal -- -------------------- function Replace_Formal (N : Node_Id) return Traverse_Result is A : Entity_Id; E : Entity_Id; begin if Is_Entity_Name (N) and then Present (Entity (N)) then E := Entity (N); if Is_Formal (E) and then Scope (E) = Subp then A := Renamed_Object (E); if Nkind (A) = N_Defining_Identifier then Rewrite (N, New_Occurrence_Of (A, Sloc (N))); -- Literal cases else Rewrite (N, New_Copy (A)); end if; end if; return Skip; else return OK; end if; end Replace_Formal; procedure Replace_Formals is new Traverse_Proc (Replace_Formal); ------------------ -- Process_Sloc -- ------------------ function Reset_Sloc (Nod : Node_Id) return Traverse_Result is begin Set_Sloc (Nod, Sloc (N)); Set_Comes_From_Source (Nod, False); return OK; end Reset_Sloc; procedure Reset_Slocs is new Traverse_Proc (Reset_Sloc); -- Start of processing for Inline_Static_Function_Call begin pragma Assert (Is_Static_Function_Call (N)); declare Decls : constant List_Id := New_List; Func_Expr : constant Node_Id := Expression_Of_Expression_Function (Subp); Expr_Copy : constant Node_Id := New_Copy_Tree (Func_Expr); begin -- Create a mapping from formals to actuals, also creating temps in -- Decls, when needed, to hold the actuals. Establish_Actual_Mapping_For_Inlined_Call (N, Subp, Decls, Func_Expr); -- Ensure that the copy has the same parent as the call (this seems -- to matter when GNATprove_Mode is set and there are nested static -- calls; prevents blowups in Insert_Actions, though it's not clear -- exactly why this is needed???). Set_Parent (Expr_Copy, Parent (N)); Insert_Actions (N, Decls); -- Now substitute actuals for their corresponding formal references -- within the expression. Replace_Formals (Expr_Copy); Reset_Slocs (Expr_Copy); -- Apply a qualified expression with the function's result subtype, -- to ensure that we check the expression against any constraint -- or predicate, which will cause the call to be illegal if the -- folded expression doesn't satisfy them. (The predicate case -- might not get checked if the subtype hasn't been frozen yet, -- which can happen if this static expression happens to be what -- causes the freezing, because Has_Static_Predicate doesn't get -- set on the subtype until it's frozen and Build_Predicates is -- called. It's not clear how to address this case. ???) Rewrite (Expr_Copy, Make_Qualified_Expression (Sloc (Expr_Copy), Subtype_Mark => New_Occurrence_Of (Etype (N), Sloc (Expr_Copy)), Expression => Relocate_Node (Expr_Copy))); Set_Etype (Expr_Copy, Etype (N)); Analyze_And_Resolve (Expr_Copy, Etype (N)); -- Finally rewrite the function call as the folded static result Rewrite (N, Expr_Copy); -- Cleanup mapping between formals and actuals for other expansions Reset_Actual_Mapping_For_Inlined_Call (Subp); end; end Inline_Static_Function_Call; ------------------------ -- Instantiate_Bodies -- ------------------------ -- Generic bodies contain all the non-local references, so an -- instantiation does not need any more context than Standard -- itself, even if the instantiation appears in an inner scope. -- Generic associations have verified that the contract model is -- satisfied, so that any error that may occur in the analysis of -- the body is an internal error. procedure Instantiate_Bodies is procedure Instantiate_Body (Info : Pending_Body_Info); -- Instantiate a pending body ------------------------ -- Instantiate_Body -- ------------------------ procedure Instantiate_Body (Info : Pending_Body_Info) is begin -- If the instantiation node is absent, it has been removed as part -- of unreachable code. if No (Info.Inst_Node) then null; -- If the instantiation node is a package body, this means that the -- instance is a compilation unit and the instantiation has already -- been performed by Build_Instance_Compilation_Unit_Nodes. elsif Nkind (Info.Inst_Node) = N_Package_Body then null; elsif Nkind (Info.Act_Decl) = N_Package_Declaration then Instantiate_Package_Body (Info); Add_Scope_To_Clean (Defining_Entity (Info.Act_Decl)); else Instantiate_Subprogram_Body (Info); end if; end Instantiate_Body; J, K : Nat; Info : Pending_Body_Info; -- Start of processing for Instantiate_Bodies begin if Serious_Errors_Detected = 0 then Expander_Active := (Operating_Mode = Opt.Generate_Code); Push_Scope (Standard_Standard); To_Clean := New_Elmt_List; if Is_Generic_Unit (Cunit_Entity (Main_Unit)) then Start_Generic; end if; -- A body instantiation may generate additional instantiations, so -- the following loop must scan to the end of a possibly expanding -- set (that's why we cannot simply use a FOR loop here). We must -- also capture the element lest the set be entirely reallocated. J := 0; if Back_End_Inlining then while J <= Called_Pending_Instantiations.Last and then Serious_Errors_Detected = 0 loop K := Called_Pending_Instantiations.Table (J); Info := Pending_Instantiations.Table (K); Instantiate_Body (Info); J := J + 1; end loop; else while J <= Pending_Instantiations.Last and then Serious_Errors_Detected = 0 loop Info := Pending_Instantiations.Table (J); Instantiate_Body (Info); J := J + 1; end loop; end if; -- Reset the table of instantiations. Additional instantiations -- may be added through inlining, when additional bodies are -- analyzed. if Back_End_Inlining then Called_Pending_Instantiations.Init; else Pending_Instantiations.Init; end if; -- We can now complete the cleanup actions of scopes that contain -- pending instantiations (skipped for generic units, since we -- never need any cleanups in generic units). if Expander_Active and then not Is_Generic_Unit (Main_Unit_Entity) then Cleanup_Scopes; elsif Is_Generic_Unit (Cunit_Entity (Main_Unit)) then End_Generic; end if; Pop_Scope; end if; end Instantiate_Bodies; --------------- -- Is_Nested -- --------------- function Is_Nested (E : Entity_Id) return Boolean is Scop : Entity_Id; begin Scop := Scope (E); while Scop /= Standard_Standard loop if Is_Subprogram (Scop) then return True; elsif Ekind (Scop) = E_Task_Type or else Ekind (Scop) = E_Entry or else Ekind (Scop) = E_Entry_Family then return True; end if; Scop := Scope (Scop); end loop; return False; end Is_Nested; ------------------------ -- List_Inlining_Info -- ------------------------ procedure List_Inlining_Info is Elmt : Elmt_Id; Nod : Node_Id; Count : Nat; begin if not Debug_Flag_Dot_J then return; end if; -- Generate listing of calls inlined by the frontend if Present (Inlined_Calls) then Count := 0; Elmt := First_Elmt (Inlined_Calls); while Present (Elmt) loop Nod := Node (Elmt); if not In_Internal_Unit (Nod) then Count := Count + 1; if Count = 1 then Write_Str ("List of calls inlined by the frontend"); Write_Eol; end if; Write_Str (" "); Write_Int (Count); Write_Str (":"); Write_Location (Sloc (Nod)); Write_Str (":"); Output.Write_Eol; end if; Next_Elmt (Elmt); end loop; end if; -- Generate listing of calls passed to the backend if Present (Backend_Calls) then Count := 0; Elmt := First_Elmt (Backend_Calls); while Present (Elmt) loop Nod := Node (Elmt); if not In_Internal_Unit (Nod) then Count := Count + 1; if Count = 1 then Write_Str ("List of inlined calls passed to the backend"); Write_Eol; end if; Write_Str (" "); Write_Int (Count); Write_Str (":"); Write_Location (Sloc (Nod)); Output.Write_Eol; end if; Next_Elmt (Elmt); end loop; end if; -- Generate listing of instances inlined for the backend if Present (Backend_Instances) then Count := 0; Elmt := First_Elmt (Backend_Instances); while Present (Elmt) loop Nod := Node (Elmt); if not In_Internal_Unit (Nod) then Count := Count + 1; if Count = 1 then Write_Str ("List of instances inlined for the backend"); Write_Eol; end if; Write_Str (" "); Write_Int (Count); Write_Str (":"); Write_Location (Sloc (Nod)); Output.Write_Eol; end if; Next_Elmt (Elmt); end loop; end if; -- Generate listing of subprograms passed to the backend if Present (Backend_Inlined_Subps) and then Back_End_Inlining then Count := 0; Elmt := First_Elmt (Backend_Inlined_Subps); while Present (Elmt) loop Nod := Node (Elmt); if not In_Internal_Unit (Nod) then Count := Count + 1; if Count = 1 then Write_Str ("List of inlined subprograms passed to the backend"); Write_Eol; end if; Write_Str (" "); Write_Int (Count); Write_Str (":"); Write_Name (Chars (Nod)); Write_Str (" ("); Write_Location (Sloc (Nod)); Write_Str (")"); Output.Write_Eol; end if; Next_Elmt (Elmt); end loop; end if; -- Generate listing of subprograms that cannot be inlined by the backend if Present (Backend_Not_Inlined_Subps) and then Back_End_Inlining then Count := 0; Elmt := First_Elmt (Backend_Not_Inlined_Subps); while Present (Elmt) loop Nod := Node (Elmt); if not In_Internal_Unit (Nod) then Count := Count + 1; if Count = 1 then Write_Str ("List of subprograms that cannot be inlined by backend"); Write_Eol; end if; Write_Str (" "); Write_Int (Count); Write_Str (":"); Write_Name (Chars (Nod)); Write_Str (" ("); Write_Location (Sloc (Nod)); Write_Str (")"); Output.Write_Eol; end if; Next_Elmt (Elmt); end loop; end if; end List_Inlining_Info; ---------- -- Lock -- ---------- procedure Lock is begin Pending_Instantiations.Release; Pending_Instantiations.Locked := True; Called_Pending_Instantiations.Release; Called_Pending_Instantiations.Locked := True; Inlined_Bodies.Release; Inlined_Bodies.Locked := True; Successors.Release; Successors.Locked := True; Inlined.Release; Inlined.Locked := True; end Lock; -------------------------------- -- Remove_Aspects_And_Pragmas -- -------------------------------- procedure Remove_Aspects_And_Pragmas (Body_Decl : Node_Id) is procedure Remove_Items (List : List_Id); -- Remove all useless aspects/pragmas from a particular list ------------------ -- Remove_Items -- ------------------ procedure Remove_Items (List : List_Id) is Item : Node_Id; Item_Id : Node_Id; Next_Item : Node_Id; begin -- Traverse the list looking for an aspect specification or a pragma Item := First (List); while Present (Item) loop Next_Item := Next (Item); if Nkind (Item) = N_Aspect_Specification then Item_Id := Identifier (Item); elsif Nkind (Item) = N_Pragma then Item_Id := Pragma_Identifier (Item); else Item_Id := Empty; end if; if Present (Item_Id) and then Chars (Item_Id) in Name_Contract_Cases | Name_Global | Name_Depends | Name_Postcondition | Name_Precondition | Name_Refined_Global | Name_Refined_Depends | Name_Refined_Post | Name_Subprogram_Variant | Name_Test_Case | Name_Unmodified | Name_Unreferenced | Name_Unused then Remove (Item); end if; Item := Next_Item; end loop; end Remove_Items; -- Start of processing for Remove_Aspects_And_Pragmas begin Remove_Items (Aspect_Specifications (Body_Decl)); Remove_Items (Declarations (Body_Decl)); -- Pragmas Unmodified, Unreferenced, and Unused may additionally appear -- in the body of the subprogram. Remove_Items (Statements (Handled_Statement_Sequence (Body_Decl))); end Remove_Aspects_And_Pragmas; -------------------------- -- Remove_Dead_Instance -- -------------------------- procedure Remove_Dead_Instance (N : Node_Id) is J : Int; begin J := 0; while J <= Pending_Instantiations.Last loop if Pending_Instantiations.Table (J).Inst_Node = N then Pending_Instantiations.Table (J).Inst_Node := Empty; return; end if; J := J + 1; end loop; end Remove_Dead_Instance; ------------------------------------------- -- Reset_Actual_Mapping_For_Inlined_Call -- ------------------------------------------- procedure Reset_Actual_Mapping_For_Inlined_Call (Subp : Entity_Id) is F : Entity_Id := First_Formal (Subp); begin while Present (F) loop Set_Renamed_Object (F, Empty); Next_Formal (F); end loop; end Reset_Actual_Mapping_For_Inlined_Call; end Inline;
<table> <thead align = "right"> <tr><th></th><td>X</td><td>Y</td><td>Z</td></tr> </thead> <tbody align = "right"> <tr><td> 1</td><td> 7255</td><td> 3014</td><td> 9436</td></tr> <tr><td> 2</td><td> 554</td><td> 3314</td><td> 8765</td></tr> <tr><td> 3</td><td> 4832</td><td> 129</td><td> 2048</td></tr> <tr><td> 4</td><td> 31</td><td> 6897</td><td> 8265</td></tr> </tbody> </table>
with Lv.Mem; package body Lv.Strings is ---------------- -- New_String -- ---------------- function New_String (Str : String) return Lv.C_String_Ptr is use System; use Interfaces; Addr : constant System.Address := Lv.Mem.Alloc (Str'Length + 1); Out_Str : String (1 .. Str'Length + 1) with Address => Addr; begin if Addr = System.Null_Address then return System.Null_Address; else Out_Str (1 .. Str'Length) := Str; Out_Str (Out_Str'Last) := ASCII.NUL; return Addr; end if; end New_String; ---------- -- Free -- ---------- procedure Free (Ptr : in out Lv.C_String_Ptr) is begin Lv.Mem.Free (Ptr); Ptr := System.Null_Address; end Free; end Lv.Strings;
with Numerics, Chebyshev, Numerics.Sparse_Matrices.CSparse; use Numerics, Chebyshev; package body Auto_Differentiation.Integrator is function Is_Setup return Boolean is Okay : Boolean := True; begin if N_Col (MatA) = 0 or else N_Row (MatA) = 0 or else N_Col (MatB) = 0 or else N_Row (MatB) = 0 or else N_Col (MatC) = 0 or else N_Row (MatC) = 0 or else N_Col (MatD) = 0 or else N_Row (MatD) = 0 then Okay := False; end if; return Okay; end Is_Setup; procedure Setup (N : in Nat; K : in Nat) is Top_Left : Sparse_Matrix := Sparse (((1.0, 0.0), (0.0, 0.0))); Top_Right : Sparse_Matrix := Sparse (((0.0, 1.0), (0.0, 0.0))); Bottom_Left : Sparse_Matrix := Sparse (((0.0, 0.0), (1.0, 0.0))); Bottom_Right : Sparse_Matrix := Sparse (((0.0, 0.0), (0.0, 1.0))); EyeN : constant Sparse_Matrix := Eye (N); EyeK : constant Sparse_Matrix := Eye (K); Eye2N : constant Sparse_Matrix := Eye (2 * N); D : constant Sparse_Matrix := Sparse (Derivative_Matrix (K, 0.0, 1.0)); begin Top_Left := Top_Left and EyeN; Top_Right := Top_Right and EyeN; Bottom_Left := Bottom_Left and EyeN; Bottom_Right := Bottom_Right and EyeN; MatC := D and Eye2N; -- temporary, overwritten below MatA := MatC * (EyeK and Top_Left); MatB := MatC * (EyeK and Bottom_Right); MatC := EyeK and Top_Right; MatD := EyeK and Bottom_Left; end Setup; function Collocation (Lagrangian : not null access function (X : Real_Vector; N : Nat) return AD_Type; Var : in Variable; Control : in out Control_Type) return Real_Vector is use Ada.Text_IO, Real_IO; K : Nat renames Control.K; N : Nat renames Control.N; Old : constant Evaluation_Level := Level; Tmp : constant Integer := 2 * N; Q : Real_Vector (1 .. 2 * N * K); DQ : Sparse_Vector; F : Sparse_Vector; J : Sparse_Matrix; Res : Real := 1.0; begin Level := Hessian; ------------------------------------------------ for I in 1 .. K loop Q ((I - 1) * 2 * N + 1 .. I * 2 * N) := Var.X; end loop; ------------------------------------------------ while Res > 1.0e-10 loop FJ (Lagrangian, Var, Control, Q, F, J); DQ := Numerics.Sparse_Matrices.CSparse.Solve (J, F); Q (Tmp + 1 .. Tmp * K) := Q (Tmp + 1 .. Tmp * K) - To_Array (DQ); Res := Norm (F); -- Put (Res); New_Line; end loop; -- New_Line; ------------------------------------------------ Control.Err := Norm (DQ) / Norm (Q); Level := Old; return Q; end Collocation; procedure FJ (Lagrangian : not null access function (X : Real_Vector; N : Nat) return AD_Type; Var : in Variable; Control : in Control_Type; Q : in Real_Vector; F : out Sparse_Vector; J : out Sparse_Matrix) is N : Nat renames Control.N; L : AD_Type; X : Real_Vector (1 .. 2 * N); Tmp : Integer; U : Sparse_Vector; V : Sparse_Matrix; A : constant Sparse_Matrix := MatA - Control.Dt * MatC; B : constant Sparse_Matrix := MatB - Control.Dt * MatD; begin pragma Assert (Q'Length = 2 * N * Control.K); ------------------------------------- X := Q (1 .. 2 * N); L := Lagrangian (X, N); U := Grad (L); V := Hessian (L); for K in 2 .. Control.K loop Tmp := 2 * N * (K - 1); X := Q (Tmp + 1 .. Tmp + 2 * N); L := Lagrangian (X, N); U := U or Grad (L); V := V or Hessian (L); end loop; ------------------------------------- F := A * Q - B * U; F := Remove_1st_N (F, 2 * N); J := A - B * V; J := Remove_1st_N (J, 2 * N); end FJ; function Bogacki_Shampine (Hamiltonian : not null access function (X : Real_Vector; N : Nat) return AD_Type; Var : in Variable; Control : in out Control_Type) return Real_Vector is X : Real_Vector renames Var.X; N : Nat renames Control.N; Dt : Real renames Control.Dt; Err : Real renames Control.Err; J : constant Sparse_Matrix := -Omega (N); Old : constant Evaluation_Level := Level; K1, K2, K3, K4, Y, Z : Real_Vector (X'Range); begin pragma Assert (2 * N = Var.N2); -- Turn off the calculation of Hessians (not used for explicit schemes): Level := Gradient; K1 := To_Array (J * Grad (Hamiltonian (X, N))); K2 := To_Array (J * Grad (Hamiltonian (X + (0.50 * Dt) * K1, N))); K3 := To_Array (J * Grad (Hamiltonian (X + (0.75 * Dt) * K2, N))); Y := X + (Dt / 9.0) * (2.0 * K1 + 3.0 * K2 + 4.0 * K3); K4 := To_Array (J * Grad (Hamiltonian (Y, N))); Z := X + (Dt / 24.0) * (7.0 * K1 + 6.0 * K2 + 8.0 * K3 + 3.0 * K4); Err := Norm (Z - Y); Level := Old; -- return to previous evaluation level return (Z); end Bogacki_Shampine; procedure Update (Hamiltonian : not null access function (X : Real_Vector; N : Nat) return AD_Type; Var : in out Variable; Control : in out Control_Type) is use Real_Functions; X : Real_Vector renames Var.X; T : Real renames Var.T; N : Nat renames Control.N; Dt : Real renames Control.Dt; Err : Real renames Control.Err; Eps : Real renames Control.Eps; Y : Real_Vector (X'Range); begin pragma Assert (2 * N = Var.N2); Err := 1.0; while Err > Eps loop Y := Bogacki_Shampine (Hamiltonian, Var, Control); if (Err <= Eps) then X := Y; T := T + Dt; end if; Dt := 0.8 * Dt * (Eps / (Err + 1.0e-20)) ** 0.3; end loop; end Update; procedure Print_XYZ (File : in File_Type; Var : in Variable) is use Real_Functions, Real_IO; X : Real_Vector renames Var.X; X1, Y1, X2, Y2 : Real; R : constant Real := 10.0; begin X1 := -R * Sin (X (1)); Y1 := R * Cos (X (1)); X2 := X1 - R * Sin (2.0 * X (1) + X (2)); Y2 := Y1 + R * Cos (2.0 * X (1) + X (2)); -- print header Put_Line (File, "3"); Put (File, "Properties=pos:R:2 Time="); Put (File, Var.T, Aft => 5, Exp => 0); New_Line (File); -- position of ball 1 Put_Line (File, "0.0 0.0 5.0"); -- position of ball 2 Put (File => File, Item => X1); Put (File => File, Item => " "); Put (File => File, Item => Y1); Put (File => File, Item => " "); Put (File => File, Item => "5.0"); New_Line (File => File); -- position of ball 3 Put (File => File, Item => X2); Put (File => File, Item => " "); Put (File => File, Item => Y2); Put (File => File, Item => " "); Put (File => File, Item => "5.0"); New_Line (File => File); end Print_XYZ; --- print data ------ procedure Print_Data (Var : in Variable; Hamiltonian : not null access function (X : Real_Vector; N : Nat) return AD_Type) is use Real_Functions, Real_IO; T : Real renames Var.X (1); S : Real renames Var.X (2); X, Y : Real_Vector (1 .. 2); begin X (1) := -Sin (T); Y (1) := Cos (T); X (2) := X (1) - Sin (2.0 * T + S); Y (2) := Y (1) + Cos (2.0 * T + S); --------------------------------------- Put (Var.T, Aft => 6, Exp => 0); -- print time for I in 1 .. 2 loop Put (", "); Put (X (I), Aft => 4, Exp => 0); Put (", "); Put (Y (I), Aft => 4, Exp => 0); -- print positions end loop; Put (", "); -- print total energy Put (Val (Hamiltonian (Var.X, 2)), Aft => 10, Exp => 0); New_Line; end Print_Data; procedure Print_Data_L (File : in File_Type; Var : in Variable) is use Real_Functions, Real_IO; T : Real renames Var.X (1); S : Real renames Var.X (2); X, Y : Real_Vector (1 .. 2); begin X (1) := -Sin (T); Y (1) := Cos (T); X (2) := X (1) - Sin (2.0 * T + S); Y (2) := Y (1) + Cos (2.0 * T + S); --------------------------------------- Put (Var.T, Aft => 6, Exp => 0); -- print time for I in 1 .. 2 loop -- print positions Put (", "); Put (X (I), Aft => 4, Exp => 0); Put (", "); Put (Y (I), Aft => 4, Exp => 0); end loop; New_Line; end Print_Data_L; end Auto_Differentiation.Integrator;
-- This package has been generated automatically by GNATtest. -- Do not edit any part of it, see GNATtest documentation for more details. -- begin read only with GNATtest_Generated; package Tk.Frame.Frame_Options_Test_Data.Frame_Options_Tests is type Test_Frame_Options is new GNATtest_Generated.GNATtest_Standard.Tk.Frame .Frame_Options_Test_Data .Test_Frame_Options with null record; procedure Test_Configure_0076be_f3ea46 (Gnattest_T: in out Test_Frame_Options); -- tk-frame.ads:88:4:Configure:Test_Configure_Frame end Tk.Frame.Frame_Options_Test_Data.Frame_Options_Tests; -- end read only
------------------------------------------------------------------------------- -- Copyright (c) 2019, Daniel King -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met: -- * Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer. -- * Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- * The name of the copyright holder may not be used to endorse or promote -- Products derived from this software without specific prior written -- permission. -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY -- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------- with Keccak.Arch.SSE2; with Keccak.Arch.AVX2; with Keccak.Generic_Parallel_KeccakF; with Keccak.Generic_Parallel_Permutation_Parallel_Fallback; with Keccak.Types; with Interfaces; pragma Elaborate_All (Keccak.Generic_Parallel_KeccakF); pragma Elaborate_All (Keccak.Generic_Parallel_Permutation_Parallel_Fallback); -- @summary -- Defines procedures for running Keccak-f permutations in parallel for -- 2x, 4x, and 8x parallelism, as well as serial permutations. -- -- @description -- This package must define the following types and procedures: -- For 2x parallelism: -- * Parallel_State_P2 -- * Init_P2 -- * XOR_Bits_Into_State_P2 -- * Extract_Bytes_P2 -- -- For 4x parallelism: -- * Parallel_State_P4 -- * Init_P4 -- * XOR_Bits_Into_State_P4 -- * Extract_Bytes_P4 -- -- For 8x parallelism: -- * Parallel_State_P8 -- * Init_P8 -- * XOR_Bits_Into_State_P8 -- * Extract_Bytes_P8 -- -- Any other declarations in this package are architecture-specific and should -- not be relied upon. package Keccak.Parallel_Keccak_1600 with SPARK_Mode => On is ------------------------ -- Keccak-f[1600]x2 -- ------------------------ -- 128-bit SIMD (SSE) is available on this architecture. package KeccakF_1600_P2 is new Keccak.Generic_Parallel_KeccakF (Lane_Size_Log => 6, Lane_Type => Interfaces.Unsigned_64, VXXI_Index => Arch.SSE2.V2DI_Vectors.V2DI_Index, VXXI => Arch.SSE2.V2DI_Vectors.V2DI, VXXI_View => Arch.SSE2.V2DI_Vectors.V2DI_View, Vector_Width => 2, Load => Arch.SSE2.V2DI_Vectors.Load, Store => Arch.SSE2.V2DI_Vectors.Store, "xor" => Arch.SSE2.V2DI_Vectors."xor", Rotate_Left => Arch.SSE2.V2DI_Vectors.Rotate_Left, And_Not => Arch.SSE2.V2DI_Vectors.And_Not, Shift_Left => Interfaces.Shift_Left, Shift_Right => Interfaces.Shift_Right); subtype Parallel_State_P2 is KeccakF_1600_P2.Parallel_State; procedure Init_P2 (S : out KeccakF_1600_P2.Parallel_State) renames KeccakF_1600_P2.Init; procedure XOR_Bits_Into_State_Separate_P2 (S : in out Parallel_State_P2; Data : in Types.Byte_Array; Data_Offset : in Natural; Bit_Len : in Natural) renames KeccakF_1600_P2.XOR_Bits_Into_State_Separate; procedure XOR_Bits_Into_State_All_P2 (S : in out Parallel_State_P2; Data : in Types.Byte_Array; Bit_Len : in Natural) renames KeccakF_1600_P2.XOR_Bits_Into_State_All; procedure Extract_Bytes_P2 (S : in Parallel_State_P2; Data : in out Types.Byte_Array; Data_Offset : in Natural; Byte_Len : in Natural) renames KeccakF_1600_P2.Extract_Bytes; ------------------------ -- Keccak-f[1600]x4 -- ------------------------ -- 256-bit SIMD (AVX2) is available on this architecture. package KeccakF_1600_P4 is new Keccak.Generic_Parallel_KeccakF (Lane_Size_Log => 6, Lane_Type => Interfaces.Unsigned_64, VXXI_Index => Arch.AVX2.V4DI_Vectors.V4DI_Index, VXXI => Arch.AVX2.V4DI_Vectors.V4DI, VXXI_View => Arch.AVX2.V4DI_Vectors.V4DI_View, Vector_Width => 4, Load => Arch.AVX2.V4DI_Vectors.Load, Store => Arch.AVX2.V4DI_Vectors.Store, "xor" => Arch.AVX2.V4DI_Vectors."xor", Rotate_Left => Arch.AVX2.V4DI_Vectors.Rotate_Left, And_Not => Arch.AVX2.V4DI_Vectors.And_Not, Shift_Left => Interfaces.Shift_Left, Shift_Right => Interfaces.Shift_Right); subtype Parallel_State_P4 is KeccakF_1600_P4.Parallel_State; procedure Init_P4 (S : out KeccakF_1600_P4.Parallel_State) renames KeccakF_1600_P4.Init; procedure XOR_Bits_Into_State_Separate_P4 (S : in out Parallel_State_P4; Data : in Types.Byte_Array; Data_Offset : in Natural; Bit_Len : in Natural) renames KeccakF_1600_P4.XOR_Bits_Into_State_Separate; procedure XOR_Bits_Into_State_All_P4 (S : in out Parallel_State_P4; Data : in Types.Byte_Array; Bit_Len : in Natural) renames KeccakF_1600_P4.XOR_Bits_Into_State_All; procedure Extract_Bytes_P4 (S : in Parallel_State_P4; Data : in out Types.Byte_Array; Data_Offset : in Natural; Byte_Len : in Natural) renames KeccakF_1600_P4.Extract_Bytes; ------------------------ -- Keccak-f[1600]x8 -- ------------------------ -- No 512-bit SIMD available on this architecture. Fallback to 4x2 package KeccakF_1600_P8 is new Keccak.Generic_Parallel_Permutation_Parallel_Fallback (Permutation_State => Parallel_State_P4, Base_Parallelism => 4, Parallel_Factor => 2, Init => Init_P4, XOR_Bits_Into_State_Separate => XOR_Bits_Into_State_Separate_P4, XOR_Bits_Into_State_All => XOR_Bits_Into_State_All_P4, Extract_Bytes => Extract_Bytes_P4, State_Size_Bits => 1600); subtype Parallel_State_P8 is KeccakF_1600_P8.Parallel_State; procedure Init_P8 (S : out Parallel_State_P8) renames KeccakF_1600_P8.Init; procedure XOR_Bits_Into_State_Separate_P8 (S : in out Parallel_State_P8; Data : in Types.Byte_Array; Data_Offset : in Natural; Bit_Len : in Natural) renames KeccakF_1600_P8.XOR_Bits_Into_State_Separate; procedure XOR_Bits_Into_State_All_P8 (S : in out Parallel_State_P8; Data : in Types.Byte_Array; Bit_Len : in Natural) renames KeccakF_1600_P8.XOR_Bits_Into_State_All; procedure Extract_Bytes_P8 (S : in Parallel_State_P8; Data : in out Types.Byte_Array; Data_Offset : in Natural; Byte_Len : in Natural) renames KeccakF_1600_P8.Extract_Bytes; end Keccak.Parallel_Keccak_1600;
----------------------------------------------------------------------- -- akt-commands -- Ada Keystore Tool commands -- Copyright (C) 2019 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with System.Multiprocessors; with Ada.Command_Line; with Ada.Text_IO; with Ada.Unchecked_Deallocation; with Util.Strings; with Util.Commands.Parsers.GNAT_Parser; with AKT.Configs; with AKT.Commands.Drivers; with AKT.Commands.Set; with AKT.Commands.Get; with AKT.Commands.Create; with AKT.Commands.List; with AKT.Commands.Remove; with AKT.Commands.Edit; with AKT.Commands.Extract; with AKT.Commands.Store; with AKT.Commands.Password.Add; with AKT.Commands.Password.Set; with AKT.Commands.Password.Remove; with AKT.Commands.Info; with AKT.Commands.Config; with Keystore.Passwords.Input; with Keystore.Passwords.Files; with Keystore.Passwords.Unsafe; with Keystore.Passwords.Cmds; package body AKT.Commands is use type Keystore.Passwords.Provider_Access; use type Keystore.Header_Slot_Count_Type; use type Keystore.Passwords.Keys.Key_Provider_Access; Help_Command : aliased AKT.Commands.Drivers.Help_Command_Type; Set_Command : aliased AKT.Commands.Set.Command_Type; Store_Command : aliased AKT.Commands.Store.Command_Type; Get_Command : aliased AKT.Commands.Get.Command_Type; Extract_Command : aliased AKT.Commands.Extract.Command_Type; Create_Command : aliased AKT.Commands.Create.Command_Type; List_Command : aliased AKT.Commands.List.Command_Type; Remove_Command : aliased AKT.Commands.Remove.Command_Type; Edit_Command : aliased AKT.Commands.Edit.Command_Type; Set_Password_Command : aliased AKT.Commands.Password.Set.Command_Type; Add_Password_Command : aliased AKT.Commands.Password.Add.Command_Type; Remove_Password_Command : aliased AKT.Commands.Password.Remove.Command_Type; Info_Command : aliased AKT.Commands.Info.Command_Type; Config_Command : aliased AKT.Commands.Config.Command_Type; Driver : Drivers.Driver_Type; -- ------------------------------ -- Print the command usage. -- ------------------------------ procedure Usage (Args : in Argument_List'Class; Context : in out Context_Type; Name : in String := "") is begin GC.Display_Help (Context.Command_Config); if Name'Length > 0 then Driver.Usage (Args, Context, Name); end if; Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); end Usage; -- ------------------------------ -- Open the keystore file using the password password. -- When `Use_Worker` is set, a workers of N tasks is created and assigned to the keystore -- for the decryption and encryption process. -- ------------------------------ procedure Open_Keystore (Context : in out Context_Type; Args : in Argument_List'Class; Use_Worker : in Boolean := False) is begin Setup_Password_Provider (Context); Setup_Key_Provider (Context); Context.Wallet.Open (Path => Context.Get_Keystore_Path (Args), Data_Path => Context.Data_Path.all, Config => Context.Config, Info => Context.Info); if not Context.No_Password_Opt or else Context.Info.Header_Count = 0 then if Context.Key_Provider /= null then Context.Wallet.Set_Master_Key (Context.Key_Provider.all); end if; if Context.Provider = null then Context.Provider := Keystore.Passwords.Input.Create (-("Enter password: "), False); end if; Context.Wallet.Unlock (Context.Provider.all, Context.Slot); else Context.GPG.Load_Secrets (Context.Wallet); Context.Wallet.Set_Master_Key (Context.GPG); Context.Wallet.Unlock (Context.GPG, Context.Slot); end if; if Use_Worker then Context.Workers := new Keystore.Task_Manager (Context.Worker_Count); Keystore.Start (Context.Workers); Context.Wallet.Set_Work_Manager (Context.Workers); end if; end Open_Keystore; -- ------------------------------ -- Open the keystore file and change the password. -- ------------------------------ procedure Change_Password (Context : in out Context_Type; Args : in Argument_List'Class; New_Password : in out Keystore.Passwords.Provider'Class; Config : in Keystore.Wallet_Config; Mode : in Keystore.Mode_Type) is begin Context.Wallet.Open (Path => Context.Get_Keystore_Path (Args), Data_Path => Context.Data_Path.all, Config => Context.Config, Info => Context.Info); if not Context.No_Password_Opt or else Context.Info.Header_Count = 0 then if Context.Key_Provider /= null then Context.Wallet.Set_Master_Key (Context.Key_Provider.all); end if; Context.Wallet.Unlock (Context.Provider.all, Context.Slot); Context.Wallet.Set_Key (Password => Context.Provider.all, New_Password => New_Password, Config => Config, Mode => Mode); else Context.GPG.Load_Secrets (Context.Wallet); Context.Wallet.Set_Master_Key (Context.GPG); Context.Wallet.Unlock (Context.GPG, Context.Slot); Context.Wallet.Set_Key (Password => Context.GPG, New_Password => New_Password, Config => Config, Mode => Mode); end if; end Change_Password; -- ------------------------------ -- Execute the command with its arguments. -- ------------------------------ procedure Execute (Name : in String; Args : in Argument_List'Class; Context : in out Context_Type) is begin Log.Info ("Execute command {0}", Name); Driver.Execute (Name, Args, Context); end Execute; -- ------------------------------ -- Initialize the commands. -- ------------------------------ overriding procedure Initialize (Context : in out Context_Type) is begin Intl.Initialize ("akt", AKT.Configs.PREFIX & "/share/locale"); Context.Worker_Count := Positive (System.Multiprocessors.Number_Of_CPUs); GC.Set_Usage (Config => Context.Command_Config, Usage => "[switchs] command [arguments]", Help => -("akt - tool to store and protect your sensitive data")); GC.Define_Switch (Config => Context.Command_Config, Output => Context.Version'Access, Switch => "-V", Long_Switch => "--version", Help => -("Print the version")); GC.Define_Switch (Config => Context.Command_Config, Output => Context.Verbose'Access, Switch => "-v", Long_Switch => "--verbose", Help => -("Verbose execution mode")); GC.Define_Switch (Config => Context.Command_Config, Output => Context.Debug'Access, Switch => "-vv", Long_Switch => "--debug", Help => -("Enable debug execution")); GC.Define_Switch (Config => Context.Command_Config, Output => Context.Dump'Access, Switch => "-vvv", Long_Switch => "--debug-dump", Help => -("Enable debug dump execution")); GC.Define_Switch (Config => Context.Command_Config, Output => Context.Zero'Access, Switch => "-z", Long_Switch => "--zero", Help => -("Erase and fill with zeros instead of random values")); GC.Define_Switch (Config => Context.Command_Config, Output => Context.Config_File'Access, Switch => "-c:", Long_Switch => "--config=", Argument => "PATH", Help => -("Defines the path for akt global configuration")); GC.Define_Switch (Config => Context.Command_Config, Output => Context.Worker_Count'Access, Switch => "-t:", Long_Switch => "--thread=", Initial => Context.Worker_Count, Argument => "COUNT", Help => -("Number of threads for the encryption/decryption process")); GC.Initialize_Option_Scan (Stop_At_First_Non_Switch => True); Driver.Set_Description (-("akt - tool to store and protect your sensitive data")); Driver.Set_Usage (-("[-V] [-v] [-vv] [-vvv] [-c path] [-t count] [-z] " & "<command> [<args>]" & ASCII.LF & "where:" & ASCII.LF & " -V Print the tool version" & ASCII.LF & " -v Verbose execution mode" & ASCII.LF & " -vv Debug execution mode" & ASCII.LF & " -vvv Dump execution mode" & ASCII.LF & " -c path Defines the path for akt " & "global configuration" & ASCII.LF & " -t count Number of threads for the " & "encryption/decryption process" & ASCII.LF & " -z Erase and fill with zeros instead of random values")); Driver.Add_Command ("help", -("print some help"), Help_Command'Access); Driver.Add_Command ("config", -("get or set global options"), Config_Command'Access); Driver.Add_Command ("set", -("insert or update a value in the keystore"), Set_Command'Access); Driver.Add_Command ("store", -("read the standard input and insert or update the" & " content in the keystore"), Store_Command'Access); Driver.Add_Command ("get", -("get a value from the keystore"), Get_Command'Access); Driver.Add_Command ("extract", -("get a value from the keystore"), Extract_Command'Access); Driver.Add_Command ("create", -("create the keystore"), Create_Command'Access); Driver.Add_Command ("list", -("list values of the keystore"), List_Command'Access); Driver.Add_Command ("remove", -("remove values from the keystore"), Remove_Command'Access); Driver.Add_Command ("edit", -("edit the value with an external editor"), Edit_Command'Access); Driver.Add_Command ("password-set", -("change the password"), Set_Password_Command'Access); Driver.Add_Command ("password-add", -("add a password"), Add_Password_Command'Access); Driver.Add_Command ("password-remove", -("remove a password"), Remove_Password_Command'Access); Driver.Add_Command ("info", -("report information about the keystore"), Info_Command'Access); end Initialize; -- ------------------------------ -- Setup the command before parsing the arguments and executing it. -- ------------------------------ procedure Setup (Config : in out GC.Command_Line_Configuration; Context : in out Context_Type) is begin GC.Define_Switch (Config => Config, Output => Context.Wallet_File'Access, Switch => "-k:", Long_Switch => "--keystore=", Argument => "PATH", Help => -("Defines the path for the keystore file")); GC.Define_Switch (Config => Config, Output => Context.Data_Path'Access, Switch => "-d:", Long_Switch => "--data-path=", Argument => "PATH", Help => -("The directory which contains the keystore data blocks")); GC.Define_Switch (Config => Config, Output => Context.Password_File'Access, Long_Switch => "--passfile=", Argument => "PATH", Help => -("Read the file that contains the password")); GC.Define_Switch (Config => Config, Output => Context.Unsafe_Password'Access, Long_Switch => "--passfd=", Argument => "NUM", Help => -("Read the password from the pipe with" & " the given file descriptor")); GC.Define_Switch (Config => Config, Output => Context.Unsafe_Password'Access, Long_Switch => "--passsocket=", Help => -("The password is passed within the socket connection")); GC.Define_Switch (Config => Config, Output => Context.Password_Env'Access, Long_Switch => "--passenv=", Argument => "NAME", Help => -("Read the environment variable that contains" & " the password (not safe)")); GC.Define_Switch (Config => Config, Output => Context.Unsafe_Password'Access, Switch => "-p:", Long_Switch => "--password=", Help => -("The password is passed within the command line (not safe)")); GC.Define_Switch (Config => Config, Output => Context.Password_Askpass'Access, Long_Switch => "--passask", Help => -("Run the ssh-askpass command to get the password")); GC.Define_Switch (Config => Config, Output => Context.Password_Command'Access, Long_Switch => "--passcmd=", Argument => "COMMAND", Help => -("Run the command to get the password")); GC.Define_Switch (Config => Config, Output => Context.Wallet_Key_File'Access, Long_Switch => "--wallet-key-file=", Argument => "PATH", Help => -("Read the file that contains the wallet keys")); end Setup; procedure Setup_Password_Provider (Context : in out Context_Type) is begin if Context.Password_Askpass then Context.Provider := Keystore.Passwords.Cmds.Create ("ssh-askpass"); elsif Context.Password_Command'Length > 0 then Context.Provider := Keystore.Passwords.Cmds.Create (Context.Password_Command.all); elsif Context.Password_File'Length > 0 then Context.Provider := Keystore.Passwords.Files.Create (Context.Password_File.all); elsif Context.Password_Command'Length > 0 then Context.Provider := Keystore.Passwords.Cmds.Create (Context.Password_Command.all); elsif Context.Unsafe_Password'Length > 0 then Context.Provider := Keystore.Passwords.Unsafe.Create (Context.Unsafe_Password.all); else Context.No_Password_Opt := True; end if; Context.Key_Provider := Keystore.Passwords.Keys.Create (Keystore.DEFAULT_WALLET_KEY); end Setup_Password_Provider; procedure Setup_Key_Provider (Context : in out Context_Type) is begin if Context.Wallet_Key_File'Length > 0 then Context.Key_Provider := Keystore.Passwords.Files.Create (Context.Wallet_Key_File.all); end if; end Setup_Key_Provider; procedure Initialize (Context : in out Keystore.Passwords.GPG.Context_Type) is begin if AKT.Configs.Exists (AKT.Configs.GPG_CRYPT_CONFIG) then Context.Set_Encrypt_Command (AKT.Configs.Get (AKT.Configs.GPG_CRYPT_CONFIG)); end if; if AKT.Configs.Exists (AKT.Configs.GPG_DECRYPT_CONFIG) then Context.Set_Decrypt_Command (AKT.Configs.Get (AKT.Configs.GPG_DECRYPT_CONFIG)); end if; if AKT.Configs.Exists (AKT.Configs.GPG_LIST_CONFIG) then Context.Set_List_Key_Command (AKT.Configs.Get (AKT.Configs.GPG_LIST_CONFIG)); end if; end Initialize; procedure Parse (Context : in out Context_Type; Arguments : out Util.Commands.Dynamic_Argument_List) is begin GC.Getopt (Config => Context.Command_Config); Util.Commands.Parsers.GNAT_Parser.Get_Arguments (Arguments, GC.Get_Argument); if Context.Debug or Context.Verbose or Context.Dump then AKT.Configure_Logs (Debug => Context.Debug, Dump => Context.Dump, Verbose => Context.Verbose); end if; AKT.Configs.Initialize (Context.Config_File.all); Initialize (Context.GPG); if Context.Version then Ada.Text_IO.Put_Line (AKT.Configs.RELEASE); return; end if; Context.Config.Randomize := not Context.Zero; declare Cmd_Name : constant String := Arguments.Get_Command_Name; begin if Cmd_Name'Length = 0 then AKT.Commands.Log.Error (-("Missing command name to execute.")); AKT.Commands.Usage (Arguments, Context); Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); return; end if; AKT.Commands.Execute (Cmd_Name, Arguments, Context); exception when GNAT.Command_Line.Invalid_Parameter => AKT.Commands.Log.Error (-("Missing option parameter")); raise Error; end; end Parse; procedure Parse_Range (Value : in String; Config : in out Keystore.Wallet_Config) is Pos : constant Natural := Util.Strings.Index (Value, ':'); Low : Integer := Config.Min_Counter; High : Integer := Config.Max_Counter; begin if Pos > 0 then Low := Integer'Value (Value (Value'First .. Pos - 1)); High := Integer'Value (Value (Pos + 1 .. Value'Last)); else High := Integer'Value (Value); if Low > High then Low := High; end if; end if; if not (Low in Positive'Range) or not (High in Positive'Range) then AKT.Commands.Log.Error (-("Value is out of range")); raise Error; end if; if Low > High then AKT.Commands.Log.Error (-("The min counter is greater than max counter")); raise Error; end if; Config.Min_Counter := Positive (Low); Config.Max_Counter := Positive (High); exception when Error => raise; when others => AKT.Commands.Log.Error (-("Invalid counter range: {0}"), Value); AKT.Commands.Log.Error (-("Valid format are 'MAX_COUNTER' or " & "'MIN_COUNTER:MAX_COUNTER'")); AKT.Commands.Log.Error (-("Counters must be positive integers.")); raise Error; end Parse_Range; -- ------------------------------ -- Get the keystore file path. -- ------------------------------ function Get_Keystore_Path (Context : in out Context_Type; Args : in Argument_List'Class) return String is begin if Context.Wallet_File'Length > 0 then Context.First_Arg := 1; return Context.Wallet_File.all; elsif Args.Get_Count > 0 then Context.First_Arg := 2; return Args.Get_Argument (1); else raise No_Keystore_File; end if; end Get_Keystore_Path; overriding procedure Finalize (Context : in out Context_Type) is use type Keystore.Task_Manager_Access; procedure Free is new Ada.Unchecked_Deallocation (Object => Keystore.Passwords.Provider'Class, Name => Keystore.Passwords.Provider_Access); procedure Free is new Ada.Unchecked_Deallocation (Object => Keystore.Task_Manager, Name => Keystore.Task_Manager_Access); begin if Context.Workers /= null then Keystore.Stop (Context.Workers); Free (Context.Workers); end if; GC.Free (Context.Command_Config); Free (Context.Provider); end Finalize; end AKT.Commands;
with Ada.Text_IO; use Ada.Text_IO; procedure Pyramid_of_Numbers is B_X, B_Y, B_Z : Integer := 0; -- Unknown variables type Block_Value is record Known : Integer := 0; X, Y, Z : Integer := 0; end record; X : constant Block_Value := (0, 1, 0, 0); Y : constant Block_Value := (0, 0, 1, 0); Z : constant Block_Value := (0, 0, 0, 1); procedure Add (L : in out Block_Value; R : Block_Value) is begin -- Symbolically adds one block to another L.Known := L.Known + R.Known; L.X := L.X + R.X - R.Z; -- Z is excluded as n(Y - X - Z) = 0 L.Y := L.Y + R.Y + R.Z; end Add; procedure Add (L : in out Block_Value; R : Integer) is begin -- Symbolically adds a value to the block L.Known := L.Known + R; end Add; function Image (N : Block_Value) return String is begin -- The block value, when X,Y,Z are known return Integer'Image (N.Known + N.X * B_X + N.Y * B_Y + N.Z * B_Z); end Image; procedure Solve_2x2 (A11, A12, B1, A21, A22, B2 : Integer) is begin -- Don't care about things, supposing an integer solution exists if A22 = 0 then B_X := B2 / A21; B_Y := (B1 - A11*B_X) / A12; else B_X := (B1*A22 - B2*A12) / (A11*A22 - A21*A12); B_Y := (B1 - A11*B_X) / A12; end if; B_Z := B_Y - B_X; end Solve_2x2; B : array (1..5, 1..5) of Block_Value; -- The lower triangle contains blocks begin -- The bottom blocks Add (B(5,1),X); Add (B(5,2),11); Add (B(5,3),Y); Add (B(5,4),4); Add (B(5,5),Z); -- Upward run for Row in reverse 1..4 loop for Column in 1..Row loop Add (B (Row, Column), B (Row + 1, Column)); Add (B (Row, Column), B (Row + 1, Column + 1)); end loop; end loop; -- Now have known blocks 40=(3,1), 151=(1,1) and Y=X+Z to determine X,Y,Z Solve_2x2 ( B(1,1).X, B(1,1).Y, 151 - B(1,1).Known, B(3,1).X, B(3,1).Y, 40 - B(3,1).Known ); -- Print the results for Row in 1..5 loop New_Line; for Column in 1..Row loop Put (Image (B(Row,Column))); end loop; end loop; end Pyramid_of_Numbers;
package openGL.Program.colored_textured -- -- Provides a program for colored, textured GL vertices. -- is type Item is new openGL.Program.item with null record; type View is access all Item'Class; overriding procedure set_Uniforms (Self : in Item); end openGL.Program.colored_textured;
package body Max with SPARK_Mode is function Arrays_Max (A : in Our_Array) return Index_Range is X : Index_Range := Index_Range'First; Y : Index_Range := Index_Range'Last; function max (L, R : Content_Range) return Content_Range is (if L > R then L else R) with Ghost; begin while X /= Y loop -- Write a suitable Loop_Invariant to help prove the postcondition -- Write a suitable Loop_Variant to help prove loop termination pragma Loop_Invariant ( -- for all values up to X, the value is <= the larger of the value at -- x and the value at y (for all k in Index_Range'first .. X => max (a (x), a (y)) >= a(k) ) and -- for all values down to Y, the value is <= the larger of the value -- at x and the value at y (for all k in Y .. Index_Range'last => max (a (x), a (y)) >= a(k) ) and ( X < Y ) ); pragma Loop_Variant (decreases => Y - X); if A (X) <= A (Y) then X := X + 1; else Y := Y - 1; end if; end loop; return X; end Arrays_Max; end Max;
-- This file is generated by SWIG. Please do *not* modify by hand. -- with Interfaces.C.Strings; with Interfaces.C; with Interfaces.C.Pointers; with Interfaces.C.Strings; with System; package clib.lconv is -- Item -- type Item is record decimal_point : aliased Interfaces.C.Strings.chars_ptr; thousands_sep : aliased Interfaces.C.Strings.chars_ptr; grouping : aliased Interfaces.C.Strings.chars_ptr; int_curr_symbol : aliased Interfaces.C.Strings.chars_ptr; currency_symbol : aliased Interfaces.C.Strings.chars_ptr; mon_decimal_point : aliased Interfaces.C.Strings.chars_ptr; mon_thousands_sep : aliased Interfaces.C.Strings.chars_ptr; mon_grouping : aliased Interfaces.C.Strings.chars_ptr; positive_sign : aliased Interfaces.C.Strings.chars_ptr; negative_sign : aliased Interfaces.C.Strings.chars_ptr; int_frac_digits : aliased Interfaces.C.char; frac_digits : aliased Interfaces.C.char; p_cs_precedes : aliased Interfaces.C.char; p_sep_by_space : aliased Interfaces.C.char; n_cs_precedes : aliased Interfaces.C.char; n_sep_by_space : aliased Interfaces.C.char; p_sign_posn : aliased Interfaces.C.char; n_sign_posn : aliased Interfaces.C.char; a_a_int_p_cs_precedes : aliased Interfaces.C.char; a_a_int_p_sep_by_space : aliased Interfaces.C.char; a_a_int_n_cs_precedes : aliased Interfaces.C.char; a_a_int_n_sep_by_space : aliased Interfaces.C.char; a_a_int_p_sign_posn : aliased Interfaces.C.char; a_a_int_n_sign_posn : aliased Interfaces.C.char; end record; -- Items -- type Items is array (Interfaces.C.size_t range <>) of aliased clib.lconv.Item; -- Pointer -- type Pointer is access all clib.lconv.Item; -- Pointers -- type Pointers is array (Interfaces.C.size_t range <>) of aliased clib.lconv.Pointer; -- Pointer_Pointer -- type Pointer_Pointer is access all clib.lconv.Pointer; end clib.lconv;
with Ada.Integer_Text_IO; procedure Faktor is N : Integer; Fakt : Integer := 1; begin Ada.Integer_Text_IO.Get( N ); for I in 1..N loop Fakt := Fakt * I; end loop; Ada.Integer_Text_IO.Put( Fakt ); end Faktor;
with AdaBase.Logger.Base; package MyLogger is package ALB renames AdaBase.Logger.Base; type CustomLogger is new ALB.Base_Logger and ALB.AIL.iLogger with null record; overriding procedure reaction (listener : CustomLogger); clogger : aliased CustomLogger; end MyLogger;
package NPC_PC is ------------------------------- -- Name: Jon Spohn -- David Rogina -- Hero and enemy stats package ------------------------------- type HeroClass is private; Type EnemyClass is private; --Set hero x,y coordinates procedure SetHeroCoord( X: in integer; Y: in integer; Hero : in out HeroClass); --set hero health procedure SetHeroHealth( H : in integer; Hero : in out HeroClass); --set hero armor procedure SetHeroArmor( A : in integer; Hero : in out HeroClass); --set hero strength procedure SetHeroStrength( S : in integer; Hero : in out HeroClass); --get hero X coordinate function GetHeroX(Hero : in HeroClass) return integer; --get hero Y coordinate function GetHeroY(Hero : in HeroClass) return integer; --get hero health function GetHeroH(Hero : in HeroClass) return integer; --get hero armor function GetHeroA(Hero : in HeroClass) return integer; --get hero strength function GetHeroS(Hero : in HeroClass) return integer; --Set enemy x,y coordinates procedure SetEnemyCoord( X: in integer; Y: in integer; Enemy : in out EnemyClass); --set enemy health procedure SetEnemyHealth( H : in integer; Enemy : in out EnemyClass); --set enemy armor procedure SetEnemyArmor( A : in integer; Enemy : in out EnemyClass); --set enemy strength procedure SetEnemyStrength( S : in integer; Enemy : in out EnemyClass); --get enemy X coordinate function GetEnemyX(Enemy : in EnemyClass) return integer; --get enemy Y coordinate function GetEnemyY(Enemy : in EnemyClass) return integer; --get enemy health function GetEnemyH(Enemy : in EnemyClass) return integer; --get enemy armor function GetEnemyA(Enemy : in EnemyClass) return integer; --get enemy strength function GetEnemyS(Enemy : in EnemyClass) return integer; --view hero stats procedure viewstats(Hero: in HeroClass); private type HeroClass is record HeroX : integer; HeroY : integer; Health : integer := 100; Armor : integer := 10; Strength : integer := 10; end record; type EnemyClass is record EnemyX: integer; EnemyY: integer; Health : integer := 100; Armor : integer := 0; Strength : integer := 0; end record; end NPC_PC;
with AdaM.Any, AdaM.a_Type, ada.Streams; package AdaM.Parameter is type Item is new Any.Item with private; -- View -- type View is access all Item'Class; procedure View_write (Stream : not null access Ada.Streams.Root_Stream_Type'Class; Self : in View); procedure View_read (Stream : not null access Ada.Streams.Root_Stream_Type'Class; Self : out View); for View'write use View_write; for View'read use View_read; -- Vector -- package Vectors is new ada.Containers.Vectors (Positive, View); subtype Vector is Vectors.Vector; function to_Source (the_Parameters : in Vector) return text_Vectors.Vector; -- Types -- type a_Mode is (in_Mode, out_Mode, in_out_Mode, access_Mode); -- Forge -- function new_Parameter (Name : in String := "") return Parameter.view; procedure free (Self : in out Parameter.view); procedure destruct (Self : in out Item); -- Attributes -- overriding function Id (Self : access Item) return AdaM.Id; function Name (Self : in Item) return String; procedure Name_is (Self : in out Item; Now : in String); function Mode (Self : in Item) return a_Mode; procedure Mode_is (Self : in out Item; Now : in a_Mode); function my_Type (Self : access Item) return access a_Type.view; function my_Type (Self : in Item) return a_Type.view; procedure Type_is (Self : in out Item; Now : in a_Type.view); function Default (Self : in Item) return String; procedure Default_is (Self : in out Item; Now : in String); function to_Source (Self : in Item) return text_Vectors.Vector; private type Item is new Any.Item with record Name : Text; Mode : a_Mode; my_Type : aliased a_Type.view; Default : Text; end record; end AdaM.Parameter;
------------------------------------------------------------------------------ -- EMAIL: <darkestkhan@gmail.com> -- -- License: ISC License (see COPYING file) -- -- -- -- Copyright © 2014 - 2015 darkestkhan -- ------------------------------------------------------------------------------ -- 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.Directories; with Ada.Environment_Variables; private with XDG.Defaults; package body XDG is ---------------------------------------------------------------------------- package EV renames Ada.Environment_Variables; -- Directory separator is different for Windows and UNIX so use appropriate -- one. Sep: constant Character := XDG.Defaults.Separator; ---------------------------------------------------------------------------- generic Variable: String; Default : String; function Get_Home return String; function Get_Home return String is Home: constant String := EV.Value ("HOME"); begin if EV.Exists (Variable) then declare Value: constant String := EV.Value (Variable); begin if Value (Value'Last) = Sep then return Value; else return Value & Sep; end if; end; else if Home (Home'Last) = Sep then return Home & Default; else return Home & Sep & Default; end if; end if; end Get_Home; function Get_Data_Home is new Get_Home ("XDG_DATA_HOME", XDG.Defaults.Home); function Get_Config_Home is new Get_Home ("XDG_CONFIG_HOME", XDG.Defaults.Config); function Get_Cache_Home is new Get_Home ("XDG_CACHE_HOME", XDG.Defaults.Cache); function Data_Home return String renames Get_Data_Home; function Config_Home return String renames Get_Config_Home; function Cache_Home return String renames Get_Cache_Home; function Runtime_Dir return String is begin if EV.Exists ("XDG_RUNTIME_DIR") then declare Value: constant String := EV.Value ("XDG_RUNTIME_DIR"); begin if Value (Value'Last) = Sep then return Value; else return Value & Sep; end if; end; else return ""; end if; end Runtime_Dir; function Data_Dirs return String is begin if EV.Exists ("XDG_DATA_DIRS") then return EV.Value ("XDG_DATA_DIRS"); else return XDG.Defaults.Data_Dirs; end if; end Data_Dirs; function Config_Dirs return String is begin if EV.Exists ("XDG_CONFIG_DIRS") then return EV.Value ("XDG_CONFIG_DIRS"); else return XDG.Defaults.Config_Dirs; end if; end Config_Dirs; ---------------------------------------------------------------------------- generic with function XDG_Path return String; function XDG_Home (Directory: in String) return String; function XDG_Home (Directory: in String) return String is Path: constant String := XDG_Path; begin if Path (Path'Last) = Sep then if Directory (Directory'Last) = Sep then return Path & Directory; else return Path & Directory & Sep; end if; else if Directory (Directory'Last) = Sep then return Path & Sep & Directory; else return Path & Sep & Directory & Sep; end if; end if; end XDG_Home; function Data_Home_Path is new XDG_Home (Data_Home); function Config_Home_Path is new XDG_Home (Config_Home); function Cache_Home_Path is new XDG_Home (Cache_Home); function Data_Home (Directory: in String) return String renames Data_Home_Path; function Config_Home (Directory: in String) return String renames Config_Home_Path; function Cache_Home (Directory: in String) return String renames Cache_Home_Path; function Runtime_Dir (Directory: in String) return String is Path: constant String := Runtime_Dir; begin if Path'Length = 0 then raise No_Runtime_Dir; elsif Directory (Directory'Last) = Sep then return Path & Directory; else return Path & Directory & Sep; end if; end Runtime_Dir; ---------------------------------------------------------------------------- generic with function XDG_Path (Directory: in String) return String; procedure Create_Home (Directory: in String); procedure Create_Home (Directory: in String) is package AD renames Ada.Directories; Path: constant String := XDG_Path (Directory); begin AD.Create_Path (Path); end Create_Home; procedure Create_Data is new Create_Home (Data_Home); procedure Create_Config is new Create_Home (Config_Home); procedure Create_Cache is new Create_Home (Cache_Home); procedure Create_Runtime is new Create_Home (Runtime_Dir); procedure Create_Data_Home (Directory: in String) renames Create_Data; procedure Create_Config_Home (Directory: in String) renames Create_Config; procedure Create_Cache_Home (Directory: in String) renames Create_Cache; procedure Create_Runtime_Dir (Directory: in String) renames Create_Runtime; ---------------------------------------------------------------------------- generic with function XDG_Path (Directory: in String) return String; procedure Delete_Home (Directory: in String; Empty_Only: in Boolean := True); procedure Delete_Home (Directory: in String; Empty_Only: in Boolean := True) is package AD renames Ada.Directories; Path: constant String := XDG_Path (Directory); begin if Empty_Only then AD.Delete_Directory (Path); else AD.Delete_Tree (Path); end if; end Delete_Home; procedure Delete_Data is new Delete_Home (Data_Home); procedure Delete_Config is new Delete_Home (Config_Home); procedure Delete_Cache is new Delete_Home (Cache_Home); procedure Delete_Runtime is new Delete_Home (Runtime_Dir); procedure Delete_Data_Home ( Directory : in String; Empty_Only: in Boolean := True ) renames Delete_Data; procedure Delete_Config_Home ( Directory : in String; Empty_Only: in Boolean := True ) renames Delete_Config; procedure Delete_Cache_Home ( Directory : in String; Empty_Only: in Boolean := True ) renames Delete_Cache; procedure Delete_Runtime_Dir ( Directory : in String; Empty_Only: in Boolean := True ) renames Delete_Runtime; ---------------------------------------------------------------------------- generic with function XDG_Home (Directory: in String) return String; function Check_Home (Directory: in String) return Boolean; function Check_Home (Directory: in String) return Boolean is package AD renames Ada.Directories; use type AD.File_Kind; Path: constant String := XDG_Home (Directory); begin if AD.Exists (Path) and then AD.Kind (Path) /= AD.Directory then return False; else return True; end if; end Check_Home; function Check_Data_Home is new Check_Home (Data_Home); function Check_Config_Home is new Check_Home (Config_Home); function Check_Cache_Home is new Check_Home (Cache_Home); function Check_Runtime_Dir is new Check_Home (Runtime_Dir); function Is_Valid_Data_Home (Directory: in String) return Boolean renames Check_Data_Home; function Is_Valid_Config_Home (Directory: in String) return Boolean renames Check_Config_Home; function Is_Valid_Cache_Home (Directory: in String) return Boolean renames Check_Cache_Home; function Is_Valid_Runtime_Dir (Directory: in String) return Boolean renames Check_Runtime_Dir; ---------------------------------------------------------------------------- end XDG;
----------------------------------------------------------------------- -- ado-cache-discrete -- Simple cache management for discrete types -- Copyright (C) 2017 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- package body ADO.Caches.Discrete is -- ------------------------------ -- Expand the name into a target parameter value to be used in the SQL query. -- The Expander can return a T_NULL when a value is not found or -- it may also raise some exception. -- ------------------------------ overriding function Expand (Instance : in out Cache_Type; Name : in String) return ADO.Parameters.Parameter is Value : Element_Type; begin Value := Instance.Find (Name); return ADO.Parameters.Parameter '(T => ADO.Parameters.T_LONG_INTEGER, Len => 0, Value_Len => 0, Position => 0, Name => "", Long_Num => Element_Type'Pos (Value)); end Expand; -- ------------------------------ -- Find the value associated with the given name. -- Raises the No_Value exception if no such mapping exist. -- ------------------------------ function Find (Cache : in out Cache_Type; Name : in String) return Element_Type is begin return Cache.Controller.Find (Name); end Find; -- ------------------------------ -- Insert the value associated with the given name in the cache. -- When <tt>Override</tt> is set, override existing values otherwise raise an exception. -- ------------------------------ procedure Insert (Cache : in out Cache_Type; Name : in String; Value : in Element_Type; Override : in Boolean := False) is begin Cache.Controller.Insert (Name, Value, Override); end Insert; -- ------------------------------ -- Delete the value associated with the given name in the cache. -- Raise the No_Value exception if the value is not found and <tt>Ignore</tt> is not set. -- ------------------------------ procedure Delete (Cache : in out Cache_Type; Name : in String; Ignore : in Boolean := False) is begin Cache.Controller.Delete (Name, Ignore); end Delete; -- ------------------------------ -- Initialize the entity cache by reading the database entity table. -- ------------------------------ procedure Initialize (Cache : in out Cache_Type; Session : in out ADO.Sessions.Session'Class) is begin null; end Initialize; protected body Cache_Controller is -- ------------------------------ -- Find the value associated with the given name. -- Raises the No_Value exception if no such mapping exist. -- ------------------------------ function Find (Name : in String) return Element_Type is Pos : constant Cache_Map.Cursor := Values.Find (Name); begin if Cache_Map.Has_Element (Pos) then return Cache_Map.Element (Pos); else Log.Info ("Unknown cached value {0}", Name); raise No_Value with "Value '" & Name & "' not found"; end if; end Find; -- ------------------------------ -- Insert the value associated with the given name in the cache. -- When <tt>Override</tt> is set, override existing values otherwise raise an exception. -- ------------------------------ procedure Insert (Name : in String; Value : in Element_Type; Override : in Boolean := False) is Pos : constant Cache_Map.Cursor := Values.Find (Name); begin if Cache_Map.Has_Element (Pos) then if not Override then raise No_Value; end if; Values.Replace_Element (Pos, Value); else Values.Insert (Name, Value); end if; end Insert; -- ------------------------------ -- Delete the value associated with the given name in the cache. -- Raise the No_Value exception if the value is not found and <tt>Ignore</tt> is not set. -- ------------------------------ procedure Delete (Name : in String; Ignore : in Boolean := False) is Pos : Cache_Map.Cursor := Values.Find (Name); begin if Cache_Map.Has_Element (Pos) then Values.Delete (Pos); elsif not Ignore then raise No_Value; end if; end Delete; end Cache_Controller; end ADO.Caches.Discrete;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2015, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- This program demonstrates the on-board "independent watchdog" provided by -- the STM32F4 family. -- Generally you will have to cycle power to the board before downloading -- (flashing) this program. Otherwise it will not run after flashing, and may -- not successfully finish the flash step itself. In this case the on-board -- Reset button will not suffice. -- The program first blinks all the LEDs on and off three times to signal -- initial execution. It then blinks the green LED indefinitely, also -- resetting the watchdog so that the board is not reset. If you see all the -- LEDs blink after initial power-up you know that the board has been reset -- by the watchdog. That makes it easy to experiment with the watchdog's -- parameters. with Last_Chance_Handler; pragma Unreferenced (Last_Chance_Handler); with STM32.IWDG; use STM32.IWDG; with Ada.Real_Time; use Ada.Real_Time; with STM32.Board; use STM32.Board; procedure Demo_IWDG is Watchdog_Count : constant := 4095; -- arbitrary -- The clock driving the watchdog downcounter is approximately 32KHz, so -- dividing by 32 gives about 1 millisecond per count. Thus the count gives -- approximately that many milliseconds before the system reset interrupt -- is triggered. Feel free to experiment with this value. Watchdog_Count_Offset : constant := -90; -- arbitrary -- The entirely arbitrary amount to add/subtract to the watchdog count, ie -- the time that causes a board reset, in order to experiment with causing -- the reset to occur. This value is added to the Watchdog_Count and the -- result passed to Do_Work, thereby controlling whether the watchdog timer -- trips or not. Feel free to experiment with this value. Work_Time : constant := Watchdog_Count + Watchdog_Count_Offset; -- The value passed to Do_Work which determines the amount of time taken by -- that call. By changing the value of Watchdog_Count_Offset you can cause -- the reset to occur, or not. Note that optimization will have influence. procedure Do_Work (Time_Required : Time_Span); -- A simple abstraction for some amount of work to be done while the -- watchdog is running. The Time_Required parameter controls how long the -- "work" should take, so that you can experiment with causing the reset -- to occur by giving it a value close to the watchdog timeout interval. procedure Do_Work (Time_Required : Time_Span) is Interval : constant Time_Span := Time_Required / 4; -- We divide so that we can blink more often begin Turn_On (Green_LED); delay until Clock + Interval; Turn_Off (Green_LED); delay until Clock + Interval; Turn_On (Green_LED); delay until Clock + Interval; Turn_Off (Green_LED); delay until Clock + Interval; end Do_Work; begin Initialize_LEDs; Initialize_Watchdog (Prescaler => Divider_32, Count => Watchdog_Count); -- Indicate initial excution, but also indicate board (program) reset for K in 1 .. 3 loop All_LEDs_On; delay until Clock + Milliseconds (200); All_LEDs_Off; delay until Clock + Milliseconds (200); end loop; Start_Watchdog; loop Do_Work (Time_Required => Milliseconds (Work_Time)); -- If Do_Work does not return in time so that the call to reset the -- watchdog can occur, the board will reset and the program will -- restart. Reset_Watchdog; end loop; end Demo_IWDG;
-- Copyright (c) 2010 - 2018, Nordic Semiconductor ASA -- -- 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, except as embedded into a Nordic -- Semiconductor ASA integrated circuit in a product or a software update for -- such product, 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 Nordic Semiconductor ASA nor the names of its -- contributors may be used to endorse or promote products derived from this -- software without specific prior written permission. -- -- 4. This software, with or without modification, must only be used with a -- Nordic Semiconductor ASA integrated circuit. -- -- 5. Any software provided in binary form under this license must not be reverse -- engineered, decompiled, modified and/or disassembled. -- -- THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS -- OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -- OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE -- DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE -- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- This spec has been automatically generated from nrf52.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package NRF_SVD.SPI is pragma Preelaborate; --------------- -- Registers -- --------------- -- Write '1' to Enable interrupt for READY event type INTENSET_READY_Field is (-- Read: Disabled Disabled, -- Read: Enabled Enabled) with Size => 1; for INTENSET_READY_Field use (Disabled => 0, Enabled => 1); -- Write '1' to Enable interrupt for READY event type INTENSET_READY_Field_1 is (-- Reset value for the field Intenset_Ready_Field_Reset, -- Enable Set) with Size => 1; for INTENSET_READY_Field_1 use (Intenset_Ready_Field_Reset => 0, Set => 1); -- Enable interrupt type INTENSET_Register is record -- unspecified Reserved_0_1 : HAL.UInt2 := 16#0#; -- Write '1' to Enable interrupt for READY event READY : INTENSET_READY_Field_1 := Intenset_Ready_Field_Reset; -- unspecified Reserved_3_31 : HAL.UInt29 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for INTENSET_Register use record Reserved_0_1 at 0 range 0 .. 1; READY at 0 range 2 .. 2; Reserved_3_31 at 0 range 3 .. 31; end record; -- Write '1' to Disable interrupt for READY event type INTENCLR_READY_Field is (-- Read: Disabled Disabled, -- Read: Enabled Enabled) with Size => 1; for INTENCLR_READY_Field use (Disabled => 0, Enabled => 1); -- Write '1' to Disable interrupt for READY event type INTENCLR_READY_Field_1 is (-- Reset value for the field Intenclr_Ready_Field_Reset, -- Disable Clear) with Size => 1; for INTENCLR_READY_Field_1 use (Intenclr_Ready_Field_Reset => 0, Clear => 1); -- Disable interrupt type INTENCLR_Register is record -- unspecified Reserved_0_1 : HAL.UInt2 := 16#0#; -- Write '1' to Disable interrupt for READY event READY : INTENCLR_READY_Field_1 := Intenclr_Ready_Field_Reset; -- unspecified Reserved_3_31 : HAL.UInt29 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for INTENCLR_Register use record Reserved_0_1 at 0 range 0 .. 1; READY at 0 range 2 .. 2; Reserved_3_31 at 0 range 3 .. 31; end record; -- Enable or disable SPI type ENABLE_ENABLE_Field is (-- Disable SPI Disabled, -- Enable SPI Enabled) with Size => 4; for ENABLE_ENABLE_Field use (Disabled => 0, Enabled => 1); -- Enable SPI type ENABLE_Register is record -- Enable or disable SPI ENABLE : ENABLE_ENABLE_Field := NRF_SVD.SPI.Disabled; -- unspecified Reserved_4_31 : HAL.UInt28 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for ENABLE_Register use record ENABLE at 0 range 0 .. 3; Reserved_4_31 at 0 range 4 .. 31; end record; subtype RXD_RXD_Field is HAL.UInt8; -- RXD register type RXD_Register is record -- Read-only. *** Reading this field has side effects on other resources -- ***. RX data received. Double buffered RXD : RXD_RXD_Field; -- unspecified Reserved_8_31 : HAL.UInt24; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for RXD_Register use record RXD at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype TXD_TXD_Field is HAL.UInt8; -- TXD register type TXD_Register is record -- TX data to send. Double buffered TXD : TXD_TXD_Field := 16#0#; -- unspecified Reserved_8_31 : HAL.UInt24 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for TXD_Register use record TXD at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- Bit order type CONFIG_ORDER_Field is (-- Most significant bit shifted out first Msbfirst, -- Least significant bit shifted out first Lsbfirst) with Size => 1; for CONFIG_ORDER_Field use (Msbfirst => 0, Lsbfirst => 1); -- Serial clock (SCK) phase type CONFIG_CPHA_Field is (-- Sample on leading edge of clock, shift serial data on trailing edge Leading, -- Sample on trailing edge of clock, shift serial data on leading edge Trailing) with Size => 1; for CONFIG_CPHA_Field use (Leading => 0, Trailing => 1); -- Serial clock (SCK) polarity type CONFIG_CPOL_Field is (-- Active high Activehigh, -- Active low Activelow) with Size => 1; for CONFIG_CPOL_Field use (Activehigh => 0, Activelow => 1); -- Configuration register type CONFIG_Register is record -- Bit order ORDER : CONFIG_ORDER_Field := NRF_SVD.SPI.Msbfirst; -- Serial clock (SCK) phase CPHA : CONFIG_CPHA_Field := NRF_SVD.SPI.Leading; -- Serial clock (SCK) polarity CPOL : CONFIG_CPOL_Field := NRF_SVD.SPI.Activehigh; -- unspecified Reserved_3_31 : HAL.UInt29 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for CONFIG_Register use record ORDER at 0 range 0 .. 0; CPHA at 0 range 1 .. 1; CPOL at 0 range 2 .. 2; Reserved_3_31 at 0 range 3 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Serial Peripheral Interface 0 type SPI_Peripheral is record -- TXD byte sent and RXD byte received EVENTS_READY : aliased HAL.UInt32; -- Enable interrupt INTENSET : aliased INTENSET_Register; -- Disable interrupt INTENCLR : aliased INTENCLR_Register; -- Enable SPI ENABLE : aliased ENABLE_Register; -- Pin select for SCK. PSELSCK : aliased HAL.UInt32; -- Pin select for MISO. PSELMISO : aliased HAL.UInt32; -- Pin select for MOSI. PSELMOSI : aliased HAL.UInt32; -- RXD register RXD : aliased RXD_Register; -- TXD register TXD : aliased TXD_Register; -- SPI frequency FREQUENCY : aliased HAL.UInt32; -- Configuration register CONFIG : aliased CONFIG_Register; end record with Volatile; for SPI_Peripheral use record EVENTS_READY at 16#108# range 0 .. 31; INTENSET at 16#304# range 0 .. 31; INTENCLR at 16#308# range 0 .. 31; ENABLE at 16#500# range 0 .. 31; PSELSCK at 16#508# range 0 .. 31; PSELMISO at 16#50C# range 0 .. 31; PSELMOSI at 16#510# range 0 .. 31; RXD at 16#518# range 0 .. 31; TXD at 16#51C# range 0 .. 31; FREQUENCY at 16#524# range 0 .. 31; CONFIG at 16#554# range 0 .. 31; end record; -- Serial Peripheral Interface 0 SPI0_Periph : aliased SPI_Peripheral with Import, Address => SPI0_Base; -- Serial Peripheral Interface 1 SPI1_Periph : aliased SPI_Peripheral with Import, Address => SPI1_Base; -- Serial Peripheral Interface 2 SPI2_Periph : aliased SPI_Peripheral with Import, Address => SPI2_Base; end NRF_SVD.SPI;
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- XML Processor -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2010-2017, Vadim Godunko <vgodunko@gmail.com> -- -- 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.SAX.Simple_Readers.Callbacks; package body XML.SAX.Simple_Readers.Analyzer is use Matreshka.Internals.XML; use Matreshka.Internals.XML.Element_Tables; use Matreshka.Internals.XML.Entity_Tables; --------------------------------------- -- Analyze_Document_Type_Declaration -- --------------------------------------- procedure Analyze_Document_Type_Declaration (Self : in out Simple_Reader'Class) is Current : Entity_Identifier; Current_Element : Element_Identifier; begin if Self.Validation.Enabled then Current := First_Entity (Self.Entities); while Current /= No_Entity loop -- [XML 4.2.2 VC: Notation Declared] -- -- "The Name MUST match the declared name of a notation." -- -- Check whether entity is unparsed and its notation is declared. if Is_External_Unparsed_General_Entity (Self.Entities, Current) and then Symbol_Tables.Notation (Self.Symbols, Notation (Self.Entities, Current)) = No_Notation then Callbacks.Call_Error (Self, League.Strings.To_Universal_String ("[XML 4.2.2 VC: Notation Declared]" & " notation name must match the declared name of a" & " notation")); end if; Next_Entity (Self.Entities, Current); end loop; end if; -- [XML 3.3] Attribute List Declaration -- -- "The Name in the AttlistDecl rule is the type of an element. At user -- option, an XML processor MAY issue a warning if attributes are -- declared for an element type not itself declared, but this is not an -- error. The Name in the AttDef rule is the name of the attribute." -- -- Check whether element is not declared and has declared attributes. Current_Element := First_Element (Self.Elements); while Current_Element /= No_Element loop if not Is_Declared (Self.Elements, Current_Element) and Is_Attributes_Declared (Self.Elements, Current_Element) then Callbacks.Call_Warning (Self, League.Strings.To_Universal_String ("[XML 3.3]" & " attribute list declaration for element type not itself" & " declared")); end if; Next_Element (Self.Elements, Current_Element); end loop; end Analyze_Document_Type_Declaration; end XML.SAX.Simple_Readers.Analyzer;
package GESTE_Fonts.FreeMonoBold8pt7b is Font : constant Bitmap_Font_Ref; private FreeMonoBold8pt7bBitmaps : aliased constant Font_Bitmap := ( 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#00#, 16#0C#, 16#03#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#36#, 16#0C#, 16#83#, 16#20#, 16#48#, 16#12#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1A#, 16#06#, 16#81#, 16#21#, 16#FE#, 16#7F#, 16#85#, 16#87#, 16#F1#, 16#FC#, 16#36#, 16#0D#, 16#83#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#30#, 16#1F#, 16#0F#, 16#C2#, 16#30#, 16#C0#, 16#3E#, 16#03#, 16#C6#, 16#11#, 16#8C#, 16#7E#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#38#, 16#09#, 16#04#, 16#40#, 16#90#, 16#3F#, 16#0E#, 16#04#, 16#E0#, 16#24#, 16#09#, 16#03#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#83#, 16#E0#, 16#C0#, 16#30#, 16#0E#, 16#06#, 16#F1#, 16#98#, 16#7F#, 16#0F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#20#, 16#08#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#00#, 16#80#, 16#60#, 16#10#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#04#, 16#01#, 16#80#, 16#60#, 16#0C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#30#, 16#0C#, 16#01#, 16#80#, 16#60#, 16#18#, 16#02#, 16#00#, 16#80#, 16#20#, 16#18#, 16#06#, 16#03#, 16#00#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#08#, 16#03#, 16#07#, 16#F0#, 16#FC#, 16#1C#, 16#0D#, 16#81#, 16#20#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#7F#, 16#9F#, 16#E0#, 16#C0#, 16#30#, 16#0C#, 16#03#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#18#, 16#06#, 16#01#, 16#00#, 16#40#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#7F#, 16#9F#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#03#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#04#, 16#03#, 16#00#, 16#80#, 16#60#, 16#18#, 16#0C#, 16#03#, 16#01#, 16#80#, 16#60#, 16#30#, 16#0C#, 16#06#, 16#01#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#78#, 16#3E#, 16#0C#, 16#C6#, 16#11#, 16#84#, 16#61#, 16#18#, 16#46#, 16#10#, 16#CC#, 16#3E#, 16#07#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1C#, 16#0F#, 16#02#, 16#C0#, 16#30#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#7F#, 16#1F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#70#, 16#7E#, 16#18#, 16#C0#, 16#30#, 16#0C#, 16#06#, 16#03#, 16#01#, 16#80#, 16#C0#, 16#7F#, 16#1F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F8#, 16#3F#, 16#00#, 16#C0#, 16#30#, 16#38#, 16#0E#, 16#00#, 16#C0#, 16#10#, 16#0C#, 16#7F#, 16#0F#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#80#, 16#A0#, 16#68#, 16#12#, 16#08#, 16#87#, 16#F1#, 16#FC#, 16#0F#, 16#03#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3F#, 16#0F#, 16#C3#, 16#00#, 16#F8#, 16#3F#, 16#00#, 16#40#, 16#11#, 16#0C#, 16#7F#, 16#0F#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1C#, 16#1F#, 16#86#, 16#03#, 16#00#, 16#F8#, 16#3F#, 16#0C#, 16#43#, 16#18#, 16#C4#, 16#1F#, 16#07#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#7F#, 16#1F#, 16#C0#, 16#30#, 16#0C#, 16#02#, 16#01#, 16#80#, 16#60#, 16#30#, 16#0C#, 16#02#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#78#, 16#3F#, 16#08#, 16#C6#, 16#10#, 16#8C#, 16#3E#, 16#0F#, 16#C6#, 16#31#, 16#8C#, 16#3F#, 16#07#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#78#, 16#3F#, 16#0C#, 16#C2#, 16#18#, 16#CE#, 16#3F#, 16#87#, 16#40#, 16#30#, 16#1C#, 16#3E#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#30#, 16#0C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#03#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#60#, 16#18#, 16#00#, 16#00#, 16#00#, 16#00#, 16#18#, 16#06#, 16#01#, 16#00#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#18#, 16#1C#, 16#1C#, 16#1C#, 16#01#, 16#C0#, 16#1C#, 16#01#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#FE#, 16#7F#, 16#80#, 16#07#, 16#F9#, 16#FE#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#00#, 16#E0#, 16#1E#, 16#01#, 16#E0#, 16#E0#, 16#E0#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1E#, 16#0F#, 16#C2#, 16#30#, 16#0C#, 16#0E#, 16#03#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#03#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#70#, 16#3E#, 16#0C#, 16#C6#, 16#11#, 16#9C#, 16#4F#, 16#12#, 16#44#, 16#91#, 16#BC#, 16#67#, 16#08#, 16#03#, 16#F0#, 16#78#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#7C#, 16#1F#, 16#01#, 16#E0#, 16#58#, 16#36#, 16#0C#, 16#C7#, 16#F1#, 16#FE#, 16#F3#, 16#FC#, 16#F0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FE#, 16#3F#, 16#C6#, 16#11#, 16#84#, 16#7F#, 16#1F#, 16#C6#, 16#19#, 16#86#, 16#FF#, 16#BF#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1F#, 16#8F#, 16#E6#, 16#19#, 16#00#, 16#40#, 16#10#, 16#04#, 16#01#, 16#80#, 16#3F#, 16#87#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FE#, 16#3F#, 16#C6#, 16#31#, 16#86#, 16#61#, 16#98#, 16#66#, 16#19#, 16#8C#, 16#FF#, 16#3F#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FF#, 16#3F#, 16#C6#, 16#11#, 16#90#, 16#7C#, 16#1F#, 16#06#, 16#59#, 16#86#, 16#FF#, 16#BF#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FF#, 16#BF#, 16#E6#, 16#19#, 16#90#, 16#7C#, 16#1F#, 16#06#, 16#41#, 16#80#, 16#FC#, 16#3F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1F#, 16#8F#, 16#E6#, 16#19#, 16#00#, 16#40#, 16#11#, 16#E4#, 16#79#, 16#86#, 16#7F#, 16#87#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#77#, 16#9D#, 16#E2#, 16#10#, 16#84#, 16#3F#, 16#0F#, 16#C2#, 16#10#, 16#84#, 16#F7#, 16#BD#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#7F#, 16#1F#, 16#C0#, 16#C0#, 16#30#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#7F#, 16#1F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1F#, 16#C7#, 16#F0#, 16#30#, 16#0C#, 16#03#, 16#00#, 16#C4#, 16#31#, 16#0C#, 16#7E#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FB#, 16#BE#, 16#E6#, 16#71#, 16#B0#, 16#7C#, 16#1F#, 16#86#, 16#61#, 16#8C#, 16#FB#, 16#FE#, 16#70#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#7C#, 16#1F#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#0C#, 16#03#, 16#08#, 16#C2#, 16#7F#, 16#9F#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E1#, 16#F8#, 16#F7#, 16#39#, 16#CE#, 16#5F#, 16#97#, 16#64#, 16#D9#, 16#06#, 16#F3#, 16#FC#, 16#F0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E7#, 16#BD#, 16#E7#, 16#19#, 16#E6#, 16#7D#, 16#9B#, 16#66#, 16#79#, 16#9E#, 16#F3#, 16#BC#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1E#, 16#0F#, 16#C6#, 16#39#, 16#06#, 16#C0#, 16#B0#, 16#24#, 16#19#, 16#8E#, 16#3F#, 16#07#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FE#, 16#3F#, 16#C6#, 16#31#, 16#84#, 16#63#, 16#1F#, 16#C7#, 16#E1#, 16#80#, 16#FC#, 16#3F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1E#, 16#0F#, 16#C6#, 16#39#, 16#06#, 16#C0#, 16#B0#, 16#24#, 16#19#, 16#8E#, 16#3F#, 16#07#, 16#83#, 16#F8#, 16#FE#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FE#, 16#3F#, 16#C6#, 16#31#, 16#8C#, 16#7F#, 16#1F#, 16#86#, 16#61#, 16#8C#, 16#F1#, 16#FC#, 16#70#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1F#, 16#0F#, 16#C6#, 16#11#, 16#80#, 16#3E#, 16#07#, 16#C0#, 16#31#, 16#86#, 16#7F#, 16#17#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#7F#, 16#9F#, 16#E4#, 16#D9#, 16#36#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#3F#, 16#0F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F7#, 16#BD#, 16#E6#, 16#11#, 16#84#, 16#61#, 16#18#, 16#46#, 16#11#, 16#8C#, 16#3F#, 16#07#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F3#, 16#FC#, 16#F6#, 16#19#, 16#84#, 16#33#, 16#0C#, 16#81#, 16#60#, 16#78#, 16#1C#, 16#03#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F3#, 16#FC#, 16#F4#, 16#19#, 16#36#, 16#6D#, 16#9F#, 16#E7#, 16#71#, 16#DC#, 16#73#, 16#0C#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F3#, 16#BC#, 16#E3#, 16#30#, 16#78#, 16#1C#, 16#07#, 16#03#, 16#60#, 16#CC#, 16#F3#, 16#BC#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F3#, 16#BC#, 16#E3#, 16#30#, 16#D8#, 16#1C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#3F#, 16#0F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3F#, 16#0F#, 16#C2#, 16#30#, 16#98#, 16#0C#, 16#06#, 16#03#, 16#10#, 16#C4#, 16#7F#, 16#1F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#03#, 16#80#, 16#C0#, 16#30#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#0C#, 16#03#, 16#00#, 16#F0#, 16#3C#, 16#00#, 16#00#, 16#00#, 16#01#, 16#80#, 16#20#, 16#0C#, 16#01#, 16#00#, 16#60#, 16#08#, 16#03#, 16#00#, 16#C0#, 16#18#, 16#06#, 16#00#, 16#C0#, 16#30#, 16#04#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3C#, 16#0F#, 16#00#, 16#C0#, 16#30#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#0C#, 16#03#, 16#03#, 16#C0#, 16#F0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#08#, 16#07#, 16#01#, 16#E0#, 16#CC#, 16#61#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#FF#, 16#00#, 16#00#, 16#00#, 16#00#, 16#40#, 16#18#, 16#03#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F8#, 16#7F#, 16#0F#, 16#C7#, 16#F1#, 16#8C#, 16#7F#, 16#8F#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E0#, 16#38#, 16#06#, 16#01#, 16#F8#, 16#7F#, 16#18#, 16#66#, 16#09#, 16#86#, 16#FF#, 16#3F#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#7E#, 16#7F#, 16#98#, 16#64#, 16#01#, 16#82#, 16#7F#, 16#87#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#80#, 16#E0#, 16#18#, 16#F6#, 16#7F#, 16#98#, 16#E4#, 16#19#, 16#8E#, 16#7F#, 16#CF#, 16#70#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#78#, 16#7F#, 16#18#, 16#47#, 16#F9#, 16#FE#, 16#7F#, 16#8F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0F#, 16#87#, 16#E1#, 16#81#, 16#FC#, 16#7F#, 16#06#, 16#01#, 16#80#, 16#60#, 16#7F#, 16#1F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F6#, 16#7F#, 16#98#, 16#C4#, 16#11#, 16#8C#, 16#7F#, 16#0F#, 16#40#, 16#30#, 16#FC#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E0#, 16#38#, 16#02#, 16#00#, 16#B8#, 16#3F#, 16#0C#, 16#C2#, 16#10#, 16#84#, 16#F7#, 16#BD#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#18#, 16#06#, 16#00#, 16#00#, 16#F0#, 16#3C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#7F#, 16#9F#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#03#, 16#00#, 16#00#, 16#F8#, 16#3E#, 16#00#, 16#80#, 16#20#, 16#08#, 16#02#, 16#00#, 16#80#, 16#21#, 16#F8#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#60#, 16#18#, 16#02#, 16#00#, 16#9C#, 16#27#, 16#0B#, 16#03#, 16#80#, 16#B8#, 16#67#, 16#99#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3C#, 16#0F#, 16#00#, 16#C0#, 16#30#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#7F#, 16#9F#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#EC#, 16#FF#, 16#93#, 16#64#, 16#D9#, 16#36#, 16#ED#, 16#FB#, 16#F0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#B8#, 16#7F#, 16#08#, 16#C2#, 16#10#, 16#84#, 16#F3#, 16#BC#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#78#, 16#7F#, 16#18#, 16#64#, 16#19#, 16#86#, 16#7F#, 16#07#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#B8#, 16#FF#, 16#98#, 16#66#, 16#09#, 16#86#, 16#7F#, 16#9B#, 16#86#, 16#03#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#F7#, 16#7F#, 16#F0#, 16#CC#, 16#13#, 16#8C#, 16#7F#, 16#0F#, 16#40#, 16#10#, 16#1F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#CE#, 16#7F#, 16#87#, 16#01#, 16#00#, 16#40#, 16#7F#, 16#1F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#7C#, 16#3F#, 16#18#, 16#43#, 16#F1#, 16#84#, 16#7F#, 16#1F#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#08#, 16#02#, 16#03#, 16#F8#, 16#FE#, 16#08#, 16#02#, 16#00#, 16#84#, 16#3F#, 16#07#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#9C#, 16#E7#, 16#08#, 16#42#, 16#10#, 16#8C#, 16#3F#, 16#8F#, 16#60#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#DF#, 16#F7#, 16#C8#, 16#C3#, 16#20#, 16#58#, 16#1C#, 16#03#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#CE#, 16#E3#, 16#DB#, 16#67#, 16#D0#, 16#FC#, 16#37#, 16#0C#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#DE#, 16#73#, 16#87#, 16#81#, 16#C0#, 16#F8#, 16#73#, 16#BD#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#CE#, 16#F3#, 16#98#, 16#C3#, 16#30#, 16#58#, 16#1C#, 16#03#, 16#01#, 16#83#, 16#F0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#FC#, 16#3F#, 16#09#, 16#80#, 16#C0#, 16#E0#, 16#7F#, 16#1F#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#03#, 16#80#, 16#C0#, 16#30#, 16#0C#, 16#0E#, 16#03#, 16#80#, 16#30#, 16#0C#, 16#03#, 16#00#, 16#E0#, 16#18#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#0C#, 16#03#, 16#00#, 16#C0#, 16#30#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#38#, 16#0E#, 16#00#, 16#C0#, 16#30#, 16#0C#, 16#03#, 16#80#, 16#E0#, 16#30#, 16#0C#, 16#03#, 16#03#, 16#80#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#E0#, 16#7C#, 16#03#, 16#E0#, 16#70#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#); Font_D : aliased constant Bitmap_Font := ( Bytes_Per_Glyph => 20, Glyph_Width => 10, Glyph_Height => 16, Data => FreeMonoBold8pt7bBitmaps'Access); Font : constant Bitmap_Font_Ref := Font_D'Access; end GESTE_Fonts.FreeMonoBold8pt7b;
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- -- Trivial implementation of subunits with Program.Subunits; with Program.Compilation_Unit_Vectors; with Program.Units.Vectors; package Program.Units.Subunits is pragma Preelaborate; type Subunit is new Unit and Program.Subunits.Subunit with private; procedure Initialize (Self : in out Subunit; Compilation : Program.Compilations.Compilation_Access; Full_Name : Text; Context_Clause : Program.Element_Vectors.Element_Vector_Access; Unit_Declaration : not null Program.Elements.Element_Access; Parent_Body : not null Program.Compilation_Units .Compilation_Unit_Access); procedure Append_Subunit (Self : in out Subunit; Value : Program.Compilation_Units.Compilation_Unit_Access); private type Subunit is new Unit and Program.Subunits.Subunit with record Subunits : aliased Program.Units.Vectors.Unit_Vector; Parent_Body : Program.Compilation_Units.Compilation_Unit_Access; end record; overriding function Subunits (Self : access Subunit) return Program.Compilation_Unit_Vectors.Compilation_Unit_Vector_Access; overriding function Parent_Body (Self : access Subunit) return not null Program.Compilation_Units.Compilation_Unit_Access; end Program.Units.Subunits;
with Sodium.Functions; use Sodium.Functions; with Ada.Text_IO; use Ada.Text_IO; procedure Demo_Ada is FF : constant Character := Character'Val (255); n1 : String (1 .. 3) := (others => ASCII.NUL); n2 : String (1 .. 3) := (others => FF); n3 : String (1 .. 3) := (3 => Character'Val (254), others => ASCII.NUL); n4 : String (1 .. 3) := (3 => FF, others => ASCII.NUL); n5 : String (1 .. 3) := (1 => Character'Val (5), 2 => FF, 3 => FF); n6 : Box_Nonce; n7 : Symmetric_Nonce; begin if not initialize_sodium_library then Put_Line ("Initialization failed"); return; end if; n6 := Random_Nonce; n7 := Random_Symmetric_Nonce; Put_Line ("N1: " & As_Hexidecimal (n1)); increment_nonce (n1); Put_Line ("+1: " & As_Hexidecimal (n1)); Put_Line (""); Put_Line ("N2: " & As_Hexidecimal (n2)); increment_nonce (n2); Put_Line ("+1: " & As_Hexidecimal (n2)); Put_Line (""); Put_Line ("N3: " & As_Hexidecimal (n3)); increment_nonce (n3); Put_Line ("+1: " & As_Hexidecimal (n3)); Put_Line (""); Put_Line ("N4: " & As_Hexidecimal (n4)); increment_nonce (n4); Put_Line ("+1: " & As_Hexidecimal (n4)); Put_Line (""); Put_Line ("N5: " & As_Hexidecimal (n5)); increment_nonce (n5); Put_Line ("+1: " & As_Hexidecimal (n5)); Put_Line (""); Put_Line ("N6: " & As_Hexidecimal (n6)); increment_nonce (n6); Put_Line ("+1: " & As_Hexidecimal (n6)); Put_Line (""); Put_Line ("N7: " & As_Hexidecimal (n7)); increment_nonce (n7); Put_Line ("+1: " & As_Hexidecimal (n7)); end Demo_Ada;
----------------------------------------------------------------------- -- GtkAda - Ada95 binding for Gtk+/Gnome -- -- -- -- Copyright (C) 2010, AdaCore -- -- -- -- This library is free software; you can redistribute it and/or -- -- modify it under the terms of the GNU General Public -- -- License as published by the Free Software Foundation; either -- -- version 2 of the License, or (at your option) any later version. -- -- -- -- This library is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- -- General Public License for more details. -- -- -- -- You should have received a copy of the GNU General Public -- -- License along with this library; if not, write to the -- -- Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- -- Boston, MA 02111-1307, USA. -- -- -- ----------------------------------------------------------------------- with Interfaces.C.Strings; use Interfaces.C.Strings; with System; use System; package body Gtk.Builder is ------------- -- Gtk_New -- ------------- procedure Gtk_New (Builder : out Gtk_Builder) is begin Builder := new Gtk_Builder_Record; Gtk.Builder.Initialize (Builder); end Gtk_New; ------------------- -- Add_From_File -- ------------------- function Add_From_File (Builder : access Gtk_Builder_Record; Filename : String) return Glib.Error.GError is function Internal (Builder : System.Address; Filename : String; Error : access Glib.Error.GError) return Guint; pragma Import (C, Internal, "gtk_builder_add_from_file"); Err : aliased Glib.Error.GError; begin if Internal (Get_Object (Builder), Filename & ASCII.NUL, Err'Access) = 0 then return Err; else return null; end if; end Add_From_File; --------------------- -- Add_From_String -- --------------------- function Add_From_String (Builder : access Gtk_Builder_Record; Buffer : String; Length : Gsize) return Glib.Error.GError is function Internal (Builder : System.Address; Buffer : String; Length : Gsize; Error : access Glib.Error.GError) return Guint; pragma Import (C, Internal, "gtk_builder_add_from_string"); Err : aliased Glib.Error.GError; begin if Internal (Get_Object (Builder), Buffer & ASCII.NUL, Length, Err'Access) = 0 then return Err; else return null; end if; end Add_From_String; -------------------------- -- Connect_Signals_Full -- -------------------------- procedure Connect_Signals_Full (Builder : access Gtk_Builder_Record; Signal_Function : Gtk_Builder_Connect_Func; User_Data : System.Address) is procedure Internal (Builder : System.Address; Handler_Function : Gtk_Builder_Connect_Func; User_Data : System.Address); pragma Import (C, Internal, "gtk_builder_connect_signals_full"); begin Internal (Glib.Object.Get_Object (Builder), Signal_Function, User_Data); end Connect_Signals_Full; ---------------- -- Get_Object -- ---------------- function Get_Object (Builder : access Gtk_Builder_Record; Object_Name : String) return Glib.Object.GObject is function Internal (Builder : System.Address; Object_Name : String) return System.Address; pragma Import (C, Internal, "gtk_builder_get_object"); Addr : System.Address; begin Addr := Internal (Glib.Object.Get_Object (Builder), Object_Name & ASCII.NUL); if Addr /= System.Null_Address then return Glib.Object.Convert (Addr); else return null; end if; end Get_Object; ---------------- -- Initialize -- ---------------- procedure Initialize (Builder : access Gtk_Builder_Record'Class) is function Internal return System.Address; pragma Import (C, Internal, "gtk_builder_new"); begin Set_Object (Builder, Internal); end Initialize; ---------------- -- Get_Widget -- ---------------- function Get_Widget (Builder : access Gtk_Builder_Record; Name : String) return Gtk.Widget.Gtk_Widget is Object : constant GObject := Get_Object (Builder, Name); begin if Object = null then return null; else return Gtk.Widget.Convert (Glib.Object.Convert (Object)); end if; end Get_Widget; end Gtk.Builder;
-- -- Copyright (C) 2016-2017 secunet Security Networks AG -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- with HW.GFX.GMA.Config; with HW.GFX.GMA.Registers; with HW.GFX.GMA.Config_Helpers; package body HW.GFX.GMA.Port_Detect is DDI_BUF_CTL_A_LANE_CAPABILITY_X4 : constant := 1 * 2 ** 4; SFUSE_STRAP_CRT_DAC_CAP_DISABLE : constant := 1 * 2 ** 6; HOTPLUG_CTL_DDI_A_HPD_INPUT_ENABLE : constant := 1 * 2 ** 4; HOTPLUG_CTL_DDI_A_HPD_STATUS : constant := 3 * 2 ** 0; HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT : constant := 1 * 2 ** 1; SHOTPLUG_CTL_DETECT_MASK : constant := 16#0303_0303#; type Digital_Port_Value is array (Digital_Port) of Word32; DDI_PORT_DETECTED : constant Digital_Port_Value := (DIGI_B => 1 * 2 ** 2, DIGI_C => 1 * 2 ** 1, DIGI_D => 1 * 2 ** 0, DIGI_A => 1 * 2 ** 0, others => 0); SHOTPLUG_CTL_HPD_INPUT_ENABLE : constant Digital_Port_Value := (DIGI_B => 1 * 2 ** 4, DIGI_C => 1 * 2 ** 12, DIGI_D => 1 * 2 ** 20, DIGI_A => 1 * 2 ** 28, others => 0); SHOTPLUG_CTL_HPD_STATUS : constant Digital_Port_Value := (DIGI_B => 3 * 2 ** 0, DIGI_C => 3 * 2 ** 8, DIGI_D => 3 * 2 ** 16, DIGI_A => 3 * 2 ** 24, others => 0); SHOTPLUG_CTL_LONG_DETECT : constant Digital_Port_Value := (DIGI_B => 1 * 2 ** 1, DIGI_C => 1 * 2 ** 9, DIGI_D => 1 * 2 ** 17, DIGI_A => 1 * 2 ** 25, others => 0); procedure Initialize is DDI_A_X4, DAC_Disabled, Internal_Detected, DDI_Detected : Boolean; subtype Ext_Digital_Port is Digital_Port range DIGI_B .. DIGI_D; type Digital_Port_To_GMA_Port is array (Ext_Digital_Port) of Port_Type; To_HDMI_Port : constant Digital_Port_To_GMA_Port := (DIGI_B => HDMI1, DIGI_C => HDMI2, DIGI_D => HDMI3); To_DP_Port : constant Digital_Port_To_GMA_Port := (DIGI_B => DP1, DIGI_C => DP2, DIGI_D => DP3); begin if Config.Has_DDI_E and Config.Has_PCH_DAC then -- PCH_DAC (_A) Registers.Is_Set_Mask (Register => Registers.DDI_BUF_CTL_A, Mask => DDI_BUF_CTL_A_LANE_CAPABILITY_X4, Result => DDI_A_X4); Registers.Is_Set_Mask (Register => Registers.SFUSE_STRAP, Mask => SFUSE_STRAP_CRT_DAC_CAP_DISABLE, Result => DAC_Disabled); Config.Valid_Port (Analog) := not (DDI_A_X4 or DAC_Disabled); end if; if Config.Internal_Is_EDP then -- DDI_A if Config.Has_Presence_Straps then Registers.Is_Set_Mask (Register => Registers.DDI_BUF_CTL_A, Mask => DDI_PORT_DETECTED (DIGI_A), Result => Internal_Detected); else Internal_Detected := True; -- XXX: Linux' i915 contains a fixme. end if; if Internal_Detected then if Config.Has_HOTPLUG_CTL then Registers.Set_Mask (Register => Registers.HOTPLUG_CTL, Mask => HOTPLUG_CTL_DDI_A_HPD_INPUT_ENABLE or HOTPLUG_CTL_DDI_A_HPD_STATUS); -- clear status if Config.Has_SHOTPLUG_CTL_A then -- Have to enable south hotplug too on SoCs. Registers.Unset_And_Set_Mask (Register => Registers.SHOTPLUG_CTL, Mask_Unset => SHOTPLUG_CTL_DETECT_MASK, Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A)); end if; else Registers.Unset_And_Set_Mask (Register => Registers.SHOTPLUG_CTL, Mask_Unset => SHOTPLUG_CTL_DETECT_MASK, Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A) or SHOTPLUG_CTL_HPD_STATUS (DIGI_A)); -- clear end if; end if; else Internal_Detected := False; end if; Config.Valid_Port (Internal) := Internal_Detected; -- DDI_[BCD] for Port in Ext_Digital_Port range DIGI_B .. Ext_Digital_Port'Min (DIGI_D, Config.Last_Digital_Port) loop if Config.Has_Presence_Straps then Registers.Is_Set_Mask (Register => Registers.SFUSE_STRAP, Mask => DDI_PORT_DETECTED (Port), Result => DDI_Detected); else DDI_Detected := True; end if; Config.Valid_Port (To_HDMI_Port (Port)) := Config.Valid_Port (To_HDMI_Port (Port)) and DDI_Detected; Config.Valid_Port (To_DP_Port (Port)) := Config.Valid_Port (To_DP_Port (Port)) and DDI_Detected; if DDI_Detected then Registers.Unset_And_Set_Mask (Register => Registers.SHOTPLUG_CTL, Mask_Unset => SHOTPLUG_CTL_DETECT_MASK, Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port) or SHOTPLUG_CTL_HPD_STATUS (Port)); -- clear status else Registers.Unset_Mask (Register => Registers.SHOTPLUG_CTL, Mask => SHOTPLUG_CTL_DETECT_MASK or SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port)); end if; end loop; end Initialize; procedure Hotplug_Detect (Port : in Active_Port_Type; Detected : out Boolean) is Ctl32 : Word32; GPU_Port : constant GMA.GPU_Port := Config_Helpers.To_GPU_Port (Primary, Port); begin if Config.Has_HOTPLUG_CTL and then GPU_Port = DIGI_A then Registers.Read (Registers.HOTPLUG_CTL, Ctl32, Verbose => False); Detected := (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT) /= 0; if (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_STATUS) /= 0 then Registers.Set_Mask (Register => Registers.HOTPLUG_CTL, Mask => HOTPLUG_CTL_DDI_A_HPD_STATUS); end if; elsif GPU_Port in DIGI_A .. DIGI_D then Registers.Read (Registers.SHOTPLUG_CTL, Ctl32, Verbose => False); Detected := (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (GPU_Port)) /= 0; if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (GPU_Port)) /= 0 then Registers.Unset_And_Set_Mask (Register => Registers.SHOTPLUG_CTL, Mask_Unset => SHOTPLUG_CTL_DETECT_MASK, Mask_Set => SHOTPLUG_CTL_HPD_STATUS (GPU_Port)); end if; else Detected := False; end if; end Hotplug_Detect; procedure Clear_Hotplug_Detect (Port : Active_Port_Type) is Ignored_HPD : Boolean; begin pragma Warnings (GNATprove, Off, "unused assignment to ""Ignored_HPD""", Reason => "We want to clear pending events only"); Port_Detect.Hotplug_Detect (Port, Ignored_HPD); pragma Warnings (GNATprove, On, "unused assignment to ""Ignored_HPD"""); end Clear_Hotplug_Detect; end HW.GFX.GMA.Port_Detect;
with EU_Projects.Nodes.Partners; -- with EU_Projects.Identifiers; -- with EU_Projects.Costs; with EU_Projects.Nodes.Timed_Nodes.Milestones; with EU_Projects.Nodes.Action_Nodes.WPs; with EU_Projects.Nodes.Action_Nodes.Tasks; with EU_Projects.Nodes.Timed_Nodes.Deliverables; with EU_Projects.Nodes.Risks; with DOM.Core.Nodes; private package Project_Processor.Parsers.XML_Parsers.Sub_Parsers is use EU_Projects.Projects; use EU_Projects; use EU_Projects.Nodes; procedure Parse_Configuration (Project : in out Project_Descriptor; Input : in DOM.Core.Node) with Pre => DOM.Core.Nodes.Node_Name (Input) = "configuration"; function Parse_Partner (N : DoM.Core.Node) return EU_Projects.Nodes.Partners.Partner_Access; procedure Parse_Milestone (N : in DoM.Core.Node; Milestone : out Nodes.Timed_Nodes.Milestones.Milestone_Access); procedure Parse_Deliverable (Deliv_Node : in DOM.Core.Node; Deliv : out Nodes.Timed_Nodes.Deliverables.Deliverable_Access); procedure Parse_Task (Task_Node : in DOM.Core.Node; Parent_WP : in Nodes.Action_Nodes.WPs.Project_WP_Access; Descriptor : out Nodes.Action_Nodes.Tasks.Project_Task_Access); procedure Parse_WP (WP_Node : in DOM.Core.Node; WP : out Nodes.Action_Nodes.WPs.Project_WP_Access); function Parse_Risk (Risk_Node : DOM.Core.Node) return Nodes.Risks.Risk_Access; end Project_Processor.Parsers.XML_Parsers.Sub_Parsers;
-- -- Copyright 2018 The wookey project team <wookey@ssi.gouv.fr> -- - Ryad Benadjila -- - Arnauld Michelizza -- - Mathieu Renard -- - Philippe Thierry -- - Philippe Trebuchet -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- with system; package soc.exti with spark_mode => on is subtype t_exti_line_index is natural range 0 .. 22; type t_exti_trigger is (EXTI_TRIGGER_NONE, EXTI_TRIGGER_RISE, EXTI_TRIGGER_FALL, EXTI_TRIGGER_BOTH); -- Initialize EXTI by enabling SYSCFG.APB2 clock procedure init; function is_line_pending (line : t_exti_line_index) return boolean; procedure clear_pending (line : in t_exti_line_index); procedure enable (line : in t_exti_line_index); procedure disable (line : in t_exti_line_index) with inline; function is_enabled (line : in t_exti_line_index) return boolean; type t_mask is (MASKED, NOT_MASKED) with size => 1; for t_mask use (MASKED => 0, NOT_MASKED => 1); type t_masks is array (t_exti_line_index) of t_mask with volatile_components, pack, size => 23; ---------------------------------------- -- Interrupt mask register (EXTI_IMR) -- ---------------------------------------- type t_EXTI_IMR is record line : t_masks; end record with volatile_full_access, size => 32; for t_EXTI_IMR use record line at 0 range 0 .. 22; end record; ------------------------------------ -- Event mask register (EXTI_EMR) -- ------------------------------------ type t_EXTI_EMR is record line : t_masks; end record with volatile_full_access, size => 32; for t_EXTI_EMR use record line at 0 range 0 .. 22; end record; --------------------------------------------------- -- Rising trigger selection register (EXTI_RTSR) -- --------------------------------------------------- type t_trigger is (TRIGGER_DISABLED, TRIGGER_ENABLED) with size => 1; for t_trigger use (TRIGGER_DISABLED => 0, TRIGGER_ENABLED => 1); type t_triggers is array (t_exti_line_index) of t_trigger with pack, size => 23; type t_EXTI_RTSR is record line : t_triggers; end record with volatile_full_access, size => 32; for t_EXTI_RTSR use record line at 0 range 0 .. 22; end record; ---------------------------------------------------- -- Falling trigger selection register (EXTI_FTSR) -- ---------------------------------------------------- type t_EXTI_FTSR is record line : t_triggers; end record with volatile_full_access, size => 32; for t_EXTI_FTSR use record line at 0 range 0 .. 22; end record; ---------------------------------------------------- -- Software interrupt event register (EXTI_SWIER) -- ---------------------------------------------------- type t_exti_lines is array (t_exti_line_index) of bit with pack, size => 23; type t_EXTI_SWIER is record line : t_exti_lines; end record with volatile_full_access, size => 32; for t_EXTI_SWIER use record line at 0 range 0 .. 22; end record; -------------------------------- -- Pending register (EXTI_PR) -- -------------------------------- type t_request is (NO_REQUEST, PENDING_REQUEST) with size => 1; for t_request use (NO_REQUEST => 0, PENDING_REQUEST => 1); -- Set the bit to '1' to clear it! CLEAR_REQUEST : constant t_request := PENDING_REQUEST; type t_requests is array (t_exti_line_index) of t_request with pack, size => 23; type t_EXTI_PR is record line : t_requests; end record with volatile_full_access, size => 32; for t_EXTI_PR use record line at 0 range 0 .. 22; end record; --------------------- -- EXTI peripheral -- --------------------- type t_EXTI_periph is record IMR : t_EXTI_IMR; EMR : t_EXTI_EMR; RTSR : t_EXTI_RTSR; FTSR : t_EXTI_FTSR; SWIER : t_EXTI_SWIER; PR : t_EXTI_PR; end record with volatile; for t_EXTI_periph use record IMR at 16#00# range 0 .. 31; EMR at 16#04# range 0 .. 31; RTSR at 16#08# range 0 .. 31; FTSR at 16#0C# range 0 .. 31; SWIER at 16#10# range 0 .. 31; PR at 16#14# range 0 .. 31; end record; EXTI : t_EXTI_periph with import, volatile, address => system'to_address (16#4001_3C00#); -- 0x40013C00 end soc.exti;
with System.Native_Directories.File_Names; function Ada.Directories.Equal_File_Names ( FS : Volumes.File_System; Left, Right : String) return Boolean is begin return System.Native_Directories.File_Names.Equal_File_Names ( FS, Left, Right); end Ada.Directories.Equal_File_Names;
with Ada.Containers.Indefinite_Hashed_Maps; with Ada.Strings.Hash; with Ada.Environment_Variables; with Ada.Text_IO; with Ada.Strings.Unbounded; package Globals is pragma Elaborate_Body; use Ada.Strings.Unbounded; Blueprint_Folder_Name : constant String := "blueprints"; Blueprint_Default : constant String := "simple"; HTML_Filetype : constant String := "html"; Front_Matter_Prefix : constant String := "--"; Front_Matter_Separator : constant String := ":"; Posts_Source_Folder_Name : constant String := "_posts"; Pages_Folder_Name : constant String := "pages"; Layout_Folder_Name : constant String := "_layouts"; Dist_Folder_Name : constant String := "_site"; Blog_Target_Folder_Name : constant String := "blog"; Feed_filename : constant String := "rssfeed.xml"; Sitemap_filename : constant String := "sitemap.xml"; Site_Configuration_Name : constant String := "_site.cfg"; Excerpt_Separator : constant String := "<!--more-->"; type OS is (Unix, Windows); Current_OS : OS := Unix; Current_Lineending : Unbounded_String; end Globals;
with vectores; use vectores; procedure eliminar_tercer_elemento_ordenada (V: in out Vector_de_enteros) is -- pre: los elementos de la lista estan ordenados -- post: si hay tres o mas elementos, el tercer elemento quedara eliminado -- y la lista mantendra el orden Inicio: Integer; begin Inicio:=V'First+2; if V'Length >= 3 then for I in Inicio..V'Last-1 loop V(I):=V(I+1); end loop; V(V'Last):=-1; end if; end eliminar_tercer_elemento_ordenada;
with Word_List; with Ada.Containers.Vectors; package Decipherer is type Encrypted_Char is new Character; type Encrypted_Word is Array(Positive range 1 .. Word_List.Word'Last) of Encrypted_Char; type Candidate_Set is Array(Positive range <>) of Encrypted_Word; -- A mapping from the encrypted character to its partner. If the character is not in -- the input set, it will map to a period. type Result_Set is Array(Encrypted_Char range 'a' .. 'z') of Character; package Result_Vectors is new Ada.Containers.Vectors(Index_Type => Positive, Element_Type => Result_Set); subtype Result_Vector is Result_Vectors.Vector; function Image(ew: Encrypted_Word) return Word_List.Word; function Decipher(candidates: Candidate_Set; words: Word_List.Word_List) return Result_Vector; end Decipherer;
pragma Style_Checks (Off); -- This spec has been automatically generated from STM32H743x.svd pragma Restrictions (No_Elaboration_Code); with HAL; with System; package STM32_SVD.PF is pragma Preelaborate; --------------- -- Registers -- --------------- -- CLIDR_CL array element subtype CLIDR_CL_Element is HAL.UInt3; -- CLIDR_CL array type CLIDR_CL_Field_Array is array (1 .. 7) of CLIDR_CL_Element with Component_Size => 3, Size => 21; -- Type definition for CLIDR_CL type CLIDR_CL_Field (As_Array : Boolean := False) is record case As_Array is when False => -- CL as a value Val : HAL.UInt21; when True => -- CL as an array Arr : CLIDR_CL_Field_Array; end case; end record with Unchecked_Union, Size => 21; for CLIDR_CL_Field use record Val at 0 range 0 .. 20; Arr at 0 range 0 .. 20; end record; subtype CLIDR_LoUIS_Field is HAL.UInt3; subtype CLIDR_LoC_Field is HAL.UInt3; subtype CLIDR_LoU_Field is HAL.UInt3; -- Cache Level ID register type CLIDR_Register is record -- Read-only. CL1 CL : CLIDR_CL_Field; -- Read-only. LoUIS LoUIS : CLIDR_LoUIS_Field; -- Read-only. LoC LoC : CLIDR_LoC_Field; -- Read-only. LoU LoU : CLIDR_LoU_Field; -- unspecified Reserved_30_31 : HAL.UInt2; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for CLIDR_Register use record CL at 0 range 0 .. 20; LoUIS at 0 range 21 .. 23; LoC at 0 range 24 .. 26; LoU at 0 range 27 .. 29; Reserved_30_31 at 0 range 30 .. 31; end record; subtype CTR_IminLine_Field is HAL.UInt4; subtype CTR_DMinLine_Field is HAL.UInt4; subtype CTR_ERG_Field is HAL.UInt4; subtype CTR_CWG_Field is HAL.UInt4; subtype CTR_Format_Field is HAL.UInt3; -- Cache Type register type CTR_Register is record -- Read-only. IminLine IminLine : CTR_IminLine_Field; -- unspecified Reserved_4_15 : HAL.UInt12; -- Read-only. DMinLine DMinLine : CTR_DMinLine_Field; -- Read-only. ERG ERG : CTR_ERG_Field; -- Read-only. CWG CWG : CTR_CWG_Field; -- unspecified Reserved_28_28 : HAL.Bit; -- Read-only. Format Format : CTR_Format_Field; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for CTR_Register use record IminLine at 0 range 0 .. 3; Reserved_4_15 at 0 range 4 .. 15; DMinLine at 0 range 16 .. 19; ERG at 0 range 20 .. 23; CWG at 0 range 24 .. 27; Reserved_28_28 at 0 range 28 .. 28; Format at 0 range 29 .. 31; end record; subtype CCSIDR_LineSize_Field is HAL.UInt3; subtype CCSIDR_Associativity_Field is HAL.UInt10; subtype CCSIDR_NumSets_Field is HAL.UInt15; -- Cache Size ID register type CCSIDR_Register is record -- Read-only. LineSize LineSize : CCSIDR_LineSize_Field; -- Read-only. Associativity Associativity : CCSIDR_Associativity_Field; -- Read-only. NumSets NumSets : CCSIDR_NumSets_Field; -- Read-only. WA WA : Boolean; -- Read-only. RA RA : Boolean; -- Read-only. WB WB : Boolean; -- Read-only. WT WT : Boolean; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for CCSIDR_Register use record LineSize at 0 range 0 .. 2; Associativity at 0 range 3 .. 12; NumSets at 0 range 13 .. 27; WA at 0 range 28 .. 28; RA at 0 range 29 .. 29; WB at 0 range 30 .. 30; WT at 0 range 31 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Processor features type PF_Peripheral is record -- Cache Level ID register CLIDR : aliased CLIDR_Register; -- Cache Type register CTR : aliased CTR_Register; -- Cache Size ID register CCSIDR : aliased CCSIDR_Register; end record with Volatile; for PF_Peripheral use record CLIDR at 16#0# range 0 .. 31; CTR at 16#4# range 0 .. 31; CCSIDR at 16#8# range 0 .. 31; end record; -- Processor features PF_Periph : aliased PF_Peripheral with Import, Address => PF_Base; end STM32_SVD.PF;
with SDL.Video.Windows.Makers; with SDL.Video.Renderers.Makers; with SDL.Video.Palettes; with SDL.Events.Events; with SDL.Events.Keyboards; procedure Colour_Bars_Display is use type SDL.Events.Event_Types; use SDL.C; Colours : constant array (0 .. 7) of SDL.Video.Palettes.Colour := ((0, 0, 0, 255), (255, 0, 0, 255), (0, 255, 0, 255), (0, 0, 255, 255), (255, 0, 255, 255), (0, 255, 255, 255), (255, 255, 0, 255), (255, 255, 255, 255)); Window : SDL.Video.Windows.Window; Renderer : SDL.Video.Renderers.Renderer; Event : SDL.Events.Events.Events; Bar_Width : int; begin if not SDL.Initialise (Flags => SDL.Enable_Screen) then return; end if; SDL.Video.Windows.Makers.Create (Win => Window, Title => "", Position => SDL.Natural_Coordinates'(0, 0), Size => SDL.Positive_Sizes'(0, 0), Flags => SDL.Video.Windows.Full_Screen_Desktop); SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface); Bar_Width := Window.Get_Size.Width / 8; for A in Colours'Range loop Renderer.Set_Draw_Colour (Colour => Colours (A)); Renderer.Fill (Rectangle => (X => SDL.C.int (A) * Bar_Width, Y => 0, Width => Bar_Width, Height => Window.Get_Size.Height)); end loop; Window.Update_Surface; Wait_Loop : loop while SDL.Events.Events.Poll (Event) loop exit Wait_Loop when Event.Common.Event_Type = SDL.Events.Keyboards.Key_Down; end loop; delay 0.050; end loop Wait_Loop; Window.Finalize; SDL.Finalise; end Colour_Bars_Display;
with Interfaces; with GL.Types; with GA_Maths; with Blade_Types; with E3GA; with Multivectors; with Multivector_Type_Base; package C3GA is -- Vector_E3 corresponds to c3ga.vectorE3GA coordinate storage float m_c[3] subtype Vector_E3 is GL.Types.Singles.Vector3; subtype Vector_E3_Array is GL.Types.Singles.Vector3_Array; subtype MV_Type is Multivector_Type_Base.MV_Typebase; -- subtype Circle_Coords is E2GA.Coords_Continuous_Array (1 .. 10); -- subtype Dual_Plane_Coords is E2GA.Coords_Continuous_Array (1 .. 4); -- subtype Line_Coords is E2GA.Coords_Continuous_Array (1 .. 6); -- subtype Sphere_Coords is E2GA.Coords_Continuous_Array (1 .. 5); -- user constants -- __ni_ct__ ni; declared in c3ga.cpp infinitiy -- __no_ct__ no; declared in c3ga.cpp origin -- type Point is private; -- 5D conformal null vector -- type Scalar is private; -- type Vector_C3GA is private; -- subtype Point is Multivectors.Multivector; subtype Sphere is Multivectors.Multivector; subtype Dual_Sphere is Multivectors.Multivector; type Dual_Sphere_Array is array (integer range <>) of Dual_Sphere; type C3GA_Normalized_Point is array (1 .. 5) of Float; MV_Basis_Vector_Names : constant array (0 .. 4) of String (1 .. 2) := ("no", "e1", "e2", "e3", "ni"); -- MV_Basis_Elements contains the order of basis elements -- in the general multivector MV_Basis_Elements : constant array (1 .. 32, 1 .. 6) of integer := ((-1, 0, 0, 0, 0, 0), (0, -1, 0, 0, 0, 0), (1, -1, 0, 0, 0, 0), (2, -1, 0, 0, 0, 0), (3, -1, 0, 0, 0, 0), (4, -1, 0, 0, 0, 0), (0, 1, -1, 0, 0, 0), (0, 2, -1, 0, 0, 0), (0, 3, -1, 0, 0, 0), (1, 2, -1, 0, 0, 0), (2, 3, -1, 0, 0, 0), (1, 3, -1, 0, 0, 0), (1, 4, -1, 0, 0, 0), (2, 4, -1, 0, 0, 0), (3, 4, -1, 0, 0, 0), (0, 4, -1, 0, 0, 0), (2, 3, 4, -1, 0, 0), (1, 3, 4, -1, 0, 0), (1, 2, 4, -1, 0, 0), (0, 3, 4, -1, 0, 0), (0, 1, 4, -1, 0, 0), (0, 2, 4, -1, 0, 0), (0, 2, 3, -1, 0, 0), (0, 1, 3, -1, 0, 0), (0, 1, 2, -1, 0, 0), (1, 2, 3, -1, 0, 0), (1, 2, 3, 4, -1, 0), (0, 2, 3, 4, -1, 0), (0, 1, 3, 4, -1, 0), (0, 1, 2, 4, -1, 0), (0, 1, 2, 3, -1, 0), (0, 1, 2, 3, 4, -1)); -- MV_Grade_Size can be used to lookup the number of coordinates -- for a grade part of a general multivector -- MV_Grade_Size : constant array (0 .. 5) of Integer := (1, 5, 10, 10, 5, 1); -- This array of integers contains the 'sign' (even/odd permutation of the canonical order) -- of basis elements in the general multivector -- Use it to answer 'what is the permutation of the coordinate at index [x]'? MV_Basis_Element_Sign_By_Index : constant array (1 .. 32) of Float := (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0); -- Joinable grade definitions Grade_0 : constant Interfaces.Unsigned_32 := 1; Grade_1 : constant Interfaces.Unsigned_32 := 2; Grade_2 : constant Interfaces.Unsigned_32 := 4; Grade_3 : constant Interfaces.Unsigned_32 := 8; Grade_4 : constant Interfaces.Unsigned_32 := 16; Grade_5 : constant Interfaces.Unsigned_32 := 32; -- function "+" (L, R : Vector_E3) return Vector_E3; -- function "-" (L, R : Vector_E3) return Vector_E3; function "*" (L : float; R : Vector_E3) return Vector_E3; -- function "*" (L : Vector_E3; R : float) return Vector_E3; -- function Coord (S : Multivectors.Scalar) return float; -- function Init (MV : Multivectors.Multivector; Epsilon : float:= 0.0) return MV_Type; -- Basis Vectors function e1 return Multivectors.Multivector; function e2 return Multivectors.Multivector; function e3 return Multivectors.Multivector; function ni return Multivectors.Multivector; function no return Multivectors.Multivector; -- Component getters function e1 (MV : Multivectors.Multivector) return float; function e2 (MV : Multivectors.Multivector) return float; function e3 (MV : Multivectors.Multivector) return float; function e1_e2 (MV : Multivectors.Multivector) return float; function e1_e3 (MV : Multivectors.Multivector) return float; function e2_e3 (MV : Multivectors.Multivector) return float; function E1_E2_NI (C : Multivectors.Multivector) return float; function E1_E2_E3 (MV : Multivectors.Multivector) return float; function E1_E3_NI (C : Multivectors.Multivector) return float; function E2_E3_NI (C : Multivectors.Multivector) return float; function Get_Coords (V : Vector_E3) return GA_Maths.Float_3D; function Get_Coords (NP : Multivectors.Normalized_Point) return GA_Maths.Coords_Continuous_Array; function NO_E1_E2 (C : Multivectors.Multivector) return float; function NO_E1_E3 (C : Multivectors.Multivector) return float; function NO_E1_NI (C : Multivectors.Multivector) return float; function NO_E2_E3 (C : Multivectors.Multivector) return float; function NO_E2_NI (C : Multivectors.Multivector) return float; function NO_E3_NI (C : Multivectors.Multivector) return float; function NO_E1_E2_E3_NI (MV : Multivectors.Multivector) return float; function E1b (NP : Multivectors.Normalized_Point) return float; function E2b (NP : Multivectors.Normalized_Point) return float; function E3b (NP : Multivectors.Normalized_Point) return float; function NIb (NP : Multivectors.Normalized_Point) return Float; function NOb (NP : Multivectors.Normalized_Point) return Float; function C3GA_Point (V : Vector_E3) return C3GA_Normalized_Point; function Multivector_String (MV : Multivectors.Multivector) return String; function Norm_E2 (V : Vector_E3) return Float; function Norm_R (V : Vector_E3) return Float; function Norm_R2 (V : Vector_E3) return Float; function Probe (Pr : Blade_Types.C3_Base) return Multivectors.Normalized_Point; function Set_Circle (P1, P2, P3 : Multivectors.Normalized_Point) return Multivectors.Circle; procedure Set_Coords (V : out Vector_E3; C1, C2, C3 : float); function Set_Dual_Plane (P1 : Multivectors.Normalized_Point; Dir : Multivectors.M_Vector) return Multivectors.Dual_Plane; -- procedure Set_Multivector (MV : out Multivectors.Multivector; NP : Normalized_Point); -- procedure Set_Multivector (MV : out Multivectors.Multivector; N : GA_Base_Types.NO_T); -- procedure Set_Multivector (MV : out Multivectors.Multivector; N : GA_Base_Types.NI_T); -- function Set_Line (E1_E2_NI, E1_E3_NI, E2_E3_NI, -- E1_NO_NI, E2_NO_NI, E3_NO_NI : Float) return Multivectors.Line; function Set_Line (P1, P2 : Multivectors.Normalized_Point) return Multivectors.Line; function Set_Normalized_Point (E1, E2, E3 : Float) return Multivectors.Normalized_Point; function Set_Normalized_Point (V : Vector_E3) return Multivectors.Normalized_Point; function Set_Normalized_Point (Point : GA_Maths.Float_3D) return Multivectors.Normalized_Point; -- function Outer_Product (MV1, MV2 : Multivectors.Multivector) return Multivectors.Multivector; -- function Unit_R (L : Multivectors.Line) return Multivectors.Line; -- Underscore constructors function To_VectorE3GA (MV : Multivectors.Multivector) return Vector_E3; function To_VectorE3GA (Vec : E3GA.E3_Vector) return Vector_E3; function NP_To_VectorE3GA (NP : Multivectors.Normalized_Point) return Vector_E3; -- function US_Normalized_Point (N : Normalized_Point) return Normalized_Point; -- function US_Set_Normalized_Point (Point : Vector_E3) return Normalized_Point; -- function US_Set_Normalized_Point (E1, E2, E3 : Float) return Normalized_Point; function Unit_E (X : C3GA.Vector_E3) return GL.Types.Singles.Vector3; private -- type Scalar is record -- Coordinates : GA_Maths.Scalar_Coords; -- m_c[1] -- end record; -- type Circle is record -- m_c[10] -- E1_E2_NI, E1_E2_E3, E2_E3_NI, E3_E1_NI, NO_E1_E2 : float := 0.0; -- NO_E1_E3, NO_E1_NI, NO_E2_E3, NO_E2_NI, NO_E3_NI : float := 0.0; -- end record; -- type Dual_Sphere is record -- m_c[4] -- NO, E1, E2, E3, NI : float := 0.0; -- Inf : GA_Base_Types.NI_T; -- end record; -- type Line is record -- m_c[6] -- E1_E2_NI, E1_E3_NI, E2_E3_NI : float := 0.0; -- E1_NO_NI, E2_NO_NI, E3_NO_NI : float := 0.0; -- end record; -- type Normalized_Point is record -- m_c[4 -- -- Origin : float := 1.0; constant -- E1, E2, E3 : float := 0.0; -- Inf : float := 0.0; -- end record; -- type Point is record -- m_c[5] -- Origin : GA_Base_Types.NO_T; -- E1, E2, E3 : float := 0.0; -- Inf : float := 0.0; -- end record; -- type Sphere is record -- m_c[5] -- E1_E2_E3_NI, E1_E2_NO_NI, E1_E3_NO_NI : float := 0.0; -- E2_E3_NO_NI, E1_E2_E3_NO : float := 0.0; -- end record; type Vector_C3GA is new GA_Maths.Coords_Continuous_Array (1 .. 5); end C3GA;
----------------------------------------------------------------------- -- gen-commands-templates -- Template based command -- Copyright (C) 2011, 2013, 2014 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Containers.Vectors; with Util.Strings.Sets; with Util.Strings.Vectors; package Gen.Commands.Templates is -- ------------------------------ -- Template Generic Command -- ------------------------------ -- This command adds a XHTML page to the web application. type Command is new Gen.Commands.Command with private; type Command_Access is access all Command'Class; -- Execute the command with the arguments. procedure Execute (Cmd : in Command; Generator : in out Gen.Generator.Handler); -- Write the help associated with the command. procedure Help (Cmd : in Command; Generator : in out Gen.Generator.Handler); -- Read the template commands defined in dynamo configuration directory. procedure Read_Commands (Generator : in out Gen.Generator.Handler); private type Param is record Name : Ada.Strings.Unbounded.Unbounded_String; Argument : Ada.Strings.Unbounded.Unbounded_String; Value : Ada.Strings.Unbounded.Unbounded_String; Is_Optional : Boolean := False; end record; package Param_Vectors is new Ada.Containers.Vectors (Index_Type => Positive, Element_Type => Param); type Patch is record Template : Ada.Strings.Unbounded.Unbounded_String; After : Util.Strings.Vectors.Vector; Missing : Util.Strings.Vectors.Vector; Before : Ada.Strings.Unbounded.Unbounded_String; Title : Ada.Strings.Unbounded.Unbounded_String; Optional : Boolean := False; end record; package Patch_Vectors is new Ada.Containers.Vectors (Index_Type => Positive, Element_Type => Patch); type Command is new Gen.Commands.Command with record Name : Ada.Strings.Unbounded.Unbounded_String; Title : Ada.Strings.Unbounded.Unbounded_String; Usage : Ada.Strings.Unbounded.Unbounded_String; Help_Msg : Ada.Strings.Unbounded.Unbounded_String; Base_Dir : Ada.Strings.Unbounded.Unbounded_String; Templates : Util.Strings.Sets.Set; Patches : Patch_Vectors.Vector; Params : Param_Vectors.Vector; end record; end Gen.Commands.Templates;
-- SipHash24_String_Hashing -- Instantiations of SipHash with recommended parameters for the String types -- in order to replace Ada.Strings.Hash and friends. -- Copyright (c) 2015, James Humphry - see LICENSE file for details pragma Spark_Mode; with Ada.Characters.Handling, Ada.Wide_Characters.Handling; with Ada.Wide_Wide_Characters.Handling; with Ada.Strings.UTF_Encoding.Wide_Wide_Strings; package body SipHash24_String_Hashing is function String_Hash_Case_Insensitive (Key : String) return Ada.Containers.Hash_Type is (String_Hash(Ada.Characters.Handling.To_Lower(Key))); function Wide_String_Hash_Case_Insensitive (Key : Wide_String) return Ada.Containers.Hash_Type is (Wide_String_Hash(Ada.Wide_Characters.Handling.To_Lower(Key))); function Wide_Wide_String_Hash_Case_Insensitive (Key : Wide_Wide_String) return Ada.Containers.Hash_Type is (Wide_Wide_String_Hash(Ada.Wide_Wide_Characters.Handling.To_Lower(Key))); function UTF_8_String_Hash_Case_Insensitive (Key : UTF_8_String) return Ada.Containers.Hash_Type is Decoded_String : constant Wide_Wide_String := Ada.Wide_Wide_Characters.Handling.To_Lower(Ada.Strings.UTF_Encoding.Wide_Wide_Strings.Decode(Key)); begin return Wide_Wide_String_Hash(Decoded_String); end UTF_8_String_Hash_Case_Insensitive; end SipHash24_String_Hashing;
with Ada.Text_IO; with Ada.Float_Text_IO; with Ada.Long_Integer_Text_IO; with Ada.Command_Line; with Ada.Environment_Variables; with Bitmaps.IO; with Bitmaps.RGB; with Ada.Text_IO.Text_Streams; with Problem; with ImageOps; with Simulated_Annealing; with RAII; procedure Main is package Positive_IO is new Ada.Text_IO.Integer_IO (Positive); type Image_Access is access all Bitmaps.RGB.Image; package Image_Problem is new Problem (Image_Access); function Opt_Iterations return Positive is Result : Positive := 1000000; Last : Positive; begin if Ada.Environment_Variables.Exists ("ANNEALING_ITERATIONS") then Positive_IO.Get (From => Ada.Environment_Variables.Value ("ANNEALING_ITERATIONS"), Item => Result, Last => Last); end if; return Result; end Opt_Iterations; function Opt_Temperature return Float is Result : Float := 100.0; Last : Positive; begin if Ada.Environment_Variables.Exists ("ANNEALING_TEMPERATURE") then Ada.Float_Text_IO.Get (From => Ada.Environment_Variables.Value ("ANNEALING_TEMPERATURE"), Item => Result, Last => Last); end if; return Result; end Opt_Temperature; function Opt_Size return Positive is Result : Positive := 64; Last : Positive; begin if Ada.Environment_Variables.Exists("ANNEALING_SIZE") then Positive_IO.Get (From => Ada.Environment_Variables.Value("ANNEALING_SIZE"), Item => Result, Last => Last); end if; return Result; end Opt_Size; Bitmap_Size : constant Positive := Opt_Size; B : aliased Bitmaps.RGB.Image (Bitmap_Size, Bitmap_Size); S : Image_Problem.State; begin ImageOps.Noise (B); S.Img := B'Access; S.E := ImageOps.Adj_Distance_Sum (B); Image_Problem.Roll (S); S.Visited := False; declare M : Image_Problem.Opt.Minimization := Image_Problem.Opt.Minimize (S); Sched : Simulated_Annealing.Scheduler := Simulated_Annealing.Exponential (Opt_Iterations, Opt_Temperature); Improved : Boolean := False; begin while Image_Problem.Opt.Step (M, Sched, Improved) loop if Improved then Ada.Text_IO.Put ("T = "); Ada.Float_Text_IO.Put (Simulated_Annealing.Temperature (Sched)); Ada.Text_IO.Put (", E = "); Ada.Long_Integer_Text_IO.Put (Image_Problem.Opt.Minimum (M).E, Width => 0); Ada.Text_IO.New_Line; if Ada.Command_Line.Argument_Count > 0 then declare CF : RAII.Controlled_File; begin Ada.Text_IO.Open (CF.File, Ada.Text_IO.Out_File, Ada.Command_Line.Argument (1)); Bitmaps.IO.Write_PPM_P6 (Ada.Text_IO.Text_Streams.Stream (CF.File), B); end; end if; end if; end loop; end; end Main;
-------------------------------------------------------------------------------- -- MIT License -- -- Copyright (c) 2020 Zane Myers -- -- Permission is hereby granted, free of charge, to any person obtaining a copy -- of this software and associated documentation files (the "Software"), to deal -- in the Software without restriction, including without limitation the rights -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -- copies of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in all -- copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. -------------------------------------------------------------------------------- with Vulkan.Math.GenDType; with Vulkan.Math.Dvec3; with Vulkan.Math.Dvec2; use Vulkan.Math.GenDType; use Vulkan.Math.Dvec3; use Vulkan.Math.Dvec2; -------------------------------------------------------------------------------- --< @group Vulkan Math Basic Types -------------------------------------------------------------------------------- --< @summary --< This package defines a double precision floating point vector type with 4 --< components. -------------------------------------------------------------------------------- package Vulkan.Math.Dvec4 is pragma Preelaborate; pragma Pure; --< A 4 component vector of double-precision floating point values. subtype Vkm_Dvec4 is Vkm_GenDType(Last_Index => 3); ---------------------------------------------------------------------------- -- Ada does not have the concept of constructors in the sense that they exist -- in C++. For this reason, we will instead define multiple methods for -- instantiating a Dvec4 here. ---------------------------------------------------------------------------- -- The following are explicit constructors for Dvec4: ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dvec4 type. --< --< @description --< Produce a default vector with all components set to 0.0. --< --< @return --< A Dvec4 with all components set to 0.0. ---------------------------------------------------------------------------- function Make_Dvec4 return Vkm_Dvec4 is (GDT.Make_GenType(Last_Index => 3, value => 0.0)) with Inline; ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dvec4 type. --< --< @description --< Produce a vector with all components set to the same value. --< --< @param scalar_value --< The value to set all components to. --< --< @return --< A Dvec4 with all components set to scalar_value. ---------------------------------------------------------------------------- function Make_Dvec4 (scalar_value : in Vkm_Double) return Vkm_Dvec4 is (GDT.Make_GenType(Last_Index => 3, value => scalar_value)) with Inline; ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dvec4 type. --< --< @description --< Produce a vector by copying components from an existing vector. --< --< @param dvec4_value --< The Dvec4 to copy components from. --< --< @return --< A Dvec4 with all of its components set equal to the corresponding --< components of dvec4_value. ---------------------------------------------------------------------------- function Make_Dvec4 (dvec4_value : in Vkm_Dvec4) return Vkm_Dvec4 is (GDT.Make_GenType(dvec4_value.data(0),dvec4_value.data(1), dvec4_value.data(2),dvec4_value.data(3))) with Inline; ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dvec4 type. --< --< @description --< Produce a vector by specifying the values for each of its components. --< --< @param value1 --< Value for component 1. --< --< @param value2 --< Value for component 2. --< --< @param value3 --< Value for componetn 3. --< --< @param value4 --< Value for component 4. --< --< @return --< A Dvec4 with all components set as specified. ---------------------------------------------------------------------------- function Make_Dvec4 (value1, value2, value3, value4 : in Vkm_Double) return Vkm_Dvec4 renames GDT.Make_GenType; ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dvec4 type. --< --< @description --< Produce a vector by concatenating a scalar value with a Dvec3. --< --< Dvec4 = [scalar_value, dvec3_value ] --< --< @param scalar_value --< The scalar value to concatenate with the Dvec3. --< --< @param dvec3_value --< The Dvec3 to concatenate to the scalar value. --< --< @return --< The instance of Dvec4. ---------------------------------------------------------------------------- function Make_Dvec4 (scalar_value : in Vkm_Double; dvec3_value : in Vkm_Dvec3) return Vkm_Dvec3 is (Make_Dvec4(scalar_value, dvec3_value.data(0), dvec3_value.data(1), dvec3_value.data(2))) with Inline; ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dvec4 type. --< --< @description --< Produce a vector by concatenating a Dvec3 with a scalar value. --< --< Dvec4 = [dvec3_value, scalar_value] --< --< @param dvec3_value --< The Dvec3 to concatenate to the scalar value. --< --< @param scalar_value --< The scalar value to concatenate to the Dvec3. --< --< @return --< The instance of Dvec4. ---------------------------------------------------------------------------- function Make_Dvec4 (dvec3_value : in Vkm_Dvec3; scalar_value : in Vkm_Double) return Vkm_Dvec4 is (Make_Dvec4(dvec3_value.data(0), dvec3_value.data(1), dvec3_value.data(2), scalar_value )) with Inline; ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dvec4 type. --< --< @description --< Produce a vector by concatenating a Dvec2 with a Dvec2. --< --< Dvec4 = [dvec2_value1, dvec2_value2] --< --< @param dvec2_value1 --< The first Dvec2. --< --< @param dvec2_value2 --< The second Dvec2. --< --< @return --< The instance of Dvec4. ---------------------------------------------------------------------------- function Make_Dvec4 (dvec2_value1, dvec2_value2 : in Vkm_Dvec2) return Vkm_Dvec4 is (Make_Dvec4(dvec2_value1.data(0),dvec2_value1.data(1), dvec2_value2.data(0),dvec2_value2.data(1))); ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dvec4 type. --< --< @description --< Produce a vector by concatenating two scalar values with a Dvec2. --< --< Dvec4 = [scalar1, scalar2, dvec2_value] --< --< @param scalar1 --< First scalar value. --< --< @param scalar2 --< Second scalar value. --< --< @param dvec2_value --< The Dvec2 value. --< --< @return --< The instance of Dvec4. ---------------------------------------------------------------------------- function Make_Dvec4 (scalar1, scalar2 : in Vkm_Double; dvec2_value : in Vkm_Dvec2) return Vkm_Dvec4 is (Make_Dvec4(scalar1, scalar2, dvec2_value.data(0),dvec2_value.data(1))); ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dvec4 type. --< --< @description --< Produce a vector by concatenating two scalar values with a Dvec2. --< --< Dvec4 = [scalar1, dvec2_value, scalar2] --< --< @param scalar1 --< First scalar value. --< --< @param dvec2_value --< The Dvec2 value. --< --< @param scalar2 --< Second scalar value. --< --< @return --< The instance of Dvec4. ---------------------------------------------------------------------------- function Make_Dvec4 (scalar1 : in Vkm_Double; dvec2_value : in Vkm_Dvec2 ; scalar2 : in Vkm_Double) return Vkm_Dvec4 is (Make_Dvec4(scalar1, dvec2_value.data(0),dvec2_value.data(1), scalar2)); ---------------------------------------------------------------------------- --< @summary --< Constructor for Vkm_Dvec4 type. --< --< @description --< Produce a vector by concatenating two scalar values with a Dvec2. --< --< Dvec4 = [dvec2_value, scalar1, scalar2] --< --< @param dvec2_value --< The Dvec2 value. --< --< @param scalar1 --< First scalar value. --< --< @param scalar2 --< Second scalar value. --< --< @return --< The instance of Dvec4. --------------------------------------------------------------------------- function Make_Dvec4 (dvec2_value : in Vkm_Dvec2 ; scalar1 : in Vkm_Double; scalar2 : in Vkm_Double) return Vkm_Dvec4 is (Make_Dvec4(dvec2_value.data(0),dvec2_value.data(1), scalar1, scalar2)); end Vulkan.Math.Dvec4;
-- -- Jan & Uwe R. Zimmer, Australia, July 2011 -- with GLOBE_3D; package Spaceship_P is procedure Create (Object : in out GLOBE_3D.p_Object_3D; Object_Scale : GLOBE_3D.Real; Centre : GLOBE_3D.Point_3D); end Spaceship_P;
generic Frequency : Unsigned_32; Source: Source_Type; Input: Input_Type; package MSPGD.Clock.Source is pragma Preelaborate; procedure Init; procedure Delay_us (us : Natural); procedure Delay_ms (ms : Natural); procedure Delay_s (s : Natural); function Millisecond_Counter return Unsigned_32; procedure Delay_Slow_Periods (P : Unsigned_16); function Maximum_Delay_ms return Unsigned_16; end MSPGD.Clock.Source;
------------------------------------------------------------------------------ -- G E L A A S I S -- -- ASIS implementation for Gela project, a portable Ada compiler -- -- http://gela.ada-ru.org -- -- - - - - - - - - - - - - - - - -- -- -- -- This specification is derived from the Ada Semantic Interface -- -- Specification Standard (ISO/IEC 15291) and ASIS 1999 Issues. -- -- -- -- The copyright notice and the license provisions that follow apply to the -- -- part following the private keyword. -- -- -- -- Read copyright and license at the end of this file -- ------------------------------------------------------------------------------ -- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $ ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -- 8 package Asis.Ada_Environments ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- package Asis.Ada_Environments is ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -- Asis.Ada_Environments encapsulates a set of queries that map physical Ada -- compilation and program execution environments to logical ASIS -- environments. ------------------------------------------------------------------------------- -- 8.1 function Default_Name ------------------------------------------------------------------------------- function Default_Name return Wide_String; ------------------------------------------------------------------------------- -- Returns the default context name. If there is no default context name, a -- null string is returned. -- ------------------------------------------------------------------------------- -- 8.2 function Default_Parameters ------------------------------------------------------------------------------- function Default_Parameters return Wide_String; ------------------------------------------------------------------------------- -- Returns the default context parameters. If there are no default context -- parameters, a null string is returned. -- ------------------------------------------------------------------------------- -- 8.3 procedure Associate ------------------------------------------------------------------------------- procedure Associate (The_Context : in out Asis.Context; Name : in Wide_String; Parameters : in Wide_String := Default_Parameters); ------------------------------------------------------------------------------- -- The_Context - Specifies the Context to associate -- Name - Specifies the name for the Context association -- Parameters - Specifies parameters to use when opening the Context -- -- Used to give name and parameter associations to a Context. The -- Has_Associations query is used to test whether or not a Context has -- been given name and parameter associations. The Name and Parameters -- queries are used to examine name and parameter associations. -- -- A Context has at most one set of name/parameter values associated with -- it at any time. Name and parameter associations cannot be modified while a -- Context is open Previous name and parameters associations for this Context -- are replaced by this call. -- -- ASIS implementations are encouraged, but not required, to validate the -- Parameters string immediately. It is recognized that some options cannot -- be completely validated until the Open is performed. An invalid Parameters -- value is reported by raising ASIS_Failed with a Status of Parameter_Error. -- -- Raises ASIS_Inappropriate_Context if The_Context is open. -- ------------------------------------------------------------------------------- -- 8.4 procedure Open ------------------------------------------------------------------------------- procedure Open (The_Context : in out Asis.Context); ------------------------------------------------------------------------------- -- The_Context - Specifies the Context to open -- -- Opens the ASIS Context using the Context's associated name and parameter -- values. -- -- Raises ASIS_Inappropriate_Context if The_Context is already open or if it -- is uninitialized (does not have associated name and parameter values). -- -- Raises ASIS_Failed if The_Context could not be opened for any reason. The -- most likely Status values are Name_Error, Use_Error, Data_Error, and -- Parameter_Error. Other possibilities include Storage_Error and -- Capacity_Error. -- ------------------------------------------------------------------------------- -- 8.5 procedure Close ------------------------------------------------------------------------------- procedure Close (The_Context : in out Asis.Context); ------------------------------------------------------------------------------- -- The_Context - Specifies the Context to close -- -- Closes the ASIS Context. Any previous Context name and parameter -- associations are retained. This allows the same Context to be re-opened -- later with the same associations. -- -- All Compilation_Unit and Element values obtained from The_Context become -- invalid when it is closed. Subsequent calls to ASIS services using such -- invalid Compilation_Unit or Element values are erroneous. ASIS -- implementations will attempt to detect such usage and raise ASIS_Failed in -- response. Applications should be aware that the ability to detect the use -- of such "dangling references" is implementation specific and not all -- implementations are able to raise ASIS_Failed at the appropriate -- points. Thus, applications that attempt to utilize invalid values may -- exhibit unpredictable behavior. -- -- Raises ASIS_Inappropriate_Context if The_Context is not open. -- ------------------------------------------------------------------------------- -- 8.6 procedure Dissociate ------------------------------------------------------------------------------- procedure Dissociate (The_Context : in out Asis.Context); ------------------------------------------------------------------------------- -- The_Context - Specifies the Context whose name and parameter associations -- are to be cleared -- -- Severs all previous associations for The_Context. A Context that does not -- have associations (is uninitialized) is returned unchanged. The -- variable The_Context is returned to its uninitialized state. -- -- Contexts that have been given Names and Parameters should be Dissociated -- when they are no longer necessary. Some amount of program storage can be -- tied up by the stored Name and Parameter strings. This space is only -- freed when a Context is Dissociated or when ASIS is Finalized. -- -- This operation has no physical affect on any implementor's Ada environment. -- -- Raises ASIS_Inappropriate_Context if The_Context is open. -- ------------------------------------------------------------------------------- -- 8.7 function Is_Equal ------------------------------------------------------------------------------- function Is_Equal (Left : in Asis.Context; Right : in Asis.Context) return Boolean; ------------------------------------------------------------------------------- -- Left - Specifies the first Context -- Right - Specifies the second Context -- -- Returns True if Left and Right designate the same set of associated -- compilation units. The Context variables may be open or closed. -- -- Unless both Contexts are open, this operation is implemented as a pair of -- simple string comparisons between the Name and Parameter associations for -- the two Contexts. If both Contexts are open, this operation acts as a -- set comparison and returns True if both sets contain the same units (all -- unit versions are included in the comparison). -- -- |AN Application Note: -- |AN -- |AN With some implementations, Is_Equal may be True before the Contexts -- |AN are opened, but may be False after the Contexts are open. -- |AN One possible cause for this is a sequence of events such as: -- |AN -- |AN a) ASIS program A opens the Left Context for READ, -- |AN -- |AN b) non-ASIS program B opens the Context for UPDATE, and creates a new -- |AN version of the implementor Context, -- |AN -- |AN c) ASIS program A opens the Right Context for READ, and gets the new -- |AN version. -- ------------------------------------------------------------------------------- -- 8.8 function Is_Identical ------------------------------------------------------------------------------- function Is_Identical (Left : in Asis.Context; Right : in Asis.Context) return Boolean; ------------------------------------------------------------------------------- -- Left - Specifies the first Context -- Right - Specifies the second Context -- -- Returns True if Left and Right both designate the value associated with -- one specific ASIS Context variable. -- -- Returns False otherwise or if either Context is not open. -- -- |AN Application Note: -- |AN -- |AN No two physically separate open Context variables are ever -- |AN Is_Identical. The value associated with an open ASIS Context variable -- |AN is also directly associated with every Compilation_Unit or Element -- |AN derived from that Context. It is possible to obtain these Context -- |AN values by way of the Enclosing_Context and the -- |AN Enclosing_Compilation_Unit queries. These Context values can be -- |AN tested for identity with each other or with -- |AN specific Context variables. An open ASIS Context variable and an -- |AN Enclosing_Context value are only Is_Identical if the Compilation_Unit -- |AN in question was derived specifically from that open ASIS Context -- |AN variable. -- ------------------------------------------------------------------------------- -- 8.9 function Exists ------------------------------------------------------------------------------- function Exists (The_Context : in Asis.Context) return Boolean; ------------------------------------------------------------------------------- -- The_Context - Specifies a Context with associated name and parameter values -- -- Returns True if The_Context is open or if The_Context designates an Ada -- environment that can be determined to exist. -- -- Returns False for any uninitialized The_Context variable. -- -- |IP Implementation Permissions: -- |IP -- |IP No guarantee is made that The_Context is readable or that an Open -- |IP operation on The_Context would succeed. The associated -- |IP parameter value for The_Context may not be fully validated by this -- |IP simple existence check. It may contain information that can only be -- |IP verified by an Open. -- ------------------------------------------------------------------------------- -- 8.10 function Is_Open ------------------------------------------------------------------------------- function Is_Open (The_Context : in Asis.Context) return Boolean; ------------------------------------------------------------------------------- -- The_Context - Specifies the Context to check -- -- Returns True if The_Context is currently open. -- ------------------------------------------------------------------------------- -- 8.11 function Has_Associations ------------------------------------------------------------------------------- function Has_Associations (The_Context : in Asis.Context) return Boolean; ------------------------------------------------------------------------------- -- The_Context - Specifies the Context to check -- -- Returns True if name and parameter values have been associated with -- The_Context. -- -- Returns False if The_Context is uninitialized. -- ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -- 8.12 function Name ------------------------------------------------------------------------------- function Name (The_Context : in Asis.Context) return Wide_String; ------------------------------------------------------------------------------- -- The_Context - Specifies the Context to check -- -- Returns the Name value associated with The_Context. -- -- Returns a null string if The_Context is uninitialized. -- ------------------------------------------------------------------------------- -- 8.13 function Parameter ------------------------------------------------------------------------------- function Parameters (The_Context : in Asis.Context) return Wide_String; ------------------------------------------------------------------------------- -- The_Context - Specifies the Context to check -- -- Returns the Parameters value associated with The_Context. -- -- Returns a null string if The_Context is uninitialized. -- ------------------------------------------------------------------------------- -- 8.14 function Debug_Image ------------------------------------------------------------------------------- function Debug_Image (The_Context : in Asis.Context) return Wide_String; ------------------------------------------------------------------------------- -- The_Context - Specifies the Context to represent -- -- Returns a string value containing implementation-defined debugging -- information associated with The_Context. -- -- The return value uses Asis.Text.Delimiter_Image to separate lines in -- multi-line results. The return value is not terminated with -- Asis.Text.Delimiter_Image. -- -- Returns a null string if The_Context is uninitialized. -- -- These values are intended for two purposes. They are suitable for -- inclusion in problem reports sent to the ASIS implementor. They can be -- presumed to contain information useful when debugging the implementation -- itself. They are also suitable for use by the ASIS application when -- printing simple application debugging messages during application -- development. They are intended to be, to some worthwhile degree, -- intelligible to the user. -- end Asis.Ada_Environments; ------------------------------------------------------------------------------ -- Copyright (c) 2006-2013, Maxim Reznik -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met: -- -- * Redistributions of source code must retain the above copyright notice, -- this list of conditions and the following disclaimer. -- * Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- * Neither the name of the Maxim Reznik, IE nor the names of its -- contributors may be used to endorse or promote products derived from -- this software without specific prior written permission. -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -- POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Calendar; use Ada.Calendar; with Ada.Containers.Vectors; procedure Show_Type_Invariant is package Courses is type Course is private with Type_Invariant => Check (Course); type Course_Container is private; procedure Add (CC : in out Course_Container; C : Course); function Init (Name : String; Start_Date, End_Date : Time) return Course; function Check (C : Course) return Boolean; private type Course is record Name : Unbounded_String; Start_Date : Time; End_Date : Time; end record; function Check (C : Course) return Boolean is (C.Start_Date <= C.End_Date); package Course_Vectors is new Ada.Containers.Vectors (Index_Type => Natural, Element_Type => Course); type Course_Container is record V : Course_Vectors.Vector; end record; end Courses; package body Courses is procedure Add (CC : in out Course_Container; C : Course) is begin CC.V.Append (C); end Add; function Init (Name : String; Start_Date, End_Date : Time) return Course is begin return Course'(Name => To_Unbounded_String (Name), Start_Date => Start_Date, End_Date => End_Date); end Init; end Courses; use Courses; CC : Course_Container; begin Add (CC, Init (Name => "Intro to Photography", Start_Date => Time_Of (2018, 5, 1), End_Date => Time_Of (2018, 5, 10))); -- This should trigger an error in the type-invariant check Add (CC, Init (Name => "Intro to Video Recording", Start_Date => Time_Of (2019, 5, 1), End_Date => Time_Of (2018, 5, 10))); end Show_Type_Invariant;
----------------------------------------------------------------------- -- awa-events-dispatchers-actions -- Event dispatcher to Ada bean actions -- Copyright (C) 2012 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Strings.Unbounded; with Ada.Exceptions; with Util.Beans.Objects; with Util.Beans.Basic; with Util.Log.Loggers; with EL.Contexts; with EL.Contexts.Default; with EL.Variables; with EL.Variables.Default; with ASF.Beans; with ASF.Requests; with ASF.Sessions; with AWA.Events.Action_Method; package body AWA.Events.Dispatchers.Actions is use Ada.Strings.Unbounded; use Util.Log; Log : constant Loggers.Logger := Loggers.Create ("AWA.Events.Dispatchers.Actions"); -- ------------------------------ -- Dispatch the event identified by <b>Event</b>. -- The event actions which are associated with the event are executed synchronously. -- ------------------------------ procedure Dispatch (Manager : in Action_Dispatcher; Event : in Module_Event'Class) is use Util.Beans.Objects; -- Dispatch the event to the event action identified by <b>Action</b>. procedure Dispatch_One (Action : in Event_Action); type Event_Bean is new Util.Beans.Basic.Readonly_Bean with null record; overriding function Get_Value (From : in Event_Bean; Name : in String) return Util.Beans.Objects.Object; -- ------------------------------ -- Get the value identified by the name. -- If the name cannot be found, the method should return the Null object. -- ------------------------------ overriding function Get_Value (From : in Event_Bean; Name : in String) return Util.Beans.Objects.Object is pragma Unreferenced (From); begin return Event.Get_Value (Name); end Get_Value; Variables : aliased EL.Variables.Default.Default_Variable_Mapper; -- ------------------------------ -- Default Resolver -- ------------------------------ type Event_ELResolver is limited new EL.Contexts.ELResolver with record Request : ASF.Requests.Request_Access; Application : AWA.Applications.Application_Access; end record; overriding function Get_Value (Resolver : Event_ELResolver; Context : EL.Contexts.ELContext'Class; Base : access Util.Beans.Basic.Readonly_Bean'Class; Name : Unbounded_String) return Util.Beans.Objects.Object; overriding procedure Set_Value (Resolver : in out Event_ELResolver; Context : in EL.Contexts.ELContext'Class; Base : access Util.Beans.Basic.Bean'Class; Name : in Unbounded_String; Value : in Util.Beans.Objects.Object); -- ------------------------------ -- Get the value associated with a base object and a given property. -- ------------------------------ overriding function Get_Value (Resolver : Event_ELResolver; Context : EL.Contexts.ELContext'Class; Base : access Util.Beans.Basic.Readonly_Bean'Class; Name : Unbounded_String) return Util.Beans.Objects.Object is use Util.Beans.Basic; use EL.Variables; use type ASF.Requests.Request_Access; Result : Object; Bean : Util.Beans.Basic.Readonly_Bean_Access; Scope : ASF.Beans.Scope_Type; Key : constant String := To_String (Name); begin if Base /= null then return Base.Get_Value (Key); end if; if Resolver.Request /= null then Result := Resolver.Request.Get_Attribute (Key); if not Util.Beans.Objects.Is_Null (Result) then return Result; end if; -- If there is a session, look if the attribute is defined there. declare Session : constant ASF.Sessions.Session := Resolver.Request.Get_Session; begin if Session.Is_Valid then Result := Session.Get_Attribute (Key); if not Util.Beans.Objects.Is_Null (Result) then return Result; end if; end if; end; end if; Resolver.Application.Create (Name, Context, Bean, Scope); if Bean = null then return Resolver.Application.Get_Global (Name, Context); end if; Result := To_Object (Bean); if Resolver.Request /= null then Resolver.Request.Set_Attribute (Key, Result); else Variables.Bind (Key, Result); end if; return Result; end Get_Value; -- ------------------------------ -- Set the value associated with a base object and a given property. -- ------------------------------ overriding procedure Set_Value (Resolver : in out Event_ELResolver; Context : in EL.Contexts.ELContext'Class; Base : access Util.Beans.Basic.Bean'Class; Name : in Unbounded_String; Value : in Util.Beans.Objects.Object) is pragma Unreferenced (Context); use type ASF.Requests.Request_Access; Key : constant String := To_String (Name); begin if Base /= null then Base.Set_Value (Name => Key, Value => Value); elsif Resolver.Request /= null then Resolver.Request.Set_Attribute (Name => Key, Value => Value); else Variables.Bind (To_String (Name), Value); end if; end Set_Value; Local_Event : aliased Event_Bean; Resolver : aliased Event_ELResolver; ELContext : aliased EL.Contexts.Default.Default_Context; -- ------------------------------ -- Dispatch the event to the event action identified by <b>Action</b>. -- ------------------------------ procedure Dispatch_One (Action : in Event_Action) is use Ada.Exceptions; Method : EL.Expressions.Method_Info; begin Method := Action.Action.Get_Method_Info (Context => ELContext); if Method.Object.all in Util.Beans.Basic.Bean'Class then -- If we have a prepare method and the bean provides a Set_Value method, -- call the preparation method to fill the bean with some values. EL.Beans.Initialize (Util.Beans.Basic.Bean'Class (Method.Object.all), Action.Properties, ELContext); end if; -- Execute the specified method on the bean and give it the event object. AWA.Events.Action_Method.Execute (Method => Method, Param => Event); -- If an exception is raised by the action, do not propagate it: -- o We have to dispatch the event to other actions. -- o The event may be dispatched asynchronously and there is no handler -- that could handle such exception exception when E : others => Log.Error ("Error when executing event action {0}: {1}: {2}", Action.Action.Get_Expression, Exception_Name (E), Exception_Message (E)); end Dispatch_One; Pos : Event_Action_Lists.Cursor := Manager.Actions.First; begin Resolver.Application := Manager.Application; ELContext.Set_Resolver (Resolver'Unchecked_Access); ELContext.Set_Variable_Mapper (Variables'Unchecked_Access); Variables.Bind (Name => "event", Value => To_Object (Local_Event'Unchecked_Access, STATIC)); while Event_Action_Lists.Has_Element (Pos) loop Event_Action_Lists.Query_Element (Pos, Dispatch_One'Access); Event_Action_Lists.Next (Pos); end loop; end Dispatch; -- ------------------------------ -- Add an action invoked when an event is dispatched through this dispatcher. -- When the event queue dispatches the event, the Ada bean identified by the method action -- represented by <b>Action</b> is created and initialized by evaluating and setting the -- parameters defined in <b>Params</b>. The action method is then invoked. -- ------------------------------ procedure Add_Action (Manager : in out Action_Dispatcher; Action : in EL.Expressions.Method_Expression; Params : in EL.Beans.Param_Vectors.Vector) is Item : Event_Action; begin Item.Action := Action; Item.Properties := Params; Manager.Actions.Append (Item); end Add_Action; -- ------------------------------ -- Create a new dispatcher associated with the application. -- ------------------------------ function Create_Dispatcher (Application : in AWA.Applications.Application_Access) return Dispatcher_Access is Result : constant Dispatcher_Access := new Action_Dispatcher '(Dispatcher with Application => Application, others => <>); begin return Result.all'Access; end Create_Dispatcher; end AWA.Events.Dispatchers.Actions;
------------------------------------------------------------------------------ -- Copyright (c) 2016-2017, 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. -- ------------------------------------------------------------------------------ package body Natools.Smaz_Implementations.Base_64_Tools is use type Ada.Streams.Stream_Element_Offset; ----------------------- -- Bit Manipulations -- ----------------------- function Low_6 (Byte : in Character) return Base_64_Digit is (Base_64_Digit (Natural (Character'Pos (Byte)) mod 64)); function Low_4 (Byte : in Character) return Single_Byte_Padding is (Single_Byte_Padding (Natural (Character'Pos (Byte)) mod 16)); function Low_2 (Byte : in Character) return Double_Byte_Padding is (Double_Byte_Padding (Natural (Character'Pos (Byte)) mod 4)); -- Least significant bits of a byte function High_6 (Byte : in Character) return Base_64_Digit is (Base_64_Digit (Natural (Character'Pos (Byte)) / 4)); function High_4 (Byte : in Character) return Single_Byte_Padding is (Single_Byte_Padding (Natural (Character'Pos (Byte)) / 16)); function High_2 (Byte : in Character) return Double_Byte_Padding is (Double_Byte_Padding (Natural (Character'Pos (Byte)) / 64)); -- Most significant bits of a byte function Image_2_4 (Low : Double_Byte_Padding; High : Single_Byte_Padding) return Base_64_Symbol is (Image (Low + High * 4)); function Image_4_2 (Low : Single_Byte_Padding; High : Double_Byte_Padding) return Base_64_Symbol is (Image (Low + High * 16)); -- Composition into a base-64 symbol function Low_4 (Digit : in Base_64_Digit) return Natural is (Natural (Digit mod 16)); function Low_2 (Digit : in Base_64_Digit) return Natural is (Natural (Digit mod 4)); -- Least significat bits of a digit function High_4 (Digit : in Base_64_Digit) return Natural is (Natural (Digit / 4)); function High_2 (Digit : in Base_64_Digit) return Natural is (Natural (Digit / 16)); -- Least significat bits of a digit function Value_2_6 (Low, High : in Natural) return Character is (Character'Val (Low + High * 4)); function Value_4_4 (Low, High : in Natural) return Character is (Character'Val (Low + High * 16)); function Value_6_2 (Low, High : in Natural) return Character is (Character'Val (Low + High * 64)); -- Combine parts of digits into a Character ---------------------- -- Public Interface -- ---------------------- procedure Decode (Input : in Ada.Streams.Stream_Element_Array; Offset : in out Ada.Streams.Stream_Element_Offset; Output : out String) is Index : Positive := Output'First; Padding_1 : Single_Byte_Padding; Padding_2 : Double_Byte_Padding; begin while Index in Output'Range loop case Output'Last - Index + 1 is when 1 => Decode_Single (Input, Offset, Output (Index), Padding_1); Index := Index + 1; when 2 => Decode_Double (Input, Offset, Output (Index .. Index + 1), Padding_2); Index := Index + 2; when others => Decode_Block (Input, Offset, Output (Index .. Index + 2)); Index := Index + 3; end case; end loop; end Decode; procedure Decode_Block (Input : in Ada.Streams.Stream_Element_Array; Offset : in out Ada.Streams.Stream_Element_Offset; Output : out Full_Block) is Data : array (1 .. 4) of Base_64_Digit; begin for I in Data'Range loop Next_Digit (Input, Offset, Data (I)); end loop; Output (1) := Value_6_2 (Natural (Data (1)), Low_2 (Data (2))); Output (2) := Value_4_4 (High_4 (Data (2)), Low_4 (Data (3))); Output (3) := Value_2_6 (High_2 (Data (3)), Natural (Data (4))); end Decode_Block; procedure Decode_Double (Input : in Ada.Streams.Stream_Element_Array; Offset : in out Ada.Streams.Stream_Element_Offset; Output : out Double_Byte; Padding : out Double_Byte_Padding) is Data : array (1 .. 3) of Base_64_Digit; begin for I in Data'Range loop Next_Digit (Input, Offset, Data (I)); end loop; Output (1) := Value_6_2 (Natural (Data (1)), Low_2 (Data (2))); Output (2) := Value_4_4 (High_4 (Data (2)), Low_4 (Data (3))); Padding := Double_Byte_Padding (High_2 (Data (3))); end Decode_Double; procedure Decode_Single (Input : in Ada.Streams.Stream_Element_Array; Offset : in out Ada.Streams.Stream_Element_Offset; Output : out Character; Padding : out Single_Byte_Padding) is Data : array (1 .. 2) of Base_64_Digit; begin for I in Data'Range loop Next_Digit (Input, Offset, Data (I)); end loop; Output := Value_6_2 (Natural (Data (1)), Low_2 (Data (2))); Padding := Single_Byte_Padding (High_4 (Data (2))); end Decode_Single; procedure Encode (Input : in String; Output : in out Ada.Streams.Stream_Element_Array; Offset : in out Ada.Streams.Stream_Element_Offset) is Index : Positive := Input'First; begin while Index in Input'Range loop case Input'Last - Index + 1 is when 1 => Encode_Single (Input (Index), 0, Output, Offset); Index := Index + 1; when 2 => Encode_Double (Input (Index .. Index + 1), 0, Output, Offset); Index := Index + 2; when others => Encode_Block (Input (Index .. Index + 2), Output, Offset); Index := Index + 3; end case; end loop; end Encode; procedure Encode_Block (Input : in Full_Block; Output : in out Ada.Streams.Stream_Element_Array; Offset : in out Ada.Streams.Stream_Element_Offset) is begin Output (Offset + 0) := Image (Low_6 (Input (1))); Output (Offset + 1) := Image_2_4 (High_2 (Input (1)), Low_4 (Input (2))); Output (Offset + 2) := Image_4_2 (High_4 (Input (2)), Low_2 (Input (3))); Output (Offset + 3) := Image (High_6 (Input (3))); Offset := Offset + 4; end Encode_Block; procedure Encode_Double (Input : in Double_Byte; Padding : in Double_Byte_Padding; Output : in out Ada.Streams.Stream_Element_Array; Offset : in out Ada.Streams.Stream_Element_Offset) is begin Output (Offset + 0) := Image (Low_6 (Input (1))); Output (Offset + 1) := Image_2_4 (High_2 (Input (1)), Low_4 (Input (2))); Output (Offset + 2) := Image_4_2 (High_4 (Input (2)), Padding); Offset := Offset + 3; end Encode_Double; procedure Encode_Single (Input : in Character; Padding : in Single_Byte_Padding; Output : in out Ada.Streams.Stream_Element_Array; Offset : in out Ada.Streams.Stream_Element_Offset) is begin Output (Offset + 0) := Image (Low_6 (Input)); Output (Offset + 1) := Image_2_4 (High_2 (Input), Padding); Offset := Offset + 2; end Encode_Single; procedure Next_Digit (Input : in Ada.Streams.Stream_Element_Array; Offset : in out Ada.Streams.Stream_Element_Offset; Digit : out Base_64_Digit) is begin while Input (Offset) not in Base_64_Symbol loop Offset := Offset + 1; end loop; Digit := Value (Input (Offset)); Offset := Offset + 1; end Next_Digit; procedure Next_Digit_Or_End (Input : in Ada.Streams.Stream_Element_Array; Offset : in out Ada.Streams.Stream_Element_Offset; Digit : out Base_64_Digit; Finished : out Boolean) is begin loop if Offset not in Input'Range then Finished := True; return; end if; exit when Input (Offset) in Base_64_Symbol; Offset := Offset + 1; end loop; Digit := Value (Input (Offset)); Finished := False; Offset := Offset + 1; end Next_Digit_Or_End; end Natools.Smaz_Implementations.Base_64_Tools;
-- { dg-do compile } -- { dg-options "-O -gnatn -Winline" } with Inline10_Pkg; use Inline10_Pkg; procedure Inline10 is begin Test (0); end;
----------------------------------------------------------------------- -- gen-artifacts-distribs-copies -- Copy based distribution artifact -- Copyright (C) 2012, 2013 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- -- The <b>Gen.Artifacts.Distribs.Copies</b> package provides distribution rules -- to copy a file or a directory to the distribution area. private package Gen.Artifacts.Distribs.Copies is -- Create a distribution rule to copy a set of files or directories. function Create_Rule (Node : in DOM.Core.Node; Copy_First_File : in Boolean) return Distrib_Rule_Access; -- ------------------------------ -- Distribution artifact -- ------------------------------ type Copy_Rule is new Distrib_Rule with private; type Copy_Rule_Access is access all Copy_Rule'Class; -- Get a name to qualify the installation rule (used for logs). overriding function Get_Install_Name (Rule : in Copy_Rule) return String; overriding procedure Install (Rule : in Copy_Rule; Path : in String; Files : in File_Vector; Context : in out Generator'Class); private type Copy_Rule is new Distrib_Rule with record -- When True and there are several source files, use the first file. -- Otherwise, use the last file. Copy_First_File : Boolean := False; end record; end Gen.Artifacts.Distribs.Copies;
type Matrix is array(Positive Range <>, Positive Range <>) of Integer; mat : Matrix(1..5,1..5) := (others => (others => 0)); -- then after the declarative section: for i in mat'Range(1) loop mat(i,i) := 1; end loop;
-- Copyright (c) 2017 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with LSP.Message_Handlers; with LSP.Messages; with LSP.Servers; with Ada_LSP.Contexts; package Ada_LSP.Handlers is type Message_Handler (Server : access LSP.Servers.Server; Context : access Ada_LSP.Contexts.Context) is limited new LSP.Message_Handlers.Request_Handler and LSP.Message_Handlers.Notification_Handler with private; private type Message_Handler (Server : access LSP.Servers.Server; Context : access Ada_LSP.Contexts.Context) is limited new LSP.Message_Handlers.Request_Handler and LSP.Message_Handlers.Notification_Handler with record null; end record; overriding procedure Exit_Notification (Self : access Message_Handler); overriding procedure Initialize_Request (Self : access Message_Handler; Value : LSP.Messages.InitializeParams; Response : in out LSP.Messages.Initialize_Response); overriding procedure Text_Document_Did_Change (Self : access Message_Handler; Value : LSP.Messages.DidChangeTextDocumentParams); overriding procedure Text_Document_Did_Open (Self : access Message_Handler; Value : LSP.Messages.DidOpenTextDocumentParams); overriding procedure Text_Document_Symbol_Request (Self : access Message_Handler; Value : LSP.Messages.DocumentSymbolParams; Response : in out LSP.Messages.Symbol_Response); overriding procedure Text_Document_Completion_Request (Self : access Message_Handler; Value : LSP.Messages.TextDocumentPositionParams; Response : in out LSP.Messages.Completion_Response); end Ada_LSP.Handlers;
with Ada.Text_Io; use Ada.Text_Io; procedure Temp_File is Temp : File_Type; Contents : String(1..80); Length : Natural; begin -- Create a temporary file Create(File => Temp); Put_Line(File => Temp, Item => "Hello World"); Reset(File => Temp, Mode => In_File); Get_Line(File => Temp, Item => Contents, Last => Length); Put_Line(Contents(1..Length)); end Temp_File;
-- part of ParserTools, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "copying.txt" with Ada.Containers; with Ada.Strings.UTF_Encoding; with Ada.Finalization; with System.Storage_Elements; private with Ada.Unchecked_Conversion; package Text is -- this package defines a reference-counted string pointer type. it is used -- for all YAML data entities and relieves the user from the need to -- manually dispose events created by the parser. -- -- typically, YAML content strings are deallocated in the same order as they -- are allocated. this knowledge is built into a storage pool for efficient -- memory usage and to avoid fragmentation. -- -- to be able to efficiently interface with C, this package allocates its -- strings so that they can directly be passed on to C without the need to -- copy any data. Use the subroutines Export and Delete_Exported to get -- C-compatible string values from a Reference. these subroutines also -- take care of reference counting for values exposed to C. this means that -- after exporting a value, you *must* eventually call Delete_Exported in -- order for the value to be freed. -- -- HINT: this package makes use of compiler implementation details and may -- not work with other compilers. however, since there currently are no -- Ada 2012 compilers but GNAT, this is not considered a problem. -- the pool allocates the memory it uses on the heap. it is allowed for the -- pool to vanish while References created on it are still around. the -- heap memory is reclaimed when the pool itself and all References -- created by it vanish. -- -- this type has pointer semantics in order to allow the usage of the same -- pool at different places without the need of access types. copying a -- value of this type will make both values use the same memory. use Create -- to generate a new independent pool. -- all strings generated by Yaml are encoded in UTF-8, regardless of input -- encoding. subtype UTF_8_String is Ada.Strings.UTF_Encoding.UTF_8_String; type UTF_8_String_Access is access UTF_8_String; subtype Pool_Offset is System.Storage_Elements.Storage_Offset range 0 .. System.Storage_Elements.Storage_Offset (Integer'Last); -- this type is used to forbid the user to copy the pointer to UTF_8_String -- into a variable of a named access type. thus, we can be sure that no -- pointer to the String outlives the smart pointers. type Accessor (Data : not null access constant UTF_8_String) is limited private with Implicit_Dereference => Data; -- this is a smart pointer. use Value to access its value. type Reference is tagged private with Constant_Indexing => Element; function Value (Object : Reference) return Accessor with Inline; -- shortcut for Object.Value.Data'Length function Length (Object : Reference) return Natural with Inline; function "&" (Left, Right : Reference) return String with Inline; function "&" (Left : Reference; Right : String) return String with Inline; function "&" (Left : Reference; Right : Character) return String with Inline; function "&" (Left : String; Right : Reference) return String with Inline; function "&" (Left : Character; Right : Reference) return String with Inline; -- compares the string content of two Content values. function "=" (Left, Right : Reference) return Boolean with Inline; function "=" (Left : Reference; Right : String) return Boolean with Inline; function "=" (Left : String; Right : Reference) return Boolean with Inline; function Hash (Object : Reference) return Ada.Containers.Hash_Type; function Element (Object : Reference; Position : Positive) return Character; -- equivalent to the empty string. default value for References. Empty : constant Reference; -- this can be used for constant Reference values that are declared at -- library level where no Pool is available. References pointing to a -- Constant_Content_Holder are never freed. type Constant_Instance (<>) is private; -- note that there is a limit of 128 characters for Content values created -- like this. function Hold (Content : String) return Constant_Instance; -- get a Reference value which is a reference to the string contained in the -- Holder. function Held (Holder : Constant_Instance) return Reference; -- used for exporting to C interfaces subtype Exported is System.Address; -- increases the reference count and returns a value that can be used in -- places where C expects a `const char*` value. function Export (Object : Reference) return Exported; -- creates a content value from an exported pointer function Import (Pointer : Exported) return Reference; -- decreases the reference count (and so possibly deallocates the value). procedure Delete_Exported (Pointer : Exported); private -- this forces GNAT to store the First and Last dope values right before -- the first element of the String. we use that to our advantage. for UTF_8_String_Access'Size use Standard'Address_Size; type Chunk_Index_Type is range 1 .. 10; subtype Refcount_Type is Integer range 0 .. 2 ** 24 - 1; -- the pool consists of multiple chunks of memory. strings are allocated -- inside the chunks. type Pool_Array is array (Pool_Offset range <>) of System.Storage_Elements.Storage_Element; type Chunk is access Pool_Array; type Chunk_Array is array (Chunk_Index_Type) of Chunk; type Usage_Array is array (Chunk_Index_Type) of Natural; -- the idea is that Cur is the pointer to the active Chunk. all new strings -- are allocated in that active Chunk until there is no more space. then, -- we allocate a new Chunk of twice the size of the current one and make -- that the current Chunk. the old Chunk lives on until all Content strings -- allocated on it vanish. Usage is the number of strings currently -- allocated on the Chunk and is used as reference count. the current Chunk -- has Usage + 1 which prevents its deallocation even if the last Content -- string on it vanishes. the Content type's finalization takes care of -- decrementing the Usage value that counts allocated strings, while the -- String_Pool type's deallocation takes care of removing the +1 for the -- current Chunk. -- -- we treat each Chunk basically as a bitvector ring list, and Pos is the -- current offset in the current Chunk. instead of having a full bitvector -- for allocating, we use the dope values from the strings that stay in the -- memory after deallocation. besides the First and Last values, we also -- store a reference count in the dope. so when searching for a place to -- allocate a new string, we can skip over regions that have a non-zero -- reference count in their header, and those with a 0 reference count are -- available space. compared to a real bitvector, we always have the -- information of the length of an free region available. we can avoid -- fragmentation by merging a region that is freed with the surrounding free -- regions. type Pool_Data is record Refcount : Refcount_Type := 1; Chunks : Chunk_Array; Usage : Usage_Array := (1 => 1, others => 0); Cur : Chunk_Index_Type := 1; Pos : Pool_Offset; end record; type Pool_Data_Access is access Pool_Data; for Pool_Data_Access'Size use Standard'Address_Size; -- this is the dope vector of each string allocated in a Chunk. it is put -- immediately before the string's value. note that the First and Last -- elements are at the exact positions where GNAT searches for the string's -- boundary dope. this allows us to access those values for maintaining the -- ring list. type Header is record Pool : Pool_Data_Access; Chunk_Index : Chunk_Index_Type; Refcount : Refcount_Type := 1; First, Last : Pool_Offset; end record; Chunk_Index_Start : constant := Standard'Address_Size; Refcount_Start : constant := Standard'Address_Size + 8; First_Start : constant := Standard'Address_Size + 32; Last_Start : constant := First_Start + Integer'Size; Header_End : constant := Last_Start + Integer'Size - 1; for Header use record Pool at 0 range 0 .. Chunk_Index_Start - 1; Chunk_Index at 0 range Chunk_Index_Start .. Refcount_Start - 1; Refcount at 0 range Refcount_Start .. First_Start - 1; First at 0 range First_Start .. Last_Start - 1; Last at 0 range Last_Start .. Header_End; end record; for Header'Size use Header_End + 1; use type System.Storage_Elements.Storage_Offset; Header_Size : constant Pool_Offset := Header'Size / System.Storage_Unit; type Constant_Instance (Length : Positive) is record Data : String (1 .. Length); end record; Chunk_Start_Index : constant := Chunk_Index_Start / System.Storage_Unit + 1; Refcount_Start_Index : constant := Refcount_Start / System.Storage_Unit + 1; First_Start_Index : constant := First_Start / System.Storage_Unit + 1; Last_Start_Index : constant := Last_Start / System.Storage_Unit + 1; End_Index : constant := (Header_End + 1) / System.Storage_Unit; Empty_Holder : constant Constant_Instance := (Length => Positive (Header_Size) + 1, Data => (1 .. Chunk_Start_Index - 1 => Character'Val (0), Chunk_Start_Index .. Refcount_Start_Index - 1 => <>, Refcount_Start_Index .. First_Start_Index - 2 => Character'Val (0), First_Start_Index - 1 => Character'Val (1), First_Start_Index .. Last_Start_Index - 2 => Character'Val (0), Last_Start_Index - 1 => Character'Val (1), Last_Start_Index .. End_Index => Character'Val (0), End_Index + 1 => Character'Val (0))); type Accessor (Data : not null access constant UTF_8_String) is limited record -- holds a copy of the smart pointer, so the string cannot be freed -- while the accessor lives. Hold : Reference; end record; function To_UTF_8_String_Access is new Ada.Unchecked_Conversion (System.Address, UTF_8_String_Access); type Reference is new Ada.Finalization.Controlled with record Data : UTF_8_String_Access := To_UTF_8_String_Access (Empty_Holder.Data (Positive (Header_Size) + 1)'Address); end record; overriding procedure Adjust (Object : in out Reference); overriding procedure Finalize (Object : in out Reference); Empty : constant Reference := (Ada.Finalization.Controlled with Data => <>); -- it is important that all allocated strings are aligned to the header -- length. else, it may happen that we generate a region of free memory that -- is not large enough to hold a header – but we need to write the header -- there to hold information for the ring list. therefore, whenever we -- calculate offsets, we use this to round them up to a multiple of -- Header_Size. function Round_To_Header_Size (Length : Pool_Offset) return Pool_Offset is ((Length + Header_Size - 1) / Header_Size * Header_Size); procedure Decrease_Usage (Pool : in out Pool_Data_Access; Chunk_Index : Chunk_Index_Type); function Fitting_Position (Length : Pool_Offset; P : Pool_Data_Access) return System.Address; function Header_Of (S : UTF_8_String_Access) return not null access Header; function As_String (C : Chunk) return String; end Text;
with Qt; use Qt; with Qt.QApplication; use Qt.QApplication; with Qt.QWidget; use Qt.QWidget; with CovidSimForm; use CovidSimForm; procedure covidsim is begin covidsim_form_init; QWidget_show(covidsim_form); QApplication_invoke; end;
with Ada.Text_IO; use Ada.Text_IO; procedure Test_Selection_Sort is type Integer_Array is array (Positive range <>) of Integer; procedure Sort (A : in out Integer_Array) is Min : Positive; Temp : Integer; begin for I in A'First..A'Last - 1 loop Min := I; for J in I + 1..A'Last loop if A (Min) > A (J) then Min := J; end if; end loop; if Min /= I then Temp := A (I); A (I) := A (Min); A (Min) := Temp; end if; end loop; end Sort; A : Integer_Array := (4, 9, 3, -2, 0, 7, -5, 1, 6, 8); begin Sort (A); for I in A'Range loop Put (Integer'Image (A (I)) & " "); end loop; end Test_Selection_Sort;
with Text_Io; -- always need these two lines for printing use Text_Io; with Ada.Float_Text_IO; use Ada.Float_Text_IO; package body Adaptive_Quad is function SimpsonsRule(a, b:float) return float is c, h3:float; begin c := (a+b) / 2.0; h3 := abs(b-a) / 6.0; return h3*(f(a) + 4.0*f(c) + f(b)); end SimpsonsRule; function RecAQuad(a, b, eps, whole:float) return float is c, left, right:float; result1, result2:float; procedure Rec is task recurTask1; task recurTask2; task body recurTask1 is begin result1 := RecAQuad(a, c, eps/2.0, left); end recurTask1; task body recurTask2 is begin result2 := RecAQuad(c, b, eps/2.0, right); end recurTask2; begin -- Rec null; end Rec; begin c := (a+b) / 2.0; left := SimpsonsRule(a,c); right := SimpsonsRule(c,b); if (abs(left + right - whole) <= 15.0*eps) then return left + right + (left + right - whole)/15.0; else Rec; end if; return result1 + result2; end RecAQuad; function AQuad(a, b, eps:float) return float is begin return RecAQuad(a, b, eps, SimpsonsRule(a,b)); end AQuad; end Adaptive_Quad;
-- This file is generated by SWIG. Do *not* modify by hand. -- with llvm; with Interfaces.C.Strings; package LLVM_execution_Engine.Binding is procedure LLVMLinkInJIT; procedure LLVMLinkInInterpreter; function LLVMCreateGenericValueOfInt (Ty : in llvm.LLVMTypeRef; N : in Interfaces.C.Extensions.unsigned_long_long; IsSigned : in Interfaces.C.int) return LLVM_execution_Engine.LLVMGenericValueRef; function LLVMCreateGenericValueOfPointer (P : access Interfaces.C.Extensions.void) return LLVM_execution_Engine.LLVMGenericValueRef; function LLVMCreateGenericValueOfFloat (Ty : in llvm.LLVMTypeRef; N : in Interfaces.C.double) return LLVM_execution_Engine.LLVMGenericValueRef; function LLVMGenericValueIntWidth (GenValRef : in LLVM_execution_Engine.LLVMGenericValueRef) return Interfaces.C.unsigned; function LLVMGenericValueToInt (GenVal : in LLVM_execution_Engine.LLVMGenericValueRef; IsSigned : in Interfaces.C.int) return Interfaces.C.Extensions.unsigned_long_long; function LLVMGenericValueToPointer (GenVal : in LLVM_execution_Engine.LLVMGenericValueRef) return access Interfaces.C.Extensions.void; function LLVMGenericValueToFloat (TyRef : in llvm.LLVMTypeRef; GenVal : in LLVM_execution_Engine.LLVMGenericValueRef) return Interfaces.C.double; procedure LLVMDisposeGenericValue (GenVal : in LLVM_execution_Engine.LLVMGenericValueRef); function LLVMCreateExecutionEngine (OutEE : access LLVM_execution_Engine.LLVMExecutionEngineRef; MP : in llvm.LLVMModuleProviderRef; OutError : access Interfaces.C.Strings.chars_ptr) return Interfaces.C.int; function LLVMCreateInterpreter (OutInterp : access LLVM_execution_Engine.LLVMExecutionEngineRef; MP : in llvm.LLVMModuleProviderRef; OutError : access Interfaces.C.Strings.chars_ptr) return Interfaces.C.int; function LLVMCreateJITCompiler (OutJIT : access LLVM_execution_Engine.LLVMExecutionEngineRef; MP : in llvm.LLVMModuleProviderRef; OptLevel : in Interfaces.C.unsigned; OutError : access Interfaces.C.Strings.chars_ptr) return Interfaces.C.int; procedure LLVMDisposeExecutionEngine (EE : in LLVM_execution_Engine.LLVMExecutionEngineRef); procedure LLVMRunStaticConstructors (EE : in LLVM_execution_Engine.LLVMExecutionEngineRef); procedure LLVMRunStaticDestructors (EE : in LLVM_execution_Engine.LLVMExecutionEngineRef); function LLVMRunFunctionAsMain (EE : in LLVM_execution_Engine.LLVMExecutionEngineRef; F : in llvm.LLVMValueRef; ArgC : in Interfaces.C.unsigned; ArgV : access Interfaces.C.Strings.chars_ptr; EnvP : access Interfaces.C.Strings.chars_ptr) return Interfaces.C.int; function LLVMRunFunction (EE : in LLVM_execution_Engine.LLVMExecutionEngineRef; F : in llvm.LLVMValueRef; NumArgs : in Interfaces.C.unsigned; Args : access LLVM_execution_Engine.LLVMGenericValueRef) return LLVM_execution_Engine.LLVMGenericValueRef; procedure LLVMFreeMachineCodeForFunction (EE : in LLVM_execution_Engine.LLVMExecutionEngineRef; F : in llvm.LLVMValueRef); procedure LLVMAddModuleProvider (EE : in LLVM_execution_Engine.LLVMExecutionEngineRef; MP : in llvm.LLVMModuleProviderRef); function LLVMRemoveModuleProvider (EE : in LLVM_execution_Engine.LLVMExecutionEngineRef; MP : in llvm.LLVMModuleProviderRef; OutMod : access llvm.LLVMModuleRef; OutError : access Interfaces.C.Strings.chars_ptr) return Interfaces.C.int; function LLVMFindFunction (EE : in LLVM_execution_Engine.LLVMExecutionEngineRef; Name : in Interfaces.C.Strings.chars_ptr; OutFn : access llvm.LLVMValueRef) return Interfaces.C.int; function LLVMGetExecutionEngineTargetData (EE : in LLVM_execution_Engine.LLVMExecutionEngineRef) return LLVM_execution_Engine.LLVMTargetDataRef; procedure LLVMAddGlobalMapping (EE : in LLVM_execution_Engine.LLVMExecutionEngineRef; Global : in llvm.LLVMValueRef; Addr : access Interfaces.C.Extensions.void); function LLVMGetPointerToGlobal (EE : in LLVM_execution_Engine.LLVMExecutionEngineRef; Global : in llvm.LLVMValueRef) return access Interfaces.C.Extensions.void; private pragma Import (C, LLVMLinkInJIT, "Ada_LLVMLinkInJIT"); pragma Import (C, LLVMLinkInInterpreter, "Ada_LLVMLinkInInterpreter"); pragma Import (C, LLVMCreateGenericValueOfInt, "Ada_LLVMCreateGenericValueOfInt"); pragma Import (C, LLVMCreateGenericValueOfPointer, "Ada_LLVMCreateGenericValueOfPointer"); pragma Import (C, LLVMCreateGenericValueOfFloat, "Ada_LLVMCreateGenericValueOfFloat"); pragma Import (C, LLVMGenericValueIntWidth, "Ada_LLVMGenericValueIntWidth"); pragma Import (C, LLVMGenericValueToInt, "Ada_LLVMGenericValueToInt"); pragma Import (C, LLVMGenericValueToPointer, "Ada_LLVMGenericValueToPointer"); pragma Import (C, LLVMGenericValueToFloat, "Ada_LLVMGenericValueToFloat"); pragma Import (C, LLVMDisposeGenericValue, "Ada_LLVMDisposeGenericValue"); pragma Import (C, LLVMCreateExecutionEngine, "Ada_LLVMCreateExecutionEngine"); pragma Import (C, LLVMCreateInterpreter, "Ada_LLVMCreateInterpreter"); pragma Import (C, LLVMCreateJITCompiler, "Ada_LLVMCreateJITCompiler"); pragma Import (C, LLVMDisposeExecutionEngine, "Ada_LLVMDisposeExecutionEngine"); pragma Import (C, LLVMRunStaticConstructors, "Ada_LLVMRunStaticConstructors"); pragma Import (C, LLVMRunStaticDestructors, "Ada_LLVMRunStaticDestructors"); pragma Import (C, LLVMRunFunctionAsMain, "Ada_LLVMRunFunctionAsMain"); pragma Import (C, LLVMRunFunction, "Ada_LLVMRunFunction"); pragma Import (C, LLVMFreeMachineCodeForFunction, "Ada_LLVMFreeMachineCodeForFunction"); pragma Import (C, LLVMAddModuleProvider, "Ada_LLVMAddModuleProvider"); pragma Import (C, LLVMRemoveModuleProvider, "Ada_LLVMRemoveModuleProvider"); pragma Import (C, LLVMFindFunction, "Ada_LLVMFindFunction"); pragma Import (C, LLVMGetExecutionEngineTargetData, "Ada_LLVMGetExecutionEngineTargetData"); pragma Import (C, LLVMAddGlobalMapping, "Ada_LLVMAddGlobalMapping"); pragma Import (C, LLVMGetPointerToGlobal, "Ada_LLVMGetPointerToGlobal"); end LLVM_execution_Engine.Binding;
-------------------------------------------------------------------------------- -- -- -- Copyright (C) 2004, RISC OS Ada Library (RASCAL) developers. -- -- -- -- This library is free software; you can redistribute it and/or -- -- modify it under the terms of the GNU Lesser General Public -- -- License as published by the Free Software Foundation; either -- -- version 2.1 of the License, or (at your option) any later version. -- -- -- -- This library is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- -- Lesser General Public License for more details. -- -- -- -- You should have received a copy of the GNU Lesser General Public -- -- License along with this library; if not, write to the Free Software -- -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- -- -- -------------------------------------------------------------------------------- -- $Author$ -- $Date$ -- $Revision$ with Kernel; use Kernel; with Interfaces.C; use Interfaces.C; with Reporter; with RASCAL.Utility; use RASCAL.Utility; with RASCAL.Memory; use RASCAL.Memory; with RASCAL.OS; with RASCAL.Mode; package body RASCAL.WimpWindow is Wimp_Extend : constant := 16#400FB#; Wimp_GetWindowInfo : constant := 16#400CC#; Wimp_GetWindowState : constant := 16#400CB#; Wimp_GetWindowOutline : constant := 16#400E0#; Wimp_CreateWindow : constant := 16#400C1#; Wimp_DeleteWindow : constant := 16#400C3#; Wimp_OpenWindow : constant := 16#400C5#; Wimp_CloseWindow : constant := 16#400C6#; Wimp_SetExtent : constant := 16#400D7#; Wimp_SetCaretPosition : constant := 16#400D2#; Wimp_GetCaretPosition : constant := 16#400D3#; Wimp_RedrawWindow : constant := 16#400C8#; Wimp_UpdateWindow : constant := 16#400C9#; Wimp_GetRectangle : constant := 16#400CA#; Wimp_ForceRedraw : constant := 16#400D1#; -- procedure Open_WindowMax (Window : in Wimp_Handle_Type) is Info : Wimp_WindowInfo_Type(0) := Get_WindowInfo(Window,false); Open : Wimp_OpenWindow_Type; begin Open.Visible_Area_Max_Y := Info.Visible_Area_Max_Y; Open.Visible_Area_Min_X := Info.Visible_Area_Min_X; Open.Visible_Area_Min_Y := Info.Visible_Area_Max_Y + Info.Work_Area_Min_Y; if Open.Visible_Area_Min_Y < 40 then Open.Visible_Area_Min_Y := 40; end if; Open.Visible_Area_Max_X := Info.Visible_Area_Min_X + Info.Work_Area_Max_X; Open.Window := Window; Open_Window (Open); end Open_WindowMax; -- procedure Open_WindowCentered (Window : in Wimp_Handle_Type) is right,top : Integer; width,height : Integer; x,y : Integer; Info : Wimp_WindowInfo_Type(0) := Get_WindowInfo(Window,false); Open : Wimp_OpenWindow_Type; begin Right := Mode.Get_X_Resolution; Top := Mode.Get_Y_Resolution; width := Info.Visible_Area_Min_X - Info.Visible_Area_Max_X; height := Info.Visible_Area_Max_Y - Info.Visible_Area_Min_Y; x := (right - width) / 2 + width; y := (top - height) / 2 + height; Open.Visible_Area_Min_X := x; Open.Visible_Area_Min_Y := y - height; Open.Visible_Area_Max_X := x - width; Open.Visible_Area_Max_Y := y; Open.Window := Window; Open_Window (Open); end Open_WindowCentered; -- procedure Open_WindowAt (Window : in Wimp_Handle_Type; x : in Integer; y : in Integer) is width,height : Integer; Info : Wimp_WindowInfo_Type(0) := Get_WindowInfo(Window,false); Open : Wimp_OpenWindow_Type; begin width := Info.Visible_Area_Min_X - Info.Visible_Area_Max_X; height := Info.Visible_Area_Max_Y - Info.Visible_Area_Min_Y; Open.Visible_Area_Min_X := x; Open.Visible_Area_Min_Y := y - height; Open.Visible_Area_Max_X := x - width; Open.Visible_Area_Max_Y := y; Open.Window := Window; Open_Window (Open); end Open_WindowAt; -- procedure Open_Window (Block : in Wimp_OpenWindow_Type) is Register : aliased Kernel.swi_regs; Error : oserror_access; begin Register.R(1) := Adr_To_Int(Block'Address); Error := Kernel.swi(Wimp_OpenWindow,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Open_Window: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; end Open_Window; -- procedure Close_Window (Window : in Wimp_Handle_Type) is Register : aliased Kernel.swi_regs; Error : oserror_access; begin Register.R(1) := Int (Window); Error := Kernel.swi(Wimp_CloseWindow,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Close_Window: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; end Close_Window; -- procedure Redraw_Window (Window : in Wimp_Handle_Type; Block : in out Wimp_RedrawInfo_Type; More : out Boolean) is Register : aliased Kernel.swi_regs; Error : oserror_access; begin Block.Window := Window; Register.R(1) := Adr_To_Int(Block'Address); Error := Kernel.SWI(Wimp_RedrawWindow,Register'Access,Register'Access); More := Error = null; end Redraw_Window; -- function Get_Rectangle (Block : in Wimp_RedrawInfo_Type) return Boolean is Register : aliased Kernel.swi_regs; Error : oserror_access; begin Register.R(0) := 0; Register.R(1) := Adr_To_Int(Block'Address); Error := Kernel.swi(Wimp_GetRectangle,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Get_Rectangle: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return Integer(Register.R(0)) /= 0; end Get_Rectangle; -- function Get_WindowOutline (Window : in Wimp_Handle_Type) return Wimp_WindowOutline_Type is Register : aliased Kernel.swi_regs; Error : oserror_access; Block : Wimp_WindowOutline_Type; begin Block.Window := Window; -- workaround for 32bit-bug Memory.PutWord(Integer(Window),Block'Address,0); Register.R(1) := Adr_To_Int(Block'Address); Error := Kernel.swi(Wimp_GetWindowOutline,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Get_WindowOutline: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return Block; end Get_WindowOutline; -- function Get_WindowState (Window : in Wimp_Handle_Type) return Wimp_WindowState_Type is Register : aliased Kernel.swi_regs; Error : oserror_access; Block : Wimp_WindowState_Type; begin Block.Window := Window; -- workaround for 32bit-bug Memory.PutWord(Integer(Window),Block'Address,0); Register.R(1) := Adr_To_Int(Block'Address); Error := Kernel.swi(Wimp_GetWindowState,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Get_WindowState: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return Block; end Get_WindowState; -- function Get_ParentWindow (Window : in Wimp_Handle_Type) return Wimp_Handle_Type is Register : aliased Kernel.swi_regs; Error : oserror_access; Block : Wimp_WindowState_Type; begin Block.Window := Window; -- workaround for 32bit-bug Memory.PutWord(Integer(Window),Block'Address,0); Register.R(1) := Adr_To_Int(Block'Address); Register.R(2) := 16#4B534154#; Error := Kernel.swi(Wimp_GetWindowState,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Get_ParentWindow: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return Wimp_Handle_Type(Register.R(3)); end Get_ParentWindow; -- function Get_AncestorWindow (Window : in Wimp_Handle_Type) return Wimp_Handle_Type is Child : Wimp_Handle_Type := Window; Parent : Wimp_Handle_Type; begin loop Parent := Get_ParentWindow(Child); -- Child has no parent if GetParent returns -1 exit when Integer(Parent) = -1; Child := Parent; end loop; return Child; end Get_AncestorWindow; -- function Get_WindowInfo(Window : in Wimp_Handle_Type; Icons : in Boolean := true) return Wimp_WindowInfo_Type is Register : aliased Kernel.swi_regs; Error : oserror_access; Icon_Nr : Integer := 0; NoIcons : Wimp_WindowInfo_Type (0); begin NoIcons.Window := Window; Register.R(1) := Adr_To_Int(NoIcons.Window'Address); Register.R(1) := Register.R(1) + 1; -- Set 'No icons' flag Error := Kernel.swi(Wimp_GetWindowInfo,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Get_WindowInfo (I): " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; if not Icons then return NoIcons; end if; Icon_Nr := NoIcons.Nr_Of_Icons_Initially; declare Block : Wimp_WindowInfo_Type(Icon_Nr); begin Block.Window := Window; Register.R(1) := Adr_To_Int(Block.Window'Address); Error := Kernel.swi(Wimp_GetWindowInfo,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Get_WindowInfo (II): " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return Block; end; end Get_WindowInfo; -- function Get_External_WindowInfo (Window : in Wimp_Handle_Type) return Wimp_External_WindowInfo_Type is Register : aliased Kernel.swi_regs; Error : oserror_access; Info : Wimp_External_WindowInfo_Type; begin Info.Window := Window; Register.R(0) := 11; Register.R(1) := Adr_To_Int(Info'Address); Error := Kernel.swi(Wimp_Extend,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Get_External_WindowInfo: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return Info; end Get_External_WindowInfo; -- function Get_Generic_WindowInfo return Wimp_External_WindowInfo_Type is begin return Get_External_WindowInfo(0); end Get_Generic_WindowInfo; -- procedure Get_WindowPosition (Window : in Wimp_Handle_Type; X_Pos : out Integer; Y_Pos : out Integer) is State : Wimp_WindowState_Type := WimpWindow.Get_WindowState (Window); begin X_Pos := State.Visible_Area_Min_X; Y_Pos := State.Visible_Area_Max_Y; end Get_WindowPosition; -- function Is_Open (Window : in Wimp_Handle_Type) return Boolean is Register : aliased Kernel.swi_regs; Error : Kernel.oserror_access; Block : Wimp_WindowState_Type; begin Block.Window := Window; -- 32bit - bug workaround Memory.PutWord(Integer(Window),Block'Address,0); Register.R(1) := Adr_To_Int(Block'Address); Error := Kernel.SWI (Wimp_GetWindowState, Register'Access, Register'Access); return ((Block.Window_Flags and 2#10000000000000000#) > 0); end Is_Open; -- procedure Work_To_Screen (Window : in Wimp_Handle_Type; Work_X : in Integer; Work_Y : in Integer; Screen_X : out Integer; Screen_Y : out Integer) is Block : Wimp_WindowState_Type := Get_WindowState (Window); begin screen_x := work_x - (Block.Scroll_X_Offset - Block.Visible_Area_Min_X); screen_y := work_y - (Block.Scroll_Y_Offset - Block.Visible_Area_Max_Y); end Work_To_Screen; -- procedure Screen_To_Work (Window : in Wimp_Handle_Type; Screen_X : in Integer; Screen_Y : in Integer; Work_X : out Integer; Work_Y : out Integer) is Block : Wimp_WindowState_Type := Get_WindowState (Window); begin work_x := screen_x + (Block.Scroll_X_Offset - Block.Visible_Area_Min_X); work_y := screen_y + (Block.Scroll_Y_Offset - Block.Visible_Area_Max_Y); end Screen_To_Work; -- procedure Force_Redraw (Window : in Wimp_Handle_Type; Min_X : in Integer; Min_Y : in Integer; Max_X : in Integer; Max_Y : in Integer) is Register : aliased Kernel.swi_regs; Error : Kernel.oserror_access; begin Register.R(0) := Int(Window); Register.R(1) := Int(Min_X); Register.R(2) := Int(Min_Y); Register.R(3) := Int(Max_X); Register.R(4) := Int(Max_Y); Error := Kernel.swi (Wimp_ForceRedraw, register'Access, register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.ForceRedraw: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; end Force_Redraw; -- procedure Force_RedrawAll is begin Force_Redraw (-1,0,0,9999,9999); end Force_RedrawAll; -- procedure Force_WindowRedraw (Window : in Wimp_Handle_Type) is Register : aliased Kernel.swi_regs; Error : Kernel.oserror_access; Info : Wimp_WindowInfo_Type(0) := Get_WindowInfo(Window,false); begin Register.R(0) := Int(Window); Register.R(1) := Int(Info.Work_Area_Min_X); Register.R(2) := Int(Info.Work_Area_Min_Y); Register.R(3) := Int(Info.Work_Area_Max_X); Register.R(4) := Int(Info.Work_Area_Max_Y); Error := Kernel.swi (Wimp_ForceRedraw, register'Access, register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Force_WindowRedraw: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; end Force_WindowRedraw; -- function Get_WindowTitle (Window : in Wimp_Handle_Type) return String is Info : Wimp_WindowInfo_Type(0) := Get_WindowInfo(Window,false); begin return To_Ada(Info.Title_Data.Title_Data); end Get_WindowTitle; -- function Get_Extent (Window : in Wimp_Handle_Type) return Wimp_WindowExtent_Type is Extent : Wimp_WindowExtent_Type; Info : Wimp_WindowInfo_Type(0) := Get_WindowInfo(Window,false); begin Extent.Work_Area_Min_X := Info.Work_Area_Min_X; Extent.Work_Area_Min_Y := Info.Work_Area_Min_Y; Extent.Work_Area_Max_X := Info.Work_Area_Max_X; Extent.Work_Area_Max_Y := Info.Work_Area_Max_Y; return Extent; end Get_Extent; -- procedure Set_Extent (Window : in Wimp_Handle_Type; Min_X : in Integer; Min_Y : in Integer; Max_X : in Integer; Max_Y : in Integer) is Register : aliased Kernel.swi_regs; Error : Kernel.oserror_access; Extent : Wimp_WindowExtent_Type; begin Extent.Work_Area_Min_X := Min_X; Extent.Work_Area_Min_Y := Min_Y; Extent.Work_Area_Max_X := Max_X; Extent.Work_Area_Max_Y := Max_Y; Register.R(0) := Int(Window); Register.R(1) := Adr_To_Int(Extent'Address); Error := Kernel.swi (Wimp_SetExtent, Register'Access, Register'Access); if Error /= null then pragma Debug(Reporter.Report("WimpWindow.Set_Extent: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; end Set_Extent; -- procedure Delete_Window (Window : in Wimp_Handle_Type) is Register : aliased Kernel.swi_regs; Error : Kernel.oserror_access; Block : Wimp_WindowOutline_Type; begin Block.Window := Window; Register.R(1) := Adr_To_Int(Block'Address); Error := Kernel.SWI (Wimp_DeleteWindow, Register'Access, Register'Access); if Error /= null then pragma Debug(Reporter.Report("WimpWindow.Delete_Window: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; end Delete_Window; -- function Get_Parent (Window : in Wimp_Handle_Type) return Wimp_Handle_Type is Register : aliased Kernel.swi_regs; Error : Kernel.oserror_access; begin Register.R(0) := 6; Register.R(1) := Int(Window); Error := Kernel.swi(Wimp_Extend,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Get_Parent: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return Wimp_Handle_Type(Register.R(1)); end Get_Parent; -- function Get_Top_ChildWindow (Window : in Wimp_Handle_Type) return Wimp_Handle_Type is Register : aliased Kernel.swi_regs; Error : Kernel.oserror_access; begin Register.R(0) := 7; Register.R(1) := Int(Window); Error := Kernel.swi(Wimp_Extend,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Get_Top_ChildWindow: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return Wimp_Handle_Type(Register.R(1)); end Get_Top_ChildWindow; -- function Get_Bottom_ChildWindow (Window : in Wimp_Handle_Type) return Wimp_Handle_Type is Register : aliased Kernel.swi_regs; Error : Kernel.oserror_access; begin Register.R(0) := 8; Register.R(1) := Int(Window); Error := Kernel.swi(Wimp_Extend,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Get_Bottom_ChildWindow: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return Wimp_Handle_Type(Register.R(1)); end Get_Bottom_ChildWindow; -- function Get_Sibling_Below (Window : in Wimp_Handle_Type) return Wimp_Handle_Type is Register : aliased Kernel.swi_regs; Error : Kernel.oserror_access; begin Register.R(0) := 9; Register.R(1) := Int(Window); Error := Kernel.swi(Wimp_Extend,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Get_Sibling_Below: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return Wimp_Handle_Type(Register.R(1)); end Get_Sibling_Below; -- function Get_Sibling_Above (Window : in Wimp_Handle_Type) return Wimp_Handle_Type is Register : aliased Kernel.swi_regs; Error : Kernel.oserror_access; begin Register.R(0) := 10; Register.R(1) := Int(Window); Error := Kernel.swi(Wimp_Extend,register'Access,register'Access); if Error /=null then pragma Debug(Reporter.Report("WimpWindow.Get_Sibling_Above: " & To_Ada(Error.ErrMess))); OS.Raise_Error(Error); end if; return Wimp_Handle_Type(Register.R(1)); end Get_Sibling_Above; -- function Count_Children (Window : in Wimp_Handle_Type) return Natural is Count : Natural := 0; Child : Wimp_Handle_Type; begin Child := Get_Top_ChildWindow(Window); while Child /= -1 loop Count := Count + 1; Child := Get_Sibling_Below (Child); end loop; return Count; end Count_Children; -- function Get_Children (Window : in Wimp_Handle_Type) return Child_List_Type is Count : constant Natural := Count_Children (Window); List : Child_List_Type (1..Count); Child : Wimp_Handle_Type; begin Child := Get_Top_ChildWindow(Window); for i in List'range loop List (i) := Child; Child := Get_Sibling_Below (Child); end loop; return List; end Get_Children; -- end RASCAL.WimpWindow;
with Ada.Text_IO; package body Problem_45 is package IO renames Ada.Text_IO; procedure Solve is -- Hexagonal numbers are a subset of the triangle numbers so if -- it's a hexagonal number, it's also a triangle number. -- The problem description has us start at a non-unitary index. hexagonal_lead : Positive := 40_755; hexagonal_index : Positive := 143; pentagonal_lead : Positive := hexagonal_lead; pentagonal_index : Positive := 165; procedure Next_Hex is begin hexagonal_lead := hexagonal_lead + 4*hexagonal_index + 1; hexagonal_index := hexagonal_index + 1; end Next_Hex; procedure Next_Pent is begin pentagonal_lead := pentagonal_lead + 3*pentagonal_index + 1; pentagonal_index := pentagonal_index + 1; end Next_Pent; begin Next_Hex; Next_Pent; loop if hexagonal_lead > pentagonal_lead then Next_Pent; elsif hexagonal_lead < pentagonal_lead then Next_Hex; else exit; end if; end loop; IO.Put_Line(Positive'Image(hexagonal_lead)); end Solve; end Problem_45;
------------------------------------------------------------------------------ -- Copyright (c) 2014-2019, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Natools.Web.Sites provides a container for data about a related set of -- -- pages (i.e. a website). -- ------------------------------------------------------------------------------ with Ada.Calendar; with Natools.Constant_Indefinite_Ordered_Maps; with Natools.S_Expressions.Caches; with Natools.S_Expressions.Lockable; with Natools.S_Expressions.Printers.Pretty; with Natools.Web.ACL; with Natools.Web.Backends; with Natools.Web.Comment_Cookies; with Natools.Web.Containers; with Natools.Web.Exchanges; with Natools.Web.Filters.Stores; with Natools.Web.Tags; limited with Natools.Web.Sites.Updaters; limited with Natools.Web.Sites.Updates; private with Ada.Containers.Indefinite_Ordered_Maps; private with Natools.S_Expressions.Atom_Refs; package Natools.Web.Sites is type Page is interface; type Site is tagged limited private; procedure Queue_Update (Object : in Site; Update : in Updates.Site_Update'Class); -- Enqueue a pending update for Object procedure Set_Updater (Object : in out Site; Updater : in Updaters.Updater_Access); -- Register an updater to handle updates for Object procedure Insert (Object : in out Site; Path : in S_Expressions.Atom; New_Page : in Page'Class); -- Inefficiently add to Object a new page with the given web path procedure Insert (Object : in out Site; Tags : in Web.Tags.Tag_List; Visible : in Web.Tags.Visible'Class); -- Inefficiently add to Object a new Visible with the given tags procedure Remove (Object : in out Site; Tags : in Web.Tags.Tag_List; Visible : in Web.Tags.Visible'Class); -- Inefficiently remove from Object a Visible with the given tags procedure Register (Object : in out Site; Name : in String; Constructor : in Filters.Stores.Constructor); -- Register a filter constructor procedure Register (Object : in out Site; Key : in Character; Filter : in not null Comment_Cookies.Decoder); -- Register a cookie decoder procedure Reload (Object : in out Site); -- Reload Object data from its original file procedure Reset (Object : in out Site; File_Name : in String); -- (Re)initialize Object with data from the given file procedure Respond (Object : in out Site; Exchange : aliased in out Exchanges.Exchange); -- Look up internal data to provide a response in Exchange procedure Set_Cookie_Encoder (Object : in out Site; Filter : in not null Comment_Cookies.Encoder; Serialization : in Comment_Cookies.Serialization_Kind); -- Set the encoder for comment cookies function Get_Backend (From : Site; Name : S_Expressions.Atom) return Backends.Backend'Class; -- Return a backend from its name, or raise Constraint_Error function Get_Filter (From : Site; Name : S_Expressions.Atom) return Filters.Filter'Class; -- Return a filter from its name, or raise Filters.Stores.No_Filter function Get_Tags (Object : Site) return Tags.Tag_DB; -- Return the whole tag database function Get_Template (Object : in Site; Name : in S_Expressions.Atom) return Containers.Optional_Expression; -- Retrieve a template from its name function Get_Template (Object : in Site; Elements : in Containers.Expression_Maps.Constant_Map; Expression : in out S_Expressions.Lockable.Descriptor'Class; Name : in S_Expressions.Atom := S_Expressions.Null_Atom; Lookup_Template : in Boolean := True; Lookup_Element : in Boolean := True; Lookup_Name : in Boolean := False) return S_Expressions.Caches.Cursor; -- Look for an expression named Name or Expression.Current_Atom -- in Elements, or Object templates, or fallback on Expression. -- If Name is empty and Lookup_Name is true, use the current atom in -- Expression as name. function Load_Date (Object : in Site) return Ada.Calendar.Time; -- Return the time at which the site was finished loading function Named_Element_Map (Object : in Site; Name : in S_Expressions.Atom) return Containers.Expression_Maps.Constant_Map; -- Return an element of the internal element map function Default_Template (Object : Site) return S_Expressions.Atom; -- Retrieve the default template name procedure Set_Parameters (Object : in Site; Printer : in out S_Expressions.Printers.Pretty.Printer'Class); -- Set pretty printer parameters to sitewide values type Exchange (Backend : not null access Exchanges.Exchange; Site : not null access constant Sites.Site) is limited private with Implicit_Dereference => Backend; function Comment_Info (Ex : in out Exchange) return Comment_Cookies.Comment_Info; function Identity (Ex : Exchange) return Containers.Identity; procedure Set_Comment_Cookie (Ex : in out Exchange; Info : in Comment_Cookies.Comment_Info); -- type Page is interface; procedure Respond (Object : in out Page; Exchange : in out Sites.Exchange; Extra_Path : in S_Expressions.Atom) is abstract with Pre'Class => not Exchanges.Has_Response (Exchange.Backend.all); package Page_Maps is new Constant_Indefinite_Ordered_Maps (S_Expressions.Atom, Page'Class, S_Expressions."<"); type Site_Builder (<>) is limited private; -- Temporary representation of Site objects while they are being built procedure Expire_At (Builder : in out Site_Builder; Time : in Ada.Calendar.Time); -- Set the expiration time to Time if it's not already earlier function Get_Backend (From : Site_Builder; Name : S_Expressions.Atom) return Backends.Backend'Class; -- Return a backend from its name, or raise Constraint_Error function Get_Filter (From : Site_Builder; Name : S_Expressions.Atom) return Filters.Filter'Class; -- Return a filter from its name, or raise Filters.Stores.No_Filter procedure Insert (Builder : in out Site_Builder; Path : in S_Expressions.Atom; New_Page : in Page'Class); -- Add to Builder a new page with the given web path procedure Insert (Builder : in out Site_Builder; Tags : in Web.Tags.Tag_List; Visible : in Web.Tags.Visible'Class); -- Add to Builder a new Visible with the given tags type Page_Loader is interface; procedure Load (Object : in out Page_Loader; Builder : in out Site_Builder; Path : in S_Expressions.Atom) is abstract; -- Create pages and register them in Builder type Transient_Page_Loader is interface and Page_Loader; function Can_Be_Stored (Object : in Transient_Page_Loader) return Boolean is abstract; -- Return whether the object can be stored in a cache type Page_Constructor is not null access function (File_Name : in S_Expressions.Atom) return Page_Loader'Class; -- Create a page loader associated with the given file name procedure Register (Self : in out Site; Name : in String; Constructor : in Page_Constructor); -- Regeister Constructor for Name in Self. -- WARNING: it is not safe to call this procedure concurrently type Backend_Constructor is not null access function (Arguments : in out S_Expressions.Lockable.Descriptor'Class) return Backends.Backend'Class; procedure Register (Self : in out Site; Name : in String; Constructor : in Backend_Constructor); -- Register Constructor for Name in Self -- WARNING: it is not safe to call this procedure concurrently type ACL_Constructor is not null access function (Arguments : in out S_Expressions.Lockable.Descriptor'Class) return ACL.Backend'Class; procedure Register (Self : in out Site; Name : in String; Constructor : in ACL_Constructor); -- Register Constructor for Name in Self -- WARNING: it is not safe to call this procedure concurrently private type Exchange (Backend : not null access Exchanges.Exchange; Site : not null access constant Sites.Site) is limited record Comment_Info_Initialized : Boolean := False; Comment_Info : Comment_Cookies.Comment_Info; end record; type Expiration_Time (Present : Boolean := False) is record case Present is when True => Time : Ada.Calendar.Time; when False => null; end case; end record; package ACL_Constructors is new Ada.Containers.Indefinite_Ordered_Maps (S_Expressions.Atom, ACL_Constructor, S_Expressions.Less_Than); package Backend_Constructors is new Ada.Containers.Indefinite_Ordered_Maps (S_Expressions.Atom, Backend_Constructor, S_Expressions.Less_Than); package Backend_Maps is new Constant_Indefinite_Ordered_Maps (S_Expressions.Atom, Backends.Backend'Class, S_Expressions.Less_Than, Backends."="); package Page_Loaders is new Constant_Indefinite_Ordered_Maps (S_Expressions.Atom, Page_Loader'Class, S_Expressions.Less_Than); package Page_Constructors is new Ada.Containers.Indefinite_Ordered_Maps (S_Expressions.Atom, Page_Constructor, S_Expressions.Less_Than); type Constructors_In_Site is record ACL : ACL_Constructors.Map; Backend : Backend_Constructors.Map; Codec_DB : Comment_Cookies.Codec_DB; Page : Page_Constructors.Map; end record; type Site is tagged limited record Load_Date : Ada.Calendar.Time; ACL : Web.ACL.Backend_Refs.Reference; Backends : Backend_Maps.Updatable_Map; Constructors : aliased Constructors_In_Site; Default_Template : S_Expressions.Atom_Refs.Immutable_Reference; Expire : Expiration_Time := (Present => False); File_Name : S_Expressions.Atom_Refs.Immutable_Reference; Filters : Web.Filters.Stores.Store; Loaders : Page_Loaders.Constant_Map; Named_Elements : Containers.Expression_Map_Maps.Constant_Map; Pages : Page_Maps.Updatable_Map; Printer_Parameters : S_Expressions.Printers.Pretty.Parameters; Static : Containers.Atom_Array_Refs.Immutable_Reference; Tags : Web.Tags.Tag_DB; Templates : Containers.Expression_Maps.Constant_Map; Updater : access Updaters.Updater'Class := null; end record; type Site_Builder (Constructors : not null access Constructors_In_Site) is limited record ACL : Web.ACL.Backend_Refs.Reference; Backends : Backend_Maps.Unsafe_Maps.Map; Default_Template : S_Expressions.Atom_Refs.Immutable_Reference; Expire : Expiration_Time := (Present => False); File_Prefix : S_Expressions.Atom_Refs.Immutable_Reference; File_Suffix : S_Expressions.Atom_Refs.Immutable_Reference; Filters : Web.Filters.Stores.Store; New_Loaders : Page_Loaders.Unsafe_Maps.Map; Old_Loaders : Page_Loaders.Constant_Map; Path_Prefix : S_Expressions.Atom_Refs.Immutable_Reference; Path_Suffix : S_Expressions.Atom_Refs.Immutable_Reference; Named_Elements : Containers.Expression_Map_Maps.Constant_Map; Pages : Page_Maps.Unsafe_Maps.Map; Printer_Parameters : S_Expressions.Printers.Pretty.Parameters; Static : Containers.Unsafe_Atom_Lists.List; Tags : Web.Tags.Tag_DB_Builder; Templates : Containers.Expression_Maps.Constant_Map; end record; procedure Update (Builder : in out Site_Builder; Expression : in out S_Expressions.Lockable.Descriptor'Class); end Natools.Web.Sites;
with p2; use p2; procedure main with SPARK_Mode is begin -- trying to reprouce the problem StratoX has in hil.ads, but doesn't show up here p2.foo; end main;
-- This file is covered by the Internet Software Consortium (ISC) License -- Reference: ../License.txt package body PortScan.Buildcycle.Ports is --------------------- -- build_package -- --------------------- function build_package (id : builders; sequence_id : port_id; interactive : Boolean := False; interphase : String := "") return Boolean is R : Boolean; break_phase : constant phases := valid_test_phase (interphase); run_selftest : constant Boolean := Unix.env_variable_defined (selftest); begin trackers (id).seq_id := sequence_id; trackers (id).loglines := 0; if uselog then if not initialize_log (id) then finalize_log (id); return False; end if; end if; for phase in phases'Range loop phase_trackers (id) := phase; case phase is when check_sanity | fetch | checksum | extract | patch | pkg_package => R := exec_phase_generic (id, phase); when pkg_depends | fetch_depends | extract_depends | patch_depends | build_depends | lib_depends | run_depends => R := exec_phase_depends (id, phase); when configure => if testing then if lock_localbase then set_localbase_protection (id, True); end if; mark_file_system (id, "preconfig"); end if; R := exec_phase_generic (id, phase); when build => R := exec_phase_build (id); when test => if testing and run_selftest then R := exec_phase_generic (id, phase); end if; when stage => if testing then mark_file_system (id, "prestage"); end if; R := exec_phase_generic (id, phase); when install_mtree | install | check_plist => if testing then R := exec_phase_generic (id, phase); end if; when deinstall => if testing then R := exec_phase_deinstall (id); end if; end case; exit when R = False; exit when interactive and then phase = break_phase; end loop; if uselog then finalize_log (id); end if; if interactive then interact_with_builder (id); end if; return R; end build_package; --------------------------- -- valid_test_phase #1 -- --------------------------- function valid_test_phase (afterphase : String) return phases is begin if afterphase = "extract" then return extract; elsif afterphase = "patch" then return patch; elsif afterphase = "configure" then return configure; elsif afterphase = "build" then return build; elsif afterphase = "stage" then return check_plist; elsif afterphase = "install" then return install; elsif afterphase = "deinstall" then return deinstall; else return check_sanity; end if; end valid_test_phase; ----------------- -- phase2str -- ----------------- function phase2str (phase : phases) return String is begin case phase is when check_sanity => return "check-sanity"; when pkg_depends => return "pkg-depends"; when fetch_depends => return "fetch-depends"; when fetch => return "fetch"; when checksum => return "checksum"; when extract_depends => return "extract-depends"; when extract => return "extract"; when patch_depends => return "patch-depends"; when patch => return "patch"; when build_depends => return "build-depends"; when lib_depends => return "lib-depends"; when configure => return "configure"; when build => return "build"; when run_depends => return "run-depends"; when stage => return "stage"; when test => return "test"; when pkg_package => return "package"; when install_mtree => return "install-mtree"; when install => return "install"; when deinstall => return "deinstall"; when check_plist => return "check-plist"; end case; end phase2str; ------------------------------- -- max_time_without_output -- ------------------------------- function max_time_without_output (phase : phases) return execution_limit is base : Integer; begin case phase is when check_sanity => base := 1; when pkg_depends => base := 3; when fetch_depends => base := 3; when fetch | checksum => return 480; -- 8 hours when extract_depends => base := 3; when extract => base := 20; when patch_depends => base := 3; when patch => base := 3; when build_depends => base := 11; -- for texlive when lib_depends => base := 5; when configure => base := 15; when build => base := 25; -- for gcc linking, tex when run_depends => base := 15; -- octave-forge is driver when stage => base := 20; -- desire 15 but too many rogue builders-in-stage when test => base := 25; when check_plist => base := 10; -- For packages with thousands of files when pkg_package => base := 80; when install_mtree => base := 3; when install => base := 10; when deinstall => base := 10; end case; declare multiplier_x10 : constant Positive := timeout_multiplier_x10; begin return execution_limit (base * multiplier_x10 / 10); end; end max_time_without_output; -------------------------- -- exec_phase_generic -- -------------------------- function exec_phase_generic (id : builders; phase : phases) return Boolean is time_limit : execution_limit := max_time_without_output (phase); begin return exec_phase (id => id, phase => phase, time_limit => time_limit); end exec_phase_generic; -------------------------- -- exec_phase_depends -- -------------------------- function exec_phase_depends (id : builders; phase : phases) return Boolean is time_limit : execution_limit := max_time_without_output (phase); phaseenv : String := "USE_PACKAGE_DEPENDS_ONLY=1"; begin return exec_phase (id => id, phase => phase, phaseenv => phaseenv, time_limit => time_limit, depends_phase => True); end exec_phase_depends; ------------------ -- exec_phase -- ------------------ function exec_phase (id : builders; phase : phases; time_limit : execution_limit; phaseenv : String := ""; depends_phase : Boolean := False; skip_header : Boolean := False; skip_footer : Boolean := False) return Boolean is root : constant String := get_root (id); port_flags : String := " NO_DEPENDS=yes "; pid : port_id := trackers (id).seq_id; catport : constant String := get_catport (all_ports (pid)); result : Boolean; timed_out : Boolean; begin if testing or else depends_phase then port_flags := (others => LAT.Space); end if; -- Nasty, we have to switch open and close the log file for each -- phase because we have to switch between File_Type and File -- Descriptors. I can't find a safe way to get the File Descriptor -- out of the File type. if uselog then if not skip_header then log_phase_begin (phase2str (phase), id); end if; TIO.Close (trackers (id).log_handle); end if; declare command : constant String := chroot & root & environment_override & phaseenv & port_flags & chroot_make_program & " -C " & port_specification (catport) & " " & phase2str (phase); begin result := generic_execute (id, command, timed_out, time_limit); end; -- Reopen the log. I guess we can leave off the exception check -- since it's been passing before if uselog then TIO.Open (File => trackers (id).log_handle, Mode => TIO.Append_File, Name => log_name (trackers (id).seq_id)); if timed_out then TIO.Put_Line (trackers (id).log_handle, "### Watchdog killed runaway process! (no activity for" & time_limit'Img & " minutes) ###"); end if; if not skip_footer then log_phase_end (id); end if; end if; return result; end exec_phase; ------------------------ -- exec_phase_build -- ------------------------ function exec_phase_build (id : builders) return Boolean is time_limit : execution_limit := max_time_without_output (build); passed : Boolean; begin passed := exec_phase (id => id, phase => build, time_limit => time_limit, skip_header => False, skip_footer => True); if testing and then passed then if lock_localbase then set_localbase_protection (id, False); end if; passed := detect_leftovers_and_MIA (id, "preconfig", "between port configure and build"); end if; if uselog then log_phase_end (id); end if; return passed; end exec_phase_build; ---------------------------- -- exec_phase_deinstall -- ---------------------------- function exec_phase_deinstall (id : builders) return Boolean is time_limit : execution_limit := max_time_without_output (deinstall); result : Boolean; begin -- This is only run during "testing" so assume that. if uselog then log_phase_begin (phase2str (deinstall), id); log_linked_libraries (id); end if; result := exec_phase (id => id, phase => deinstall, time_limit => time_limit, skip_header => True, skip_footer => True); if not result then if uselog then log_phase_end (id); end if; return False; end if; if uselog then result := detect_leftovers_and_MIA (id, "prestage", "between staging and package deinstallation"); log_phase_end (id); end if; return result; end exec_phase_deinstall; ---------------------- -- builder_status -- ---------------------- function builder_status (id : builders; shutdown : Boolean := False; idle : Boolean := False) return Display.builder_rec is phasestr : constant String := phase2str (phase_trackers (id)); begin return builder_status_core (id => id, shutdown => shutdown, idle => idle, phasestr => phasestr); end builder_status; ------------------------ -- last_build_phase -- ------------------------ function last_build_phase (id : builders) return String is begin return phase2str (phase => phase_trackers (id)); end last_build_phase; end PortScan.Buildcycle.Ports;
--=========================================================================== -- -- This is the main master program for the Pico for the -- use cases: -- 1: Master Pico -> Slave Pico -- 2: Master Pico -> Slave ItsyBitsy -- --=========================================================================== -- -- Copyright 2022 (C) Holger Rodriguez -- -- SPDX-License-Identifier: BSD-3-Clause -- with HAL; with HAL.SPI; with RP.Clock; with RP.GPIO; with RP.SPI; with RP.Device; with Pico; with SPI_Master_Pico; procedure Main_Master_Pico is Data_Out_16 : HAL.SPI.SPI_Data_16b (1 .. 1); Status_Out : HAL.SPI.SPI_Status; Data_In_16 : HAL.SPI.SPI_Data_16b (1 .. 1) := (others => 0); Status_In : HAL.SPI.SPI_Status; Word : HAL.UInt16; use HAL; use HAL.SPI; use RP.SPI; begin RP.Clock.Initialize (Pico.XOSC_Frequency); RP.Device.Timer.Enable; Pico.LED.Configure (RP.GPIO.Output); SPI_Master_Pico.Initialize; loop -- construct the values for the transmission for Higher_Byte in HAL.UInt8'Range loop for Lower_Byte in HAL.UInt8'Range loop Word := Shift_Left (Value => HAL.UInt16 (Higher_Byte), Amount => 8) or HAL.UInt16 (Lower_Byte); Data_Out_16 (1) := Word; SPI_Master_Pico.SPI.Transmit (Data_Out_16, Status_Out); SPI_Master_Pico.SPI.Receive (Data_In_16, Status_In, 0); RP.Device.Timer.Delay_Milliseconds (100); Pico.LED.Toggle; end loop; end loop; end loop; end Main_Master_Pico;
with Interfaces.C; use Interfaces.C; with Mysql.Mysql; use Mysql.Mysql; package Mysql.Time is pragma Preelaborate; -- Copyright (C) 2004 MySQL AB -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; version 2 of the License. -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- Time declarations shared between the server and client API: -- you should not add anything to this header unless it's used -- (and hence should be visible) in mysql.h. -- If you're looking for a place to add new time-related declaration, -- it's most likely my_time.h. See also "C API Handling of Date -- and Time Values" chapter in documentation. -- subtype enum_mysql_timestamp_type is unsigned; MYSQL_TIMESTAMP_NONE : constant enum_mysql_timestamp_type := -2; MYSQL_TIMESTAMP_ERROR : constant enum_mysql_timestamp_type := -1; MYSQL_TIMESTAMP_DATE : constant enum_mysql_timestamp_type := 0; MYSQL_TIMESTAMP_DATETIME : constant enum_mysql_timestamp_type := 1; MYSQL_TIMESTAMP_TIME : constant enum_mysql_timestamp_type := 2; -- Structure which is used to represent datetime values inside MySQL. -- We assume that values in this structure are normalized, i.e. year <= 9999, -- month <= 12, day <= 31, hour <= 23, hour <= 59, hour <= 59. Many functions -- in server such as my_system_gmt_sec() or make_time() family of functions -- rely on this (actually now usage of make_*() family relies on a bit weaker -- restriction). Also functions that produce MYSQL_TIME as result ensure this. -- There is one exception to this rule though if this structure holds time -- value (time_type == MYSQL_TIMESTAMP_TIME) days and hour member can hold -- bigger values. -- type st_mysql_time is record year : aliased unsigned; month : aliased unsigned; day : aliased unsigned; hour : aliased unsigned; minute : aliased unsigned; second : aliased unsigned; second_part : aliased unsigned_long; neg : aliased my_bool; time_type : aliased enum_mysql_timestamp_type; end record; pragma Convention (C, st_mysql_time); subtype MYSQL_TIME is st_mysql_time; end Mysql.Time;
-- Copyright (c) 2013, Nordic Semiconductor ASA -- 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 Nordic Semiconductor ASA nor the names of its -- contributors may be used to endorse or promote products derived from -- this software without specific prior written permission. -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- This spec has been automatically generated from nrf51.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package NRF51_SVD.SPIS is pragma Preelaborate; --------------- -- Registers -- --------------- -- Shortcut between END event and the ACQUIRE task. type SHORTS_END_ACQUIRE_Field is ( -- Shortcut disabled. Disabled, -- Shortcut enabled. Enabled) with Size => 1; for SHORTS_END_ACQUIRE_Field use (Disabled => 0, Enabled => 1); -- Shortcuts for SPIS. type SHORTS_Register is record -- unspecified Reserved_0_1 : HAL.UInt2 := 16#0#; -- Shortcut between END event and the ACQUIRE task. END_ACQUIRE : SHORTS_END_ACQUIRE_Field := NRF51_SVD.SPIS.Disabled; -- unspecified Reserved_3_31 : HAL.UInt29 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SHORTS_Register use record Reserved_0_1 at 0 range 0 .. 1; END_ACQUIRE at 0 range 2 .. 2; Reserved_3_31 at 0 range 3 .. 31; end record; -- Enable interrupt on END event. type INTENSET_END_Field is ( -- Interrupt disabled. Disabled, -- Interrupt enabled. Enabled) with Size => 1; for INTENSET_END_Field use (Disabled => 0, Enabled => 1); -- Enable interrupt on END event. type INTENSET_END_Field_1 is ( -- Reset value for the field Intenset_End_Field_Reset, -- Enable interrupt on write. Set) with Size => 1; for INTENSET_END_Field_1 use (Intenset_End_Field_Reset => 0, Set => 1); -- Enable interrupt on ACQUIRED event. type INTENSET_ACQUIRED_Field is ( -- Interrupt disabled. Disabled, -- Interrupt enabled. Enabled) with Size => 1; for INTENSET_ACQUIRED_Field use (Disabled => 0, Enabled => 1); -- Enable interrupt on ACQUIRED event. type INTENSET_ACQUIRED_Field_1 is ( -- Reset value for the field Intenset_Acquired_Field_Reset, -- Enable interrupt on write. Set) with Size => 1; for INTENSET_ACQUIRED_Field_1 use (Intenset_Acquired_Field_Reset => 0, Set => 1); -- Interrupt enable set register. type INTENSET_Register is record -- unspecified Reserved_0_0 : HAL.Bit := 16#0#; -- Enable interrupt on END event. END_k : INTENSET_END_Field_1 := Intenset_End_Field_Reset; -- unspecified Reserved_2_9 : HAL.UInt8 := 16#0#; -- Enable interrupt on ACQUIRED event. ACQUIRED : INTENSET_ACQUIRED_Field_1 := Intenset_Acquired_Field_Reset; -- unspecified Reserved_11_31 : HAL.UInt21 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for INTENSET_Register use record Reserved_0_0 at 0 range 0 .. 0; END_k at 0 range 1 .. 1; Reserved_2_9 at 0 range 2 .. 9; ACQUIRED at 0 range 10 .. 10; Reserved_11_31 at 0 range 11 .. 31; end record; -- Disable interrupt on END event. type INTENCLR_END_Field is ( -- Interrupt disabled. Disabled, -- Interrupt enabled. Enabled) with Size => 1; for INTENCLR_END_Field use (Disabled => 0, Enabled => 1); -- Disable interrupt on END event. type INTENCLR_END_Field_1 is ( -- Reset value for the field Intenclr_End_Field_Reset, -- Disable interrupt on write. Clear) with Size => 1; for INTENCLR_END_Field_1 use (Intenclr_End_Field_Reset => 0, Clear => 1); -- Disable interrupt on ACQUIRED event. type INTENCLR_ACQUIRED_Field is ( -- Interrupt disabled. Disabled, -- Interrupt enabled. Enabled) with Size => 1; for INTENCLR_ACQUIRED_Field use (Disabled => 0, Enabled => 1); -- Disable interrupt on ACQUIRED event. type INTENCLR_ACQUIRED_Field_1 is ( -- Reset value for the field Intenclr_Acquired_Field_Reset, -- Disable interrupt on write. Clear) with Size => 1; for INTENCLR_ACQUIRED_Field_1 use (Intenclr_Acquired_Field_Reset => 0, Clear => 1); -- Interrupt enable clear register. type INTENCLR_Register is record -- unspecified Reserved_0_0 : HAL.Bit := 16#0#; -- Disable interrupt on END event. END_k : INTENCLR_END_Field_1 := Intenclr_End_Field_Reset; -- unspecified Reserved_2_9 : HAL.UInt8 := 16#0#; -- Disable interrupt on ACQUIRED event. ACQUIRED : INTENCLR_ACQUIRED_Field_1 := Intenclr_Acquired_Field_Reset; -- unspecified Reserved_11_31 : HAL.UInt21 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for INTENCLR_Register use record Reserved_0_0 at 0 range 0 .. 0; END_k at 0 range 1 .. 1; Reserved_2_9 at 0 range 2 .. 9; ACQUIRED at 0 range 10 .. 10; Reserved_11_31 at 0 range 11 .. 31; end record; -- Semaphore status. type SEMSTAT_SEMSTAT_Field is ( -- Semaphore is free. Free, -- Semaphore is assigned to the CPU. Cpu, -- Semaphore is assigned to the SPIS. Spis, -- Semaphore is assigned to the SPIS, but a handover to the CPU is -- pending. Cpupending) with Size => 2; for SEMSTAT_SEMSTAT_Field use (Free => 0, Cpu => 1, Spis => 2, Cpupending => 3); -- Semaphore status. type SEMSTAT_Register is record -- Read-only. Semaphore status. SEMSTAT : SEMSTAT_SEMSTAT_Field; -- unspecified Reserved_2_31 : HAL.UInt30; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SEMSTAT_Register use record SEMSTAT at 0 range 0 .. 1; Reserved_2_31 at 0 range 2 .. 31; end record; -- TX buffer overread detected, and prevented. type STATUS_OVERREAD_Field is ( -- Error not present. Notpresent, -- Error present. Present) with Size => 1; for STATUS_OVERREAD_Field use (Notpresent => 0, Present => 1); -- TX buffer overread detected, and prevented. type STATUS_OVERREAD_Field_1 is ( -- Reset value for the field Status_Overread_Field_Reset, -- Clear on write. Clear) with Size => 1; for STATUS_OVERREAD_Field_1 use (Status_Overread_Field_Reset => 0, Clear => 1); -- RX buffer overflow detected, and prevented. type STATUS_OVERFLOW_Field is ( -- Error not present. Notpresent, -- Error present. Present) with Size => 1; for STATUS_OVERFLOW_Field use (Notpresent => 0, Present => 1); -- RX buffer overflow detected, and prevented. type STATUS_OVERFLOW_Field_1 is ( -- Reset value for the field Status_Overflow_Field_Reset, -- Clear on write. Clear) with Size => 1; for STATUS_OVERFLOW_Field_1 use (Status_Overflow_Field_Reset => 0, Clear => 1); -- Status from last transaction. type STATUS_Register is record -- TX buffer overread detected, and prevented. OVERREAD : STATUS_OVERREAD_Field_1 := Status_Overread_Field_Reset; -- RX buffer overflow detected, and prevented. OVERFLOW : STATUS_OVERFLOW_Field_1 := Status_Overflow_Field_Reset; -- unspecified Reserved_2_31 : HAL.UInt30 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for STATUS_Register use record OVERREAD at 0 range 0 .. 0; OVERFLOW at 0 range 1 .. 1; Reserved_2_31 at 0 range 2 .. 31; end record; -- Enable or disable SPIS. type ENABLE_ENABLE_Field is ( -- Disabled SPIS. Disabled, -- Enable SPIS. Enabled) with Size => 3; for ENABLE_ENABLE_Field use (Disabled => 0, Enabled => 2); -- Enable SPIS. type ENABLE_Register is record -- Enable or disable SPIS. ENABLE : ENABLE_ENABLE_Field := NRF51_SVD.SPIS.Disabled; -- unspecified Reserved_3_31 : HAL.UInt29 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for ENABLE_Register use record ENABLE at 0 range 0 .. 2; Reserved_3_31 at 0 range 3 .. 31; end record; subtype MAXRX_MAXRX_Field is HAL.UInt8; -- Maximum number of bytes in the receive buffer. type MAXRX_Register is record -- Maximum number of bytes in the receive buffer. MAXRX : MAXRX_MAXRX_Field := 16#0#; -- unspecified Reserved_8_31 : HAL.UInt24 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MAXRX_Register use record MAXRX at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype AMOUNTRX_AMOUNTRX_Field is HAL.UInt8; -- Number of bytes received in last granted transaction. type AMOUNTRX_Register is record -- Read-only. Number of bytes received in last granted transaction. AMOUNTRX : AMOUNTRX_AMOUNTRX_Field; -- unspecified Reserved_8_31 : HAL.UInt24; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for AMOUNTRX_Register use record AMOUNTRX at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype MAXTX_MAXTX_Field is HAL.UInt8; -- Maximum number of bytes in the transmit buffer. type MAXTX_Register is record -- Maximum number of bytes in the transmit buffer. MAXTX : MAXTX_MAXTX_Field := 16#0#; -- unspecified Reserved_8_31 : HAL.UInt24 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for MAXTX_Register use record MAXTX at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype AMOUNTTX_AMOUNTTX_Field is HAL.UInt8; -- Number of bytes transmitted in last granted transaction. type AMOUNTTX_Register is record -- Read-only. Number of bytes transmitted in last granted transaction. AMOUNTTX : AMOUNTTX_AMOUNTTX_Field; -- unspecified Reserved_8_31 : HAL.UInt24; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for AMOUNTTX_Register use record AMOUNTTX at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- Bit order. type CONFIG_ORDER_Field is ( -- Most significant bit transmitted out first. Msbfirst, -- Least significant bit transmitted out first. Lsbfirst) with Size => 1; for CONFIG_ORDER_Field use (Msbfirst => 0, Lsbfirst => 1); -- Serial clock (SCK) phase. type CONFIG_CPHA_Field is ( -- Sample on leading edge of the clock. Shift serial data on trailing -- edge. Leading, -- Sample on trailing edge of the clock. Shift serial data on leading -- edge. Trailing) with Size => 1; for CONFIG_CPHA_Field use (Leading => 0, Trailing => 1); -- Serial clock (SCK) polarity. type CONFIG_CPOL_Field is ( -- Active high. Activehigh, -- Active low. Activelow) with Size => 1; for CONFIG_CPOL_Field use (Activehigh => 0, Activelow => 1); -- Configuration register. type CONFIG_Register is record -- Bit order. ORDER : CONFIG_ORDER_Field := NRF51_SVD.SPIS.Msbfirst; -- Serial clock (SCK) phase. CPHA : CONFIG_CPHA_Field := NRF51_SVD.SPIS.Leading; -- Serial clock (SCK) polarity. CPOL : CONFIG_CPOL_Field := NRF51_SVD.SPIS.Activehigh; -- unspecified Reserved_3_31 : HAL.UInt29 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CONFIG_Register use record ORDER at 0 range 0 .. 0; CPHA at 0 range 1 .. 1; CPOL at 0 range 2 .. 2; Reserved_3_31 at 0 range 3 .. 31; end record; subtype DEF_DEF_Field is HAL.UInt8; -- Default character. type DEF_Register is record -- Default character. DEF : DEF_DEF_Field := 16#0#; -- unspecified Reserved_8_31 : HAL.UInt24 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DEF_Register use record DEF at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; subtype ORC_ORC_Field is HAL.UInt8; -- Over-read character. type ORC_Register is record -- Over-read character. ORC : ORC_ORC_Field := 16#0#; -- unspecified Reserved_8_31 : HAL.UInt24 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for ORC_Register use record ORC at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- Peripheral power control. type POWER_POWER_Field is ( -- Module power disabled. Disabled, -- Module power enabled. Enabled) with Size => 1; for POWER_POWER_Field use (Disabled => 0, Enabled => 1); -- Peripheral power control. type POWER_Register is record -- Peripheral power control. POWER : POWER_POWER_Field := NRF51_SVD.SPIS.Disabled; -- unspecified Reserved_1_31 : HAL.UInt31 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for POWER_Register use record POWER at 0 range 0 .. 0; Reserved_1_31 at 0 range 1 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- SPI slave 1. type SPIS_Peripheral is record -- Acquire SPI semaphore. TASKS_ACQUIRE : aliased HAL.UInt32; -- Release SPI semaphore. TASKS_RELEASE : aliased HAL.UInt32; -- Granted transaction completed. EVENTS_END : aliased HAL.UInt32; -- Semaphore acquired. EVENTS_ACQUIRED : aliased HAL.UInt32; -- Shortcuts for SPIS. SHORTS : aliased SHORTS_Register; -- Interrupt enable set register. INTENSET : aliased INTENSET_Register; -- Interrupt enable clear register. INTENCLR : aliased INTENCLR_Register; -- Semaphore status. SEMSTAT : aliased SEMSTAT_Register; -- Status from last transaction. STATUS : aliased STATUS_Register; -- Enable SPIS. ENABLE : aliased ENABLE_Register; -- Pin select for SCK. PSELSCK : aliased HAL.UInt32; -- Pin select for MISO. PSELMISO : aliased HAL.UInt32; -- Pin select for MOSI. PSELMOSI : aliased HAL.UInt32; -- Pin select for CSN. PSELCSN : aliased HAL.UInt32; -- RX data pointer. RXDPTR : aliased HAL.UInt32; -- Maximum number of bytes in the receive buffer. MAXRX : aliased MAXRX_Register; -- Number of bytes received in last granted transaction. AMOUNTRX : aliased AMOUNTRX_Register; -- TX data pointer. TXDPTR : aliased HAL.UInt32; -- Maximum number of bytes in the transmit buffer. MAXTX : aliased MAXTX_Register; -- Number of bytes transmitted in last granted transaction. AMOUNTTX : aliased AMOUNTTX_Register; -- Configuration register. CONFIG : aliased CONFIG_Register; -- Default character. DEF : aliased DEF_Register; -- Over-read character. ORC : aliased ORC_Register; -- Peripheral power control. POWER : aliased POWER_Register; end record with Volatile; for SPIS_Peripheral use record TASKS_ACQUIRE at 16#24# range 0 .. 31; TASKS_RELEASE at 16#28# range 0 .. 31; EVENTS_END at 16#104# range 0 .. 31; EVENTS_ACQUIRED at 16#128# range 0 .. 31; SHORTS at 16#200# range 0 .. 31; INTENSET at 16#304# range 0 .. 31; INTENCLR at 16#308# range 0 .. 31; SEMSTAT at 16#400# range 0 .. 31; STATUS at 16#440# range 0 .. 31; ENABLE at 16#500# range 0 .. 31; PSELSCK at 16#508# range 0 .. 31; PSELMISO at 16#50C# range 0 .. 31; PSELMOSI at 16#510# range 0 .. 31; PSELCSN at 16#514# range 0 .. 31; RXDPTR at 16#534# range 0 .. 31; MAXRX at 16#538# range 0 .. 31; AMOUNTRX at 16#53C# range 0 .. 31; TXDPTR at 16#544# range 0 .. 31; MAXTX at 16#548# range 0 .. 31; AMOUNTTX at 16#54C# range 0 .. 31; CONFIG at 16#554# range 0 .. 31; DEF at 16#55C# range 0 .. 31; ORC at 16#5C0# range 0 .. 31; POWER at 16#FFC# range 0 .. 31; end record; -- SPI slave 1. SPIS1_Periph : aliased SPIS_Peripheral with Import, Address => System'To_Address (16#40004000#); end NRF51_SVD.SPIS;
package Solar_System.Graphics is protected Graphic_Context is procedure Set_Window(W: Window_ID); entry Get_Window(W: out Window_ID; C : out Canvas_ID); private Window : Window_ID; Canvas : Canvas_ID; Is_Set : Boolean := False; end Graphic_Context; task T_Display; private procedure Draw_Body(Object : Body_Type; Canvas : Canvas_ID); end Solar_System.Graphics;
with Ada.Text_IO; with PrimeUtilities; package body Problem_69 is package IO renames Ada.Text_IO; subtype One_Million is Integer range 1 .. 1_000_000; best : One_Million := 1; package Million_Primes is new PrimeUtilities(One_Million); procedure Solve is prime : One_Million; gen : Million_Primes.Prime_Generator := Million_Primes.Make_Generator(One_Million'Last); begin -- The Euler number can be calculated by multiplying together the percent of the numbers that -- each prime factor of the number will remove. Since we're scaling by the number itself -- getting bigger numbers will not help us, just a larger percent of numbers filtered. Each -- prime factor will filter out 1/p of the numbers in the number line, leaving p-1/p -- remaining. So the smaller the primes we can pick, the larger the percent of numbers we will -- filter out. And since we're picking the smallest primes, we know we could never pick more -- larger primes and end up with a smaller end target (because we could replace the larger -- prime with a smaller prime, get a better ratio). As a result we can just multiply from the -- smallest prime number upwards until we get above our maximum ratio. loop Million_Primes.Next_Prime(gen, prime); exit when prime = 1; exit when One_Million'Last / prime < best; best := best * prime; end loop; IO.Put_Line(Integer'Image(best)); end Solve; end Problem_69;
-- -- Copyright 2021 (C) Jeremy Grosser <jeremy@synack.me> -- -- SPDX-License-Identifier: Apache-2.0 -- package body Notcurses is function "+" (Left, Right : Coordinate) return Coordinate is ((Y => Left.Y + Right.Y, X => Left.X + Right.X)); function "-" (Left, Right : Coordinate) return Coordinate is ((Y => Left.Y - Right.Y, X => Left.X - Right.X)); function Version return String is begin return Interfaces.C.Strings.Value (Thin.notcurses_version); end Version; end Notcurses;
package Opt17 is subtype S is String (1 .. 5); function Func return S; end Opt17;
-- longer_integers.adb with Ada.Text_IO; use Ada.Text_IO; procedure longer_integers is TestLI : Long_Long_Integer := 4; begin Put_Line(" Long_Long_Integer: " & Long_Long_Integer'Image(TestLI)); Put_Line(" Long_Long_Integer min: [ " & Long_Long_Integer'Image(Long_Long_Integer'First) & " ] and max : [ " & Long_Long_Integer'Image(Long_Long_Integer'Last) & " ]"); end longer_integers;
------------------------------------------------------------------------------ -- G E L A A S I S -- -- ASIS implementation for Gela project, a portable Ada compiler -- -- http://gela.ada-ru.org -- -- - - - - - - - - - - - - - - - -- -- Read copyright and license at the end of this file -- ------------------------------------------------------------------------------ -- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $ package body Gela.Embeded_Links.Lists is --------------------- -- Agreed_To_Array -- --------------------- function Agreed_To_Array (Container : List) return Access_Array is Count : Index'Base := 0; Next : aliased Element_Access; begin while Iterate (Container, Next'Access) loop if Agree (Next) then Count := Count + 1; end if; end loop; declare Vector : Access_Array (1 .. Count); begin Count := 0; while Iterate (Container, Next'Access) loop if Agree (Next) then Count := Count + 1; Vector (Count) := Next; end if; end loop; return Vector; end; end Agreed_To_Array; -------------------------------- -- Agreed_To_Array_With_Param -- -------------------------------- function Agreed_To_Array_With_Param (Container : List; Param : Parameter) return Access_Array is Count : Index'Base := 0; Next : aliased Element_Access; begin while Iterate (Container, Next'Access) loop if Agree (Next, Param) then Count := Count + 1; end if; end loop; declare Vector : Access_Array (1 .. Count); begin Count := 0; while Iterate (Container, Next'Access) loop Count := Count + 1; if Agree (Next, Param) then Count := Count + 1; Vector (Count) := Next; end if; end loop; return Vector; end; end Agreed_To_Array_With_Param; ------------ -- Append -- ------------ procedure Append (Container : in out List; New_Item : in Element_Access) is begin pragma Assert (Get_Next (New_Item) = null); Prepend (Container, New_Item); Container.Tail := New_Item; end Append; ----------- -- Clear -- ----------- procedure Clear (Container : in out List) is Next : aliased Element_Access; Prev : Element_Access := Last (Container); begin while Iterate (Container, Next'Access) loop Set_Next (Prev, null); Prev := Next; end loop; Container.Tail := null; end Clear; ------------ -- Delete -- ------------ procedure Delete (Container : in out List; Item : in Element_Access) is Prev : Element_Access := First (Container); Next : aliased Element_Access := Prev; begin pragma Assert (Get_Next (Item) /= null); if Item = Prev then Delete_First (Container, Prev); else while Iterate (Container, Next'Access) loop if Next = Item then Delete_Next (Container, Prev, Next); return; else Prev := Next; end if; end loop; end if; end Delete; ------------------ -- Delete_First -- ------------------ procedure Delete_First (Container : in out List; Removed : out Element_Access) is begin if Is_Empty (Container) then Removed := null; return; end if; Removed := First (Container); if Removed = Last (Container) then Container.Tail := null; else Set_Next (Last (Container), Get_Next (Removed)); end if; Set_Next (Removed, null); end Delete_First; ----------------- -- Delete_Next -- ----------------- procedure Delete_Next (Container : in out List; After : in Element_Access; Removed : out Element_Access) is begin pragma Assert (Get_Next (After) /= null); if After /= Last (Container) then Removed := Get_Next (After); Set_Next (After, Get_Next (Removed)); if Removed = Last (Container) then Container.Tail := After; end if; else Removed := null; end if; end Delete_Next; ----------- -- First -- ----------- function First (Container : List) return Element_Access is begin return Get_Next (Container.Tail); end First; -------------- -- For_Each -- -------------- procedure For_Each (Container : in List) is Next : aliased Element_Access; begin while Iterate (Container, Next'Access) loop Proc (Next); end loop; end For_Each; ------------------------- -- For_Each_With_Param -- ------------------------- procedure For_Each_With_Param (Container : in List; Param : in out Parameter) is Next : aliased Element_Access; begin while Iterate (Container, Next'Access) loop Proc (Next, Param); end loop; end For_Each_With_Param; -------------------- -- Generic_Search -- -------------------- package body Generic_Search is --------- -- "=" -- --------- function "=" (Left, Right : List) return Boolean is Left_Item : aliased Element_Access; Right_Item : aliased Element_Access; begin while Iterate (Left, Left_Item'Access) and then Iterate (Right, Right_Item'Access) loop if Left_Item.all /= Right_Item.all then return False; end if; end loop; return Left_Item = null and then Right_Item = null; end "="; -------------- -- Contains -- -------------- function Contains (Container : List; Item : Element_Type) return Boolean is Next : aliased Element_Access; begin while Iterate (Container, Next'Access) loop if Next.all = Item then return True; end if; end loop; return False; end Contains; ---------- -- Find -- ---------- function Find (Container : List; Item : Element_Type; After : Element_Access := null) return Element_Access is Next : aliased Element_Access := After; begin pragma Assert (After = null or else Get_Next (After) /= null); while Iterate (Container, Next'Access) loop if Next.all = Item then return Next; end if; end loop; return null; end Find; end Generic_Search; ------------------ -- Insert_After -- ------------------ procedure Insert_After (Container : in out List; After : in Element_Access; New_Item : in Element_Access) is begin pragma Assert (Get_Next (After) /= null and Get_Next (New_Item) = null); Set_Next (New_Item, Get_Next (After)); Set_Next (After, New_Item); if Container.Tail = After then Container.Tail := New_Item; end if; end Insert_After; -------------- -- Is_Empty -- -------------- function Is_Empty (Container : List) return Boolean is begin return Container.Tail = null; end Is_Empty; ------------- -- Iterate -- ------------- function Iterate (Container : in List; Next : access Element_Access) return Boolean is begin if Is_Empty (Container) or Next.all = Last (Container) then Next.all := null; return False; elsif Next.all = null then Next.all := First (Container); return True; else Next.all := Get_Next (Next.all); return True; end if; end Iterate; ---------- -- Last -- ---------- function Last (Container : List) return Element_Access is begin return Container.Tail; end Last; ------------ -- Length -- ------------ function Length (Container : List) return Natural is Result : Natural := 0; Next : aliased Element_Access; begin while Iterate (Container, Next'Access) loop Result := Result + 1; end loop; return Result; end Length; ---------- -- Next -- ---------- function Next (Container : List; Item : Element_Access) return Element_Access is begin pragma Assert (Item /= null and Get_Next (Item) /= null); if Item = Last (Container) then return null; else return Get_Next (Item); end if; end Next; ------------- -- Prepend -- ------------- procedure Prepend (Container : in out List; New_Item : in Element_Access) is begin pragma Assert (Get_Next (New_Item) = null); if Is_Empty (Container) then Container.Tail := New_Item; Set_Next (New_Item, New_Item); else Set_Next (New_Item, Get_Next (Container.Tail)); Set_Next (Container.Tail, New_Item); end if; end Prepend; ------------------ -- Splice_After -- ------------------ procedure Splice_After (Target : in out List; Source : in out List; After : in Element_Access := null) is Last : Element_Access; begin if Is_Empty (Source) then return; elsif Is_Empty (Target) then Target.Tail := Source.Tail; else if After = null then Last := After; else Last := Target.Tail; end if; Set_Next (Source.Tail, Get_Next (Last)); Set_Next (Last, Source.Tail); if Last = Target.Tail then Target.Tail := Source.Tail; end if; end if; Source.Tail := null; end Splice_After; -------------- -- To_Array -- -------------- function To_Array (Container : List) return Access_Array is Count : Index'Base := Index'Base (Length (Container)); Next : aliased Element_Access; Vector : Access_Array (1 .. Count); begin Count := 0; while Iterate (Container, Next'Access) loop Count := Count + 1; Vector (Count) := Next; end loop; return Vector; end To_Array; end Gela.Embeded_Links.Lists; ------------------------------------------------------------------------------ -- Copyright (c) 2006, Maxim Reznik -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met: -- -- * Redistributions of source code must retain the above copyright notice, -- this list of conditions and the following disclaimer. -- * Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- * Neither the name of the Maxim Reznik, IE nor the names of its -- contributors may be used to endorse or promote products derived from -- this software without specific prior written permission. -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -- POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------
--=========================================================================== -- -- This program implements a demo program for the SH1107 OLED driver. -- It is implemented on a Raspberry Pico. -- --=========================================================================== -- -- Copyright 2022 (C) Holger Rodriguez -- -- SPDX-License-Identifier: BSD-3-Clause -- -- with HAL; -- with HAL.Framebuffer; with HAL.SPI; with RP.Clock; with RP.Device; with RP.GPIO; with RP.I2C_Master; with RP.SPI; with RP.Timer; with Pico; with SH1107; with Demos; procedure Example_Pico is ORIENTIATION_SELECTED : constant SH1107.SH1107_Orientation := SH1107.Up; Initialize_Timer : aliased RP.Timer.Delays; procedure Initialize_Device is begin RP.Clock.Initialize (Pico.XOSC_Frequency); RP.Clock.Enable (RP.Clock.PERI); RP.Device.Timer.Enable; RP.Device.Timer.Enable; RP.GPIO.Enable; Pico.LED.Configure (RP.GPIO.Output); RP.Timer.Enable (This => Initialize_Timer); end Initialize_Device; --======================================================================== -- -- I2C Section -- --======================================================================== My_I2C : RP.I2C_Master.I2C_Master_Port renames RP.Device.I2C_0; procedure Initialize_I2C_0 is SDA : RP.GPIO.GPIO_Point renames Pico.GP0; SCL : RP.GPIO.GPIO_Point renames Pico.GP1; begin SDA.Configure (RP.GPIO.Output, RP.GPIO.Pull_Up, RP.GPIO.I2C); SCL.Configure (RP.GPIO.Output, RP.GPIO.Pull_Up, RP.GPIO.I2C); My_I2C.Enable (400_000); end Initialize_I2C_0; My_Screen_I2C : SH1107.SH1107_Screen (Connect_With => SH1107.Connect_I2C); --======================================================================== -- -- I2C Section -- --======================================================================== My_SPI : RP.SPI.SPI_Port renames RP.Device.SPI_0; My_DC_SPI : RP.GPIO.GPIO_Point renames Pico.GP13; procedure Initialize_SPI_0 is SCK : RP.GPIO.GPIO_Point renames Pico.GP2; MOSI : RP.GPIO.GPIO_Point renames Pico.GP3; MISO : RP.GPIO.GPIO_Point renames Pico.GP4; CS : RP.GPIO.GPIO_Point renames Pico.GP5; DC : RP.GPIO.GPIO_Point renames My_DC_SPI; CONFIG : constant RP.SPI.SPI_Configuration := (Role => RP.SPI.Master, Baud => 1_000_000, Data_Size => HAL.SPI.Data_Size_8b, Polarity => RP.SPI.Active_Low, Phase => RP.SPI.Rising_Edge, Blocking => True ); begin SCK.Configure (RP.GPIO.Output, RP.GPIO.Pull_Up, RP.GPIO.SPI); MOSI.Configure (RP.GPIO.Output, RP.GPIO.Pull_Up, RP.GPIO.SPI); CS.Configure (RP.GPIO.Output, RP.GPIO.Pull_Up, RP.GPIO.SPI); MISO.Configure (RP.GPIO.Input, RP.GPIO.Pull_Up, RP.GPIO.SPI); DC.Configure (RP.GPIO.Output, RP.GPIO.Pull_Up); My_SPI.Configure (CONFIG); end Initialize_SPI_0; My_Screen_SPI : SH1107.SH1107_Screen (Connect_With => SH1107.Connect_SPI); begin Initialize_Device; -- Show we are alive Pico.LED.Set; if True then Initialize_I2C_0; SH1107.Initialize (This => My_Screen_I2C, Orientation => ORIENTIATION_SELECTED, Port => My_I2C'Access, Address => 16#3C#); if not SH1107.Initialized (This => My_Screen_I2C) then -- STOP here Pico.LED.Clear; loop null; end loop; end if; end if; if True then Initialize_SPI_0; SH1107.Initialize (This => My_Screen_SPI, Orientation => ORIENTIATION_SELECTED, Port => My_SPI'Access, DC_SPI => My_DC_SPI'Access); if not SH1107.Initialized (This => My_Screen_SPI) then -- STOP here Pico.LED.Clear; loop null; end loop; end if; end if; Pico.LED.Set; loop for Orientation_To_Use in SH1107.SH1107_Orientation loop for Demo_To_Show in Demos.Demos_Available'Range loop if True then Demos.Show_1_Demo (S => My_Screen_I2C, O => Orientation_To_Use, Demo => Demo_To_Show); end if; if True then Demos.Show_1_Demo (S => My_Screen_SPI, O => Orientation_To_Use, Demo => Demo_To_Show); end if; end loop; end loop; end loop; end Example_Pico;
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2017 onox <denkpadje@gmail.com> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. with System.Multiprocessors; with Orka.Jobs.Executors; generic with package Executors is new Orka.Jobs.Executors (<>); Queue : Executors.Queues.Queue_Ptr; Task_Name : String; -- Name of a worker task in system's process viewer Count : System.Multiprocessors.CPU; -- Number of workers to spawn package Orka.Jobs.Workers is procedure Shutdown; -- Ask all workers to stop dequeuing jobs and terminate private type Worker; task type Worker_Task (Data : not null access constant Worker); type Worker is limited record ID : Positive; T : Worker_Task (Worker'Access); end record; type Worker_Array is array (Positive range <>) of Worker; function Make_Workers return Worker_Array; end Orka.Jobs.Workers;
pragma License (Unrestricted); -- runtime unit with Ada; with System.Unwind.Representation; package System.Unwind.Raising is pragma Preelaborate; -- equivalent to Raise_With_Location_And_Msg (a-except-2005.adb) procedure Raise_Exception ( E : not null Exception_Data_Access; File : String := ""; Line : Integer := 0; Column : Integer := 0; Message : String := ""); pragma No_Return (Raise_Exception); -- equivalent to Raise_From_Signal_Handler (a-except-2005.adb) procedure Raise_From_Signal_Handler ( E : not null Exception_Data_Access; Message : String; Stack_Guard : Address); pragma No_Return (Raise_From_Signal_Handler); -- implementation for raising (a-except-2005.adb) procedure Raise_E ( E : Exception_Data_Access; Message : String) with Export, Convention => Ada, External_Name => "ada__exceptions__raise_exception"; pragma No_Return (Raise_E); procedure Raise_Exception_From_Here ( E : not null Exception_Data_Access; File : String := Ada.Debug.File; Line : Integer := Ada.Debug.Line) with Export, Convention => Ada, External_Name => "__drake_raise_exception_from_here"; procedure Raise_Exception_From_Here_With ( E : not null Exception_Data_Access; File : String := Ada.Debug.File; Line : Integer := Ada.Debug.Line; Message : String) with Export, Convention => Ada, External_Name => "__drake_raise_exception_from_here_with"; pragma No_Return (Raise_Exception_From_Here); pragma No_Return (Raise_Exception_From_Here_With); -- implementation for reraising (a-except-2005.adb) procedure Reraise (X : Exception_Occurrence) with Export, Convention => Ada, External_Name => "ada__exceptions__reraise_occurrence_always"; pragma No_Return (Reraise); -- implementation for reraising from when all others (a-except-2005.adb) procedure Reraise_From_All_Others (X : Exception_Occurrence) with Export, Convention => Ada, External_Name => "ada__exceptions__reraise_occurrence_no_defer"; pragma No_Return (Reraise_From_All_Others); -- implementation for raising from controlled objects (a-except-2005.adb) procedure Reraise_From_Controlled_Operation (X : Exception_Occurrence) with Export, Convention => Ada, External_Name => "__gnat_raise_from_controlled_operation"; pragma No_Return (Reraise_From_Controlled_Operation); -- equivalent to Reraise_GCC_Exception (a-exexpr-gcc.adb) -- for nested controlled types procedure Reraise_Machine_Occurrence ( Machine_Occurrence : not null Representation.Machine_Occurrence_Access) with Export, Convention => C, External_Name => "__gnat_reraise_zcx"; -- utility for implementing a dummy subprogram procedure Raise_Program_Error with Export, Convention => Ada, External_Name => "__drake_program_error"; -- for runtime checks (a-except-2005.adb) procedure rcheck_00 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_CE_Access_Check"; pragma No_Return (rcheck_00); procedure rcheck_02 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_CE_Discriminant_Check"; pragma No_Return (rcheck_02); procedure rcheck_03 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_CE_Divide_By_Zero"; pragma No_Return (rcheck_03); -- equivalent to rcheck_03 procedure Zero_Division ( File : String := Ada.Debug.File; Line : Integer := Ada.Debug.Line); pragma No_Return (Zero_Division); procedure rcheck_04 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_CE_Explicit_Raise"; pragma No_Return (rcheck_04); procedure rcheck_05 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_CE_Index_Check"; pragma No_Return (rcheck_05); procedure rcheck_06 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_CE_Invalid_Data"; pragma No_Return (rcheck_06); procedure rcheck_07 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_CE_Length_Check"; pragma No_Return (rcheck_07); procedure rcheck_09 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_CE_Null_Not_Allowed"; pragma No_Return (rcheck_09); procedure rcheck_10 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_CE_Overflow_Check"; pragma No_Return (rcheck_10); -- equivalent to rcheck_10 procedure Overflow ( File : String := Ada.Debug.File; Line : Integer := Ada.Debug.Line); pragma No_Return (Overflow); procedure rcheck_12 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_CE_Range_Check"; pragma No_Return (rcheck_12); procedure rcheck_13 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_CE_Tag_Check"; pragma No_Return (rcheck_13); procedure rcheck_14 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_PE_Access_Before_Elaboration"; pragma No_Return (rcheck_14); procedure rcheck_15 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_PE_Accessibility_Check"; pragma No_Return (rcheck_15); procedure rcheck_18 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_PE_All_Guards_Closed"; pragma No_Return (rcheck_18); procedure rcheck_22 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_PE_Explicit_Raise"; pragma No_Return (rcheck_22); procedure rcheck_23 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_PE_Finalize_Raised_Exception"; pragma No_Return (rcheck_23); -- equivalent to rcheck_23 procedure Finalize_Raised_Exception; pragma No_Return (Finalize_Raised_Exception); procedure rcheck_24 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_PE_Implicit_Return"; pragma No_Return (rcheck_24); procedure rcheck_25 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_PE_Misaligned_Address_Value"; pragma No_Return (rcheck_25); procedure rcheck_26 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_PE_Missing_Return"; pragma No_Return (rcheck_26); procedure rcheck_27 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_PE_Overlaid_Controlled_Object"; pragma No_Return (rcheck_27); procedure rcheck_30 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_PE_Unchecked_Union_Restriction"; pragma No_Return (rcheck_30); procedure rcheck_32 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_SE_Empty_Storage_Pool"; pragma No_Return (rcheck_32); procedure rcheck_33 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_SE_Explicit_Raise"; pragma No_Return (rcheck_33); procedure rcheck_35 (File : not null access Character; Line : Integer) with Export, Convention => C, External_Name => "__gnat_rcheck_SE_Object_Too_Large"; pragma No_Return (rcheck_35); procedure Save_Exception ( X : out Exception_Occurrence; E : not null Exception_Data_Access; File : String := ""; Line : Integer := 0; Column : Integer := 0; Message : String := ""); procedure Save_E ( X : out Exception_Occurrence; E : not null Exception_Data_Access; Message : String) with Export, Convention => Ada, External_Name => "__drake_save_exception"; procedure Save_Exception_From_Here ( X : out Exception_Occurrence; E : not null Exception_Data_Access; File : String := Ada.Debug.File; Line : Integer := Ada.Debug.Line) with Export, Convention => Ada, External_Name => "__drake_save_exception_from_here"; procedure Save_Exception_From_Here_With ( X : out Exception_Occurrence; E : not null Exception_Data_Access; File : String := Ada.Debug.File; Line : Integer := Ada.Debug.Line; Message : String) with Export, Convention => Ada, External_Name => "__drake_save_exception_from_here_with"; -- excluding code range function AAA return Address; function ZZZ return Address; -- GDB knows some names for "catch exception" command. -- However, it works incompletely with official gcc (works fine with GNAT -- Community/GPL Edition). -- In drake, only the simple form of "catch exception" is supported. -- (s-excdeb.ads) procedure Debug_Raise_Exception ( E : not null Exception_Data_Access; Message : String) with Export, Convention => Ada, External_Name => "__gnat_debug_raise_exception"; -- procedure __gnat_unhandled_exception (E : Exception_Data_Ptr); -- procedure __gnat_debug_raise_assert_failure; -- procedure __gnat_raise_nodefer_with_msg (E : Exception_Data_Ptr); end System.Unwind.Raising;
package SPARKNaCl.MAC with Pure, SPARK_Mode => On is -- Limited, so no assignment or comparison, and always -- pass-by-reference. type Poly_1305_Key is limited private; function Construct (K : in Bytes_32) return Poly_1305_Key with Global => null; procedure Construct (K : out Poly_1305_Key; X : in Bytes_32) with Global => null; function Serialize (K : in Poly_1305_Key) return Bytes_32 with Global => null; procedure Sanitize (K : out Poly_1305_Key) with Global => null; -------------------------------------------------------- -- One-time authentication -------------------------------------------------------- procedure Onetimeauth (Output : out Bytes_16; M : in Byte_Seq; K : in Poly_1305_Key) with Global => null, Pre => M'First = 0; function Onetimeauth_Verify (H : in Bytes_16; M : in Byte_Seq; K : in Poly_1305_Key) return Boolean with Global => null, Pre => M'First = 0; private -- Note - also limited here in the full view to ensure -- no assignment and pass-by-reference in the body. type Poly_1305_Key is limited record F : Bytes_32; end record; end SPARKNaCl.MAC;
with Cmd_ada; package Test_Procs is procedure Test1 (Params : Cmd_ada.Cb_Parameters.Vector); end Test_Procs;
with System.Multiprocessors.Dispatching_Domains; use System.Multiprocessors.Dispatching_Domains; package Dispatch is My_Domain : Dispatching_Domain := Create(2,2); task My_Task with Dispatching_Domain => My_Domain; end Dispatch;
------------------------------------------------------------------------------ -- -- -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS -- -- -- -- S Y S T E M . S T A C K _ C H E C K I N G -- -- -- -- B o d y -- -- -- -- $Revision$ -- -- -- Copyright (C) 1999-2001 Free Software Foundation, Inc. -- -- -- -- GNARL is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNARL is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNARL; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- GNARL was developed by the GNARL team at Florida State University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Ada.Exceptions; with System.Storage_Elements; use System.Storage_Elements; with System.Parameters; use System.Parameters; with System.Soft_Links; package body System.Stack_Checking is Kilobyte : constant Storage_Offset := 1024; Default_Env_Stack_Size : constant Storage_Offset := 8000 * Kilobyte; -- This size is assumed for the environment stack when no size has been -- set by the runtime, and no GNAT_STACK_LIMIT environment variable was -- present. The value is chosen to be just under 8 MB whic is the actual -- default size on some systems including GNU/LinuxThreads, so we will get -- correct storage errors on those systems without setting environment -- variables. function Set_Stack_Info (Stack : access Stack_Access) return Stack_Access; -- The function Set_Stack_Info is the actual function that updates -- the cache containing a pointer to the Stack_Info. It may also -- be used for detecting asynchronous abort in combination with -- Invalidate_Self_Cache. -- Set_Stack_Info should do the following things in order: -- 1) Get the Stack_Access value for the current task -- 2) Set Stack.all to the value obtained in 1) -- 3) Optionally Poll to check for asynchronous abort -- This order is important because if at any time a write to -- the stack cache is pending, that write should be followed -- by a Poll to prevent loosing signals. -- Note: This function must be compiled with Polling turned off -- Note: on systems like VxWorks and OS/2 with real thread-local storage, -- Set_Stack_Info should return an access value for such local -- storage. In those cases the cache will always be up-to-date. -- The following constants should be imported from some system-specific -- constants package. The constants must be static for performance reasons. ---------------------------- -- Invalidate_Stack_Cache -- ---------------------------- procedure Invalidate_Stack_Cache (Any_Stack : Stack_Access) is begin Cache := Null_Stack; end Invalidate_Stack_Cache; -------------------- -- Set_Stack_Info -- -------------------- function Set_Stack_Info (Stack : access Stack_Access) return Stack_Access is type Frame_Mark is null record; Frame_Location : Frame_Mark; Frame_Address : Address := Frame_Location'Address; My_Stack : Stack_Access; Limit_Chars : System.Address; Limit : Integer; function getenv (S : String) return System.Address; pragma Import (C, getenv, External_Name => "getenv"); function atoi (A : System.Address) return Integer; pragma Import (C, atoi); begin -- The order of steps 1 .. 3 is important, see specification. -- 1) Get the Stack_Access value for the current task My_Stack := Soft_Links.Get_Stack_Info.all; if My_Stack.Base = Null_Address then -- First invocation, initialize based on the assumption that -- there are Environment_Stack_Size bytes available beyond -- the current frame address. if My_Stack.Size = 0 then My_Stack.Size := Default_Env_Stack_Size; -- When the environment variable GNAT_STACK_LIMIT is set, -- set Environment_Stack_Size to that number of kB. Limit_Chars := getenv ("GNAT_STACK_LIMIT" & ASCII.NUL); if Limit_Chars /= Null_Address then Limit := atoi (Limit_Chars); if Limit >= 0 then My_Stack.Size := Storage_Offset (Limit) * Kilobyte; end if; end if; end if; My_Stack.Base := Frame_Address; if Stack_Grows_Down then -- Prevent wrap-around on too big stack sizes My_Stack.Limit := My_Stack.Base - My_Stack.Size; if My_Stack.Limit > My_Stack.Base then My_Stack.Limit := Address'First; end if; else My_Stack.Limit := My_Stack.Base + My_Stack.Size; -- Prevent wrap-around on too big stack sizes if My_Stack.Limit < My_Stack.Base then My_Stack.Limit := Address'Last; end if; end if; end if; -- 2) Set Stack.all to the value obtained in 1) Stack.all := My_Stack; -- 3) Optionally Poll to check for asynchronous abort if Soft_Links.Check_Abort_Status.all /= 0 then raise Standard'Abort_Signal; end if; return My_Stack; -- Never trust the cached value, but return local copy! end Set_Stack_Info; -------------------- -- Set_Stack_Size -- -------------------- -- Specify the stack size for the current frame. procedure Set_Stack_Size (Stack_Size : System.Storage_Elements.Storage_Offset) is My_Stack : Stack_Access; Frame_Address : constant System.Address := My_Stack'Address; begin My_Stack := Stack_Check (Frame_Address); if Stack_Grows_Down then My_Stack.Limit := My_Stack.Base - Stack_Size; else My_Stack.Limit := My_Stack.Base + Stack_Size; end if; end Set_Stack_Size; ----------------- -- Stack_Check -- ----------------- function Stack_Check (Stack_Address : System.Address) return Stack_Access is type Frame_Marker is null record; Marker : Frame_Marker; Cached_Stack : constant Stack_Access := Cache; Frame_Address : constant System.Address := Marker'Address; begin -- This function first does a "cheap" check which is correct -- if it succeeds. In case of failure, the full check is done. -- Ideally the cheap check should be done in an optimized manner, -- or be inlined. if (Stack_Grows_Down and then (Frame_Address <= Cached_Stack.Base and Stack_Address > Cached_Stack.Limit)) or else (not Stack_Grows_Down and then (Frame_Address >= Cached_Stack.Base and Stack_Address < Cached_Stack.Limit)) then -- Cached_Stack is valid as it passed the stack check return Cached_Stack; end if; Full_Check : declare My_Stack : Stack_Access := Set_Stack_Info (Cache'Access); -- At this point Stack.all might already be invalid, so -- it is essential to use our local copy of Stack! begin if (Stack_Grows_Down and then (not (Frame_Address <= My_Stack.Base))) or else (not Stack_Grows_Down and then (not (Frame_Address >= My_Stack.Base))) then -- The returned Base is lower than the stored one, -- so assume that the original one wasn't right and use the -- current Frame_Address as new one. This allows initializing -- Base with the Frame_Address as approximation. -- During initialization the Frame_Address will be close to -- the stack base anyway: the difference should be compensated -- for in the stack reserve. My_Stack.Base := Frame_Address; end if; if (Stack_Grows_Down and then Stack_Address < My_Stack.Limit) or else (not Stack_Grows_Down and then Stack_Address > My_Stack.Limit) then Ada.Exceptions.Raise_Exception (E => Storage_Error'Identity, Message => "stack overflow detected"); end if; return My_Stack; end Full_Check; end Stack_Check; ------------------------ -- Update_Stack_Cache -- ------------------------ procedure Update_Stack_Cache (Stack : Stack_Access) is begin if not Multi_Processor then Cache := Stack; end if; end Update_Stack_Cache; end System.Stack_Checking;
-- { dg-do run } with GNAT.Expect; use GNAT.Expect; with Ada.Text_IO; use Ada.Text_IO; procedure expect1 is Process : Process_Descriptor; begin begin Close (Process); raise Program_Error; exception when Invalid_Process => null; -- expected end; end expect1;