content
stringlengths 23
1.05M
|
|---|
package Bombilla is
procedure Crear (
id: in String;
potencia_nominal: in Float;
luminosidad_nominal: in Float;
es_regulable: in Boolean;
bomb: out Bombilla;
);
function Potencia(B: in Bombilla) return Float;
function Esta_Encendida(B: in Bombilla) return Boolean;
procedure Encender(B: in out Bombilla);
procedure Actualizar_Luminosidades (B: in out Bombilla; vector: in Vectores_Luminosidad.Vector);
function Eficacia(B: in Bombilla) return Float;
private
type Bombilla is record
identificador: String(1..4);
potencia_nominal: Float;
luminosidad_nominal: Float;
esta_encendida: Boolean;
es_regulable: Boolean;
niveles_potencia_arr: Vectores_Luminosidad.Vector;
end record;
end Bombilla;
|
with Interfaces;
use Interfaces;
package body STM32.F4.GPIO.Ports is
package body GPIO_Port_Boolean is
procedure Set(Value: Boolean) is
begin
Register.BSRR := (
BR => 2**Bit,
BS => 2**Bit * Boolean'Pos(Value)
);
end;
function Value return Boolean is
begin
return (Register.IDR and 2**Bit) /= 0;
end;
end GPIO_Port_Boolean;
package body GPIO_Port_Modular is
Size: constant Positive := 1 + Last_Bit - First_Bit;
Mask: constant Unsigned_16 := 2**(Last_Bit + 1) - 2**First_Bit;
procedure Set(Value: Value_Type) is
begin
Register.BSRR := (
BR => Mask,
BS => 2**First_Bit * Unsigned_16(Value)
);
end;
function Value return Value_Type is
begin
return Value_Type((Register.IDR / 2**First_Bit) and (2**Size - 1));
end;
end GPIO_Port_Modular;
end STM32.F4.GPIO.Ports;
|
-----------------------------------------------------------------------
-- Util.beans.factory -- Bean Registration and Factory
-- Copyright (C) 2009, 2010 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;
package body Util.Beans.Factory is
use Util.Log;
-- The logger
Log : constant Loggers.Logger := Loggers.Create ("EL.Beans.Factory");
-- ------------------------------
-- Register under the given name a function to create the bean instance when
-- it is accessed for a first time. The scope defines the scope of the bean.
-- bean
-- ------------------------------
procedure Register (Factory : in out Bean_Factory;
Name : in String;
Definition : in Bean_Definition_Access;
Scope : in Scope_Type := REQUEST_SCOPE) is
B : constant Simple_Binding_Access := new Simple_Binding '(Def => Definition,
Scope => Scope);
begin
Log.Info ("Register bean '{0}' in scope {1}", Name, Scope_Type'Image (Scope));
Register (Factory, Name, B.all'Access);
end Register;
-- ------------------------------
-- Register under the given name a function to create the bean instance when
-- it is accessed for a first time. The scope defines the scope of the bean.
-- bean
-- ------------------------------
procedure Register (Factory : in out Bean_Factory;
Name : in String;
Bind : in Binding_Access) is
begin
Log.Info ("Register bean binding '{0}'", Name);
Factory.Map.Include (Key => To_Unbounded_String (Name),
New_Item => Bind);
end Register;
-- ------------------------------
-- Register all the definitions from a factory to a main factory.
-- ------------------------------
procedure Register (Factory : in out Bean_Factory;
From : in Bean_Factory) is
Pos : Bean_Maps.Cursor := Bean_Maps.First (From.Map);
begin
while Bean_Maps.Has_Element (Pos) loop
Factory.Map.Include (Key => Bean_Maps.Key (Pos),
New_Item => Bean_Maps.Element (Pos));
Bean_Maps.Next (Pos);
end loop;
end Register;
-- ------------------------------
-- Create a bean by using the create operation registered for the name
-- ------------------------------
procedure Create (Factory : in Bean_Factory;
Name : in Unbounded_String;
Result : out Util.Beans.Basic.Readonly_Bean_Access;
Definition : out Bean_Definition_Access;
Scope : out Scope_Type) is
Pos : constant Bean_Maps.Cursor := Factory.Map.Find (Name);
begin
if Bean_Maps.Has_Element (Pos) then
declare
B : constant Binding_Access := Bean_Maps.Element (Pos);
begin
B.Create (Name, Result, Definition, Scope);
end;
end if;
end Create;
procedure Create (Factory : in Simple_Binding;
Name : in Ada.Strings.Unbounded.Unbounded_String;
Result : out Util.Beans.Basic.Readonly_Bean_Access;
Definition : out Bean_Definition_Access;
Scope : out Scope_Type) is
pragma Unreferenced (Name);
begin
Result := Factory.Def.Create;
Definition := Factory.Def;
Scope := Factory.Scope;
end Create;
end Util.Beans.Factory;
|
pragma Ada_2012;
with Protypo.Api.Engine_Values.Constant_Wrappers;
use Protypo.Api.Engine_Values.Constant_Wrappers;
with Protypo.Api.Engine_Values.Handlers;
-- with Protypo.Api.Engine_Values.Iterator_Wrappers;
package body Protypo.Api.Engine_Values.List_Wrappers is
-- package Wrappers is
-- new Protypo.Api.Engine_Values.Iterator_Wrappers
-- (Cursor => Engine_Value_Lists.Cursor,
-- Has_Element => Engine_Value_Lists.Has_Element,
-- Element => Engine_Value_Lists.Element,
-- Iterators => Engine_Value_Lists.List_Iterator_Interfaces);
type Iterator_Type is new Handlers.Iterator_Interface
with
record
First : Engine_Value_Lists.Cursor;
Pos : Engine_Value_Lists.Cursor;
end record;
overriding procedure Reset (Iter : in out Iterator_Type);
overriding procedure Next (Iter : in out Iterator_Type);
overriding function End_Of_Iteration (Iter : Iterator_Type) return Boolean;
overriding function Element (Iter : Iterator_Type) return Handler_Value;
procedure Reset (Iter : in out Iterator_Type)
is
begin
Iter.Pos := Iter.First;
end Reset;
procedure Next (Iter : in out Iterator_Type)
is
begin
Engine_Value_Lists.Next (Iter.Pos);
end Next;
function End_Of_Iteration (Iter : Iterator_Type) return Boolean
is (not Engine_Value_Lists.Has_Element (Iter.Pos));
function Element (Iter : Iterator_Type) return Handler_Value
is (To_Handler_Value (Engine_Value_Lists.Element (Iter.Pos)));
------------
-- Append --
------------
procedure Append
(Item : in out List;
Value : Engine_Value)
is
begin
Item.L.Append (Value);
end Append;
--------------
-- Iterator --
--------------
function Iterator (Item : List) return Handlers.Iterator_Interface_Access
is
use Handlers;
begin
return Iterator_Interface_Access'(new Iterator_Type'(First => Item.L.First,
Pos => Item.L.First));
end Iterator;
----------------
-- Initialize --
----------------
overriding procedure Initialize (Obj : in out List)
is
begin
Obj.L := new Engine_Value_Lists.List;
end Initialize;
end Protypo.Api.Engine_Values.List_Wrappers;
|
--
-- Copyright 2021 (C) Jeremy Grosser <jeremy@synack.me>
--
-- SPDX-License-Identifier: BSD-3-Clause
--
package body Font is
function Get
(Ch : Wide_Wide_Character)
return UInt8_Array
is
begin
for MC of Characters loop
if MC.Code = Wide_Wide_Character'Pos (Ch) then
return MC.Bytes;
end if;
end loop;
return (16#7F#, 16#7F#, 16#7F#, 16#7F#, 16#7F#);
end Get;
end Font;
|
with Ada.Containers.Indefinite_Vectors;
package Tokenize.Token_Vectors is
package String_Vectors is
new Ada.Containers.Indefinite_Vectors (Index_Type => Positive,
Element_Type => String);
subtype Vector is String_Vectors.Vector;
function To_Vector (X : Token_Array) return Vector;
end Tokenize.Token_Vectors;
|
pragma Style_Checks (Off);
-- This spec has been automatically generated from ATSAMD51G19A.svd
pragma Restrictions (No_Elaboration_Code);
with HAL;
with System;
package SAM_SVD.PAC is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype PAC_WRCTRL_PERID_Field is HAL.UInt16;
-- Peripheral access control key
type WRCTRL_KEYSelect is
(-- No action
OFF,
-- Clear protection
CLR,
-- Set protection
SET,
-- Set and lock protection
SETLCK)
with Size => 8;
for WRCTRL_KEYSelect use
(OFF => 0,
CLR => 1,
SET => 2,
SETLCK => 3);
-- Write control
type PAC_WRCTRL_Register is record
-- Peripheral identifier
PERID : PAC_WRCTRL_PERID_Field := 16#0#;
-- Peripheral access control key
KEY : WRCTRL_KEYSelect := SAM_SVD.PAC.OFF;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PAC_WRCTRL_Register use record
PERID at 0 range 0 .. 15;
KEY at 0 range 16 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
-- Event control
type PAC_EVCTRL_Register is record
-- Peripheral acess error event output
ERREO : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for PAC_EVCTRL_Register use record
ERREO at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- Interrupt enable clear
type PAC_INTENCLR_Register is record
-- Peripheral access error interrupt disable
ERR : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for PAC_INTENCLR_Register use record
ERR at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- Interrupt enable set
type PAC_INTENSET_Register is record
-- Peripheral access error interrupt enable
ERR : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for PAC_INTENSET_Register use record
ERR at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- Bridge interrupt flag status
type PAC_INTFLAGAHB_Register is record
-- FLASH
FLASH : Boolean := False;
-- FLASH_ALT
FLASH_ALT : Boolean := False;
-- SEEPROM
SEEPROM : Boolean := False;
-- RAMCM4S
RAMCM4S : Boolean := False;
-- RAMPPPDSU
RAMPPPDSU : Boolean := False;
-- RAMDMAWR
RAMDMAWR : Boolean := False;
-- RAMDMACICM
RAMDMACICM : Boolean := False;
-- HPB0
HPB0 : Boolean := False;
-- HPB1
HPB1 : Boolean := False;
-- HPB2
HPB2 : Boolean := False;
-- HPB3
HPB3 : Boolean := False;
-- PUKCC
PUKCC : Boolean := False;
-- SDHC0
SDHC0 : Boolean := False;
-- unspecified
Reserved_13_13 : HAL.Bit := 16#0#;
-- QSPI
QSPI : Boolean := False;
-- BKUPRAM
BKUPRAM : Boolean := False;
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PAC_INTFLAGAHB_Register use record
FLASH at 0 range 0 .. 0;
FLASH_ALT at 0 range 1 .. 1;
SEEPROM at 0 range 2 .. 2;
RAMCM4S at 0 range 3 .. 3;
RAMPPPDSU at 0 range 4 .. 4;
RAMDMAWR at 0 range 5 .. 5;
RAMDMACICM at 0 range 6 .. 6;
HPB0 at 0 range 7 .. 7;
HPB1 at 0 range 8 .. 8;
HPB2 at 0 range 9 .. 9;
HPB3 at 0 range 10 .. 10;
PUKCC at 0 range 11 .. 11;
SDHC0 at 0 range 12 .. 12;
Reserved_13_13 at 0 range 13 .. 13;
QSPI at 0 range 14 .. 14;
BKUPRAM at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-- Peripheral interrupt flag status - Bridge A
type PAC_INTFLAGA_Register is record
-- PAC
PAC : Boolean := False;
-- PM
PM : Boolean := False;
-- MCLK
MCLK : Boolean := False;
-- RSTC
RSTC : Boolean := False;
-- OSCCTRL
OSCCTRL : Boolean := False;
-- OSC32KCTRL
OSC32KCTRL : Boolean := False;
-- SUPC
SUPC : Boolean := False;
-- GCLK
GCLK : Boolean := False;
-- WDT
WDT : Boolean := False;
-- RTC
RTC : Boolean := False;
-- EIC
EIC : Boolean := False;
-- FREQM
FREQM : Boolean := False;
-- SERCOM0
SERCOM0 : Boolean := False;
-- SERCOM1
SERCOM1 : Boolean := False;
-- TC0
TC0 : Boolean := False;
-- TC1
TC1 : Boolean := False;
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PAC_INTFLAGA_Register use record
PAC at 0 range 0 .. 0;
PM at 0 range 1 .. 1;
MCLK at 0 range 2 .. 2;
RSTC at 0 range 3 .. 3;
OSCCTRL at 0 range 4 .. 4;
OSC32KCTRL at 0 range 5 .. 5;
SUPC at 0 range 6 .. 6;
GCLK at 0 range 7 .. 7;
WDT at 0 range 8 .. 8;
RTC at 0 range 9 .. 9;
EIC at 0 range 10 .. 10;
FREQM at 0 range 11 .. 11;
SERCOM0 at 0 range 12 .. 12;
SERCOM1 at 0 range 13 .. 13;
TC0 at 0 range 14 .. 14;
TC1 at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-- Peripheral interrupt flag status - Bridge B
type PAC_INTFLAGB_Register is record
-- USB
USB : Boolean := False;
-- DSU
DSU : Boolean := False;
-- NVMCTRL
NVMCTRL : Boolean := False;
-- CMCC
CMCC : Boolean := False;
-- PORT
PORT : Boolean := False;
-- DMAC
DMAC : Boolean := False;
-- HMATRIX
HMATRIX : Boolean := False;
-- EVSYS
EVSYS : Boolean := False;
-- unspecified
Reserved_8_8 : HAL.Bit := 16#0#;
-- SERCOM2
SERCOM2 : Boolean := False;
-- SERCOM3
SERCOM3 : Boolean := False;
-- TCC0
TCC0 : Boolean := False;
-- TCC1
TCC1 : Boolean := False;
-- TC2
TC2 : Boolean := False;
-- TC3
TC3 : Boolean := False;
-- unspecified
Reserved_15_15 : HAL.Bit := 16#0#;
-- RAMECC
RAMECC : Boolean := False;
-- unspecified
Reserved_17_31 : HAL.UInt15 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PAC_INTFLAGB_Register use record
USB at 0 range 0 .. 0;
DSU at 0 range 1 .. 1;
NVMCTRL at 0 range 2 .. 2;
CMCC at 0 range 3 .. 3;
PORT at 0 range 4 .. 4;
DMAC at 0 range 5 .. 5;
HMATRIX at 0 range 6 .. 6;
EVSYS at 0 range 7 .. 7;
Reserved_8_8 at 0 range 8 .. 8;
SERCOM2 at 0 range 9 .. 9;
SERCOM3 at 0 range 10 .. 10;
TCC0 at 0 range 11 .. 11;
TCC1 at 0 range 12 .. 12;
TC2 at 0 range 13 .. 13;
TC3 at 0 range 14 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
RAMECC at 0 range 16 .. 16;
Reserved_17_31 at 0 range 17 .. 31;
end record;
-- Peripheral interrupt flag status - Bridge C
type PAC_INTFLAGC_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3 := 16#0#;
-- TCC2
TCC2 : Boolean := False;
-- unspecified
Reserved_4_6 : HAL.UInt3 := 16#0#;
-- PDEC
PDEC : Boolean := False;
-- AC
AC : Boolean := False;
-- AES
AES : Boolean := False;
-- TRNG
TRNG : Boolean := False;
-- ICM
ICM : Boolean := False;
-- PUKCC
PUKCC : Boolean := False;
-- QSPI
QSPI : Boolean := False;
-- CCL
CCL : Boolean := False;
-- unspecified
Reserved_15_31 : HAL.UInt17 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PAC_INTFLAGC_Register use record
Reserved_0_2 at 0 range 0 .. 2;
TCC2 at 0 range 3 .. 3;
Reserved_4_6 at 0 range 4 .. 6;
PDEC at 0 range 7 .. 7;
AC at 0 range 8 .. 8;
AES at 0 range 9 .. 9;
TRNG at 0 range 10 .. 10;
ICM at 0 range 11 .. 11;
PUKCC at 0 range 12 .. 12;
QSPI at 0 range 13 .. 13;
CCL at 0 range 14 .. 14;
Reserved_15_31 at 0 range 15 .. 31;
end record;
-- Peripheral interrupt flag status - Bridge D
type PAC_INTFLAGD_Register is record
-- SERCOM4
SERCOM4 : Boolean := False;
-- SERCOM5
SERCOM5 : Boolean := False;
-- unspecified
Reserved_2_6 : HAL.UInt5 := 16#0#;
-- ADC0
ADC0 : Boolean := False;
-- ADC1
ADC1 : Boolean := False;
-- DAC
DAC : Boolean := False;
-- unspecified
Reserved_10_10 : HAL.Bit := 16#0#;
-- PCC
PCC : Boolean := False;
-- unspecified
Reserved_12_31 : HAL.UInt20 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PAC_INTFLAGD_Register use record
SERCOM4 at 0 range 0 .. 0;
SERCOM5 at 0 range 1 .. 1;
Reserved_2_6 at 0 range 2 .. 6;
ADC0 at 0 range 7 .. 7;
ADC1 at 0 range 8 .. 8;
DAC at 0 range 9 .. 9;
Reserved_10_10 at 0 range 10 .. 10;
PCC at 0 range 11 .. 11;
Reserved_12_31 at 0 range 12 .. 31;
end record;
-- Peripheral write protection status - Bridge A
type PAC_STATUSA_Register is record
-- Read-only. PAC APB Protect Enable
PAC : Boolean;
-- Read-only. PM APB Protect Enable
PM : Boolean;
-- Read-only. MCLK APB Protect Enable
MCLK : Boolean;
-- Read-only. RSTC APB Protect Enable
RSTC : Boolean;
-- Read-only. OSCCTRL APB Protect Enable
OSCCTRL : Boolean;
-- Read-only. OSC32KCTRL APB Protect Enable
OSC32KCTRL : Boolean;
-- Read-only. SUPC APB Protect Enable
SUPC : Boolean;
-- Read-only. GCLK APB Protect Enable
GCLK : Boolean;
-- Read-only. WDT APB Protect Enable
WDT : Boolean;
-- Read-only. RTC APB Protect Enable
RTC : Boolean;
-- Read-only. EIC APB Protect Enable
EIC : Boolean;
-- Read-only. FREQM APB Protect Enable
FREQM : Boolean;
-- Read-only. SERCOM0 APB Protect Enable
SERCOM0 : Boolean;
-- Read-only. SERCOM1 APB Protect Enable
SERCOM1 : Boolean;
-- Read-only. TC0 APB Protect Enable
TC0 : Boolean;
-- Read-only. TC1 APB Protect Enable
TC1 : Boolean;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PAC_STATUSA_Register use record
PAC at 0 range 0 .. 0;
PM at 0 range 1 .. 1;
MCLK at 0 range 2 .. 2;
RSTC at 0 range 3 .. 3;
OSCCTRL at 0 range 4 .. 4;
OSC32KCTRL at 0 range 5 .. 5;
SUPC at 0 range 6 .. 6;
GCLK at 0 range 7 .. 7;
WDT at 0 range 8 .. 8;
RTC at 0 range 9 .. 9;
EIC at 0 range 10 .. 10;
FREQM at 0 range 11 .. 11;
SERCOM0 at 0 range 12 .. 12;
SERCOM1 at 0 range 13 .. 13;
TC0 at 0 range 14 .. 14;
TC1 at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-- Peripheral write protection status - Bridge B
type PAC_STATUSB_Register is record
-- Read-only. USB APB Protect Enable
USB : Boolean;
-- Read-only. DSU APB Protect Enable
DSU : Boolean;
-- Read-only. NVMCTRL APB Protect Enable
NVMCTRL : Boolean;
-- Read-only. CMCC APB Protect Enable
CMCC : Boolean;
-- Read-only. PORT APB Protect Enable
PORT : Boolean;
-- Read-only. DMAC APB Protect Enable
DMAC : Boolean;
-- Read-only. HMATRIX APB Protect Enable
HMATRIX : Boolean;
-- Read-only. EVSYS APB Protect Enable
EVSYS : Boolean;
-- unspecified
Reserved_8_8 : HAL.Bit;
-- Read-only. SERCOM2 APB Protect Enable
SERCOM2 : Boolean;
-- Read-only. SERCOM3 APB Protect Enable
SERCOM3 : Boolean;
-- Read-only. TCC0 APB Protect Enable
TCC0 : Boolean;
-- Read-only. TCC1 APB Protect Enable
TCC1 : Boolean;
-- Read-only. TC2 APB Protect Enable
TC2 : Boolean;
-- Read-only. TC3 APB Protect Enable
TC3 : Boolean;
-- unspecified
Reserved_15_15 : HAL.Bit;
-- Read-only. RAMECC APB Protect Enable
RAMECC : Boolean;
-- unspecified
Reserved_17_31 : HAL.UInt15;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PAC_STATUSB_Register use record
USB at 0 range 0 .. 0;
DSU at 0 range 1 .. 1;
NVMCTRL at 0 range 2 .. 2;
CMCC at 0 range 3 .. 3;
PORT at 0 range 4 .. 4;
DMAC at 0 range 5 .. 5;
HMATRIX at 0 range 6 .. 6;
EVSYS at 0 range 7 .. 7;
Reserved_8_8 at 0 range 8 .. 8;
SERCOM2 at 0 range 9 .. 9;
SERCOM3 at 0 range 10 .. 10;
TCC0 at 0 range 11 .. 11;
TCC1 at 0 range 12 .. 12;
TC2 at 0 range 13 .. 13;
TC3 at 0 range 14 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
RAMECC at 0 range 16 .. 16;
Reserved_17_31 at 0 range 17 .. 31;
end record;
-- Peripheral write protection status - Bridge C
type PAC_STATUSC_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3;
-- Read-only. TCC2 APB Protect Enable
TCC2 : Boolean;
-- unspecified
Reserved_4_6 : HAL.UInt3;
-- Read-only. PDEC APB Protect Enable
PDEC : Boolean;
-- Read-only. AC APB Protect Enable
AC : Boolean;
-- Read-only. AES APB Protect Enable
AES : Boolean;
-- Read-only. TRNG APB Protect Enable
TRNG : Boolean;
-- Read-only. ICM APB Protect Enable
ICM : Boolean;
-- Read-only. PUKCC APB Protect Enable
PUKCC : Boolean;
-- Read-only. QSPI APB Protect Enable
QSPI : Boolean;
-- Read-only. CCL APB Protect Enable
CCL : Boolean;
-- unspecified
Reserved_15_31 : HAL.UInt17;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PAC_STATUSC_Register use record
Reserved_0_2 at 0 range 0 .. 2;
TCC2 at 0 range 3 .. 3;
Reserved_4_6 at 0 range 4 .. 6;
PDEC at 0 range 7 .. 7;
AC at 0 range 8 .. 8;
AES at 0 range 9 .. 9;
TRNG at 0 range 10 .. 10;
ICM at 0 range 11 .. 11;
PUKCC at 0 range 12 .. 12;
QSPI at 0 range 13 .. 13;
CCL at 0 range 14 .. 14;
Reserved_15_31 at 0 range 15 .. 31;
end record;
-- Peripheral write protection status - Bridge D
type PAC_STATUSD_Register is record
-- Read-only. SERCOM4 APB Protect Enable
SERCOM4 : Boolean;
-- Read-only. SERCOM5 APB Protect Enable
SERCOM5 : Boolean;
-- unspecified
Reserved_2_6 : HAL.UInt5;
-- Read-only. ADC0 APB Protect Enable
ADC0 : Boolean;
-- Read-only. ADC1 APB Protect Enable
ADC1 : Boolean;
-- Read-only. DAC APB Protect Enable
DAC : Boolean;
-- unspecified
Reserved_10_10 : HAL.Bit;
-- Read-only. PCC APB Protect Enable
PCC : Boolean;
-- unspecified
Reserved_12_31 : HAL.UInt20;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PAC_STATUSD_Register use record
SERCOM4 at 0 range 0 .. 0;
SERCOM5 at 0 range 1 .. 1;
Reserved_2_6 at 0 range 2 .. 6;
ADC0 at 0 range 7 .. 7;
ADC1 at 0 range 8 .. 8;
DAC at 0 range 9 .. 9;
Reserved_10_10 at 0 range 10 .. 10;
PCC at 0 range 11 .. 11;
Reserved_12_31 at 0 range 12 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Peripheral Access Controller
type PAC_Peripheral is record
-- Write control
WRCTRL : aliased PAC_WRCTRL_Register;
-- Event control
EVCTRL : aliased PAC_EVCTRL_Register;
-- Interrupt enable clear
INTENCLR : aliased PAC_INTENCLR_Register;
-- Interrupt enable set
INTENSET : aliased PAC_INTENSET_Register;
-- Bridge interrupt flag status
INTFLAGAHB : aliased PAC_INTFLAGAHB_Register;
-- Peripheral interrupt flag status - Bridge A
INTFLAGA : aliased PAC_INTFLAGA_Register;
-- Peripheral interrupt flag status - Bridge B
INTFLAGB : aliased PAC_INTFLAGB_Register;
-- Peripheral interrupt flag status - Bridge C
INTFLAGC : aliased PAC_INTFLAGC_Register;
-- Peripheral interrupt flag status - Bridge D
INTFLAGD : aliased PAC_INTFLAGD_Register;
-- Peripheral write protection status - Bridge A
STATUSA : aliased PAC_STATUSA_Register;
-- Peripheral write protection status - Bridge B
STATUSB : aliased PAC_STATUSB_Register;
-- Peripheral write protection status - Bridge C
STATUSC : aliased PAC_STATUSC_Register;
-- Peripheral write protection status - Bridge D
STATUSD : aliased PAC_STATUSD_Register;
end record
with Volatile;
for PAC_Peripheral use record
WRCTRL at 16#0# range 0 .. 31;
EVCTRL at 16#4# range 0 .. 7;
INTENCLR at 16#8# range 0 .. 7;
INTENSET at 16#9# range 0 .. 7;
INTFLAGAHB at 16#10# range 0 .. 31;
INTFLAGA at 16#14# range 0 .. 31;
INTFLAGB at 16#18# range 0 .. 31;
INTFLAGC at 16#1C# range 0 .. 31;
INTFLAGD at 16#20# range 0 .. 31;
STATUSA at 16#34# range 0 .. 31;
STATUSB at 16#38# range 0 .. 31;
STATUSC at 16#3C# range 0 .. 31;
STATUSD at 16#40# range 0 .. 31;
end record;
-- Peripheral Access Controller
PAC_Periph : aliased PAC_Peripheral
with Import, Address => PAC_Base;
end SAM_SVD.PAC;
|
with Ada.Calendar;
package pkgrename is
package AC renames Ada.Calendar;
end pkgrename;
|
-- $Id: Position.md,v 1.2 1994/01/29 22:25:57 grosch rel $
-- $Log: Position.md,v $
-- Ich, Doktor Josef Grosch, Informatiker, Aug. 1994
with Text_Io; use Text_Io;
package Position is
type tPosition is record Line, Column: Integer; end record;
NoPosition : constant tPosition := (0, 0);
-- A default position (0, 0).
function Compare (Position1, Position2: tPosition) return Integer;
-- Returns -1 if Position1 < Position2.
-- Returns 0 if Position1 = Position2.
-- Returns 1 if Position1 > Position2.
procedure WritePosition (File: File_Type; Position: tPosition);
-- The 'Position' is printed on the 'File'.
procedure ReadPosition (File: File_Type; Position: out tPosition);
-- The 'Position' is read from the 'File'.
end Position;
|
-- flyweights-untracked_ptrs.ads
-- A package of generalised references which point to resources inside a
-- Flyweight without tracking or releasing those resources
-- Copyright (c) 2016, James Humphry
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-- PERFORMANCE OF THIS SOFTWARE.
pragma Profile (No_Implementation_Extensions);
with Ada.Containers;
with Flyweights_Hashtables_Spec;
generic
type Element(<>) is limited private;
type Element_Access is access Element;
with package Flyweight_Hashtables is
new Flyweights_Hashtables_Spec(Element_Access => Element_Access,
others => <>);
package Flyweights.Untracked_Ptrs is
type E_Ref(E : access Element) is null record
with Implicit_Dereference => E;
type Untracked_Element_Ptr is tagged private;
function P (P : Untracked_Element_Ptr) return E_Ref
with Inline;
function Get (P : Untracked_Element_Ptr) return Element_Access
with Inline;
function Insert_Ptr (F : aliased in out Flyweight_Hashtables.Flyweight;
E : in out Element_Access) return Untracked_Element_Ptr
with Inline;
type Untracked_Element_Ref (E : not null access Element) is tagged private
with Implicit_Dereference => E;
function Get (P : Untracked_Element_Ref) return Element_Access
with Inline;
function Insert_Ref (F : aliased in out Flyweight_Hashtables.Flyweight;
E : in out Element_Access) return Untracked_Element_Ref
with Inline;
function Make_Ptr (R : Untracked_Element_Ref'Class)
return Untracked_Element_Ptr
with Inline;
function Make_Ref (P : Untracked_Element_Ptr'Class)
return Untracked_Element_Ref
with Inline, Pre => (Get(P) /= null or else
(raise Flyweights_Error with "Cannot make a " &
"Refcounted_Element_Ref from a null Refcounted_Element_Ptr"));
private
type Flyweight_Ptr is access all Flyweight_Hashtables.Flyweight;
type Untracked_Element_Ptr is tagged
record
E : Element_Access := null;
Containing_Flyweight : Flyweight_Ptr := null;
Containing_Bucket : Ada.Containers.Hash_Type;
end record;
type Untracked_Element_Ref (E : access Element) is tagged
record
Containing_Flyweight : Flyweight_Ptr := null;
Containing_Bucket : Ada.Containers.Hash_Type;
end record;
end Flyweights.Untracked_Ptrs;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T V S N --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package spec holds version information for the GNAT tools.
-- It is updated whenever the release number is changed.
package Gnatvsn is
Gnat_Static_Version_String : constant String := "GNU Ada";
-- Static string identifying this version, that can be used as an argument
-- to e.g. pragma Ident.
function Gnat_Version_String return String;
-- Version output when GNAT (compiler), or its related tools, including
-- GNATBIND, GNATCHOP, GNATFIND, GNATLINK, GNATMAKE, GNATXREF, are run
-- (with appropriate verbose option switch set).
type Gnat_Build_Type is (FSF, GPL);
-- See Build_Type below for the meaning of these values.
Build_Type : constant Gnat_Build_Type := FSF;
-- Kind of GNAT build:
--
-- FSF
-- GNAT FSF version. This version of GNAT is part of a Free Software
-- Foundation release of the GNU Compiler Collection (GCC). The bug
-- box generated by Comperr gives information on how to report bugs
-- and list the "no warranty" information.
--
-- GPL
-- GNAT GPL Edition. This is a special version of GNAT, released by
-- Ada Core Technologies and intended for academic users, and free
-- software developers. The bug box generated by the package Comperr
-- gives appropriate bug submission instructions that do not reference
-- customer number etc.
function Gnat_Free_Software return String;
-- Text to be displayed by the different GNAT tools when switch --version
-- is used. This text depends on the GNAT build type.
function Copyright_Holder return String;
-- Return the name of the Copyright holder to be displayed by the different
-- GNAT tools when switch --version is used.
Ver_Len_Max : constant := 256;
-- Longest possible length for Gnat_Version_String in this or any
-- other version of GNAT. This is used by the binder to establish
-- space to store any possible version string value for checks. This
-- value should never be decreased in the future, but it would be
-- OK to increase it if absolutely necessary. If it is increased,
-- be sure to increase GNAT.Compiler.Version.Ver_Len_Max as well.
Ver_Prefix : constant String := "GNAT Version: ";
-- Prefix generated by binder. If it is changed, be sure to change
-- GNAT.Compiler_Version.Ver_Prefix as well.
Library_Version : constant String := "5";
-- Library version. This value must be updated when the compiler
-- version number Gnat_Static_Version_String is updated.
--
-- Note: Makefile.in uses the library version string to construct the
-- soname value.
Verbose_Library_Version : constant String := "GNAT Lib v" & Library_Version;
-- Version string stored in e.g. ALI files
Current_Year : constant String := "2015";
-- Used in printing copyright messages
end Gnatvsn;
|
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr>
-- MIT license. Please refer to the LICENSE file.
with Apsepp.Generic_Shared_Instance;
with Apsepp.Output_Class; use Apsepp.Output_Class;
package Apsepp.Output is
package Shared_Instance is new Generic_Shared_Instance (Output_Interfa);
subtype Output_Access is Shared_Instance.Instance_Type_Access;
function Output return Output_Access renames Shared_Instance.Instance;
end Apsepp.Output;
|
with Ada.Text_IO, Ada.Unchecked_Deallocation;
use Ada.Text_IO;
package body hetro_stack is
procedure Free is new Ada.Unchecked_Deallocation(hetroStackElem, hetroStackElemPtr);
procedure PushFront(Stack: in out hetroStack; Data: ItemPt) is
Pt : hetroStackElemPtr := new hetroStackElem;
begin
Pt.Data := Data;
Pt.RightPtr := Stack.Top.RightPtr;
Pt.LeftPtr := Stack.Top;
Pt.RightPtr.LeftPtr := Pt;
Pt.LeftPtr.RightPtr := Pt;
Stack.Count := Stack.Count + 1;
end PushFront;
procedure SetHeadNode(Stack: in out hetroStack) is
HeadNode : hetroStackElemPtr := new hetroStackElem;
begin
HeadNode.RightPtr := HeadNode;
HeadNode.LeftPtr := HeadNode;
Stack.Top := HeadNode;
end SetHeadNode;
procedure PushRear(Stack: in out hetroStack; Data: ItemPt ) is
Pt: hetroStackElemPtr := new hetroStackElem;
begin
Pt.Data := Data;
Pt.LeftPtr := Stack.Top.LeftPtr;
Pt.RightPtr := Stack.Top;
Pt.LeftPtr.RightPtr := Pt;
Pt.RightPtr.LeftPtr := Pt;
Stack.Count := Stack.Count + 1;
end PushRear;
function StackSize(Stack: hetroStack) return integer is
begin
return Stack.Count;
end StackSize;
procedure PrintList(List: in hetroStack) is
Pt : hetroStackElemPtr;
begin
Pt := List.Top.RightPtr;
while Pt /= List.Top loop
PrintData(Pt.Data.all);
Pt := Pt.RightPtr;
end loop;
end PrintList;
function RemoveSpecificNode(Stack: in out hetroStack; Data: ItemPt) return ItemPt is
Pt: hetroStackElemPtr;
Item : ItemPt;
begin
Pt := Stack.Top.RightPtr;
while Pt /= Stack.Top loop
if Data.all = Pt.Data.all then
Pt.LeftPtr.RightPtr := Pt.RightPtr;
Pt.RightPtr.LeftPtr := Pt.LeftPtr;
Item := Pt.Data;
Free(Pt);
Stack.Count := Stack.Count - 1;
return Item;
end if;
Pt := Pt.RightPtr;
end loop;
return null;
end RemoveSpecificNode;
end hetro_stack;
|
with Ada.Text_IO; use Ada.Text_IO;
-- Item\tQuantity\tPrice\tTaxable[\tTax]
procedure Main is
type Money_Type is delta 0.01 range -1_000_000_000.0 .. 1_000_000_000.0;
for Money_Type'Small use 0.0001;
subtype Tax_Type is Money_Type range 0.0 .. 1.0;
subtype Quantity_Type is Integer range 0..1000;
subtype Buffer_Length is Integer range 1..256;
subtype Input_String is String(Buffer_Length'First..Buffer_Length'Last);
package Fixed_IO is new Ada.Text_IO.Fixed_IO(Money_Type);
package Integer_IO is new Ada.Text_IO.Integer_IO(Integer);
Sub_Total : Money_Type := 0.0;
Total : Money_Type;
Taxable_Total : Money_Type := 0.0;
begin
Set_Line_Length(To => Count'Val(Buffer_Length'Last));
loop
declare
Item_Name : Input_String;
Item_Name_Length : Buffer_Length;
Item_Quantity : Quantity_Type;
Item_Price : Money_Type;
Item_Taxable_Input : Character;
--Item_Taxable_Length : Buffer_Length;
Item_Taxable : Boolean;
--Item_Tax : Tax_Type;
begin
Put("Item name: ");
Get_Line(Item_Name, Item_Name_Length);
if Item_Name_Length = Buffer_Length'Last then
Put_Line("Item name is too long. Limit is " & Integer'Image(Buffer_Length'Last-1) & " characters.");
raise Data_Error;
end if;
Put_Line("Item name set to " & Item_Name(Input_String'First..Item_Name_Length));
Put_Line("");
Put("Item quantity: ");
Integer_IO.Get(Item_Quantity);
Put_Line("Item quantity set to " & Integer'Image(Item_Quantity));
Put_Line("");
Skip_Line;
Put("Item price: ");
Fixed_IO.Get(Item_Price);
Put_Line("Item price set to " & Money_Type'Image(Item_Price));
Put_Line("");
Skip_Line;
Put("Item taxable (y/n): ");
Get(Item_Taxable_Input);
Item_Taxable := Item_Taxable_Input = 'y';
Put_Line("Item taxability set to " & Boolean'Image(Item_Taxable));
Put_Line("");
Skip_Line;
if Item_Taxable then
Taxable_Total := Taxable_Total + Item_Price;
end if;
Sub_Total := Sub_Total + Item_Price;
exception
-- EOF is End_Error.
when End_Error => exit;
-- If invalid input, we'll retry.
when Data_Error =>
Put_Line("");
Put_Line("***ERROR: Please try again.");
Skip_Line;
end;
end loop;
Put_Line("Transaction:");
Total := Taxable_Total*0.07125 + Sub_Total;
Put_Line("Subtotal: " & Money_Type'Image(Sub_Total));
Put_Line("Taxable total: " & Money_Type'Image(Taxable_Total));
Put_Line("Total: " & Money_Type'Image(Total));
end Main;
|
with SDL;
with SDL.Error;
with SDL.Log;
with System;
use type System.Bit_Order;
procedure Error is
begin
SDL.Log.Set (Category => SDL.Log.Application, Priority => SDL.Log.Debug);
SDL.Error.Set ("No worries");
SDL.Log.Put_Debug ("Error string : " & SDL.Error.Get);
SDL.Finalise;
end Error;
|
with Ada.Calendar.Formatting;
with Ada.Characters.Latin_1;
with Ada.Command_Line;
with Ada.IO_Exceptions;
with Ada.Text_IO;
procedure Notes is
Notes_Filename : constant String := "notes.txt";
Notes_File : Ada.Text_IO.File_Type;
Argument_Count : Natural := Ada.Command_Line.Argument_Count;
begin
if Argument_Count = 0 then
begin
Ada.Text_IO.Open
(File => Notes_File,
Mode => Ada.Text_IO.In_File,
Name => Notes_Filename);
while not Ada.Text_IO.End_Of_File (File => Notes_File) loop
Ada.Text_IO.Put_Line (Ada.Text_IO.Get_Line (File => Notes_File));
end loop;
exception
when Ada.IO_Exceptions.Name_Error =>
null;
end;
else
begin
Ada.Text_IO.Open
(File => Notes_File,
Mode => Ada.Text_IO.Append_File,
Name => Notes_Filename);
exception
when Ada.IO_Exceptions.Name_Error =>
Ada.Text_IO.Create (File => Notes_File, Name => Notes_Filename);
end;
Ada.Text_IO.Put_Line
(File => Notes_File,
Item => Ada.Calendar.Formatting.Image (Date => Ada.Calendar.Clock));
Ada.Text_IO.Put (File => Notes_File, Item => Ada.Characters.Latin_1.HT);
for I in 1 .. Argument_Count loop
Ada.Text_IO.Put
(File => Notes_File,
Item => Ada.Command_Line.Argument (I));
if I /= Argument_Count then
Ada.Text_IO.Put (File => Notes_File, Item => ' ');
end if;
end loop;
Ada.Text_IO.Flush (File => Notes_File);
end if;
if Ada.Text_IO.Is_Open (File => Notes_File) then
Ada.Text_IO.Close (File => Notes_File);
end if;
end Notes;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- Copyright (C) 2012-2019, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
pragma Ada_2012; -- To work around pre-commit check?
pragma Suppress (All_Checks);
-- This initialization procedure mainly initializes the PLLs and
-- all derived clocks.
with Ada.Unchecked_Conversion;
with Interfaces.STM32; use Interfaces, Interfaces.STM32;
with Interfaces.STM32.Flash; use Interfaces.STM32.Flash;
with Interfaces.STM32.RCC; use Interfaces.STM32.RCC;
with Interfaces.STM32.PWR; use Interfaces.STM32.PWR;
with System.BB.Parameters; use System.BB.Parameters;
with System.STM32; use System.STM32;
procedure Setup_Pll is
procedure Initialize_Clocks;
procedure Reset_Clocks;
------------------------------
-- Clock Tree Configuration --
------------------------------
HSE_Enabled : constant Boolean := True; -- use high-speed external clock
HSE_Bypass : constant Boolean := True; -- bypass osc. with external clock
HSI_Enabled : constant Boolean := False; -- use high-speed internal clock
CSI_Enabled : constant Boolean :=
(if not HSE_Enabled and not HSI_Enabled then True);
-- Use low-power internal clock when HSE and HSI are disabled.
LSE_Enabled : constant Boolean := False; -- use low-speed external clock
LSI_Enabled : constant Boolean := False; -- use low-speed internal clock
HSI48_Enabled : constant Boolean := False; -- use high-speed internal clock
Activate_PLL1 : constant Boolean := True;
Activate_PLL2 : constant Boolean := True;
Activate_PLL3 : constant Boolean := True;
-----------------------
-- Initialize_Clocks --
-----------------------
procedure Initialize_Clocks
is
-------------------------------
-- Compute Clock Frequencies --
-------------------------------
PLL1P_Value : constant := 2;
PLL1Q_Value : constant := 4; -- 200 MHz
PLL1R_Value : constant := 8; -- 100 MHz
PLL2M_Value : constant := 2; -- 4 MHz with HSE
PLL2N_Value : constant := 240; -- 960 MHz
PLL2P_Value : constant := 4; -- 240 MHz for ADCs
PLL2Q_Value : constant := 20; -- 48 MHz
PLL2R_Value : constant := 8; -- 120 MHz
PLL2M : constant UInt6 := UInt6 (PLL2M_Value);
PLL2N : constant UInt9 := UInt9 (PLL2N_Value - 1);
PLL2P : constant UInt7 := UInt7 (PLL2P_Value - 1);
PLL2Q : constant UInt7 := UInt7 (PLL2Q_Value - 1);
PLL2R : constant UInt7 := UInt7 (PLL2R_Value - 1);
PLL3M_Value : constant := 2; -- 4 MHz with HSE
PLL3N_Value : constant := 240; -- 960 MHz
PLL3P_Value : constant := 4; -- 240 MHz
PLL3Q_Value : constant := 20; -- 48 MHz for USB
PLL3R_Value : constant := 8; -- 120 MHz
PLL3M : constant UInt6 := UInt6 (PLL3M_Value);
PLL3N : constant UInt9 := UInt9 (PLL3N_Value - 1);
PLL3P : constant UInt7 := UInt7 (PLL3P_Value - 1);
PLL3Q : constant UInt7 := UInt7 (PLL3Q_Value - 1);
PLL3R : constant UInt7 := UInt7 (PLL3R_Value - 1);
PLLCLKIN : constant Integer := 4_000_000;
-- PLL input clock value
PLL1M_Value : constant Integer := (if HSE_Enabled then HSE_Clock
elsif HSI_Enabled then HSI_Clock else CSI_Clock) / PLLCLKIN;
-- First divider DIVM1 is set to produce a 4Mhz clock to be compatible
-- with the 4 MHz CSI RC clock.
PLL1N_Value : constant Integer :=
(PLL1P_Value * Clock_Frequency) / PLLCLKIN;
-- Compute DIVN1 to generate the required PLLCLK frequency
pragma Compile_Time_Error
(Activate_PLL1 and PLL1M_Value not in PLLM_Range,
"Invalid PLL1M clock configuration value");
pragma Compile_Time_Error
(Activate_PLL1 and PLL1N_Value not in PLLN_Range,
"Invalid PLL1N clock configuration value");
pragma Compile_Time_Error
(Activate_PLL1 and PLL1R_Value not in PLLR_Range,
"Invalid PLL1R clock configuration value");
pragma Compile_Time_Error
(Activate_PLL1 and
(PLL1P_Value rem 2 /= 0 or PLL1P_Value not in PLL1P_Range),
"Invalid PLL1P clock configuration value");
pragma Compile_Time_Error
(Activate_PLL1 and PLL1Q_Value not in PLLQ_Range,
"Invalid PLL1Q clock configuration value");
PLLVCO : constant Integer := PLLCLKIN * PLL1N_Value; -- PLL1N_OUT
pragma Compile_Time_Error
(Activate_PLL1 and PLLVCO not in PLLN_OUT_Range,
"Invalid PLL1N clock configuration output value");
PLLCLKOUT : constant Integer := PLLVCO / PLL1P_Value; -- PLLCLK
pragma Compile_Time_Error
(Activate_PLL1 and PLLCLKOUT not in PLLCLK_Range,
"Invalid PLL1R clock configuration output value");
PLL1M : constant UInt6 := UInt6 (PLL1M_Value);
PLL1N : constant UInt9 := UInt9 (PLL1N_Value - 1);
PLL1P : constant UInt7 := UInt7 (PLL1P_Value - 1);
PLL1Q : constant UInt7 := UInt7 (PLL1Q_Value - 1);
PLL1R : constant UInt7 := UInt7 (PLL1R_Value - 1);
SW : constant SYSCLK_Source := (if Activate_PLL1 then SYSCLK_SRC_PLL
elsif HSE_Enabled then SYSCLK_SRC_HSE
elsif HSI_Enabled then SYSCLK_SRC_HSI
else SYSCLK_SRC_CSI);
SYSCLK : constant Integer := (if Activate_PLL1 then PLLCLKOUT
elsif HSE_Enabled then HSE_Clock
elsif HSI_Enabled then HSI_Clock
else CSI_Clock);
HCLK1 : constant Integer :=
(if not AHB1_PRE.Enabled then SYSCLK
else
(case AHB1_PRE.Value is
when DIV2 => SYSCLK / 2,
when DIV4 => SYSCLK / 4,
when DIV8 => SYSCLK / 8,
when DIV16 => SYSCLK / 16,
when DIV64 => SYSCLK / 64,
when DIV128 => SYSCLK / 128,
when DIV256 => SYSCLK / 256,
when DIV512 => SYSCLK / 512));
HCLK2 : constant Integer :=
(if not AHB2_PRE.Enabled then HCLK1
else
(case AHB2_PRE.Value is
when DIV2 => HCLK1 / 2,
when DIV4 => HCLK1 / 4,
when DIV8 => HCLK1 / 8,
when DIV16 => HCLK1 / 16,
when DIV64 => HCLK1 / 64,
when DIV128 => HCLK1 / 128,
when DIV256 => HCLK1 / 256,
when DIV512 => HCLK1 / 512));
PCLK1 : constant Integer :=
(if not APB1_PRE.Enabled then HCLK2
else
(case APB1_PRE.Value is
when DIV2 => HCLK2 / 2,
when DIV4 => HCLK2 / 4,
when DIV8 => HCLK2 / 8,
when DIV16 => HCLK2 / 16));
PCLK2 : constant Integer :=
(if not APB2_PRE.Enabled then HCLK2
else
(case APB2_PRE.Value is
when DIV2 => HCLK2 / 2,
when DIV4 => HCLK2 / 4,
when DIV8 => HCLK2 / 8,
when DIV16 => HCLK2 / 16));
PCLK3 : constant Integer :=
(if not APB3_PRE.Enabled then HCLK2
else
(case APB3_PRE.Value is
when DIV2 => HCLK2 / 2,
when DIV4 => HCLK2 / 4,
when DIV8 => HCLK2 / 8,
when DIV16 => HCLK2 / 16));
PCLK4 : constant Integer :=
(if not APB4_PRE.Enabled then HCLK2
else
(case APB4_PRE.Value is
when DIV2 => HCLK2 / 2,
when DIV4 => HCLK2 / 4,
when DIV8 => HCLK2 / 8,
when DIV16 => HCLK2 / 16));
function To_AHB is new Ada.Unchecked_Conversion
(AHB_Prescaler, UInt4);
function To_APB is new Ada.Unchecked_Conversion
(APB_Prescaler, UInt3);
begin
pragma Compile_Time_Error
(SYSCLK /= Clock_Frequency, "Cannot generate requested clock");
-- Cannot be checked at compile time, depends on APB1_PRE to APB4_PRE
pragma Assert
(HCLK1 not in HCLK1_Range
or else HCLK2 not in HCLK2_Range
or else PCLK1 not in PCLK1_Range
or else PCLK2 not in PCLK2_Range
or else PCLK3 not in PCLK3_Range
or else PCLK4 not in PCLK4_Range,
"Invalid AHB/APB prescalers configuration");
-- PWR initialization
-- System.BB.MCU_Parameters.PWR_Initialize;
if HSE_Enabled then
-- Configure high-speed external clock, if enabled
RCC_Periph.CR.HSEBYP := (if HSE_Bypass then 1 else 0);
-- Enable security for HSERDY
RCC_Periph.CR.HSECSSON := 1;
-- Setup high-speed external clock
RCC_Periph.CR.HSEON := 1;
-- Wait for HSE stabilisation.
loop
exit when RCC_Periph.CR.HSERDY = 1;
end loop;
else
if HSI_Enabled then
-- Setup high-speed internal clock and wait for stabilisation.
RCC_Periph.CR.HSION := 1;
loop
exit when RCC_Periph.CR.HSIRDY = 1;
end loop;
elsif CSI_Enabled then
-- Setup low-power internal clock and wait for stabilization.
RCC_Periph.CR.CSION := 1;
loop
exit when RCC_Periph.CR.CSIRDY = 1;
end loop;
end if;
end if;
if LSE_Enabled then
-- Setup low-speed external clock and wait for stabilization.
RCC_Periph.BDCR.LSEON := 1;
loop
exit when RCC_Periph.BDCR.LSERDY = 1;
end loop;
end if;
if LSI_Enabled then
-- Setup low-speed internal clock and wait for stabilization.
RCC_Periph.CSR.LSION := 1;
loop
exit when RCC_Periph.CSR.LSIRDY = 1;
end loop;
end if;
if HSI48_Enabled then
-- Setup high-speed internal clock and wait for stabilization.
RCC_Periph.CR.HSI48ON := 1;
loop
exit when RCC_Periph.CR.HSI48RDY = 1;
end loop;
end if;
-- Activate PLL1 if enabled
if Activate_PLL1 then
-- Disable the main PLL before configuring it
RCC_Periph.CR.PLL1ON := 0;
-- Configure the PLL clock source, multiplication and division
-- factors
RCC_Periph.PLLCKSELR :=
(PLLSRC => (if HSE_Enabled then PLL_SRC_HSE'Enum_Rep
elsif HSI_Enabled then PLL_SRC_HSI'Enum_Rep
else PLL_SRC_CSI'Enum_Rep),
DIVM1 => PLL1M,
others => <>);
RCC_Periph.PLLCFGR :=
(PLL1VCOSEL => 0, -- PLL wide VCO range from 192 to 836 MHz
PLL1RGE => 2, -- PLL input clock range between 4 and 8 MHz
PLL1FRACEN => 0, -- Disable fractional mode
DIVP1EN => 1, -- Enable PLL DIVP output (default)
DIVQ1EN => 1, -- Enable PLL DIVQ output (default)
DIVR1EN => 1, -- Enable PLL DIVR output (default)
others => <>);
RCC_Periph.PLL1DIVR :=
(DIVN1 => PLL1N,
DIVP1 => PLL1P,
DIVQ1 => PLL1Q,
DIVR1 => PLL1R,
others => <>);
-- Setup PLL and wait for stabilization.
RCC_Periph.CR.PLL1ON := 1;
loop
exit when RCC_Periph.CR.PLL1RDY = 1;
end loop;
-- Set VCORE to VOS1
PWR_Periph.D3CR.VOS := Scale_1'Enum_Rep;
end if;
-- Activate PLL2 if enabled
if Activate_PLL2 then
-- Disable the main PLL before configuring it
RCC_Periph.CR.PLL2ON := 0;
-- Configure the PLL clock source, multiplication and division
-- factors
RCC_Periph.PLLCKSELR.DIVM2 := PLL2M;
RCC_Periph.PLLCFGR :=
(PLL2VCOSEL => 0, -- PLL wide VCO range from 192 to 836 MHz
PLL2RGE => 2, -- PLL input clock range between 4 and 8 MHz
PLL2FRACEN => 0, -- Disable fractional mode
DIVP2EN => 1, -- Enable PLL DIVP output (default)
DIVQ2EN => 1, -- Enable PLL DIVQ output (default)
DIVR2EN => 1, -- Enable PLL DIVR output (default)
others => <>);
RCC_Periph.PLL2DIVR :=
(DIVN2 => PLL2N,
DIVP2 => PLL2P,
DIVQ2 => PLL2Q,
DIVR2 => PLL2R,
others => <>);
-- Setup PLL and wait for stabilization.
RCC_Periph.CR.PLL2ON := 1;
loop
exit when RCC_Periph.CR.PLL2RDY = 1;
end loop;
end if;
-- Activate PLL3 if enabled
if Activate_PLL3 then
-- Disable the main PLL before configuring it
RCC_Periph.CR.PLL3ON := 0;
-- Configure the PLL clock source, multiplication and division
-- factors
RCC_Periph.PLLCKSELR.DIVM3 := PLL3M;
RCC_Periph.PLLCFGR :=
(PLL3VCOSEL => 0, -- PLL wide VCO range from 192 to 836 MHz
PLL3RGE => 2, -- PLL input clock range between 4 and 8 MHz
PLL3FRACEN => 0, -- Disable fractional mode
DIVP3EN => 1, -- Enable PLL DIVP output (default)
DIVQ3EN => 1, -- Enable PLL DIVQ output (default)
DIVR3EN => 1, -- Enable PLL DIVR output (default)
others => <>);
RCC_Periph.PLL3DIVR :=
(DIVN3 => PLL3N,
DIVP3 => PLL3P,
DIVQ3 => PLL3Q,
DIVR3 => PLL3R,
others => <>);
-- Setup PLL and wait for stabilization.
RCC_Periph.CR.PLL3ON := 1;
loop
exit when RCC_Periph.CR.PLL3RDY = 1;
end loop;
end if;
-- Flash configuration must be done before increasing the frequency,
-- otherwise the CPU won't be able to fetch new instructions.
-- Constants for Flash read latency with VCORE Range in relation to
-- AXI Interface clock frequency (MHz) (AXI clock is HCLK2):
-- RM0433 STM32H743 pg. 159 table 17 chapter 4.3.8.
if HCLK2 in FLASH_Latency_0 then
FLASH_Latency := FWS0'Enum_Rep;
elsif HCLK2 in FLASH_Latency_1 then
FLASH_Latency := FWS1'Enum_Rep;
elsif HCLK2 in FLASH_Latency_2 then
FLASH_Latency := FWS2'Enum_Rep;
elsif HCLK2 in FLASH_Latency_3 then
FLASH_Latency := FWS3'Enum_Rep;
elsif HCLK2 in FLASH_Latency_4 then
FLASH_Latency := FWS4'Enum_Rep;
end if;
Flash_Periph.ACR.LATENCY := FLASH_Latency;
-- Configure PER_CK clock
RCC_Periph.D1CCIPR.CKPERSEL :=
(if HSE_Enabled then PER_SRC_HSE'Enum_Rep
elsif HSI_Enabled then PER_SRC_HSI'Enum_Rep
else PER_SRC_CSI'Enum_Rep);
-- Configure domain 1 clocks
RCC_Periph.D1CFGR :=
(HPRE => To_AHB (AHB2_PRE), -- AHB2 peripheral clock
D1CPRE => To_AHB (AHB1_PRE), -- AHB1 CPU clock
D1PPRE => To_APB (APB3_PRE), -- APB3 peripheral clock
others => <>);
-- Configure domain 2 clocks
RCC_Periph.D2CFGR :=
(D2PPRE1 => To_APB (APB1_PRE), -- APB1 peripheral clock
D2PPRE2 => To_APB (APB2_PRE), -- APB2 peripheral clock
others => <>);
-- Configure domain 3 clocks
RCC_Periph.D3CFGR :=
(D3PPRE => To_APB (APB4_PRE), -- APB4 peripheral clock
others => <>);
-- Configure SYSCLK source clock
RCC_Periph.CFGR.SW := SW'Enum_Rep;
-- Test system clock switch status
case SW is
when SYSCLK_SRC_PLL =>
loop
exit when RCC_Periph.CFGR.SWS = SYSCLK_SRC_PLL'Enum_Rep;
end loop;
when SYSCLK_SRC_HSE =>
loop
exit when RCC_Periph.CFGR.SWS = SYSCLK_SRC_HSE'Enum_Rep;
end loop;
when SYSCLK_SRC_HSI =>
loop
exit when RCC_Periph.CFGR.SWS = SYSCLK_SRC_HSI'Enum_Rep;
end loop;
when SYSCLK_SRC_CSI =>
loop
exit when RCC_Periph.CFGR.SWS = SYSCLK_SRC_CSI'Enum_Rep;
end loop;
end case;
-- Change VOR to level 0 (VOR0) = 480 MHz
-- if Activate_PLL1 then System.BB.MCU_Parameters.PWR_Overdrive_Enable;
end Initialize_Clocks;
------------------
-- Reset_Clocks --
------------------
procedure Reset_Clocks is
begin
-- Switch on high speed internal clock
RCC_Periph.CR.HSION := 1;
-- Reset CFGR regiser
RCC_Periph.CFGR := (others => <>);
-- Reset HSEON, CSSON and PLLON bits
RCC_Periph.CR.HSEON := 0;
RCC_Periph.CR.HSECSSON := 0;
RCC_Periph.CR.PLL1ON := 0;
-- Reset PLL configuration register
RCC_Periph.PLLCFGR := (others => <>);
-- Reset HSE bypass bit
RCC_Periph.CR.HSEBYP := 0;
-- Disable all interrupts
RCC_Periph.CIER := (others => <>);
end Reset_Clocks;
begin
Reset_Clocks;
Initialize_Clocks;
end Setup_Pll;
|
pragma Ada_2012;
with Ada.Streams; use Ada.Streams;
with Fastpbkdf2_Generic;
package Fastpbkdf2_Ada is new Fastpbkdf2_Generic
(Stream_Element, Stream_Element_Offset, Stream_Element_Array);
|
-- Abstract :
--
-- see spec
--
-- Copyright (C) 2014, 2015, 2017 - 2019 All Rights Reserved.
--
-- This program is free software; you can redistribute it and/or
-- modify it under terms of the GNU General Public License as
-- published by the Free Software Foundation; either version 3, or (at
-- your option) any later version. This program is distributed in the
-- hope that it will be useful, but WITHOUT ANY WARRANTY; without even
-- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-- PURPOSE. See the GNU General Public License for more details. You
-- should have received a copy of the GNU General Public License
-- distributed with this program; see file COPYING. If not, write to
-- the Free Software Foundation, 51 Franklin Street, Suite 500, Boston,
-- MA 02110-1335, USA.
pragma License (GPL);
with Ada.Exceptions;
with Ada.Text_IO;
with WisiToken.Generate; use WisiToken.Generate;
with WisiToken.Syntax_Trees;
with WisiToken.Wisi_Ada;
package body WisiToken.BNF.Generate_Utils is
-- For Constant_Reference
Aliased_EOI_Name : aliased constant Ada.Strings.Unbounded.Unbounded_String := +EOI_Name;
Aliased_WisiToken_Accept_Name : aliased constant Ada.Strings.Unbounded.Unbounded_String :=
+WisiToken_Accept_Name;
-- body specs, as needed.
----------
-- Body subprograms
function Find_Kind (Data : aliased Generate_Data; Target_Kind : in String) return Token_ID
is begin
for Cursor in All_Tokens (Data).Iterate loop
if Kind (Cursor) = Target_Kind then
return ID (Cursor);
end if;
end loop;
return Invalid_Token_ID;
end Find_Kind;
function Name_1 (Cursor : in Token_Cursor) return String
is begin
-- This function is used to compute Descriptor.Image
case Cursor.Kind is
when Non_Grammar_Kind =>
declare
Kind_Ref : constant WisiToken.BNF.Token_Lists.Constant_Reference_Type :=
WisiToken.BNF.Token_Lists.Constant_Reference (Cursor.Data.Tokens.Non_Grammar, Cursor.Token_Kind);
Item_Ref : constant String_Pair_Lists.Constant_Reference_Type :=
String_Pair_Lists.Constant_Reference (Kind_Ref.Element.Tokens, Cursor.Token_Item);
begin
return -Item_Ref.Element.Name;
end;
when Terminals_Keywords =>
declare
Keyword_Ref : constant String_Pair_Lists.Constant_Reference_Type :=
String_Pair_Lists.Constant_Reference (Cursor.Data.Tokens.Keywords, Cursor.Keyword);
begin
return -Keyword_Ref.Element.Name;
end;
when Terminals_Others =>
declare
Kind_Ref : constant WisiToken.BNF.Token_Lists.Constant_Reference_Type :=
WisiToken.BNF.Token_Lists.Constant_Reference (Cursor.Data.Tokens.Tokens, Cursor.Token_Kind);
Item_Ref : constant String_Pair_Lists.Constant_Reference_Type :=
String_Pair_Lists.Constant_Reference (Kind_Ref.Element.Tokens, Cursor.Token_Item);
begin
return -Item_Ref.Element.Name;
end;
when EOI =>
return EOI_Name;
when WisiToken_Accept =>
return WisiToken_Accept_Name;
when Nonterminal =>
declare
Rule_Ref : constant Rule_Lists.Constant_Reference_Type := Rule_Lists.Constant_Reference
(Cursor.Data.Tokens.Rules, Cursor.Nonterminal);
begin
return -Rule_Ref.Element.Left_Hand_Side;
end;
when Done =>
raise SAL.Programmer_Error with "token cursor is done";
end case;
end Name_1;
procedure To_Grammar
(Data : aliased in out Generate_Data;
Source_File_Name : in String;
Start_Token : in String)
is
use WisiToken.Wisi_Ada;
Descriptor : WisiToken.Descriptor renames Data.Descriptor.all;
begin
Data.Grammar.Set_First (Descriptor.First_Nonterminal);
Data.Grammar.Set_Last (Descriptor.Last_Nonterminal);
Data.Source_Line_Map.Set_First (Descriptor.First_Nonterminal);
Data.Source_Line_Map.Set_Last (Descriptor.Last_Nonterminal);
Data.Action_Names := new Names_Array_Array (Descriptor.First_Nonterminal .. Descriptor.Last_Nonterminal);
Data.Check_Names := new Names_Array_Array (Descriptor.First_Nonterminal .. Descriptor.Last_Nonterminal);
pragma Assert (Descriptor.Accept_ID = Descriptor.First_Nonterminal);
begin
Data.Grammar (Descriptor.Accept_ID) :=
Descriptor.Accept_ID <= Only
(Find_Token_ID (Data, Start_Token) & Descriptor.EOI_ID + WisiToken.Syntax_Trees.Null_Action);
Data.Source_Line_Map (Descriptor.Accept_ID).Line := Line_Number_Type'First;
Data.Source_Line_Map (Descriptor.Accept_ID).RHS_Map.Set_First (0);
Data.Source_Line_Map (Descriptor.Accept_ID).RHS_Map.Set_Last (0);
Data.Source_Line_Map (Descriptor.Accept_ID).RHS_Map (0) := Line_Number_Type'First;
exception
when Not_Found =>
Put_Error
(Error_Message
(Source_File_Name, 1,
"start token '" & (Start_Token) & "' not found; need %start?"));
end;
for Rule of Data.Tokens.Rules loop
declare
RHS_Index : Natural := 0;
RHSs : WisiToken.Productions.RHS_Arrays.Vector;
LHS : Token_ID; -- not initialized for exception handler
Action_Names : Names_Array (0 .. Integer (Rule.Right_Hand_Sides.Length) - 1);
Action_All_Empty : Boolean := True;
Check_Names : Names_Array (0 .. Integer (Rule.Right_Hand_Sides.Length) - 1);
Check_All_Empty : Boolean := True;
begin
LHS := Find_Token_ID (Data, -Rule.Left_Hand_Side);
RHSs.Set_First (RHS_Index);
RHSs.Set_Last (Natural (Rule.Right_Hand_Sides.Length) - 1);
Data.Source_Line_Map (LHS).Line := Rule.Source_Line;
Data.Source_Line_Map (LHS).RHS_Map.Set_First (RHSs.First_Index);
Data.Source_Line_Map (LHS).RHS_Map.Set_Last (RHSs.Last_Index);
for Right_Hand_Side of Rule.Right_Hand_Sides loop
declare
use Ada.Strings.Unbounded;
use all type Ada.Containers.Count_Type;
Tokens : WisiToken.Token_ID_Arrays.Vector;
I : Integer := 1;
begin
if Right_Hand_Side.Tokens.Length > 0 then
Tokens.Set_First (I);
Tokens.Set_Last (Integer (Right_Hand_Side.Tokens.Length));
for Token of Right_Hand_Side.Tokens loop
Tokens (I) := Find_Token_ID (Data, -Token.Identifier);
I := I + 1;
end loop;
end if;
RHSs (RHS_Index) := (Tokens => Tokens, Action => null, Check => null);
if Length (Right_Hand_Side.Action) > 0 then
Action_All_Empty := False;
Action_Names (RHS_Index) := new String'
(-Rule.Left_Hand_Side & '_' & WisiToken.Trimmed_Image (RHS_Index));
end if;
if Length (Right_Hand_Side.Check) > 0 then
Check_All_Empty := False;
Check_Names (RHS_Index) := new String'
(-Rule.Left_Hand_Side & '_' & WisiToken.Trimmed_Image (RHS_Index) & "_check");
end if;
Data.Source_Line_Map (LHS).RHS_Map (RHS_Index) := Right_Hand_Side.Source_Line;
exception
when E : Not_Found =>
-- From "&"
Put_Error
(Error_Message
(Source_File_Name, Right_Hand_Side.Source_Line, Ada.Exceptions.Exception_Message (E)));
end;
RHS_Index := RHS_Index + 1;
end loop;
Data.Grammar (LHS) := LHS <= RHSs;
if not Action_All_Empty then
Data.Action_Names (LHS) := new Names_Array'(Action_Names);
end if;
if not Check_All_Empty then
Data.Check_Names (LHS) := new Names_Array'(Check_Names);
end if;
exception
when E : Not_Found =>
-- From Find_Token_ID (left_hand_side)
Put_Error
(Error_Message
(Source_File_Name, Rule.Source_Line, Ada.Exceptions.Exception_Message (E)));
end;
end loop;
WisiToken.Generate.Check_Consistent (Data.Grammar, Descriptor, Source_File_Name);
end To_Grammar;
----------
-- Public subprograms, declaration order
function Initialize
(Input_Data : aliased in WisiToken_Grammar_Runtime.User_Data_Type;
Ignore_Conflicts : in Boolean := False)
return Generate_Data
is
EOI_ID : constant Token_ID := Token_ID
(Count (Input_Data.Tokens.Non_Grammar) + Count (Input_Data.Tokens.Tokens)) + Token_ID
(Input_Data.Tokens.Keywords.Length) + Token_ID'First;
begin
return Result : aliased Generate_Data :=
(Tokens => Input_Data.Tokens'Access,
Descriptor => new WisiToken.Descriptor
(First_Terminal =>
(if Count (Input_Data.Tokens.Non_Grammar) > 0
then Token_ID (Count (Input_Data.Tokens.Non_Grammar)) + Token_ID'First
else Token_ID'First),
Last_Terminal => EOI_ID,
EOI_ID => EOI_ID,
Accept_ID => EOI_ID + 1,
First_Nonterminal => EOI_ID + 1,
Last_Nonterminal => EOI_ID + 1 + Token_ID (Input_Data.Tokens.Rules.Length)),
others => <>)
do
Result.Descriptor.Case_Insensitive := Input_Data.Language_Params.Case_Insensitive;
Result.Descriptor.New_Line_ID := Find_Kind (Result, "new-line");
Result.Descriptor.String_1_ID := Find_Kind (Result, "string-single");
Result.Descriptor.String_2_ID := Find_Kind (Result, "string-double");
-- Image set in loop below, which also updates these widths.
Result.Descriptor.Terminal_Image_Width := 0;
Result.Descriptor.Image_Width := 0;
Result.Descriptor.Last_Lookahead :=
(case (Input_Data.User_Parser) is
when None => Invalid_Token_ID,
when LR1 => Result.Descriptor.Last_Terminal,
when LALR => Result.Descriptor.First_Nonterminal,
when Packrat_Generate_Algorithm | External => Invalid_Token_ID);
for Cursor in All_Tokens (Result).Iterate loop
Result.Descriptor.Image (ID (Cursor)) := new String'(Name_1 (Cursor));
end loop;
for ID in Result.Descriptor.Image'Range loop
if ID in Result.Descriptor.First_Terminal .. Result.Descriptor.Last_Terminal then
if Result.Descriptor.Image (ID).all'Length > Result.Descriptor.Terminal_Image_Width then
Result.Descriptor.Terminal_Image_Width := Result.Descriptor.Image (ID).all'Length;
end if;
end if;
if Result.Descriptor.Image (ID).all'Length > Result.Descriptor.Image_Width then
Result.Descriptor.Image_Width := Result.Descriptor.Image (ID).all'Length;
end if;
end loop;
To_Grammar (Result, Input_Data.Grammar_Lexer.File_Name, -Input_Data.Language_Params.Start_Token);
Result.Ignore_Conflicts := Ignore_Conflicts;
end return;
end Initialize;
function Find_Token_ID (Data : aliased in Generate_Data; Token : in String) return Token_ID
is begin
for Cursor in All_Tokens (Data).Iterate loop
if Name (Cursor) = Token then
return ID (Cursor);
end if;
end loop;
raise Not_Found with "token '" & Token & "' not found";
end Find_Token_ID;
function All_Tokens (Data : aliased in Generate_Data) return Token_Container
is begin
return (Data => Data'Access);
end All_Tokens;
function Constant_Reference
(Container : aliased in Token_Container'Class;
Cursor : in Token_Cursor)
return Token_Constant_Reference_Type
is begin
case Cursor.Kind is
when Non_Grammar_Kind =>
declare
Token_Ref : constant WisiToken.BNF.Token_Lists.Constant_Reference_Type :=
WisiToken.BNF.Token_Lists.Constant_Reference (Container.Data.Tokens.Non_Grammar, Cursor.Token_Kind);
Item_Ref : constant String_Pair_Lists.Constant_Reference_Type :=
String_Pair_Lists.Constant_Reference (Token_Ref.Element.Tokens, Cursor.Token_Item);
begin
return (Element => Item_Ref.Element.all.Name'Access);
end;
when Terminals_Keywords =>
declare
Keyword_Ref : constant String_Pair_Lists.Constant_Reference_Type :=
String_Pair_Lists.Constant_Reference (Container.Data.Tokens.Keywords, Cursor.Keyword);
begin
return (Element => Keyword_Ref.Element.all.Name'Access);
end;
when Terminals_Others =>
declare
Token_Ref : constant WisiToken.BNF.Token_Lists.Constant_Reference_Type :=
WisiToken.BNF.Token_Lists.Constant_Reference (Container.Data.Tokens.Tokens, Cursor.Token_Kind);
Item_Ref : constant String_Pair_Lists.Constant_Reference_Type :=
String_Pair_Lists.Constant_Reference (Token_Ref.Element.Tokens, Cursor.Token_Item);
begin
return (Element => Item_Ref.Element.all.Name'Access);
end;
when EOI =>
return (Element => Aliased_EOI_Name'Access);
when WisiToken_Accept =>
return (Element => Aliased_WisiToken_Accept_Name'Access);
when Nonterminal =>
declare
Rule_Ref : constant Rule_Lists.Constant_Reference_Type := Rule_Lists.Constant_Reference
(Container.Data.Tokens.Rules, Cursor.Nonterminal);
begin
return (Element => Rule_Ref.Element.all.Left_Hand_Side'Access);
end;
when Done =>
raise SAL.Programmer_Error with "token cursor is done";
end case;
end Constant_Reference;
type Token_Access_Constant is access constant Token_Container;
type Iterator is new Iterator_Interfaces.Forward_Iterator with record
Container : Token_Access_Constant;
Non_Grammar : Boolean;
Nonterminals : Boolean;
end record;
overriding function First (Object : Iterator) return Token_Cursor;
overriding function Next (Object : Iterator; Position : Token_Cursor) return Token_Cursor;
overriding function First (Object : Iterator) return Token_Cursor
is begin
return First (Object.Container.Data.all, Object.Non_Grammar, Object.Nonterminals);
end First;
overriding function Next (Object : Iterator; Position : Token_Cursor) return Token_Cursor
is
Next_Position : Token_Cursor := Position;
begin
Next (Next_Position, Object.Nonterminals);
return Next_Position;
end Next;
function Iterate
(Container : aliased Token_Container;
Non_Grammar : in Boolean := True;
Nonterminals : in Boolean := True)
return Iterator_Interfaces.Forward_Iterator'Class
is begin
return Iterator'(Container'Access, Non_Grammar, Nonterminals);
end Iterate;
function Next_Kind_Internal
(Cursor : in out Token_Cursor;
Nonterminals : in Boolean)
return Boolean
is begin
-- Advance Cursor to the next kind; return True if any of that
-- kind exist, or kind is Done; False otherwise.
case Cursor.Kind is
when Non_Grammar_Kind =>
Cursor :=
(Data => Cursor.Data,
Kind => Terminals_Keywords,
ID => Cursor.Data.Descriptor.First_Terminal,
Token_Kind => WisiToken.BNF.Token_Lists.No_Element,
Token_Item => String_Pair_Lists.No_Element,
Keyword => Cursor.Data.Tokens.Keywords.First,
Nonterminal => Rule_Lists.No_Element);
return String_Pair_Lists.Has_Element (Cursor.Keyword);
when Terminals_Keywords =>
Cursor :=
(Data => Cursor.Data,
Kind => Terminals_Others,
ID => Cursor.ID,
Token_Kind => Cursor.Data.Tokens.Tokens.First,
Token_Item => String_Pair_Lists.No_Element,
Keyword => String_Pair_Lists.No_Element,
Nonterminal => Rule_Lists.No_Element);
if WisiToken.BNF.Token_Lists.Has_Element (Cursor.Token_Kind) then
Cursor.Token_Item := Cursor.Data.Tokens.Tokens (Cursor.Token_Kind).Tokens.First;
return WisiToken.BNF.String_Pair_Lists.Has_Element (Cursor.Token_Item);
else
return False;
end if;
when Terminals_Others =>
Cursor :=
(Data => Cursor.Data,
Kind => EOI,
ID => Cursor.ID,
Token_Kind => WisiToken.BNF.Token_Lists.No_Element,
Token_Item => String_Pair_Lists.No_Element,
Keyword => String_Pair_Lists.No_Element,
Nonterminal => Rule_Lists.No_Element);
return True;
when EOI =>
if Nonterminals then
if Rule_Lists.Has_Element (Cursor.Data.Tokens.Rules.First) then
Cursor :=
(Data => Cursor.Data,
Kind => WisiToken_Accept,
ID => Cursor.ID,
Token_Kind => WisiToken.BNF.Token_Lists.No_Element,
Token_Item => String_Pair_Lists.No_Element,
Keyword => String_Pair_Lists.No_Element,
Nonterminal => Rule_Lists.No_Element);
else
Cursor.Kind := Done;
end if;
return True;
else
Cursor.Kind := Done;
return True;
end if;
when WisiToken_Accept =>
Cursor :=
(Data => Cursor.Data,
Kind => Nonterminal,
ID => Cursor.ID,
Token_Kind => WisiToken.BNF.Token_Lists.No_Element,
Token_Item => String_Pair_Lists.No_Element,
Keyword => String_Pair_Lists.No_Element,
Nonterminal => Cursor.Data.Tokens.Rules.First);
-- Can't get here with no rules
return True;
when Nonterminal =>
Cursor.Kind := Done;
return True;
when Done =>
return True;
end case;
end Next_Kind_Internal;
function First
(Data : aliased in Generate_Data;
Non_Grammar : in Boolean;
Nonterminals : in Boolean)
return Token_Cursor
is
Cursor : Token_Cursor :=
(Data => Data'Access,
Kind => Non_Grammar_Kind,
ID => Token_ID'First,
Token_Kind => Data.Tokens.Non_Grammar.First,
Token_Item => String_Pair_Lists.No_Element,
Keyword => String_Pair_Lists.No_Element,
Nonterminal => Rule_Lists.No_Element);
begin
if Non_Grammar then
if WisiToken.BNF.Token_Lists.Has_Element (Cursor.Token_Kind) then
Cursor.Token_Item := Cursor.Data.Tokens.Non_Grammar (Cursor.Token_Kind).Tokens.First;
if WisiToken.BNF.String_Pair_Lists.Has_Element (Cursor.Token_Item) then
return Cursor;
end if;
end if;
end if;
-- There are no non_grammar tokens, or Non_Grammar false
loop
exit when Next_Kind_Internal (Cursor, Nonterminals);
end loop;
return Cursor;
end First;
procedure Next (Cursor : in out Token_Cursor; Nonterminals : in Boolean)
is begin
Cursor.ID := Cursor.ID + 1;
case Cursor.Kind is
when Non_Grammar_Kind =>
String_Pair_Lists.Next (Cursor.Token_Item);
if String_Pair_Lists.Has_Element (Cursor.Token_Item) then
return;
else
WisiToken.BNF.Token_Lists.Next (Cursor.Token_Kind);
if WisiToken.BNF.Token_Lists.Has_Element (Cursor.Token_Kind) then
Cursor.Token_Item := Cursor.Data.Tokens.Non_Grammar (Cursor.Token_Kind).Tokens.First;
if String_Pair_Lists.Has_Element (Cursor.Token_Item) then
return;
end if;
end if;
end if;
loop
exit when Next_Kind_Internal (Cursor, Nonterminals);
end loop;
return;
when Terminals_Keywords =>
-- Keywords before other terminals, so they have precedence over Identifiers
String_Pair_Lists.Next (Cursor.Keyword);
if String_Pair_Lists.Has_Element (Cursor.Keyword) then
return;
end if;
loop
exit when Next_Kind_Internal (Cursor, Nonterminals);
end loop;
return;
when Terminals_Others =>
WisiToken.BNF.String_Pair_Lists.Next (Cursor.Token_Item);
if WisiToken.BNF.String_Pair_Lists.Has_Element (Cursor.Token_Item) then
return;
else
WisiToken.BNF.Token_Lists.Next (Cursor.Token_Kind);
if WisiToken.BNF.Token_Lists.Has_Element (Cursor.Token_Kind) then
Cursor.Token_Item := Cursor.Data.Tokens.Tokens (Cursor.Token_Kind).Tokens.First;
if WisiToken.BNF.String_Pair_Lists.Has_Element (Cursor.Token_Item) then
return;
end if;
end if;
end if;
loop
exit when Next_Kind_Internal (Cursor, Nonterminals);
end loop;
return;
when EOI =>
if Next_Kind_Internal (Cursor, Nonterminals) then
return;
else
raise SAL.Programmer_Error;
end if;
when WisiToken_Accept =>
if Next_Kind_Internal (Cursor, Nonterminals) then
return;
else
raise SAL.Programmer_Error;
end if;
when Nonterminal =>
Rule_Lists.Next (Cursor.Nonterminal);
if Rule_Lists.Has_Element (Cursor.Nonterminal) then
return;
end if;
loop
exit when Next_Kind_Internal (Cursor, Nonterminals);
end loop;
return;
when Done =>
null;
end case;
end Next;
function Is_Done (Cursor : in Token_Cursor) return Boolean
is begin
return Cursor.Kind = Done;
end Is_Done;
function ID (Cursor : in Token_Cursor) return Token_ID
is begin
return Cursor.ID;
end ID;
function Name (Cursor : in Token_Cursor) return String
is begin
return Cursor.Data.Descriptor.Image (Cursor.ID).all;
end Name;
function Kind (Cursor : in Token_Cursor) return String
is begin
case Cursor.Kind is
when Non_Grammar_Kind =>
return -Token_Lists.Constant_Reference (Cursor.Data.Tokens.Non_Grammar, Cursor.Token_Kind).Kind;
when Terminals_Keywords =>
return "keyword";
when Terminals_Others =>
return -Token_Lists.Constant_Reference (Cursor.Data.Tokens.Tokens, Cursor.Token_Kind).Kind;
when EOI =>
return "EOI";
when WisiToken_Accept =>
return "accept";
when Nonterminal =>
return "nonterminal";
when Done =>
raise SAL.Programmer_Error with "token cursor is done";
end case;
end Kind;
function Value (Cursor : in Token_Cursor) return String
is begin
case Cursor.Kind is
when Non_Grammar_Kind =>
declare
Token_Ref : constant WisiToken.BNF.Token_Lists.Constant_Reference_Type :=
WisiToken.BNF.Token_Lists.Constant_Reference (Cursor.Data.Tokens.Non_Grammar, Cursor.Token_Kind);
Item_Ref : constant String_Pair_Lists.Constant_Reference_Type :=
String_Pair_Lists.Constant_Reference (Token_Ref.Element.Tokens, Cursor.Token_Item);
begin
return -Item_Ref.Element.Value;
end;
when Terminals_Keywords =>
declare
Keyword_Ref : constant String_Pair_Lists.Constant_Reference_Type :=
String_Pair_Lists.Constant_Reference (Cursor.Data.Tokens.Keywords, Cursor.Keyword);
begin
return -Keyword_Ref.Element.Value;
end;
when Terminals_Others =>
declare
Token_Ref : constant WisiToken.BNF.Token_Lists.Constant_Reference_Type :=
WisiToken.BNF.Token_Lists.Constant_Reference (Cursor.Data.Tokens.Tokens, Cursor.Token_Kind);
Item_Ref : constant String_Pair_Lists.Constant_Reference_Type :=
String_Pair_Lists.Constant_Reference (Token_Ref.Element.Tokens, Cursor.Token_Item);
begin
return -Item_Ref.Element.Value;
end;
when EOI | WisiToken_Accept | Nonterminal =>
return "";
when Done =>
raise SAL.Programmer_Error with "token cursor is done";
end case;
end Value;
function To_Conflicts
(Data : aliased in out Generate_Data;
Conflicts : in WisiToken.BNF.Conflict_Lists.List;
Source_File_Name : in String)
return WisiToken.Generate.LR.Conflict_Lists.List
is
use WisiToken.Generate.LR;
Result : WisiToken.Generate.LR.Conflict_Lists.List;
Conflict : WisiToken.Generate.LR.Conflict;
begin
for Item of Conflicts loop
begin
Conflict :=
(Conflict_Parse_Actions'Value (-Item.Action_A),
Find_Token_ID (Data, -Item.LHS_A),
Conflict_Parse_Actions'Value (-Item.Action_B),
Find_Token_ID (Data, -Item.LHS_B),
-1,
Find_Token_ID (Data, -Item.On));
Result.Append (Conflict);
exception
when E : Not_Found =>
if not Data.Ignore_Conflicts then
Put_Error
(Error_Message
(Source_File_Name, Item.Source_Line, Ada.Exceptions.Exception_Message (E)));
end if;
end;
end loop;
return Result;
end To_Conflicts;
function To_Nonterminal_ID_Set
(Data : aliased in Generate_Data;
Item : in String_Lists.List)
return Token_ID_Set
is
Result : Token_ID_Set := (Data.Descriptor.First_Nonterminal .. Data.Descriptor.Last_Nonterminal => False);
begin
for Token of Item loop
Result (Find_Token_ID (Data, Token)) := True;
end loop;
return Result;
end To_Nonterminal_ID_Set;
function To_McKenzie_Param
(Data : aliased in Generate_Data;
Item : in McKenzie_Recover_Param_Type)
return WisiToken.Parse.LR.McKenzie_Param_Type
is
use Ada.Strings.Unbounded;
Result : WisiToken.Parse.LR.McKenzie_Param_Type :=
-- We use an aggregate, and overwrite some below, so the compiler
-- reminds us to change this when we modify McKenzie_Param_Type.
(Data.Descriptor.First_Terminal,
Data.Descriptor.Last_Terminal,
Data.Descriptor.First_Nonterminal,
Data.Descriptor.Last_Nonterminal,
Insert => (others => Item.Default_Insert),
Delete => (others => Item.Default_Delete_Terminal),
Push_Back => (others => Item.Default_Push_Back),
Undo_Reduce => (others => Item.Default_Push_Back), -- no separate default for undo_reduce
Minimal_Complete_Cost_Delta => Item.Minimal_Complete_Cost_Delta,
Fast_Forward => Item.Fast_Forward,
Matching_Begin => Item.Matching_Begin,
Ignore_Check_Fail => Item.Ignore_Check_Fail,
Task_Count => 0,
Check_Limit => Item.Check_Limit,
Check_Delta_Limit => Item.Check_Delta_Limit,
Enqueue_Limit => Item.Enqueue_Limit);
begin
for Pair of Item.Delete loop
Result.Delete (Find_Token_ID (Data, -Pair.Name)) := Natural'Value (-Pair.Value);
end loop;
for Pair of Item.Insert loop
Result.Insert (Find_Token_ID (Data, -Pair.Name)) := Natural'Value (-Pair.Value);
end loop;
for Pair of Item.Push_Back loop
Result.Push_Back (Find_Token_ID (Data, -Pair.Name)) := Natural'Value (-Pair.Value);
end loop;
for Pair of Item.Undo_Reduce loop
Result.Undo_Reduce (Find_Token_ID (Data, -Pair.Name)) := Natural'Value (-Pair.Value);
end loop;
return Result;
end To_McKenzie_Param;
procedure Count_Actions (Data : in out Generate_Utils.Generate_Data)
is begin
Data.Table_Actions_Count := 0;
for State_Index in Data.LR_Parse_Table.States'Range loop
Data.Table_Actions_Count := Data.Table_Actions_Count +
Actions_Length (Data.LR_Parse_Table.States (State_Index)) + 1;
end loop;
end Count_Actions;
procedure Put_Stats
(Input_Data : in WisiToken_Grammar_Runtime.User_Data_Type;
Generate_Data : in Generate_Utils.Generate_Data)
is
use Ada.Text_IO;
begin
New_Line;
Put_Line
(Integer'Image (Input_Data.Rule_Count) & " rules," &
Integer'Image (Input_Data.Action_Count) & " user actions," &
Integer'Image (Input_Data.Check_Count) & " checks," &
WisiToken.State_Index'Image (Generate_Data.Parser_State_Count) & " states," &
Integer'Image (Generate_Data.Table_Actions_Count) & " parse actions");
end Put_Stats;
function Actions_Length (State : in Parse.LR.Parse_State) return Integer
is
use all type WisiToken.Parse.LR.Action_Node_Ptr;
Node : Parse.LR.Action_Node_Ptr := State.Action_List;
begin
return Result : Integer := 0
do
loop
exit when Node = null;
Result := Result + 1;
Node := Node.Next;
exit when Node.Next = null; -- don't count Error
end loop;
end return;
end Actions_Length;
end WisiToken.BNF.Generate_Utils;
|
with System.Unsigned_Types; use System.Unsigned_Types;
package body System.Img_Uns is
--------------------
-- Image_Unsigned --
--------------------
procedure Image_Unsigned
(V : System.Unsigned_Types.Unsigned;
S : in out String;
P : out Natural)
is
pragma Assert (S'First = 1);
begin
P := 0;
Set_Image_Unsigned (V, S, P);
end Image_Unsigned;
------------------------
-- Set_Image_Unsigned --
------------------------
Hex : constant array (System.Unsigned_Types.Unsigned range 0 .. 15)
of Character := "0123456789ABCDEF";
procedure Set_Image_Unsigned
(V : System.Unsigned_Types.Unsigned;
S : in out String;
P : in out Natural)
is
begin
if V >= 16 then
Set_Image_Unsigned (V / 16, S, P);
P := P + 1;
S (P) := Hex (V rem 16);
else
P := P + 1;
S (P) := Hex (V);
end if;
end Set_Image_Unsigned;
end System.Img_Uns;
|
with AWS.SMTP, AWS.SMTP.Client, AWS.SMTP.Authentication.Plain;
with Ada.Text_IO;
use Ada, AWS;
procedure Sendmail is
Status : SMTP.Status;
Auth : aliased constant SMTP.Authentication.Plain.Credential :=
SMTP.Authentication.Plain.Initialize ("id", "password");
Isp : SMTP.Receiver;
begin
Isp :=
SMTP.Client.Initialize
("smtp.mail.com",
Port => 5025,
Credential => Auth'Unchecked_Access);
SMTP.Client.Send
(Isp,
From => SMTP.E_Mail ("Me", "me@some.org"),
To => SMTP.E_Mail ("You", "you@any.org"),
Subject => "subject",
Message => "Here is the text",
Status => Status);
if not SMTP.Is_Ok (Status) then
Text_IO.Put_Line
("Can't send message :" & SMTP.Status_Message (Status));
end if;
end Sendmail;
|
-- 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 Orka.SIMD.SSE.Singles.Arithmetic;
with Orka.SIMD.SSE.Singles.Swizzle;
with Orka.SIMD.SSE3.Singles.Swizzle;
package body Orka.SIMD.SSE3.Singles.Arithmetic is
function Sum (Elements : m128) return Float_32 is
use SIMD.SSE.Singles.Arithmetic;
use SIMD.SSE.Singles.Swizzle;
use SIMD.SSE3.Singles.Swizzle;
-- From https://stackoverflow.com/a/35270026
-- Elements: X Y Z W
-- Shuffled: Y Y W W
-- --------------- +
-- Sum: X+Y Y+Y Z+W W+W
Shuffled : constant m128 := Duplicate_H (Elements);
Sum : constant m128 := Elements + Shuffled;
-- Sum: X+Y Y+Y Z+W W+W
-- Move: Z+W W+W W W
-- --------------- +
-- New sum: X+Y+Z+W . . .
Result : constant m128 := Move_HL (Shuffled, Sum) + Sum;
begin
return Result (X);
end Sum;
end Orka.SIMD.SSE3.Singles.Arithmetic;
|
with numbers; use numbers;
with strings; use strings;
package address is
type pos_addr_t is tagged private;
null_pos_addr : constant pos_addr_t;
error_address_odd : exception;
function create (value : word) return pos_addr_t;
procedure set (pos_addr : in out pos_addr_t; value : word);
function get (pos_addr : pos_addr_t) return word;
function valid_value_for_pos_addr (value : word) return boolean;
procedure inc (pos_addr : in out pos_addr_t);
function inc (pos_addr : pos_addr_t) return pos_addr_t;
procedure dec (pos_addr : in out pos_addr_t);
function "<" (a, b : pos_addr_t) return boolean;
function "<=" (a, b : pos_addr_t) return boolean;
function ">" (a, b : pos_addr_t) return boolean;
function ">=" (a, b : pos_addr_t) return boolean;
function "-" (a, b : pos_addr_t) return pos_addr_t;
function "+" (a, b : pos_addr_t) return pos_addr_t;
function "*" (a, b : pos_addr_t) return pos_addr_t;
function "/" (a, b : pos_addr_t) return pos_addr_t;
function "+" (a: pos_addr_t; b : natural) return pos_addr_t;
function "+" (a: pos_addr_t; b : word) return pos_addr_t;
private
use type word;
type pos_addr_t is tagged record
addr : word;
end record;
null_pos_addr : constant pos_addr_t := (addr => 16#ffff#);
end address;
|
with League.Strings;
with XML.SAX.Attributes;
with XML.SAX.Content_Handlers;
package Handlers is
type Handler is
limited new XML.SAX.Content_Handlers.SAX_Content_Handler with null record;
overriding procedure Start_Element
(Self : in out Handler;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String;
Qualified_Name : League.Strings.Universal_String;
Attributes : XML.SAX.Attributes.SAX_Attributes;
Success : in out Boolean);
overriding function Error_String
(Self : Handler) return League.Strings.Universal_String;
end Handlers;
|
with Asis.Compilation_Units;
with Asis.Elements;
with Asis.Iterator;
-- -- GNAT-specific:
with Asis.Set_Get;
with Asis.Text;
with Asis_Adapter.Element.Associations;
with Asis_Adapter.Element.Clauses;
with Asis_Adapter.Element.Declarations;
with Asis_Adapter.Element.Defining_Names;
with Asis_Adapter.Element.Definitions;
with Asis_Adapter.Element.Exception_Handlers;
with Asis_Adapter.Element.Expressions;
with Asis_Adapter.Element.Paths;
with Asis_Adapter.Element.Pragmas;
with Asis_Adapter.Element.Statements;
package body Asis_Adapter.Element is
----------------------
-- EXPORTED (private):
----------------------
procedure Add_To_Dot_Label
(This : in out Class;
Name : in String;
Value : in String) is
begin
Add_To_Dot_Label (Dot_Label => This.Dot_Label,
Outputs => This.Outputs,
Name => Name,
Value => Value);
end;
procedure Add_To_Dot_Label
(This : in out Class;
Name : in String;
Value : in Wide_String) is
begin
This.Add_To_Dot_Label (Name, To_String (Value));
end;
procedure Add_To_Dot_Label
(This : in out Class;
Name : in String;
Value : in a_nodes_h.Element_ID) is
begin
This.Add_To_Dot_Label (Name, To_String (Value));
end;
procedure Add_To_Dot_Label
(This : in out Class;
Name : in String;
Value : in Boolean) is
begin
Add_To_Dot_Label (Dot_Label => This.Dot_Label,
Outputs => This.Outputs,
Name => Name,
Value => Value);
end;
procedure Add_To_Dot_Label
(This : in out Class;
Value : in String) is
begin
Add_To_Dot_Label (Dot_Label => This.Dot_Label,
Outputs => This.Outputs,
Value => Value);
end;
procedure Add_Not_Implemented
(This : in out Class;
Ada_Version : in Ada_Versions := Supported_Ada_Version) is
begin
if Ada_Version <= Supported_Ada_Version then
This.Add_To_Dot_Label
("ASIS_PROCESSING", String'("NOT_IMPLEMENTED_COMPLETELY"));
This.Outputs.A_Nodes.Add_Not_Implemented;
else
This.Add_To_Dot_Label
("ASIS_PROCESSING",
Ada_Version'Image & "_FEATURE_NOT_IMPLEMENTED_IN_" &
Supported_Ada_Version'Image);
end if;
end Add_Not_Implemented;
procedure Add_Dot_Edge
(This : in out Class;
From : in a_nodes_h.Element_ID;
To : in a_nodes_h.Element_ID;
Label : in String)
is
begin
Add_Dot_Edge (Outputs => This.Outputs,
From => From,
From_Kind => Element_ID_Kind,
To => To,
To_Kind => Element_ID_Kind,
Label => Label);
end Add_Dot_Edge;
procedure Add_To_Dot_Label_And_Edge
(This : in out Class;
Label : in String;
To : in a_nodes_h.Element_ID) is
begin
This.Add_To_Dot_Label (Label, To_String (To));
This.Add_Dot_Edge (From => This.Element_IDs.First_Element,
To => To,
Label => Label);
end Add_To_Dot_Label_And_Edge;
-----------------------------------------------------------------------------
-- Element_ID support
------------
-- EXPORTED:
------------
function Get_Element_ID
(Element : in Asis.Element)
return Element_ID
is
((Node_ID => Asis.Set_Get.Node_Value (Element),
Kind => Asis.Set_Get.Int_Kind (Element)));
------------
-- EXPORTED:
------------
function To_Element_ID
(This : in Element_ID)
return a_nodes_h.Element_ID
is
Result : Integer;
begin
Result := Integer (This.Node_ID) * 1000 +
A4G.Int_Knds.Internal_Element_Kinds'Pos(This.Kind);
return a_nodes_h.Element_ID (Result);
end To_Element_ID;
------------
-- EXPORTED:
------------
function Get_Element_ID
(Element : in Asis.Element)
return a_nodes_h.Element_ID
is
(To_Element_ID (Get_Element_ID (Element)));
------------
-- EXPORTED:
------------
function To_String
(This : in a_nodes_h.Element_ID)
return String
is
(To_String (This, Element_ID_Kind));
-- END Element_ID support
-----------------------------------------------------------------------------
------------
-- EXPORTED:
------------
function To_Element_ID_List
(Dot_Label : in out Dot.HTML_Like_Labels.Class;
Outputs : in out Outputs_Record;
This_Element_ID : in a_nodes_h.Element_ID;
Elements_In : in Asis.Element_List;
Dot_Label_Name : in String;
Add_Edges : in Boolean := False;
This_Is_Unit : in Boolean := False)
return a_nodes_h.Element_ID_List
is
Element_Count : constant Natural := Elements_In'Length;
IDs : anhS.Element_ID_Array_Access := new
anhS.Element_ID_Array (1 .. Element_Count);
IDs_Index : Positive := IDs'First;
begin
for Element of Elements_In loop
declare
Element_ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Element);
Label : constant String :=
Dot_Label_Name & " (" & IDs_Index'Image & ")";
begin
IDs (IDs_Index) := Element_ID;
Add_To_Dot_Label (Dot_Label => Dot_Label,
Outputs => Outputs,
Name => Label,
Value => To_String (Element_ID));
if Add_Edges then
Add_Dot_Edge (Outputs => Outputs,
From => This_Element_ID,
From_Kind => (if This_Is_Unit
then Unit_Id_Kind
else Element_ID_Kind),
To => Element_ID,
To_Kind => Element_ID_Kind,
Label => Label);
end if;
IDs_Index := IDs_Index + 1;
end;
end loop;
return
(length => Interfaces.C.int(Element_Count),
IDs => anhS.To_Element_ID_Ptr (IDs));
end To_Element_ID_List;
------------
-- EXPORTED:
------------
function Add_Operator_Kind
(State : in out Class;
Element : in Asis.Element)
return a_nodes_h.Operator_Kinds
is
Operator_Kind : constant Asis.Operator_Kinds :=
Asis.Elements.Operator_Kind (Element);
begin
State.Add_To_Dot_Label ("Operator_Kind", Operator_Kind'Image);
return To_Operator_Kinds (Operator_Kind);
end;
------------
-- EXPORTED:
------------
function To_Element_ID_List
(This : in out Class;
Elements_In : in Asis.Element_List;
Dot_Label_Name : in String;
Add_Edges : in Boolean := False)
return a_nodes_h.Element_ID_List is
begin
return To_Element_ID_List (Dot_Label => This.Dot_Label,
Outputs => This.Outputs,
This_Element_ID => This.Element_IDs.First_Element,
Elements_In => Elements_In,
Dot_Label_Name => Dot_Label_Name,
Add_Edges => Add_Edges);
end To_Element_ID_List;
------------
-- EXPORTED:
------------
procedure Add_Element_List
(This : in out Class;
Elements_In : in Asis.Element_List;
Dot_Label_Name : in String;
List_Out : out a_nodes_h.Element_ID_List;
Add_Edges : in Boolean := False) is
begin
List_Out := To_Element_ID_List (This => This,
Elements_In => Elements_In,
Dot_Label_Name => Dot_Label_Name,
Add_Edges => Add_Edges);
end Add_Element_List;
--------------------------------------------------------------------------
--------------------------------------------------------------------------
-- function Enclosing_ID
-- (Element : in Asis.Element)
-- return Dot.ID_Type
-- is
-- Result : Dot.ID_Type; -- Initilaized
-- Enclosing_Element_Id : constant a_nodes_h.Element_ID :=
-- Get_Element_ID (Asis.Elements.Enclosing_Element (Element));
-- Enclosing_Unit_Id : constant A4G.A_Types.Unit_Id :=
-- Asis.Set_Get.Encl_Unit_Id (Element);
-- function Enclosing_Is_Element return boolean
-- is (Types."/=" (Enclosing_Element_Id, Types.Empty));
-- begin
-- if Enclosing_Is_Element then
-- Result := To_Dot_ID_Type (Enclosing_Element_Id);
-- else
-- Result := To_Dot_ID_Type (Enclosing_Unit_Id);
-- end if;
-- return Result;
-- end Enclosing_ID;
function Enclosing_ID
(Element : in Asis.Element)
return a_nodes_h.Element_ID is
begin
return Get_Element_ID
(Asis.Elements.Enclosing_Element (Element));
end Enclosing_ID;
function Spec_Or_Body_Image
(Unit_Class : in Asis.Unit_Classes)
return String
is
use all type Asis.Unit_Classes;
begin
case Unit_Class is
when Not_A_Class =>
return "";
when A_Public_Declaration |
A_Private_Declaration =>
return ".ads";
when A_Public_Body |
A_Private_Body |
A_Public_Declaration_And_Body |
A_Separate_Body =>
return ".adb";
end case;
end Spec_Or_Body_Image;
function Source_Location_Image
(Unit_Name : in String;
Span : in Asis.Text.Span)
return String is
begin
return Unit_Name & " - " &
NLB_Image (Span.First_Line) & ":" & NLB_Image (Span.First_Column) &
" .. " &
NLB_Image (Span.Last_Line) & ":" & NLB_Image (Span.Last_Column);
end Source_Location_Image;
--------------------------------------------------------------------------
--------------------------------------------------------------------------
------------
-- EXPORTED:
------------
procedure Do_Pre_Child_Processing
(Element : in Asis.Element;
Control : in out Asis.Traverse_Control;
State : in out Class)
is
Parent_Name : constant String := Module_Name;
Module_Name : constant String := Parent_Name & ".Process_Element";
Result : a_nodes_h.Element_Struct renames State.A_Element;
Element_Kind : constant Asis.Element_Kinds :=
Asis.Elements.Element_Kind (Element);
procedure Add_Element_ID is begin
-- ID is in the Dot node twice (once in the Label and once in
-- Node_ID), but not in the a_node twice.
State.Add_To_Dot_Label (To_String (State.Element_IDs.First_Element));
Result.id := State.Element_IDs.First_Element;
end;
procedure Add_Element_Kind is begin
State.Add_To_Dot_Label ("Element_Kind", Element_Kind'Image);
Result.Element_Kind := To_Element_Kinds (Element_Kind);
end;
procedure Add_Source_Location is
Unit : constant Asis.Compilation_Unit :=
Asis.Elements.Enclosing_Compilation_Unit (Element);
Unit_Class : constant Asis.Unit_Classes :=
Asis.Compilation_Units.Unit_Class (Unit);
Unit_Name : constant String := To_String
(Asis.Compilation_Units.Unit_Full_Name (Unit)) &
Spec_Or_Body_Image (Unit_Class);
Span : constant Asis.Text.Span := Asis.Text.Element_Span (Element);
Image : constant string := Source_Location_Image
(Unit_Name, Span);
begin
State.Add_To_Dot_Label ("Source", Image);
Result.Source_Location :=
(Unit_Name => To_Chars_Ptr (Unit_Name),
First_Line => Interfaces.C.int (Span.First_Line),
First_Column => Interfaces.C.int (Span.First_Column),
Last_Line => Interfaces.C.int (Span.Last_Line),
Last_Column => Interfaces.C.int (Span.Last_Column));
end;
-- Alphabetical order:
procedure Add_Is_Part_Of_Implicit is
Value : constant Boolean := Asis.Elements.Is_Part_Of_Implicit (Element);
begin
State.Add_To_Dot_Label ("Is_Part_Of_Implicit", Value);
Result.Is_Part_Of_Implicit := a_nodes_h.Support.To_bool (Value);
end;
procedure Add_Is_Part_Of_Inherited is
Value : constant Boolean := Asis.Elements.Is_Part_Of_Inherited (Element);
begin
State.Add_To_Dot_Label ("Is_Part_Of_Inherited", Value);
Result.Is_Part_Of_Inherited := a_nodes_h.Support.To_bool (Value);
end;
procedure Add_Is_Part_Of_Instance is
Value : constant Boolean := Asis.Elements.Is_Part_Of_Instance (Element);
begin
State.Add_To_Dot_Label ("Is_Part_Of_Instance", Value);
Result.Is_Part_Of_Instance := a_nodes_h.Support.To_bool (Value);
end;
procedure Add_Hash is
Value : constant Asis.ASIS_Integer := Asis.Elements.Hash (Element);
begin
State.Add_To_Dot_Label ("Hash", Value'Image);
Result.Hash := a_nodes_h.ASIS_Integer (Value);
end;
procedure Add_Enclosing_Element is
Value : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Elements.Enclosing_Element (Element));
begin
-- State.Add_Dot_Edge (From => Enclosing_Element_Id,
-- To => State.Element_Id,
-- Label => "Child");
State.Add_To_Dot_Label ("Enclosing_Element", Value);
Result.Enclosing_Element_Id := Value;
end;
function Debug_Image return ICS.chars_ptr is
WS : constant Wide_String := Asis.Elements.Debug_Image (Element);
begin
State.Add_To_Dot_Label ("Debug_Image", To_Quoted_String (WS));
return To_Chars_Ptr(WS);
end;
procedure Put_Debug is
procedure Put_Line (Name : in String;
Value : in String) is
begin
State.Outputs.Text.Put_Indented_Line ("* " & Name & " => " & Value);
end;
procedure Put_Separator is
begin
State.Outputs.Text.Put_Indented_Line (String'(1 .. 40 => '*'));
end;
use Asis.Set_Get;
begin
Put_Separator;
Put_Line ("Node ", Node (Element)'Image);
Put_Line ("R_Node ", R_Node (Element)'Image);
Put_Line ("Node_Field_1 ", Node_Field_1 (Element)'Image);
Put_Line ("Node_Field_2 ", Node_Field_2 (Element)'Image);
Put_Line ("Node_Value ", Node_Value (Element)'Image);
Put_Line ("R_Node_Value ", R_Node_Value (Element)'Image);
Put_Line ("Node_Field_1_Value", Node_Field_1_Value (Element)'Image);
Put_Line ("Node_Field_2_Value", Node_Field_2_Value (Element)'Image);
-- Put_Line ("Encl_Unit ", Encl_Unit (Element)'Image);
Put_Line ("Encl_Unit_Id ", Encl_Unit_Id (Element)'Image);
-- Put_Line ("Encl_Cont ", Encl_Cont (Element)'Image);
Put_Line ("Encl_Cont_Id ", Encl_Cont_Id (Element)'Image);
Put_Line ("Kind ", Kind (Element)'Image);
Put_Line ("Int_Kind ", Int_Kind (Element)'Image);
Put_Line ("Is_From_Implicit ", Is_From_Implicit (Element)'Image);
Put_Line ("Is_From_Inherited ", Is_From_Inherited (Element)'Image);
Put_Line ("Is_From_Instance ", Is_From_Instance (Element)'Image);
Put_Line ("Special_Case ", Special_Case (Element)'Image);
Put_Line ("Normalization_Case", Normalization_Case (Element)'Image);
Put_Line ("Parenth_Count ", Parenth_Count (Element)'Image);
Put_Line ("Encl_Tree ", Encl_Tree (Element)'Image);
Put_Line ("Rel_Sloc ", Rel_Sloc (Element)'Image);
Put_Line ("Character_Code ", Character_Code (Element)'Image);
-- Put_Line ("Obtained ", Obtained (Element)'Image);
Put_Separator;
end;
procedure Start_Output is
Default_Node : Dot.Node_Stmt.Class; -- Initialized
Default_Label : Dot.HTML_Like_Labels.Class; -- Initialized
begin
-- Set defaults:
Result := a_nodes_h.Support.Default_Element_Struct;
State.Outputs.Text.End_Line;
-- Element ID comes out on next line via Add_Element_ID:
State.Outputs.Text.Put_Indented_Line (String'("BEGIN "));
State.Outputs.Text.Indent;
State.Dot_Node := Default_Node;
State.Dot_Label := Default_Label;
-- Get ID:
State.Element_IDs.Prepend (Get_Element_ID (Element));
State.Dot_Node.Node_ID.ID :=
To_Dot_ID_Type (State.Element_IDs.First_Element, Element_ID_Kind);
-- Result.Debug_Image := Debug_Image;
-- Put_Debug;
Add_Element_ID;
Add_Element_Kind;
Add_Is_Part_Of_Implicit;
Add_Is_Part_Of_Inherited;
Add_Is_Part_Of_Instance;
Add_Hash;
Add_Enclosing_Element;
Add_Source_Location;
end;
procedure Finish_Output is
begin
State.Dot_Node.Add_Label (State.Dot_Label);
State.Outputs.Graph.Append_Stmt
(new Dot.Node_Stmt.Class'(State.Dot_Node));
State.Outputs.A_Nodes.Push (Result);
end;
use all type Asis.Element_Kinds;
begin
If Element_Kind /= Not_An_Element then
Start_Output;
end if;
case Element_Kind is
when Not_An_Element =>
raise Program_Error with
Module_Name & " called with: " & Element_Kind'Image;
when A_Pragma =>
Pragmas.Do_Pre_Child_Processing (Element, State);
when A_Defining_Name =>
Defining_Names.Do_Pre_Child_Processing (Element, State);
when A_Declaration =>
Declarations.Do_Pre_Child_Processing (Element, State);
when A_Definition =>
Definitions.Do_Pre_Child_Processing (Element, State);
when An_Expression =>
Expressions.Do_Pre_Child_Processing (Element, State);
when An_Association =>
Associations.Do_Pre_Child_Processing (Element, State);
when A_Statement =>
Statements.Do_Pre_Child_Processing (Element, State);
when A_Path =>
Paths.Do_Pre_Child_Processing (Element, State);
when A_Clause =>
Clauses.Do_Pre_Child_Processing (Element, State);
when An_Exception_Handler =>
Exception_Handlers.Do_Pre_Child_Processing (Element, State);
end case;
-- Add_Enclosing_Element;
Finish_Output;
end Do_Pre_Child_Processing;
procedure Do_Post_Child_Processing
(Element : Asis.Element;
Control : in out Asis.Traverse_Control;
State : in out Class) is
Element_Kind : constant Asis.Element_Kinds :=
Asis.Elements.Element_Kind (Element);
use all type Asis.Element_Kinds;
begin
State.Outputs.Text.End_Line;
State.Outputs.Text.Dedent;
State.Outputs.Text.Put_Indented_Line
(String'("END " & To_String (State.Element_IDs.First_Element)));
State.Element_IDs.Delete_First;
-- Another traversal is needed to retrieve information for
-- implicit elements. This has to happen in post_child_processing
-- as the elements are created in the pre_child_processing step.
If Element_Kind = A_Definition then
Definitions.Do_Post_Child_Processing (Element, State);
end if;
end Do_Post_Child_Processing;
-- Call Pre_Operation on ths element, call Traverse_Element on all children,
-- then call Post_Operation on this element:
procedure Traverse_Element is new
Asis.Iterator.Traverse_Element
(State_Information => Class,
Pre_Operation => Do_Pre_Child_Processing,
Post_Operation => Do_Post_Child_Processing);
------------
-- EXPORTED:
------------
procedure Process_Element_Tree
(This : in out Class;
Element : in Asis.Element;
Outputs : in Outputs_Record)
is
Process_Control : Asis.Traverse_Control := Asis.Continue;
begin
-- I would like to just pass Outputs through and not store it in the
-- object, since it is all pointers and we doesn't need to store their
-- values between calls to Process_Element_Tree. Outputs has to go into
-- State_Information in the Traverse_Element instatiation, though, so
-- we'll put it in the object and pass that:
This.Outputs := Outputs;
Traverse_Element
(Element => Element,
Control => Process_Control,
State => This);
end Process_Element_Tree;
end Asis_Adapter.Element;
|
-----------------------------------------------------------------------
-- 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.
-----------------------------------------------------------------------
with Ada.Containers;
with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Hash;
with ADO.Sessions;
generic
type Element_Type is (<>);
package ADO.Caches.Discrete is
pragma Elaborate_Body;
-- The cache type that maintains a cache of name/value pairs.
type Cache_Type is new ADO.Caches.Cache_Type with private;
type Cache_Type_Access is access all Cache_Type'Class;
-- 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;
-- 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;
-- 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);
-- 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);
-- Initialize the entity cache by reading the database entity table.
procedure Initialize (Cache : in out Cache_Type;
Session : in out ADO.Sessions.Session'Class);
private
package Cache_Map is new
Ada.Containers.Indefinite_Hashed_Maps (Key_Type => String,
Element_Type => Element_Type,
Hash => Ada.Strings.Hash,
Equivalent_Keys => "=");
protected type 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;
-- 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);
-- 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);
private
Values : Cache_Map.Map;
end Cache_Controller;
type Cache_Type is new ADO.Caches.Cache_Type with record
Controller : Cache_Controller;
end record;
end ADO.Caches.Discrete;
|
-- Instantiate this package to create a sub-command parser/executor
with CLIC.Config;
generic
Main_Command_Name : String; -- Name of the main command or program
Version : String; -- Version of the program
with procedure Set_Global_Switches
(Config : in out CLIC.Subcommand.Switches_Configuration);
-- This procedure should define the global switches using the
-- Register_Switch procedures of the CLIC.Subcommand package.
with procedure Put (Str : String); -- Used to print help and usage
with procedure Put_Line (Str : String); -- Used to print help and usage
with procedure Put_Error (Str : String); -- Used to print errors
with procedure Error_Exit (Code : Integer);
-- Used to signal that the program should terminate with the give error
-- code. Typicaly use GNAT.OS_Lib.OS_Exit.
-- The procedures below are used to format the output such as usage and
-- help. Use CLIC.Subcommand.No_TTY if you don't want or need formating.
with function TTY_Chapter (Str : String) return String;
with function TTY_Description (Str : String) return String;
with function TTY_Version (Str : String) return String;
with function TTY_Underline (Str : String) return String;
with function TTY_Emph (Str : String) return String;
package CLIC.Subcommand.Instance is
procedure Register (Cmd : not null Command_Access);
-- Register a sub-command
procedure Register (Group : String; Cmd : not null Command_Access);
-- Register a sub-command in a group
procedure Register (Topic : not null Help_Topic_Access);
-- Register an help topic
procedure Set_Alias (Alias : Identifier; Replacement : AAA.Strings.Vector);
-- Define Alias such that "<Main_Command_Name> <Alias> <Extra_Args>" will
-- be replaced by "<Main_Command_Name> <Replacement> <Extra_Args>".
-- If Alias is already set, it will be silently replaced.
procedure Load_Aliases (Conf : CLIC.Config.Instance;
Root_Key : String := "alias");
-- Load aliases from the given configuration.
--
-- All the config keys in the format "<Root_Key>.<sub-key>" are
-- processed. If the value of a key is a (not null) String, <sub-key>
-- is registered as an alias for the value (parsed into a list with
-- GNAT.OS_Lib.Argument_String_To_List).
--
-- For instance when Root_Key := "alias" (default):
-- alias.test1 = "cmd arg1 arg2" # Valid: test1 -> ["cmd", "arg1", "arg2"]
-- alias.test2 = "cmd" # Valid: test2 -> ["cmd"]
-- alias.test3 = "" # Ignored
-- alias.test4.test = "cmd arg1" # Ignored
-- alias.test5 = 20 # Ignored
-- alias.test6 = ["cmd", "arg1"] # Ignored
procedure Execute
(Command_Line : AAA.Strings.Vector := AAA.Strings.Empty_Vector);
-- Parse the command line and execute a sub-command or display help/usage
-- depending on command line args.
--
-- If Command_Line is not empty it will be used instead of the actual
-- command line arguments from Ada.Command_Line.
procedure Parse_Global_Switches
(Command_Line : AAA.Strings.Vector := AAA.Strings.Empty_Vector);
-- Optional. Call this procedure before Execute to get only global switches
-- parsed. This can be useful to check the values of global switches before
-- running a sub-command or change the behavior of your program based on
-- these (e.g. verbosity, output color, etc.).
--
-- If Command_Line is not empty it will be used instead of the actual
-- command line arguments from Ada.Command_Line.
function What_Command return String;
procedure Display_Usage (Displayed_Error : Boolean := False);
procedure Display_Help (Keyword : String);
Error_No_Command : exception;
Command_Already_Defined : exception;
type Builtin_Help is new Command with private;
-- Use Register (new Builtin_Help); to provide a build-in help command
private
-- Built-in Help Command --
type Builtin_Help is new Command with null record;
overriding
function Name (This : Builtin_Help) return Identifier
is ("help");
overriding
function Switch_Parsing (This : Builtin_Help) return Switch_Parsing_Kind
is (Parse_All);
overriding
procedure Execute (This : in out Builtin_Help;
Args : AAA.Strings.Vector);
overriding
function Long_Description (This : Builtin_Help)
return AAA.Strings.Vector
is (AAA.Strings.Empty_Vector
.Append ("Shows information about commands and topics.")
.Append ("See available commands with '" &
Main_Command_Name & " help commands'")
.Append ("See available topics with '" &
Main_Command_Name & " help topics'."));
overriding
procedure Setup_Switches
(This : in out Builtin_Help;
Config : in out CLIC.Subcommand.Switches_Configuration)
is null;
overriding
function Short_Description (This : Builtin_Help) return String
is ("Shows help on the given command/topic");
overriding
function Usage_Custom_Parameters (This : Builtin_Help) return String
is ("[<command>|<topic>]");
end CLIC.Subcommand.Instance;
|
with Numerics, Ada.Text_IO;
use Numerics, Ada.Text_IO;
procedure PE_Landscape is
use Real_IO, Int_IO, Real_Functions;
α : constant Real := 1.0e-2;
R : constant Real := π * 0.7028;
function Phi (R : in Real) return Real is
begin
return 0.5 * (1.0 + Tanh (50.0 * (R - 0.5)));
end Phi;
function PE (Q : in Real_Vector) return Real is
PE_G, PE_M : Real;
T : Real renames Q (1);
S : Real renames Q (2);
R : constant Real := 2.0 * abs (Cos (0.5 * (T + S)));
Cs : constant Real := Cos (S);
Ct : constant Real := Cos (T);
C2tps : constant Real := Cos (2.0 * T + S);
Ctp2s : constant Real := Cos (T + 2.0 * S);
Vo, Vi, Tmp, Ro : Real;
begin
Ro := 0.9;
if R < Ro then return -250.0; end if;
Tmp := 1.0 / R;
PE_G := Ct + 2.0 * C2tps;
Vi := 0.01 * Exp (-12.0 * (R - Ro)) / (R - Ro) ** 2;
Vo := (Tmp ** 3) * Cos (2.0 * (T + S))
- 3.0 * (Tmp ** 5) * ((Ct + C2tps) * (Cs + Ctp2s));
PE_M := Cos (2.0 * T) - 3.0 * Ct ** 2
+ Cos (2.0 * S) - 3.0 * Cs ** 2
+ Vo * Phi (R) + Vi * (1.0 - Phi (R));
return (1.0 * ((α / 6.0) * PE_M - PE_G));
end PE;
function PE2 (Q : in Real_Vector) return Real is
PE_G, PE_M : Real;
T : Real renames Q (1);
S : Real renames Q (2);
R : constant Real := 2.0 * abs (Cos (0.5 * (T + S)));
Cs : constant Real := Cos (S);
Ct : constant Real := Cos (T);
C2tps : constant Real := Cos (2.0 * T + S);
Ctp2s : constant Real := Cos (T + 2.0 * S);
Vo : Real;
begin
PE_G := Ct + 2.0 * C2tps;
Vo := (Cos (2.0 * (T + S)) * R ** 2 - 3.0 * ((Ct + C2tps) * (Cs + Ctp2s)))
/ R ** 5;
PE_M := Cos (2.0 * T) - 3.0 * Ct ** 2 + Cos (2.0 * S) - 3.0 * Cs ** 2 + Vo;
return ((α / 6.0) * PE_M - PE_G);
end PE2;
function Coordinate_Transform (X : in Real_Vector) return Real_Vector is
Y : Real_Vector (1 .. 2);
begin
Y (1) := 0.5 * (3.0 * X (1) + X (2));
Y (2) := 0.5 * (-3.0 * X (1) + X (2));
return Y;
end Coordinate_Transform;
N : constant Nat := 1_000;
Dx : constant Real := 2.0 / Real (N);
X, Y : Real_Vector (1 .. 2);
R13, Tmp : Real;
Max_Diff : Real := 0.0;
begin
for I in 1 .. N loop
X (1) := -1.0 + (Real (I) - 0.5) * Dx;
for J in 1 .. N loop
X (2) := -1.0 + (Real (J) - 0.5) * Dx;
Y := R * Coordinate_Transform (X);
Tmp := abs ((PE (Y) - PE2 (Y)) / PE2 (Y));
R13 := 2.0 * Cos (0.5 * (Y (1) + Y (2)));
if R13 > 1.0 then
if Tmp > Max_Diff then
Max_Diff := Tmp;
Put (Y (1)); Put (", "); Put (Y (2)); New_Line;
Put (" difference = "); Put (Max_Diff); New_Line; New_Line;
end if;
end if;
end loop;
end loop;
end PE_Landscape;
|
with Interfaces.C.Strings;
with System;
package AMPC is
package C renames Interfaces.C;
-- States - mpc_state_t
type States is
record
Position : C.long;
Row : C.long;
Column : C.long;
Term : C.int;
end record with
Convention => C;
type States_Ptr is access States with
Convention => C;
-- Errors - mpc_err_t
type Errors is
record
State : States;
Expected_Num : C.int;
Filename : C.Strings.chars_ptr;
Failure : C.Strings.chars_ptr;
Expected : System.Address;
Recieved : C.char;
end record with
Convention => C;
type Errors_Ptr is access all Errors with
Convention => C;
procedure Put (Error : in Errors_Ptr) with
Import => True,
Convention => C,
External_Name => "mpc_err_print";
procedure Free (Error : in Errors_Ptr) with
Import => True,
Convention => C,
External_Name => "mpc_err_delete";
-- Values - mpc_val_t
type Values is null record with
Convention => C;
type Values_Ptr is access Values;
type Results (Success : Boolean) is
record
case Success is
when False =>
Error : Errors_Ptr;
when True =>
Output : Values_Ptr;
end case;
end record with
Convention => C_Pass_By_Copy,
Unchecked_Union => True;
type Results_Ptr is access all Results with
Convention => C;
-- Parsers - mpc_parser_t
type Parsers is null record with
Convention => C;
type Parsers_Ptr is access Parsers with
Convention => C;
function Parse (Input : in String;
Parser : in Parsers_Ptr;
Result : in Results_Ptr;
Filename : in String := "<stdin>") return Boolean;
function New_Parser (Name : in String) return Parsers_Ptr;
procedure Free (Parser : in Parsers_Ptr);
procedure Free (Parser_1 : in Parsers_Ptr;
Parser_2 : in Parsers_Ptr);
procedure Free (Parser_1 : in Parsers_Ptr;
Parser_2 : in Parsers_Ptr;
Parser_3 : in Parsers_Ptr);
procedure Free (Parser_1 : in Parsers_Ptr;
Parser_2 : in Parsers_Ptr;
Parser_3 : in Parsers_Ptr;
Parser_4 : in Parsers_Ptr);
type Language_Flags is (Default, Predictive, Whitespace_Sensitive) with
Convention => C;
function Language (Flags : in Language_Flags; Grammar : in String; Parser : in Parsers_Ptr) return Errors_Ptr;
function Language (Flags : in Language_Flags;
Grammar : in String;
Parser_1 : in Parsers_Ptr;
Parser_2 : in Parsers_Ptr) return Errors_Ptr;
function Language (Flags : in Language_Flags;
Grammar : in String;
Parser_1 : in Parsers_Ptr;
Parser_2 : in Parsers_Ptr;
Parser_3 : in Parsers_Ptr) return Errors_Ptr;
function Language (Flags : in Language_Flags;
Grammar : in String;
Parser_1 : in Parsers_Ptr;
Parser_2 : in Parsers_Ptr;
Parser_3 : in Parsers_Ptr;
Parser_4 : in Parsers_Ptr) return Errors_Ptr;
function Language (Flags : in Language_Flags;
Grammar : in String;
Parser_1 : in Parsers_Ptr;
Parser_2 : in Parsers_Ptr;
Parser_3 : in Parsers_Ptr;
Parser_4 : in Parsers_Ptr;
Parser_5 : in Parsers_Ptr) return Errors_Ptr;
-- AST - mpc_ast_t
type ASTs is null record with
Convention => C;
type AST_Ptr is access ASTs with
Convention => C;
procedure Put (AST : in AST_Ptr) with
Import => True,
Convention => C,
External_Name => "mpc_ast_print";
procedure Free (AST : in AST_Ptr) with
Import => True,
Convention => C,
External_Name => "mpc_ast_delete";
end AMPC;
|
package body Tkmrpc.Contexts.dh
is
pragma Warnings
(Off, "* already use-visible through previous use type clause");
use type Types.dh_id_type;
use type Types.dha_id_type;
use type Types.rel_time_type;
use type Types.dh_priv_type;
use type Types.dh_key_type;
pragma Warnings
(On, "* already use-visible through previous use type clause");
type dh_FSM_Type is record
State : dh_State_Type;
dha_id : Types.dha_id_type;
creation_time : Types.rel_time_type;
priv : Types.dh_priv_type;
key : Types.dh_key_type;
end record;
-- Diffie-Hellman Context
Null_dh_FSM : constant dh_FSM_Type
:= dh_FSM_Type'
(State => clean,
dha_id => Types.dha_id_type'First,
creation_time => Types.rel_time_type'First,
priv => Types.Null_dh_priv_type,
key => Types.Null_dh_key_type);
type Context_Array_Type is
array (Types.dh_id_type) of dh_FSM_Type;
Context_Array : Context_Array_Type := Context_Array_Type'
(others => (Null_dh_FSM));
-------------------------------------------------------------------------
function Get_State
(Id : Types.dh_id_type)
return dh_State_Type
is
begin
return Context_Array (Id).State;
end Get_State;
-------------------------------------------------------------------------
function Has_creation_time
(Id : Types.dh_id_type;
creation_time : Types.rel_time_type)
return Boolean
is (Context_Array (Id).creation_time = creation_time);
-------------------------------------------------------------------------
function Has_dha_id
(Id : Types.dh_id_type;
dha_id : Types.dha_id_type)
return Boolean
is (Context_Array (Id).dha_id = dha_id);
-------------------------------------------------------------------------
function Has_key
(Id : Types.dh_id_type;
key : Types.dh_key_type)
return Boolean
is (Context_Array (Id).key = key);
-------------------------------------------------------------------------
function Has_priv
(Id : Types.dh_id_type;
priv : Types.dh_priv_type)
return Boolean
is (Context_Array (Id).priv = priv);
-------------------------------------------------------------------------
function Has_State
(Id : Types.dh_id_type;
State : dh_State_Type)
return Boolean
is (Context_Array (Id).State = State);
-------------------------------------------------------------------------
pragma Warnings
(Off, "condition can only be False if invalid values present");
function Is_Valid (Id : Types.dh_id_type) return Boolean
is (Context_Array'First <= Id and Id <= Context_Array'Last);
pragma Warnings
(On, "condition can only be False if invalid values present");
-------------------------------------------------------------------------
procedure consume
(Id : Types.dh_id_type;
dh_key : out Types.dh_key_type)
is
begin
dh_key := Context_Array (Id).key;
Context_Array (Id).dha_id := Types.dha_id_type'First;
Context_Array (Id).creation_time := Types.rel_time_type'First;
Context_Array (Id).priv := Types.Null_dh_priv_type;
Context_Array (Id).key := Types.Null_dh_key_type;
Context_Array (Id).State := clean;
end consume;
-------------------------------------------------------------------------
procedure create
(Id : Types.dh_id_type;
dha_id : Types.dha_id_type;
secvalue : Types.dh_priv_type)
is
begin
Context_Array (Id).dha_id := dha_id;
Context_Array (Id).priv := secvalue;
Context_Array (Id).State := created;
end create;
-------------------------------------------------------------------------
procedure generate
(Id : Types.dh_id_type;
dh_key : Types.dh_key_type;
timestamp : Types.rel_time_type)
is
begin
Context_Array (Id).key := dh_key;
Context_Array (Id).creation_time := timestamp;
Context_Array (Id).priv := Types.Null_dh_priv_type;
Context_Array (Id).State := generated;
end generate;
-------------------------------------------------------------------------
function get_dha_id
(Id : Types.dh_id_type)
return Types.dha_id_type
is
begin
return Context_Array (Id).dha_id;
end get_dha_id;
-------------------------------------------------------------------------
function get_secvalue
(Id : Types.dh_id_type)
return Types.dh_priv_type
is
begin
return Context_Array (Id).priv;
end get_secvalue;
-------------------------------------------------------------------------
procedure invalidate
(Id : Types.dh_id_type)
is
begin
Context_Array (Id).State := invalid;
end invalidate;
-------------------------------------------------------------------------
procedure reset
(Id : Types.dh_id_type)
is
begin
Context_Array (Id).dha_id := Types.dha_id_type'First;
Context_Array (Id).creation_time := Types.rel_time_type'First;
Context_Array (Id).priv := Types.Null_dh_priv_type;
Context_Array (Id).key := Types.Null_dh_key_type;
Context_Array (Id).State := clean;
end reset;
end Tkmrpc.Contexts.dh;
|
--
-- Copyright (C) 2015 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;
with HW.Time;
with HW.Debug_Sink;
use type HW.Word64;
use type HW.Int64;
package body HW.Debug
with
SPARK_Mode => Off
is
Start_Of_Line : Boolean := True;
Register_Write_Delay_Nanoseconds : Word64 := 0;
type Base_Range is new Positive range 2 .. 16;
type Width_Range is new Natural range 0 .. 64;
procedure Put_By_Base
(Item : Word64;
Min_Width : Width_Range;
Base : Base_Range);
procedure Do_Put_Int64
(Item : Int64);
----------------------------------------------------------------------------
procedure Put_Time
is
Now_US : Int64;
begin
if Start_Of_Line then
Start_Of_Line := False;
Now_US := Time.Now_US;
Debug_Sink.Put_Char ('[');
Do_Put_Int64 ((Now_US / 1_000_000) mod 1_000_000);
Debug_Sink.Put_Char ('.');
Put_By_Base (Word64 (Now_US mod 1_000_000), 6, 10);
Debug_Sink.Put ("] ");
end if;
end Put_Time;
----------------------------------------------------------------------------
procedure Put (Item : String) is
begin
Put_Time;
HW.Debug_Sink.Put (Item);
end Put;
procedure Put_Line (Item : String) is
begin
Put (Item);
New_Line;
end Put_Line;
procedure New_Line is
begin
HW.Debug_Sink.New_Line;
Start_Of_Line := True;
end New_Line;
----------------------------------------------------------------------------
procedure Put_By_Base
(Item : Word64;
Min_Width : Width_Range;
Base : Base_Range)
is
Temp : Word64 := Item;
subtype Chars_Range is Width_Range range 0 .. 63;
Index : Width_Range := 0;
type Chars_Array is array (Chars_Range) of Character;
Chars : Chars_Array := (others => '0');
Digit : Natural;
begin
while Temp > 0 loop
Digit := Natural (Temp rem Word64 (Base));
if Digit < 10 then
Chars (Index) := Character'Val (Character'Pos ('0') + Digit);
else
Chars (Index) := Character'Val (Character'Pos ('a') + Digit - 10);
end if;
Temp := Temp / Word64 (Base);
Index := Index + 1;
end loop;
if Index < Min_Width then
Index := Min_Width;
end if;
for I in reverse Width_Range range 0 .. Index - 1 loop
HW.Debug_Sink.Put_Char (Chars (I));
end loop;
end Put_By_Base;
----------------------------------------------------------------------------
procedure Put_Word
(Item : Word64;
Min_Width : Width_Range;
Print_Ox : Boolean := True) is
begin
Put_Time;
if Print_Ox then
Put ("0x");
end if;
Put_By_Base (Item, Min_Width, 16);
end Put_Word;
procedure Put_Word8 (Item : Word8) is
begin
Put_Word (Word64 (Item), 2);
end Put_Word8;
procedure Put_Word16 (Item : Word16) is
begin
Put_Word (Word64 (Item), 4);
end Put_Word16;
procedure Put_Word32 (Item : Word32) is
begin
Put_Word (Word64 (Item), 8);
end Put_Word32;
procedure Put_Word64 (Item : Word64) is
begin
Put_Word (Item, 16);
end Put_Word64;
----------------------------------------------------------------------------
procedure Do_Put_Int64 (Item : Int64)
is
Temp : Word64;
begin
if Item < 0 then
Debug_Sink.Put_Char ('-');
Temp := Word64 (-Item);
else
Temp := Word64 (Item);
end if;
Put_By_Base (Temp, 1, 10);
end Do_Put_Int64;
procedure Put_Int64 (Item : Int64)
is
begin
Put_Time;
Do_Put_Int64 (Item);
end Put_Int64;
procedure Put_Int8 (Item : Int8) is
begin
Put_Int64 (Int64 (Item));
end Put_Int8;
procedure Put_Int16 (Item : Int16) is
begin
Put_Int64 (Int64 (Item));
end Put_Int16;
procedure Put_Int32 (Item : Int32) is
begin
Put_Int64 (Int64 (Item));
end Put_Int32;
----------------------------------------------------------------------------
procedure Put_Reg8 (Name : String; Item : Word8) is
begin
Put (Name);
Put (": ");
Put_Word8 (Item);
New_Line;
end Put_Reg8;
procedure Put_Reg16 (Name : String; Item : Word16)
is
begin
Put (Name);
Put (": ");
Put_Word16 (Item);
New_Line;
end Put_Reg16;
procedure Put_Reg32 (Name : String; Item : Word32)
is
begin
Put (Name);
Put (": ");
Put_Word32 (Item);
New_Line;
end Put_Reg32;
procedure Put_Reg64 (Name : String; Item : Word64)
is
begin
Put (Name);
Put (": ");
Put_Word64 (Item);
New_Line;
end Put_Reg64;
----------------------------------------------------------------------------
procedure Put_Buffer
(Name : String;
Buf : Buffer;
Len : Buffer_Range)
is
Line_Start, Left : Natural;
begin
if Len = 0 then
if Name'Length > 0 then
Put (Name);
Put_Line ("+0x00:");
end if;
else
Line_Start := 0;
Left := Len - 1;
for I in Natural range 1 .. ((Len + 15) / 16) loop
if Name'Length > 0 then
Put (Name);
Debug_Sink.Put_Char ('+');
Put_Word16 (Word16 (Line_Start));
Put (": ");
end if;
for J in Natural range 0 .. Natural'Min (7, Left)
loop
Put_Word (Word64 (Buf (Line_Start + J)), 2, False);
Debug_Sink.Put_Char (' ');
end loop;
Debug_Sink.Put_Char (' ');
for J in Natural range 8 .. Natural'Min (15, Left)
loop
Put_Word (Word64(Buf (Line_Start + J)), 2, False);
Debug_Sink.Put_Char (' ');
end loop;
New_Line;
Line_Start := Line_Start + 16;
Left := Left - Natural'Min (Left, 16);
end loop;
end if;
end Put_Buffer;
----------------------------------------------------------------------------
procedure Set_Register_Write_Delay (Value : Word64)
is
begin
Register_Write_Delay_Nanoseconds := Value;
end Set_Register_Write_Delay;
----------------------------------------------------------------------------
Procedure Register_Write_Wait
is
begin
if Register_Write_Delay_Nanoseconds > 0 then
Time.U_Delay (Natural ((Register_Write_Delay_Nanoseconds + 999) / 1000));
end if;
end Register_Write_Wait;
end HW.Debug;
-- vim: set ts=8 sts=3 sw=3 et:
|
with Ada.Exception_Identification.From_Here;
with Ada.Exceptions.Finally;
with Ada.Unchecked_Conversion;
with System.Address_To_Named_Access_Conversions;
with System.Storage_Map;
with System.System_Allocators;
with System.Zero_Terminated_WStrings;
with C.string;
with C.winternl;
package body System.Native_IO.Names is
use Ada.Exception_Identification.From_Here;
use type Storage_Elements.Storage_Offset;
use type C.char_array;
use type C.size_t;
use type C.winternl.NTSTATUS;
use type C.winnt.LPWSTR; -- Name_Pointer
use type C.winnt.WCHAR; -- Name_Character
use type C.winnt.WCHAR_array; -- Name_String
package Name_Pointer_Conv is
new Address_To_Named_Access_Conversions (
Name_Character,
Name_Pointer);
package POBJECT_NAME_INFORMATION_Conv is
new Address_To_Named_Access_Conversions (
C.winternl.struct_OBJECT_NAME_INFORMATION,
C.winternl.POBJECT_NAME_INFORMATION);
function "+" (Left : Name_Pointer; Right : C.ptrdiff_t)
return Name_Pointer
with Convention => Intrinsic;
pragma Inline_Always ("+");
function "+" (Left : Name_Pointer; Right : C.ptrdiff_t)
return Name_Pointer is
begin
return Name_Pointer_Conv.To_Pointer (
Name_Pointer_Conv.To_Address (Left)
+ Storage_Elements.Storage_Offset (Right)
* (Name_Character'Size / Standard'Storage_Unit));
end "+";
type NtQueryObject_Type is access function (
Handle : C.winnt.HANDLE;
ObjectInformationClass : C.winternl.OBJECT_INFORMATION_CLASS;
ObjectInformation : C.winnt.PVOID;
ObjectInformationLength : C.windef.ULONG;
ReturnLength : access C.windef.ULONG)
return C.winternl.NTSTATUS
with Convention => WINAPI;
NtQueryObject_Name : constant C.char_array (0 .. 13) :=
"NtQueryObject" & C.char'Val (0);
function To_NtQueryObject_Type is
new Ada.Unchecked_Conversion (C.windef.FARPROC, NtQueryObject_Type);
-- implementation
procedure Open_Ordinary (
Method : Open_Method;
Handle : aliased out Handle_Type;
Mode : File_Mode;
Name : String;
Out_Name : aliased out Name_Pointer;
Form : Packed_Form)
is
C_Name : aliased Name_String (
0 .. Name'Length * Zero_Terminated_WStrings.Expanding);
begin
Zero_Terminated_WStrings.To_C (Name, C_Name (0)'Access);
Open_Ordinary (Method, Handle, Mode, C_Name (0)'Unchecked_Access, Form);
Out_Name := null;
end Open_Ordinary;
procedure Get_Full_Name (
Handle : Handle_Type;
Has_Full_Name : in out Boolean;
Name : in out Name_Pointer;
Is_Standard : Boolean;
Raise_On_Error : Boolean)
is
procedure Finally (X : in out C.winnt.PVOID);
procedure Finally (X : in out C.winnt.PVOID) is
begin
System_Allocators.Free (Address (X));
end Finally;
package Holder is
new Ada.Exceptions.Finally.Scoped_Holder (C.winnt.PVOID, Finally);
NtQueryObject : constant NtQueryObject_Type :=
To_NtQueryObject_Type (
C.winbase.GetProcAddress (
Storage_Map.NTDLL,
NtQueryObject_Name (0)'Access));
Info : aliased C.winnt.PVOID := C.void_ptr (Null_Address);
ReturnLength : aliased C.windef.ULONG;
Unicode_Name : C.winternl.PUNICODE_STRING;
New_Name : Name_Pointer;
Drives : aliased Name_String (0 .. 3 * 26); -- (A to Z) * "X:\"
Drive : Name_String (0 .. 2); -- "X:"
New_Name_Length : C.size_t;
Relative_Index : C.size_t;
Skip_Length : C.size_t;
begin
if NtQueryObject = null then
-- Failed, keep Has_Full_Name and Name.
if Raise_On_Error then
raise Program_Error; -- ??
end if;
return; -- error
end if;
-- Get ObjectNameInformation.
Holder.Assign (Info);
Info := C.winnt.PVOID (System_Allocators.Allocate (4096));
if Address (Info) = Null_Address then
-- Failed, keep Has_Full_Name and Name.
if Raise_On_Error then
raise Storage_Error;
end if;
return; -- error
end if;
if NtQueryObject (
Handle,
C.winternl.ObjectNameInformation,
Info,
4096,
ReturnLength'Access) /= 0 -- STATUS_SUCCESS
then
declare
New_Info : constant C.winnt.PVOID :=
C.winnt.PVOID (
System_Allocators.Reallocate (
Address (Info),
Storage_Elements.Storage_Offset (ReturnLength)));
begin
if Address (New_Info) = Null_Address then
-- Failed, keep Has_Full_Name and Name.
if Raise_On_Error then
raise Storage_Error;
end if;
return; -- error
end if;
Info := New_Info;
end;
if NtQueryObject (
Handle,
C.winternl.ObjectNameInformation,
Info,
ReturnLength,
null) /= 0 -- STATUS_SUCCESS
then
-- Failed, keep Has_Full_Name and Name.
if Raise_On_Error then
Raise_Exception (Use_Error'Identity);
end if;
return; -- error
end if;
end if;
Unicode_Name :=
POBJECT_NAME_INFORMATION_Conv.To_Pointer (Address (Info)).Name'Access;
-- To DOS name.
if C.winbase.GetLogicalDriveStrings (Drives'Length, Drives (0)'Access) >=
Drives'Length
then
-- Failed, keep Has_Full_Name and Name.
if Raise_On_Error then
Raise_Exception (Use_Error'Identity);
end if;
return; -- error
end if;
Drive (1) := Name_Character'Val (Character'Pos (':'));
Drive (2) := Name_Character'Val (0);
Skip_Length := 0;
Relative_Index := 0;
New_Name_Length := C.size_t (Unicode_Name.Length);
declare
Unicode_Name_All : Name_String (
0 .. C.size_t (Unicode_Name.Length) - 1);
for Unicode_Name_All'Address use
Name_Pointer_Conv.To_Address (Unicode_Name.Buffer);
P : Name_Pointer := Drives (0)'Unchecked_Access;
begin
while P.all /= Name_Character'Val (0) loop
declare
Length : constant C.size_t := C.string.wcslen (P);
Long_Name : aliased Name_String (0 .. C.windef.MAX_PATH - 1);
begin
if Length > 0 then
Drive (0) := P.all; -- drop trailing '\'
if C.winbase.QueryDosDevice (
Drive (0)'Access,
Long_Name (0)'Access,
C.windef.MAX_PATH) /= 0
then
declare
Long_Name_Length : C.size_t := 0;
begin
while Long_Name (Long_Name_Length) /=
Name_Character'Val (0)
loop
if Long_Name (Long_Name_Length) =
Name_Character'Val (Character'Pos (';'))
then
-- Skip ";X:\" (Is it a bug of VirtualBox?)
Long_Name (
Long_Name_Length .. Long_Name'Last - 4) :=
Long_Name (
Long_Name_Length + 4 .. Long_Name'Last);
end if;
Long_Name_Length := Long_Name_Length + 1;
end loop;
if Long_Name (0 .. Long_Name_Length - 1) =
Unicode_Name_All (0 .. Long_Name_Length - 1)
and then Unicode_Name_All (Long_Name_Length) =
Name_Character'Val (Character'Pos ('\'))
then
Skip_Length := Long_Name_Length;
Relative_Index := 2;
New_Name_Length :=
New_Name_Length - Skip_Length + 2;
exit;
end if;
end;
end if;
end if;
P := P + C.ptrdiff_t (Length);
end;
P := P + 1; -- skip NUL
end loop;
if Relative_Index = 0
and then Unicode_Name_All (1) /=
Name_Character'Val (Character'Pos (':'))
and then (
Unicode_Name_All (0) /= Name_Character'Val (Character'Pos ('\'))
or else Unicode_Name_All (1) /=
Name_Character'Val (Character'Pos ('\')))
then
-- For example, a pipe's name is like "pipe:[N]".
Drive (0) := Name_Character'Val (Character'Pos ('*'));
Relative_Index := 1;
New_Name_Length := New_Name_Length + 1;
end if;
end;
-- Copy a name.
New_Name :=
Name_Pointer_Conv.To_Pointer (
System_Allocators.Allocate (
(Storage_Elements.Storage_Offset (New_Name_Length) + 1)
* (Name_Character'Size / Standard'Storage_Unit)));
if New_Name = null then
-- Failed, keep Has_Full_Name and Name.
if Raise_On_Error then
raise Storage_Error;
end if;
return; -- error
end if;
declare
Unicode_Name_All : Name_String (
0 .. C.size_t (Unicode_Name.Length) - 1);
for Unicode_Name_All'Address use
Name_Pointer_Conv.To_Address (Unicode_Name.Buffer);
New_Name_All : Name_String (0 .. New_Name_Length); -- NUL
for New_Name_All'Address use Name_Pointer_Conv.To_Address (New_Name);
begin
if Relative_Index > 0 then
New_Name_All (0 .. Relative_Index - 1) :=
Drive (0 .. Relative_Index - 1);
end if;
New_Name_All (Relative_Index .. New_Name_Length - 1) :=
Unicode_Name_All (
Skip_Length .. C.size_t (Unicode_Name.Length) - 1);
New_Name_All (New_Name_Length) := Name_Character'Val (0);
end;
-- Succeeded.
if not Is_Standard then
Free (Name); -- External or External_No_Close
end if;
Name := New_Name;
Has_Full_Name := True;
end Get_Full_Name;
end System.Native_IO.Names;
|
--
-- The author disclaims copyright to this source code. In place of
-- a legal notice, here is a blessing:
--
-- May you do good and not evil.
-- May you find forgiveness for yourself and forgive others.
-- May you share freely, not taking more than you give.
--
with Rules;
with Rule_Lists;
with Symbol_Sets;
with Prop_Links;
limited with States;
package Configs is
-- A configuration is a production rule of the grammar together with
-- a mark (dot) showing how much of that rule has been processed so far.
-- Configurations also contain a follow-set which is a list of terminal
-- symbols which are allowed to immediately follow the end of the rule.
-- Every configuration is recorded as an instance of the following:
type Config_Status is (Complete, Incomplete);
type Config_Record;
type Config_Access is access all Config_Record;
type Config_Record is
record
Rule : Rule_Lists.Rule_Access;
-- The rule upon which the configuration is based
Dot : Rules.Dot_Type;
-- The parse point
Follow_Set : Symbol_Sets.Set_Type;
-- Follow-set for this configuration only
Forward_PL : Prop_Links.List;
-- Forward propagation links
Backward_PL : Prop_Links.List;
-- Follow-set backwards propagation links
State : access States.State_Record;
-- Pointer to state which contains this
Status : Config_Status;
-- Used during followset and shift computations
Next : Config_Access;
-- Next configuration in the state
Basis : Config_Access;
-- The next basis configuration
end record;
function "<" (Left, Right : in Config_Record) return Boolean;
function "<" (Left, Right : in Config_Access) return Boolean;
end Configs;
|
separate (Numerics.Sparse_Matrices)
function Triplet_To_Matrix (I : in Int_Array;
J : in Int_Array;
X : in Real_Vector;
N_Row : in Pos := 0;
N_Col : in Pos := 0;
Format : in Sparse_Matrix_Format := CSC) return Sparse_Matrix is
Result : Sparse_Matrix;
begin
Result.N_Row := Pos'Max (N_Row, Max (I));
Result.N_Col := Pos'Max (N_Col, Max (J));
Result.Format := Triplet;
Set (X => Result.I, To => I);
Set (X => Result.P, To => J);
Set (X => Result.X, To => X);
case Format is
when CSC => Compress (Result);
when Triplet => null;
when CSR =>
Compress (Result);
Convert (Result);
end case;
return Result;
end Triplet_To_Matrix;
|
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr>
-- MIT license. Please refer to the LICENSE file.
private with Ada.Finalization;
package Apsepp.Scope_Bound_Locks is
type SB_Lock_CB is access procedure;
generic
SBLCB_Access : SB_Lock_CB;
procedure SB_Lock_CB_procedure;
type SB_Lock (Lock_CB, Unlock_CB : SB_Lock_CB := null) is limited private;
type SB_Lock_Access is not null access all SB_Lock;
function Locked (Lock : SB_Lock) return Boolean;
type SB_L_Locker (Lock : SB_Lock_Access) is tagged limited private
with Type_Invariant'Class => Locked (Lock.all);
not overriding
function Has_Actually_Locked (Obj : SB_L_Locker) return Boolean;
private
type SB_Lock (Lock_CB, Unlock_CB : SB_Lock_CB := null) is limited record
Is_Locked : Boolean := False;
end record;
type SB_L_Locker (Lock : SB_Lock_Access)
is limited new Ada.Finalization.Limited_Controlled with record
Is_Instantiated : Boolean := False;
Has_Locked : Boolean := False;
end record;
overriding
procedure Initialize (Obj : in out SB_L_Locker);
overriding
procedure Finalize (Obj : in out SB_L_Locker);
end Apsepp.Scope_Bound_Locks;
|
-- ___ _ ___ _ _ --
-- / __| |/ (_) | | Common SKilL implementation --
-- \__ \ ' <| | | |__ file partitioning info --
-- |___/_|\_\_|_|____| by: Timm Felden --
-- --
pragma Ada_2012;
with Ada.Containers.Vectors;
with Skill.Types;
with Skill.Containers.Vectors;
with Ada.Unchecked_Deallocation;
with Ada.Unchecked_Conversion;
-- documentation can be found in java common
package body Skill.Internal.Parts is
function To_Simple (This : access Chunk_T'Class) return Simple_Chunk_X is
type P is access all Chunk_T'Class;
function Cast is new Ada.Unchecked_Conversion (P, Simple_Chunk_X);
begin
return Cast (This);
end To_Simple;
function To_Bulk (This : access Chunk_T'Class) return Bulk_Chunk_X is
type P is access all Chunk_T'Class;
function Cast is new Ada.Unchecked_Conversion (P, Bulk_Chunk_X);
begin
return Cast (This);
end To_Bulk;
procedure Free (This : access Simple_Chunk) is
type T is access all Simple_Chunk;
procedure Delete is new Ada.Unchecked_Deallocation (Simple_Chunk, T);
D : T := T (This);
begin
Delete (D);
end Free;
procedure Free (This : access Bulk_Chunk) is
type T is access all Bulk_Chunk;
procedure Delete is new Ada.Unchecked_Deallocation (Bulk_Chunk, T);
D : T := T (This);
begin
Delete (D);
end Free;
end Skill.Internal.Parts;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . I M G _ U T I L --
-- --
-- B o d y --
-- --
-- Copyright (C) 2020-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. --
-- --
------------------------------------------------------------------------------
with System.Img_Uns; use System.Img_Uns;
package body System.Img_Util is
------------------------
-- Set_Decimal_Digits --
------------------------
procedure Set_Decimal_Digits
(Digs : in out String;
NDigs : Natural;
S : out String;
P : in out Natural;
Scale : Integer;
Fore : Natural;
Aft : Natural;
Exp : Natural)
is
pragma Assert (NDigs >= 1);
pragma Assert (Digs'First = 1);
pragma Assert (Digs'First < Digs'Last);
Minus : constant Boolean := (Digs (Digs'First) = '-');
-- Set True if input is negative
Zero : Boolean := (Digs (Digs'First + 1) = '0');
-- Set True if input is exactly zero (only case when a leading zero
-- is permitted in the input string given to this procedure). This
-- flag can get set later if rounding causes the value to become zero.
FD : Natural := 2;
-- First digit position of digits remaining to be processed
LD : Natural := NDigs;
-- Last digit position of digits remaining to be processed
ND : Natural := NDigs - 1;
-- Number of digits remaining to be processed (LD - FD + 1)
Digits_Before_Point : Integer := ND - Scale;
-- Number of digits before decimal point in the input value. This
-- value can be negative if the input value is less than 0.1, so
-- it is an indication of the current exponent. Digits_Before_Point
-- is adjusted if the rounding step generates an extra digit.
Digits_After_Point : constant Natural := Integer'Max (1, Aft);
-- Digit positions after decimal point in result string
Expon : Integer;
-- Integer value of exponent
procedure Round (N : Integer);
-- Round the number in Digs. N is the position of the last digit to be
-- retained in the rounded position (rounding is based on Digs (N + 1)
-- FD, LD, ND are reset as necessary if required. Note that if the
-- result value rounds up (e.g. 9.99 => 10.0), an extra digit can be
-- placed in the sign position as a result of the rounding, this is
-- the case in which FD is adjusted. The call to Round has no effect
-- if N is outside the range FD .. LD.
procedure Set (C : Character);
pragma Inline (Set);
-- Sets character C in output buffer
procedure Set_Blanks_And_Sign (N : Integer);
-- Sets leading blanks and minus sign if needed. N is the number of
-- positions to be filled (a minus sign is output even if N is zero
-- or negative, but for a positive value, if N is non-positive, then
-- the call has no effect).
procedure Set_Digits (S, E : Natural);
pragma Inline (Set_Digits);
-- Set digits S through E from Digs, no effect if S > E
procedure Set_Zeroes (N : Integer);
pragma Inline (Set_Zeroes);
-- Set N zeroes, no effect if N is negative
-----------
-- Round --
-----------
procedure Round (N : Integer) is
D : Character;
pragma Assert (NDigs >= 1);
pragma Assert (Digs'First = 1);
pragma Assert (Digs'First < Digs'Last);
begin
-- Nothing to do if rounding past the last digit we have
if N >= LD then
return;
-- Cases of rounding before the initial digit
elsif N < FD then
-- The result is zero, unless we are rounding just before
-- the first digit, and the first digit is five or more.
if N = 1 and then Digs (Digs'First + 1) >= '5' then
Digs (Digs'First) := '1';
else
Digs (Digs'First) := '0';
Zero := True;
end if;
Digits_Before_Point := Digits_Before_Point + 1;
FD := 1;
LD := 1;
ND := 1;
-- Normal case of rounding an existing digit
else
LD := N;
pragma Assert (LD >= 1);
-- In this case, we have N < LD and N >= FD. FD is a Natural,
-- So we can conclude, LD >= 1
ND := LD - 1;
pragma Assert (N + 1 <= Digs'Last);
if Digs (N + 1) >= '5' then
for J in reverse Digs'First + 1 .. Digs'First + N - 1 loop
pragma Assert (Digs (J) in '0' .. '9' | ' ' | '-');
-- Because it is a decimal image, we can assume that
-- it can only contain these characters.
D := Character'Succ (Digs (J));
if D <= '9' then
Digs (J) := D;
return;
else
Digs (J) := '0';
end if;
end loop;
-- Here the rounding overflows into the sign position. That's
-- OK, because we already captured the value of the sign and
-- we are in any case destroying the value in the Digs buffer
Digs (Digs'First) := '1';
FD := 1;
ND := ND + 1;
Digits_Before_Point := Digits_Before_Point + 1;
end if;
end if;
end Round;
---------
-- Set --
---------
procedure Set (C : Character) is
begin
pragma Assert (P >= (S'First - 1) and P < S'Last and
P < Natural'Last);
-- No check is done as documented in the header : updating P to
-- point to the last character stored, the caller promises that the
-- buffer is large enough and no check is made for this.
-- Constraint_Error will not necessarily be raised if this
-- requirement is violated, since it is perfectly valid to compile
-- this unit with checks off.
P := P + 1;
S (P) := C;
end Set;
-------------------------
-- Set_Blanks_And_Sign --
-------------------------
procedure Set_Blanks_And_Sign (N : Integer) is
begin
if Minus then
for J in 1 .. N - 1 loop
Set (' ');
end loop;
Set ('-');
else
for J in 1 .. N loop
Set (' ');
end loop;
end if;
end Set_Blanks_And_Sign;
----------------
-- Set_Digits --
----------------
procedure Set_Digits (S, E : Natural) is
begin
pragma Assert (S >= Digs'First and E <= Digs'Last);
-- S and E should be in the Digs array range
-- TBC: Analysis should be completed
for J in S .. E loop
Set (Digs (J));
end loop;
end Set_Digits;
----------------
-- Set_Zeroes --
----------------
procedure Set_Zeroes (N : Integer) is
begin
for J in 1 .. N loop
Set ('0');
end loop;
end Set_Zeroes;
-- Start of processing for Set_Decimal_Digits
begin
-- Case of exponent given
if Exp > 0 then
Set_Blanks_And_Sign (Fore - 1);
Round (Digits_After_Point + 2);
Set (Digs (FD));
FD := FD + 1;
pragma Assert (ND >= 1);
ND := ND - 1;
Set ('.');
if ND >= Digits_After_Point then
Set_Digits (FD, FD + Digits_After_Point - 1);
else
Set_Digits (FD, LD);
Set_Zeroes (Digits_After_Point - ND);
end if;
-- Calculate exponent. The number of digits before the decimal point
-- in the input is Digits_Before_Point, and the number of digits
-- before the decimal point in the output is 1, so we can get the
-- exponent as the difference between these two values. The one
-- exception is for the value zero, which by convention has an
-- exponent of +0.
Expon := (if Zero then 0 else Digits_Before_Point - 1);
Set ('E');
ND := 0;
if Expon >= 0 then
Set ('+');
Set_Image_Unsigned (Unsigned (Expon), Digs, ND);
else
Set ('-');
Set_Image_Unsigned (Unsigned (-Expon), Digs, ND);
end if;
Set_Zeroes (Exp - ND - 1);
Set_Digits (1, ND);
return;
-- Case of no exponent given. To make these cases clear, we use
-- examples. For all the examples, we assume Fore = 2, Aft = 3.
-- A P in the example input string is an implied zero position,
-- not included in the input string.
else
-- Round at correct position
-- Input: 4PP => unchanged
-- Input: 400.03 => unchanged
-- Input 3.4567 => 3.457
-- Input: 9.9999 => 10.000
-- Input: 0.PPP5 => 0.001
-- Input: 0.PPP4 => 0
-- Input: 0.00003 => 0
Round (LD - (Scale - Digits_After_Point));
-- No digits before point in input
-- Input: .123 Output: 0.123
-- Input: .PP3 Output: 0.003
if Digits_Before_Point <= 0 then
Set_Blanks_And_Sign (Fore - 1);
Set ('0');
Set ('.');
declare
DA : Natural := Digits_After_Point;
-- Digits remaining to output after point
LZ : constant Integer := Integer'Min (DA, -Digits_Before_Point);
-- Number of leading zeroes after point. Note: there used to be
-- a Max of this result with zero, but that's redundant, since
-- we know DA is positive, and because of the test above, we
-- know that -Digits_Before_Point >= 0.
begin
Set_Zeroes (LZ);
DA := DA - LZ;
if DA < ND then
-- Note: it is definitely possible for the above condition
-- to be True, for example:
-- V => 1234, Scale => 5, Fore => 0, After => 1, Exp => 0
-- but in this case DA = 0, ND = 1, FD = 1, FD + DA-1 = 0
-- so the arguments in the call are (1, 0) meaning that no
-- digits are output.
-- No obvious example exists where the following call to
-- Set_Digits actually outputs some digits, but we lack a
-- proof that no such example exists.
-- So it is safer to retain this call, even though as a
-- result it is hard (or perhaps impossible) to create a
-- coverage test for the inlined code of the call.
Set_Digits (FD, FD + DA - 1);
else
Set_Digits (FD, LD);
Set_Zeroes (DA - ND);
end if;
end;
-- At least one digit before point in input
else
-- Less digits in input than are needed before point
-- Input: 1PP Output: 100.000
if ND < Digits_Before_Point then
-- Special case, if the input is the single digit 0, then we
-- do not want 000.000, but instead 0.000.
if ND = 1 and then Digs (FD) = '0' then
Set_Blanks_And_Sign (Fore - 1);
Set ('0');
-- Normal case where we need to output scaling zeroes
else
Set_Blanks_And_Sign (Fore - Digits_Before_Point);
Set_Digits (FD, LD);
Set_Zeroes (Digits_Before_Point - ND);
end if;
-- Set period and zeroes after the period
Set ('.');
Set_Zeroes (Digits_After_Point);
-- Input has full amount of digits before decimal point
else
Set_Blanks_And_Sign (Fore - Digits_Before_Point);
pragma Assert (FD + Digits_Before_Point - 1 >= 0);
-- In this branch, we have Digits_Before_Point > 0. It is the
-- else of test (Digits_Before_Point <= 0)
Set_Digits (FD, FD + Digits_Before_Point - 1);
Set ('.');
Set_Digits (FD + Digits_Before_Point, LD);
Set_Zeroes (Digits_After_Point - (ND - Digits_Before_Point));
end if;
end if;
end if;
end Set_Decimal_Digits;
--------------------------------
-- Set_Floating_Invalid_Value --
--------------------------------
procedure Set_Floating_Invalid_Value
(V : Floating_Invalid_Value;
S : out String;
P : in out Natural;
Fore : Natural;
Aft : Natural;
Exp : Natural)
is
procedure Set (C : Character);
-- Sets character C in output buffer
procedure Set_Special_Fill (N : Natural);
-- After outputting +Inf, -Inf or NaN, this routine fills out the
-- rest of the field with * characters. The argument is the number
-- of characters output so far (either 3 or 4)
---------
-- Set --
---------
procedure Set (C : Character) is
begin
pragma Assert (P in S'First - 1 .. S'Last - 1);
-- No check is done as documented in the header: updating P to point
-- to the last character stored, the caller promises that the buffer
-- is large enough and no check is made for this. Constraint_Error
-- will not necessarily be raised if this requirement is violated,
-- since it is perfectly valid to compile this unit with checks off.
P := P + 1;
S (P) := C;
end Set;
----------------------
-- Set_Special_Fill --
----------------------
procedure Set_Special_Fill (N : Natural) is
begin
if Exp /= 0 then
for J in N + 1 .. Fore + 1 + Aft + 1 + Exp loop
Set ('*');
end loop;
else
for J in N + 1 .. Fore + 1 + Aft loop
Set ('*');
end loop;
end if;
end Set_Special_Fill;
-- Start of processing for Set_Floating_Invalid_Value
begin
case V is
when Minus_Infinity =>
Set ('-');
Set ('I');
Set ('n');
Set ('f');
Set_Special_Fill (4);
when Infinity =>
Set ('+');
Set ('I');
Set ('n');
Set ('f');
Set_Special_Fill (4);
when Not_A_Number =>
Set ('N');
Set ('a');
Set ('N');
Set_Special_Fill (3);
end case;
end Set_Floating_Invalid_Value;
end System.Img_Util;
|
private with Ada.Finalization;
package MPFR.Root_FR is
pragma Preelaborate;
type MP_Float (Precision : MPFR.Precision) is private;
function To_MP_Float (
X : Long_Long_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function To_Long_Long_Float (X : MP_Float; Rounding : MPFR.Rounding)
return Long_Long_Float;
function Image (
Value : MP_Float;
Base : Number_Base := 10;
Rounding : MPFR.Rounding)
return String;
function Value (
Image : String;
Base : Number_Base := 10;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function "=" (Left, Right : MP_Float) return Boolean;
function "<" (Left, Right : MP_Float) return Boolean;
function ">" (Left, Right : MP_Float) return Boolean;
function "<=" (Left, Right : MP_Float) return Boolean;
function ">=" (Left, Right : MP_Float) return Boolean;
function Copy ( -- Positive
Right : MP_Float;
Precision : MPFR.Precision := Default_Precision;
Rounding : MPFR.Rounding := Default_Rounding)
return MP_Float;
function Negative (
Right : MP_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Add (
Left, Right : MP_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Add (
Left : MP_Float;
Right : Long_Long_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Add (
Left : Long_Long_Float;
Right : MP_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Subtract (
Left, Right : MP_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Subtract (
Left : MP_Float;
Right : Long_Long_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Subtract (
Left : Long_Long_Float;
Right : MP_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Multiply (
Left, Right : MP_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Multiply (
Left : MP_Float;
Right : Long_Long_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Multiply (
Left : Long_Long_Float;
Right : MP_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Divide (
Left, Right : MP_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Divide (
Left : MP_Float;
Right : Long_Long_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Divide (
Left : Long_Long_Float;
Right : MP_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Power (
Left : MP_Float;
Right : Integer;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function Sqrt (
X : MP_Float;
Precision : MPFR.Precision;
Rounding : MPFR.Rounding)
return MP_Float;
function NaN (Precision : MPFR.Precision) return MP_Float;
function Infinity (Precision : MPFR.Precision) return MP_Float;
private
package Controlled is
type MP_Float is private;
function Create (Precision : MPFR.Precision) return MP_Float;
function Reference (Item : in out Root_FR.MP_Float)
return not null access C.mpfr.mpfr_struct;
function Constant_Reference (Item : Root_FR.MP_Float)
return not null access constant C.mpfr.mpfr_struct;
pragma Inline (Reference);
pragma Inline (Constant_Reference);
private
type MP_Float is new Ada.Finalization.Controlled
with record
Raw : aliased C.mpfr.mpfr_t := (others => (others => <>));
end record;
overriding procedure Initialize (Object : in out MP_Float);
overriding procedure Adjust (Object : in out MP_Float);
overriding procedure Finalize (Object : in out MP_Float);
end Controlled;
-- [gcc-4.8/4.9/5.0] derivation with discriminants makes many problems.
type MP_Float (Precision : MPFR.Precision) is record
Data : Controlled.MP_Float := Controlled.Create (Precision);
end record;
end MPFR.Root_FR;
|
------------------------------------------------------------------------------
-- --
-- Ada User Repository Annex (AURA) --
-- Reference Implementation --
-- --
-- ------------------------------------------------------------------------ --
-- --
-- Copyright (C) 2020, ANNEXI-STRAYLINE Trans-Human Ltd. --
-- All rights reserved. --
-- --
-- Original Contributors: --
-- * Richard Wai (ANNEXI-STRAYLINE) --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- --
-- * Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A --
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with Ada.Streams;
with Ada.Assertions;
with Ada.Directories;
with Ada.Strings.Fixed;
with Ada.Strings.Bounded;
with Child_Processes;
with Child_Processes.Path_Searching;
with Child_Processes.Wait_And_Buffer;
separate (Repositories.Cache)
package body Checkout_Git is
Git_Cache_Failure: exception;
package Program_Paths renames Child_Processes.Path_Searching;
Git_Program : aliased constant String := "git";
Git : constant Program_Paths.Elaboration_Path_Search
:= Program_Paths.Initialize (Git_Program);
Git_Timeout : constant Duration := 300.0; -- 5 minutes
Output_Poll_Rate: constant Duration := 0.5;
package Output_Buffers is
new Ada.Strings.Bounded.Generic_Bounded_Length (8096);
procedure Buffer_Append (Buffer: in out Output_Buffers.Bounded_String;
Item : in String)
is begin
-- Since we are using bounded inputs, we'd rather not crash just because
-- the input exceeds the buffers, but rather have it truncate.
Output_Buffers.Append (Source => Buffer,
New_Item => Item,
Drop => Ada.Strings.Right);
end Buffer_Append;
procedure Wait_And_Buffer is new Child_Processes.Wait_And_Buffer
(Buffer_Type => Output_Buffers.Bounded_String,
Append => Buffer_Append,
Empty_Buffer => Output_Buffers.Null_Bounded_String);
--
-- Checkout_Git_Order
--
-- Checkout_Order checks out a git repository when the cache does
-- not exist (or has been invalidated)
type Cache_Git_Order is new Workers.Work_Order with
record
Repo : Repository;
Index: Repository_Index;
end record;
overriding procedure Execute (Order: in out Cache_Git_Order);
overriding function Image (Order: Cache_Git_Order) return String;
-----------
-- Image --
-----------
function Image (Order: Cache_Git_Order) return String
is ( "[Cache_Git_Order]" & New_Line
& " Repoistory No."
& Repository_Index'Image (Order.Index) & New_Line
& " Git : " & UBS.To_String (Order.Repo.Location)
& (if (UBS.Length (Order.Repo.Snapshot) > 0) then
New_Line & " Commit: " & UBS.To_String (Order.Repo.Snapshot)
else
"")
& (if (UBS.Length (Order.Repo.Tracking_Branch) > 0) then
New_Line & " Branch: "
& UBS.To_String (Order.Repo.Tracking_Branch)
else
""));
-------------
-- Execute --
-------------
procedure Execute (Order: in out Cache_Git_Order) is
use Child_Processes;
use type Ada.Directories.File_Kind;
Trimmed_Index: constant String
:= Ada.Strings.Fixed.Trim
(Source => Repository_Index'Image (Order.Index),
Side => Ada.Strings.Both);
Cache_Path: constant String := Cache_Root & '/' & Trimmed_Index;
STDERR: Output_Buffers.Bounded_String;
STDOUT: Output_Buffers.Bounded_String;
procedure Wait_Proc (Title: in String;
Proc : in out Child_Process'Class)
is
type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
Timed_Out: Boolean;
Proc_Exit: Exit_Status := Failure;
begin
-- Wait until finish, if timeout, kill the process. If
-- exit status = Failure then drain Standard_Error. In both cases,
-- raise an exception
Wait_And_Buffer (Process => Proc,
Poll_Rate => Output_Poll_Rate,
Timeout => Git_Timeout,
Output => STDOUT,
Error => STDERR,
Timed_Out => Timed_Out,
Status => Proc_Exit);
if Timed_Out then
-- This should actually be very rare
Proc.Kill;
raise Git_Cache_Failure with Title
& " timed-out"
& " STDOUT: " & Output_Buffers.To_String (STDOUT)
& " STDERR: " & Output_Buffers.To_String (STDERR);
elsif Proc_Exit = Failure then
raise Git_Cache_Failure with Title & " failed: "
& Output_Buffers.To_String (STDERR);
end if;
end Wait_Proc;
procedure Git_Command (Args : in String;
Ignore_Fail: Boolean := False) is
Proc: Child_Process'Class
:= Spawn_Process
(Image_Path => Program_Paths.Image_Path (Git),
Arguments => Args,
Working_Directory => Cache_Path);
begin
Wait_Proc (Title => "git " & Args,
Proc => Proc);
exception
when Git_Cache_Failure =>
if Ignore_Fail then
return;
else
raise;
end if;
end Git_Command;
Cache_Bad: Boolean := False;
begin
UBS.Set_Unbounded_String (Target => Order.Repo.Cache_Path,
Source => Cache_Path);
Order.Repo.Cache_State := Available;
-- These will only be updated in the registry if the checkout is
-- successful
-- Verify that git is actually available
if not Program_Paths.Found (Git) then
raise Program_Error with
"Unable to checkout git repository: Could not find git!";
end if;
-- First step is to see if this repo is already cached, and if it is,
-- that it is on the right commit or branch, and that it has no
-- unstaged/uncommited changes. If that is all good, we're done. If any
-- of that is off, we wipe it and start from scratch (the user should
-- never be messing with a git cache directly)
if Ada.Directories.Exists (Cache_Path) then
if Ada.Directories.Kind (Cache_Path) = Ada.Directories.Directory then
begin
if UBS.Length (Order.Repo.Snapshot) > 0 then
-- If Snapshot is not empty, this means the repo is on a
-- specific commit (regardless of any Tracking_Branch).
Git_Command ("log -1 --pretty=format:%H");
if Output_Buffers.To_String (STDOUT)
/= UBS.To_String (Order.Repo.Snapshot)
then
Cache_Bad := True;
end if;
end if;
-- Check for any pollution. We expect a short status to only
-- have one line, giving either "## HEAD" (Snapshot) or
--"## branch...origin/branch" (Tracking_Branch)
--
-- Any lines following that indicate changes to the cache, which
-- is not acceptable
Git_Command ("status -s -b");
-- If we have a snapshot, we expect a detached head
if UBS.Length (Order.Repo.Snapshot) > 0
-- "## HEAD "
-- ^ ^
-- 1 8
and then Output_Buffers.Slice (Source => STDOUT,
Low => 1,
High => 8)
/= "## HEAD "
then
Cache_Bad := True;
else
-- If we don't have a snapshot, we expect to see the correct
-- branch
pragma Assert (UBS.Length (Order.Repo.Tracking_Branch) > 0);
-- This should be checked when the repo file is parsed
declare
Expected: constant String
:= "## "
& UBS.To_String (Order.Repo.Tracking_Branch)
& "...origin/"
& UBS.To_String (Order.Repo.Tracking_Branch);
begin
if Output_Buffers.Slice (Source => STDOUT,
Low => 1,
High => Expected'Length)
/= Expected
then
Cache_Bad := True;
end if;
end;
end if;
-- Finally, there should be only one line
if Output_Buffers.Count (Source => STDOUT,
Pattern => String'(1 .. 1 => New_Line))
> 1
then
Cache_Bad := True;
end if;
exception
when Git_Cache_Failure =>
-- Any of the above commands failing simply means the cache
-- is invalid, so we just need to destroy it
Cache_Bad := True;
end;
if not Cache_Bad then
-- done.
Update_Repository (Index => Order.Index,
Updated => Order.Repo);
return;
else
-- Expunge
Ada.Directories.Delete_Tree (Cache_Path);
end if;
else
-- Path points at a non-directory file, that's not ok
Ada.Directories.Delete_File (Cache_Path);
end if;
end if;
-- If we get here, then either the cache didn't exist, or something was
-- wrong with it and it was obliterated
-- Create the cache path
Ada.Directories.Create_Path (Cache_Path);
-- Clone the repo
Git_Command ("clone -n -q -j 0 " -- Quiet and don't checkout anything
& UBS.To_String (Order.Repo.Location) & ' '
& Cache_Path);
-- If the snapshot is set, that takes priority
if UBS.Length (Order.Repo.Snapshot) > 0 then
Git_Command ("checkout --detach "
& UBS.To_String (Order.Repo.Snapshot));
-- If Tracking_Branch is set, and we have no snapshow, check that out
elsif UBS.Length (Order.Repo.Tracking_Branch) > 0 then
Git_Command ("checkout "
& UBS.To_String (Order.Repo.Tracking_Branch));
-- Otherwise, we just use the default branch
else
Git_Command ("checkout "
& UBS.To_String (Order.Repo.Tracking_Branch));
end if;
-- Finally we checkout submodules, if any
Git_Command ("submodule --quiet update "
& "--init --checkout --recursive -j 0");
Update_Repository (Index => Order.Index,
Updated => Order.Repo);
end Execute;
--------------
-- Dispatch --
--------------
procedure Dispatch (Repo: in Repository; Index: in Repository_Index) is
Order: Cache_Git_Order
:= (Tracker => Caching_Progress'Access,
Repo => Repo,
Index => Index);
begin
Workers.Enqueue_Order (Order);
end Dispatch;
end Checkout_Git;
|
with Ada.Text_IO; use Ada.Text_IO;
package body Greeter is
Hello_Text : constant String := "Hello ";
procedure Greet (S : String) is
begin
Put_Line (Hello_Text & S & "!");
Put_Line (Hi_Text);
end Greet;
end Greeter;
|
with
FLTK.Images;
limited with
FLTK.Widgets.Groups.Windows;
private with
System.Address_To_Access_Conversions,
Ada.Unchecked_Conversion,
Interfaces.C;
package FLTK.Widgets is
type Widget is new Wrapper with private;
type Widget_Reference (Data : not null access Widget'Class) is limited null record
with Implicit_Dereference => Data;
type Widget_Callback is access procedure
(Item : in out Widget'Class);
type Callback_Flag is private;
function "+" (Left, Right : in Callback_Flag) return Callback_Flag;
Call_Never : constant Callback_Flag;
When_Changed : constant Callback_Flag;
When_Interact : constant Callback_Flag;
When_Release : constant Callback_Flag;
When_Enter_Key : constant Callback_Flag;
package Forge is
function Create
(X, Y, W, H : in Integer;
Text : in String)
return Widget;
end Forge;
procedure Activate
(This : in out Widget);
procedure Deactivate
(This : in out Widget);
function Is_Active
(This : in Widget)
return Boolean;
function Is_Tree_Active
(This : in Widget)
return Boolean;
procedure Set_Active
(This : in out Widget;
To : in Boolean);
function Has_Changed
(This : in Widget)
return Boolean;
procedure Set_Changed
(This : in out Widget;
To : in Boolean);
function Is_Output_Only
(This : in Widget)
return Boolean;
procedure Set_Output_Only
(This : in out Widget;
To : in Boolean);
function Is_Visible
(This : in Widget)
return Boolean;
function Is_Tree_Visible
(This : in Widget)
return Boolean;
procedure Set_Visible
(This : in out Widget;
To : in Boolean);
function Has_Visible_Focus
(This : in Widget)
return Boolean;
procedure Set_Visible_Focus
(This : in out Widget;
To : in Boolean);
function Take_Focus
(This : in out Widget)
return Boolean;
function Takes_Events
(This : in Widget)
return Boolean;
function Get_Background_Color
(This : in Widget)
return Color;
procedure Set_Background_Color
(This : in out Widget;
To : in Color);
function Get_Selection_Color
(This : in Widget)
return Color;
procedure Set_Selection_Color
(This : in out Widget;
To : in Color);
function Parent
(This : in Widget)
return access FLTK.Widgets.Groups.Group'Class;
function Contains
(This : in Widget;
Item : in Widget'Class)
return Boolean;
function Inside
(This : in Widget;
Parent : in Widget'Class)
return Boolean;
function Nearest_Window
(This : in Widget)
return access FLTK.Widgets.Groups.Windows.Window'Class;
function Top_Window
(This : in Widget)
return access FLTK.Widgets.Groups.Windows.Window'Class;
function Top_Window_Offset
(This : in Widget;
Offset_X, Offset_Y : out Integer)
return access FLTK.Widgets.Groups.Windows.Window'Class;
function Get_Alignment
(This : in Widget)
return Alignment;
procedure Set_Alignment
(This : in out Widget;
New_Align : in Alignment);
function Get_Box
(This : in Widget)
return Box_Kind;
procedure Set_Box
(This : in out Widget;
Box : in Box_Kind);
function Get_Tooltip
(This : in Widget)
return String;
procedure Set_Tooltip
(This : in out Widget;
Text : in String);
function Get_Label
(This : in Widget)
return String;
procedure Set_Label
(This : in out Widget;
Text : in String);
function Get_Label_Color
(This : in Widget)
return Color;
procedure Set_Label_Color
(This : in out Widget;
Value : in Color);
function Get_Label_Font
(This : in Widget)
return Font_Kind;
procedure Set_Label_Font
(This : in out Widget;
Font : in Font_Kind);
function Get_Label_Size
(This : in Widget)
return Font_Size;
procedure Set_Label_Size
(This : in out Widget;
Size : in Font_Size);
function Get_Label_Type
(This : in Widget)
return Label_Kind;
procedure Set_Label_Type
(This : in out Widget;
Label : in Label_Kind);
procedure Measure_Label
(This : in Widget;
W, H : out Integer);
function Get_Callback
(This : in Widget)
return Widget_Callback;
procedure Set_Callback
(This : in out Widget;
Func : in Widget_Callback);
procedure Do_Callback
(This : in out Widget);
function Get_When
(This : in Widget)
return Callback_Flag;
procedure Set_When
(This : in out Widget;
To : in Callback_Flag);
function Get_X
(This : in Widget)
return Integer;
function Get_Y
(This : in Widget)
return Integer;
function Get_W
(This : in Widget)
return Integer;
function Get_H
(This : in Widget)
return Integer;
procedure Resize
(This : in out Widget;
W, H : in Integer);
procedure Reposition
(This : in out Widget;
X, Y : in Integer);
function Get_Image
(This : in Widget)
return access FLTK.Images.Image'Class;
procedure Set_Image
(This : in out Widget;
Pic : in out FLTK.Images.Image'Class);
function Get_Inactive_Image
(This : in Widget)
return access FLTK.Images.Image'Class;
procedure Set_Inactive_Image
(This : in out Widget;
Pic : in out FLTK.Images.Image'Class);
function Is_Damaged
(This : in Widget)
return Boolean;
procedure Set_Damaged
(This : in out Widget;
To : in Boolean);
procedure Set_Damaged
(This : in out Widget;
To : in Boolean;
X, Y, W, H : in Integer);
procedure Draw
(This : in out Widget) is null;
procedure Draw_Label
(This : in Widget;
X, Y, W, H : in Integer;
Align : in Alignment);
procedure Redraw
(This : in out Widget);
procedure Redraw_Label
(This : in out Widget);
function Handle
(This : in out Widget;
Event : in Event_Kind)
return Event_Outcome;
private
type Widget is new Wrapper with
record
Callback : Widget_Callback;
Current_Image : access FLTK.Images.Image'Class;
Inactive_Image : access FLTK.Images.Image'Class;
end record;
overriding procedure Finalize
(This : in out Widget);
type Callback_Flag is new Interfaces.C.unsigned;
Call_Never : constant Callback_Flag := 0;
When_Changed : constant Callback_Flag := 1;
When_Interact : constant Callback_Flag := 2;
When_Release : constant Callback_Flag := 4;
When_Enter_Key : constant Callback_Flag := 8;
-- the user data portion should always be a reference back to the Ada binding
procedure Callback_Hook
(W, U : in System.Address);
pragma Convention (C, Callback_Hook);
procedure Draw_Hook
(U : in System.Address);
pragma Convention (C, Draw_Hook);
function Handle_Hook
(U : in System.Address;
E : in Interfaces.C.int)
return Interfaces.C.int;
pragma Convention (C, Handle_Hook);
package Widget_Convert is new System.Address_To_Access_Conversions (Widget'Class);
package Callback_Convert is
function To_Pointer is new Ada.Unchecked_Conversion (System.Address, Widget_Callback);
function To_Address is new Ada.Unchecked_Conversion (Widget_Callback, System.Address);
end Callback_Convert;
function fl_widget_get_user_data
(W : in System.Address)
return System.Address;
pragma Import (C, fl_widget_get_user_data, "fl_widget_get_user_data");
procedure fl_widget_set_user_data
(W, D : in System.Address);
pragma Import (C, fl_widget_set_user_data, "fl_widget_set_user_data");
pragma Inline (Activate);
pragma Inline (Deactivate);
pragma Inline (Is_Active);
pragma Inline (Is_Tree_Active);
pragma Inline (Set_Active);
pragma Inline (Has_Changed);
pragma Inline (Set_Changed);
pragma Inline (Is_Output_Only);
pragma Inline (Set_Output_Only);
pragma Inline (Is_Visible);
pragma Inline (Set_Visible);
pragma Inline (Has_Visible_Focus);
pragma Inline (Set_Visible_Focus);
pragma Inline (Take_Focus);
pragma Inline (Takes_Events);
pragma Inline (Get_Background_Color);
pragma Inline (Set_Background_Color);
pragma Inline (Get_Selection_Color);
pragma Inline (Set_Selection_Color);
pragma Inline (Parent);
pragma Inline (Contains);
pragma Inline (Inside);
pragma Inline (Nearest_Window);
pragma Inline (Top_Window);
pragma Inline (Top_Window_Offset);
pragma Inline (Get_Alignment);
pragma Inline (Set_Alignment);
pragma Inline (Get_Box);
pragma Inline (Set_Box);
pragma Inline (Get_Tooltip);
pragma Inline (Set_Tooltip);
pragma Inline (Get_Label);
pragma Inline (Set_Label);
pragma Inline (Get_Label_Color);
pragma Inline (Set_Label_Color);
pragma Inline (Get_Label_Font);
pragma Inline (Set_Label_Font);
pragma Inline (Get_Label_Size);
pragma Inline (Set_Label_Size);
pragma Inline (Get_Label_Type);
pragma Inline (Set_Label_Type);
pragma Inline (Measure_Label);
pragma Inline (Get_Callback);
pragma Inline (Set_Callback);
pragma Inline (Do_Callback);
pragma Inline (Get_When);
pragma Inline (Set_When);
pragma Inline (Get_X);
pragma Inline (Get_Y);
pragma Inline (Get_W);
pragma Inline (Get_H);
pragma Inline (Resize);
pragma Inline (Reposition);
pragma Inline (Get_Image);
pragma Inline (Set_Image);
pragma Inline (Get_Inactive_Image);
pragma Inline (Set_Inactive_Image);
pragma Inline (Is_Damaged);
pragma Inline (Set_Damaged);
pragma Inline (Draw);
pragma Inline (Draw_Label);
pragma Inline (Redraw);
pragma Inline (Redraw_Label);
pragma Inline (Handle);
end FLTK.Widgets;
|
-----------------------------------------------------------------------
-- html.lists -- List of items
-- Copyright (C) 2009, 2010, 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 Util.Log.Loggers;
with Util.Beans.Basic;
with ASF.Components.Base;
package body ASF.Components.Html.Lists is
use type EL.Objects.Data_Type;
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("ASF.Components.Html.Lists");
function Get_Item_Layout (List_Layout : in String;
Item_Class : in String) return String;
-- ------------------------------
-- Get the list layout to use. The default is to use no layout or a div if some CSS style
-- is applied on the list or some specific list ID must be generated. Possible layout values
-- include:
-- "simple" : the list is rendered as is or as a div with each children as is,
-- "unorderedList" : the list is rendered as an HTML ul/li list,
-- "orderedList" : the list is rendered as an HTML ol/li list.
-- ------------------------------
function Get_Layout (UI : in UIList;
Class : in String;
Context : in Faces_Context'Class) return String is
Value : constant EL.Objects.Object := UI.Get_Attribute (Context, "layout");
Layout : constant String := EL.Objects.To_String (Value);
begin
if Layout = "orderedList" or Layout = "ordered" then
return "ol";
elsif Layout = "unorderedList" or Layout = "unordered" then
return "ul";
elsif Class'Length > 0 or else not UI.Is_Generated_Id then
return "div";
else
return "";
end if;
end Get_Layout;
-- ------------------------------
-- Get the item layout according to the list layout and the item class (if any).
-- ------------------------------
function Get_Item_Layout (List_Layout : in String;
Item_Class : in String) return String is
begin
if List_Layout'Length = 2 then
return "li";
elsif Item_Class'Length > 0 then
return "div";
else
return "";
end if;
end Get_Item_Layout;
-- ------------------------------
-- Get the value to write on the output.
-- ------------------------------
function Get_Value (UI : in UIList) return EL.Objects.Object is
begin
return UI.Get_Attribute (UI.Get_Context.all, "value");
end Get_Value;
-- ------------------------------
-- Set the value to write on the output.
-- ------------------------------
procedure Set_Value (UI : in out UIList;
Value : in EL.Objects.Object) is
begin
null;
end Set_Value;
-- ------------------------------
-- Get the variable name
-- ------------------------------
function Get_Var (UI : in UIList) return String is
Var : constant EL.Objects.Object := UI.Get_Attribute (UI.Get_Context.all, "var");
begin
return EL.Objects.To_String (Var);
end Get_Var;
-- ------------------------------
-- Encode an item of the list with the given item layout and item class.
-- ------------------------------
procedure Encode_Item (UI : in UIList;
Item_Layout : in String;
Item_Class : in String;
Context : in out Faces_Context'Class) is
Writer : constant Response_Writer_Access := Context.Get_Response_Writer;
begin
if Item_Layout'Length > 0 then
Writer.Start_Element (Item_Layout);
end if;
if Item_Class'Length > 0 then
Writer.Write_Attribute ("class", Item_Class);
end if;
Base.UIComponent (UI).Encode_Children (Context);
if Item_Layout'Length > 0 then
Writer.End_Element (Item_Layout);
end if;
end Encode_Item;
procedure Encode_Children (UI : in UIList;
Context : in out Faces_Context'Class) is
begin
if not UI.Is_Rendered (Context) then
return;
end if;
declare
Value : EL.Objects.Object := Get_Value (UI);
Kind : constant EL.Objects.Data_Type := EL.Objects.Get_Type (Value);
Name : constant String := UI.Get_Var;
Bean : access Util.Beans.Basic.Readonly_Bean'Class;
Is_Reverse : constant Boolean := UI.Get_Attribute ("reverse", Context, False);
List : Util.Beans.Basic.List_Bean_Access;
Count : Natural;
begin
-- Check that we have a List_Bean but do not complain if we have a null value.
if Kind /= EL.Objects.TYPE_BEAN then
if Kind /= EL.Objects.TYPE_NULL then
ASF.Components.Base.Log_Error (UI, "Invalid list bean (found a {0})",
EL.Objects.Get_Type_Name (Value));
end if;
return;
end if;
Bean := EL.Objects.To_Bean (Value);
if Bean = null or else not (Bean.all in Util.Beans.Basic.List_Bean'Class) then
ASF.Components.Base.Log_Error (UI, "Invalid list bean: "
& "it does not implement 'List_Bean' interface");
return;
end if;
List := Util.Beans.Basic.List_Bean'Class (Bean.all)'Unchecked_Access;
Count := List.Get_Count;
if Count /= 0 then
declare
Class : constant String := UI.Get_Attribute (STYLE_CLASS_ATTR_NAME,
Context, "");
Item_Class : constant String := UI.Get_Attribute (ITEM_STYLE_CLASS_ATTR_NAME,
Context, "");
Layout : constant String := UI.Get_Layout (Class, Context);
Writer : constant Response_Writer_Access := Context.Get_Response_Writer;
Item_Layout : constant String := Get_Item_Layout (Layout, Item_Class);
begin
if Layout'Length > 0 then
Writer.Start_Element (Layout);
end if;
if not UI.Is_Generated_Id then
Writer.Write_Attribute ("id", UI.Get_Client_Id);
end if;
if Class'Length > 0 then
Writer.Write_Attribute ("class", Class);
end if;
if Is_Reverse then
for I in reverse 1 .. Count loop
List.Set_Row_Index (I);
Value := List.Get_Row;
Context.Set_Attribute (Name, Value);
Log.Debug ("Set variable {0}", Name);
UI.Encode_Item (Item_Layout, Item_Class, Context);
end loop;
else
for I in 1 .. Count loop
List.Set_Row_Index (I);
Value := List.Get_Row;
Context.Set_Attribute (Name, Value);
Log.Debug ("Set variable {0}", Name);
UI.Encode_Item (Item_Layout, Item_Class, Context);
end loop;
end if;
if Layout'Length > 0 then
Writer.End_Element (Layout);
end if;
end;
end if;
end;
end Encode_Children;
end ASF.Components.Html.Lists;
|
-- $Id: scanner.ads,v 1.5 2000/09/04 11:17:27 grosch rel $
with Position, Strings;
use Position, Strings;
$- user import declarations
$@ package @ is
$E[ user export declarations
type tScanAttribute is record Position: tPosition; end record;
procedure ErrorAttribute (Token: Integer; Attribute: out tScanAttribute);
$]
EofToken : constant Integer := 0;
TokenLength : Integer;
TokenIndex : Integer;
Attribute : tScanAttribute;
procedure BeginScanner ;
procedure BeginFile (FileName: String);
function GetToken return Integer;
procedure GetWord (Word: out Strings.tString);
procedure GetLower (Word: out Strings.tString);
procedure GetUpper (Word: out Strings.tString);
procedure CloseFile ;
procedure CloseScanner ;
$@ end @;
|
------------------------------------------------------------------------------
-- --
-- WAVEFILES --
-- --
-- Main package --
-- --
-- The MIT License (MIT) --
-- --
-- Copyright (c) 2015 -- 2021 Gustavo A. Hoffmann --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining --
-- a copy of this software and associated documentation files (the --
-- "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, sublicense, and / or sell copies of the Software, and to --
-- permit persons to whom the Software is furnished to do so, subject to --
-- the following conditions: --
-- --
-- The above copyright notice and this permission notice shall be --
-- included in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, --
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
-- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY --
-- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, --
-- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE --
-- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
------------------------------------------------------------------------------
with Ada.Streams.Stream_IO;
with Ada.Containers.Vectors;
with Interfaces;
with Audio.RIFF;
with Audio.RIFF.Wav.Formats; use Audio.RIFF.Wav.Formats;
package Audio.Wavefiles is
type Wavefile is tagged limited private;
type File_Mode is new Ada.Streams.Stream_IO.File_Mode;
type Wavefile_Error_Code is
(Wavefile_Error_File_Not_Open,
Wavefile_Error_File_Already_Open,
Wavefile_Error_File_Too_Short,
Wavefile_Error_Format_Chuck_Not_Found,
Wavefile_Error_Data_Chuck_Not_Found,
Wavefile_Error_Unsupported_Wavefile_Format,
Wavefile_Error_Unsupported_Bit_Depth,
Wavefile_Error_Unsupported_Format_Size);
type Wavefile_Errors is array (Wavefile_Error_Code) of Boolean
with Pack;
No_Wavefile_Errors : constant Wavefile_Errors := (others => False);
type Wavefile_Warning_Code is
(Wavefile_Warning_Inconsistent_Channel_Mask);
type Wavefile_Warnings is array (Wavefile_Warning_Code) of Boolean
with Pack;
No_Wavefile_Warnings : constant Wavefile_Warnings := (others => False);
subtype Byte is Interfaces.Unsigned_8;
type Byte_Array is array (Long_Integer range <>) of Byte;
type Wav_Chunk_Element is
record
Chunk_Tag : Wav_Chunk_Tag;
ID : Audio.RIFF.FOURCC_String;
Size : Long_Integer;
Start_Index : Ada.Streams.Stream_IO.Positive_Count;
Consolidated : Boolean;
end record;
function Chunk_Element_Data
(WF : Wavefile;
Chunk_Element : Wav_Chunk_Element) return Byte_Array;
package Wav_Chunk_Element_Vectors is new Ada.Containers.Vectors
(Index_Type => Positive,
Element_Type => Wav_Chunk_Element);
use Wav_Chunk_Element_Vectors;
subtype Wav_Chunk_Elements is Wav_Chunk_Element_Vectors.Vector;
type Wav_Chunk_Element_Found (Success : Boolean := False) is
record
case Success is
when False =>
null;
when True =>
Chunk_Element : Wav_Chunk_Element;
end case;
end record;
procedure Find_First_Chunk
(Chunks : Wav_Chunk_Elements;
Chunk_Tag : Wav_Chunk_Tag;
Found : out Wav_Chunk_Element_Found);
type RIFF_Information is
record
Id : RIFF_Identifier;
Format : RIFF_Format;
Chunks : Wav_Chunk_Elements;
end record;
procedure Create
(WF : in out Wavefile;
Mode : File_Mode := Out_File;
Name : String := "";
Form : String := "");
procedure Open
(WF : in out Wavefile;
Mode : File_Mode;
Name : String;
Form : String := "");
function Is_Open
(WF : Wavefile) return Boolean;
function End_Of_File
(WF : in out Wavefile) return Boolean
with Inline, Pre => Mode (WF) = In_File;
procedure Close (WF : in out Wavefile);
function Errors (WF : Wavefile) return Wavefile_Errors
with Inline;
function Warnings (WF : Wavefile) return Wavefile_Warnings
with Inline;
procedure Set_Format_Of_Wavefile
(WF : in out Wavefile;
Format : Wave_Format_Extensible)
with Pre => not Is_Open (WF);
function Format_Of_Wavefile
(W : Wavefile) return Wave_Format_Extensible;
function Number_Of_Channels
(W : Wavefile) return Positive;
function Bit_Depth
(W : Wavefile) return Wav_Bit_Depth;
function Sample_Rate
(W : Wavefile) return Wav_Sample_Rate;
function Mode
(W : Wavefile) return File_Mode;
function Name
(W : Wavefile) return String;
procedure Get_RIFF_Info
(WF : in out Wavefile;
Info : out RIFF_Information)
with Pre => Is_Open (WF);
subtype Sample_Count is Long_Long_Integer;
function Current_Sample
(WF : Wavefile) return Sample_Count;
function First_Sample
(WF : Wavefile) return Sample_Count;
function Last_Sample
(WF : Wavefile) return Sample_Count;
function Total_Sample_Count
(WF : Wavefile) return Sample_Count;
procedure Set_Current_Sample
(WF : in out Wavefile;
Position : Sample_Count)
with Pre => (Mode (WF) = In_File
and Position >= WF.First_Sample
and Position <= WF.Last_Sample);
subtype Wavefile_Time_In_Seconds is Long_Long_Float;
function Current_Time
(WF : Wavefile) return Wavefile_Time_In_Seconds;
function End_Time
(WF : Wavefile) return Wavefile_Time_In_Seconds;
procedure Set_Current_Time
(WF : in out Wavefile;
At_Time : Wavefile_Time_In_Seconds)
with Pre => Mode (WF) = In_File;
function Is_Supported_Format
(W : Wave_Format_Extensible) return Boolean;
private
--
-- Constants that indicate a range of
-- "First_Sample_Count .. <total_sample_count> - Total_To_Last_Diff"
--
-- Range used in this implementation: "0 .. <total_sample_count> - 1"
--
-- You can change this range to "1 .. <total_sample_count>" by changing
-- the constants as follows:
--
-- First_Sample_Count : constant Sample_Count := 1;
-- Total_To_Last_Diff : constant Sample_Count := 0;
--
First_Sample_Count : constant Sample_Count := 0;
Total_To_Last_Diff : constant Sample_Count := 1;
type Sample_Info is
record
Current : Sample_Count;
Total : Sample_Count;
end record
with Dynamic_Predicate =>
Sample_Info.Current in
First_Sample_Count .. Sample_Info.Total - Total_To_Last_Diff + 1;
-- Note: the "+ 1" above indicates that the Current counter can be in the
-- "end of file" position after a call to Get.
procedure Set_Error (WF : in out Wavefile;
Error_Code : Wavefile_Error_Code);
procedure Reset_Errors (WF : in out Wavefile);
procedure Set_Warning (WF : in out Wavefile;
Warning_Code : Wavefile_Warning_Code);
procedure Reset_Warnings (WF : in out Wavefile);
type Wavefile is tagged limited
record
Is_Opened : Boolean := False;
File : Ada.Streams.Stream_IO.File_Type;
File_Access : Ada.Streams.Stream_IO.Stream_Access;
Wave_Format : Wave_Format_Extensible := Default;
Sample_Pos : Sample_Info;
RIFF_Info : RIFF_Information;
Errors : Wavefile_Errors := (others => False);
Warnings : Wavefile_Warnings := (others => False);
end record;
function First_Sample
(WF : Wavefile) return Sample_Count is (First_Sample_Count);
function Is_Open
(WF : Wavefile) return Boolean is (WF.Is_Opened);
function Errors (WF : Wavefile) return Wavefile_Errors is
(WF.Errors);
function Warnings (WF : Wavefile) return Wavefile_Warnings is
(WF.Warnings);
end Audio.Wavefiles;
|
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr>
-- MIT license. Please refer to the LICENSE file.
private with Ada.Containers.Vectors,
Ada.Containers.Hashed_Maps,
Ada.Containers.Multiway_Trees;
with Apsepp.Tags; use Apsepp.Tags;
package Apsepp.Test_Reporter_Data_Struct_Class.Impl is
type Test_Reporter_Data
is limited new Test_Reporter_Data_Interfa with private;
overriding
function Is_Empty (Obj : Test_Reporter_Data) return Boolean;
overriding
procedure Reset (Obj : in out Test_Reporter_Data);
overriding
function Is_Active (Obj : Test_Reporter_Data;
Node_Tag : Tag) return Boolean;
overriding
procedure Include_Node (Obj : in out Test_Reporter_Data;
Node_Lineage : Tag_Array);
overriding
procedure Add_Event (Obj : in out Test_Reporter_Data;
Node_Tag : Tag;
Event : Test_Event_Base'Class);
private
package Event_Index_Vectors is new Ada.Containers.Vectors
(Index_Type => Event_Index,
Element_Type => Event_Index);
type Node_Data is record
T : Tag;
Event_Index_Vector : Event_Index_Vectors.Vector;
end record;
function Same_Tag (N_D_1, N_D_2 : Node_Data) return Boolean
is (N_D_1.T = N_D_2.T);
package Node_Data_Trees is new Ada.Containers.Multiway_Trees
(Element_Type => Node_Data,
"=" => Same_Tag);
use Node_Data_Trees; -- Makes "=" for type Node_Data_Trees.Cursor directly
-- visible.
package Node_Data_Hashed_Maps is new Ada.Containers.Hashed_Maps
(Key_Type => Tag,
Element_Type => Node_Data_Trees.Cursor,
Hash => Tag_Hash,
Equivalent_Keys => "=");
type Node_Event is record
Node_Data_Cursor : Node_Data_Trees.Cursor;
Event : Test_Event_Access;
end record;
package Node_Event_Vectors is new Ada.Containers.Vectors
(Index_Type => Event_Index,
Element_Type => Node_Event);
type Test_Reporter_Data
is limited new Test_Reporter_Data_Interfa with record
Node_Data_Tree : Node_Data_Trees.Tree;
Event_Vector : Node_Event_Vectors.Vector;
Active_Node_Map : Node_Data_Hashed_Maps.Map;
end record;
not overriding
function Is_Active_Node (Obj : Test_Reporter_Data;
T : Tag) return Boolean
is (Obj.Active_Node_Map.Contains (T))
with Post'Class
=> not Is_Active_Node'Result
or else
Obj.Node_Data_Tree.Contains ((T => T,
Event_Index_Vector => <>));
not overriding
procedure Add_And_Or_Set_Active_Node (Obj : in out Test_Reporter_Data;
T : Tag;
C : out Node_Data_Trees.Cursor)
with Post'Class
=> Obj.Node_Data_Tree.Contains ((T => T,
Event_Index_Vector => <>))
and then
Obj.Is_Active_Node (T);
end Apsepp.Test_Reporter_Data_Struct_Class.Impl;
|
pragma Ada_2012;
with AUnit.Assertions; use AUnit.Assertions;
with AUnit.Test_Caller;
with Ada.Streams; use Ada.Streams;
with HMAC; use HMAC.HMAC_SHA_1;
package body HMAC_SHA1_Streams_Tests is
package Caller is new AUnit.Test_Caller (Fixture);
Test_Suite : aliased AUnit.Test_Suites.Test_Suite;
function Suite return AUnit.Test_Suites.Access_Test_Suite is
Name : constant String := "[HMAC_SHA1 - Ada.Streams] ";
begin
Test_Suite.Add_Test
(Caller.Create
(Name & "HMAC_SHA1() - RFC 2202 test vectors",
HMAC_SHA1_RFC2202_Test'Access));
return Test_Suite'Access;
end Suite;
procedure HMAC_SHA1_RFC2202_Test (Object : in out Fixture) is
function HMAC (Key, Message : String) return Stream_Element_Array renames
HMAC.HMAC_SHA_1.HMAC;
begin
declare
Ctx : Context :=
Initialize
(Stream_Element_Array'
(16#0b#, 16#0b#, 16#0b#, 16#0b#, 16#0b#, 16#0b#, 16#0b#,
16#0b#, 16#0b#, 16#0b#, 16#0b#, 16#0b#, 16#0b#, 16#0b#,
16#0b#, 16#0b#, 16#0b#, 16#0b#, 16#0b#, 16#0b#));
begin
Update (Ctx, "Hi There");
Assert
(Finalize (Ctx) =
Stream_Element_Array'
(16#b6#, 16#17#, 16#31#, 16#86#, 16#55#, 16#05#, 16#72#, 16#64#,
16#e2#, 16#8b#, 16#c0#, 16#b6#, 16#fb#, 16#37#, 16#8c#, 16#8e#,
16#f1#, 16#46#, 16#be#, 16#00#),
"test case no. 1");
end;
Assert
(HMAC (Key => "Jefe", Message => "what do ya want for nothing?") =
Stream_Element_Array'
(16#ef#, 16#fc#, 16#df#, 16#6a#, 16#e5#, 16#eb#, 16#2f#, 16#a2#,
16#d2#, 16#74#, 16#16#, 16#d5#, 16#f1#, 16#84#, 16#df#, 16#9c#,
16#25#, 16#9a#, 16#7c#, 16#79#),
"test case no. 2");
declare
Ctx : Context :=
Initialize (Stream_Element_Array'(1 .. 20 => 16#aa#));
begin
Update (Ctx, Stream_Element_Array'(1 .. 50 => 16#dd#));
Assert
(Finalize (Ctx) =
Stream_Element_Array'
(16#12#, 16#5d#, 16#73#, 16#42#, 16#b9#, 16#ac#, 16#11#, 16#cd#,
16#91#, 16#a3#, 16#9a#, 16#f4#, 16#8a#, 16#a1#, 16#7b#, 16#4f#,
16#63#, 16#f1#, 16#75#, 16#d3#),
"test case no. 3");
end;
declare
Ctx : Context :=
Initialize
(Stream_Element_Array'
(16#01#, 16#02#, 16#03#, 16#04#, 16#05#, 16#06#, 16#07#,
16#08#, 16#09#, 16#0a#, 16#0b#, 16#0c#, 16#0d#, 16#0e#,
16#0f#, 16#10#, 16#11#, 16#12#, 16#13#, 16#14#, 16#15#,
16#16#, 16#17#, 16#18#, 16#19#));
begin
Update (Ctx, Stream_Element_Array'(1 .. 50 => 16#cd#));
Assert
(Finalize (Ctx) =
Stream_Element_Array'
(16#4c#, 16#90#, 16#07#, 16#f4#, 16#02#, 16#62#, 16#50#, 16#c6#,
16#bc#, 16#84#, 16#14#, 16#f9#, 16#bf#, 16#50#, 16#c8#, 16#6c#,
16#2d#, 16#72#, 16#35#, 16#da#),
"test case no. 4");
end;
declare
Ctx : Context :=
Initialize (Stream_Element_Array'(1 .. 20 => 16#0c#));
begin
Update (Ctx, "Test With Truncation");
Assert
(Finalize (Ctx) =
Stream_Element_Array'
(16#4c#, 16#1a#, 16#03#, 16#42#, 16#4b#, 16#55#, 16#e0#, 16#7f#,
16#e7#, 16#f2#, 16#7b#, 16#e1#, 16#d5#, 16#8b#, 16#b9#, 16#32#,
16#4a#, 16#9a#, 16#5a#, 16#04#),
"test case no. 5");
end;
declare
Ctx : Context :=
Initialize (Stream_Element_Array'(1 .. 80 => 16#aa#));
begin
Update
(Ctx, "Test Using Larger Than Block-Size Key - Hash Key First");
Assert
(Finalize (Ctx) =
Stream_Element_Array'
(16#aa#, 16#4a#, 16#e5#, 16#e1#, 16#52#, 16#72#, 16#d0#, 16#0e#,
16#95#, 16#70#, 16#56#, 16#37#, 16#ce#, 16#8a#, 16#3b#, 16#55#,
16#ed#, 16#40#, 16#21#, 16#12#),
"test case no. 6");
end;
declare
Ctx : Context :=
Initialize (Stream_Element_Array'(1 .. 80 => 16#aa#));
begin
Update
(Ctx,
"Test Using Larger Than Block-Size Key and" &
" Larger Than One Block-Size Data");
Assert
(Finalize (Ctx) =
Stream_Element_Array'
(16#e8#, 16#e9#, 16#9d#, 16#0f#, 16#45#, 16#23#, 16#7d#, 16#78#,
16#6d#, 16#6b#, 16#ba#, 16#a7#, 16#96#, 16#5c#, 16#78#, 16#08#,
16#bb#, 16#ff#, 16#1a#, 16#91#),
"test case no. 7");
end;
end HMAC_SHA1_RFC2202_Test;
end HMAC_SHA1_Streams_Tests;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Record4 is
type R is record A, B: Character; end record;
type S is record C: Character; D: R; E: Character; end record;
V, W: R;
X, Y: S;
procedure PrintR(x: R) is
begin
Put('[');
Put(x.A);
Put(',');
Put(x.B);
Put(']');
end;
procedure PrintS(x: S) is
begin
Put('[');
Put(x.C);
Put(',');
PrintR(x.D);
Put(',');
Put(x.E);
Put(']');
end;
begin
V.A := '1';
V.B := '2';
X.C := '0';
X.D := V;
X.E := '3';
W.A := 'b';
W.B := 'c';
Y.C := 'a';
Y.D := W;
Y.E := 'd';
PrintS(X); New_Line;
PrintS(Y); New_Line;
if X = Y then Put('*'); else Put('.'); end if;
if X.D = W then Put('*'); else Put('.'); end if;
if X.D = Y.D then Put('*'); else Put('.'); end if;
if X.D.A = Y.D.A then Put('*'); else Put('.'); end if;
X.D := Y.D;
if X.D = W then Put('*'); else Put('.'); end if;
if X.D = Y.D then Put('*'); else Put('.'); end if;
if X.D.A = Y.D.A then Put('*'); else Put('.'); end if;
X := Y;
if X = Y then Put('*'); else Put('.'); end if;
if X.D = W then Put('*'); else Put('.'); end if;
if X.D = Y.D then Put('*'); else Put('.'); end if;
if X.D.A = Y.D.A then Put('*'); else Put('.'); end if;
New_Line;
end Record4;
-- Local Variables:
-- compile-command: "gnatmake record4.adb && ./record4"
-- End:
|
with Ada.Finalization;
with Ada.Iterator_Interfaces;
generic
type Key_Type is private;
type Element_Type is private;
type Hash_Type is mod <>;
type Change_Count is mod <>;
with function Hash (Key : Key_Type) return Hash_Type;
with function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
with function "=" (Left, Right : Element_Type) return Boolean is <>;
with procedure Destroy (Value : in out Element_Type) is null;
package Regions.Shared_Hashed_Maps is
pragma Preelaborate;
type Map is tagged private
with Constant_Indexing => Constant_Indexing,
Variable_Indexing => Variable_Indexing,
Default_Iterator => Iterate,
Iterator_Element => Element_Type;
function "=" (Left : Map; Right : Map) return Boolean;
-- Compare two maps. This is fast ifone was copied from another.
function Empty_Map (Active : not null access Change_Count) return Map;
-- Return an empty map object
procedure Insert
(Self : in out Map;
Key : Key_Type;
Item : Element_Type);
-- Insert (or replace) an item with given Key into the map
function Contains (Self : Map; Key : Key_Type) return Boolean;
-- Check if the map contain given key
function Element (Self : Map; Key : Key_Type) return Element_Type;
-- Return item by key
type Cursor is private;
function Has_Element (Self : Cursor) return Boolean;
-- Check if the cursor points to any element
package Iterator_Interfaces is new Ada.Iterator_Interfaces
(Cursor, Has_Element);
type Forward_Iterator is new Iterator_Interfaces.Forward_Iterator
with private;
function Iterate (Self : Map'Class) return Forward_Iterator;
-- Iterate over all elements in the map
function Key (Self : Cursor) return Key_Type;
-- Return key correponding to the cursor
function To_Element (Self : Cursor) return Element_Type;
-- Return Element pointed by the cursor
type Constant_Reference (Element : access constant Element_Type) is
null record
with Implicit_Dereference => Element;
function Constant_Indexing
(Self : Map;
Position : Cursor) return Constant_Reference;
type Variable_Reference (Element : access Element_Type) is null record
with Implicit_Dereference => Element;
function Variable_Indexing
(Self : in out Map;
Position : Cursor) return Variable_Reference;
No_Element : constant Cursor;
private
Slit_Bits : constant := 6;
Branches : constant := 2 ** 6;
type Unsigned_64 is mod 2 ** Branches;
subtype Bit_Count is Natural range 0 .. Branches;
subtype Bit_Index is Natural range 0 .. Branches - 1;
type Node;
type Node_Access is access all Node;
type Node_Access_Array is array (Bit_Count range <>) of Node_Access;
type Node (Length : Bit_Count) is record
Version : Change_Count;
Counter : Natural;
case Length is
when 0 =>
Hash : Hash_Type; -- Hash (Key)
Key : Key_Type;
Item : aliased Element_Type;
when 1 .. Branches =>
Mask : Unsigned_64;
Child : Node_Access_Array (1 .. Length);
end case;
end record;
type Map is new Ada.Finalization.Controlled with record
Active : not null access Change_Count;
Root : Node_Access;
end record;
overriding procedure Adjust (Self : in out Map);
overriding procedure Finalize (Self : in out Map);
subtype Tree_Depth is Bit_Count range 0 .. Hash_Type'Size / Slit_Bits + 1;
type Cursor (Length : Tree_Depth := 1) is record
Path : Node_Access_Array (1 .. Length);
end record;
type Forward_Iterator is new Iterator_Interfaces.Forward_Iterator
with record
First : Cursor;
end record;
overriding function First (Self : Forward_Iterator) return Cursor;
overriding function Next
(Self : Forward_Iterator;
Position : Cursor) return Cursor;
No_Element : constant Cursor := (Length => 0, others => <>);
end Regions.Shared_Hashed_Maps;
|
with ZMQ;
with Ada.Text_IO;
with Ada.Directories;
with Ada.Command_Line;
with GNAT.Command_Line;
procedure Getinfo is
use GNAT.Command_Line;
use Ada.Text_IO;
command_Name : constant String :=
Ada.Directories.Base_Name (Ada.Command_Line.Command_Name);
procedure Help;
procedure Help is
use ASCII;
begin
Put_Line
(command_Name & " [options]" & LF &
"Options:" & LF &
" --ada-library-version Print Ada-Library version" & LF &
" --binding-version Print Binding version" & LF &
" --library-version Print version of the 0mq library." & LF &
" -? | -h | --help Print this text");
end Help;
begin
loop
case Getopt ("-binding-version " &
"-ada-library-version " &
"-library-version " &
"-compiler-version " &
"h ? -help") is -- Accepts '-a', '-ad', or '-b argument'
when ASCII.NUL => exit;
when 'h' | '?' =>
Help;
return;
when '-' =>
if Full_Switch = "-binding-version" then
Put_Line (ZMQ.Image (ZMQ.Binding_Version));
elsif Full_Switch = "-library-version" then
Put_Line (ZMQ.Image (ZMQ.Library_Version));
elsif Full_Switch = "-compiler-version" then
Put_Line (Standard'Compiler_Version);
elsif Full_Switch = "-ada-library-version" then
Put_Line ($version);
elsif Full_Switch = "-help" then
Help;
return;
end if;
when others =>
raise Program_Error; -- cannot occur!
end case;
end loop;
loop
declare
S : constant String := Get_Argument (Do_Expansion => True);
begin
exit when S'Length = 0;
Put_Line ("Got " & S);
end;
end loop;
exception
when Invalid_Switch => Put_Line ("Invalid Switch " & Full_Switch);
when Invalid_Parameter => Put_Line ("No parameter for " & Full_Switch);
end Getinfo;
|
package body Spawn_Manager.Server is
-----------
-- Spawn --
-----------
Wait_Options_Map : constant array (Wait_Options) of Integer := (8, 1, 2);
function Spawn (Request : Spawn_Request) return Spawn_Response is
Args : GNAT.OS_Lib.Argument_List_Access;
Cursor : Integer;
begin
return Ret : Spawn_Response do
Args := new GNAT.OS_Lib.Argument_List (1 .. Integer (Request.Args.Length));
Cursor := Args.all'First;
for I of Request.Args loop
Args.all (Cursor) := new String'(To_String (I));
Cursor := Cursor + 1;
end loop;
case Request.Spawn_Type is
when Spawn_1 =>
GNAT.OS_Lib.Spawn
(Program_Name => To_String (Request.Program_Name),
Args => Args.all,
Success => Ret.Success);
when Spawn_2 =>
Ret.Return_Code := GNAT.OS_Lib.Spawn
(Program_Name => To_String (Request.Program_Name),
Args => Args.all);
when Spawn_3 =>
GNAT.OS_Lib.Spawn
(Program_Name => To_String (Request.Program_Name),
Args => Args.all,
Output_File => To_String (Request.Output_File),
Success => Ret.Success,
Return_Code => Ret.Return_Code,
Err_To_Out => Request.Err_To_Out);
when Non_Blocking_Spawn_1 =>
Ret.Pid := GNAT.OS_Lib.Non_Blocking_Spawn
(Program_Name => To_String (Request.Program_Name),
Args => Args.all);
when Non_Blocking_Spawn_2 =>
Ret.Pid := GNAT.OS_Lib.Non_Blocking_Spawn
(Program_Name => To_String (Request.Program_Name),
Args => Args.all,
Output_File => To_String (Request.Output_File),
Err_To_Out => Request.Err_To_Out);
when Wait_Process =>
GNAT.OS_Lib.Wait_Process (Ret.Pid, Ret.Success);
when Waitpid =>
declare
function I_Waitpid
(Pid : Process_Id;
Stat : not null access Integer;
Options : Integer) return Process_Id;
pragma Import (C, I_Waitpid, "waitpid");
begin
Ret.Pid := I_Waitpid (Request.Pid, Ret.Return_Code'Access, Wait_Options_Map (Request.Options));
end;
when Terminate_Server =>
raise Program_Error with "Shall never happend";
end case;
Free (Args);
end return;
end Spawn;
end Spawn_Manager.Server;
|
-- SipHash.Entropy
-- A child package that attempts to set the key from an entropy source on the
-- system.
-- This implementation loads bytes from /dev/urandom on Linux/Unix-like systems.
-- Copyright (c) 2015, James Humphry - see LICENSE file for details
with Ada.Streams, Ada.Streams.Stream_IO;
use Ada.Streams;
with System.Storage_Elements;
use System.Storage_Elements;
package body SipHash.Entropy
with SPARK_Mode => Off
is
pragma Compile_Time_Error (Storage_Element'Size > Stream_Element'Size,
"Cannot read entropy from /dev/urandom due to "&
"mis-matched Storage_Element'Size and "&
"Stream_Element'Size");
function System_Entropy_Source return Boolean is
(True);
procedure Set_Key_From_System_Entropy is
use Ada.Streams.Stream_IO;
Key : SipHash_Key;
Buffer : Stream_Element_Array(1..16);
Last : Stream_Element_Offset;
Dev_Urandom : File_Type;
begin
begin
Open(File => Dev_Urandom,
Mode => In_File,
Name => "/dev/urandom");
Read(File => Dev_Urandom,
Item => Buffer,
Last => Last);
exception
when others =>
raise Entropy_Unavailable
with "IO error when reading /dev/urandom.";
end;
if Last /= 16 then
raise Entropy_Unavailable
with "Insufficient entropy read from /dev/urandom.";
end if;
for I in Key'Range loop
Key(I) := Storage_Element'Mod(Buffer(Stream_Element_Offset(I)));
end loop;
Set_Key(Key);
end Set_Key_From_System_Entropy;
procedure Set_Key_From_System_Entropy (Success : out Boolean) is
begin
Set_Key_From_System_Entropy;
Success := True;
exception
when Entropy_Unavailable =>
Success := False;
end Set_Key_From_System_Entropy;
end SipHash.Entropy;
|
--
-- Copyright (C) 2017 Nico Huber <nico.h@gmx.de>
--
-- 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.
--
package HW.PCI
is
type Bus is range 0 .. 255;
type Slot is range 0 .. 31;
type Func is range 0 .. 7;
type Address is record
Bus : PCI.Bus;
Slot : PCI.Slot;
Func : PCI.Func;
end record;
type Index is range 0 .. 4095;
Vendor_Id : constant Index := 16#00#;
Device_Id : constant Index := 16#02#;
Command : constant Index := 16#04#;
Command_Memory : constant := 16#02#;
Header_Type : constant Index := 16#0e#;
Header_Type_Mask : constant := 16#7f#;
Header_Type_Normal : constant := 16#00#;
type Resource is (Res0, Res1, Res2, Res3, Res4, Res5);
Base_Address : constant array (Resource) of Index :=
(16#10#, 16#14#, 16#18#, 16#1c#, 16#20#, 16#24#);
Base_Address_Space_Mask : constant := 1 * 2 ** 0;
Base_Address_Space_IO : constant := 1 * 2 ** 0;
Base_Address_Space_Mem : constant := 0 * 2 ** 0;
Base_Address_Mem_Type_Mask : constant := 3 * 2 ** 1;
Base_Address_Mem_Type_32 : constant := 0 * 2 ** 1;
Base_Address_Mem_Type_1M : constant := 1 * 2 ** 1;
Base_Address_Mem_Type_64 : constant := 2 * 2 ** 1;
Base_Address_Mem_Prefetch : constant := 1 * 2 ** 3;
Base_Address_IO_Mask : constant := 16#ffff_fffc#;
Base_Address_Mem_Mask : constant := 16#ffff_fff0#;
private
use type HW.Word64;
function Calc_Base_Address (Base_Addr : Word64; Dev : Address) return Word64
is
(Base_Addr +
Word64 (Dev.Bus) * 32 * 8 * 4096 +
Word64 (Dev.Slot) * 8 * 4096 +
Word64 (Dev.Func) * 4096);
end HW.PCI;
|
-- @(#)File: logging-appender.ads
-- @(#)Last changed: Jul 21 2015 13:08:00
-- @(#)Purpose: Application and system logging
-- @(#)Author: Marc Bejerano <marcbejerano@gmail.com>
-- @(#)Copyright: Copyright (C) 2015, Marc Bejerano, All Rights Reserved
-- @(#)Product: None
-- @(#)License: BSD3
--
-- Copyright (c) 2015, Marc Bejerano
-- 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 ada-tools 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 Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Containers.Vectors; use Ada.Containers;
with Logging.Event; use Logging.Event;
package Logging.Appender is
--
-- Base appender object
--
type Appender is tagged record
Pattern : Unbounded_String := To_Unbounded_String("%d{ISO8601} [%-5p] %m%n");
end record;
--
-- Set the logger output format pattern for all log messages. See Format()
-- for formatting conversion codes.
-- @param aPattern Message output pattern
--
procedure Set_Pattern(aAppender: in out Appender; aPattern: in String);
--
-- Return the current message formatting pattern.
-- @return Formatting pattern
--
function Get_Pattern(aAppender: in Appender) return String;
--
-- Output the given string top the File_Appender. This being the
-- base Appender Put() function ... it does nothing. Just a stub.
-- @param aAppender Appender to write to
-- @param aEvent Event to log
-- @param aString MEssage to log
--
procedure Put(aAppender: in Appender; aEvent: in Log_Event);
--
-- Console appender object. All output goes to the console
--
type Console_Appender is new Appender with null record;
type Console_Appender_Ptr is access all Console_Appender;
--
-- Output the given string top the File_Appender
-- @param aAppender Appender to write to
-- @param aEvent Event to log
-- @param aString MEssage to log
--
procedure Put(aAppender: in Console_Appender; aEvent: in Log_Event);
--
-- File appender object. All output is appended to the named file.
--
type File_Appender is new Appender with record
File_Name: Unbounded_String;
end record;
type File_Appender_Ptr is access all File_Appender;
--
-- Output the given string top the File_Appender
-- @param aAppender Appender to write to
-- @param aEvent Event to log
-- @param aString MEssage to log
--
procedure Put(aAppender: in File_Appender; aEvent: in Log_Event);
--
-- Set the file appender output filename
-- @param aAppender Appender to update
-- @param aFileName Name of file
--
procedure Set_File_Name(aAppender: in out File_Appender; aFileName: in String);
--
-- Pointer to an object of class Appender
--
type Appender_Class_Ptr is access all Appender'Class;
--
-- Aliased vector container of Appenders
--
package Appender_Vectors is new Ada.Containers.Vectors(
Element_Type => Appender_Class_Ptr,
Index_Type => Positive);
end Logging.Appender;
|
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr>
-- MIT license. Please refer to the LICENSE file.
with Apsepp.Generic_Shared_Instance;
with Apsepp.Debug_Trace_Class; use Apsepp.Debug_Trace_Class;
package Apsepp.Debug_Trace is
package Shared_Instance
is new Generic_Shared_Instance (Debug_Trace_Interfa);
subtype Debug_Trace_Access is Shared_Instance.Instance_Type_Access;
function Debug_Trace return Debug_Trace_Access
renames Shared_Instance.Instance;
end Apsepp.Debug_Trace;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . T A G S --
-- --
-- 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. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Exceptions;
with Ada.Unchecked_Conversion;
with System.HTable;
with System.Storage_Elements; use System.Storage_Elements;
with System.WCh_Con; use System.WCh_Con;
with System.WCh_StW; use System.WCh_StW;
pragma Elaborate (System.HTable);
-- Elaborate needed instead of Elaborate_All to avoid elaboration cycles
-- when polling is turned on. This is safe because HTable doesn't do anything
-- at elaboration time; it just contains a generic package we want to
-- instantiate.
package body Ada.Tags is
-----------------------
-- Local Subprograms --
-----------------------
function Get_External_Tag (T : Tag) return System.Address;
-- Returns address of a null terminated string containing the external name
function Is_Primary_DT (T : Tag) return Boolean;
-- Given a tag returns True if it has the signature of a primary dispatch
-- table. This is Inline_Always since it is called from other Inline_
-- Always subprograms where we want no out of line code to be generated.
function IW_Membership
(Descendant_TSD : Type_Specific_Data_Ptr;
T : Tag) return Boolean;
-- Subsidiary function of IW_Membership and CW_Membership which factorizes
-- the functionality needed to check if a given descendant implements an
-- interface tag T.
function Length (Str : Cstring_Ptr) return Natural;
-- Length of string represented by the given pointer (treating the string
-- as a C-style string, which is Nul terminated). See comment in body
-- explaining why we cannot use the normal strlen built-in.
function OSD (T : Tag) return Object_Specific_Data_Ptr;
-- Ada 2005 (AI-251): Given a pointer T to a secondary dispatch table,
-- retrieve the address of the record containing the Object Specific
-- Data table.
function SSD (T : Tag) return Select_Specific_Data_Ptr;
-- Ada 2005 (AI-251): Given a pointer T to a dispatch Table, retrieves the
-- address of the record containing the Select Specific Data in T's TSD.
pragma Inline_Always (Get_External_Tag);
pragma Inline_Always (Is_Primary_DT);
pragma Inline_Always (OSD);
pragma Inline_Always (SSD);
-- Unchecked conversions
function To_Address is
new Unchecked_Conversion (Cstring_Ptr, System.Address);
function To_Cstring_Ptr is
new Unchecked_Conversion (System.Address, Cstring_Ptr);
-- Disable warnings on possible aliasing problem
function To_Tag is
new Unchecked_Conversion (Integer_Address, Tag);
function To_Addr_Ptr is
new Ada.Unchecked_Conversion (System.Address, Addr_Ptr);
function To_Address is
new Ada.Unchecked_Conversion (Tag, System.Address);
function To_Dispatch_Table_Ptr is
new Ada.Unchecked_Conversion (Tag, Dispatch_Table_Ptr);
function To_Dispatch_Table_Ptr is
new Ada.Unchecked_Conversion (System.Address, Dispatch_Table_Ptr);
function To_Object_Specific_Data_Ptr is
new Ada.Unchecked_Conversion (System.Address, Object_Specific_Data_Ptr);
function To_Tag_Ptr is
new Ada.Unchecked_Conversion (System.Address, Tag_Ptr);
function To_Type_Specific_Data_Ptr is
new Ada.Unchecked_Conversion (System.Address, Type_Specific_Data_Ptr);
-------------------------------
-- Inline_Always Subprograms --
-------------------------------
-- Inline_always subprograms must be placed before their first call to
-- avoid defeating the frontend inlining mechanism and thus ensure the
-- generation of their correct debug info.
-------------------
-- CW_Membership --
-------------------
-- Canonical implementation of Classwide Membership corresponding to:
-- Obj in Typ'Class
-- Each dispatch table contains a reference to a table of ancestors (stored
-- in the first part of the Tags_Table) and a count of the level of
-- inheritance "Idepth".
-- Obj is in Typ'Class if Typ'Tag is in the table of ancestors that are
-- contained in the dispatch table referenced by Obj'Tag . Knowing the
-- level of inheritance of both types, this can be computed in constant
-- time by the formula:
-- TSD (Obj'tag).Tags_Table (TSD (Obj'tag).Idepth - TSD (Typ'tag).Idepth)
-- = Typ'tag
function CW_Membership (Obj_Tag : Tag; Typ_Tag : Tag) return Boolean is
Obj_TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (Obj_Tag) - DT_Typeinfo_Ptr_Size);
Typ_TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (Typ_Tag) - DT_Typeinfo_Ptr_Size);
Obj_TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (Obj_TSD_Ptr.all);
Typ_TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (Typ_TSD_Ptr.all);
Pos : constant Integer := Obj_TSD.Idepth - Typ_TSD.Idepth;
begin
return Pos >= 0 and then Obj_TSD.Tags_Table (Pos) = Typ_Tag;
end CW_Membership;
----------------------
-- Get_External_Tag --
----------------------
function Get_External_Tag (T : Tag) return System.Address is
TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (TSD_Ptr.all);
begin
return To_Address (TSD.External_Tag);
end Get_External_Tag;
-----------------
-- Is_Abstract --
-----------------
function Is_Abstract (T : Tag) return Boolean is
TSD_Ptr : Addr_Ptr;
TSD : Type_Specific_Data_Ptr;
begin
if T = No_Tag then
raise Tag_Error;
end if;
TSD_Ptr := To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
TSD := To_Type_Specific_Data_Ptr (TSD_Ptr.all);
return TSD.Is_Abstract;
end Is_Abstract;
-------------------
-- Is_Primary_DT --
-------------------
function Is_Primary_DT (T : Tag) return Boolean is
begin
return DT (T).Signature = Primary_DT;
end Is_Primary_DT;
---------
-- OSD --
---------
function OSD (T : Tag) return Object_Specific_Data_Ptr is
OSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
begin
return To_Object_Specific_Data_Ptr (OSD_Ptr.all);
end OSD;
---------
-- SSD --
---------
function SSD (T : Tag) return Select_Specific_Data_Ptr is
TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (TSD_Ptr.all);
begin
return TSD.SSD;
end SSD;
-------------------------
-- External_Tag_HTable --
-------------------------
type HTable_Headers is range 1 .. 64;
-- The following internal package defines the routines used for the
-- instantiation of a new System.HTable.Static_HTable (see below). See
-- spec in g-htable.ads for details of usage.
package HTable_Subprograms is
procedure Set_HT_Link (T : Tag; Next : Tag);
function Get_HT_Link (T : Tag) return Tag;
function Hash (F : System.Address) return HTable_Headers;
function Equal (A, B : System.Address) return Boolean;
end HTable_Subprograms;
package External_Tag_HTable is new System.HTable.Static_HTable (
Header_Num => HTable_Headers,
Element => Dispatch_Table,
Elmt_Ptr => Tag,
Null_Ptr => null,
Set_Next => HTable_Subprograms.Set_HT_Link,
Next => HTable_Subprograms.Get_HT_Link,
Key => System.Address,
Get_Key => Get_External_Tag,
Hash => HTable_Subprograms.Hash,
Equal => HTable_Subprograms.Equal);
------------------------
-- HTable_Subprograms --
------------------------
-- Bodies of routines for hash table instantiation
package body HTable_Subprograms is
-----------
-- Equal --
-----------
function Equal (A, B : System.Address) return Boolean is
Str1 : constant Cstring_Ptr := To_Cstring_Ptr (A);
Str2 : constant Cstring_Ptr := To_Cstring_Ptr (B);
J : Integer;
begin
J := 1;
loop
if Str1 (J) /= Str2 (J) then
return False;
elsif Str1 (J) = ASCII.NUL then
return True;
else
J := J + 1;
end if;
end loop;
end Equal;
-----------------
-- Get_HT_Link --
-----------------
function Get_HT_Link (T : Tag) return Tag is
TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (TSD_Ptr.all);
begin
return TSD.HT_Link.all;
end Get_HT_Link;
----------
-- Hash --
----------
function Hash (F : System.Address) return HTable_Headers is
function H is new System.HTable.Hash (HTable_Headers);
Str : constant Cstring_Ptr := To_Cstring_Ptr (F);
Res : constant HTable_Headers := H (Str (1 .. Length (Str)));
begin
return Res;
end Hash;
-----------------
-- Set_HT_Link --
-----------------
procedure Set_HT_Link (T : Tag; Next : Tag) is
TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (TSD_Ptr.all);
begin
TSD.HT_Link.all := Next;
end Set_HT_Link;
end HTable_Subprograms;
------------------
-- Base_Address --
------------------
function Base_Address (This : System.Address) return System.Address is
begin
return This + Offset_To_Top (This);
end Base_Address;
---------------
-- Check_TSD --
---------------
procedure Check_TSD (TSD : Type_Specific_Data_Ptr) is
T : Tag;
E_Tag_Len : constant Integer := Length (TSD.External_Tag);
E_Tag : String (1 .. E_Tag_Len);
for E_Tag'Address use TSD.External_Tag.all'Address;
pragma Import (Ada, E_Tag);
Dup_Ext_Tag : constant String := "duplicated external tag """;
begin
-- Verify that the external tag of this TSD is not registered in the
-- runtime hash table.
T := External_Tag_HTable.Get (To_Address (TSD.External_Tag));
if T /= null then
-- Avoid concatenation, as it is not allowed in no run time mode
declare
Msg : String (1 .. Dup_Ext_Tag'Length + E_Tag_Len + 1);
begin
Msg (1 .. Dup_Ext_Tag'Length) := Dup_Ext_Tag;
Msg (Dup_Ext_Tag'Length + 1 .. Dup_Ext_Tag'Length + E_Tag_Len) :=
E_Tag;
Msg (Msg'Last) := '"';
raise Program_Error with Msg;
end;
end if;
end Check_TSD;
--------------------
-- Descendant_Tag --
--------------------
function Descendant_Tag (External : String; Ancestor : Tag) return Tag is
Int_Tag : constant Tag := Internal_Tag (External);
begin
if not Is_Descendant_At_Same_Level (Int_Tag, Ancestor) then
raise Tag_Error;
else
return Int_Tag;
end if;
end Descendant_Tag;
--------------
-- Displace --
--------------
function Displace (This : System.Address; T : Tag) return System.Address is
Iface_Table : Interface_Data_Ptr;
Obj_Base : System.Address;
Obj_DT : Dispatch_Table_Ptr;
Obj_DT_Tag : Tag;
begin
if System."=" (This, System.Null_Address) then
return System.Null_Address;
end if;
Obj_Base := Base_Address (This);
Obj_DT_Tag := To_Tag_Ptr (Obj_Base).all;
Obj_DT := DT (To_Tag_Ptr (Obj_Base).all);
Iface_Table := To_Type_Specific_Data_Ptr (Obj_DT.TSD).Interfaces_Table;
if Iface_Table /= null then
for Id in 1 .. Iface_Table.Nb_Ifaces loop
if Iface_Table.Ifaces_Table (Id).Iface_Tag = T then
-- Case of Static value of Offset_To_Top
if Iface_Table.Ifaces_Table (Id).Static_Offset_To_Top then
Obj_Base := Obj_Base -
Iface_Table.Ifaces_Table (Id).Offset_To_Top_Value;
-- Otherwise call the function generated by the expander to
-- provide the value.
else
Obj_Base := Obj_Base -
Iface_Table.Ifaces_Table (Id).Offset_To_Top_Func.all
(Obj_Base);
end if;
return Obj_Base;
end if;
end loop;
end if;
-- Check if T is an immediate ancestor. This is required to handle
-- conversion of class-wide interfaces to tagged types.
if CW_Membership (Obj_DT_Tag, T) then
return Obj_Base;
end if;
-- If the object does not implement the interface we must raise CE
raise Constraint_Error with "invalid interface conversion";
end Displace;
--------
-- DT --
--------
function DT (T : Tag) return Dispatch_Table_Ptr is
Offset : constant SSE.Storage_Offset :=
To_Dispatch_Table_Ptr (T).Prims_Ptr'Position;
begin
return To_Dispatch_Table_Ptr (To_Address (T) - Offset);
end DT;
-------------------
-- IW_Membership --
-------------------
function IW_Membership
(Descendant_TSD : Type_Specific_Data_Ptr;
T : Tag) return Boolean
is
Iface_Table : Interface_Data_Ptr;
begin
Iface_Table := Descendant_TSD.Interfaces_Table;
if Iface_Table /= null then
for Id in 1 .. Iface_Table.Nb_Ifaces loop
if Iface_Table.Ifaces_Table (Id).Iface_Tag = T then
return True;
end if;
end loop;
end if;
-- Look for the tag in the ancestor tags table. This is required for:
-- Iface_CW in Typ'Class
for Id in 0 .. Descendant_TSD.Idepth loop
if Descendant_TSD.Tags_Table (Id) = T then
return True;
end if;
end loop;
return False;
end IW_Membership;
-------------------
-- IW_Membership --
-------------------
-- Canonical implementation of Classwide Membership corresponding to:
-- Obj in Iface'Class
-- Each dispatch table contains a table with the tags of all the
-- implemented interfaces.
-- Obj is in Iface'Class if Iface'Tag is found in the table of interfaces
-- that are contained in the dispatch table referenced by Obj'Tag.
function IW_Membership (This : System.Address; T : Tag) return Boolean is
Obj_Base : System.Address;
Obj_DT : Dispatch_Table_Ptr;
Obj_TSD : Type_Specific_Data_Ptr;
begin
Obj_Base := Base_Address (This);
Obj_DT := DT (To_Tag_Ptr (Obj_Base).all);
Obj_TSD := To_Type_Specific_Data_Ptr (Obj_DT.TSD);
return IW_Membership (Obj_TSD, T);
end IW_Membership;
-------------------
-- Expanded_Name --
-------------------
function Expanded_Name (T : Tag) return String is
Result : Cstring_Ptr;
TSD_Ptr : Addr_Ptr;
TSD : Type_Specific_Data_Ptr;
begin
if T = No_Tag then
raise Tag_Error;
end if;
TSD_Ptr := To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
TSD := To_Type_Specific_Data_Ptr (TSD_Ptr.all);
Result := TSD.Expanded_Name;
return Result (1 .. Length (Result));
end Expanded_Name;
------------------
-- External_Tag --
------------------
function External_Tag (T : Tag) return String is
Result : Cstring_Ptr;
TSD_Ptr : Addr_Ptr;
TSD : Type_Specific_Data_Ptr;
begin
if T = No_Tag then
raise Tag_Error;
end if;
TSD_Ptr := To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
TSD := To_Type_Specific_Data_Ptr (TSD_Ptr.all);
Result := TSD.External_Tag;
return Result (1 .. Length (Result));
end External_Tag;
---------------------
-- Get_Entry_Index --
---------------------
function Get_Entry_Index (T : Tag; Position : Positive) return Positive is
begin
return SSD (T).SSD_Table (Position).Index;
end Get_Entry_Index;
----------------------
-- Get_Prim_Op_Kind --
----------------------
function Get_Prim_Op_Kind
(T : Tag;
Position : Positive) return Prim_Op_Kind
is
begin
return SSD (T).SSD_Table (Position).Kind;
end Get_Prim_Op_Kind;
----------------------
-- Get_Offset_Index --
----------------------
function Get_Offset_Index
(T : Tag;
Position : Positive) return Positive
is
begin
if Is_Primary_DT (T) then
return Position;
else
return OSD (T).OSD_Table (Position);
end if;
end Get_Offset_Index;
---------------------
-- Get_Tagged_Kind --
---------------------
function Get_Tagged_Kind (T : Tag) return Tagged_Kind is
begin
return DT (T).Tag_Kind;
end Get_Tagged_Kind;
-----------------------------
-- Interface_Ancestor_Tags --
-----------------------------
function Interface_Ancestor_Tags (T : Tag) return Tag_Array is
TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (TSD_Ptr.all);
Iface_Table : constant Interface_Data_Ptr := TSD.Interfaces_Table;
begin
if Iface_Table = null then
declare
Table : Tag_Array (1 .. 0);
begin
return Table;
end;
else
declare
Table : Tag_Array (1 .. Iface_Table.Nb_Ifaces);
begin
for J in 1 .. Iface_Table.Nb_Ifaces loop
Table (J) := Iface_Table.Ifaces_Table (J).Iface_Tag;
end loop;
return Table;
end;
end if;
end Interface_Ancestor_Tags;
------------------
-- Internal_Tag --
------------------
-- Internal tags have the following format:
-- "Internal tag at 16#ADDRESS#: <full-name-of-tagged-type>"
Internal_Tag_Header : constant String := "Internal tag at ";
Header_Separator : constant Character := '#';
function Internal_Tag (External : String) return Tag is
pragma Unsuppress (All_Checks);
-- To make T'Class'Input robust in the case of bad data
Res : Tag := null;
begin
-- Raise Tag_Error for empty strings and very long strings. This makes
-- T'Class'Input robust in the case of bad data, for example
--
-- String (123456789..1234)
--
-- The limit of 10,000 characters is arbitrary, but is unlikely to be
-- exceeded by legitimate external tag names.
if External'Length not in 1 .. 10_000 then
raise Tag_Error;
end if;
-- Handle locally defined tagged types
if External'Length > Internal_Tag_Header'Length
and then
External (External'First ..
External'First + Internal_Tag_Header'Length - 1) =
Internal_Tag_Header
then
declare
Addr_First : constant Natural :=
External'First + Internal_Tag_Header'Length;
Addr_Last : Natural;
Addr : Integer_Address;
begin
-- Search the second separator (#) to identify the address
Addr_Last := Addr_First;
for J in 1 .. 2 loop
while Addr_Last <= External'Last
and then External (Addr_Last) /= Header_Separator
loop
Addr_Last := Addr_Last + 1;
end loop;
-- Skip the first separator
if J = 1 then
Addr_Last := Addr_Last + 1;
end if;
end loop;
if Addr_Last <= External'Last then
-- Protect the run-time against wrong internal tags. We
-- cannot use exception handlers here because it would
-- disable the use of this run-time compiling with
-- restriction No_Exception_Handler.
declare
C : Character;
Wrong_Tag : Boolean := False;
begin
if External (Addr_First) /= '1'
or else External (Addr_First + 1) /= '6'
or else External (Addr_First + 2) /= '#'
then
Wrong_Tag := True;
else
for J in Addr_First + 3 .. Addr_Last - 1 loop
C := External (J);
if not (C in '0' .. '9')
and then not (C in 'A' .. 'F')
and then not (C in 'a' .. 'f')
then
Wrong_Tag := True;
exit;
end if;
end loop;
end if;
-- Convert the numeric value into a tag
if not Wrong_Tag then
Addr := Integer_Address'Value
(External (Addr_First .. Addr_Last));
-- Internal tags never have value 0
if Addr /= 0 then
return To_Tag (Addr);
end if;
end if;
end;
end if;
end;
-- Handle library-level tagged types
else
-- Make NUL-terminated copy of external tag string
declare
Ext_Copy : aliased String (External'First .. External'Last + 1);
pragma Assert (Ext_Copy'Length > 1); -- See Length check at top
begin
Ext_Copy (External'Range) := External;
Ext_Copy (Ext_Copy'Last) := ASCII.NUL;
Res := External_Tag_HTable.Get (Ext_Copy'Address);
end;
end if;
if Res = null then
declare
Msg1 : constant String := "unknown tagged type: ";
Msg2 : String (1 .. Msg1'Length + External'Length);
begin
Msg2 (1 .. Msg1'Length) := Msg1;
Msg2 (Msg1'Length + 1 .. Msg1'Length + External'Length) :=
External;
Ada.Exceptions.Raise_Exception (Tag_Error'Identity, Msg2);
end;
end if;
return Res;
end Internal_Tag;
---------------------------------
-- Is_Descendant_At_Same_Level --
---------------------------------
function Is_Descendant_At_Same_Level
(Descendant : Tag;
Ancestor : Tag) return Boolean
is
begin
if Descendant = Ancestor then
return True;
else
declare
D_TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (Descendant) - DT_Typeinfo_Ptr_Size);
A_TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (Ancestor) - DT_Typeinfo_Ptr_Size);
D_TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (D_TSD_Ptr.all);
A_TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (A_TSD_Ptr.all);
begin
return
D_TSD.Access_Level = A_TSD.Access_Level
and then (CW_Membership (Descendant, Ancestor)
or else IW_Membership (D_TSD, Ancestor));
end;
end if;
end Is_Descendant_At_Same_Level;
------------
-- Length --
------------
-- Note: This unit is used in the Ravenscar runtime library, so it cannot
-- depend on System.CTRL. Furthermore, this happens on CPUs where the GCC
-- intrinsic strlen may not be available, so we need to recode our own Ada
-- version here.
function Length (Str : Cstring_Ptr) return Natural is
Len : Integer;
begin
Len := 1;
while Str (Len) /= ASCII.NUL loop
Len := Len + 1;
end loop;
return Len - 1;
end Length;
-------------------
-- Offset_To_Top --
-------------------
function Offset_To_Top
(This : System.Address) return SSE.Storage_Offset
is
Tag_Size : constant SSE.Storage_Count :=
SSE.Storage_Count (1 * (Standard'Address_Size / System.Storage_Unit));
type Storage_Offset_Ptr is access SSE.Storage_Offset;
function To_Storage_Offset_Ptr is
new Unchecked_Conversion (System.Address, Storage_Offset_Ptr);
Curr_DT : Dispatch_Table_Ptr;
begin
Curr_DT := DT (To_Tag_Ptr (This).all);
-- See the documentation of Dispatch_Table_Wrapper.Offset_To_Top
if Curr_DT.Offset_To_Top = SSE.Storage_Offset'Last then
-- The parent record type has variable-size components, so the
-- instance-specific offset is stored in the tagged record, right
-- after the reference to Curr_DT (which is a secondary dispatch
-- table).
return To_Storage_Offset_Ptr (This + Tag_Size).all;
else
-- The offset is compile-time known, so it is simply stored in the
-- Offset_To_Top field.
return Curr_DT.Offset_To_Top;
end if;
end Offset_To_Top;
------------------------
-- Needs_Finalization --
------------------------
function Needs_Finalization (T : Tag) return Boolean is
TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (TSD_Ptr.all);
begin
return TSD.Needs_Finalization;
end Needs_Finalization;
-----------------
-- Parent_Size --
-----------------
function Parent_Size
(Obj : System.Address;
T : Tag) return SSE.Storage_Count
is
Parent_Slot : constant Positive := 1;
-- The tag of the parent is always in the first slot of the table of
-- ancestor tags.
TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (TSD_Ptr.all);
-- Pointer to the TSD
Parent_Tag : constant Tag := TSD.Tags_Table (Parent_Slot);
Parent_TSD_Ptr : constant Addr_Ptr :=
To_Addr_Ptr (To_Address (Parent_Tag) - DT_Typeinfo_Ptr_Size);
Parent_TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (Parent_TSD_Ptr.all);
begin
-- Here we compute the size of the _parent field of the object
return SSE.Storage_Count (Parent_TSD.Size_Func.all (Obj));
end Parent_Size;
----------------
-- Parent_Tag --
----------------
function Parent_Tag (T : Tag) return Tag is
TSD_Ptr : Addr_Ptr;
TSD : Type_Specific_Data_Ptr;
begin
if T = No_Tag then
raise Tag_Error;
end if;
TSD_Ptr := To_Addr_Ptr (To_Address (T) - DT_Typeinfo_Ptr_Size);
TSD := To_Type_Specific_Data_Ptr (TSD_Ptr.all);
-- The Parent_Tag of a root-level tagged type is defined to be No_Tag.
-- The first entry in the Ancestors_Tags array will be null for such
-- a type, but it's better to be explicit about returning No_Tag in
-- this case.
if TSD.Idepth = 0 then
return No_Tag;
else
return TSD.Tags_Table (1);
end if;
end Parent_Tag;
-------------------------------
-- Register_Interface_Offset --
-------------------------------
procedure Register_Interface_Offset
(Prim_T : Tag;
Interface_T : Tag;
Is_Static : Boolean;
Offset_Value : SSE.Storage_Offset;
Offset_Func : Offset_To_Top_Function_Ptr)
is
Prim_DT : constant Dispatch_Table_Ptr := DT (Prim_T);
Iface_Table : constant Interface_Data_Ptr :=
To_Type_Specific_Data_Ptr (Prim_DT.TSD).Interfaces_Table;
begin
-- Save Offset_Value in the table of interfaces of the primary DT.
-- This data will be used by the subprogram "Displace" to give support
-- to backward abstract interface type conversions.
-- Register the offset in the table of interfaces
if Iface_Table /= null then
for Id in 1 .. Iface_Table.Nb_Ifaces loop
if Iface_Table.Ifaces_Table (Id).Iface_Tag = Interface_T then
if Is_Static or else Offset_Value = 0 then
Iface_Table.Ifaces_Table (Id).Static_Offset_To_Top := True;
Iface_Table.Ifaces_Table (Id).Offset_To_Top_Value :=
Offset_Value;
else
Iface_Table.Ifaces_Table (Id).Static_Offset_To_Top := False;
Iface_Table.Ifaces_Table (Id).Offset_To_Top_Func :=
Offset_Func;
end if;
return;
end if;
end loop;
end if;
-- If we arrive here there is some error in the run-time data structure
raise Program_Error;
end Register_Interface_Offset;
------------------
-- Register_Tag --
------------------
procedure Register_Tag (T : Tag) is
begin
External_Tag_HTable.Set (T);
end Register_Tag;
-------------------
-- Secondary_Tag --
-------------------
function Secondary_Tag (T, Iface : Tag) return Tag is
Iface_Table : Interface_Data_Ptr;
Obj_DT : Dispatch_Table_Ptr;
begin
if not Is_Primary_DT (T) then
raise Program_Error;
end if;
Obj_DT := DT (T);
Iface_Table := To_Type_Specific_Data_Ptr (Obj_DT.TSD).Interfaces_Table;
if Iface_Table /= null then
for Id in 1 .. Iface_Table.Nb_Ifaces loop
if Iface_Table.Ifaces_Table (Id).Iface_Tag = Iface then
return Iface_Table.Ifaces_Table (Id).Secondary_DT;
end if;
end loop;
end if;
-- If the object does not implement the interface we must raise CE
raise Constraint_Error with "invalid interface conversion";
end Secondary_Tag;
---------------------
-- Set_Entry_Index --
---------------------
procedure Set_Entry_Index
(T : Tag;
Position : Positive;
Value : Positive)
is
begin
SSD (T).SSD_Table (Position).Index := Value;
end Set_Entry_Index;
-------------------------------
-- Set_Dynamic_Offset_To_Top --
-------------------------------
procedure Set_Dynamic_Offset_To_Top
(This : System.Address;
Prim_T : Tag;
Interface_T : Tag;
Offset_Value : SSE.Storage_Offset;
Offset_Func : Offset_To_Top_Function_Ptr)
is
Sec_Base : System.Address;
Sec_DT : Dispatch_Table_Ptr;
begin
-- Save the offset to top field in the secondary dispatch table
if Offset_Value /= 0 then
Sec_Base := This - Offset_Value;
Sec_DT := DT (To_Tag_Ptr (Sec_Base).all);
Sec_DT.Offset_To_Top := SSE.Storage_Offset'Last;
end if;
Register_Interface_Offset
(Prim_T, Interface_T, False, Offset_Value, Offset_Func);
end Set_Dynamic_Offset_To_Top;
----------------------
-- Set_Prim_Op_Kind --
----------------------
procedure Set_Prim_Op_Kind
(T : Tag;
Position : Positive;
Value : Prim_Op_Kind)
is
begin
SSD (T).SSD_Table (Position).Kind := Value;
end Set_Prim_Op_Kind;
--------------------
-- Unregister_Tag --
--------------------
procedure Unregister_Tag (T : Tag) is
begin
External_Tag_HTable.Remove (Get_External_Tag (T));
end Unregister_Tag;
------------------------
-- Wide_Expanded_Name --
------------------------
WC_Encoding : Character;
pragma Import (C, WC_Encoding, "__gl_wc_encoding");
-- Encoding method for source, as exported by binder
function Wide_Expanded_Name (T : Tag) return Wide_String is
S : constant String := Expanded_Name (T);
W : Wide_String (1 .. S'Length);
L : Natural;
begin
String_To_Wide_String
(S, W, L, Get_WC_Encoding_Method (WC_Encoding));
return W (1 .. L);
end Wide_Expanded_Name;
-----------------------------
-- Wide_Wide_Expanded_Name --
-----------------------------
function Wide_Wide_Expanded_Name (T : Tag) return Wide_Wide_String is
S : constant String := Expanded_Name (T);
W : Wide_Wide_String (1 .. S'Length);
L : Natural;
begin
String_To_Wide_Wide_String
(S, W, L, Get_WC_Encoding_Method (WC_Encoding));
return W (1 .. L);
end Wide_Wide_Expanded_Name;
end Ada.Tags;
|
-- POK header
--
-- The following file is a part of the POK project. Any modification should
-- be made according to the POK licence. You CANNOT use this file or a part
-- of a file for your own project.
--
-- For more information on the POK licence, please see our LICENCE FILE
--
-- Please follow the coding guidelines described in doc/CODING_GUIDELINES
--
-- Copyright (c) 2007-2020 POK team
-- ---------------------------------------------------------------------------
-- --
-- TIME constant and type definitions and management services --
-- --
-- ---------------------------------------------------------------------------
package APEX.Timing is
procedure Timed_Wait
(Delay_Time : in System_Time_Type;
Return_Code : out Return_Code_Type);
procedure Periodic_Wait (Return_Code : out Return_Code_Type);
procedure Get_Time
(System_Time : out System_Time_Type;
Return_Code : out Return_Code_Type);
procedure Replenish
(Budget_Time : in System_Time_Type;
Return_Code : out Return_Code_Type);
-- POK BINDINGS
pragma Import (C, Timed_Wait, "TIMED_WAIT");
pragma Import (C, Periodic_Wait, "PERIODIC_WAIT");
pragma Import (C, Get_Time, "GET_TIME");
pragma Import (C, Replenish, "REPLENISH");
-- END OF POK BINDINGS
end Apex.Timing;
|
--
-- Copyright (C) 2021 Jeremy Grosser <jeremy@synack.me>
--
-- SPDX-License-Identifier: BSD-3-Clause
--
with HAL.Time;
with HAL.GPIO;
with HAL.SPI;
with HAL;
package ST7789 is
type ST7789_Screen
(CS : not null HAL.GPIO.Any_GPIO_Point;
DC : not null HAL.GPIO.Any_GPIO_Point;
RST : HAL.GPIO.Any_GPIO_Point;
Port : not null HAL.SPI.Any_SPI_Port;
Time : not null HAL.Time.Any_Delays)
is tagged null record;
-- These register names come from the ST7735S datasheet, just for extra confusion.
type Register is
(SWRESET,
SLPOUT,
INVOFF,
INVON,
GAMSET,
DISPOFF,
DISPON,
CASET,
RASET,
RAMWR,
TEON,
MADCTL,
COLMOD,
FRMCTR1,
FRMCTR2,
GCTRL,
VCOMS,
LCMCTRL,
VDVVRHEN,
VRHS,
VDVS,
FRCTRL2,
PWRCTRL1,
GMCTRP1,
GMCTRN1);
procedure Initialize
(This : in out ST7789_Screen);
procedure Write
(This : in out ST7789_Screen;
Reg : Register);
procedure Write
(This : in out ST7789_Screen;
Reg : Register;
Data : HAL.UInt8);
procedure Write
(This : in out ST7789_Screen;
Reg : Register;
Data : HAL.UInt8_Array);
type RGB565 is record
R : HAL.UInt5;
G : HAL.UInt6;
B : HAL.UInt5;
end record
with Size => 16;
for RGB565 use record
R at 0 range 11 .. 15;
G at 0 range 5 .. 10;
B at 0 range 0 .. 4;
end record;
type Pixels is array (Integer range <>) of RGB565
with Component_Size => 16;
procedure Write
(This : in out ST7789_Screen;
Data : Pixels);
private
for Register'Size use 8;
for Register use
(SWRESET => 16#01#,
SLPOUT => 16#11#,
INVOFF => 16#20#,
INVON => 16#21#,
GAMSET => 16#26#,
DISPOFF => 16#28#,
DISPON => 16#29#,
CASET => 16#2A#,
RASET => 16#2B#,
RAMWR => 16#2C#,
TEON => 16#35#,
MADCTL => 16#36#,
COLMOD => 16#3A#,
FRMCTR1 => 16#B1#,
FRMCTR2 => 16#B2#,
GCTRL => 16#B7#,
VCOMS => 16#BB#,
LCMCTRL => 16#C0#,
VDVVRHEN => 16#C2#,
VRHS => 16#C3#,
VDVS => 16#C4#,
FRCTRL2 => 16#C6#,
PWRCTRL1 => 16#D0#,
GMCTRP1 => 16#E0#,
GMCTRN1 => 16#E1#);
end ST7789;
|
pragma Ada_2005;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with System;
limited with CUPS.bits_pthreadtypes_h;
with CUPS.bits_types_h;
private package CUPS.bits_siginfo_h is
-- unsupported macro: sigev_notify_function _sigev_un._sigev_thread._function
-- unsupported macro: sigev_notify_attributes _sigev_un._sigev_thread._attribute
-- unsupported macro: SIGEV_SIGNAL SIGEV_SIGNAL
-- unsupported macro: SIGEV_NONE SIGEV_NONE
-- unsupported macro: SIGEV_THREAD SIGEV_THREAD
-- unsupported macro: SIGEV_THREAD_ID SIGEV_THREAD_ID
-- siginfo_t, sigevent and constants. Linux x86-64 version.
-- Copyright (C) 2012-2016 Free Software Foundation, Inc.
-- This file is part of the GNU C Library.
-- The GNU C 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.
-- The GNU C 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 the GNU C Library; if not, see
-- <http://www.gnu.org/licenses/>.
-- Type for data associated with a signal.
type sigval (discr : unsigned := 0) is record
case discr is
when 0 =>
sival_int : aliased int; -- bits/siginfo.h:34
when others =>
sival_ptr : System.Address; -- bits/siginfo.h:35
end case;
end record;
pragma Convention (C_Pass_By_Copy, sigval);
pragma Unchecked_Union (sigval); -- bits/siginfo.h:32
subtype sigval_t is sigval;
-- si_utime and si_stime must be 4 byte aligned for x32 to match the
-- kernel. We align siginfo_t to 8 bytes so that si_utime and si_stime
-- are actually aligned to 8 bytes since their offsets are multiple of
-- 8 bytes.
-- Signal number.
-- If non-zero, an errno value associated with
-- this signal, as defined in <errno.h>.
-- Signal code.
-- kill().
-- Sending process ID.
-- Real user ID of sending process.
-- POSIX.1b timers.
-- Timer ID.
-- Overrun count.
-- Signal value.
-- POSIX.1b signals.
-- Sending process ID.
-- Real user ID of sending process.
-- Signal value.
-- SIGCHLD.
-- Which child.
-- Real user ID of sending process.
-- Exit value or signal.
-- SIGILL, SIGFPE, SIGSEGV, SIGBUS.
-- Faulting insn/memory ref.
-- Valid LSB of the reported address.
-- SIGPOLL.
-- Band event for SIGPOLL.
-- SIGSYS.
-- Calling user insn.
-- Triggering system call number.
-- AUDIT_ARCH_* of syscall.
-- X/Open requires some more fields with fixed names.
-- Values for `si_code'. Positive values are reserved for kernel-generated
-- signals.
-- Sent by asynch name lookup completion.
-- Sent by tkill.
-- Sent by queued SIGIO.
-- Sent by AIO completion.
-- Sent by real time mesq state change.
-- Sent by timer expiration.
-- Sent by sigqueue.
-- Sent by kill, sigsend.
-- Send by kernel.
-- `si_code' values for SIGILL signal.
-- Illegal opcode.
-- Illegal operand.
-- Illegal addressing mode.
-- Illegal trap.
-- Privileged opcode.
-- Privileged register.
-- Coprocessor error.
-- Internal stack error.
-- `si_code' values for SIGFPE signal.
-- Integer divide by zero.
-- Integer overflow.
-- Floating point divide by zero.
-- Floating point overflow.
-- Floating point underflow.
-- Floating point inexact result.
-- Floating point invalid operation.
-- Subscript out of range.
-- `si_code' values for SIGSEGV signal.
-- Address not mapped to object.
-- Invalid permissions for mapped object.
-- `si_code' values for SIGBUS signal.
-- Invalid address alignment.
-- Non-existant physical address.
-- Object specific hardware error.
-- Hardware memory error: action required.
-- Hardware memory error: action optional.
-- `si_code' values for SIGTRAP signal.
-- Process breakpoint.
-- Process trace trap.
-- `si_code' values for SIGCHLD signal.
-- Child has exited.
-- Child was killed.
-- Child terminated abnormally.
-- Traced child has trapped.
-- Child has stopped.
-- Stopped child has continued.
-- `si_code' values for SIGPOLL signal.
-- Data input available.
-- Output buffers available.
-- Input message available.
-- I/O error.
-- High priority input available.
-- Device disconnected.
-- Structure to transport application-defined values with signals.
-- Forward declaration.
type sigevent;
type anon_33;
type anon_34 is record
u_function : access procedure (arg1 : sigval_t); -- bits/siginfo.h:336
u_attribute : access CUPS.bits_pthreadtypes_h.pthread_attr_t; -- bits/siginfo.h:337
end record;
pragma Convention (C_Pass_By_Copy, anon_34);
type sigevent_u_pad_array is array (0 .. 11) of aliased int;
type anon_33 (discr : unsigned := 0) is record
case discr is
when 0 =>
u_pad : aliased sigevent_u_pad_array; -- bits/siginfo.h:328
when 1 =>
u_tid : aliased CUPS.bits_types_h.uu_pid_t; -- bits/siginfo.h:332
when others =>
u_sigev_thread : aliased anon_34; -- bits/siginfo.h:338
end case;
end record;
pragma Convention (C_Pass_By_Copy, anon_33);
pragma Unchecked_Union (anon_33);type sigevent is record
sigev_value : aliased sigval_t; -- bits/siginfo.h:322
sigev_signo : aliased int; -- bits/siginfo.h:323
sigev_notify : aliased int; -- bits/siginfo.h:324
u_sigev_un : aliased anon_33; -- bits/siginfo.h:339
end record;
pragma Convention (C_Pass_By_Copy, sigevent); -- bits/siginfo.h:320
-- When SIGEV_SIGNAL and SIGEV_THREAD_ID set, LWP ID of the
-- thread to receive the signal.
-- Function to start.
-- Thread attributes.
subtype sigevent_t is sigevent;
-- POSIX names to access some of the members.
-- `sigev_notify' values.
-- Notify via signal.
-- Other notification: meaningless.
-- Deliver via thread creation.
-- Send signal to specific thread.
end CUPS.bits_siginfo_h;
|
-- { dg-do compile }
with Ada.Characters.Handling; use Ada.Characters.Handling;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with Text_IO; use Text_IO;
package body Noreturn5 is
procedure Proc (Arg_Line : Wide_String; Keep_Going : Boolean) is
begin
Put (To_String (Arg_Line));
if Keep_Going then
raise Constraint_Error;
else
OS_Exit (1);
end if;
exception
when Constraint_Error =>
raise;
when others =>
if Keep_Going then
raise Constraint_Error;
else
OS_Exit (1);
end if;
end;
end Noreturn5;
|
with Giza.Colors; use Giza.Colors;
with Giza.GUI; use Giza.GUI;
with Engine_Control_Events; use Engine_Control_Events;
package body Engine_Control_UI is
Set_PP_Evt : aliased Set_PP_Event;
-------------
-- On_Init --
-------------
procedure On_Init (This : in out Engine_Control_Window) is
begin
This.RPM_Widget := new RPM;
This.RPM_Widget.Set_Background (White);
This.RPM_Widget.Set_Foreground (Black);
This.RPM_Widget.Disable_Frame;
This.RPM_Widget.Set_Size ((This.Get_Size.W - 2, 38));
This.Add_Child (This.RPM_Widget, (1, 1));
This.PP := new PP_Widget;
This.PP.Set_Background (White);
This.PP.Set_Foreground (Red);
This.PP.Disable_Frame;
This.PP.Set_Size ((This.Get_Size.W - 2, 160));
This.Add_Child (This.PP, (1, 41));
This.Tabs := new Gtabs (2);
This.Tabs.Set_Size ((This.Get_Size.W, 116));
This.Manual := new Composite_Widget;
This.Auto := new Composite_Widget;
This.Tabs.Set_Tab (1, "MANUAL", This.Manual);
This.Tabs.Set_Tab (2, "AUTO", This.Auto);
This.Add_Child (This.Tabs, (0, 202));
This.Ignition := new Gnumber_Select;
This.Ignition.Set_Size ((This.Get_Size.W, 42));
This.Ignition.Set_Label ("Ignition");
This.Ignition.Set_Min (0);
This.Ignition.Set_Max (100);
This.Ignition.Set_Step (5);
This.Ignition.Set_Value (25);
This.Duration := new Gnumber_Select;
This.Duration.Set_Size ((This.Get_Size.W, 42));
This.Duration.Set_Label ("Duration");
This.Duration.Set_Min (0);
This.Duration.Set_Max (100);
This.Duration.Set_Step (5);
This.Duration.Set_Value (50);
This.Manual.Add_Child (This.Ignition, (0, 0));
This.Manual.Add_Child (This.Duration, (0, 43));
This.Tabs.Set_Selected (1);
This.Target_RPM := new Gnumber_Select;
This.Target_RPM.Set_Label ("Target RPM");
This.Target_RPM.Set_Size ((This.Get_Size.W, 85));
This.Target_RPM.Set_Min (200);
This.Target_RPM.Set_Max (2500);
This.Target_RPM.Set_Step (100);
This.Target_RPM.Set_Value (1500);
This.Target_RPM.Show_Value;
This.Auto.Add_Child (This.Target_RPM, (0, 0));
This.Background := new Gbackground;
This.Background.Set_Background (Black);
This.Background.Set_Size (This.Get_Size);
This.Add_Child (This.Background, (0, 0));
end On_Init;
------------------
-- On_Displayed --
------------------
procedure On_Displayed (This : in out Engine_Control_Window) is
begin
null;
end On_Displayed;
---------------
-- On_Hidden --
---------------
procedure On_Hidden (This : in out Engine_Control_Window) is
begin
null;
end On_Hidden;
-----------------------
-- On_Position_Event --
-----------------------
function On_Position_Event
(This : in out Engine_Control_Window;
Evt : Position_Event_Ref;
Pos : Point_T) return Boolean
is
begin
if Giza.Widgets.Composite.On_Position_Event
(Giza.Widgets.Composite.Composite_Widget (This), Evt, Pos)
then
Set_PP_Evt := (Ignition => This.Ignition.Value,
Duration => This.Duration.Value);
Giza.GUI.Emit (Set_PP_Evt'Access);
return True;
else
return False;
end if;
end On_Position_Event;
end Engine_Control_UI;
|
-------------------------------------------------------------------------------
-- package Disorderly.Random.Clock_Entropy, Random Number Initialization
-- Copyright (C) 1995-2018 Jonathan S. Parker
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-------------------------------------------------------------------------------
-- PACKAGE Disorderly.Random.Clock_Entropy
--
-- Clock provides a few bits of entropy to help find a unique initial seed.
--
-- Calendar.Clock is used here by procedure Reset to help choose the initial
-- State, S, for calls to the random number generator, Get_Random.
--
-- Want Disorderly.Random to be Pure and thread-safe, but
-- Package Calendar is not pure. That is why the Calendar based
-- Reset is placed here, a child package of Disorderly.Random.
package Disorderly.Random.Clock_Entropy is
procedure Reset (S : out State);
-- procedure Reset_with_Calendar initializes State S.
-- It calls Calendar (along with 2 calls to the delay statement) in
-- an attempt to get a unique State each time Reset is called.
--
-- All we need is 1 bit of difference between the outputs of two
-- successive calls to Ada.Calendar.Clock, and the two 256 bit
-- states generated by the successive calls will have no apparent
-- similarities. (Not remotely good enough for cryptography, but
-- very useful for Monte-Carlo applications.)
end Disorderly.Random.Clock_Entropy;
|
-- $Header:$
--
--
-- NOTES
-- This file is added by Umass for the purpose of adding more error recovery
-- power to Ayacc.
--
package Error_Report_File is
--
-- TITLE: package Error_Report_File
-- Output the code which allows users to see what the error token was.
--
-- LANGUAGE:
-- Ada
--
-- PERSONNEL:
-- AUTHOR: Benjamin Hurwitz
-- DATE: Jul 27 1990
--
-- OVERVIEW:
-- Export the procedure Write_File which outputs all the code to the
-- file {base_name}_error_report.a
--
-- UPDATES:
--
procedure Write_File;
end Error_Report_File;
|
-- This spec has been automatically generated from STM32WB55x.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.COMP is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype COMP1_CSR_PWRMODE_Field is HAL.UInt2;
subtype COMP1_CSR_INMSEL_Field is HAL.UInt3;
subtype COMP1_CSR_INPSEL_Field is HAL.UInt2;
subtype COMP1_CSR_HYST_Field is HAL.UInt2;
subtype COMP1_CSR_BLANKING_Field is HAL.UInt3;
subtype COMP1_CSR_INMESEL_Field is HAL.UInt2;
type COMP1_CSR_Register is record
EN : Boolean := False;
-- unspecified
Reserved_1_1 : HAL.Bit := 16#0#;
PWRMODE : COMP1_CSR_PWRMODE_Field := 16#0#;
INMSEL : COMP1_CSR_INMSEL_Field := 16#0#;
INPSEL : COMP1_CSR_INPSEL_Field := 16#0#;
-- unspecified
Reserved_9_14 : HAL.UInt6 := 16#0#;
POLARITY : Boolean := False;
HYST : COMP1_CSR_HYST_Field := 16#0#;
BLANKING : COMP1_CSR_BLANKING_Field := 16#0#;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
BRGEN : Boolean := False;
SCALEN : Boolean := False;
-- unspecified
Reserved_24_24 : HAL.Bit := 16#0#;
INMESEL : COMP1_CSR_INMESEL_Field := 16#0#;
-- unspecified
Reserved_27_29 : HAL.UInt3 := 16#0#;
VALUE : Boolean := False;
LOCK : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for COMP1_CSR_Register use record
EN at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
PWRMODE at 0 range 2 .. 3;
INMSEL at 0 range 4 .. 6;
INPSEL at 0 range 7 .. 8;
Reserved_9_14 at 0 range 9 .. 14;
POLARITY at 0 range 15 .. 15;
HYST at 0 range 16 .. 17;
BLANKING at 0 range 18 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
BRGEN at 0 range 22 .. 22;
SCALEN at 0 range 23 .. 23;
Reserved_24_24 at 0 range 24 .. 24;
INMESEL at 0 range 25 .. 26;
Reserved_27_29 at 0 range 27 .. 29;
VALUE at 0 range 30 .. 30;
LOCK at 0 range 31 .. 31;
end record;
subtype COMP2_CSR_PWRMODE_Field is HAL.UInt2;
subtype COMP2_CSR_INMSEL_Field is HAL.UInt3;
subtype COMP2_CSR_INPSEL_Field is HAL.UInt2;
subtype COMP2_CSR_HYST_Field is HAL.UInt2;
subtype COMP2_CSR_BLANKING_Field is HAL.UInt3;
subtype COMP2_CSR_INMESEL_Field is HAL.UInt2;
type COMP2_CSR_Register is record
EN : Boolean := False;
-- unspecified
Reserved_1_1 : HAL.Bit := 16#0#;
PWRMODE : COMP2_CSR_PWRMODE_Field := 16#0#;
INMSEL : COMP2_CSR_INMSEL_Field := 16#0#;
INPSEL : COMP2_CSR_INPSEL_Field := 16#0#;
WINMODE : Boolean := False;
-- unspecified
Reserved_10_14 : HAL.UInt5 := 16#0#;
POLARITY : Boolean := False;
HYST : COMP2_CSR_HYST_Field := 16#0#;
BLANKING : COMP2_CSR_BLANKING_Field := 16#0#;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
BRGEN : Boolean := False;
SCALEN : Boolean := False;
-- unspecified
Reserved_24_24 : HAL.Bit := 16#0#;
INMESEL : COMP2_CSR_INMESEL_Field := 16#0#;
-- unspecified
Reserved_27_29 : HAL.UInt3 := 16#0#;
VALUE : Boolean := False;
LOCK : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for COMP2_CSR_Register use record
EN at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
PWRMODE at 0 range 2 .. 3;
INMSEL at 0 range 4 .. 6;
INPSEL at 0 range 7 .. 8;
WINMODE at 0 range 9 .. 9;
Reserved_10_14 at 0 range 10 .. 14;
POLARITY at 0 range 15 .. 15;
HYST at 0 range 16 .. 17;
BLANKING at 0 range 18 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
BRGEN at 0 range 22 .. 22;
SCALEN at 0 range 23 .. 23;
Reserved_24_24 at 0 range 24 .. 24;
INMESEL at 0 range 25 .. 26;
Reserved_27_29 at 0 range 27 .. 29;
VALUE at 0 range 30 .. 30;
LOCK at 0 range 31 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
type COMP_Peripheral is record
COMP1_CSR : aliased COMP1_CSR_Register;
COMP2_CSR : aliased COMP2_CSR_Register;
end record
with Volatile;
for COMP_Peripheral use record
COMP1_CSR at 16#0# range 0 .. 31;
COMP2_CSR at 16#4# range 0 .. 31;
end record;
COMP_Periph : aliased COMP_Peripheral
with Import, Address => System'To_Address (16#40010200#);
end STM32_SVD.COMP;
|
package Addr7 is
type Bytes is array (1 .. 4) of Character;
for Bytes'Alignment use 4;
procedure Proc (B: aliased Bytes);
end Addr7;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../../License.txt
--
-- Some of these definitions originate from the Matresha Project
-- http://forge.ada-ru.org/matreshka
-- Used with permission from Vadim Godunko <vgodunko@gmail.com>
with System;
with Interfaces.C.Strings;
package AdaBase.Bindings.SQLite is
pragma Preelaborate;
package SYS renames System;
package IC renames Interfaces.C;
package ICS renames Interfaces.C.Strings;
------------------------
-- Type Definitions --
------------------------
type sql64 is new Interfaces.Integer_64;
type sqlite3 is limited private;
type sqlite3_Access is access all sqlite3;
pragma Convention (C, sqlite3_Access);
type sqlite3_stmt is limited private;
type sqlite3_stmt_Access is access all sqlite3_stmt;
pragma Convention (C, sqlite3_stmt_Access);
type sqlite3_destructor is access procedure (text : ICS.char_array_access);
pragma Convention (C, sqlite3_destructor);
---------------
-- Constants --
---------------
type enum_field_types is
(SQLITE_INTEGER,
SQLITE_FLOAT,
SQLITE_TEXT,
SQLITE_BLOB,
SQLITE_NULL);
pragma Convention (C, enum_field_types);
for enum_field_types use
(SQLITE_INTEGER => 1,
SQLITE_FLOAT => 2,
SQLITE_TEXT => 3,
SQLITE_BLOB => 4,
SQLITE_NULL => 5);
SQLITE_OK : constant := 0; -- Successful result
SQLITE_ROW : constant := 100; -- sqlite3_step() has another row ready
SQLITE_DONE : constant := 101; -- sqlite3_step() has finished executing
SQLITE_CONFIG_SINGLETHREAD : constant := 1; -- nil
SQLITE_CONFIG_MULTITHREAD : constant := 2; -- nil
SQLITE_CONFIG_SERIALIZED : constant := 3; -- nil
SQLITE_STATIC : constant IC.int := IC.int (0);
SQLITE_TRANSIENT : constant IC.int := IC.int (-1);
---------------------
-- Library Calls --
----------------------
-- For now, only support SQLITE_STATIC and SQLITE_TRANSIENT at the
-- cost of sqlite3_destructor. Shame on them mixing pointers and integers
-- Applies to bind_text and bind_blob
function sqlite3_bind_text (Handle : sqlite3_stmt_Access;
Index : IC.int;
Text : ICS.chars_ptr;
nBytes : IC.int;
destructor : IC.int) return IC.int;
pragma Import (C, sqlite3_bind_text);
function sqlite3_bind_blob (Handle : sqlite3_stmt_Access;
Index : IC.int;
binary : ICS.char_array_access;
nBytes : IC.int;
destructor : IC.int) return IC.int;
pragma Import (C, sqlite3_bind_blob);
function sqlite3_bind_double (Handle : not null sqlite3_stmt_Access;
Index : IC.int;
Value : IC.double) return IC.int;
pragma Import (C, sqlite3_bind_double);
function sqlite3_bind_int64 (Handle : not null sqlite3_stmt_Access;
Index : IC.int;
Value : sql64) return IC.int;
pragma Import (C, sqlite3_bind_int64);
function sqlite3_bind_null (Handle : not null sqlite3_stmt_Access;
Index : IC.int) return IC.int;
pragma Import (C, sqlite3_bind_null);
function sqlite3_bind_parameter_count
(Handle : not null sqlite3_stmt_Access) return IC.int;
pragma Import (C, sqlite3_bind_parameter_count);
function sqlite3_column_count (Handle : not null sqlite3_stmt_Access)
return IC.int;
pragma Import (C, sqlite3_column_count);
function sqlite3_column_table_name (Handle : not null sqlite3_stmt_Access;
index : IC.int) return ICS.chars_ptr;
pragma Import (C, sqlite3_column_table_name);
function sqlite3_column_name (Handle : not null sqlite3_stmt_Access;
index : IC.int) return ICS.chars_ptr;
pragma Import (C, sqlite3_column_name);
function sqlite3_column_origin_name (Handle : not null sqlite3_stmt_Access;
index : IC.int) return ICS.chars_ptr;
pragma Import (C, sqlite3_column_origin_name);
function sqlite3_column_database_name
(Handle : not null sqlite3_stmt_Access;
index : IC.int) return ICS.chars_ptr;
pragma Import (C, sqlite3_column_database_name);
function sqlite3_table_column_metadata
(Handle : not null sqlite3_Access;
dbname : ICS.chars_ptr;
table : ICS.chars_ptr;
column : ICS.chars_ptr;
datatype : access ICS.chars_ptr;
collseq : access ICS.chars_ptr;
notnull : access IC.int;
primekey : access IC.int;
autoinc : access IC.int) return IC.int;
pragma Import (C, sqlite3_table_column_metadata);
function sqlite3_close (db : not null sqlite3_Access) return IC.int;
pragma Import (C, sqlite3_close);
function sqlite3_column_type (Handle : not null sqlite3_stmt_Access;
iCol : IC.int) return IC.int;
pragma Import (C, sqlite3_column_type);
function sqlite3_column_bytes (Handle : not null sqlite3_stmt_Access;
iCol : IC.int) return IC.int;
pragma Import (C, sqlite3_column_bytes);
function sqlite3_column_double (Handle : not null sqlite3_stmt_Access;
iCol : IC.int) return IC.double;
pragma Import (C, sqlite3_column_double);
function sqlite3_column_int64 (Handle : not null sqlite3_stmt_Access;
iCol : IC.int) return sql64;
pragma Import (C, sqlite3_column_int64);
function sqlite3_column_text (Handle : not null sqlite3_stmt_Access;
iCol : IC.int) return ICS.chars_ptr;
pragma Import (C, sqlite3_column_text);
function sqlite3_column_blob (Handle : not null sqlite3_stmt_Access;
iCol : IC.int) return ICS.chars_ptr;
pragma Import (C, sqlite3_column_blob);
function sqlite3_config (Option : IC.int) return IC.int;
pragma Import (C, sqlite3_config);
function sqlite3_errmsg (db : not null sqlite3_Access) return ICS.chars_ptr;
pragma Import (C, sqlite3_errmsg);
function sqlite3_errcode (db : not null sqlite3_Access) return IC.int;
pragma Import (C, sqlite3_errcode);
function sqlite3_changes (db : not null sqlite3_Access) return IC.int;
pragma Import (C, sqlite3_changes);
function sqlite3_last_insert_rowid (db : not null sqlite3_Access)
return sql64;
pragma Import (C, sqlite3_last_insert_rowid);
function sqlite3_exec (db : not null sqlite3_Access;
sql : ICS.chars_ptr;
callback : System.Address;
firstarg : System.Address;
errmsg : System.Address) return IC.int;
pragma Import (C, sqlite3_exec);
function sqlite3_open (File_Name : ICS.chars_ptr;
Handle : not null access sqlite3_Access)
return IC.int;
pragma Import (C, sqlite3_open);
function sqlite3_prepare_v2 (db : not null sqlite3_Access;
zSql : ICS.chars_ptr;
nByte : IC.int;
ppStmt : not null access sqlite3_stmt_Access;
pzTail : not null access ICS.chars_ptr)
return IC.int;
pragma Import (C, sqlite3_prepare_v2);
function sqlite3_reset (pStmt : not null sqlite3_stmt_Access) return IC.int;
pragma Import (C, sqlite3_reset);
function sqlite3_step (Handle : not null sqlite3_stmt_Access) return IC.int;
pragma Import (C, sqlite3_step);
function sqlite3_finalize (Handle : not null sqlite3_stmt_Access)
return IC.int;
pragma Import (C, sqlite3_finalize);
function sqlite3_libversion return ICS.chars_ptr;
pragma Import (C, sqlite3_libversion);
function sqlite3_sourceid return ICS.chars_ptr;
pragma Import (C, sqlite3_sourceid);
function sqlite3_get_autocommit (db : not null sqlite3_Access)
return IC.int;
pragma Import (C, sqlite3_get_autocommit);
private
type sqlite3 is limited null record;
type sqlite3_stmt is limited null record;
end AdaBase.Bindings.SQLite;
|
with Ada.Streams; use Ada.Streams;
with AWS.Response;
with AWS.Status;
with Computation_Type;
with Image_Types;
with Fractal;
with Julia_Set;
package Router_Cb is
function Router (Request : AWS.Status.Data) return AWS.Response.Data;
procedure Init;
Server_Alive : Boolean := True;
type Color is new Natural range 0 .. 255
with Size => 8;
Max_Iterations : constant := Color'Last / 5;
type RGB888_Pixel is record
Red : Color;
Green : Color;
Blue : Color;
Alpha : Color;
end record
with Size => 32;
for RGB888_Pixel use record
Red at 0 range 0 .. 7;
Green at 1 range 0 .. 7;
Blue at 2 range 0 .. 7;
Alpha at 3 range 0 .. 7;
end record;
procedure Color_Pixel (Z_Escape : Boolean;
Iter_Escape : Natural;
Px : out RGB888_Pixel);
package RGB888_IT is new Image_Types (Pixel => RGB888_Pixel,
Color_Pixel => Color_Pixel,
Max_Iterations => Max_Iterations);
use RGB888_IT;
Max_Buffer_Size : constant Buffer_Offset :=
Buffer_Offset (ImgWidth'Last * ImgHeight'Last * (RGB888_Pixel'Size / 8));
RawData : Buffer_Access :=
new Buffer_Array (1 .. Max_Buffer_Size);
private
Task_Pool_Size : constant := 16;
Compute_Time : Duration := Duration'First;
Viewport : Viewport_Info;
type Computation_Enum is
(Fixed_Type, Float_Type);
Frame_Counter : Color := 0;
Cnt_Up : Boolean := True;
procedure Increment_Frame;
type Real_Float is new Float;
function Integer_To_Float (V : Integer) return Real_Float is
(Real_Float (V));
function Float_To_Integer (V : Real_Float) return Integer is
(Natural (V));
function Float_To_Real_Float (V : Float) return Real_Float is
(Real_Float (V));
function Real_Float_To_Float (V : Real_Float) return Float is
(Float (V));
function Float_Image (V : Real_Float) return String is
(V'Img);
D_Small : constant := 2.0 ** (-21);
type Real_Fixed is delta D_Small range -100.0 .. 201.0 - D_Small;
function "*" (Left, Right : Real_Fixed) return Real_Fixed;
pragma Import (Intrinsic, "*");
function "/" (Left, Right : Real_Fixed) return Real_Fixed;
pragma Import (Intrinsic, "/");
function Integer_To_Fixed (V : Integer) return Real_Fixed is
(Real_Fixed (V));
function Float_To_Fixed (V : Float) return Real_Fixed is
(Real_Fixed (V));
function Fixed_To_Float (V : Real_Fixed) return Float is
(Float (V));
function Fixed_To_Integer (V : Real_Fixed) return Integer is
(Natural (V));
function Fixed_Image (V : Real_Fixed) return String is
(V'Img);
package Fixed_Computation is new Computation_Type (Real => Real_Fixed,
"*" => Router_Cb."*",
"/" => Router_Cb."/",
To_Real => Integer_To_Fixed,
F_To_Real => Float_To_Fixed,
To_Integer => Fixed_To_Integer,
To_Float => Fixed_To_Float,
Image => Fixed_Image);
package Fixed_Julia is new Julia_Set (CT => Fixed_Computation,
IT => RGB888_IT,
Escape_Threshold => 100.0);
package Fixed_Julia_Fractal is new Fractal (CT => Fixed_Computation,
IT => RGB888_IT,
Calculate_Pixel => Fixed_Julia.Calculate_Pixel,
Task_Pool_Size => Task_Pool_Size);
package Float_Computation is new Computation_Type (Real => Real_Float,
To_Real => Integer_To_Float,
F_To_Real => Float_To_Real_Float,
To_Integer => Float_To_Integer,
To_Float => Real_Float_To_Float,
Image => Float_Image);
package Float_Julia is new Julia_Set (CT => Float_Computation,
IT => RGB888_IT,
Escape_Threshold => 100.0);
package Float_Julia_Fractal is new Fractal (CT => Float_Computation,
IT => RGB888_IT,
Calculate_Pixel => Float_Julia.Calculate_Pixel,
Task_Pool_Size => Task_Pool_Size);
procedure ImgSize_Parse (URI : String);
function Compute_Image (Comp_Type : Computation_Enum)
return Buffer_Offset;
procedure Reset_Viewport;
end Router_Cb;
|
-- { dg-do run }
-- { dg-options "-fstack-check" }
-- This test requires architecture- and OS-specific support code for unwinding
-- through signal frames (typically located in *-unwind.h) to pass. Feel free
-- to disable it if this code hasn't been implemented yet.
procedure Stack_Check2 is
function UB return Integer is
begin
return 2048;
end;
type A is Array (Positive range <>) of Integer;
procedure Consume_Stack (N : Integer) is
My_A : A (1..UB); -- 8 KB dynamic
begin
My_A (1) := 0;
if N <= 0 then
return;
end if;
Consume_Stack (N-1);
end;
Task T;
Task body T is
begin
begin
Consume_Stack (Integer'Last);
raise Program_Error;
exception
when Storage_Error => null;
end;
Consume_Stack (128);
end;
begin
null;
end;
|
pragma Ada_2005;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Extensions;
package umingw_h is
USE_u_u_UUIDOF : constant := 0; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw.h:79
WINVER : constant := 16#0502#; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw.h:225
-- unsupported macro: UNALIGNED __unaligned
--*
-- * This file has no copyright assigned and is placed in the Public Domain.
-- * This file is part of the mingw-w64 runtime package.
-- * No warranty is given; refer to the file DISCLAIMER.PD within this package.
--
-- Include _cygwin.h if we're building a Cygwin application.
-- Target specific macro replacement for type "long". In the Windows API,
-- the type long is always 32 bit, even if the target is 64 bit (LLP64).
-- On 64 bit Cygwin, the type long is 64 bit (LP64). So, to get the right
-- sized definitions and declarations, all usage of type long in the Windows
-- headers have to be replaced by the below defined macro __LONG32.
-- C/C++ specific language defines.
-- Note the extern. This is needed to work around GCC's
--limitations in handling dllimport attribute.
-- Attribute `nonnull' was valid as of gcc 3.3. We don't use GCC's
-- variadiac macro facility, because variadic macros cause syntax
-- errors with --traditional-cpp.
-- High byte is the major version, low byte is the minor.
-- other headers depend on this include
-- We have to define _DLL for gcc based mingw version. This define is set
-- by VC, when DLL-based runtime is used. So, gcc based runtime just have
-- DLL-base runtime, therefore this define has to be set.
-- As our headers are possibly used by windows compiler having a static
-- C-runtime, we make this definition gnu compiler specific here.
subtype ssize_t is Long_Long_Integer; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw.h:387
subtype intptr_t is Long_Long_Integer; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw.h:399
subtype uintptr_t is Extensions.unsigned_long_long; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw.h:412
subtype wint_t is unsigned_short; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw.h:443
subtype wctype_t is unsigned_short; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw.h:444
subtype errno_t is int; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw.h:463
subtype uu_time32_t is long; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw.h:468
subtype uu_time64_t is Long_Long_Integer; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw.h:473
subtype time_t is uu_time64_t; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw.h:481
-- MSVC defines _NATIVE_NULLPTR_SUPPORTED when nullptr is supported. We emulate it here for GCC.
-- We are activating __USE_MINGW_ANSI_STDIO for various define indicators.
-- Note that we enable it also for _GNU_SOURCE in C++, but not for C case.
-- Enable __USE_MINGW_ANSI_STDIO if _POSIX defined
-- * and If user did _not_ specify it explicitly...
-- _dowildcard is an int that controls the globbing of the command line.
-- * The MinGW32 (mingw.org) runtime calls it _CRT_glob, so we are adding
-- * a compatibility definition here: you can use either of _CRT_glob or
-- * _dowildcard .
-- * If _dowildcard is non-zero, the command line will be globbed: *.*
-- * will be expanded to be all files in the startup directory.
-- * In the mingw-w64 library a _dowildcard variable is defined as being
-- * 0, therefore command line globbing is DISABLED by default. To turn it
-- * on and to leave wildcard command line processing MS's globbing code,
-- * include a line in one of your source modules defining _dowildcard and
-- * setting it to -1, like so:
-- * int _dowildcard = -1;
--
-- Macros for __uuidof template-based emulation
-- skipped func __debugbreak
-- mingw-w64 specific functions:
-- skipped func __mingw_get_crt_info
end umingw_h;
|
with Ada.Containers.Doubly_Linked_Lists;
with Ada.Text_IO;
with Ada.Calendar;
with Ada.Strings;
with Ada.Strings.Unbounded;
with DOM.Core;
package Events is
type Event_Type is (None, Normal, Reserved, Deleted, Excepted);
type Interval is (daily, weekly, monthly, yearly);
type Month_Day is (first, second, third, fourth, last);
type Event is record
Created, Last_Modified,
Event_Date, End_Date : Ada.Calendar.Time;
Event_Duration : Duration;
Is_All_Day, Is_Recurrent : Boolean;
The_Type : Event_Type;
Summary, Description : Ada.Strings.Unbounded.Unbounded_String;
Location, Category : Ada.Strings.Unbounded.Unbounded_String;
UID, Recurrence_Data : Ada.Strings.Unbounded.Unbounded_String;
Master_ID : Ada.Strings.Unbounded.Unbounded_String;
Recurrence_ID : Ada.Calendar.Time;
end record;
function To_Event_Type (S : String) return Event_Type;
function To_String (I : Interval) return String;
function To_Month_Day (S : String) return Month_Day;
Unexpected_Node : exception;
package Lists is new Ada.Containers.Doubly_Linked_Lists
(Element_Type => Event);
List : Lists.List;
procedure Read (Data_Nodes : DOM.Core.Node_List);
procedure Write (To_File : Ada.Text_IO.File_Type);
end Events;
|
--
-- Copyright (C) 2021, AdaCore
--
pragma Style_Checks (Off);
-- This spec has been automatically generated from STM32L562.svd
-- This is a version for the STM32L562 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/PVM1/PVM2/PVM3/PVM4 through EXTI
PVD_PVM_Interrupt : constant Interrupt_ID := 1;
-- RTC global interrupts (EXTI line 17)
RTC_Interrupt : constant Interrupt_ID := 2;
-- RTC secure global interrupts (EXTI line 18)
RTC_S_Interrupt : constant Interrupt_ID := 3;
-- TAMPTamper global interrupt (EXTI line 19)
TAMP_Interrupt : constant Interrupt_ID := 4;
-- Tamper secure global interrupt (EXTI line 20)
TAMP_S_Interrupt : constant Interrupt_ID := 5;
-- Flash global interrupt
FLASH_Interrupt : constant Interrupt_ID := 6;
-- Flash memory secure global interrupt
FLASH_S_Interrupt : constant Interrupt_ID := 7;
-- TZIC secure global interrupt
GTZC_Interrupt : constant Interrupt_ID := 8;
-- RCC global interrupt
RCC_Interrupt : constant Interrupt_ID := 9;
-- RCC SECURE GLOBAL INTERRUPT
RCC_S_Interrupt : constant Interrupt_ID := 10;
-- EXTI line0 interrupt
EXTI0_Interrupt : constant Interrupt_ID := 11;
-- EXTI line1 interrupt
EXTI1_Interrupt : constant Interrupt_ID := 12;
-- EXTI line2 interrupt
EXTI2_Interrupt : constant Interrupt_ID := 13;
-- EXTI line3 interrupt
EXTI3_Interrupt : constant Interrupt_ID := 14;
-- EXTI line4 interrupt
EXTI4_Interrupt : constant Interrupt_ID := 15;
-- EXTI line5 interrupt
EXTI5_Interrupt : constant Interrupt_ID := 16;
-- EXTI line6 interrupt
EXTI6_Interrupt : constant Interrupt_ID := 17;
-- EXTI line7 interrupt
EXTI7_Interrupt : constant Interrupt_ID := 18;
-- EXTI line8 interrupt
EXTI8_Interrupt : constant Interrupt_ID := 19;
-- EXTI line9 interrupt
EXTI9_Interrupt : constant Interrupt_ID := 20;
-- EXTI line10 interrupt
EXTI10_Interrupt : constant Interrupt_ID := 21;
-- EXTI line11 interrupt
EXTI11_Interrupt : constant Interrupt_ID := 22;
-- EXTI line12 interrupt
EXTI12_Interrupt : constant Interrupt_ID := 23;
-- EXTI line13 interrupt
EXTI13_Interrupt : constant Interrupt_ID := 24;
-- EXTI line14 interrupt
EXTI14_Interrupt : constant Interrupt_ID := 25;
-- EXTI line15 interrupt
EXTI15_Interrupt : constant Interrupt_ID := 26;
-- DMAMUX overrun interrupt
DMAMUX1_OVR_Interrupt : constant Interrupt_ID := 27;
-- DMAMUX1 secure overRun interrupt
DMAMUX1_OVR_S_Interrupt : constant Interrupt_ID := 28;
-- DMA1 Channel1 global interrupt
DMA1_Channel1_Interrupt : constant Interrupt_ID := 29;
-- DMA1 Channel2 global interrupt
DMA1_Channel2_Interrupt : constant Interrupt_ID := 30;
-- DMA1 Channel3 interrupt
DMA1_Channel3_Interrupt : constant Interrupt_ID := 31;
-- DMA1 Channel4 interrupt
DMA1_Channel4_Interrupt : constant Interrupt_ID := 32;
-- DMA1 Channel5 interrupt
DMA1_Channel5_Interrupt : constant Interrupt_ID := 33;
-- DMA1 Channel6 interrupt
DMA1_Channel6_Interrupt : constant Interrupt_ID := 34;
-- DMA1 Channel 7 interrupt
DMA1_Channel7_Interrupt : constant Interrupt_ID := 35;
-- DMA1_Channel8
DMA1_Channel8_Interrupt : constant Interrupt_ID := 36;
-- ADC1_2 global interrupt
ADC1_2_Interrupt : constant Interrupt_ID := 37;
-- DAC global interrupt
DAC_Interrupt : constant Interrupt_ID := 38;
-- FDCAN1 Interrupt 0
FDCAN1_IT0_Interrupt : constant Interrupt_ID := 39;
-- FDCAN1 Interrupt 1
FDCAN1_IT1_Interrupt : constant Interrupt_ID := 40;
-- TIM1 Break
TIM1_BRK_Interrupt : constant Interrupt_ID := 41;
-- TIM1 Update
TIM1_UP_Interrupt : constant Interrupt_ID := 42;
-- TIM1 Trigger and Commutation
TIM1_TRG_COM_Interrupt : constant Interrupt_ID := 43;
-- TIM1 Capture Compare interrupt
TIM1_CC_Interrupt : constant Interrupt_ID := 44;
-- TIM2 global interrupt
TIM2_Interrupt : constant Interrupt_ID := 45;
-- TIM3 global interrupt
TIM3_Interrupt : constant Interrupt_ID := 46;
-- TIM4 global interrupt
TIM4_Interrupt : constant Interrupt_ID := 47;
-- TIM5 global interrupt
TIM5_Interrupt : constant Interrupt_ID := 48;
-- TIM6 global interrupt
TIM6_Interrupt : constant Interrupt_ID := 49;
-- TIM7 global interrupt
TIM7_Interrupt : constant Interrupt_ID := 50;
-- TIM8 Break Interrupt
TIM8_BRK_Interrupt : constant Interrupt_ID := 51;
-- TIM8 Update Interrupt
TIM8_UP_Interrupt : constant Interrupt_ID := 52;
-- TIM8 Trigger and Commutation Interrupt
TIM8_TRG_COM_Interrupt : constant Interrupt_ID := 53;
-- TIM8 Capture Compare Interrupt
TIM8_CC_Interrupt : constant Interrupt_ID := 54;
-- I2C1 event interrupt
I2C1_EV_Interrupt : constant Interrupt_ID := 55;
-- I2C1 error interrupt
I2C1_ER_Interrupt : constant Interrupt_ID := 56;
-- I2C2 event interrupt
I2C2_EV_Interrupt : constant Interrupt_ID := 57;
-- I2C2 error interrupt
I2C2_ER_Interrupt : constant Interrupt_ID := 58;
-- SPI1 global interrupt
SPI1_Interrupt : constant Interrupt_ID := 59;
-- SPI2 global interrupt
SPI2_Interrupt : constant Interrupt_ID := 60;
-- USART1 global interrupt
USART1_Interrupt : constant Interrupt_ID := 61;
-- USART2 global interrupt
USART2_Interrupt : constant Interrupt_ID := 62;
-- USART3 global interrupt
USART3_Interrupt : constant Interrupt_ID := 63;
-- UART4 global interrupt
UART4_Interrupt : constant Interrupt_ID := 64;
-- UART5 global interrupt
UART5_Interrupt : constant Interrupt_ID := 65;
-- LPUART1 global interrupt
LPUART1_Interrupt : constant Interrupt_ID := 66;
-- LP TIM1 interrupt
LPTIM1_Interrupt : constant Interrupt_ID := 67;
-- LP TIM2 interrupt
LPTIM2_Interrupt : constant Interrupt_ID := 68;
-- TIM15 global interrupt
TIM15_Interrupt : constant Interrupt_ID := 69;
-- TIM16 global interrupt
TIM16_Interrupt : constant Interrupt_ID := 70;
-- TIM17 global interrupt
TIM17_Interrupt : constant Interrupt_ID := 71;
-- COMP1 and COMP2 interrupts
COMP_Interrupt : constant Interrupt_ID := 72;
-- USB FS global interrupt
USB_FS_Interrupt : constant Interrupt_ID := 73;
-- Clock recovery system global interrupt
CRS_Interrupt : constant Interrupt_ID := 74;
-- FMC global interrupt
FMC_Interrupt : constant Interrupt_ID := 75;
-- OCTOSPI1 global interrupt
OCTOSPI1_Interrupt : constant Interrupt_ID := 76;
-- SDMMC1 global interrupt
SDMMC1_Interrupt : constant Interrupt_ID := 78;
-- DMA2_CH1
DMA2_CH1_Interrupt : constant Interrupt_ID := 80;
-- DMA2_CH2
DMA2_CH2_Interrupt : constant Interrupt_ID := 81;
-- FPU global interrupt
FPU_Interrupt : constant Interrupt_ID := 81;
-- DMA2_CH3
DMA2_CH3_Interrupt : constant Interrupt_ID := 82;
-- DMA2_CH4
DMA2_CH4_Interrupt : constant Interrupt_ID := 83;
-- DMA2_CH5
DMA2_CH5_Interrupt : constant Interrupt_ID := 84;
-- DMA2_CH6
DMA2_CH6_Interrupt : constant Interrupt_ID := 85;
-- DMA2_CH7
DMA2_CH7_Interrupt : constant Interrupt_ID := 86;
-- DMA2_CH8
DMA2_CH8_Interrupt : constant Interrupt_ID := 87;
-- I2C3 event interrupt
I2C3_EV_Interrupt : constant Interrupt_ID := 88;
-- I2C3 error interrupt
I2C3_ER_Interrupt : constant Interrupt_ID := 89;
-- SAI1 global interrupt
SAI1_Interrupt : constant Interrupt_ID := 90;
-- SAI2 global interrupt
SAI2_Interrupt : constant Interrupt_ID := 91;
-- TSC global interrupt
TSC_Interrupt : constant Interrupt_ID := 92;
-- AES global interrupts
AES_Interrupt : constant Interrupt_ID := 93;
-- RNG global interrupt
RNG_Interrupt : constant Interrupt_ID := 94;
-- HASH interrupt
HASH_Interrupt : constant Interrupt_ID := 96;
-- PKA global interrupts
PKA_Interrupt : constant Interrupt_ID := 97;
-- LPTIM3
LPTIM3_Interrupt : constant Interrupt_ID := 98;
-- SPI3
SPI3_Interrupt : constant Interrupt_ID := 99;
-- I2C4 error interrupt
I2C4_ER_Interrupt : constant Interrupt_ID := 100;
-- I2C4 event interrupt
I2C4_EV_Interrupt : constant Interrupt_ID := 101;
-- DFSDM1_FLT0 global interrupt
DFSDM1_FLT0_Interrupt : constant Interrupt_ID := 102;
-- DFSDM1_FLT1 global interrupt
DFSDM1_FLT1_Interrupt : constant Interrupt_ID := 103;
-- DFSDM1_FLT2 global interrupt
DFSDM1_FLT2_Interrupt : constant Interrupt_ID := 104;
-- DFSDM1_FLT3 global interrupt
DFSDM1_FLT3_Interrupt : constant Interrupt_ID := 105;
-- UCPD global interrupt
UCPD1_Interrupt : constant Interrupt_ID := 106;
-- ICACHE
ICACHE_Interrupt : constant Interrupt_ID := 107;
-- OTFDEC1 secure global interrupt
OTFDEC1_Interrupt : constant Interrupt_ID := 108;
end Ada.Interrupts.Names;
|
with Extools; use Extools;
package body Display_Warning is
procedure Warning (Message : String; Down :Integer := 0;D : Duration := 0.0) is
Display_Window : Window;
Width : Column_Position := 40;
Length : Line_Position := 5;
c : Key_Code;
Lines : Line_Position;
Columns : Column_Position;
-- D : Duration := 0.3;
Now : Time := Clock;
Next : Time := Now + D;
begin
Get_Size(Number_Of_Lines => Lines,Number_Of_Columns => Columns);
Display_Window := Sub_Window(Win => Standard_Window,
Number_Of_Lines => Length,
Number_Of_Columns => Width,
First_Line_Position => ((Lines - Length) / 2)+Line_Position(Down),
First_Column_Position => (Columns - Width) / 2);
Clear(Display_Window);
Box(Display_Window);
Add (Win => Display_Window,
Column => Column_Position((Width - Message'Length) / 2),
Line => 2,
Str => Message);
Refrosh(Display_Window);
if D > 0.0 then
delay until Next;
else
Add (Win => Display_Window,Column => 1,Line => 4,Str => "Any Key to Continue");
Refrosh(Display_Window);
c := Get_Keystroke;
end if;
Clear(Display_Window);
Refrosh(Display_Window);
Delete (Win => Display_Window);
end;
function GetYN (Message : String; Down : Integer := 0) return Boolean is
Display_Window : Window;
Width : Column_Position := 40;
Length : Line_Position := 5;
c : Key_Code;
Lines : Line_Position;
Columns : Column_Position;
retval : Boolean := False;
begin
Get_Size(Number_Of_Lines => Lines,Number_Of_Columns => Columns);
Display_Window := Sub_Window(Win => Standard_Window,
Number_Of_Lines => Length,
Number_Of_Columns => Width,
First_Line_Position => ((Lines - Length) / 2)+Line_Position(Down),
First_Column_Position => (Columns - Width) / 2);
Clear(Display_Window);
Box(Display_Window);
Add (Win => Display_Window,
Column => 1,
Line => 2,
Str => Message);
Add (Win => Display_Window,Column => 1,Line => 4,Str => "y/n Continue Esc Cancel");
Refrosh(Display_Window);
Cancel := False;
loop
c := Get_Keystroke;
case Character'Val (c) is
when 'Y'|'y' =>
retval := True;
exit;
when 'N'|'n' =>
retval := False;
exit;
when ESC =>
Cancel := True;
exit;
when others => null;
end case;
end loop;
Clear(Display_Window);
Refrosh(Display_Window);
Delete (Win => Display_Window);
return retval;
end;
end Display_Warning;
|
-- parse_args-generic_indefinite_options.ads
-- A simple command line option parser
-- Copyright (c) 2015, James Humphry
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-- PERFORMANCE OF THIS SOFTWARE.
pragma Profile(No_Implementation_Extensions);
package body Parse_Args.Generic_Indefinite_Options is
use Ada.Finalization;
----------------
-- Set_Option --
----------------
procedure Set_Option
(O : in out Element_Option;
A : in out Argument_Parser'Class)
is
begin
if O.Set then
A.State := Finish_Erroneous;
A.Message := To_Unbounded_String("Argument cannot be specified twice.");
else
A.State := Required_Argument;
end if;
end Set_Option;
-------------------------
-- Set_Option_Argument --
-------------------------
procedure Set_Option_Argument
(O : in out Element_Option;
Arg : in String;
A : in out Argument_Parser'Class)
is
Constraint_Met : Boolean := True;
begin
O.Set := True;
O.Value := Value(Arg);
Valid(O.Value, Constraint_Met);
if not Constraint_Met then
A.State := Finish_Erroneous;
A.Message := To_Unbounded_String(Arg & " does not meet constraints");
end if;
exception
when Constraint_Error =>
A.State := Finish_Erroneous;
A.Message := To_Unbounded_String("Not a valid value: " & Arg);
end Set_Option_Argument;
-----------
-- Value --
-----------
function Value (A : in Argument_Parser; Name : in String) return Element_Access is
begin
if A.Arguments.Contains(Name) then
if A.Arguments(Name).all in Element_Option'Class then
return Element_Option'Class(A.Arguments(Name).all).Value;
else
raise Constraint_Error with "Argument " & Name
& " is not of the right type.";
end if;
else
raise Constraint_Error with "No argument: " & Name & ".";
end if;
end Value;
-----------------
-- Make_Option --
-----------------
function Make_Option return Option_Ptr
is
(new Element_Option'(Limited_Controlled with
Set => False,
Value =>null
));
--------------
-- Finalize --
--------------
procedure Finalize(Object : in out Element_Option) is
begin
if Object.Value /= null then
Free_Element(Object.Value);
end if;
end Finalize;
end Parse_Args.Generic_Indefinite_Options;
|
with Ada.Text_IO;
with Intcode;
procedure Day09 is
use Ada.Text_IO;
use Intcode;
Compiler : Intcode_Compiler := Compile ("src/main/resources/2019/day09.txt");
begin
declare
Instance : Intcode_Instance := Instantiate (Compiler);
begin
Instance.Inputs.Append (1);
Instance.Run;
pragma Assert (Instance.State = Halted);
pragma Assert (Integer (Instance.Outputs.Length) = 1);
Put_Line (Instance.Outputs.Last_Element'Image);
end;
end Day09;
|
pragma Warnings (Off);
pragma Style_Checks (Off);
with Ada.Unchecked_Deallocation;
with GLOBE_3D.Math;
package body GLOBE_3D.BSP is
use Ada.Strings.Unbounded;
procedure Locate (P : Point_3D; tree : p_BSP_node; area : out p_Object_3D) is
procedure Locate_point (tree_point : p_BSP_node) is
-- ^ internal, for skipping useless parameter passing
use Math, GL;
begin
info_b_str1 := info_b_str1 & " - > " & Integer'Image (tree_point.node_id);
info_b_ntl1 := info_b_ntl1 + 1;
if P * tree_point.normal + tree_point.distance > 0.0 then -- in front
if tree_point.front_child = null then
area := tree_point.front_leaf;
else
Locate_point (tree_point.front_child);
end if;
else -- in back
if tree_point.back_child = null then
area := tree_point.back_leaf;
else
Locate_point (tree_point.back_child);
end if;
end if;
end Locate_point;
begin
info_b_str1 := Null_Unbounded_String;
info_b_ntl1 := 0; -- depth counter
area := null;
if tree /= null then
Locate_point (tree);
end if;
info_b_bool1 := area /= null;
end Locate;
procedure Delete (tree : in out p_BSP_node) is
procedure Dispose is new Ada.Unchecked_Deallocation (BSP_node, p_BSP_node);
begin
if tree/=null then
Delete (tree.front_child);
Delete (tree.back_child);
Dispose (tree);
tree := null;
end if;
end Delete;
end GLOBE_3D.BSP;
|
--
-- 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 soc.rcc;
with soc.rcc.default;
package body soc.usart
with spark_mode => off
is
procedure set_baudrate
(usart : in t_USART_peripheral_access;
baudrate : in unsigned_32)
is
APB_clock : unsigned_32;
mantissa : unsigned_32;
fraction : unsigned_32;
begin
-- Configuring the baud rate is a tricky part. See RM0090 p. 982-983
-- for further informations
if usart = USART1'access or
usart = USART6'access
then
APB_clock := soc.rcc.default.CLOCK_APB2;
else
APB_clock := soc.rcc.default.CLOCK_APB1;
end if;
mantissa := APB_clock / (16 * baudrate);
fraction := ((APB_clock * 25) / (4 * baudrate)) - mantissa * 100;
fraction := (fraction * 16) / 100;
usart.all.BRR.DIV_MANTISSA := bits_12 (mantissa);
usart.all.BRR.DIV_FRACTION := bits_4 (fraction);
end set_baudrate;
procedure transmit
(usart : in t_USART_peripheral_access;
data : in t_USART_DR)
is
begin
loop
exit when usart.all.SR.TXE;
end loop;
usart.all.DR := data;
end transmit;
procedure receive
(usart : in t_USART_peripheral_access;
data : out t_USART_DR)
is
begin
loop
exit when usart.all.SR.RXNE;
end loop;
data := usart.all.DR;
end receive;
end soc.usart;
|
type Lower_Case is new Character range 'a' .. 'z';
|
with Lv.Color;
with Lv.Area;
private with System;
package Lv.Hal.Disp is
type Color_Array is
array (0 .. Natural'Last) of aliased Lv.Color.Color_T with
Convention => C;
type Disp_Drv_T is record
-- Write the internal buffer (VDB) to the display. 'lv_flush_ready()' has
-- to be called when finished.
Disp_Flush : access procedure
(X1 : Int32_T;
Y1 : Int32_T;
X2 : Int32_T;
Y2 : Int32_T;
Color : access constant Color_Array);
-- Fill an area with a color on the display
Disp_Fill : access procedure
(X1 : Int32_T;
Y1 : Int32_T;
X2 : Int32_T;
Y2 : Int32_T;
Color : Lv.Color.Color_T);
-- Write pixel map (e.g. image) to the display
Disp_Map : access procedure
(X1 : Int32_T;
Y1 : Int32_T;
X2 : Int32_T;
Y2 : Int32_T;
Color : access constant Color_Array);
-- Optional interface functions to use GPU
Mem_Blend : access procedure
(Dest : access Color_Array;
Src : access constant Color_Array;
Length : Uint32_T;
Opa : Lv.Color.Opa_T);
-- Fill a memory with a color (GPU only)
Mem_Fill : access procedure
(Dest : access Color_Array;
Length : Uint32_T;
Color : Lv.Color.Color_T);
-- Optional: Set a pixel in a buffer according to the requirements of the
-- display.
Vdb_Wr : access procedure
(Arg1 : access Uint8_T;
Arg2 : Lv.Area.Coord_T;
Arg3 : Lv.Area.Coord_T;
Arg4 : Lv.Area.Coord_T;
Arg5 : Lv.Color.Color_T;
Arg6 : Lv.Color.Opa_T);
end record;
pragma Convention (C_Pass_By_Copy, Disp_Drv_T);
type Disp_T is private;
-- Initialize a display driver with default values.
-- It is used to surly have known values in the fields ant not memory junk.
-- After it you can set the fields.
-- @param driver pointer to driver variable to initialize
procedure Init_Drv (Driver : access Disp_Drv_T);
-- Register an initialized display driver.
-- Automatically set the first display as active.
-- @param driver pointer to an initialized 'lv_disp_drv_t' variable (can be local variable)
-- @return pointer to the new display or NULL on error
function Register
(Driver : access Disp_Drv_T) return Disp_T;
-- Set the active display
-- @param disp pointer to a display (return value of 'lv_disp_register')
procedure Set_Active (Disp : Disp_T);
-- Get a pointer to the active display
-- @return pointer to the active display
function Get_Active return Disp_T;
-- Get the next display.
-- @param disp pointer to the current display. NULL to initialize.
-- @return the next display or NULL if no more. Give the first display when the parameter is NULL
function Next (Disp : Disp_T) return Disp_T;
-- Fill a rectangular area with a color on the active display
-- @param x1 left coordinate of the rectangle
-- @param x2 right coordinate of the rectangle
-- @param y1 top coordinate of the rectangle
-- @param y2 bottom coordinate of the rectangle
-- @param color_p pointer to an array of colors
procedure Flush
(X1 : Int32_T;
X2 : Int32_T;
Y1 : Int32_T;
Y2 : Int32_T;
Color : access Color_Array);
-- Fill a rectangular area with a color on the active display
-- @param x1 left coordinate of the rectangle
-- @param x2 right coordinate of the rectangle
-- @param y1 top coordinate of the rectangle
-- @param y2 bottom coordinate of the rectangle
-- @param color fill color
procedure Fill
(X1 : Int32_T;
X2 : Int32_T;
Y1 : Int32_T;
Y2 : Int32_T;
Color : Lv.Color.Color_T);
-- Put a color map to a rectangular area on the active display
-- @param x1 left coordinate of the rectangle
-- @param x2 right coordinate of the rectangle
-- @param y1 top coordinate of the rectangle
-- @param y2 bottom coordinate of the rectangle
-- @param color_map pointer to an array of colors
procedure Map
(X1 : Int32_T;
X2 : Int32_T;
Y1 : Int32_T;
Y2 : Int32_T;
Color_Map : access constant Color_Array);
-- Blend pixels to a destination memory from a source memory
-- In 'lv_disp_drv_t' 'mem_blend' is optional. (NULL if not available)
-- @param dest a memory address. Blend 'src' here.
-- @param src pointer to pixel map. Blend it to 'dest'.
-- @param length number of pixels in 'src'
-- @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
procedure Mem_Blend
(Dest : access Color_Array;
Src : access constant Color_Array;
Length : Uint32_T;
Opa : Lv.Color.Opa_T);
-- Fill a memory with a color (GPUs may support it)
-- In 'lv_disp_drv_t' 'mem_fill' is optional. (NULL if not available)
-- @param dest a memory address. Copy 'src' here.
-- @param src pointer to pixel map. Copy it to 'dest'.
-- @param length number of pixels in 'src'
-- @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
procedure Mem_Fill
(Src : access Color_Array;
Length : Uint32_T;
Opa : Lv.Color.Color_T);
-- Shows if memory blending (by GPU) is supported or not
-- @return false: 'mem_blend' is not supported in the driver; true: 'mem_blend' is supported in the driver
function Is_Mem_Blend_Supported return U_Bool;
-- Shows if memory fill (by GPU) is supported or not
-- @return false: 'mem_fill' is not supported in the drover; true: 'mem_fill' is supported in the driver
function Is_Mem_Fill_Supported return U_Bool;
private
type Disp_T is new System.Address;
-------------
-- Imports --
-------------
pragma Import (C, Init_Drv, "lv_disp_drv_init");
pragma Import (C, Register, "lv_disp_drv_register");
pragma Import (C, Set_Active, "lv_disp_set_active");
pragma Import (C, Get_Active, "lv_disp_get_active");
pragma Import (C, Next, "lv_disp_next");
pragma Import (C, Flush, "lv_disp_flush");
pragma Import (C, Fill, "lv_disp_fill");
pragma Import (C, Map, "lv_disp_map");
pragma Import (C, Mem_Blend, "lv_disp_mem_blend");
pragma Import (C, Mem_Fill, "lv_disp_mem_fill");
pragma Import (C, Is_Mem_Blend_Supported, "lv_disp_is_mem_blend_supported");
pragma Import (C, Is_Mem_Fill_Supported, "lv_disp_is_mem_fill_supported");
end Lv.Hal.Disp;
|
package vectores is
type Vector_De_Enteros is array (Integer range <>) of Integer;
type Vector_De_Reales is array (Integer range <>) of Float;
type Vector_De_Booleanos is array (Integer range <>) of Boolean;
type Vector_De_Caracteres is array (Integer range <>) of Character;
end vectores;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- P R J . E N V --
-- --
-- B o d y --
-- --
-- Copyright (C) 2001-2006, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Namet; use Namet;
with Opt;
with Osint; use Osint;
with Output; use Output;
with Prj.Com; use Prj.Com;
with Tempdir;
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
package body Prj.Env is
Current_Source_Path_File : Name_Id := No_Name;
-- Current value of project source path file env var.
-- Used to avoid setting the env var to the same value.
Current_Object_Path_File : Name_Id := No_Name;
-- Current value of project object path file env var.
-- Used to avoid setting the env var to the same value.
Ada_Path_Buffer : String_Access := new String (1 .. 1024);
-- A buffer where values for ADA_INCLUDE_PATH
-- and ADA_OBJECTS_PATH are stored.
Ada_Path_Length : Natural := 0;
-- Index of the last valid character in Ada_Path_Buffer
Ada_Prj_Include_File_Set : Boolean := False;
Ada_Prj_Objects_File_Set : Boolean := False;
-- These flags are set to True when the corresponding environment variables
-- are set and are used to give these environment variables an empty string
-- value at the end of the program. This has no practical effect on most
-- platforms, except on VMS where the logical names are deassigned, thus
-- avoiding the pollution of the environment of the caller.
Default_Naming : constant Naming_Id := Naming_Table.First;
Fill_Mapping_File : Boolean := True;
type Project_Flags is array (Project_Id range <>) of Boolean;
-- A Boolean array type used in Create_Mapping_File to select the projects
-- in the closure of a specific project.
-----------------------
-- Local Subprograms --
-----------------------
function Body_Path_Name_Of
(Unit : Unit_Id;
In_Tree : Project_Tree_Ref) return String;
-- Returns the path name of the body of a unit.
-- Compute it first, if necessary.
function Spec_Path_Name_Of
(Unit : Unit_Id;
In_Tree : Project_Tree_Ref) return String;
-- Returns the path name of the spec of a unit.
-- Compute it first, if necessary.
procedure Add_To_Path
(Source_Dirs : String_List_Id;
In_Tree : Project_Tree_Ref);
-- Add to Ada_Path_Buffer all the source directories in string list
-- Source_Dirs, if any. Increment Ada_Path_Length.
procedure Add_To_Path (Dir : String);
-- If Dir is not already in the global variable Ada_Path_Buffer, add it.
-- Increment Ada_Path_Length.
-- If Ada_Path_Length /= 0, prepend a Path_Separator character to
-- Path.
procedure Add_To_Source_Path
(Source_Dirs : String_List_Id; In_Tree : Project_Tree_Ref);
-- Add to Ada_Path_B all the source directories in string list
-- Source_Dirs, if any. Increment Ada_Path_Length.
procedure Add_To_Object_Path
(Object_Dir : Name_Id;
In_Tree : Project_Tree_Ref);
-- Add Object_Dir to object path table. Make sure it is not duplicate
-- and it is the last one in the current table.
function Contains_ALI_Files (Dir : Name_Id) return Boolean;
-- Return True if there is at least one ALI file in the directory Dir
procedure Create_New_Path_File
(In_Tree : Project_Tree_Ref;
Path_FD : out File_Descriptor;
Path_Name : out Name_Id);
-- Create a new temporary path file. Get the file name in Path_Name.
-- The name is normally obtained by increasing the number in
-- Temp_Path_File_Name by 1.
procedure Set_Path_File_Var (Name : String; Value : String);
-- Call Setenv, after calling To_Host_File_Spec
function Ultimate_Extension_Of
(Project : Project_Id;
In_Tree : Project_Tree_Ref) return Project_Id;
-- Return a project that is either Project or an extended ancestor of
-- Project that itself is not extended.
----------------------
-- Ada_Include_Path --
----------------------
function Ada_Include_Path
(Project : Project_Id;
In_Tree : Project_Tree_Ref) return String_Access is
procedure Add (Project : Project_Id);
-- Add all the source directories of a project to the path only if
-- this project has not been visited. Calls itself recursively for
-- projects being extended, and imported projects. Adds the project
-- to the list Seen if this is the call to Add for this project.
---------
-- Add --
---------
procedure Add (Project : Project_Id) is
begin
-- If Seen is empty, then the project cannot have been visited
if not In_Tree.Projects.Table (Project).Seen then
In_Tree.Projects.Table (Project).Seen := True;
declare
Data : constant Project_Data :=
In_Tree.Projects.Table (Project);
List : Project_List := Data.Imported_Projects;
begin
-- Add to path all source directories of this project
Add_To_Path (Data.Source_Dirs, In_Tree);
-- Call Add to the project being extended, if any
if Data.Extends /= No_Project then
Add (Data.Extends);
end if;
-- Call Add for each imported project, if any
while List /= Empty_Project_List loop
Add
(In_Tree.Project_Lists.Table (List).Project);
List := In_Tree.Project_Lists.Table (List).Next;
end loop;
end;
end if;
end Add;
-- Start of processing for Ada_Include_Path
begin
-- If it is the first time we call this function for
-- this project, compute the source path
if
In_Tree.Projects.Table (Project).Ada_Include_Path = null
then
Ada_Path_Length := 0;
for Index in Project_Table.First ..
Project_Table.Last (In_Tree.Projects)
loop
In_Tree.Projects.Table (Index).Seen := False;
end loop;
Add (Project);
In_Tree.Projects.Table (Project).Ada_Include_Path :=
new String'(Ada_Path_Buffer (1 .. Ada_Path_Length));
end if;
return In_Tree.Projects.Table (Project).Ada_Include_Path;
end Ada_Include_Path;
----------------------
-- Ada_Include_Path --
----------------------
function Ada_Include_Path
(Project : Project_Id;
In_Tree : Project_Tree_Ref;
Recursive : Boolean) return String
is
begin
if Recursive then
return Ada_Include_Path (Project, In_Tree).all;
else
Ada_Path_Length := 0;
Add_To_Path
(In_Tree.Projects.Table (Project).Source_Dirs, In_Tree);
return Ada_Path_Buffer (1 .. Ada_Path_Length);
end if;
end Ada_Include_Path;
----------------------
-- Ada_Objects_Path --
----------------------
function Ada_Objects_Path
(Project : Project_Id;
In_Tree : Project_Tree_Ref;
Including_Libraries : Boolean := True) return String_Access
is
procedure Add (Project : Project_Id);
-- Add all the object directories of a project to the path only if
-- this project has not been visited. Calls itself recursively for
-- projects being extended, and imported projects. Adds the project
-- to the list Seen if this is the first call to Add for this project.
---------
-- Add --
---------
procedure Add (Project : Project_Id) is
begin
-- If this project has not been seen yet
if not In_Tree.Projects.Table (Project).Seen then
In_Tree.Projects.Table (Project).Seen := True;
declare
Data : constant Project_Data :=
In_Tree.Projects.Table (Project);
List : Project_List := Data.Imported_Projects;
begin
-- Add to path the object directory of this project
-- except if we don't include library project and
-- this is a library project.
if (Data.Library and then Including_Libraries)
or else
(Data.Object_Directory /= No_Name
and then
(not Including_Libraries or else not Data.Library))
then
-- For a library project, add the library directory,
-- if there is no object directory or if it contains ALI
-- files; otherwise add the object directory.
if Data.Library then
if Data.Object_Directory = No_Name
or else
Contains_ALI_Files (Data.Library_ALI_Dir)
then
Add_To_Path (Get_Name_String (Data.Library_ALI_Dir));
else
Add_To_Path (Get_Name_String (Data.Object_Directory));
end if;
else
-- For a non library project, add the object directory
Add_To_Path (Get_Name_String (Data.Object_Directory));
end if;
end if;
-- Call Add to the project being extended, if any
if Data.Extends /= No_Project then
Add (Data.Extends);
end if;
-- Call Add for each imported project, if any
while List /= Empty_Project_List loop
Add
(In_Tree.Project_Lists.Table (List).Project);
List := In_Tree.Project_Lists.Table (List).Next;
end loop;
end;
end if;
end Add;
-- Start of processing for Ada_Objects_Path
begin
-- If it is the first time we call this function for
-- this project, compute the objects path
if
In_Tree.Projects.Table (Project).Ada_Objects_Path = null
then
Ada_Path_Length := 0;
for Index in Project_Table.First ..
Project_Table.Last (In_Tree.Projects)
loop
In_Tree.Projects.Table (Index).Seen := False;
end loop;
Add (Project);
In_Tree.Projects.Table (Project).Ada_Objects_Path :=
new String'(Ada_Path_Buffer (1 .. Ada_Path_Length));
end if;
return In_Tree.Projects.Table (Project).Ada_Objects_Path;
end Ada_Objects_Path;
------------------------
-- Add_To_Object_Path --
------------------------
procedure Add_To_Object_Path
(Object_Dir : Name_Id; In_Tree : Project_Tree_Ref)
is
begin
-- Check if the directory is already in the table
for Index in Object_Path_Table.First ..
Object_Path_Table.Last (In_Tree.Private_Part.Object_Paths)
loop
-- If it is, remove it, and add it as the last one
if In_Tree.Private_Part.Object_Paths.Table (Index) = Object_Dir then
for Index2 in Index + 1 ..
Object_Path_Table.Last
(In_Tree.Private_Part.Object_Paths)
loop
In_Tree.Private_Part.Object_Paths.Table (Index2 - 1) :=
In_Tree.Private_Part.Object_Paths.Table (Index2);
end loop;
In_Tree.Private_Part.Object_Paths.Table
(Object_Path_Table.Last (In_Tree.Private_Part.Object_Paths)) :=
Object_Dir;
return;
end if;
end loop;
-- The directory is not already in the table, add it
Object_Path_Table.Increment_Last (In_Tree.Private_Part.Object_Paths);
In_Tree.Private_Part.Object_Paths.Table
(Object_Path_Table.Last (In_Tree.Private_Part.Object_Paths)) :=
Object_Dir;
end Add_To_Object_Path;
-----------------
-- Add_To_Path --
-----------------
procedure Add_To_Path
(Source_Dirs : String_List_Id;
In_Tree : Project_Tree_Ref)
is
Current : String_List_Id := Source_Dirs;
Source_Dir : String_Element;
begin
while Current /= Nil_String loop
Source_Dir := In_Tree.String_Elements.Table (Current);
Add_To_Path (Get_Name_String (Source_Dir.Display_Value));
Current := Source_Dir.Next;
end loop;
end Add_To_Path;
procedure Add_To_Path (Dir : String) is
Len : Natural;
New_Buffer : String_Access;
Min_Len : Natural;
function Is_Present (Path : String; Dir : String) return Boolean;
-- Return True if Dir is part of Path
----------------
-- Is_Present --
----------------
function Is_Present (Path : String; Dir : String) return Boolean is
Last : constant Integer := Path'Last - Dir'Length + 1;
begin
for J in Path'First .. Last loop
-- Note: the order of the conditions below is important, since
-- it ensures a minimal number of string comparisons.
if (J = Path'First
or else Path (J - 1) = Path_Separator)
and then
(J + Dir'Length > Path'Last
or else Path (J + Dir'Length) = Path_Separator)
and then Dir = Path (J .. J + Dir'Length - 1)
then
return True;
end if;
end loop;
return False;
end Is_Present;
-- Start of processing for Add_To_Path
begin
if Is_Present (Ada_Path_Buffer (1 .. Ada_Path_Length), Dir) then
-- Dir is already in the path, nothing to do
return;
end if;
Min_Len := Ada_Path_Length + Dir'Length;
if Ada_Path_Length > 0 then
-- Add 1 for the Path_Separator character
Min_Len := Min_Len + 1;
end if;
-- If Ada_Path_Buffer is too small, increase it
Len := Ada_Path_Buffer'Last;
if Len < Min_Len then
loop
Len := Len * 2;
exit when Len >= Min_Len;
end loop;
New_Buffer := new String (1 .. Len);
New_Buffer (1 .. Ada_Path_Length) :=
Ada_Path_Buffer (1 .. Ada_Path_Length);
Free (Ada_Path_Buffer);
Ada_Path_Buffer := New_Buffer;
end if;
if Ada_Path_Length > 0 then
Ada_Path_Length := Ada_Path_Length + 1;
Ada_Path_Buffer (Ada_Path_Length) := Path_Separator;
end if;
Ada_Path_Buffer
(Ada_Path_Length + 1 .. Ada_Path_Length + Dir'Length) := Dir;
Ada_Path_Length := Ada_Path_Length + Dir'Length;
end Add_To_Path;
------------------------
-- Add_To_Source_Path --
------------------------
procedure Add_To_Source_Path
(Source_Dirs : String_List_Id; In_Tree : Project_Tree_Ref)
is
Current : String_List_Id := Source_Dirs;
Source_Dir : String_Element;
Add_It : Boolean;
begin
-- Add each source directory
while Current /= Nil_String loop
Source_Dir := In_Tree.String_Elements.Table (Current);
Add_It := True;
-- Check if the source directory is already in the table
for Index in Source_Path_Table.First ..
Source_Path_Table.Last
(In_Tree.Private_Part.Source_Paths)
loop
-- If it is already, no need to add it
if In_Tree.Private_Part.Source_Paths.Table (Index) =
Source_Dir.Value
then
Add_It := False;
exit;
end if;
end loop;
if Add_It then
Source_Path_Table.Increment_Last
(In_Tree.Private_Part.Source_Paths);
In_Tree.Private_Part.Source_Paths.Table
(Source_Path_Table.Last (In_Tree.Private_Part.Source_Paths)) :=
Source_Dir.Value;
end if;
-- Next source directory
Current := Source_Dir.Next;
end loop;
end Add_To_Source_Path;
-----------------------
-- Body_Path_Name_Of --
-----------------------
function Body_Path_Name_Of
(Unit : Unit_Id; In_Tree : Project_Tree_Ref) return String
is
Data : Unit_Data := In_Tree.Units.Table (Unit);
begin
-- If we don't know the path name of the body of this unit,
-- we compute it, and we store it.
if Data.File_Names (Body_Part).Path = No_Name then
declare
Current_Source : String_List_Id :=
In_Tree.Projects.Table
(Data.File_Names (Body_Part).Project).Sources;
Path : GNAT.OS_Lib.String_Access;
begin
-- By default, put the file name
Data.File_Names (Body_Part).Path :=
Data.File_Names (Body_Part).Name;
-- For each source directory
while Current_Source /= Nil_String loop
Path :=
Locate_Regular_File
(Namet.Get_Name_String
(Data.File_Names (Body_Part).Name),
Namet.Get_Name_String
(In_Tree.String_Elements.Table
(Current_Source).Value));
-- If the file is in this directory, then we store the path,
-- and we are done.
if Path /= null then
Name_Len := Path'Length;
Name_Buffer (1 .. Name_Len) := Path.all;
Data.File_Names (Body_Part).Path := Name_Enter;
exit;
else
Current_Source :=
In_Tree.String_Elements.Table
(Current_Source).Next;
end if;
end loop;
In_Tree.Units.Table (Unit) := Data;
end;
end if;
-- Returned the stored value
return Namet.Get_Name_String (Data.File_Names (Body_Part).Path);
end Body_Path_Name_Of;
------------------------
-- Contains_ALI_Files --
------------------------
function Contains_ALI_Files (Dir : Name_Id) return Boolean is
Dir_Name : constant String := Get_Name_String (Dir);
Direct : Dir_Type;
Name : String (1 .. 1_000);
Last : Natural;
Result : Boolean := False;
begin
Open (Direct, Dir_Name);
-- For each file in the directory, check if it is an ALI file
loop
Read (Direct, Name, Last);
exit when Last = 0;
Canonical_Case_File_Name (Name (1 .. Last));
Result := Last >= 5 and then Name (Last - 3 .. Last) = ".ali";
exit when Result;
end loop;
Close (Direct);
return Result;
exception
-- If there is any problem, close the directory if open and return
-- True; the library directory will be added to the path.
when others =>
if Is_Open (Direct) then
Close (Direct);
end if;
return True;
end Contains_ALI_Files;
--------------------------------
-- Create_Config_Pragmas_File --
--------------------------------
procedure Create_Config_Pragmas_File
(For_Project : Project_Id;
Main_Project : Project_Id;
In_Tree : Project_Tree_Ref;
Include_Config_Files : Boolean := True)
is
pragma Unreferenced (Main_Project);
pragma Unreferenced (Include_Config_Files);
File_Name : Name_Id := No_Name;
File : File_Descriptor := Invalid_FD;
Current_Unit : Unit_Id := Unit_Table.First;
First_Project : Project_List := Empty_Project_List;
Current_Project : Project_List;
Current_Naming : Naming_Id;
Status : Boolean;
-- For call to Close
procedure Check (Project : Project_Id);
-- Recursive procedure that put in the config pragmas file any non
-- standard naming schemes, if it is not already in the file, then call
-- itself for any imported project.
procedure Check_Temp_File;
-- Check that a temporary file has been opened.
-- If not, create one, and put its name in the project data,
-- with the indication that it is a temporary file.
procedure Put
(Unit_Name : Name_Id;
File_Name : Name_Id;
Unit_Kind : Spec_Or_Body;
Index : Int);
-- Put an SFN pragma in the temporary file
procedure Put (File : File_Descriptor; S : String);
procedure Put_Line (File : File_Descriptor; S : String);
-- Output procedures, analogous to normal Text_IO procs of same name
-----------
-- Check --
-----------
procedure Check (Project : Project_Id) is
Data : constant Project_Data :=
In_Tree.Projects.Table (Project);
begin
if Current_Verbosity = High then
Write_Str ("Checking project file """);
Write_Str (Namet.Get_Name_String (Data.Name));
Write_Str (""".");
Write_Eol;
end if;
-- Is this project in the list of the visited project?
Current_Project := First_Project;
while Current_Project /= Empty_Project_List
and then In_Tree.Project_Lists.Table
(Current_Project).Project /= Project
loop
Current_Project :=
In_Tree.Project_Lists.Table (Current_Project).Next;
end loop;
-- If it is not, put it in the list, and visit it
if Current_Project = Empty_Project_List then
Project_List_Table.Increment_Last
(In_Tree.Project_Lists);
In_Tree.Project_Lists.Table
(Project_List_Table.Last (In_Tree.Project_Lists)) :=
(Project => Project, Next => First_Project);
First_Project :=
Project_List_Table.Last (In_Tree.Project_Lists);
-- Is the naming scheme of this project one that we know?
Current_Naming := Default_Naming;
while Current_Naming <=
Naming_Table.Last (In_Tree.Private_Part.Namings)
and then not Same_Naming_Scheme
(Left => In_Tree.Private_Part.Namings.Table (Current_Naming),
Right => Data.Naming) loop
Current_Naming := Current_Naming + 1;
end loop;
-- If we don't know it, add it
if Current_Naming >
Naming_Table.Last (In_Tree.Private_Part.Namings)
then
Naming_Table.Increment_Last (In_Tree.Private_Part.Namings);
In_Tree.Private_Part.Namings.Table
(Naming_Table.Last (In_Tree.Private_Part.Namings)) :=
Data.Naming;
-- We need a temporary file to be created
Check_Temp_File;
-- Put the SFN pragmas for the naming scheme
-- Spec
Put_Line
(File, "pragma Source_File_Name_Project");
Put_Line
(File, " (Spec_File_Name => ""*" &
Namet.Get_Name_String (Data.Naming.Ada_Spec_Suffix) &
""",");
Put_Line
(File, " Casing => " &
Image (Data.Naming.Casing) & ",");
Put_Line
(File, " Dot_Replacement => """ &
Namet.Get_Name_String (Data.Naming.Dot_Replacement) &
""");");
-- and body
Put_Line
(File, "pragma Source_File_Name_Project");
Put_Line
(File, " (Body_File_Name => ""*" &
Namet.Get_Name_String (Data.Naming.Ada_Body_Suffix) &
""",");
Put_Line
(File, " Casing => " &
Image (Data.Naming.Casing) & ",");
Put_Line
(File, " Dot_Replacement => """ &
Namet.Get_Name_String (Data.Naming.Dot_Replacement) &
""");");
-- and maybe separate
if
Data.Naming.Ada_Body_Suffix /= Data.Naming.Separate_Suffix
then
Put_Line
(File, "pragma Source_File_Name_Project");
Put_Line
(File, " (Subunit_File_Name => ""*" &
Namet.Get_Name_String (Data.Naming.Separate_Suffix) &
""",");
Put_Line
(File, " Casing => " &
Image (Data.Naming.Casing) &
",");
Put_Line
(File, " Dot_Replacement => """ &
Namet.Get_Name_String (Data.Naming.Dot_Replacement) &
""");");
end if;
end if;
if Data.Extends /= No_Project then
Check (Data.Extends);
end if;
declare
Current : Project_List := Data.Imported_Projects;
begin
while Current /= Empty_Project_List loop
Check
(In_Tree.Project_Lists.Table
(Current).Project);
Current := In_Tree.Project_Lists.Table
(Current).Next;
end loop;
end;
end if;
end Check;
---------------------
-- Check_Temp_File --
---------------------
procedure Check_Temp_File is
begin
if File = Invalid_FD then
Tempdir.Create_Temp_File (File, Name => File_Name);
if File = Invalid_FD then
Prj.Com.Fail
("unable to create temporary configuration pragmas file");
elsif Opt.Verbose_Mode then
Write_Str ("Creating temp file """);
Write_Str (Get_Name_String (File_Name));
Write_Line ("""");
end if;
end if;
end Check_Temp_File;
---------
-- Put --
---------
procedure Put
(Unit_Name : Name_Id;
File_Name : Name_Id;
Unit_Kind : Spec_Or_Body;
Index : Int)
is
begin
-- A temporary file needs to be open
Check_Temp_File;
-- Put the pragma SFN for the unit kind (spec or body)
Put (File, "pragma Source_File_Name_Project (");
Put (File, Namet.Get_Name_String (Unit_Name));
if Unit_Kind = Specification then
Put (File, ", Spec_File_Name => """);
else
Put (File, ", Body_File_Name => """);
end if;
Put (File, Namet.Get_Name_String (File_Name));
Put (File, """");
if Index /= 0 then
Put (File, ", Index =>");
Put (File, Index'Img);
end if;
Put_Line (File, ");");
end Put;
procedure Put (File : File_Descriptor; S : String) is
Last : Natural;
begin
Last := Write (File, S (S'First)'Address, S'Length);
if Last /= S'Length then
Prj.Com.Fail ("Disk full");
end if;
if Current_Verbosity = High then
Write_Str (S);
end if;
end Put;
--------------
-- Put_Line --
--------------
procedure Put_Line (File : File_Descriptor; S : String) is
S0 : String (1 .. S'Length + 1);
Last : Natural;
begin
-- Add an ASCII.LF to the string. As this config file is supposed to
-- be used only by the compiler, we don't care about the characters
-- for the end of line. In fact we could have put a space, but
-- it is more convenient to be able to read gnat.adc during
-- development, for which the ASCII.LF is fine.
S0 (1 .. S'Length) := S;
S0 (S0'Last) := ASCII.LF;
Last := Write (File, S0'Address, S0'Length);
if Last /= S'Length + 1 then
Prj.Com.Fail ("Disk full");
end if;
if Current_Verbosity = High then
Write_Line (S);
end if;
end Put_Line;
-- Start of processing for Create_Config_Pragmas_File
begin
if not
In_Tree.Projects.Table (For_Project).Config_Checked
then
-- Remove any memory of processed naming schemes, if any
Naming_Table.Set_Last (In_Tree.Private_Part.Namings, Default_Naming);
-- Check the naming schemes
Check (For_Project);
-- Visit all the units and process those that need an SFN pragma
while
Current_Unit <= Unit_Table.Last (In_Tree.Units)
loop
declare
Unit : constant Unit_Data :=
In_Tree.Units.Table (Current_Unit);
begin
if Unit.File_Names (Specification).Needs_Pragma then
Put (Unit.Name,
Unit.File_Names (Specification).Name,
Specification,
Unit.File_Names (Specification).Index);
end if;
if Unit.File_Names (Body_Part).Needs_Pragma then
Put (Unit.Name,
Unit.File_Names (Body_Part).Name,
Body_Part,
Unit.File_Names (Body_Part).Index);
end if;
Current_Unit := Current_Unit + 1;
end;
end loop;
-- If there are no non standard naming scheme, issue the GNAT
-- standard naming scheme. This will tell the compiler that
-- a project file is used and will forbid any pragma SFN.
if File = Invalid_FD then
Check_Temp_File;
Put_Line (File, "pragma Source_File_Name_Project");
Put_Line (File, " (Spec_File_Name => ""*.ads"",");
Put_Line (File, " Dot_Replacement => ""-"",");
Put_Line (File, " Casing => lowercase);");
Put_Line (File, "pragma Source_File_Name_Project");
Put_Line (File, " (Body_File_Name => ""*.adb"",");
Put_Line (File, " Dot_Replacement => ""-"",");
Put_Line (File, " Casing => lowercase);");
end if;
-- Close the temporary file
GNAT.OS_Lib.Close (File, Status);
if not Status then
Prj.Com.Fail ("disk full");
end if;
if Opt.Verbose_Mode then
Write_Str ("Closing configuration file """);
Write_Str (Get_Name_String (File_Name));
Write_Line ("""");
end if;
In_Tree.Projects.Table (For_Project).Config_File_Name :=
File_Name;
In_Tree.Projects.Table (For_Project).Config_File_Temp :=
True;
In_Tree.Projects.Table (For_Project).Config_Checked :=
True;
end if;
end Create_Config_Pragmas_File;
-------------------------
-- Create_Mapping_File --
-------------------------
procedure Create_Mapping_File
(Project : Project_Id;
In_Tree : Project_Tree_Ref;
Name : out Name_Id)
is
File : File_Descriptor := Invalid_FD;
The_Unit_Data : Unit_Data;
Data : File_Name_Data;
Status : Boolean;
-- For call to Close
Present : Project_Flags
(No_Project .. Project_Table.Last (In_Tree.Projects)) :=
(others => False);
-- For each project in the closure of Project, the corresponding flag
-- will be set to True;
procedure Put_Name_Buffer;
-- Put the line contained in the Name_Buffer in the mapping file
procedure Put_Data (Spec : Boolean);
-- Put the mapping of the spec or body contained in Data in the file
-- (3 lines).
procedure Recursive_Flag (Prj : Project_Id);
-- Set the flags corresponding to Prj, the projects it imports
-- (directly or indirectly) or extends to True. Call itself recursively.
---------
-- Put --
---------
procedure Put_Name_Buffer is
Last : Natural;
begin
Name_Len := Name_Len + 1;
Name_Buffer (Name_Len) := ASCII.LF;
Last := Write (File, Name_Buffer (1)'Address, Name_Len);
if Last /= Name_Len then
Prj.Com.Fail ("Disk full");
end if;
end Put_Name_Buffer;
--------------
-- Put_Data --
--------------
procedure Put_Data (Spec : Boolean) is
begin
-- Line with the unit name
Get_Name_String (The_Unit_Data.Name);
Name_Len := Name_Len + 1;
Name_Buffer (Name_Len) := '%';
Name_Len := Name_Len + 1;
if Spec then
Name_Buffer (Name_Len) := 's';
else
Name_Buffer (Name_Len) := 'b';
end if;
Put_Name_Buffer;
-- Line with the file name
Get_Name_String (Data.Name);
Put_Name_Buffer;
-- Line with the path name
Get_Name_String (Data.Path);
Put_Name_Buffer;
end Put_Data;
--------------------
-- Recursive_Flag --
--------------------
procedure Recursive_Flag (Prj : Project_Id) is
Imported : Project_List;
Proj : Project_Id;
begin
-- Nothing to do for non existent project or project that has
-- already been flagged.
if Prj = No_Project or else Present (Prj) then
return;
end if;
-- Flag the current project
Present (Prj) := True;
Imported :=
In_Tree.Projects.Table (Prj).Imported_Projects;
-- Call itself for each project directly imported
while Imported /= Empty_Project_List loop
Proj :=
In_Tree.Project_Lists.Table (Imported).Project;
Imported :=
In_Tree.Project_Lists.Table (Imported).Next;
Recursive_Flag (Proj);
end loop;
-- Call itself for an eventual project being extended
Recursive_Flag (In_Tree.Projects.Table (Prj).Extends);
end Recursive_Flag;
-- Start of processing for Create_Mapping_File
begin
-- Flag the necessary projects
Recursive_Flag (Project);
-- Create the temporary file
Tempdir.Create_Temp_File (File, Name => Name);
if File = Invalid_FD then
Prj.Com.Fail ("unable to create temporary mapping file");
elsif Opt.Verbose_Mode then
Write_Str ("Creating temp mapping file """);
Write_Str (Get_Name_String (Name));
Write_Line ("""");
end if;
if Fill_Mapping_File then
-- For all units in table Units
for Unit in 1 .. Unit_Table.Last (In_Tree.Units) loop
The_Unit_Data := In_Tree.Units.Table (Unit);
-- If the unit has a valid name
if The_Unit_Data.Name /= No_Name then
Data := The_Unit_Data.File_Names (Specification);
-- If there is a spec, put it mapping in the file if it is
-- from a project in the closure of Project.
if Data.Name /= No_Name and then Present (Data.Project) then
Put_Data (Spec => True);
end if;
Data := The_Unit_Data.File_Names (Body_Part);
-- If there is a body (or subunit) put its mapping in the file
-- if it is from a project in the closure of Project.
if Data.Name /= No_Name and then Present (Data.Project) then
Put_Data (Spec => False);
end if;
end if;
end loop;
end if;
GNAT.OS_Lib.Close (File, Status);
if not Status then
Prj.Com.Fail ("disk full");
end if;
end Create_Mapping_File;
--------------------------
-- Create_New_Path_File --
--------------------------
procedure Create_New_Path_File
(In_Tree : Project_Tree_Ref;
Path_FD : out File_Descriptor;
Path_Name : out Name_Id)
is
begin
Tempdir.Create_Temp_File (Path_FD, Path_Name);
if Path_Name /= No_Name then
-- Record the name, so that the temp path file will be deleted
-- at the end of the program.
Path_File_Table.Increment_Last (In_Tree.Private_Part.Path_Files);
In_Tree.Private_Part.Path_Files.Table
(Path_File_Table.Last (In_Tree.Private_Part.Path_Files)) :=
Path_Name;
end if;
end Create_New_Path_File;
---------------------------
-- Delete_All_Path_Files --
---------------------------
procedure Delete_All_Path_Files (In_Tree : Project_Tree_Ref) is
Disregard : Boolean := True;
begin
for Index in Path_File_Table.First ..
Path_File_Table.Last (In_Tree.Private_Part.Path_Files)
loop
if In_Tree.Private_Part.Path_Files.Table (Index) /= No_Name then
Delete_File
(Get_Name_String
(In_Tree.Private_Part.Path_Files.Table (Index)),
Disregard);
end if;
end loop;
-- If any of the environment variables ADA_PRJ_INCLUDE_FILE or
-- ADA_PRJ_OBJECTS_FILE has been set, then reset their value to
-- the empty string. On VMS, this has the effect of deassigning
-- the logical names.
if Ada_Prj_Include_File_Set then
Setenv (Project_Include_Path_File, "");
Ada_Prj_Include_File_Set := False;
end if;
if Ada_Prj_Objects_File_Set then
Setenv (Project_Objects_Path_File, "");
Ada_Prj_Objects_File_Set := False;
end if;
end Delete_All_Path_Files;
------------------------------------
-- File_Name_Of_Library_Unit_Body --
------------------------------------
function File_Name_Of_Library_Unit_Body
(Name : String;
Project : Project_Id;
In_Tree : Project_Tree_Ref;
Main_Project_Only : Boolean := True;
Full_Path : Boolean := False) return String
is
The_Project : Project_Id := Project;
Data : Project_Data :=
In_Tree.Projects.Table (Project);
Original_Name : String := Name;
Extended_Spec_Name : String :=
Name & Namet.Get_Name_String
(Data.Naming.Ada_Spec_Suffix);
Extended_Body_Name : String :=
Name & Namet.Get_Name_String
(Data.Naming.Ada_Body_Suffix);
Unit : Unit_Data;
The_Original_Name : Name_Id;
The_Spec_Name : Name_Id;
The_Body_Name : Name_Id;
begin
Canonical_Case_File_Name (Original_Name);
Name_Len := Original_Name'Length;
Name_Buffer (1 .. Name_Len) := Original_Name;
The_Original_Name := Name_Find;
Canonical_Case_File_Name (Extended_Spec_Name);
Name_Len := Extended_Spec_Name'Length;
Name_Buffer (1 .. Name_Len) := Extended_Spec_Name;
The_Spec_Name := Name_Find;
Canonical_Case_File_Name (Extended_Body_Name);
Name_Len := Extended_Body_Name'Length;
Name_Buffer (1 .. Name_Len) := Extended_Body_Name;
The_Body_Name := Name_Find;
if Current_Verbosity = High then
Write_Str ("Looking for file name of """);
Write_Str (Name);
Write_Char ('"');
Write_Eol;
Write_Str (" Extended Spec Name = """);
Write_Str (Extended_Spec_Name);
Write_Char ('"');
Write_Eol;
Write_Str (" Extended Body Name = """);
Write_Str (Extended_Body_Name);
Write_Char ('"');
Write_Eol;
end if;
-- For extending project, search in the extended project
-- if the source is not found. For non extending projects,
-- this loop will be run only once.
loop
-- Loop through units
-- Should have comment explaining reverse ???
for Current in reverse Unit_Table.First ..
Unit_Table.Last (In_Tree.Units)
loop
Unit := In_Tree.Units.Table (Current);
-- Check for body
if not Main_Project_Only
or else Unit.File_Names (Body_Part).Project = The_Project
then
declare
Current_Name : constant Name_Id :=
Unit.File_Names (Body_Part).Name;
begin
-- Case of a body present
if Current_Name /= No_Name then
if Current_Verbosity = High then
Write_Str (" Comparing with """);
Write_Str (Get_Name_String (Current_Name));
Write_Char ('"');
Write_Eol;
end if;
-- If it has the name of the original name,
-- return the original name
if Unit.Name = The_Original_Name
or else Current_Name = The_Original_Name
then
if Current_Verbosity = High then
Write_Line (" OK");
end if;
if Full_Path then
return Get_Name_String
(Unit.File_Names (Body_Part).Path);
else
return Get_Name_String (Current_Name);
end if;
-- If it has the name of the extended body name,
-- return the extended body name
elsif Current_Name = The_Body_Name then
if Current_Verbosity = High then
Write_Line (" OK");
end if;
if Full_Path then
return Get_Name_String
(Unit.File_Names (Body_Part).Path);
else
return Extended_Body_Name;
end if;
else
if Current_Verbosity = High then
Write_Line (" not good");
end if;
end if;
end if;
end;
end if;
-- Check for spec
if not Main_Project_Only
or else Unit.File_Names (Specification).Project = The_Project
then
declare
Current_Name : constant Name_Id :=
Unit.File_Names (Specification).Name;
begin
-- Case of spec present
if Current_Name /= No_Name then
if Current_Verbosity = High then
Write_Str (" Comparing with """);
Write_Str (Get_Name_String (Current_Name));
Write_Char ('"');
Write_Eol;
end if;
-- If name same as original name, return original name
if Unit.Name = The_Original_Name
or else Current_Name = The_Original_Name
then
if Current_Verbosity = High then
Write_Line (" OK");
end if;
if Full_Path then
return Get_Name_String
(Unit.File_Names (Specification).Path);
else
return Get_Name_String (Current_Name);
end if;
-- If it has the same name as the extended spec name,
-- return the extended spec name.
elsif Current_Name = The_Spec_Name then
if Current_Verbosity = High then
Write_Line (" OK");
end if;
if Full_Path then
return Get_Name_String
(Unit.File_Names (Specification).Path);
else
return Extended_Spec_Name;
end if;
else
if Current_Verbosity = High then
Write_Line (" not good");
end if;
end if;
end if;
end;
end if;
end loop;
-- If we are not in an extending project, give up
exit when (not Main_Project_Only) or else Data.Extends = No_Project;
-- Otherwise, look in the project we are extending
The_Project := Data.Extends;
Data := In_Tree.Projects.Table (The_Project);
end loop;
-- We don't know this file name, return an empty string
return "";
end File_Name_Of_Library_Unit_Body;
-------------------------
-- For_All_Object_Dirs --
-------------------------
procedure For_All_Object_Dirs
(Project : Project_Id;
In_Tree : Project_Tree_Ref)
is
Seen : Project_List := Empty_Project_List;
procedure Add (Project : Project_Id);
-- Process a project. Remember the processes visited to avoid
-- processing a project twice. Recursively process an eventual
-- extended project, and all imported projects.
---------
-- Add --
---------
procedure Add (Project : Project_Id) is
Data : constant Project_Data :=
In_Tree.Projects.Table (Project);
List : Project_List := Data.Imported_Projects;
begin
-- If the list of visited project is empty, then
-- for sure we never visited this project.
if Seen = Empty_Project_List then
Project_List_Table.Increment_Last
(In_Tree.Project_Lists);
Seen :=
Project_List_Table.Last (In_Tree.Project_Lists);
In_Tree.Project_Lists.Table (Seen) :=
(Project => Project, Next => Empty_Project_List);
else
-- Check if the project is in the list
declare
Current : Project_List := Seen;
begin
loop
-- If it is, then there is nothing else to do
if In_Tree.Project_Lists.Table
(Current).Project = Project
then
return;
end if;
exit when
In_Tree.Project_Lists.Table (Current).Next =
Empty_Project_List;
Current :=
In_Tree.Project_Lists.Table (Current).Next;
end loop;
-- This project has never been visited, add it
-- to the list.
Project_List_Table.Increment_Last
(In_Tree.Project_Lists);
In_Tree.Project_Lists.Table (Current).Next :=
Project_List_Table.Last (In_Tree.Project_Lists);
In_Tree.Project_Lists.Table
(Project_List_Table.Last
(In_Tree.Project_Lists)) :=
(Project => Project, Next => Empty_Project_List);
end;
end if;
-- If there is an object directory, call Action
-- with its name
if Data.Object_Directory /= No_Name then
Get_Name_String (Data.Object_Directory);
Action (Name_Buffer (1 .. Name_Len));
end if;
-- If we are extending a project, visit it
if Data.Extends /= No_Project then
Add (Data.Extends);
end if;
-- And visit all imported projects
while List /= Empty_Project_List loop
Add (In_Tree.Project_Lists.Table (List).Project);
List := In_Tree.Project_Lists.Table (List).Next;
end loop;
end Add;
-- Start of processing for For_All_Object_Dirs
begin
-- Visit this project, and its imported projects,
-- recursively
Add (Project);
end For_All_Object_Dirs;
-------------------------
-- For_All_Source_Dirs --
-------------------------
procedure For_All_Source_Dirs
(Project : Project_Id;
In_Tree : Project_Tree_Ref)
is
Seen : Project_List := Empty_Project_List;
procedure Add (Project : Project_Id);
-- Process a project. Remember the processes visited to avoid
-- processing a project twice. Recursively process an eventual
-- extended project, and all imported projects.
---------
-- Add --
---------
procedure Add (Project : Project_Id) is
Data : constant Project_Data :=
In_Tree.Projects.Table (Project);
List : Project_List := Data.Imported_Projects;
begin
-- If the list of visited project is empty, then
-- for sure we never visited this project.
if Seen = Empty_Project_List then
Project_List_Table.Increment_Last
(In_Tree.Project_Lists);
Seen := Project_List_Table.Last
(In_Tree.Project_Lists);
In_Tree.Project_Lists.Table (Seen) :=
(Project => Project, Next => Empty_Project_List);
else
-- Check if the project is in the list
declare
Current : Project_List := Seen;
begin
loop
-- If it is, then there is nothing else to do
if In_Tree.Project_Lists.Table
(Current).Project = Project
then
return;
end if;
exit when
In_Tree.Project_Lists.Table (Current).Next =
Empty_Project_List;
Current :=
In_Tree.Project_Lists.Table (Current).Next;
end loop;
-- This project has never been visited, add it
-- to the list.
Project_List_Table.Increment_Last
(In_Tree.Project_Lists);
In_Tree.Project_Lists.Table (Current).Next :=
Project_List_Table.Last (In_Tree.Project_Lists);
In_Tree.Project_Lists.Table
(Project_List_Table.Last
(In_Tree.Project_Lists)) :=
(Project => Project, Next => Empty_Project_List);
end;
end if;
declare
Current : String_List_Id := Data.Source_Dirs;
The_String : String_Element;
begin
-- If there are Ada sources, call action with the name of every
-- source directory.
if
In_Tree.Projects.Table (Project).Ada_Sources_Present
then
while Current /= Nil_String loop
The_String :=
In_Tree.String_Elements.Table (Current);
Action (Get_Name_String (The_String.Value));
Current := The_String.Next;
end loop;
end if;
end;
-- If we are extending a project, visit it
if Data.Extends /= No_Project then
Add (Data.Extends);
end if;
-- And visit all imported projects
while List /= Empty_Project_List loop
Add (In_Tree.Project_Lists.Table (List).Project);
List := In_Tree.Project_Lists.Table (List).Next;
end loop;
end Add;
-- Start of processing for For_All_Source_Dirs
begin
-- Visit this project, and its imported projects recursively
Add (Project);
end For_All_Source_Dirs;
-------------------
-- Get_Reference --
-------------------
procedure Get_Reference
(Source_File_Name : String;
In_Tree : Project_Tree_Ref;
Project : out Project_Id;
Path : out Name_Id)
is
begin
-- Body below could use some comments ???
if Current_Verbosity > Default then
Write_Str ("Getting Reference_Of (""");
Write_Str (Source_File_Name);
Write_Str (""") ... ");
end if;
declare
Original_Name : String := Source_File_Name;
Unit : Unit_Data;
begin
Canonical_Case_File_Name (Original_Name);
for Id in Unit_Table.First ..
Unit_Table.Last (In_Tree.Units)
loop
Unit := In_Tree.Units.Table (Id);
if (Unit.File_Names (Specification).Name /= No_Name
and then
Namet.Get_Name_String
(Unit.File_Names (Specification).Name) = Original_Name)
or else (Unit.File_Names (Specification).Path /= No_Name
and then
Namet.Get_Name_String
(Unit.File_Names (Specification).Path) =
Original_Name)
then
Project := Ultimate_Extension_Of
(Project => Unit.File_Names (Specification).Project,
In_Tree => In_Tree);
Path := Unit.File_Names (Specification).Display_Path;
if Current_Verbosity > Default then
Write_Str ("Done: Specification.");
Write_Eol;
end if;
return;
elsif (Unit.File_Names (Body_Part).Name /= No_Name
and then
Namet.Get_Name_String
(Unit.File_Names (Body_Part).Name) = Original_Name)
or else (Unit.File_Names (Body_Part).Path /= No_Name
and then Namet.Get_Name_String
(Unit.File_Names (Body_Part).Path) =
Original_Name)
then
Project := Ultimate_Extension_Of
(Project => Unit.File_Names (Body_Part).Project,
In_Tree => In_Tree);
Path := Unit.File_Names (Body_Part).Display_Path;
if Current_Verbosity > Default then
Write_Str ("Done: Body.");
Write_Eol;
end if;
return;
end if;
end loop;
end;
Project := No_Project;
Path := No_Name;
if Current_Verbosity > Default then
Write_Str ("Cannot be found.");
Write_Eol;
end if;
end Get_Reference;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
Fill_Mapping_File := True;
end Initialize;
------------------------------------
-- Path_Name_Of_Library_Unit_Body --
------------------------------------
-- Could use some comments in the body here ???
function Path_Name_Of_Library_Unit_Body
(Name : String;
Project : Project_Id;
In_Tree : Project_Tree_Ref) return String
is
Data : constant Project_Data :=
In_Tree.Projects.Table (Project);
Original_Name : String := Name;
Extended_Spec_Name : String :=
Name & Namet.Get_Name_String
(Data.Naming.Ada_Spec_Suffix);
Extended_Body_Name : String :=
Name & Namet.Get_Name_String
(Data.Naming.Ada_Body_Suffix);
First : Unit_Id := Unit_Table.First;
Current : Unit_Id;
Unit : Unit_Data;
begin
Canonical_Case_File_Name (Original_Name);
Canonical_Case_File_Name (Extended_Spec_Name);
Canonical_Case_File_Name (Extended_Body_Name);
if Current_Verbosity = High then
Write_Str ("Looking for path name of """);
Write_Str (Name);
Write_Char ('"');
Write_Eol;
Write_Str (" Extended Spec Name = """);
Write_Str (Extended_Spec_Name);
Write_Char ('"');
Write_Eol;
Write_Str (" Extended Body Name = """);
Write_Str (Extended_Body_Name);
Write_Char ('"');
Write_Eol;
end if;
while First <= Unit_Table.Last (In_Tree.Units)
and then In_Tree.Units.Table
(First).File_Names (Body_Part).Project /= Project
loop
First := First + 1;
end loop;
Current := First;
while Current <= Unit_Table.Last (In_Tree.Units) loop
Unit := In_Tree.Units.Table (Current);
if Unit.File_Names (Body_Part).Project = Project
and then Unit.File_Names (Body_Part).Name /= No_Name
then
declare
Current_Name : constant String :=
Namet.Get_Name_String (Unit.File_Names (Body_Part).Name);
begin
if Current_Verbosity = High then
Write_Str (" Comparing with """);
Write_Str (Current_Name);
Write_Char ('"');
Write_Eol;
end if;
if Current_Name = Original_Name then
if Current_Verbosity = High then
Write_Line (" OK");
end if;
return Body_Path_Name_Of (Current, In_Tree);
elsif Current_Name = Extended_Body_Name then
if Current_Verbosity = High then
Write_Line (" OK");
end if;
return Body_Path_Name_Of (Current, In_Tree);
else
if Current_Verbosity = High then
Write_Line (" not good");
end if;
end if;
end;
elsif Unit.File_Names (Specification).Name /= No_Name then
declare
Current_Name : constant String :=
Namet.Get_Name_String
(Unit.File_Names (Specification).Name);
begin
if Current_Verbosity = High then
Write_Str (" Comparing with """);
Write_Str (Current_Name);
Write_Char ('"');
Write_Eol;
end if;
if Current_Name = Original_Name then
if Current_Verbosity = High then
Write_Line (" OK");
end if;
return Spec_Path_Name_Of (Current, In_Tree);
elsif Current_Name = Extended_Spec_Name then
if Current_Verbosity = High then
Write_Line (" OK");
end if;
return Spec_Path_Name_Of (Current, In_Tree);
else
if Current_Verbosity = High then
Write_Line (" not good");
end if;
end if;
end;
end if;
Current := Current + 1;
end loop;
return "";
end Path_Name_Of_Library_Unit_Body;
-------------------
-- Print_Sources --
-------------------
-- Could use some comments in this body ???
procedure Print_Sources (In_Tree : Project_Tree_Ref) is
Unit : Unit_Data;
begin
Write_Line ("List of Sources:");
for Id in Unit_Table.First ..
Unit_Table.Last (In_Tree.Units)
loop
Unit := In_Tree.Units.Table (Id);
Write_Str (" ");
Write_Line (Namet.Get_Name_String (Unit.Name));
if Unit.File_Names (Specification).Name /= No_Name then
if Unit.File_Names (Specification).Project = No_Project then
Write_Line (" No project");
else
Write_Str (" Project: ");
Get_Name_String
(In_Tree.Projects.Table
(Unit.File_Names (Specification).Project).Path_Name);
Write_Line (Name_Buffer (1 .. Name_Len));
end if;
Write_Str (" spec: ");
Write_Line
(Namet.Get_Name_String
(Unit.File_Names (Specification).Name));
end if;
if Unit.File_Names (Body_Part).Name /= No_Name then
if Unit.File_Names (Body_Part).Project = No_Project then
Write_Line (" No project");
else
Write_Str (" Project: ");
Get_Name_String
(In_Tree.Projects.Table
(Unit.File_Names (Body_Part).Project).Path_Name);
Write_Line (Name_Buffer (1 .. Name_Len));
end if;
Write_Str (" body: ");
Write_Line
(Namet.Get_Name_String
(Unit.File_Names (Body_Part).Name));
end if;
end loop;
Write_Line ("end of List of Sources.");
end Print_Sources;
----------------
-- Project_Of --
----------------
function Project_Of
(Name : String;
Main_Project : Project_Id;
In_Tree : Project_Tree_Ref) return Project_Id
is
Result : Project_Id := No_Project;
Original_Name : String := Name;
Data : constant Project_Data :=
In_Tree.Projects.Table (Main_Project);
Extended_Spec_Name : String :=
Name & Namet.Get_Name_String
(Data.Naming.Ada_Spec_Suffix);
Extended_Body_Name : String :=
Name & Namet.Get_Name_String
(Data.Naming.Ada_Body_Suffix);
Unit : Unit_Data;
Current_Name : Name_Id;
The_Original_Name : Name_Id;
The_Spec_Name : Name_Id;
The_Body_Name : Name_Id;
begin
Canonical_Case_File_Name (Original_Name);
Name_Len := Original_Name'Length;
Name_Buffer (1 .. Name_Len) := Original_Name;
The_Original_Name := Name_Find;
Canonical_Case_File_Name (Extended_Spec_Name);
Name_Len := Extended_Spec_Name'Length;
Name_Buffer (1 .. Name_Len) := Extended_Spec_Name;
The_Spec_Name := Name_Find;
Canonical_Case_File_Name (Extended_Body_Name);
Name_Len := Extended_Body_Name'Length;
Name_Buffer (1 .. Name_Len) := Extended_Body_Name;
The_Body_Name := Name_Find;
for Current in reverse Unit_Table.First ..
Unit_Table.Last (In_Tree.Units)
loop
Unit := In_Tree.Units.Table (Current);
-- Check for body
Current_Name := Unit.File_Names (Body_Part).Name;
-- Case of a body present
if Current_Name /= No_Name then
-- If it has the name of the original name or the body name,
-- we have found the project.
if Unit.Name = The_Original_Name
or else Current_Name = The_Original_Name
or else Current_Name = The_Body_Name
then
Result := Unit.File_Names (Body_Part).Project;
exit;
end if;
end if;
-- Check for spec
Current_Name := Unit.File_Names (Specification).Name;
if Current_Name /= No_Name then
-- If name same as the original name, or the spec name, we have
-- found the project.
if Unit.Name = The_Original_Name
or else Current_Name = The_Original_Name
or else Current_Name = The_Spec_Name
then
Result := Unit.File_Names (Specification).Project;
exit;
end if;
end if;
end loop;
-- Get the ultimate extending project
if Result /= No_Project then
while In_Tree.Projects.Table (Result).Extended_By /=
No_Project
loop
Result := In_Tree.Projects.Table (Result).Extended_By;
end loop;
end if;
return Result;
end Project_Of;
-------------------
-- Set_Ada_Paths --
-------------------
procedure Set_Ada_Paths
(Project : Project_Id;
In_Tree : Project_Tree_Ref;
Including_Libraries : Boolean)
is
Source_FD : File_Descriptor := Invalid_FD;
Object_FD : File_Descriptor := Invalid_FD;
Process_Source_Dirs : Boolean := False;
Process_Object_Dirs : Boolean := False;
Status : Boolean;
-- For calls to Close
Len : Natural;
procedure Add (Proj : Project_Id);
-- Add all the source/object directories of a project to the path only
-- if this project has not been visited. Calls an internal procedure
-- recursively for projects being extended, and imported projects.
---------
-- Add --
---------
procedure Add (Proj : Project_Id) is
procedure Recursive_Add (Project : Project_Id);
-- Recursive procedure to add the source/object paths of extended/
-- imported projects.
-------------------
-- Recursive_Add --
-------------------
procedure Recursive_Add (Project : Project_Id) is
begin
-- If Seen is False, then the project has not yet been visited
if not In_Tree.Projects.Table (Project).Seen then
In_Tree.Projects.Table (Project).Seen := True;
declare
Data : constant Project_Data :=
In_Tree.Projects.Table (Project);
List : Project_List := Data.Imported_Projects;
begin
if Process_Source_Dirs then
-- Add to path all source directories of this project
-- if there are Ada sources.
if In_Tree.Projects.Table
(Project).Ada_Sources_Present
then
Add_To_Source_Path (Data.Source_Dirs, In_Tree);
end if;
end if;
if Process_Object_Dirs then
-- Add to path the object directory of this project
-- except if we don't include library project and
-- this is a library project.
if (Data.Library and then Including_Libraries)
or else
(Data.Object_Directory /= No_Name
and then
(not Including_Libraries or else not Data.Library))
then
-- For a library project, add the library ALI
-- directory if there is no object directory or
-- if the library ALI directory contains ALI files;
-- otherwise add the object directory.
if Data.Library then
if Data.Object_Directory = No_Name
or else Contains_ALI_Files (Data.Library_ALI_Dir)
then
Add_To_Object_Path
(Data.Library_ALI_Dir, In_Tree);
else
Add_To_Object_Path
(Data.Object_Directory, In_Tree);
end if;
-- For a non-library project, add the object
-- directory, if it is not a virtual project, and
-- if there are Ada sources or if the project is an
-- extending project. if There Are No Ada sources,
-- adding the object directory could disrupt
-- the order of the object dirs in the path.
elsif not Data.Virtual
and then (In_Tree.Projects.Table
(Project).Ada_Sources_Present
or else
(Data.Extends /= No_Project
and then
Data.Object_Directory /= No_Name))
then
Add_To_Object_Path
(Data.Object_Directory, In_Tree);
end if;
end if;
end if;
-- Call Add to the project being extended, if any
if Data.Extends /= No_Project then
Recursive_Add (Data.Extends);
end if;
-- Call Add for each imported project, if any
while List /= Empty_Project_List loop
Recursive_Add
(In_Tree.Project_Lists.Table
(List).Project);
List :=
In_Tree.Project_Lists.Table (List).Next;
end loop;
end;
end if;
end Recursive_Add;
begin
Source_Path_Table.Set_Last (In_Tree.Private_Part.Source_Paths, 0);
Object_Path_Table.Set_Last (In_Tree.Private_Part.Object_Paths, 0);
for Index in Project_Table.First ..
Project_Table.Last (In_Tree.Projects)
loop
In_Tree.Projects.Table (Index).Seen := False;
end loop;
Recursive_Add (Proj);
end Add;
-- Start of processing for Set_Ada_Paths
begin
-- If it is the first time we call this procedure for
-- this project, compute the source path and/or the object path.
if In_Tree.Projects.Table (Project).Include_Path_File =
No_Name
then
Process_Source_Dirs := True;
Create_New_Path_File
(In_Tree, Source_FD,
In_Tree.Projects.Table (Project).Include_Path_File);
end if;
-- For the object path, we make a distinction depending on
-- Including_Libraries.
if Including_Libraries then
if In_Tree.Projects.Table
(Project).Objects_Path_File_With_Libs = No_Name
then
Process_Object_Dirs := True;
Create_New_Path_File
(In_Tree, Object_FD, In_Tree.Projects.Table (Project).
Objects_Path_File_With_Libs);
end if;
else
if In_Tree.Projects.Table
(Project).Objects_Path_File_Without_Libs = No_Name
then
Process_Object_Dirs := True;
Create_New_Path_File
(In_Tree, Object_FD, In_Tree.Projects.Table (Project).
Objects_Path_File_Without_Libs);
end if;
end if;
-- If there is something to do, set Seen to False for all projects,
-- then call the recursive procedure Add for Project.
if Process_Source_Dirs or Process_Object_Dirs then
Add (Project);
end if;
-- Write and close any file that has been created
if Source_FD /= Invalid_FD then
for Index in Source_Path_Table.First ..
Source_Path_Table.Last
(In_Tree.Private_Part.Source_Paths)
loop
Get_Name_String (In_Tree.Private_Part.Source_Paths.Table (Index));
Name_Len := Name_Len + 1;
Name_Buffer (Name_Len) := ASCII.LF;
Len := Write (Source_FD, Name_Buffer (1)'Address, Name_Len);
if Len /= Name_Len then
Prj.Com.Fail ("disk full");
end if;
end loop;
Close (Source_FD, Status);
if not Status then
Prj.Com.Fail ("disk full");
end if;
end if;
if Object_FD /= Invalid_FD then
for Index in Object_Path_Table.First ..
Object_Path_Table.Last
(In_Tree.Private_Part.Object_Paths)
loop
Get_Name_String (In_Tree.Private_Part.Object_Paths.Table (Index));
Name_Len := Name_Len + 1;
Name_Buffer (Name_Len) := ASCII.LF;
Len := Write (Object_FD, Name_Buffer (1)'Address, Name_Len);
if Len /= Name_Len then
Prj.Com.Fail ("disk full");
end if;
end loop;
Close (Object_FD, Status);
if not Status then
Prj.Com.Fail ("disk full");
end if;
end if;
-- Set the env vars, if they need to be changed, and set the
-- corresponding flags.
if Current_Source_Path_File /=
In_Tree.Projects.Table (Project).Include_Path_File
then
Current_Source_Path_File :=
In_Tree.Projects.Table (Project).Include_Path_File;
Set_Path_File_Var
(Project_Include_Path_File,
Get_Name_String (Current_Source_Path_File));
Ada_Prj_Include_File_Set := True;
end if;
if Including_Libraries then
if Current_Object_Path_File
/= In_Tree.Projects.Table
(Project).Objects_Path_File_With_Libs
then
Current_Object_Path_File :=
In_Tree.Projects.Table
(Project).Objects_Path_File_With_Libs;
Set_Path_File_Var
(Project_Objects_Path_File,
Get_Name_String (Current_Object_Path_File));
Ada_Prj_Objects_File_Set := True;
end if;
else
if Current_Object_Path_File /=
In_Tree.Projects.Table
(Project).Objects_Path_File_Without_Libs
then
Current_Object_Path_File :=
In_Tree.Projects.Table
(Project).Objects_Path_File_Without_Libs;
Set_Path_File_Var
(Project_Objects_Path_File,
Get_Name_String (Current_Object_Path_File));
Ada_Prj_Objects_File_Set := True;
end if;
end if;
end Set_Ada_Paths;
---------------------------------------------
-- Set_Mapping_File_Initial_State_To_Empty --
---------------------------------------------
procedure Set_Mapping_File_Initial_State_To_Empty is
begin
Fill_Mapping_File := False;
end Set_Mapping_File_Initial_State_To_Empty;
-----------------------
-- Set_Path_File_Var --
-----------------------
procedure Set_Path_File_Var (Name : String; Value : String) is
Host_Spec : String_Access := To_Host_File_Spec (Value);
begin
if Host_Spec = null then
Prj.Com.Fail
("could not convert file name """, Value, """ to host spec");
else
Setenv (Name, Host_Spec.all);
Free (Host_Spec);
end if;
end Set_Path_File_Var;
-----------------------
-- Spec_Path_Name_Of --
-----------------------
function Spec_Path_Name_Of
(Unit : Unit_Id; In_Tree : Project_Tree_Ref) return String
is
Data : Unit_Data := In_Tree.Units.Table (Unit);
begin
if Data.File_Names (Specification).Path = No_Name then
declare
Current_Source : String_List_Id :=
In_Tree.Projects.Table
(Data.File_Names (Specification).Project).Sources;
Path : GNAT.OS_Lib.String_Access;
begin
Data.File_Names (Specification).Path :=
Data.File_Names (Specification).Name;
while Current_Source /= Nil_String loop
Path := Locate_Regular_File
(Namet.Get_Name_String
(Data.File_Names (Specification).Name),
Namet.Get_Name_String
(In_Tree.String_Elements.Table
(Current_Source).Value));
if Path /= null then
Name_Len := Path'Length;
Name_Buffer (1 .. Name_Len) := Path.all;
Data.File_Names (Specification).Path := Name_Enter;
exit;
else
Current_Source :=
In_Tree.String_Elements.Table
(Current_Source).Next;
end if;
end loop;
In_Tree.Units.Table (Unit) := Data;
end;
end if;
return Namet.Get_Name_String (Data.File_Names (Specification).Path);
end Spec_Path_Name_Of;
---------------------------
-- Ultimate_Extension_Of --
---------------------------
function Ultimate_Extension_Of
(Project : Project_Id;
In_Tree : Project_Tree_Ref) return Project_Id
is
Result : Project_Id := Project;
begin
while In_Tree.Projects.Table (Result).Extended_By /=
No_Project
loop
Result := In_Tree.Projects.Table (Result).Extended_By;
end loop;
return Result;
end Ultimate_Extension_Of;
end Prj.Env;
|
package Non_LValue is
type T (Length : Natural) is record
A : String (1 .. Length);
B : String (1 .. Length);
end record;
type T_Ptr is access all T;
type U is record
X : T_Ptr;
end record;
function A (Y : U) return String;
end;
|
with Ada.Characters.Latin_1;
with Ada.Text_IO.Unbounded_IO;
with Dir_Iterators.Recursive;
package body DTG is
use Ada.Characters.Latin_1;
use Ada.Text_IO;
use Ada.Text_IO.Unbounded_IO;
function Create(File_Name : String) return Report is
begin
return R : Report do
AIO.Open(R.Output_File, AIO.Out_File, File_Name);
AIO.Put_Line (R.Output_File, "digraph directories {");
AIO.Put_Line (R.Output_File, "rankdir=" & Quotation & "LR" & Quotation & ";");
end return;
end Create;
overriding
procedure Finalize(Self : in out Report) is
begin
AIO.Put_Line (Self.Output_File, "}");
Close(Self.Output_File);
end Finalize;
function Skip_Dot_Files (E : AD.Directory_Entry_Type) return Boolean is
Name : constant String := AD.Simple_Name (E);
begin
if Name'Length = 1 then
-- Current directory '.', check the longer name.
declare
Parent_Name : constant String := AD.Simple_Name (AD.Containing_Directory (AD.Full_Name (E)));
begin
if Parent_Name'Length > 1 and then Parent_Name (1) = '.' then
return False;
end if;
end;
elsif Name (1) = '.' then
return False;
end if;
return True;
end Skip_Dot_Files;
function Should_Include (R : Report; E : AD.Directory_Entry_Type) return Boolean is
begin
return R.Include_Dot_Files or else Skip_Dot_Files (E);
end Should_Include;
procedure Add (R : in Report; E : in AD.Directory_Entry_Type) is
package AD renames Ada.Directories;
use type ASU.Unbounded_String;
Name : constant ASU.Unbounded_String := Node_Name (AD.Full_Name (E));
Parent_Name : constant ASU.Unbounded_String := Node_Name (Parent (AD.Full_Name (E)));
begin
declare
Source : ASU.Unbounded_String;
Destination : ASU.Unbounded_String;
Element_Name : ASU.Unbounded_String;
begin
if AD.Simple_Name (E) = "." then
Source := Node_Name (Parent (Parent (AD.Full_Name (E))));
Destination := Parent_Name;
Element_Name := ASU.To_Unbounded_String (AD.Simple_Name (Parent (AD.Full_Name (E))));
else
Source := Parent_Name;
Destination := Name;
Element_Name := ASU.To_Unbounded_String (AD.Simple_Name (E));
end if;
Put_Line (R.Output_File, Destination & "[shape=box label=" & Quotation & Element_Name & Quotation & "];");
Put_Line (R.Output_File, Source & " -> " & Destination & ";");
end;
end Add;
function Node_Name (Full_Name : String) return ASU.Unbounded_String is
Safe_Name : ASU.Unbounded_String;
begin
for C of Full_Name loop
case C is
when '/' | '\' | '.' | ':' | ' ' | '-' | '!' | '$' =>
ASU.Append (Safe_Name, '_');
when others =>
ASU.Append (Safe_Name, C);
end case;
end loop;
return Safe_Name;
end Node_Name;
function Replace (Full_Name : String) return ASU.Unbounded_String is
Result : ASU.Unbounded_String;
begin
for C of Full_Name loop
case C is
when '\' =>
ASU.Append (Result, '/');
when others =>
ASU.Append (Result, C);
end case;
end loop;
return Result;
end Replace;
function Parent (Full_Name : String) return String is
begin
return AD.Containing_Directory (Full_Name);
end Parent;
procedure Evaluate (Result : in out Report; Dir_Root : String) is
function Filter (E : AD.Directory_Entry_Type) return Boolean is
begin
if Result.Include_Dot_Files then
return True;
else
declare
Name : constant String := AD.Simple_Name(E);
begin
return not (Name'Length > 1 and then Name(1) = '.');
end;
end if;
end Filter;
Walk : constant Dir_Iterators.Recursive.Recursive_Dir_Walk :=
Dir_Iterators.Recursive.Walk (Dir_Root, Filter'Access);
begin
for Dir_Entry of Walk loop
if AD.Full_Name (Dir_Entry) /= AD.Full_Name (Dir_Root) and DTG.Should_Include (Result, Dir_Entry) then
DTG.Add (Result, Dir_Entry);
end if;
end loop;
end Evaluate;
end DTG;
|
package SomePackage is
type SomeClass is record
someAttribute : Integer := 1;
end record;
function someFunction (Self : in SomeClass) return Integer;
procedure someProcedure (Self : in SomeClass);
procedure someUnrelatedProcedure;
end SomePackage;
|
-----------------------------------------------------------------------
-- ADO Statements -- Database statements
-- Copyright (C) 2009, 2010, 2011, 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 ADO.Statements.Create is
-- Create the query statement
function Create_Statement (Proxy : in Query_Statement_Access;
Expander : in ADO.Parameters.Expander_Access := null)
return Query_Statement;
-- Create the delete statement
function Create_Statement (Proxy : in Delete_Statement_Access;
Expander : in ADO.Parameters.Expander_Access := null)
return Delete_Statement;
-- Create an update statement
function Create_Statement (Proxy : in Update_Statement_Access;
Expander : in ADO.Parameters.Expander_Access := null)
return Update_Statement;
-- Create the insert statement.
function Create_Statement (Proxy : in Update_Statement_Access;
Expander : in ADO.Parameters.Expander_Access := null)
return Insert_Statement;
end ADO.Statements.Create;
|
-----------------------------------------------------------------------
-- awa-events-configs -- Event configuration
-- Copyright (C) 2012, 2013, 2017, 2018 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.Serialize.Mappers.Record_Mapper;
with EL.Utils;
package body AWA.Events.Configs is
use AWA.Events.Queues;
-- ------------------------------
-- Set the configuration value identified by <b>Value</b> after having parsed
-- the element identified by <b>Field</b>.
-- ------------------------------
procedure Set_Member (Into : in out Controller_Config;
Field : in Config_Fields;
Value : in Util.Beans.Objects.Object) is
use Ada.Strings.Unbounded;
use Util.Beans.Objects;
begin
case Field is
when FIELD_NAME =>
Into.Name := Value;
when FIELD_TYPE =>
Into.Queue_Type := Value;
when FIELD_QUEUE_NAME =>
declare
Name : constant String := Util.Beans.Objects.To_String (Value);
begin
Into.Queue := Into.Manager.Find_Queue (Name);
end;
when FIELD_ACTION =>
declare
Expr : constant String := Util.Beans.Objects.To_String (Value);
begin
Into.Action := EL.Expressions.Create_Expression (Expr, Into.Context.all);
exception
when others =>
raise Util.Serialize.Mappers.Field_Error with "Invalid entity type: " & Expr;
end;
when FIELD_PROPERTY_NAME =>
Into.Prop_Name := Value;
when FIELD_PROPERTY_VALUE =>
if Util.Beans.Objects.Is_Null (Into.Prop_Name) then
raise Util.Serialize.Mappers.Field_Error with "Missing property name";
end if;
-- Add the new property.
declare
Name : constant String := Util.Beans.Objects.To_String (Into.Prop_Name);
Expr : constant String := Util.Beans.Objects.To_String (Value);
begin
EL.Beans.Add_Parameter (Container => Into.Params,
Name => Name,
Value => Expr,
Context => Into.Context.all);
end;
Into.Prop_Name := Util.Beans.Objects.Null_Object;
when FIELD_ON_EVENT =>
if Util.Beans.Objects.Is_Null (Into.Name) then
raise Util.Serialize.Mappers.Field_Error with "Missing event name";
end if;
declare
Name : constant String := Util.Beans.Objects.To_String (Into.Name);
begin
Into.Manager.Add_Action (Event => Name,
Queue => Into.Queue,
Action => Into.Action,
Params => Into.Params);
end;
Into.Name := Util.Beans.Objects.Null_Object;
Into.Queue := AWA.Events.Queues.Null_Queue;
Into.Params.Clear;
when FIELD_QUEUE =>
-- Create the queue with the given name and properties and add it to the manager.
declare
Name : constant String := Util.Beans.Objects.To_String (Into.Name);
Kind : constant String := Util.Beans.Objects.To_String (Into.Queue_Type);
Queue : constant Queue_Ref := Queues.Create_Queue (Name => Name,
Kind => Kind,
Props => Into.Params,
Context => Into.Context.all);
begin
Into.Manager.Add_Queue (Queue);
end;
Into.Name := Util.Beans.Objects.Null_Object;
Into.Queue_Type := Util.Beans.Objects.Null_Object;
Into.Params.Clear;
when FIELD_DISPATCHER_PRIORITY =>
Into.Priority := To_Integer (EL.Utils.Eval (Value => Value,
Context => Into.Context.all));
when FIELD_DISPATCHER_COUNT =>
Into.Count := To_Integer (EL.Utils.Eval (Value => Value,
Context => Into.Context.all));
when FIELD_DISPATCHER_QUEUE =>
declare
Match : constant String := Util.Beans.Objects.To_String (Value);
begin
if Length (Into.Match) > 0 then
Append (Into.Match, ",");
end if;
Append (Into.Match, Match);
end;
when FIELD_DISPATCHER =>
if Into.Count > 0 then
Into.Manager.Add_Dispatcher (Match => To_String (Into.Match),
Count => Into.Count,
Priority => Into.Priority);
end if;
Into.Match := To_Unbounded_String ("");
end case;
end Set_Member;
package Config_Mapper is
new Util.Serialize.Mappers.Record_Mapper (Element_Type => Controller_Config,
Element_Type_Access => Controller_Config_Access,
Fields => Config_Fields,
Set_Member => Set_Member);
Event_Mapper : aliased Config_Mapper.Mapper;
procedure Add_Mapping (Mapper : in out Util.Serialize.Mappers.Processing;
Config : in Controller_Config_Access) is
begin
Mapper.Add_Mapping ("module", Event_Mapper'Access);
Config_Mapper.Set_Context (Mapper, Config);
end Add_Mapping;
begin
Event_Mapper.Add_Mapping ("queue", FIELD_QUEUE);
Event_Mapper.Add_Mapping ("queue/@name", FIELD_NAME);
Event_Mapper.Add_Mapping ("queue/@type", FIELD_TYPE);
Event_Mapper.Add_Mapping ("queue/property/@name", FIELD_PROPERTY_NAME);
Event_Mapper.Add_Mapping ("queue/property", FIELD_PROPERTY_VALUE);
Event_Mapper.Add_Mapping ("on-event", FIELD_ON_EVENT);
Event_Mapper.Add_Mapping ("on-event/@name", FIELD_NAME);
Event_Mapper.Add_Mapping ("on-event/@queue", FIELD_QUEUE_NAME);
Event_Mapper.Add_Mapping ("on-event/property/@name", FIELD_PROPERTY_NAME);
Event_Mapper.Add_Mapping ("on-event/property", FIELD_PROPERTY_VALUE);
Event_Mapper.Add_Mapping ("on-event/action", FIELD_ACTION);
Event_Mapper.Add_Mapping ("dispatcher", FIELD_DISPATCHER);
Event_Mapper.Add_Mapping ("dispatcher/@name", FIELD_NAME);
Event_Mapper.Add_Mapping ("dispatcher/queue/@match", FIELD_DISPATCHER_QUEUE);
Event_Mapper.Add_Mapping ("dispatcher/priority", FIELD_DISPATCHER_PRIORITY);
Event_Mapper.Add_Mapping ("dispatcher/count", FIELD_DISPATCHER_COUNT);
end AWA.Events.Configs;
|
-- { dg-do run { target { ! "*-*-solaris2*" } } }
with GNAT.Sockets; use GNAT.Sockets;
procedure socket1 is
X : Character;
begin
X := 'x';
GNAT.Sockets.Initialize;
declare
H : Host_Entry_Type := Get_Host_By_Address (Inet_Addr ("127.0.0.1"));
begin
null;
end;
end socket1;
|
-- Copyright 2020-2021 Jeff Foley. All rights reserved.
-- Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
local url = require("url")
name = "GoogleCT"
type = "cert"
function start()
set_rate_limit(2)
end
function vertical(ctx, domain)
local token = ""
local hdrs={
Connection="close",
Referer="https://transparencyreport.google.com/https/certificates",
}
while(true) do
local page, err = request(ctx, {
['url']=build_url(domain, token),
headers=hdrs,
})
if (err ~= nil and err ~= "") then
log(ctx, "vertical request to service failed: " .. err)
break
end
send_names(ctx, page)
token = get_token(page)
if token == "" then
break
end
end
end
function build_url(domain, token)
local base = "https://www.google.com/transparencyreport/api/v3/httpsreport/ct/certsearch"
if token ~= "" then
base = base .. "/page"
end
local params = {
['domain']=domain,
['include_expired']="true",
['include_subdomains']="true",
}
if token ~= "" then
params['p'] = token
end
return base .. "?" .. url.build_query_string(params)
end
function get_token(content)
local pattern = "\\[(null|\"[a-zA-Z0-9]+\"),\"([a-zA-Z0-9]+)\",null,([0-9]+),([0-9]+)\\]"
local matches = submatch(content, pattern)
if (matches == nil or #matches == 0) then
return ""
end
local match = matches[1]
if (match ~= nil and #match == 5 and (match[4] < match[5])) then
return match[3]
end
return ""
end
|
with AUnit; use AUnit;
with AUnit.Test_Cases; use AUnit.Test_Cases;
package LayerModelTests is
type TestCase is new AUnit.Test_Cases.Test_Case with null record;
procedure Register_Tests(T: in out TestCase);
function Name(T: TestCase) return Message_String;
procedure testDense(T : in out Test_Cases.Test_Case'Class);
procedure testDenseDeep(T : in out Test_Cases.Test_Case'Class);
end LayerModelTests;
|
generic
type Elem is (<>);
package Linked_List_Pkg is
type Linked_List is limited private;
type Vertex is private;
Empty_Linked_List : exception;
procedure Push( L : in out Linked_List; E : in Elem );
procedure Pop( L : in out Linked_List; E : out Elem );
-- can raise Empty_Linked_List exception;
function Is_Empty( L : Linked_List ) return Boolean;
function Size( L : Linked_List ) return Natural;
private
type Pointer is access Vertex;
type Vertex is record
data: Elem;
next: Pointer := null;
end record;
type Linked_List is record
size: Natural := 0;
front: Pointer := null;
back: Pointer := null;
end record;
end Linked_List_Pkg;
|
with ZMQ.Sockets;
with ZMQ.Contexts;
with ZMQ.Messages;
with Ada.Text_IO; use Ada.Text_IO;
procedure ZMQ.examples.Server is
ctx : ZMQ.Contexts.Context;
s : ZMQ.Sockets.Socket;
resultset_string : constant String := "OK";
begin
-- Initialise 0MQ context, requesting a single application thread
-- and a single I/O thread
ctx.Initialize (1);
-- Create a ZMQ_REP socket to receive requests and send replies
s.Initialize (ctx, ZMQ.Sockets.REP);
-- Bind to the TCP transport and port 5555 on the 'lo' interface
s.Bind ("tcp://lo:5555");
loop
declare
query : ZMQ.Messages.Message;
begin
query.Initialize;
-- Receive a message, blocks until one is available
s.recv (query);
-- Process the query
Put_Line (query.getData);
declare
-- Allocate a response message and fill in an example response
resultset : ZMQ.Messages.Message;
begin
resultset.Initialize (query.getData & "->" & resultset_string);
-- Send back our canned response
s.Send (resultset);
resultset.Finalize;
end;
query.Finalize;
end;
end loop;
end ZMQ.Examples.Server;
|
with ACO.Events;
package body ACO.Slave_Monitors is
function Is_Monitored
(This : Slave_Monitor;
Node_Id : ACO.Messages.Slave_Node_Nr)
return Boolean
is
use type ACO.Messages.Node_Nr;
begin
for Alarm of This.Slaves loop
if Alarm.Node_Id = Node_Id then
return True;
end if;
end loop;
return False;
end Is_Monitored;
function Get_State
(This : Slave_Monitor;
Node_Id : ACO.Messages.Slave_Node_Nr)
return ACO.States.State
is
use type ACO.Messages.Node_Nr;
begin
for Alarm of This.Slaves loop
if Alarm.Node_Id = Node_Id then
return Alarm.Slave_State.Current;
end if;
end loop;
return ACO.States.Unknown_State;
end Get_State;
overriding
procedure Signal
(This : access Slave_Alarm;
T_Now : in Ada.Real_Time.Time)
is
pragma Unreferenced (T_Now);
begin
This.Slave_State := (Previous => This.Slave_State.Current,
Current => ACO.States.Unknown_State);
if This.Ref /= null then
This.Ref.Od.Events.Node_Events.Put
((Event => ACO.Events.Slave_State_Transition,
Slave => (This.Slave_State, This.Node_Id)));
This.Ref.Od.Events.Node_Events.Put
((Event => ACO.Events.Heartbeat_Timed_Out,
Node_Id => This.Node_Id));
end if;
This.Node_Id := ACO.Messages.Not_A_Slave;
end Signal;
procedure Restart
(This : in out Slave_Monitor;
T_Now : in Ada.Real_Time.Time)
is
use type Ada.Real_Time.Time;
use type ACO.Messages.Node_Nr;
Period : Natural;
begin
for Alarm of This.Slaves loop
if Alarm.Node_Id /= ACO.Messages.Not_A_Slave then
This.Manager.Cancel (Alarm'Unchecked_Access);
Period := This.Od.Get_Heartbeat_Consumer_Period (Alarm.Node_Id);
if Period > 0 then
This.Manager.Set
(Alarm'Unchecked_Access,
T_Now + Ada.Real_Time.Milliseconds (Period));
else
Alarm.Node_Id := ACO.Messages.Not_A_Slave;
end if;
end if;
end loop;
end Restart;
procedure Start
(This : in out Slave_Monitor;
Node_Id : in ACO.Messages.Slave_Node_Nr;
Slave_State : in ACO.States.State;
T_Now : in Ada.Real_Time.Time)
is
use type Ada.Real_Time.Time;
use type ACO.Messages.Node_Nr;
Period : constant Natural := This.Od.Get_Heartbeat_Consumer_Period (Node_Id);
begin
if Period > 0 then
for Alarm of This.Slaves loop
if Alarm.Node_Id = ACO.Messages.Not_A_Slave then
Alarm.Node_Id := Node_Id;
Alarm.Slave_State := (Previous => ACO.States.Unknown_State,
Current => Slave_State);
This.Manager.Set
(Alarm'Unchecked_Access,
T_Now + Ada.Real_Time.Milliseconds (Period));
This.Od.Events.Node_Events.Put
((Event => ACO.Events.Slave_State_Transition,
Slave => (Alarm.Slave_State, Alarm.Node_Id)));
exit;
end if;
end loop;
end if;
end Start;
procedure Update_State
(This : in out Slave_Monitor;
Node_Id : in ACO.Messages.Slave_Node_Nr;
Slave_State : in ACO.States.State;
T_Now : in Ada.Real_Time.Time)
is
use type Ada.Real_Time.Time;
use type ACO.Messages.Node_Nr;
Period : constant Natural := This.Od.Get_Heartbeat_Consumer_Period (Node_Id);
begin
for Alarm of This.Slaves loop
if Alarm.Node_Id = Node_Id then
This.Manager.Cancel (Alarm'Unchecked_Access);
if Period > 0 then
Alarm.Slave_State := (Previous => Alarm.Slave_State.Current,
Current => Slave_State);
This.Manager.Set
(Alarm'Unchecked_Access,
T_Now + Ada.Real_Time.Milliseconds (Period));
This.Od.Events.Node_Events.Put
((Event => ACO.Events.Slave_State_Transition,
Slave => (Alarm.Slave_State, Alarm.Node_Id)));
else
Alarm.Node_Id := ACO.Messages.Not_A_Slave;
end if;
exit;
end if;
end loop;
end Update_State;
procedure Update_Alarms
(This : in out Slave_Monitor;
T_Now : in Ada.Real_Time.Time)
is
begin
This.Manager.Process (T_Now);
end Update_Alarms;
end ACO.Slave_Monitors;
|
PACKAGE BODY aux IS
PROCEDURE start IS
BEGIN
start;
END start;
END aux;
|
-- 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.TtkLabel.Ttk_Label_Options_Test_Data.Ttk_Label_Options_Tests is
type Test_Ttk_Label_Options is new GNATtest_Generated.GNATtest_Standard.Tk
.TtkLabel
.Ttk_Label_Options_Test_Data
.Test_Ttk_Label_Options with
null record;
procedure Test_Create_32e405_895b32
(Gnattest_T: in out Test_Ttk_Label_Options);
-- tk-ttklabel.ads:114:4:Create:Test_Create_TtkLabel1
procedure Test_Create_ebbdc1_3cc244
(Gnattest_T: in out Test_Ttk_Label_Options);
-- tk-ttklabel.ads:148:4:Create:Test_Create_TtkLabel2
procedure Test_Get_Options_ded36e_523496
(Gnattest_T: in out Test_Ttk_Label_Options);
-- tk-ttklabel.ads:173:4:Get_Options:Test_Get_Options_TtkLabel
procedure Test_Configure_0076be_ea215f
(Gnattest_T: in out Test_Ttk_Label_Options);
-- tk-ttklabel.ads:194:4:Configure:Test_Configure_TtkLabel
end Tk.TtkLabel.Ttk_Label_Options_Test_Data.Ttk_Label_Options_Tests;
-- end read only
|
-- [ dg-do compile }
with System;
package body Subp_Elim_Errors is
type Acc_Proc is access procedure;
procedure Proc is
begin
null;
end Proc;
procedure Pass_Proc (P : Acc_Proc) is
begin
P.all;
end Pass_Proc;
procedure Pass_Proc (P : System.Address) is
begin
null;
end Pass_Proc;
begin
Proc; -- { dg-error "eliminated" }
Pass_Proc (Proc'Access); -- { dg-error "eliminated" }
Pass_Proc (Proc'Address); -- { dg-error "eliminated" }
Pass_Proc (Proc'Code_Address); -- { dg-error "eliminated" }
end Subp_Elim_Errors;
|
pragma Ada_2012;
package body HMAC_Generic is
function Initialize (Key : String) return Context is
Result : Context;
begin
Initialize (Result, Key);
return Result;
end Initialize;
function Initialize (Key : Element_Array) return Context is
Result : Context;
begin
Initialize (Result, Key);
return Result;
end Initialize;
procedure Initialize (Ctx : out Context; Key : String) is
Buffer : Element_Array (Index (Key'First) .. Index (Key'Last));
for Buffer'Address use Key'Address;
pragma Import (Ada, Buffer);
begin
Initialize (Ctx, Buffer);
end Initialize;
procedure Initialize (Ctx : out Context; Key : Element_Array) is
Block_Sized_Key : Element_Array (0 .. Block_Length - 1) := (others => 0);
begin
Ctx.Outer := Hash_Initialize;
Ctx.Inner := Hash_Initialize;
if Key'Length > Block_Length then
-- Keys longer than block size are hashed to shorten them
declare
Hash_Ctx : Hash_Context := Hash_Initialize;
begin
Hash_Update (Hash_Ctx, Key);
Block_Sized_Key (0 .. Digest_Length - 1) :=
Hash_Finalize (Hash_Ctx);
end;
else
-- Otherwise we just copy, Block_Sized_Key is already containing 0s
Block_Sized_Key (0 .. Key'Length - 1) := Key;
end if;
-- Prepare outer padded key
declare
Outer_Padded_Key : Element_Array := Block_Sized_Key;
begin
for B of Outer_Padded_Key loop
B := B xor 16#5c#;
end loop;
Hash_Update (Ctx.Outer, Outer_Padded_Key);
end;
-- Prepare inner padded key
declare
Inner_Padded_Key : Element_Array := Block_Sized_Key;
begin
for B of Inner_Padded_Key loop
B := B xor 16#36#;
end loop;
Hash_Update (Ctx.Inner, Inner_Padded_Key);
end;
end Initialize;
procedure Update (Ctx : in out Context; Input : String) is
Buffer : Element_Array (Index (Input'First) .. Index (Input'Last));
for Buffer'Address use Input'Address;
pragma Import (Ada, Buffer);
begin
Update (Ctx, Buffer);
end Update;
procedure Update (Ctx : in out Context; Input : Element_Array) is
begin
Hash_Update (Ctx.Inner, Input);
end Update;
function Finalize (Ctx : Context) return Digest is
Result : Digest;
begin
Finalize (Ctx, Result);
return Result;
end Finalize;
procedure Finalize (Ctx : Context; Output : out Digest) is
Ctx_Copy : Context := Ctx;
begin
Hash_Update (Ctx_Copy.Outer, Hash_Finalize (Ctx_Copy.Inner));
Output := Hash_Finalize (Ctx_Copy.Outer);
end Finalize;
function HMAC (Key : String; Message : String) return Digest is
Ctx : Context := Initialize (Key);
begin
Update (Ctx, Message);
return Finalize (Ctx);
end HMAC;
function HMAC (Key : Element_Array; Message : Element_Array) return Digest
is
Ctx : Context := Initialize (Key);
begin
Update (Ctx, Message);
return Finalize (Ctx);
end HMAC;
end HMAC_Generic;
|
with Ada.Text_IO;
use Ada.Text_IO;
procedure BubbleSort is
type Index is new Integer;
type Elem is new Integer;
type Arr is array (Index range <>) of Elem;
function Max_Hely ( T: Arr ) return Index is
Mh: Index := T'First;
begin
for I in T'Range loop
if T(Mh) < T(I) then
Mh := I;
end if;
end loop;
return Mh;
end Max_Hely;
procedure Swap ( A, B: in out Elem ) is
Tmp: Elem := A;
begin
A := B;
B := Tmp;
end Swap;
procedure Rendez ( T: in out Arr ) is
Mh: Index;
begin
for I in reverse T'Range loop
Mh := Max_Hely( T(T'First..I) );
Swap( T(I), T(Mh) );
end loop;
end Rendez;
function Sort ( T: Arr ) return Arr is
Uj: Arr := T;
begin
Rendez(Uj);
return Uj;
end Sort;
A: Arr := (3,6,1,5,3);
begin
A := Sort(A);
for I in A'Range loop
Put_Line( Elem'Image( A(I) ) );
end loop;
end BubbleSort;
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . U N I T _ R E C --
-- --
-- S p e c --
-- --
-- Copyright (C) 1995-2011, Free Software Foundation, Inc. --
-- --
-- ASIS-for-GNAT is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. ASIS-for-GNAT is distributed in the hope that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with ASIS-for-GNAT; see file --
-- COPYING. If not, write to the Free Software Foundation, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, USA. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the --
-- Software Engineering Laboratory of the Swiss Federal Institute of --
-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the --
-- Scientific Research Computer Center of Moscow State University (SRCC --
-- MSU), Russia, with funding partially provided by grants from the Swiss --
-- National Science Foundation and the Swiss Academy of Engineering --
-- Sciences. ASIS-for-GNAT is now maintained by AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
-- This package defines the type Unit_Record used for storing the
-- information about ASIS Compilation Units. This type is used as an actual
-- parameter for instantiating the GNAT Table package and obtaining the type
-- for defining the individual Unit Table for each ASIS Context.
with Asis;
with Asis.Extensions; use Asis.Extensions;
with A4G.A_Types; use A4G.A_Types;
with Types; use Types;
package A4G.Unit_Rec is
-- See A4G.Contt (spec) and A4G.Contt.UT for the complete documentation of
-- the Compilation Units processing in ASIS.
-- !!! Documentation should be put in order later!!!
---------------------------------
-- Unit_Record type definition --
---------------------------------
type Unit_Record is record -- the field should be commented also here!!!
--------------------------------
-- Fields for Unit Name Table --
--------------------------------
Ada_Name_Chars_Index : Int;
Norm_Ada_Name_Chars_Index : Int;
File_Name_Chars_Index : Int;
Ref_Name_Chars_Index : Int;
-- Starting locations of characters in the Name_Chars table minus
-- one (i.e. pointer to character just before first character). The
-- reason for the bias of one is that indexes in Name_Buffer are
-- one's origin, so this avoids unnecessary adds and subtracts of 1.
Ada_Name_Len : Short;
Norm_Ada_Name_Len : Short;
File_Name_Len : Short;
Ref_Name_Len : Short;
-- Lengths of the names in characters
-- We keep separate starting locations and separate lengths
-- for each "column" of Unit Name Table, but all the actual
-- strings are stored in the same Name_Chars table
Hash_Link : Unit_Id;
-- Link to next entry in names table for same hash code
-----------------------------------------------
-- Fields for Black-Box Unit Name Attributes --
-----------------------------------------------
Top : Node_Id;
-- ??? Do we really need it?
-- This field is used only during the tree investigation,
-- and it is used only for the Units contained in this tree,
-- which have been known to ASIS before (the aim is to optimize
-- the tree investigation by eliminating the need to compute
-- the top node for the these Units). Tree swapping makes
-- the values of these fields obsolete, and we do not want
-- to keep them valid after investigating the tree. Instead,
-- if we need the top node corresponding to some Unit during
-- processing of some ASIS query, we compute it, and this
-- computation includes, if the Unit may be processed on the
-- base of the currently accessed tree, resetting this
-- tree, if necessary, and finding out the corresponding
-- N_Compuilation_Unit node in this tree.
Kind : Asis.Unit_Kinds;
Class : Asis.Unit_Classes;
Origin : Asis.Unit_Origins;
Main_Unit : Boolean;
Is_Body_Required : Boolean;
Time_Stamp : Time_Stamp_Type;
Is_Consistent : Boolean;
Source_File_Status : Source_File_Statuses;
Full_View_Trees : Elist_Id;
Limited_View_Trees : Elist_Id;
-- The lists of the trees in which the subtree for a given Unit is
-- contained, all these trees are consistent in the sense, that all of
-- them correspond to the same, latest version of unit's source. The
-- first list contains trees that contain full view of the unit, the
-- second contains trees that contain only limited views of the unit.
Main_Tree : Tree_Id;
-- The tree for which the given unit is a main unit. If there is no
-- tree for which the unit is the main unit, this field set to
-- Nil_Tree_Id
--------------------------------------
-- Fields for Semantic Dependencies --
--------------------------------------
Ancestors : Elist_Id;
Descendants : Elist_Id;
Direct_Supporters : Elist_Id;
Supporters : Elist_Id;
Implicit_Supporters : Elist_Id;
Direct_Dependents : Elist_Id;
Dependents : Elist_Id;
Subunits_Or_Childs : Elist_Id;
Compilation_Dependencies : Elist_Id;
Subunits_Computed : Boolean;
-- The meaning of these lists completely corresponds to the values
-- of the Asis.Unit_Kinds.Relation_Kinds type, represented by its
-- literals with the same names.
-- SHOULD BE REVISED! For example, for subunits it may make sense
-- to use Ancestors for parent bodies, and it would make sense
-- for bodies to use Descendants for subunits.
--
-- All these fields are either non-empty unit lists, or equal to
-- No_List, the latter case correspond to the situation, when
-- the corresponding dependency list is empty (???).
-- it would be nice to get rid of Direct_Supporters and of
-- Direct_Dependants as of ill-defined notions (they are not
-- defined in RM95, opposite to Supporters and Dependents
-- We may need Implicit_Supporters for
-- Asis.Compilation_Units.Elaboration_Order query
-- Subunits_Computed indicates if for a given parent body all its
-- subunits have already been computed (as a result of a Compilation
-- Unit semantic query). Computing subunits include allocating
-- nonexistent units for missed subunits.
-- Do we really need the list for Ancestors? We can easy compute
-- ancestors by stripping out selectors in normalized unit names.
-- OPEN PROBLEMS with ASIS 95 definition
-- =====================================
-- 1. RM95 says 10.1.1(9):
-- A library unit is a program unit that is declared by a
-- library_item. When a program unit is a library unit, the
-- prefix "library" is used to refer to it (or "generic
-- library" if generic), as well as to its declaration and
-- body, as in "library procedure", "library package_body",
-- or "generic library package". The term compilation unit
-- is used to refer to a compilation_unit. When the meaning
-- is clear from context, the term is also used to refer to
-- the library_item of a compilation_unit or to the proper_body
-- of a subunit (that is, the compilation_unit without the
-- context_clause and the separate (parent_unit_name)).
--
-- And AARM adds in 10.1.1(9.d):
-- We like to use the word "unit" for declaration-plus-body
-- things, and "item" for declaration or body separately
-- (as in declarative_item). The terms "compilation_unit",
-- "compilation unit" and "subunit" are exceptions to this rule.
--
-- RM95 says 10.1.1(10):
-- The parent declaration of a library_item (and of the library
-- unit) is the declaration denoted by the parent_unit_name, if
-- any, of the defining_program_unit_name of the library_item.
-- If there is no parent_unit_name, the parent declaration is
-- the declaration of Standard, the library_item is a root
-- library_item, and the library unit (renaming) is a root
-- library unit (renaming). The declaration and body of
-- Standard itself have no parent declaration. The parent unit
-- of a library_item or library unit is the library unit
-- declared by its parent declaration.
--
-- And AARM adds in 10.1.1(10.d):
-- Library units ... have "parent declarations" [which are
-- *compilation* units] and "parent units" [spec + body].
-- We didn't bother to define the other possibilities: parent
-- body of a library unit, parent declaration of a subunit,
-- parent unit of a subunit. These are not needed...
--
-- RM95 says 10.1.1(11):
-- The children of a library unit occur immediately within the
-- declarative region of the declaration of the library unit.
-- The ancestors of a library unit are itself, its parent, its
-- parent's parent, and so on. (Standard is an ancestor of
-- every library unit.) The descendant relation is the inverse
-- of the ancestor relation.
--
-- AARM adds (10.1.1(11.b):
-- We use the unadorned term "ancestors" here to concisely
-- define both "ancestor unit" and "ancestor declaration"
--
-- THE QUESTION IS: what do the *ASIS* notions of ancestors
-- and descendants mean - do they mean "ancestor (descendant)
-- unit" or "ancestor (descendant) declaration"?
--
-- THE "WORKING" SOLUTION: now *in ASIS* "ancestor" means
-- "ancestor declaration", and "descendant" means "descendant
-- unit". (Is it really a good decision, if the Descendants
-- relation is defined by ASIS as the inverse of the ancestor
-- relation? From the other side, this looks quite natural from
-- the application viewpoint: if we are asking about ancestors,
-- we are very likely interested in declarations, but not
-- bodies,, and when we are asking about descendants, we are
-- very likely interested in *all* (compilation units which are)
-- the descendants.
--
-- (Moreover, the query
-- Asis.Compilation_Units.Corresponding_Children has only
-- *declarations* as appropriate argument unit kinds, and it
-- returns declarations *and bodies (if any)*
end record;
end A4G.Unit_Rec;
|
<table>
@@TABLE@@
<tr>
<td>@_WEB_ESCAPE:CHAR_@</td>
<td>@_WEB_ESCAPE:SPEECH_@</td>
</tr>
@@END_TABLE@@
</table>
|
------------------------------------------------------------------------------
-- --
-- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . T A S K I N G . P R O T E C T E D _ O B J E C T S . --
-- E N T R I E S --
-- --
-- S p e c --
-- --
-- $Revision$
-- --
-- Copyright (C) 1992-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. --
-- --
------------------------------------------------------------------------------
-- This package contains all the simple primitives related to
-- Protected_Objects with entries (i.e init, lock, unlock).
-- The handling of protected objects with no entries is done in
-- System.Tasking.Protected_Objects, the complex routines for protected
-- objects with entries in System.Tasking.Protected_Objects.Operations.
-- The split between Entries and Operations is needed to break circular
-- dependencies inside the run time.
-- Note: the compiler generates direct calls to this interface, via Rtsfind.
-- Any changes to this interface may require corresponding compiler changes.
with Ada.Finalization;
-- used for Limited_Controlled
with Unchecked_Conversion;
package System.Tasking.Protected_Objects.Entries is
pragma Elaborate_Body;
subtype Positive_Protected_Entry_Index is
Protected_Entry_Index range 1 .. Protected_Entry_Index'Last;
type Find_Body_Index_Access is access
function
(O : System.Address;
E : Protected_Entry_Index)
return Protected_Entry_Index;
type Protected_Entry_Body_Array is
array (Positive_Protected_Entry_Index range <>) of Entry_Body;
-- This is an array of the executable code for all entry bodies of
-- a protected type.
type Protected_Entry_Body_Access is access all Protected_Entry_Body_Array;
type Protected_Entry_Queue_Array is
array (Protected_Entry_Index range <>) of Entry_Queue;
-- This type contains the GNARL state of a protected object. The
-- application-defined portion of the state (i.e. private objects)
-- is maintained by the compiler-generated code.
-- note that there is a simplified version of this type declared in
-- System.Tasking.PO_Simple that handle the simple case (no entries).
type Protection_Entries (Num_Entries : Protected_Entry_Index) is new
Ada.Finalization.Limited_Controlled
with record
L : aliased Task_Primitives.Lock;
-- The underlying lock associated with a Protection_Entries.
-- Note that you should never (un)lock Object.L directly, but instead
-- use Lock_Entries/Unlock_Entries.
Compiler_Info : System.Address;
Call_In_Progress : Entry_Call_Link;
Ceiling : System.Any_Priority;
Old_Base_Priority : System.Any_Priority;
Pending_Action : Boolean;
-- Flag indicating that priority has been dipped temporarily
-- in order to avoid violating the priority ceiling of the lock
-- associated with this protected object, in Lock_Server.
-- The flag tells Unlock_Server or Unlock_And_Update_Server to
-- restore the old priority to Old_Base_Priority. This is needed
-- because of situations (bad language design?) where one
-- needs to lock a PO but to do so would violate the priority
-- ceiling. For example, this can happen when an entry call
-- has been requeued to a lower-priority object, and the caller
-- then tries to cancel the call while its own priority is higher
-- than the ceiling of the new PO.
Finalized : Boolean := False;
-- Set to True by Finalize to make this routine idempotent.
Entry_Bodies : Protected_Entry_Body_Access;
-- The following function maps the entry index in a call (which denotes
-- the queue to the proper entry) into the body of the entry.
Find_Body_Index : Find_Body_Index_Access;
Entry_Queues : Protected_Entry_Queue_Array (1 .. Num_Entries);
end record;
pragma Volatile (Protection_Entries);
-- No default initial values for this type, since call records
-- will need to be re-initialized before every use.
type Protection_Entries_Access is access all Protection_Entries'Class;
-- See comments in s-tassta.adb about the implicit call to Current_Master
-- generated by this declaration.
function To_Protection_Entries is new Unchecked_Conversion
(Protection_Access, Protection_Entries_Access);
function To_Address is
new Unchecked_Conversion (Protection_Entries_Access, System.Address);
function To_Protection is
new Unchecked_Conversion (System.Address, Protection_Entries_Access);
function Has_Interrupt_Or_Attach_Handler
(Object : Protection_Entries_Access) return Boolean;
-- Returns True if an Interrupt_Handler or Attach_Handler pragma applies
-- to the protected object. That is to say this primitive returns False for
-- Protection, but is overriden to return True when interrupt handlers are
-- declared so the check required by C.3.1(11) can be implemented in
-- System.Tasking.Protected_Objects.Initialize_Protection.
procedure Initialize_Protection_Entries
(Object : Protection_Entries_Access;
Ceiling_Priority : Integer;
Compiler_Info : System.Address;
Entry_Bodies : Protected_Entry_Body_Access;
Find_Body_Index : Find_Body_Index_Access);
-- Initialize the Object parameter so that it can be used by the runtime
-- to keep track of the runtime state of a protected object.
procedure Lock_Entries (Object : Protection_Entries_Access);
-- Lock a protected object for write access. Upon return, the caller
-- owns the lock to this object, and no other call to Lock or
-- Lock_Read_Only with the same argument will return until the
-- corresponding call to Unlock has been made by the caller.
-- Program_Error is raised in case of ceiling violation.
procedure Lock_Entries
(Object : Protection_Entries_Access; Ceiling_Violation : out Boolean);
-- Same as above, but return the ceiling violation status instead of
-- raising Program_Error.
procedure Lock_Read_Only_Entries (Object : Protection_Entries_Access);
-- Lock a protected object for read access. Upon return, the caller
-- owns the lock for read access, and no other calls to Lock with the
-- same argument will return until the corresponding call to Unlock
-- has been made by the caller. Other calls to Lock_Read_Only may (but
-- need not) return before the call to Unlock, and the corresponding
-- callers will also own the lock for read access.
--
-- Note: we are not currently using this interface, it is provided
-- for possible future use. At the current time, everyone uses Lock
-- for both read and write locks.
procedure Unlock_Entries (Object : Protection_Entries_Access);
-- Relinquish ownership of the lock for the object represented by
-- the Object parameter. If this ownership was for write access, or
-- if it was for read access where there are no other read access
-- locks outstanding, one (or more, in the case of Lock_Read_Only)
-- of the tasks waiting on this lock (if any) will be given the
-- lock and allowed to return from the Lock or Lock_Read_Only call.
private
procedure Finalize (Object : in out Protection_Entries);
-- Clean up a Protection object; in particular, finalize the associated
-- Lock object.
end System.Tasking.Protected_Objects.Entries;
|
-- If you comment out the Nested_Package.Comment_Out_This_Line_And_All_Ok;
-- lines in Buggy_Package, all is well, or if you only comment out one of
-- these lines and don't instantiate the other generic in Buggy_Package_Demo,
-- then all is well.
package Nested_Package is
procedure Comment_Out_This_Line_And_All_Ok;
end Nested_Package;
package body Nested_Package is
procedure Comment_Out_This_Line_And_All_Ok is
begin
NULL;
end;
end Nested_Package;
package Buggy_Package is
generic
type INT is range <>;
function Func_INT return INT;
generic
type INT is range <>;
procedure Proc_INT;
end Buggy_Package;
with Nested_Package;
package body Buggy_Package is
function Func_INT return INT is
begin
Nested_Package.Comment_Out_This_Line_And_All_Ok;
return INT'FIRST;
end Func_INT;
procedure Proc_INT is
begin
Nested_Package.Comment_Out_This_Line_And_All_Ok;
null;
end Proc_INT;
end Buggy_Package;
|
with System.Storage_Elements; use System.Storage_Elements;
with AUnit.Assertions; use AUnit.Assertions;
with AAA.Strings;
with Test_Utils; use Test_Utils;
package body Testsuite.Decode.Basic_Tests is
pragma Style_Checks ("gnatyM120-s");
----------------
-- Basic_Test --
----------------
procedure Basic_Test (Fixture : in out Decoder_Fixture;
Input, Expected : Storage_Array)
is
Expected_Frame : constant Data_Frame := From_Array (Expected);
begin
Fixture.Decoder.Clear;
for Elt of Input loop
Fixture.Decoder.Receive (Elt);
end loop;
Fixture.Decoder.End_Of_Test;
Assert (Fixture.Decoder.Number_Of_Frames = 1,
"Unexpected number of output frames: " &
Fixture.Decoder.Number_Of_Frames'Img & ASCII.LF &
"Input : " & Image (Input));
declare
Output_Frame : constant Data_Frame := Fixture.Decoder.Get_Frame (0);
begin
if Output_Frame /= Expected_Frame then
declare
Diff : constant AAA.Strings.Vector :=
Test_Utils.Diff (From_Array (Expected),
Fixture.Decoder.Get_Frame (0));
begin
Assert (False,
"Input : " & Image (Input) & ASCII.LF &
Diff.Flatten (ASCII.LF));
end;
end if;
end;
end Basic_Test;
---------------
-- Test_Zero --
---------------
procedure Test_Zero (Fixture : in out Decoder_Fixture) is
begin
-- Basic tests from the wikipedia COBS page...
Basic_Test (Fixture,
Input => (1, 1, 0),
Expected => (0 => 0));
Basic_Test (Fixture,
Input => (1, 1, 1, 0),
Expected => (0, 0));
Basic_Test (Fixture,
Input => (3, 1, 2, 2, 3, 0),
Expected => (1, 2, 0, 3));
end Test_Zero;
----------------
-- Test_1_254 --
----------------
procedure Test_1_254 (Fixture : in out Decoder_Fixture) is
Long_Input : Storage_Array (0 .. 255);
begin
for X in Long_Input'Range loop
Long_Input (X) := Storage_Element (X);
end loop;
Basic_Test (Fixture,
Input => (0 => 16#FF#) & Long_Input (1 .. 254) & (0 => 16#00#),
Expected => Long_Input (1 .. 254));
end Test_1_254;
----------------
-- Test_0_254 --
----------------
procedure Test_0_254 (Fixture : in out Decoder_Fixture) is
Long_Input : Storage_Array (0 .. 255);
begin
for X in Long_Input'Range loop
Long_Input (X) := Storage_Element (X);
end loop;
Basic_Test (Fixture,
Input => (16#01#, 16#FF#) & Long_Input (1 .. 254) & (0 => 16#00#),
Expected => Long_Input (0 .. 254));
end Test_0_254;
----------------
-- Test_1_255 --
----------------
procedure Test_1_255 (Fixture : in out Decoder_Fixture) is
Long_Input : Storage_Array (0 .. 255);
begin
for X in Long_Input'Range loop
Long_Input (X) := Storage_Element (X);
end loop;
Basic_Test (Fixture,
Input => (0 => 16#FF#) & Long_Input (1 .. 254) &
(16#02#, 16#FF#, 16#00#),
Expected => Long_Input (1 .. 255));
end Test_1_255;
------------------
-- Test_2_255_0 --
------------------
procedure Test_2_255_0 (Fixture : in out Decoder_Fixture) is
Long_Input : Storage_Array (0 .. 255);
begin
for X in Long_Input'Range loop
Long_Input (X) := Storage_Element (X);
end loop;
Basic_Test (Fixture,
Input => (0 => 16#FF#) & Long_Input (2 .. 255) &
(16#01#, 16#01#, 16#00#),
Expected => Long_Input (2 .. 255) & (0 => 16#0#));
end Test_2_255_0;
--------------------
-- Test_3_255_0_1 --
--------------------
procedure Test_3_255_0_1 (Fixture : in out Decoder_Fixture) is
Long_Input : Storage_Array (0 .. 255);
begin
for X in Long_Input'Range loop
Long_Input (X) := Storage_Element (X);
end loop;
Basic_Test (Fixture,
Input => (0 => 16#FE#) & Long_Input (3 .. 255) &
(16#02#, 16#01#, 16#00#),
Expected => Long_Input (3 .. 255) & (16#0#, 16#01#));
end Test_3_255_0_1;
---------------
-- Add_Tests --
---------------
procedure Add_Tests (Suite : in out AUnit.Test_Suites.Test_Suite'Class) is
begin
Suite.Add_Test (Decoder_Caller.Create ("Basics", Test_Zero'Access));
Suite.Add_Test (Decoder_Caller.Create ("1 .. 254", Test_1_254'Access));
Suite.Add_Test (Decoder_Caller.Create ("0 .. 254", Test_0_254'Access));
Suite.Add_Test (Decoder_Caller.Create ("1 .. 255", Test_1_255'Access));
Suite.Add_Test (Decoder_Caller.Create ("2 .. 255 & 0", Test_2_255_0'Access));
Suite.Add_Test (Decoder_Caller.Create ("3 .. 255 & 0 & 1", Test_3_255_0_1'Access));
end Add_Tests;
end Testsuite.Decode.Basic_Tests;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.