repo_name
stringlengths 9
74
| language
stringclasses 1
value | length_bytes
int64 11
9.34M
| extension
stringclasses 2
values | content
stringlengths 11
9.34M
|
---|---|---|---|---|
leo-brewin/ada-lapack | Ada | 4,482 | adb | with Ada.Text_IO;
with Ada.Text_IO.Complex_IO;
with Ada.Numerics.Generic_Real_Arrays;
with Ada.Numerics.Generic_Complex_Types;
with Ada.Numerics.Generic_Complex_Arrays;
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Numerics.Generic_Complex_Elementary_Functions;
with Ada_Lapack;
use Ada.Text_IO;
procedure tdgesdd is
type Real is digits 18;
package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real);
package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Real);
package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays (Real_Arrays, Complex_Types);
package Real_Maths is new Ada.Numerics.Generic_Elementary_Functions (Real);
package Complex_Maths is new Ada.Numerics.Generic_Complex_Elementary_Functions (Complex_Types);
package Real_IO is new Ada.Text_IO.Float_IO (Real);
package Integer_IO is new Ada.Text_IO.Integer_IO (Integer);
package Complex_IO is new Ada.Text_IO.Complex_IO (Complex_Types);
package Lapack is new Ada_Lapack(Real, Complex_Types, Real_Arrays, Complex_Arrays);
use Lapack;
use Real_Arrays;
use Complex_Types;
use Complex_Arrays;
use Real_IO;
use Integer_IO;
use Complex_IO;
use Real_Maths;
use Complex_Maths;
function min(left,right : Integer) return Integer is
begin
if left < right
then return left;
else return right;
end if;
end min;
matrix : Real_Matrix (1..6,1..4);
matrix_rows : Integer := Matrix'Length (1);
matrix_cols : Integer := Matrix'Length (2);
num_singular : Integer;
singular_values : Real_Vector (1..min(matrix_rows,matrix_cols));
u_rows : Integer := matrix_rows;
u_cols : Integer := matrix_rows;
u_matrix : Real_Matrix (1..u_rows,1..u_cols);
-- note: must declare v_transpose as square even though bottom rows may not be used (when rows>cols)
v_rows : Integer := matrix_cols;
v_cols : Integer := matrix_cols;
v_transpose : Real_Matrix (1..v_rows,1..v_cols);
short_vector : Real_Vector (1..1);
iwork : Integer_Vector (1..8*min(matrix_rows,matrix_cols));
return_code : Integer;
begin
matrix :=( ( 7.52, -1.10, -7.95, 1.08),
( -0.76, 0.62, 9.34, -7.10),
( 5.13, 6.62, -5.66, 0.87),
( -4.75, 8.52, 5.75, 5.30),
( 1.33, 4.91, -5.49, -3.52),
( -2.40, -6.77, 2.34, 3.95) );
GESDD ( JOBZ => 'A',
M => matrix_rows,
N => matrix_cols,
A => matrix,
LDA => matrix_rows,
S => singular_values,
U => u_matrix,
LDU => u_rows,
VT => v_transpose,
LDVT => v_rows,
WORK => short_vector,
LWORK => -1,
IWORK => iwork,
INFO => return_code );
declare
work_vector_rows : Integer := Integer( short_vector(1) );
work_vector : Real_Vector (1 .. work_vector_rows);
begin
GESDD ( JOBZ => 'A',
M => matrix_rows,
N => matrix_cols,
A => matrix,
LDA => matrix_rows,
S => singular_values,
U => u_matrix,
LDU => u_rows,
VT => v_transpose,
LDVT => v_rows,
WORK => work_vector,
LWORK => work_vector_rows,
IWORK => iwork,
INFO => return_code );
end;
if return_code > 0 then
Put ("DGESDD failed, the return code was : ");
Put ( return_code );
New_line;
else
num_singular := min(matrix_rows,matrix_cols);
put_line("Singular values");
for i in 1..num_singular loop
put(singular_values(i),3,4,0);
end loop;
new_line;
new_line;
put_line("Matrix U");
for i in 1..matrix_rows loop
for j in 1..num_singular loop
put(u_matrix(i,j),3,4,0);
end loop;
new_line;
end loop;
new_line;
put_line("Matrix V transpose");
for i in 1..num_singular loop
for j in 1..matrix_cols loop
put(v_transpose(i,j),3,4,0);
end loop;
new_line;
end loop;
end if;
end tdgesdd;
|
wookey-project/ewok-legacy | Ada | 42 | ads | ../../stm32f439/Ada/soc-layout-stm32f4.ads |
stcarrez/ada-ado | Ada | 6,854 | adb | -----------------------------------------------------------------------
-- ado-sequences -- Database sequence generator
-- Copyright (C) 2009, 2010, 2011, 2012, 2022 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Log;
with Util.Log.Loggers;
with Util.Strings;
with ADO.Sessions.Factory;
with Ada.Unchecked_Deallocation;
package body ADO.Sequences is
use Util.Log;
use Sequence_Maps;
Log : constant Loggers.Logger := Loggers.Create ("ADO.Sequences");
procedure Free is new
Ada.Unchecked_Deallocation (Object => Sequence_Generator,
Name => Sequence_Generator_Access);
procedure Free is new
Ada.Unchecked_Deallocation (Object => Generator'Class,
Name => Generator_Access);
-- ------------------------------
-- Get a session to connect to the database.
-- ------------------------------
function Get_Session (Gen : in Generator) return ADO.Sessions.Master_Session'Class is
begin
return Gen.Factory.Get_Master_Session;
end Get_Session;
protected body Sequence_Generator is
-- ------------------------------
-- Allocate a unique identifier for the given sequence.
-- ------------------------------
procedure Allocate (Session : in out Sessions.Master_Session'Class;
Id : in out Objects.Object_Record'Class) is
begin
Generator.Allocate (Session, Id);
end Allocate;
procedure Set_Generator (Gen : in Generator_Access) is
begin
Free (Generator);
Generator := Gen;
end Set_Generator;
end Sequence_Generator;
-- ------------------------------
-- Allocate a unique identifier for the given table.
-- ------------------------------
procedure Allocate (Manager : in out Factory;
Session : in out ADO.Sessions.Master_Session'Class;
Id : in out ADO.Objects.Object_Record'Class) is
Gen : Sequence_Generator_Access;
Name : constant Util.Strings.Name_Access := Id.Get_Table_Name;
begin
Manager.Map.Get_Generator (Name.all, Gen);
Gen.Allocate (Session, Id);
end Allocate;
-- ------------------------------
-- Set a generator to be used for the given sequence.
-- ------------------------------
procedure Set_Generator (Manager : in out Factory;
Gen : in Generator_Access) is
begin
Manager.Map.Set_Generator (Gen);
end Set_Generator;
-- ------------------------------
-- Set the default factory for creating generators.
-- The default factory is the HiLo generator.
-- ------------------------------
procedure Set_Default_Generator
(Manager : in out Factory;
Factory : in Generator_Factory;
Sess_Factory : in Session_Factory_Access;
Use_New_Session : in Boolean) is
begin
Manager.Map.Set_Default_Generator (Factory, Sess_Factory, Use_New_Session);
end Set_Default_Generator;
-- The sequence factory map is also accessed through a protected type.
protected body Factory_Map is
-- ------------------------------
-- Get the sequence generator associated with the name.
-- If there is no such generator, an entry is created by using
-- the default generator.
-- ------------------------------
procedure Get_Generator (Name : in String;
Seq : out Sequence_Generator_Access) is
Pos : constant Cursor := Find (Map, Name);
begin
if not Has_Element (Pos) then
Log.Info ("Creating sequence generator for {0}", Name);
declare
Generator : constant Generator_Access
:= Create_Generator.all (Sess_Factory, Name);
begin
Generator.Use_New_Session := Use_New_Session;
Seq := new Sequence_Generator;
Seq.Set_Generator (Generator);
end;
Insert (Map, Name, Seq);
else
Seq := Element (Pos);
end if;
end Get_Generator;
-- ------------------------------
-- Set the sequence generator associated with the name.
-- ------------------------------
procedure Set_Generator (Gen : in Generator_Access) is
Pos : constant Cursor := Find (Map, Gen.Name);
begin
Log.Info ("Setting sequence generator for {0}", Gen.Name);
if not Has_Element (Pos) then
declare
Seq : constant Sequence_Generator_Access := new Sequence_Generator;
begin
Seq.Set_Generator (Gen);
Insert (Map, Gen.Name, Seq);
end;
else
declare
Seq : constant Sequence_Generator_Access := Element (Pos);
begin
Seq.Set_Generator (Gen);
end;
end if;
end Set_Generator;
-- ------------------------------
-- Set the default sequence generator.
-- ------------------------------
procedure Set_Default_Generator
(Gen : in Generator_Factory;
Factory : in Session_Factory_Access;
Gen_Use_New_Session : in Boolean) is
begin
Create_Generator := Gen;
Sess_Factory := Factory;
Use_New_Session := Gen_Use_New_Session;
end Set_Default_Generator;
-- ------------------------------
-- Clear the factory map.
-- ------------------------------
procedure Clear is
begin
Log.Info ("Clearing the sequence factory");
loop
declare
Pos : Cursor := Map.First;
Seq : Sequence_Generator_Access;
begin
exit when not Has_Element (Pos);
Seq := Element (Pos);
Map.Delete (Pos);
Seq.all.Set_Generator (null);
Free (Seq);
end;
end loop;
end Clear;
end Factory_Map;
overriding
procedure Finalize (Manager : in out Factory) is
begin
Manager.Map.Clear;
end Finalize;
end ADO.Sequences;
|
ekoeppen/STM32_Generic_Ada_Drivers | Ada | 11,555 | ads | pragma Style_Checks (Off);
-- This spec has been automatically generated from STM32L0x3.svd
pragma Restrictions (No_Elaboration_Code);
with System;
package STM32_SVD.LPTIM is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype ISR_CMPM_Field is STM32_SVD.Bit;
subtype ISR_ARRM_Field is STM32_SVD.Bit;
subtype ISR_EXTTRIG_Field is STM32_SVD.Bit;
subtype ISR_CMPOK_Field is STM32_SVD.Bit;
subtype ISR_ARROK_Field is STM32_SVD.Bit;
subtype ISR_UP_Field is STM32_SVD.Bit;
subtype ISR_DOWN_Field is STM32_SVD.Bit;
-- Interrupt and Status Register
type ISR_Register is record
-- Read-only. Compare match
CMPM : ISR_CMPM_Field;
-- Read-only. Autoreload match
ARRM : ISR_ARRM_Field;
-- Read-only. External trigger edge event
EXTTRIG : ISR_EXTTRIG_Field;
-- Read-only. Compare register update OK
CMPOK : ISR_CMPOK_Field;
-- Read-only. Autoreload register update OK
ARROK : ISR_ARROK_Field;
-- Read-only. Counter direction change down to up
UP : ISR_UP_Field;
-- Read-only. Counter direction change up to down
DOWN : ISR_DOWN_Field;
-- unspecified
Reserved_7_31 : STM32_SVD.UInt25;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ISR_Register use record
CMPM at 0 range 0 .. 0;
ARRM at 0 range 1 .. 1;
EXTTRIG at 0 range 2 .. 2;
CMPOK at 0 range 3 .. 3;
ARROK at 0 range 4 .. 4;
UP at 0 range 5 .. 5;
DOWN at 0 range 6 .. 6;
Reserved_7_31 at 0 range 7 .. 31;
end record;
subtype ICR_CMPMCF_Field is STM32_SVD.Bit;
subtype ICR_ARRMCF_Field is STM32_SVD.Bit;
subtype ICR_EXTTRIGCF_Field is STM32_SVD.Bit;
subtype ICR_CMPOKCF_Field is STM32_SVD.Bit;
subtype ICR_ARROKCF_Field is STM32_SVD.Bit;
subtype ICR_UPCF_Field is STM32_SVD.Bit;
subtype ICR_DOWNCF_Field is STM32_SVD.Bit;
-- Interrupt Clear Register
type ICR_Register is record
-- Write-only. compare match Clear Flag
CMPMCF : ICR_CMPMCF_Field := 16#0#;
-- Write-only. Autoreload match Clear Flag
ARRMCF : ICR_ARRMCF_Field := 16#0#;
-- Write-only. External trigger valid edge Clear Flag
EXTTRIGCF : ICR_EXTTRIGCF_Field := 16#0#;
-- Write-only. Compare register update OK Clear Flag
CMPOKCF : ICR_CMPOKCF_Field := 16#0#;
-- Write-only. Autoreload register update OK Clear Flag
ARROKCF : ICR_ARROKCF_Field := 16#0#;
-- Write-only. Direction change to UP Clear Flag
UPCF : ICR_UPCF_Field := 16#0#;
-- Write-only. Direction change to down Clear Flag
DOWNCF : ICR_DOWNCF_Field := 16#0#;
-- unspecified
Reserved_7_31 : STM32_SVD.UInt25 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ICR_Register use record
CMPMCF at 0 range 0 .. 0;
ARRMCF at 0 range 1 .. 1;
EXTTRIGCF at 0 range 2 .. 2;
CMPOKCF at 0 range 3 .. 3;
ARROKCF at 0 range 4 .. 4;
UPCF at 0 range 5 .. 5;
DOWNCF at 0 range 6 .. 6;
Reserved_7_31 at 0 range 7 .. 31;
end record;
subtype IER_CMPMIE_Field is STM32_SVD.Bit;
subtype IER_ARRMIE_Field is STM32_SVD.Bit;
subtype IER_EXTTRIGIE_Field is STM32_SVD.Bit;
subtype IER_CMPOKIE_Field is STM32_SVD.Bit;
subtype IER_ARROKIE_Field is STM32_SVD.Bit;
subtype IER_UPIE_Field is STM32_SVD.Bit;
subtype IER_DOWNIE_Field is STM32_SVD.Bit;
-- Interrupt Enable Register
type IER_Register is record
-- Compare match Interrupt Enable
CMPMIE : IER_CMPMIE_Field := 16#0#;
-- Autoreload match Interrupt Enable
ARRMIE : IER_ARRMIE_Field := 16#0#;
-- External trigger valid edge Interrupt Enable
EXTTRIGIE : IER_EXTTRIGIE_Field := 16#0#;
-- Compare register update OK Interrupt Enable
CMPOKIE : IER_CMPOKIE_Field := 16#0#;
-- Autoreload register update OK Interrupt Enable
ARROKIE : IER_ARROKIE_Field := 16#0#;
-- Direction change to UP Interrupt Enable
UPIE : IER_UPIE_Field := 16#0#;
-- Direction change to down Interrupt Enable
DOWNIE : IER_DOWNIE_Field := 16#0#;
-- unspecified
Reserved_7_31 : STM32_SVD.UInt25 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for IER_Register use record
CMPMIE at 0 range 0 .. 0;
ARRMIE at 0 range 1 .. 1;
EXTTRIGIE at 0 range 2 .. 2;
CMPOKIE at 0 range 3 .. 3;
ARROKIE at 0 range 4 .. 4;
UPIE at 0 range 5 .. 5;
DOWNIE at 0 range 6 .. 6;
Reserved_7_31 at 0 range 7 .. 31;
end record;
subtype CFGR_CKSEL_Field is STM32_SVD.Bit;
subtype CFGR_CKPOL_Field is STM32_SVD.UInt2;
subtype CFGR_CKFLT_Field is STM32_SVD.UInt2;
subtype CFGR_TRGFLT_Field is STM32_SVD.UInt2;
subtype CFGR_PRESC_Field is STM32_SVD.UInt3;
subtype CFGR_TRIGSEL_Field is STM32_SVD.UInt3;
subtype CFGR_TRIGEN_Field is STM32_SVD.UInt2;
subtype CFGR_TIMOUT_Field is STM32_SVD.Bit;
subtype CFGR_WAVE_Field is STM32_SVD.Bit;
subtype CFGR_WAVPOL_Field is STM32_SVD.Bit;
subtype CFGR_PRELOAD_Field is STM32_SVD.Bit;
subtype CFGR_COUNTMODE_Field is STM32_SVD.Bit;
subtype CFGR_ENC_Field is STM32_SVD.Bit;
-- Configuration Register
type CFGR_Register is record
-- Clock selector
CKSEL : CFGR_CKSEL_Field := 16#0#;
-- Clock Polarity
CKPOL : CFGR_CKPOL_Field := 16#0#;
-- Configurable digital filter for external clock
CKFLT : CFGR_CKFLT_Field := 16#0#;
-- unspecified
Reserved_5_5 : STM32_SVD.Bit := 16#0#;
-- Configurable digital filter for trigger
TRGFLT : CFGR_TRGFLT_Field := 16#0#;
-- unspecified
Reserved_8_8 : STM32_SVD.Bit := 16#0#;
-- Clock prescaler
PRESC : CFGR_PRESC_Field := 16#0#;
-- unspecified
Reserved_12_12 : STM32_SVD.Bit := 16#0#;
-- Trigger selector
TRIGSEL : CFGR_TRIGSEL_Field := 16#0#;
-- unspecified
Reserved_16_16 : STM32_SVD.Bit := 16#0#;
-- Trigger enable and polarity
TRIGEN : CFGR_TRIGEN_Field := 16#0#;
-- Timeout enable
TIMOUT : CFGR_TIMOUT_Field := 16#0#;
-- Waveform shape
WAVE : CFGR_WAVE_Field := 16#0#;
-- Waveform shape polarity
WAVPOL : CFGR_WAVPOL_Field := 16#0#;
-- Registers update mode
PRELOAD : CFGR_PRELOAD_Field := 16#0#;
-- counter mode enabled
COUNTMODE : CFGR_COUNTMODE_Field := 16#0#;
-- Encoder mode enable
ENC : CFGR_ENC_Field := 16#0#;
-- unspecified
Reserved_25_31 : STM32_SVD.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CFGR_Register use record
CKSEL at 0 range 0 .. 0;
CKPOL at 0 range 1 .. 2;
CKFLT at 0 range 3 .. 4;
Reserved_5_5 at 0 range 5 .. 5;
TRGFLT at 0 range 6 .. 7;
Reserved_8_8 at 0 range 8 .. 8;
PRESC at 0 range 9 .. 11;
Reserved_12_12 at 0 range 12 .. 12;
TRIGSEL at 0 range 13 .. 15;
Reserved_16_16 at 0 range 16 .. 16;
TRIGEN at 0 range 17 .. 18;
TIMOUT at 0 range 19 .. 19;
WAVE at 0 range 20 .. 20;
WAVPOL at 0 range 21 .. 21;
PRELOAD at 0 range 22 .. 22;
COUNTMODE at 0 range 23 .. 23;
ENC at 0 range 24 .. 24;
Reserved_25_31 at 0 range 25 .. 31;
end record;
subtype CR_ENABLE_Field is STM32_SVD.Bit;
subtype CR_SNGSTRT_Field is STM32_SVD.Bit;
subtype CR_CNTSTRT_Field is STM32_SVD.Bit;
-- Control Register
type CR_Register is record
-- LPTIM Enable
ENABLE : CR_ENABLE_Field := 16#0#;
-- LPTIM start in single mode
SNGSTRT : CR_SNGSTRT_Field := 16#0#;
-- Timer start in continuous mode
CNTSTRT : CR_CNTSTRT_Field := 16#0#;
-- unspecified
Reserved_3_31 : STM32_SVD.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CR_Register use record
ENABLE at 0 range 0 .. 0;
SNGSTRT at 0 range 1 .. 1;
CNTSTRT at 0 range 2 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
subtype CMP_CMP_Field is STM32_SVD.UInt16;
-- Compare Register
type CMP_Register is record
-- Compare value.
CMP : CMP_CMP_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CMP_Register use record
CMP at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype ARR_ARR_Field is STM32_SVD.UInt16;
-- Autoreload Register
type ARR_Register is record
-- Auto reload value.
ARR : ARR_ARR_Field := 16#1#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ARR_Register use record
ARR at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype CNT_CNT_Field is STM32_SVD.UInt16;
-- Counter Register
type CNT_Register is record
-- Read-only. Counter value.
CNT : CNT_CNT_Field;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CNT_Register use record
CNT at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Low power timer
type LPTIM_Peripheral is record
-- Interrupt and Status Register
ISR : aliased ISR_Register;
-- Interrupt Clear Register
ICR : aliased ICR_Register;
-- Interrupt Enable Register
IER : aliased IER_Register;
-- Configuration Register
CFGR : aliased CFGR_Register;
-- Control Register
CR : aliased CR_Register;
-- Compare Register
CMP : aliased CMP_Register;
-- Autoreload Register
ARR : aliased ARR_Register;
-- Counter Register
CNT : aliased CNT_Register;
end record
with Volatile;
for LPTIM_Peripheral use record
ISR at 16#0# range 0 .. 31;
ICR at 16#4# range 0 .. 31;
IER at 16#8# range 0 .. 31;
CFGR at 16#C# range 0 .. 31;
CR at 16#10# range 0 .. 31;
CMP at 16#14# range 0 .. 31;
ARR at 16#18# range 0 .. 31;
CNT at 16#1C# range 0 .. 31;
end record;
-- Low power timer
LPTIM_Periph : aliased LPTIM_Peripheral
with Import, Address => LPTIM_Base;
end STM32_SVD.LPTIM;
|
sungyeon/drake | Ada | 36 | ads | ../machine-apple-darwin/s-prdyli.ads |
reznikmm/matreshka | Ada | 3,771 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012-2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.UML.Classifiers;
package AMF.OCL.Any_Types is
pragma Preelaborate;
type OCL_Any_Type is limited interface
and AMF.UML.Classifiers.UML_Classifier;
type OCL_Any_Type_Access is
access all OCL_Any_Type'Class;
for OCL_Any_Type_Access'Storage_Size use 0;
end AMF.OCL.Any_Types;
|
AdaCore/gpr | Ada | 2,797 | adb | with Ada.Text_IO;
with GPR2.Containers;
with GPR2.Context;
with GPR2.Path_Name;
with GPR2.Project.Registry.Attribute;
with GPR2.Project.Registry.Pack;
with GPR2.Project.Tree.View_Builder;
with GPR2.Source_Info;
procedure Main
is
use GPR2, GPR2.Path_Name, GPR2.Project.Tree;
package PRA renames GPR2.Project.Registry.Attribute;
package PRP renames GPR2.Project.Registry.Pack;
Root : View_Builder.Object :=
View_Builder.Create (Create_Directory ("demo"), "Custom_Project");
Src_Dirs : Containers.Value_List;
Mains : Containers.Value_List;
Tree : Project.Tree.Object;
Ctxt : GPR2.Context.Object;
procedure Print_Attrs (Pck : GPR2.Package_Id) is
begin
for A of Tree.Root_Project.Attributes (Pack => Pck,
With_Config => False)
loop
declare
use type PRA.Value_Kind;
Attr_Name : constant String := Image (A.Name.Id.Attr);
First : Boolean := True;
begin
if Pck /= Project_Level_Scope then
Ada.Text_IO.Put (Image (Pck) & "'");
end if;
Ada.Text_IO.Put (Attr_Name);
if A.Has_Index then
Ada.Text_IO.Put (" (""" & String (A.Index.Value) & """)");
end if;
Ada.Text_IO.Put (": ");
if A.Kind = PRA.Single then
Ada.Text_IO.Put_Line
("""" & String (A.Value.Text) & """");
else
for V of A.Values loop
if not First then
Ada.Text_IO.Put (", ");
else
First := False;
end if;
Ada.Text_IO.Put ("""" & V.Text & """");
end loop;
Ada.Text_IO.New_Line;
end if;
end;
end loop;
end Print_Attrs;
begin
Src_Dirs.Append ("src1");
Src_Dirs.Append ("src2");
Root.Set_Attribute (PRA.Source_Dirs, Src_Dirs);
Root.Set_Attribute (PRA.Object_Dir, "obj");
Mains.Append ("main.adb");
Root.Set_Attribute (PRA.Main, Mains);
Root.Set_Attribute (PRA.Builder.Executable,
"main.adb", "mymain");
View_Builder.Load_Autoconf (Tree, Root, Ctxt);
if Tree.Log_Messages.Has_Error then
Tree.Log_Messages.Output_Messages;
return;
end if;
Ada.Text_IO.Put_Line ("Attributes:");
Print_Attrs (Project_Level_Scope);
Print_Attrs (PRP.Builder);
Ada.Text_IO.Put_Line ("Sources:");
Tree.Update_Sources (Backends => Source_Info.No_Backends);
for S of Tree.Root_Project.Sources loop
Ada.Text_IO.Put_Line (String (S.Path_Name.Value));
end loop;
exception
when GPR2.Project_Error =>
Tree.Log_Messages.Output_Messages;
end Main;
|
AdaCore/Ada_Drivers_Library | Ada | 16,375 | adb | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015-2016, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- with STM32.RCC; use STM32.RCC;
with STM32_SVD.DMA2D; use STM32_SVD.DMA2D;
with STM32_SVD.RCC; use STM32_SVD.RCC;
package body STM32.DMA2D is
use type System.Address;
function To_Word is new Ada.Unchecked_Conversion (System.Address, UInt32);
function Offset (Buffer : DMA2D_Buffer;
X, Y : Integer) return UInt32 with Inline_Always;
DMA2D_Init_Transfer_Int : DMA2D_Sync_Procedure := null;
DMA2D_Wait_Transfer_Int : DMA2D_Sync_Procedure := null;
------------------
-- DMA2D_DeInit --
------------------
procedure DMA2D_DeInit is
begin
RCC_Periph.AHB1ENR.DMA2DEN := False;
DMA2D_Init_Transfer_Int := null;
DMA2D_Wait_Transfer_Int := null;
end DMA2D_DeInit;
----------------
-- DMA2D_Init --
----------------
procedure DMA2D_Init
(Init : DMA2D_Sync_Procedure;
Wait : DMA2D_Sync_Procedure)
is
begin
if DMA2D_Init_Transfer_Int = Init then
return;
end if;
DMA2D_DeInit;
DMA2D_Init_Transfer_Int := Init;
DMA2D_Wait_Transfer_Int := Wait;
RCC_Periph.AHB1ENR.DMA2DEN := True;
RCC_Periph.AHB1RSTR.DMA2DRST := True;
RCC_Periph.AHB1RSTR.DMA2DRST := False;
end DMA2D_Init;
------------
-- Offset --
------------
function Offset (Buffer : DMA2D_Buffer;
X, Y : Integer) return UInt32
is
Off : constant UInt32 := UInt32 (X + Buffer.Width * Y);
begin
case Buffer.Color_Mode is
when ARGB8888 =>
return 4 * Off;
when RGB888 =>
return 3 * Off;
when ARGB1555 | ARGB4444 | RGB565 | AL88 =>
return 2 * Off;
when L8 | AL44 | A8 =>
return Off;
when L4 | A4 =>
return Off / 2;
end case;
end Offset;
----------------
-- DMA2D_Fill --
----------------
procedure DMA2D_Fill
(Buffer : DMA2D_Buffer;
Color : UInt32;
Synchronous : Boolean := False)
is
function Conv is new Ada.Unchecked_Conversion (UInt32, OCOLR_Register);
begin
DMA2D_Wait_Transfer_Int.all;
DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (R2M);
DMA2D_Periph.OPFCCR.CM := As_UInt3 (Buffer.Color_Mode);
DMA2D_Periph.OCOLR := Conv (Color);
DMA2D_Periph.OMAR := To_Word (Buffer.Addr);
DMA2D_Periph.OOR := (LO => 0, others => <>);
DMA2D_Periph.NLR := (NL => UInt16 (Buffer.Height),
PL => UInt14 (Buffer.Width),
others => <>);
DMA2D_Init_Transfer_Int.all;
if Synchronous then
DMA2D_Wait_Transfer_Int.all;
end if;
end DMA2D_Fill;
---------------------
-- DMA2D_Fill_Rect --
---------------------
procedure DMA2D_Fill_Rect
(Buffer : DMA2D_Buffer;
Color : UInt32;
X : Integer;
Y : Integer;
Width : Integer;
Height : Integer;
Synchronous : Boolean := False)
is
function Conv is new Ada.Unchecked_Conversion (UInt32, OCOLR_Register);
Off : constant UInt32 := Offset (Buffer, X, Y);
begin
DMA2D_Wait_Transfer_Int.all;
DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (R2M);
DMA2D_Periph.OPFCCR :=
(CM => DMA2D_Color_Mode'Enum_Rep (Buffer.Color_Mode),
others => <>);
DMA2D_Periph.OCOLR := Conv (Color);
DMA2D_Periph.OMAR := To_Word (Buffer.Addr) + Off;
DMA2D_Periph.OOR.LO := UInt14 (Buffer.Width - Width);
DMA2D_Periph.NLR :=
(NL => UInt16 (Height), PL => UInt14 (Width), others => <>);
DMA2D_Init_Transfer_Int.all;
if Synchronous then
DMA2D_Wait_Transfer_Int.all;
end if;
end DMA2D_Fill_Rect;
---------------------
-- DMA2D_Draw_Rect --
---------------------
procedure DMA2D_Draw_Rect
(Buffer : DMA2D_Buffer;
Color : UInt32;
X : Integer;
Y : Integer;
Width : Integer;
Height : Integer)
is
begin
DMA2D_Draw_Horizontal_Line (Buffer, Color, X, Y, Width);
DMA2D_Draw_Horizontal_Line (Buffer, Color, X, Y + Height - 1, Width);
DMA2D_Draw_Vertical_Line (Buffer, Color, X, Y, Height);
DMA2D_Draw_Vertical_Line (Buffer, Color, X + Width - 1, Y, Height, True);
end DMA2D_Draw_Rect;
---------------------
-- DMA2D_Copy_Rect --
---------------------
procedure DMA2D_Copy_Rect
(Src_Buffer : DMA2D_Buffer;
X_Src : Natural;
Y_Src : Natural;
Dst_Buffer : DMA2D_Buffer;
X_Dst : Natural;
Y_Dst : Natural;
Bg_Buffer : DMA2D_Buffer;
X_Bg : Natural;
Y_Bg : Natural;
Width : Natural;
Height : Natural;
Synchronous : Boolean := False)
is
Src_Off : constant UInt32 := Offset (Src_Buffer, X_Src, Y_Src);
Dst_Off : constant UInt32 := Offset (Dst_Buffer, X_Dst, Y_Dst);
begin
DMA2D_Wait_Transfer_Int.all;
if Bg_Buffer /= Null_Buffer then
-- PFC and blending
DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (M2M_BLEND);
elsif Src_Buffer.Color_Mode = Dst_Buffer.Color_Mode then
-- Direct memory transfer
DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (M2M);
else
DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (M2M_PFC);
end if;
-- SOURCE CONFIGURATION
DMA2D_Periph.FGPFCCR :=
(CM => DMA2D_Color_Mode'Enum_Rep (Src_Buffer.Color_Mode),
AM => DMA2D_AM'Enum_Rep (NO_MODIF),
ALPHA => 255,
others => <>);
if Src_Buffer.Color_Mode = L8 or else Src_Buffer.Color_Mode = L4 then
if Src_Buffer.CLUT_Addr = System.Null_Address then
raise Program_Error with "Source CLUT address required";
end if;
DMA2D_Periph.FGCMAR := To_Word (Src_Buffer.CLUT_Addr);
DMA2D_Periph.FGCMAR := To_Word (Src_Buffer.CLUT_Addr);
DMA2D_Periph.FGPFCCR.CS := (case Src_Buffer.Color_Mode is
when L8 => 2**8 - 1,
when L4 => 2**4 - 1,
when others => 0);
-- Set CLUT mode to RGB888
DMA2D_Periph.FGPFCCR.CCM := Src_Buffer.CLUT_Color_Mode = RGB888;
-- Start loading the CLUT
DMA2D_Periph.FGPFCCR.START := True;
while DMA2D_Periph.FGPFCCR.START loop
-- Wait for CLUT loading...
null;
end loop;
end if;
DMA2D_Periph.FGOR := (LO => UInt14 (Src_Buffer.Width - Width),
others => <>);
DMA2D_Periph.FGMAR := To_Word (Src_Buffer.Addr) + Src_Off;
if Bg_Buffer /= Null_Buffer then
declare
Bg_Off : constant UInt32 := Offset (Bg_Buffer, X_Bg, Y_Bg);
begin
DMA2D_Periph.BGPFCCR.CM :=
DMA2D_Color_Mode'Enum_Rep (Bg_Buffer.Color_Mode);
DMA2D_Periph.BGMAR := To_Word (Bg_Buffer.Addr) + Bg_Off;
DMA2D_Periph.BGPFCCR.CS := 0;
DMA2D_Periph.BGPFCCR.START := False;
DMA2D_Periph.BGOR :=
(LO => UInt14 (Bg_Buffer.Width - Width), others => <>);
if Bg_Buffer.Color_Mode = L8 or else Bg_Buffer.Color_Mode = L4 then
if Bg_Buffer.CLUT_Addr = System.Null_Address then
raise Program_Error with "Background CLUT address required";
end if;
DMA2D_Periph.BGCMAR := To_Word (Bg_Buffer.CLUT_Addr);
DMA2D_Periph.BGPFCCR.CS := (case Bg_Buffer.Color_Mode is
when L8 => 2**8 - 1,
when L4 => 2**4 - 1,
when others => 0);
-- Set CLUT mode to RGB888
DMA2D_Periph.BGPFCCR.CCM := Bg_Buffer.CLUT_Color_Mode = RGB888;
-- Start loading the CLUT
DMA2D_Periph.BGPFCCR.START := True;
while DMA2D_Periph.BGPFCCR.START loop
-- Wait for CLUT loading...
null;
end loop;
end if;
end;
end if;
-- DST CONFIGURATION
DMA2D_Periph.OPFCCR.CM :=
DMA2D_Color_Mode'Enum_Rep (Dst_Buffer.Color_Mode);
DMA2D_Periph.OMAR := To_Word (Dst_Buffer.Addr) + Dst_Off;
DMA2D_Periph.OOR := (LO => UInt14 (Dst_Buffer.Width - Width),
others => <>);
DMA2D_Periph.NLR := (NL => UInt16 (Height),
PL => UInt14 (Width),
others => <>);
DMA2D_Init_Transfer_Int.all;
if Synchronous then
DMA2D_Wait_Transfer_Int.all;
end if;
end DMA2D_Copy_Rect;
------------------------------
-- DMA2D_Draw_Vertical_Line --
------------------------------
procedure DMA2D_Draw_Vertical_Line
(Buffer : DMA2D_Buffer;
Color : UInt32;
X : Integer;
Y : Integer;
Height : Integer;
Synchronous : Boolean := False)
is
NY, NH : Integer;
begin
if Y >= Buffer.Height
or else X not in 0 .. Buffer.Width - 1
then
return;
end if;
if Y < 0 then
NY := 0;
NH := Height + Y;
else
NY := Y;
NH := Height;
end if;
NH := Integer'Min (NH, Buffer.Height - NY - 1);
DMA2D_Fill_Rect (Buffer, Color, X, NY, 1, NH, Synchronous);
end DMA2D_Draw_Vertical_Line;
--------------------------------
-- DMA2D_Draw_Horizontal_Line --
--------------------------------
procedure DMA2D_Draw_Horizontal_Line
(Buffer : DMA2D_Buffer;
Color : UInt32;
X : Integer;
Y : Integer;
Width : Integer;
Synchronous : Boolean := False)
is
NX, NW : Integer;
begin
if X >= Buffer.Width
or else Y not in 0 .. Buffer.Height - 1
then
return;
end if;
if X < 0 then
NX := 0;
NW := Width + X;
else
NX := X;
NW := Width;
end if;
NW := Integer'Min (NW, Buffer.Width - NX - 1);
DMA2D_Fill_Rect (Buffer, Color, NX, Y, NW, 1, Synchronous);
end DMA2D_Draw_Horizontal_Line;
---------------------
-- DMA2D_Set_Pixel --
---------------------
procedure DMA2D_Set_Pixel
(Buffer : DMA2D_Buffer;
X, Y : Integer;
Color : UInt32;
Synchronous : Boolean := False)
is
function Conv is new Ada.Unchecked_Conversion (UInt32, OCOLR_Register);
Off : constant UInt32 := Offset (Buffer, X, Y);
Dead : Boolean := False with Unreferenced;
begin
if X < 0 or else Y < 0
or else X >= Buffer.Width or else Y >= Buffer.Height
then
return;
end if;
DMA2D_Wait_Transfer_Int.all;
DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (R2M);
DMA2D_Periph.OPFCCR.CM := As_UInt3 (Buffer.Color_Mode);
DMA2D_Periph.OCOLR := Conv (Color);
DMA2D_Periph.OMAR := To_Word (Buffer.Addr) + Off;
DMA2D_Periph.OOR := (LO => 1, others => <>);
DMA2D_Periph.NLR := (NL => 1, PL => 1, others => <>);
DMA2D_Init_Transfer_Int.all;
if Synchronous then
DMA2D_Wait_Transfer_Int.all;
end if;
end DMA2D_Set_Pixel;
---------------------------
-- DMA2D_Set_Pixel_Blend --
---------------------------
procedure DMA2D_Set_Pixel_Blend
(Buffer : DMA2D_Buffer;
X, Y : Integer;
Color : DMA2D_Color;
Synchronous : Boolean := False)
is
Off : constant UInt32 := Offset (Buffer, X, Y);
Dead : Boolean := False with Unreferenced;
begin
if X < 0 or else Y < 0
or else X >= Buffer.Width or else Y >= Buffer.Height
then
return;
end if;
DMA2D_Wait_Transfer_Int.all;
-- PFC and blending
DMA2D_Periph.CR.MODE := DMA2D_MODE'Enum_Rep (M2M_BLEND);
-- SOURCE CONFIGURATION
DMA2D_Periph.FGPFCCR.CM := ARGB8888'Enum_Rep;
DMA2D_Periph.FGMAR := To_Word (Color'Address);
DMA2D_Periph.FGPFCCR.AM := DMA2D_AM'Enum_Rep (NO_MODIF);
DMA2D_Periph.FGPFCCR.ALPHA := 255;
DMA2D_Periph.FGPFCCR.CS := 0;
DMA2D_Periph.FGPFCCR.START := False;
DMA2D_Periph.FGOR := (LO => 0, others => <>);
DMA2D_Periph.FGPFCCR.CCM := False; -- Disable CLUT color mode
-- Setup the Background buffer to the destination buffer
DMA2D_Periph.BGPFCCR.CM :=
DMA2D_Color_Mode'Enum_Rep (Buffer.Color_Mode);
DMA2D_Periph.BGMAR := To_Word (Buffer.Addr) + Off;
DMA2D_Periph.BGPFCCR.CS := 0;
DMA2D_Periph.BGPFCCR.START := False;
DMA2D_Periph.BGOR := (LO => UInt14 (Buffer.Width - 1),
others => <>);
DMA2D_Periph.BGPFCCR.CCM := False; -- Disable CLUT color mode
-- DST CONFIGURATION
DMA2D_Periph.OPFCCR.CM :=
DMA2D_Color_Mode'Enum_Rep (Buffer.Color_Mode);
DMA2D_Periph.OMAR := To_Word (Buffer.Addr) + Off;
DMA2D_Periph.OOR := (LO => UInt14 (Buffer.Width - 1),
others => <>);
DMA2D_Periph.NLR := (NL => 1,
PL => 1,
others => <>);
DMA2D_Init_Transfer_Int.all;
if Synchronous then
DMA2D_Wait_Transfer_Int.all;
end if;
end DMA2D_Set_Pixel_Blend;
-------------------------
-- DMA2D_Wait_Transfer --
-------------------------
procedure DMA2D_Wait_Transfer is
begin
DMA2D_Wait_Transfer_Int.all;
end DMA2D_Wait_Transfer;
end STM32.DMA2D;
|
charlie5/lace | Ada | 8,386 | adb | with
openGL.Tasks,
GL.Pointers,
GL.lean,
ada.Characters.latin_1,
interfaces.C.Strings;
package body openGL.Program
is
use gl.lean,
Interfaces;
compiling_in_debug_Mode : constant Boolean := True;
type Shader_view is access all Shader.item'Class;
--------------
-- Parameters
--
procedure Program_is (Self : in out Parameters; Now : in openGL.Program.view)
is
begin
Self.Program := Now;
end Program_is;
function Program (Self : in Parameters) return openGL.Program.view
is
begin
return Self.Program;
end Program;
---------
--- Forge
--
procedure define (Self : in out Item; use_vertex_Shader : in Shader.view;
use_fragment_Shader : in Shader.view)
is
begin
Tasks.check;
Self.gl_Program := glCreateProgram;
glAttachShader (Self.gl_Program, use_vertex_Shader.gl_Shader);
glAttachShader (Self.gl_Program, use_fragment_Shader.gl_Shader);
Self. vertex_Shader := use_vertex_Shader;
Self.fragment_Shader := use_fragment_Shader;
glLinkProgram (Self.gl_Program);
declare
use type C.int;
Status : aliased gl.glInt;
begin
glGetProgramiv (Self.gl_Program,
GL_LINK_STATUS,
Status'unchecked_Access);
if Status = 0
then
declare
link_Log : constant String := Self.ProgramInfoLog;
begin
Self.destroy;
raise Error with "Program link error ~ " & link_Log;
end;
end if;
end;
if compiling_in_debug_Mode
then
glValidateProgram (Self.gl_Program);
end if;
end define;
procedure define (Self : in out Item; use_vertex_Shader_File : in String;
use_fragment_Shader_File : in String)
is
use openGL.Shader;
the_vertex_Shader : constant Shader_view := new openGL.Shader.item;
the_fragment_Shader : constant Shader_view := new openGL.Shader.item;
begin
the_vertex_Shader .define (openGL.Shader.vertex, use_vertex_Shader_File);
the_fragment_Shader.define (openGL.Shader.fragment, use_fragment_Shader_File);
Self.define ( the_vertex_Shader.all'Access,
the_fragment_Shader.all'Access);
end define;
procedure destroy (Self : in out Item)
is
begin
Tasks.check;
glDeleteProgram (Self.gl_Program);
end destroy;
--------------
-- Attributes
--
function Attribute (Self : access Item'Class; Named : in String) return openGL.Attribute.view
is
begin
for Each in 1 .. Self.attribute_Count
loop
if Self.Attributes (Each).Name = Named
then
return Self.Attributes (Each);
end if;
end loop;
raise Error with "'" & Named & "' is not a valid program attribute.";
end Attribute;
function attribute_Location (Self : access Item'Class; Named : in String) return gl.GLuint
is
use gl.Pointers;
use type gl.GLint;
attribute_Name : C.strings.chars_ptr := C.Strings.new_String (Named & ada.characters.Latin_1.NUL);
begin
Tasks.check;
declare
gl_Location : constant gl.GLint := glGetAttribLocation (Self.gl_Program,
to_GLchar_access (attribute_Name));
begin
if gl_Location = -1
then
raise Error with "Requested attribute '" & Named & "' has no gl location in program.";
end if;
C.Strings.free (attribute_Name);
return gl.GLuint (gl_Location);
end;
end attribute_Location;
function is_defined (Self : in Item'Class) return Boolean
is
use type a_gl_Program;
begin
return Self.gl_Program /= 0;
end is_defined;
function ProgramInfoLog (Self : in Item) return String
is
use C, GL;
info_log_Length : aliased glInt := 0;
chars_Written : aliased glSizei := 0;
begin
Tasks.check;
glGetProgramiv (Self.gl_Program,
GL_INFO_LOG_LENGTH,
info_log_Length'unchecked_Access);
if info_log_Length = 0 then
return "";
end if;
declare
use GL.Pointers;
info_Log : aliased C.char_array := C.char_array' [1 .. C.size_t (info_log_Length) => <>];
info_Log_ptr : constant C.strings.chars_ptr := C.strings.to_chars_ptr (info_Log'unchecked_Access);
begin
glGetProgramInfoLog (Self.gl_Program,
glSizei (info_log_Length),
chars_Written'unchecked_Access,
to_GLchar_access (info_Log_ptr));
return C.to_Ada (info_Log);
end;
end ProgramInfoLog;
function uniform_Variable (Self : access Item'Class; Named : in String) return Variable.uniform.bool
is
the_Variable : Variable.uniform.bool;
begin
the_Variable.define (Self, Named);
return the_Variable;
end uniform_Variable;
function uniform_Variable (Self : access Item'Class; Named : in String) return Variable.uniform.int
is
the_Variable : Variable.uniform.int;
begin
the_Variable.define (Self, Named);
return the_Variable;
end uniform_Variable;
function uniform_Variable (Self : access Item'Class; Named : in String) return Variable.uniform.float
is
the_Variable : Variable.uniform.float;
begin
the_Variable.define (Self, Named);
return the_Variable;
end uniform_Variable;
function uniform_Variable (Self : access Item'Class; Named : in String) return Variable.uniform.vec3
is
the_Variable : Variable.uniform.vec3;
begin
the_Variable.define (Self, Named);
return the_Variable;
end uniform_Variable;
function uniform_Variable (Self : access Item'Class; Named : in String) return Variable.uniform.vec4
is
the_Variable : Variable.uniform.vec4;
begin
the_Variable.define (Self, Named);
return the_Variable;
end uniform_Variable;
function uniform_Variable (Self : access Item'Class; Named : in String) return Variable.uniform.mat3
is
the_Variable : Variable.uniform.mat3;
begin
the_Variable.define (Self, Named);
return the_Variable;
end uniform_Variable;
function uniform_Variable (Self : access Item'Class; Named : in String) return Variable.uniform.mat4
is
the_Variable : Variable.uniform.mat4;
begin
the_Variable.define (Self, Named);
return the_Variable;
end uniform_Variable;
--------------
-- Operations
--
procedure add (Self : in out Item; Attribute : in openGL.Attribute.view)
is
begin
Self.attribute_Count := Self.attribute_Count + 1;
Self.Attributes (Self.attribute_Count) := Attribute;
end add;
procedure enable (Self : in out Item)
is
use type gl.GLuint;
begin
Tasks.check;
if Self.gl_Program = 0
then
Item'Class (Self).define; -- TODO: This appears to do nothing.
end if;
glUseProgram (self.gl_Program);
end enable;
procedure enable_Attributes (Self : in Item)
is
begin
for Each in 1 .. Self.attribute_Count
loop
Self.Attributes (Each).enable;
end loop;
end enable_Attributes;
procedure mvp_Transform_is (Self : in out Item; Now : in Matrix_4x4)
is
begin
Self.mvp_Transform := Now;
end mvp_Transform_is;
procedure Scale_is (Self : in out Item; Now : in Vector_3)
is
begin
Self.Scale := Now;
end Scale_is;
procedure set_Uniforms (Self : in Item)
is
the_mvp_Uniform : constant Variable.uniform.mat4 := Self.uniform_Variable ("mvp_Transform");
the_scale_Uniform : constant Variable.uniform.vec3 := Self.uniform_Variable ("Scale");
begin
the_mvp_Uniform .Value_is (Self.mvp_Transform);
the_scale_Uniform.Value_is (Self.Scale);
end set_Uniforms;
-- Privvy
--
function gl_Program (Self : in Item) return a_gl_Program
is
begin
return Self.gl_Program;
end gl_Program;
end openGL.Program;
|
DrenfongWong/tkm-rpc | Ada | 1,305 | ads | with Tkmrpc.Types;
with Tkmrpc.Operations.Ike;
package Tkmrpc.Request.Ike.Dh_Reset is
Data_Size : constant := 8;
type Data_Type is record
Dh_Id : Types.Dh_Id_Type;
end record;
for Data_Type use record
Dh_Id at 0 range 0 .. (8 * 8) - 1;
end record;
for Data_Type'Size use Data_Size * 8;
Padding_Size : constant := Request.Body_Size - Data_Size;
subtype Padding_Range is Natural range 1 .. Padding_Size;
subtype Padding_Type is Types.Byte_Sequence (Padding_Range);
type Request_Type is record
Header : Request.Header_Type;
Data : Data_Type;
Padding : Padding_Type;
end record;
for Request_Type use record
Header at 0 range 0 .. (Request.Header_Size * 8) - 1;
Data at Request.Header_Size range 0 .. (Data_Size * 8) - 1;
Padding at Request.Header_Size + Data_Size range
0 .. (Padding_Size * 8) - 1;
end record;
for Request_Type'Size use Request.Request_Size * 8;
Null_Request : constant Request_Type :=
Request_Type'
(Header =>
Request.Header_Type'(Operation => Operations.Ike.Dh_Reset,
Request_Id => 0),
Data => Data_Type'(Dh_Id => Types.Dh_Id_Type'First),
Padding => Padding_Type'(others => 0));
end Tkmrpc.Request.Ike.Dh_Reset;
|
pvrego/adaino | Ada | 5,779 | adb | -- =============================================================================
-- Package body AVR.TIMERS
-- =============================================================================
package body AVR.TIMERS is
function Get_Current_Value
(Timer : TIMERS.Timer_Type)
return Unsigned_16_Array_Byte
is
Curr_Value : Unsigned_16_Array_Byte;
begin
case Timer is
when TIMER0 =>
Curr_Value := (L => Unsigned_8 (Reg_Timer0.TCNT),
H => 0);
when TIMER1 =>
Curr_Value := (L => Unsigned_8 (Reg_Timer1.TCNT (0)),
H => Unsigned_8 (Reg_Timer1.TCNT (1)));
when TIMER2 =>
Curr_Value := (L => Unsigned_8 (Reg_Timer2.TCNT),
H => 0);
#if MCU="ATMEGA2560" then
when TIMER3 =>
Curr_Value := (L => Unsigned_8 (Reg_Timer3.TCNT (0)),
H => Unsigned_8 (Reg_Timer3.TCNT (1)));
when TIMER4 =>
Curr_Value := (L => Unsigned_8 (Reg_Timer4.TCNT (0)),
H => Unsigned_8 (Reg_Timer4.TCNT (1)));
when TIMER5 =>
Curr_Value := (L => Unsigned_8 (Reg_Timer5.TCNT (0)),
H => Unsigned_8 (Reg_Timer5.TCNT (1)));
#end if;
end case;
return Curr_Value;
exception
when others => return (L => 0,
H => 0);
end Get_Current_Value;
function Get_Current_Value
(Timer : TIMERS.Timer_Type)
return Unsigned_16
is
begin
return To_Unsigned_16 (Get_Current_Value (Timer));
end Get_Current_Value;
function Get_Compare_Value
(Timer : TIMERS.Timer_Type;
Channel : TIMERS.Channel_Type)
return Unsigned_16_Array_Byte
is
Curr_Value : Unsigned_16_Array_Byte;
begin
case Timer is
when TIMER0 => -- Timer0 is 8-bit, only A and B channels
case Channel is
when CHANNEL_A =>
Curr_Value := (L => Unsigned_8 (Reg_Timer0.OCRA),
H => 0);
when CHANNEL_B =>
Curr_Value := (L => Unsigned_8 (Reg_Timer0.OCRB),
H => 0);
#if MCU="ATMEGA2560" then
when others => null;
#end if;
end case;
when TIMER1 =>
case Channel is
when CHANNEL_A =>
Curr_Value := (L => Unsigned_8 (Reg_Timer1.OCRA (0)),
H => Unsigned_8 (Reg_Timer1.OCRA (1)));
when CHANNEL_B =>
Curr_Value := (L => Unsigned_8 (Reg_Timer1.OCRB (0)),
H => Unsigned_8 (Reg_Timer1.OCRB (1)));
#if MCU="ATMEGA2560" then
when CHANNEL_C =>
Curr_Value := (L => Unsigned_8 (Reg_Timer1.OCRC (0)),
H => Unsigned_8 (Reg_Timer1.OCRC (1)));
#end if;
end case;
when TIMER2 => -- Timer2 is 8-bit, only A and B channels
case Channel is
when CHANNEL_A =>
Curr_Value := (L => Unsigned_8 (Reg_Timer2.OCRA),
H => 0);
when CHANNEL_B =>
Curr_Value := (L => Unsigned_8 (Reg_Timer2.OCRB),
H => 0);
#if MCU="ATMEGA2560" then
when others => null;
#end if;
end case;
#if MCU="ATMEGA2560" then
when TIMER3 =>
case Channel is
when CHANNEL_A =>
Curr_Value := (L => Unsigned_8 (Reg_Timer3.OCRA (0)),
H => Unsigned_8 (Reg_Timer3.OCRA (1)));
when CHANNEL_B =>
Curr_Value := (L => Unsigned_8 (Reg_Timer3.OCRB (0)),
H => Unsigned_8 (Reg_Timer3.OCRB (1)));
when CHANNEL_C =>
Curr_Value := (L => Unsigned_8 (Reg_Timer3.OCRC (0)),
H => Unsigned_8 (Reg_Timer3.OCRC (1)));
end case;
when TIMER4 =>
case Channel is
when CHANNEL_A =>
Curr_Value := (L => Unsigned_8 (Reg_Timer4.OCRA (0)),
H => Unsigned_8 (Reg_Timer4.OCRA (1)));
when CHANNEL_B =>
Curr_Value := (L => Unsigned_8 (Reg_Timer4.OCRB (0)),
H => Unsigned_8 (Reg_Timer4.OCRB (1)));
when CHANNEL_C =>
Curr_Value := (L => Unsigned_8 (Reg_Timer4.OCRC (0)),
H => Unsigned_8 (Reg_Timer4.OCRC (1)));
end case;
when TIMER5 =>
case Channel is
when CHANNEL_A =>
Curr_Value := (L => Unsigned_8 (Reg_Timer5.OCRA (0)),
H => Unsigned_8 (Reg_Timer5.OCRA (1)));
when CHANNEL_B =>
Curr_Value := (L => Unsigned_8 (Reg_Timer5.OCRB (0)),
H => Unsigned_8 (Reg_Timer5.OCRB (1)));
when CHANNEL_C =>
Curr_Value := (L => Unsigned_8 (Reg_Timer5.OCRC (0)),
H => Unsigned_8 (Reg_Timer5.OCRC (1)));
end case;
#end if;
end case;
return Curr_Value;
exception
when others => return (L => 0,
H => 0);
end Get_Compare_Value;
function Get_Compare_Value
(Timer : TIMERS.Timer_Type;
Channel : TIMERS.Channel_Type)
return Unsigned_16
is
begin
return To_Unsigned_16
(Get_Compare_Value
(Timer => Timer,
Channel => Channel));
end Get_Compare_Value;
end AVR.TIMERS;
|
reznikmm/matreshka | Ada | 6,760 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Anim.Audio_Elements is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Anim_Audio_Element_Node is
begin
return Self : Anim_Audio_Element_Node do
Matreshka.ODF_Anim.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Anim_Prefix);
end return;
end Create;
----------------
-- Enter_Node --
----------------
overriding procedure Enter_Node
(Self : not null access Anim_Audio_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Enter_Anim_Audio
(ODF.DOM.Anim_Audio_Elements.ODF_Anim_Audio_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Enter_Node (Visitor, Control);
end if;
end Enter_Node;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Anim_Audio_Element_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Audio_Element;
end Get_Local_Name;
----------------
-- Leave_Node --
----------------
overriding procedure Leave_Node
(Self : not null access Anim_Audio_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Leave_Anim_Audio
(ODF.DOM.Anim_Audio_Elements.ODF_Anim_Audio_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Leave_Node (Visitor, Control);
end if;
end Leave_Node;
----------------
-- Visit_Node --
----------------
overriding procedure Visit_Node
(Self : not null access Anim_Audio_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then
ODF.DOM.Iterators.Abstract_ODF_Iterator'Class
(Iterator).Visit_Anim_Audio
(Visitor,
ODF.DOM.Anim_Audio_Elements.ODF_Anim_Audio_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Visit_Node (Iterator, Visitor, Control);
end if;
end Visit_Node;
begin
Matreshka.DOM_Documents.Register_Element
(Matreshka.ODF_String_Constants.Anim_URI,
Matreshka.ODF_String_Constants.Audio_Element,
Anim_Audio_Element_Node'Tag);
end Matreshka.ODF_Anim.Audio_Elements;
|
reznikmm/gela | Ada | 3,553 | ads | with Ada.Containers.Vectors;
with League.Calendars;
with League.String_Vectors;
with League.Strings;
with Gela.Compilations;
with Gela.Contexts;
with Gela.Element_Factories;
with Gela.Lexers;
with Gela.Lexical_Types;
with Gela.Parsers;
package Gela.Plain_Compilations is
pragma Preelaborate;
type Compilation (Context : Gela.Contexts.Context_Access) is
limited new Gela.Compilations.Compilation
and Gela.Lexers.Lexer_Destination
and Gela.Parsers.Parser_Input with private;
type Compilation_Access is access all Compilation;
not overriding procedure Initialize
(Self : in out Compilation;
Text_Name : League.Strings.Universal_String;
Source : League.Strings.Universal_String;
Factory : Gela.Element_Factories.Element_Factory_Access);
private
package Token_Vectors is new Ada.Containers.Vectors
(Index_Type => Gela.Lexical_Types.Token_Index,
Element_Type => Gela.Lexical_Types.Token,
"=" => Gela.Lexical_Types."=");
package Line_Vectors is new Ada.Containers.Vectors
(Index_Type => Gela.Lexical_Types.Line_Index,
Element_Type => Gela.Lexical_Types.Line_Span,
"=" => Gela.Lexical_Types."=");
type Compilation (Context : Gela.Contexts.Context_Access) is
limited new Gela.Compilations.Compilation
and Gela.Lexers.Lexer_Destination
and Gela.Parsers.Parser_Input with
record
Index : Gela.Lexical_Types.Token_Index := 1;
Tokens : Token_Vectors.Vector;
Lines : Line_Vectors.Vector;
Update : League.Calendars.Date_Time;
Text_Name : League.Strings.Universal_String;
Source : League.Strings.Universal_String;
Factory : Gela.Element_Factories.Element_Factory_Access;
end record;
overriding function Context
(Self : Compilation) return Gela.Contexts.Context_Access;
overriding function Text_Name
(Self : Compilation) return League.Strings.Universal_String;
overriding function Object_Name
(Self : Compilation) return League.Strings.Universal_String;
overriding function Compilation_Command_Line_Options
(Self : Compilation)
return League.String_Vectors.Universal_String_Vector;
overriding function Time_Of_Last_Update
(Self : Compilation)
return League.Calendars.Date_Time;
overriding function Compilation_CPU_Duration
(Self : Compilation) return Duration;
overriding function Source
(Self : Compilation) return League.Strings.Universal_String;
overriding function Line_Count
(Self : Compilation) return Gela.Lexical_Types.Line_Count;
overriding function Get_Line_Span
(Self : Compilation;
Index : Gela.Lexical_Types.Line_Index)
return Gela.Lexical_Types.Line_Span;
overriding function Token_Count
(Self : Compilation) return Gela.Lexical_Types.Token_Count;
overriding function Get_Token
(Self : Compilation;
Index : Gela.Lexical_Types.Token_Index)
return Gela.Lexical_Types.Token;
overriding procedure Next_Token
(Self : in out Compilation;
Token : out Gela.Lexical_Types.Token_Kind;
Index : out Gela.Lexical_Types.Token_Index);
overriding procedure New_Token
(Self : in out Compilation;
Token : Gela.Lexical_Types.Token);
overriding procedure New_Line
(Self : in out Compilation;
Line : Gela.Lexical_Types.Line_Span);
overriding function Factory
(Self : Compilation) return Gela.Element_Factories.Element_Factory_Access;
end Gela.Plain_Compilations;
|
reznikmm/matreshka | Ada | 3,659 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Elements;
package ODF.DOM.Form_Listbox_Elements is
pragma Preelaborate;
type ODF_Form_Listbox is limited interface
and XML.DOM.Elements.DOM_Element;
type ODF_Form_Listbox_Access is
access all ODF_Form_Listbox'Class
with Storage_Size => 0;
end ODF.DOM.Form_Listbox_Elements;
|
reznikmm/matreshka | Ada | 9,453 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013-2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with League.Holders;
with League.JSON.Arrays;
with League.JSON.Objects;
with League.JSON.Values;
with League.String_Vectors;
package body Matreshka.JSON_Generator is
--------------
-- Generate --
--------------
function Generate
(Document : League.JSON.Documents.JSON_Document'Class)
return League.Strings.Universal_String
is
Result : League.Strings.Universal_String;
procedure Generate_Array (Value : League.JSON.Arrays.JSON_Array);
procedure Generate_Object (Value : League.JSON.Objects.JSON_Object);
procedure Generate_Value (Value : League.JSON.Values.JSON_Value);
procedure Generate_String (Value : League.Strings.Universal_String);
--------------------
-- Generate_Array --
--------------------
procedure Generate_Array (Value : League.JSON.Arrays.JSON_Array) is
begin
Result.Append ('[');
for J in 1 .. Value.Length loop
if J /= 1 then
Result.Append (',');
end if;
Generate_Value (Value.Element (J));
end loop;
Result.Append (']');
end Generate_Array;
---------------------
-- Generate_Object --
---------------------
procedure Generate_Object (Value : League.JSON.Objects.JSON_Object) is
Members : constant League.String_Vectors.Universal_String_Vector
:= Value.Keys;
begin
Result.Append ('{');
for J in 1 .. Members.Length loop
if J /= 1 then
Result.Append (',');
end if;
Generate_String (Members.Element (J));
Result.Append (':');
Generate_Value (Value.Value (Members.Element (J)));
end loop;
Result.Append ('}');
end Generate_Object;
---------------------
-- Generate_String --
---------------------
procedure Generate_String (Value : League.Strings.Universal_String) is
To_Hex : constant array (Natural range 0 .. 15) of Wide_Wide_Character
:= "0123456789ABCDEF";
Code : Natural;
begin
Result.Append ('"');
for J in 1 .. Value.Length loop
case Value.Element (J).To_Wide_Wide_Character is
when Wide_Wide_Character'Val (16#0000#)
.. Wide_Wide_Character'Val (16#0007#)
| Wide_Wide_Character'Val (16#000B#)
| Wide_Wide_Character'Val (16#000E#)
.. Wide_Wide_Character'Val (16#001F#)
=>
Code :=
Wide_Wide_Character'Pos
(Value.Element (J).To_Wide_Wide_Character);
Result.Append ("\u00");
Result.Append (To_Hex ((Code / 16) mod 16));
Result.Append (To_Hex (Code mod 16));
when Wide_Wide_Character'Val (16#0008#) => -- backspace
Result.Append ("\b");
when Wide_Wide_Character'Val (16#0009#) => -- carriage return
Result.Append ("\r");
when Wide_Wide_Character'Val (16#000A#) => -- line feed
Result.Append ("\n");
when Wide_Wide_Character'Val (16#000C#) => -- form feed
Result.Append ("\f");
when Wide_Wide_Character'Val (16#000D#) => -- tab
Result.Append ("\t");
when '"' =>
Result.Append ("\""");
when '\' =>
Result.Append ("\\");
when others =>
Result.Append (Value.Element (J));
end case;
end loop;
Result.Append ('"');
end Generate_String;
--------------------
-- Generate_Value --
--------------------
procedure Generate_Value (Value : League.JSON.Values.JSON_Value) is
begin
case Value.Kind is
when League.JSON.Values.Empty_Value =>
null;
when League.JSON.Values.Boolean_Value =>
case Value.To_Boolean is
when False =>
Result.Append ("false");
when True =>
Result.Append ("true");
end case;
when League.JSON.Values.Number_Value =>
if Value.Is_Integer_Number then
declare
Image : constant Wide_Wide_String
:= League.Holders.Universal_Integer'Wide_Wide_Image
(Value.To_Integer);
begin
if Image (Image'First) /= ' ' then
Result.Append (Image);
else
Result.Append (Image (Image'First + 1 .. Image'Last));
end if;
end;
else
declare
Image : constant Wide_Wide_String
:= League.Holders.Universal_Float'Wide_Wide_Image
(Value.To_Float);
begin
if Image (Image'First) /= ' ' then
Result.Append (Image);
else
Result.Append (Image (Image'First + 1 .. Image'Last));
end if;
end;
end if;
when League.JSON.Values.String_Value =>
Generate_String (Value.To_String);
when League.JSON.Values.Array_Value =>
Generate_Array (Value.To_Array);
when League.JSON.Values.Object_Value =>
Generate_Object (Value.To_Object);
when League.JSON.Values.Null_Value =>
Result.Append ("null");
end case;
end Generate_Value;
begin
if Document.Is_Object then
Generate_Object (Document.To_JSON_Object);
elsif Document.Is_Array then
Generate_Array (Document.To_JSON_Array);
end if;
return Result;
end Generate;
end Matreshka.JSON_Generator;
|
AdaCore/Ada_Drivers_Library | Ada | 9,086 | adb | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015-2022, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with STM32.Device; use STM32.Device;
package body Serial_IO.Nonblocking is
-------------------------
-- Initialize_Hardware --
-------------------------
procedure Initialize_Hardware (This : in out Serial_Port) is
begin
Serial_IO.Initialize_Hardware (This.Device);
end Initialize_Hardware;
---------------
-- Configure --
---------------
procedure Configure
(This : in out Serial_Port;
Baud_Rate : Baud_Rates;
Parity : Parities := No_Parity;
Data_Bits : Word_Lengths := Word_Length_8;
End_Bits : Stop_Bits := Stopbits_1;
Control : Flow_Control := No_Flow_Control)
is
begin
Serial_IO.Configure (This.Device, Baud_Rate, Parity, Data_Bits, End_Bits, Control);
end Configure;
----------
-- Send --
----------
procedure Send (This : in out Serial_Port; Msg : not null access Message) is
begin
This.Start_Sending (Msg);
end Send;
-------------
-- Receive --
-------------
procedure Receive (This : in out Serial_Port; Msg : not null access Message) is
begin
This.Start_Receiving (Msg);
end Receive;
-----------------
-- Serial_Port --
-----------------
protected body Serial_Port is
-------------------------
-- Handle_Transmission --
-------------------------
procedure Handle_Transmission is
begin
-- if Word_Lenth = 9 then
-- -- handle the extra byte required for the 9th bit
-- else -- 8 data bits so no extra byte involved
Transmit
(Device.Transceiver.all,
Character'Pos (Outgoing_Msg.Content_At (Next_Out)));
Next_Out := Next_Out + 1;
-- end if;
if Next_Out > Outgoing_Msg.Length then
Disable_Interrupts (Device.Transceiver.all, Source => Transmission_Complete);
Outgoing_Msg.Signal_Transmission_Complete;
Outgoing_Msg := null;
end if;
end Handle_Transmission;
----------------------
-- Handle_Reception --
----------------------
procedure Handle_Reception is
Received_Char : constant Character := Character'Val (Current_Input (Device.Transceiver.all));
begin
if Received_Char /= Terminator (Incoming_Msg.all) then
Incoming_Msg.Append (Received_Char);
end if;
if Received_Char = Incoming_Msg.Terminator or
Incoming_Msg.Length = Incoming_Msg.Physical_Size
then -- reception complete
loop
-- wait for device to clear the status
exit when not Status (Device.Transceiver.all, Read_Data_Register_Not_Empty);
end loop;
Disable_Interrupts (Device.Transceiver.all, Source => Received_Data_Not_Empty);
Incoming_Msg.Signal_Reception_Complete;
Incoming_Msg := null;
end if;
end Handle_Reception;
---------
-- ISR --
---------
procedure ISR is
begin
-- check for data arrival
if Status (Device.Transceiver.all, Read_Data_Register_Not_Empty) and
Interrupt_Enabled (Device.Transceiver.all, Received_Data_Not_Empty)
then
Detect_Errors (Is_Xmit_IRQ => False);
Handle_Reception;
Clear_Status (Device.Transceiver.all, Read_Data_Register_Not_Empty);
end if;
-- check for transmission ready
if Status (Device.Transceiver.all, Transmission_Complete_Indicated) and
Interrupt_Enabled (Device.Transceiver.all, Transmission_Complete)
then
Detect_Errors (Is_Xmit_IRQ => True);
Handle_Transmission;
Clear_Status (Device.Transceiver.all, Transmission_Complete_Indicated);
end if;
end ISR;
-------------------
-- Start_Sending --
-------------------
procedure Start_Sending (Msg : not null access Message) is
begin
Outgoing_Msg := Msg;
Next_Out := 1;
Enable_Interrupts (Device.Transceiver.all, Parity_Error);
Enable_Interrupts (Device.Transceiver.all, Error);
Enable_Interrupts (Device.Transceiver.all, Transmission_Complete);
end Start_Sending;
---------------------
-- Start_Receiving --
---------------------
procedure Start_Receiving (Msg : not null access Message) is
begin
Incoming_Msg := Msg;
Incoming_Msg.Clear;
Enable_Interrupts (Device.Transceiver.all, Parity_Error);
Enable_Interrupts (Device.Transceiver.all, Error);
Enable_Interrupts (Device.Transceiver.all, Received_Data_Not_Empty);
end Start_Receiving;
-------------------
-- Detect_Errors --
-------------------
procedure Detect_Errors (Is_Xmit_IRQ : Boolean) is
begin
if Status (Device.Transceiver.all, Parity_Error_Indicated) and
Interrupt_Enabled (Device.Transceiver.all, Parity_Error)
then
Clear_Status (Device.Transceiver.all, Parity_Error_Indicated);
if Is_Xmit_IRQ then
Outgoing_Msg.Note_Error (Parity_Error_Detected);
else
Incoming_Msg.Note_Error (Parity_Error_Detected);
end if;
end if;
if Status (Device.Transceiver.all, Framing_Error_Indicated) and
Interrupt_Enabled (Device.Transceiver.all, Error)
then
Clear_Status (Device.Transceiver.all, Framing_Error_Indicated);
if Is_Xmit_IRQ then
Outgoing_Msg.Note_Error (Frame_Error_Detected);
else
Incoming_Msg.Note_Error (Frame_Error_Detected);
end if;
end if;
if Status (Device.Transceiver.all, USART_Noise_Error_Indicated) and
Interrupt_Enabled (Device.Transceiver.all, Error)
then
Clear_Status (Device.Transceiver.all, USART_Noise_Error_Indicated);
if Is_Xmit_IRQ then
Outgoing_Msg.Note_Error (Noise_Error_Detected);
else
Incoming_Msg.Note_Error (Noise_Error_Detected);
end if;
end if;
if Status (Device.Transceiver.all, Overrun_Error_Indicated) and
Interrupt_Enabled (Device.Transceiver.all, Error)
then
Clear_Status (Device.Transceiver.all, Overrun_Error_Indicated);
if Is_Xmit_IRQ then
Outgoing_Msg.Note_Error (Overrun_Error_Detected);
else
Incoming_Msg.Note_Error (Overrun_Error_Detected);
end if;
end if;
end Detect_Errors;
end Serial_Port;
end Serial_IO.Nonblocking;
|
PThierry/ewok-kernel | Ada | 1,891 | ads | --
-- Copyright 2018 The wookey project team <[email protected]>
-- - Ryad Benadjila
-- - Arnauld Michelizza
-- - Mathieu Renard
-- - Philippe Thierry
-- - Philippe Trebuchet
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
--
with ada.unchecked_conversion;
package ewok.syscalls
with spark_mode => off
is
subtype t_syscall_ret is unsigned_32;
SYS_E_DONE : constant t_syscall_ret := 0; -- Syscall succesful
SYS_E_INVAL : constant t_syscall_ret := 1; -- Invalid input data
SYS_E_DENIED : constant t_syscall_ret := 2; -- Permission is denied
SYS_E_BUSY : constant t_syscall_ret := 3;
-- Target is busy OR not enough ressources OR ressource is already used
type t_svc is
(SVC_EXIT,
SVC_YIELD,
SVC_GET_TIME,
SVC_RESET,
SVC_SLEEP,
SVC_GET_RANDOM,
SVC_LOG,
SVC_REGISTER_DEVICE,
SVC_REGISTER_DMA,
SVC_REGISTER_DMA_SHM,
SVC_GET_TASKID,
SVC_INIT_DONE,
SVC_IPC_RECV_SYNC,
SVC_IPC_SEND_SYNC,
SVC_IPC_RECV_ASYNC,
SVC_IPC_SEND_ASYNC,
SVC_GPIO_SET,
SVC_GPIO_GET,
SVC_GPIO_UNLOCK_EXTI,
SVC_DMA_RECONF,
SVC_DMA_RELOAD,
SVC_DMA_DISABLE,
SVC_DEV_MAP,
SVC_DEV_UNMAP,
SVC_DEV_RELEASE,
SVC_LOCK_ENTER,
SVC_LOCK_EXIT)
with size => 8;
end ewok.syscalls;
|
AdaCore/gpr | Ada | 24,996 | adb | with Ada.Containers;
--
-- Copyright (C) 2019-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0
--
with Ada.Directories;
with Ada.Exceptions;
with Ada.Strings.Unbounded;
with GNAT.IO; use GNAT.IO;
with GPR2;
with GPR2.Containers;
with GPR2.Context;
with GPR2.File_Readers;
with GPR2.KB;
with GPR2.Log;
with GPR2.Options;
with GPR2.Path_Name;
with GPR2.Path_Name.Set;
with GPR2.Project.Tree;
procedure test is
Options : GPR2.Options.Object;
procedure Print_Test_OK is
begin
Put_Line ("Test OK");
Put_Line ("");
end Print_Test_OK;
procedure Add_Switch_Pre_Check is
begin
Options.Add_Switch (GPR2.Options.Unchecked_Shared_Lib_Imports);
end Add_Switch_Pre_Check;
procedure Base_Pre_Check is
Base : GPR2.KB.Object := Options.Base;
pragma Unreferenced (Base);
begin
null;
end Base_Pre_Check;
procedure Build_Path_Pre_Check is
Build_Path : GPR2.Path_Name.Object := Options.Build_Path;
pragma Unreferenced (Build_Path);
begin
null;
end Build_Path_Pre_Check;
procedure Check_Shared_Lib_Pre_Check is
Check_Shared_Lib : Boolean := Options.Check_Shared_Lib;
pragma Unreferenced (Check_Shared_Lib);
begin
null;
end Check_Shared_Lib_Pre_Check;
procedure Config_Project_Pre_Check is
Config_Project : GPR2.Path_Name.Object := Options.Config_Project;
pragma Unreferenced (Config_Project);
begin
null;
end Config_Project_Pre_Check;
procedure Config_Project_Has_Error_Pre_Check is
Config_Project_Has_Error :Boolean := Options.Config_Project_Has_Error;
pragma Unreferenced (Config_Project_Has_Error);
begin
null;
end Config_Project_Has_Error_Pre_Check;
procedure Config_Project_Log_Pre_Check is
Config_Project_Log : GPR2.Log.Object := Options.Config_Project_Log;
pragma Unreferenced (Config_Project_Log);
begin
null;
end Config_Project_Log_Pre_Check;
procedure Context_Pre_Check is
Context : GPR2.Context.Object := Options.Context;
pragma Unreferenced (Context);
begin
null;
end Context_Pre_Check;
procedure Filename_Pre_Check is
Filename : GPR2.Path_Name.Object := Options.Filename;
pragma Unreferenced (Filename);
begin
null;
end Filename_Pre_Check;
procedure Finalize_Pre_Check is
begin
Options.Finalize;
end Finalize_Pre_Check;
procedure Implicit_With_Pre_Check is
Implicit_With : GPR2.Path_Name.Set.Object := Options.Implicit_With;
pragma Unreferenced (Implicit_With);
begin
null;
end Implicit_With_Pre_Check;
procedure Load_Project_Pre_Check is
Tree : GPR2.Project.Tree.Object;
Loaded : Boolean := Options.Load_Project (Tree);
pragma Unreferenced (Loaded);
begin
null;
end Load_Project_Pre_Check;
procedure On_Extra_Arg_Pre_Check is
On_Extra_Arg : Boolean := Options.On_Extra_Arg ("extra-arg");
pragma Unreferenced (On_Extra_Arg);
begin
null;
end On_Extra_Arg_Pre_Check;
procedure Project_File_Pre_Check is
Project_File : GPR2.Path_Name.Object := Options.Project_File;
pragma Unreferenced (Project_File);
begin
null;
end Project_File_Pre_Check;
procedure Project_Is_Defined_Pre_Check is
Project_Is_Defined : Boolean := Options.Project_Is_Defined;
pragma Unreferenced (Project_Is_Defined);
begin
null;
end Project_Is_Defined_Pre_Check;
procedure RTS_Map_Pre_Check is
RTS_Map : GPR2.Containers.Lang_Value_Map := Options.RTS_Map;
pragma Unreferenced (RTS_Map);
begin
null;
end RTS_Map_Pre_Check;
procedure Src_Subdirs_Unbounded_Pre_Check is
Src_Subdirs : Ada.Strings.Unbounded.Unbounded_String := Options.Src_Subdirs;
pragma Unreferenced (Src_Subdirs);
begin
null;
end Src_Subdirs_Unbounded_Pre_Check;
procedure Src_Subdirs_Pre_Check is
Src_Subdirs : GPR2.Optional_Name_Type := Options.Src_Subdirs;
pragma Unreferenced (Src_Subdirs);
begin
null;
end Src_Subdirs_Pre_Check;
procedure Subdirs_Unbounded_Pre_Check is
Subdirs : Ada.Strings.Unbounded.Unbounded_String := Options.Subdirs;
pragma Unreferenced (Subdirs);
begin
null;
end Subdirs_Unbounded_Pre_Check;
procedure Subdirs_Pre_Check is
Subdirs : GPR2.Optional_Name_Type := Options.Subdirs;
pragma Unreferenced (Subdirs);
begin
null;
end Subdirs_Pre_Check;
procedure Target_Pre_Check is
Target : GPR2.Name_Type := Options.Target;
pragma Unreferenced (Target);
begin
null;
end Target_Pre_Check;
procedure Pre_Check_Test (Test : access procedure; Name : String; Finalized : Boolean := False) is
begin
Put_Line ("Testing " & Name);
Options := GPR2.Options.Empty_Options;
if Finalized then
Options.Add_Switch (GPR2.Options.No_Project);
Options.Finalize;
end if;
begin
Test.all;
exception
when E : others =>
Put_Line (Name & " => " & Ada.Exceptions.Exception_Name (E));
Print_Test_OK;
end;
end Pre_Check_Test;
procedure Pre_Check_Tests is
begin
Pre_Check_Test (Add_Switch_Pre_Check'Access, "Add_Switch pre check", True);
Pre_Check_Test (Base_Pre_Check'Access, "Base pre check", False);
Pre_Check_Test (Build_Path_Pre_Check'Access, "Build_Path pre check", False);
Pre_Check_Test (Check_Shared_Lib_Pre_Check'Access, "Check_Shared_Lib pre check", False);
Pre_Check_Test (Config_Project_Pre_Check'Access, "Config_Project_Pre_Check pre check", False);
Pre_Check_Test (Config_Project_Has_Error_Pre_Check'Access, "Config_Project_Has_Error pre check", False);
Pre_Check_Test (Config_Project_Log_Pre_Check'Access, "Config_Project_Log pre check", False);
Pre_Check_Test (Context_Pre_Check'Access, "Context pre check", False);
Pre_Check_Test (Filename_Pre_Check'Access, "Filename pre check", False);
Pre_Check_Test (Finalize_Pre_Check'Access, "Finalize pre check", True);
Pre_Check_Test (Implicit_With_Pre_Check'Access, "Implicit_With pre check", False);
Pre_Check_Test (Load_Project_Pre_Check'Access, "Load_Project pre check", False);
Pre_Check_Test (On_Extra_Arg_Pre_Check'Access, "On_Extra_Arg pre check", True);
Pre_Check_Test (Project_File_Pre_Check'Access, "Project_File pre check", False);
Pre_Check_Test (Project_Is_Defined_Pre_Check'Access, "Project_Is_Defined pre check", False);
Pre_Check_Test (RTS_Map_Pre_Check'Access, "RTS_Map pre check", False);
Pre_Check_Test (Src_Subdirs_Unbounded_Pre_Check'Access, "Src_Subdirs_Unbounded pre check", False);
Pre_Check_Test (Src_Subdirs_Pre_Check'Access, "Src_Subdirs pre check", False);
Pre_Check_Test (Subdirs_Unbounded_Pre_Check'Access, "Subdirs_Unbounded pre check", False);
Pre_Check_Test (Subdirs_Pre_Check'Access, "Subdirs pre check", False);
Pre_Check_Test (Target_Pre_Check'Access, "Target pre check", False);
end Pre_Check_Tests;
procedure Test_Add_Switch_DB is
begin
Put_Line ("Testing Add_Switch --db test.gpr");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.DB, "test.gpr");
Print_Test_OK;
Put_Line ("Testing Add_Switch --db src");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.DB, "src");
Print_Test_OK;
Put_Line ("Testing Add_Switch --db unexisting");
Options := GPR2.Options.Empty_Options;
begin
Options.Add_Switch (GPR2.Options.DB, "unexisting");
exception
when E : GPR2.Options.Usage_Error =>
Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
Print_Test_OK;
end;
end Test_Add_Switch_DB;
procedure Test_Add_Switch_P is
begin
Put_Line ("Testing Add_Switch -Pfirst -Psecond");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.P, "first");
begin
Options.Add_Switch (GPR2.Options.P, "second");
exception
when E : GPR2.Options.Usage_Error =>
Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
Print_Test_OK;
end;
Put_Line ("Testing Add_Switch extra.gpr -Ptest");
Options := GPR2.Options.Empty_Options;
Put_Line ("On_Extra_Arg (""extra.gpr"") => " & GPR2.Options.On_Extra_Arg (Options, "extra.gpr")'Image);
begin
Options.Add_Switch (GPR2.Options.P, "test");
exception
when E : GPR2.Options.Usage_Error =>
Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
Print_Test_OK;
end;
end Test_Add_Switch_P;
procedure Test_Add_Switch_X is
begin
Put_Line ("Testing Add_Switch -X name:value");
Options := GPR2.Options.Empty_Options;
begin
Options.Add_Switch (GPR2.Options.X, "name:value");
exception
when E : GPR2.Options.Usage_Error =>
Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
Print_Test_OK;
end;
end Test_Add_Switch_X;
procedure Test_On_Extra_Arg is
Name1 : constant String := "extra1.gpr";
Name2 : constant String := "extra2.gpr";
Other_Arg : constant String := "other-arg";
begin
Put_Line ("Testing On_Extra_Arg other-arg extra1.gpr other-arg extra2.gpr");
Options := GPR2.Options.Empty_Options;
Put_Line ("On_Extra_Arg (""" & Other_Arg & """) => " & GPR2.Options.On_Extra_Arg (Options, Other_Arg)'Image);
Put_Line ("On_Extra_Arg (""" & Name1 & """) => " & GPR2.Options.On_Extra_Arg (Options, Name1)'Image);
Put_Line ("On_Extra_Arg (""" & Other_Arg & """) => " & GPR2.Options.On_Extra_Arg (Options, Other_Arg)'Image);
begin
Put_Line ("On_Extra_Arg (""" & Name2 & """) => " & GPR2.Options.On_Extra_Arg (Options, Name2)'Image);
exception
when E : GPR2.Options.Usage_Error =>
Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
Print_Test_OK;
end;
Put_Line ("Testing Add_Switch -Ptest extra.gpr");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.P, "test");
begin
Put_Line ("On_Extra_Arg (""extra.gpr"") => " & GPR2.Options.On_Extra_Arg (Options, "extra.gpr")'Image);
exception
when E : GPR2.Options.Usage_Error =>
Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
Print_Test_OK;
end;
end Test_On_Extra_Arg;
procedure Test_Add_Switch_RTS_Map is
use GPR2;
RTS : GPR2.Containers.Lang_Value_Map;
Other_Language : constant Language_Id := +"otherlanguage";
begin
Put_Line ("Testing --RTS=adaRuntime1 --RTS:otherLanguage=otherRuntime1");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.No_Project);
Options.Add_Switch (GPR2.Options.RTS, "adaRuntime1");
Options.Add_Switch (GPR2.Options.RTS, "otherRuntime1", "otherLanguage");
Options.Finalize;
RTS := Options.RTS_Map;
Put_Line ("Ada runtime: " & RTS.Element (GPR2.Ada_Language));
Put_Line ("Other runtime: " & RTS.Element (Other_Language));
Print_Test_OK;
Put_Line ("Testing --RTS:ada=adaRuntime0 --RTS:ADA=adaRuntime2 --RTS:otherLanguage=otherRuntime1");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.No_Project);
Options.Add_Switch (GPR2.Options.RTS, "adaRuntime0", "ada");
Options.Add_Switch (GPR2.Options.RTS, "adaRuntime2", "ADA");
Options.Add_Switch (GPR2.Options.RTS, "otherRuntime0", "otherLanguage");
Options.Add_Switch (GPR2.Options.RTS, "otherRuntime2", "OTHERLANGUAGE");
Options.Finalize;
RTS := Options.RTS_Map;
Put_Line ("Ada runtime: " & RTS.Element (GPR2.Ada_Language));
Put_Line ("Other language runtime: " & RTS.Element (Other_Language));
Print_Test_OK;
end Test_Add_Switch_RTS_Map;
procedure Test_Values is
procedure Output_Values (Allow_Implicit_Project : String := "")is
use Ada.Containers;
begin
Put_Line ("Filename" & Allow_Implicit_Project & ":" & Options.Filename.Value);
Put_Line ("Context.Length" & Allow_Implicit_Project & ":" & Options.Context.Length'Image);
if Options.Implicit_With.Length > 0 then
Put_Line ("Context'First " & String (Options.Context.First_Key) & "=" & String (Options.Context.First_Element));
else
Put_Line ("Context" & Allow_Implicit_Project & ": is empty");
end if;
if Options.Config_Project.Is_Defined then
Put_Line ("Config_Project:" & String (Options.Config_Project.Name));
else
Put_Line ("Config_Project" & Allow_Implicit_Project & ": is not defined");
end if;
Put_Line ("Build_Path" & Allow_Implicit_Project & ":" & Options.Build_Path.Value);
declare
Subdirs : constant GPR2.Optional_Name_Type := Options.Subdirs;
Src_Subdirs : constant GPR2.Optional_Name_Type := Options.Src_Subdirs;
begin
Put_Line ("Subdirs" & Allow_Implicit_Project & ":" & String (Subdirs));
Put_Line ("Subdirs (unbounded)" & Allow_Implicit_Project & ":" & Ada.Strings.Unbounded.To_String (Options.Subdirs));
Put_Line ("Src_Subdirs" & Allow_Implicit_Project & ":" & String (Src_Subdirs));
Put_Line ("Src_Subdirs (unbounded)" & Allow_Implicit_Project & ":" & Ada.Strings.Unbounded.To_String (Options.Src_Subdirs));
end;
Put_Line ("Check_Shared_Lib" & Allow_Implicit_Project & ":" & Options.Check_Shared_Lib'Image);
if Options.Implicit_With.Length > 0 then
Put_Line ("Implicit_With'First" & String (Options.Implicit_With.First_Element.Name));
else
Put_Line ("Implicit_With" & Allow_Implicit_Project & ": is empty");
end if;
Put_Line ("Target" & Allow_Implicit_Project & ":" & String (Options.Target));
Put_Line ("RTS_Map.Length" & Allow_Implicit_Project & ":" & Options.RTS_Map.Length'Image);
Put_Line ("Base.Is_Default_Db" & Allow_Implicit_Project & ":" & Options.Base.Is_Default_Db'Image);
Put_Line ("Project_Is_Defined" & Allow_Implicit_Project & ":" & Options.Project_Is_Defined'Image);
end Output_Values;
begin
Put_Line ("Testing default values (--no-project)");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.No_Project);
Options.Finalize (Allow_Implicit_Project => False);
Output_Values;
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.No_Project);
Options.Finalize;
Output_Values ("(Allow_Implicit_Project)");
Print_Test_OK;
Put_Line ("Testing values");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.AP, "./path-added");
Options.Add_Switch (GPR2.Options.Autoconf, "autoconf.cgpr");
Options.Add_Switch (GPR2.Options.Db_Minus);
Options.Add_Switch (GPR2.Options.Implicit_With, "implicit.gpr");
Options.Add_Switch (GPR2.Options.Src_Subdirs, "Src_Subdirs");
Options.Add_Switch (GPR2.Options.Subdirs, "Subdirs");
Options.Add_Switch (GPR2.Options.Target, "arm-elf");
Options.Add_Switch (GPR2.Options.Unchecked_Shared_Lib_Imports);
Options.Add_Switch (GPR2.Options.X, "key=value");
Options.Finalize;
Output_Values;
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.Config, "config.cgpr");
Options.Finalize;
Put_Line ("Config_Project (--config):" & String (Options.Config_Project.Name));
Print_Test_OK;
end Test_Values;
procedure Test_Finalize is
procedure Print_Path (Name : String; Path_Name : GPR2.Path_Name.Object) is
begin
if Path_Name.Is_Defined then
Put_Line (Name & ":" & String (Path_Name.Name));
else
Put_Line (Name & " is Undefined");
end if;
end Print_Path;
procedure Print_Paths is
begin
Print_Path ("Filename", Options.Filename);
Print_Path ("Build_Path", Options.Build_Path);
end Print_Paths;
procedure Test (Current_Directory : String; Allow_Implicit_Project : Boolean := True;Quiet : Boolean := False) is
begin
Ada.Directories.Set_Directory (Current_Directory);
Put_Line ("Testing Finalize no arguments at " & Ada.Directories.Current_Directory
& " with Allow_Implicit_Project=" & Allow_Implicit_Project'Image );
Options := GPR2.Options.Empty_Options;
Options.Finalize (Allow_Implicit_Project, Quiet);
Print_Paths;
Print_Test_OK;
end Test;
begin
Put_Line ("Testing Finalize --no-project -Ptest");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.No_Project);
Options.Add_Switch (GPR2.Options.P, "test");
begin
Options.Finalize;
exception
when E : GPR2.Options.Usage_Error =>
Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
Print_Test_OK;
end;
Put_Line ("Testing Finalize --root-dir=root -Ptest");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.Root_Dir, "root");
Options.Add_Switch (GPR2.Options.P, "test");
begin
Options.Finalize;
exception
when E : GPR2.Options.Usage_Error =>
Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
Print_Test_OK;
end;
Test (".");
Test ("./new-current-directory/default");
Test ("../two-gpr");
Test ("../two-gpr", Quiet => True);
Test ("../no-gpr");
Test ("../..", Allow_Implicit_Project => False);
Put_Line ("Testing Finalize -Ptest");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.P, "test");
Options.Finalize;
Print_Paths;
Print_Test_OK;
Put_Line ("Testing Finalize --relocate-build-tree=relocated -Ptest");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.P, "test");
Options.Add_Switch (GPR2.Options.Relocate_Build_Tree, "relocated");
Options.Finalize;
Print_Paths;
Print_Test_OK;
Put_Line ("Testing Finalize --no-project --relocate-build-tree=relocated");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.No_Project);
Options.Add_Switch (GPR2.Options.Relocate_Build_Tree, "relocated");
Options.Finalize;
Print_Paths;
Print_Test_OK;
Put_Line ("Testing Finalize --no-project --relocate-build-tree=relocated --root-dir=.");
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.No_Project);
Options.Add_Switch (GPR2.Options.Relocate_Build_Tree, "relocated");
Options.Add_Switch (GPR2.Options.Root_Dir, Ada.Directories.Current_Directory & ".");
Options.Finalize;
Print_Paths;
Print_Test_OK;
end Test_Finalize;
procedure Test_Load_Project is
Tree : GPR2.Project.Tree.Object;
procedure Test (Name : String;
Tree : in out GPR2.Project.Tree.Object;
Absent_Dir_Error : GPR2.Project.Tree.Error_Level :=
GPR2.Project.Tree.Warning;
File_Reader : GPR2.File_Readers.File_Reader_Reference :=
GPR2.File_Readers.No_File_Reader_Reference;
Quiet : Boolean := False) is
Loaded : Boolean;
procedure Output_Messages (Log : GPR2.Log.Object) is
begin
for C in Log.Iterate
(Information => False,
Warning => True,
Error => True,
Lint => False,
Read => False,
Unread => True)
loop
Put_Line (Log (C).Format);
end loop;
end Output_Messages;
begin
Put_Line ("Testing Load Project " & Name);
Loaded := Options.Load_Project
(Tree => Tree,
Absent_Dir_Error => Absent_Dir_Error,
File_Reader => File_Reader,
Quiet => Quiet);
Put_Line ("Load_Project returned " & Loaded'Image);
if Options.Config_Project_Has_Error then
Output_Messages (Options.Config_Project_Log);
end if;
if Tree.Log_Messages.Has_Error then
Output_Messages (Tree.Log_Messages.all);
end if;
if not Loaded then
Put_Line ("Target:" & String (Tree.Target));
Put_Line ("Runtime(Ada):" & String (Tree.Runtime (GPR2.Ada_Language)));
Put_Line ("Subdirs:" & String (Tree.Subdirs));
if Tree.Has_Src_Subdirs then
Put_Line ("Src_Subdirs:" & String (Tree.Src_Subdirs));
end if;
Put_Line ("Build_Path:" & String (Tree.Build_Path.Name));
Put_Line ("Object_Directory:" & String (Tree.Root_Project.Object_Directory.Name));
end if;
Print_Test_OK;
end Test;
begin
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.AP, "added-path");
Options.Add_Switch (GPR2.Options.P, "load-project/test");
Options.Add_Switch (GPR2.Options.Autoconf, "autoconf.cgpr");
Options.Add_Switch (GPR2.Options.Src_Subdirs, "src_subdirs");
Options.Add_Switch (GPR2.Options.Subdirs, "subdirs");
Options.Add_Switch (GPR2.Options.X, "BUILD=Debug");
Options.Finalize;
Test ("-aP added-path -Pload-project/test --autoconf=other-autoconf.cgpr --subdirs=subdirs --src_subdirs=srcsubdirs -XBUILD=Debug", Tree);
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.AP, "added-path");
Options.Add_Switch (GPR2.Options.AP, "load-project");
Options.Add_Switch (GPR2.Options.Root_Dir, ".");
Options.Add_Switch (GPR2.Options.Relocate_Build_Tree, "relocated");
Options.Add_Switch (GPR2.Options.P, "test");
Options.Add_Switch (GPR2.Options.Autoconf, "other-autoconf.cgpr");
Options.Add_Switch (GPR2.Options.X, "BUILD=Debug");
Options.Finalize;
Test ("-aP added-path -aP load-project --root-dir=. --relocate-build-tree=relocated -Ptest --autoconf=autoconf.cgpr -XBUILD=Debug", Tree, Quiet => True);
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.AP, "added-path");
Options.Add_Switch (GPR2.Options.P, "load-project/test");
Options.Add_Switch (GPR2.Options.Config, "autoconf.cgpr");
Options.Add_Switch (GPR2.Options.Src_Subdirs, "src_subdirs");
Options.Add_Switch (GPR2.Options.Subdirs, "subdirs");
Options.Add_Switch (GPR2.Options.X, "BUILD=Release");
Options.Finalize;
Test ("-aP added-path -Pload-project/test --config=autoconf.cgpr --subdirs=subdirs --src_subdirs=srcsubdirs -XBUILD=Debug", Tree);
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.AP, "added-path");
Options.Add_Switch (GPR2.Options.P, "load-project/test");
Options.Add_Switch (GPR2.Options.Target, String (Tree.Target));
Options.Add_Switch (GPR2.Options.Config, "autoconf.cgpr");
Options.Add_Switch (GPR2.Options.X, "BUILD=Release");
Options.Finalize;
Test ("-aP added-path -Pload-project/test --config=autoconf.cgpr --subdirs=subdirs --src_subdirs=srcsubdirs -XBUILD=Debug --target " & String (Tree.Target), Tree);
Options := GPR2.Options.Empty_Options;
Options.Add_Switch (GPR2.Options.AP, "added-path");
Options.Add_Switch (GPR2.Options.P, "load-project/test");
Options.Add_Switch (GPR2.Options.Target, "unknown-target");
Options.Add_Switch (GPR2.Options.Config, "autoconf.cgpr");
Options.Add_Switch (GPR2.Options.Src_Subdirs, "src_subdirs");
Options.Add_Switch (GPR2.Options.Subdirs, "subdirs");
Options.Add_Switch (GPR2.Options.X, "BUILD=Release");
Options.Finalize;
Test ("-aP added-path -Pload-project/test --config=autoconf.cgpr --subdirs=subdirs --src_subdirs=srcsubdirs -XBUILD=Debug --target unknown-target", Tree);
end Test_Load_Project;
begin
Pre_Check_Tests;
Test_Add_Switch_DB;
Test_Add_Switch_P;
Test_Add_Switch_X;
Test_On_Extra_Arg;
Test_Add_Switch_RTS_Map;
Test_Values;
Test_Finalize;
Test_Load_Project;
end test;
|
AdaCore/gpr | Ada | 413 | ads | --
-- Copyright (C) 2019-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception
--
with Ada.Containers.Indefinite_Hashed_Maps;
package GPR2.Project.Unit_Info.Set is
package Set is
new Ada.Containers.Indefinite_Hashed_Maps
(Name_Type, Unit_Info.Object, GPR2.Hash, GPR2."=");
subtype Object is Set.Map;
subtype Cursor is Set.Cursor;
end GPR2.Project.Unit_Info.Set;
|
RREE/build-avr-ada-toolchain | Ada | 5,711 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . S E C O N D A R Y _ S T A C K --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2013, 2016-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. --
-- --
------------------------------------------------------------------------------
-- This version is a simplified edition of the original
-- System.Secondary_Stack from gcc-4.7 and gcc-9.2 for use in single
-- threaded AVR applications.
pragma Compiler_Unit_Warning;
with System.Parameters;
with System.Storage_Elements;
package System.Secondary_Stack is
pragma Preelaborate;
package SP renames System.Parameters;
package SSE renames System.Storage_Elements;
type SS_Stack (Size : SP.Size_Type) is private;
type SS_Stack_Ptr is access all SS_Stack with Storage_Size => 0;
procedure SS_Init
(Stack : in out SS_Stack_Ptr;
Size : SP.Size_Type := SP.Unspecified_Size);
-- Initialize the given secondary stack Stack.
procedure SS_Allocate
(Addr : out System.Address;
Storage_Size : SSE.Storage_Count);
-- Allocate enough space for a 'Storage_Size' bytes object with
-- maximum alignment. The address of the allocated space is
-- returned in Addr.
type Mark_Id is private;
-- Type used to mark the stack for mark/release processing
function SS_Mark return Mark_Id;
-- Return the Mark corresponding to the current state of the stack
procedure SS_Release (M : Mark_Id);
-- Restore the state of the stack corresponding to the mark M.
function SS_Get_Max return Long_Long_Integer;
-- Return maximum used space in storage units for the current secondary
-- stack.
private
SS_Pool : Integer;
-- Unused entity that is just present to ease the sharing of the
-- pool mechanism for specific allocation/deallocation in the
-- compiler (???)
subtype SS_Ptr is SP.Size_Type;
type Memory is array (SS_Ptr range <>) of SSE.Storage_Element
with
Alignment => Standard'Maximum_Alignment;
-- The region of memory that holds the stack itself.
-- This stack grows up.
type SS_Stack (Size : SP.Size_Type) is record
Top : SS_Ptr;
Max : SS_Ptr;
Internal_Chunk : Memory (1 .. Size);
end record;
type Mark_Id is new SS_Ptr;
------------------------------------
-- Binder Allocated Stack Support --
------------------------------------
-- When the No_Implicit_Heap_Allocations or No_Implicit_Task_Allocations
-- restrictions are in effect the binder statically generates secondary
-- stacks for tasks who are using default-sized secondary stack. Assignment
-- of these stacks to tasks is handled by SS_Init. The following variables
-- assist SS_Init and are defined here so the runtime does not depend on
-- the binder.
Binder_SS_Count : Natural;
pragma Export (Ada, Binder_SS_Count, "__gnat_binder_ss_count");
-- The number of default sized secondary stacks allocated by the binder
Default_SS_Size : SP.Size_Type;
pragma Export (Ada, Default_SS_Size, "__gnat_default_ss_size");
-- The default size for secondary stacks. Defined here and not in init.c/
-- System.Init because these locations are not present on ZFP or
-- Ravenscar-SFP run-times.
Default_Sized_SS_Pool : System.Address;
pragma Export (Ada, Default_Sized_SS_Pool, "__gnat_default_ss_pool");
-- Address to the secondary stack pool generated by the binder that
-- contains default sized stacks.
Num_Of_Assigned_Stacks : Natural := 0;
-- The number of currently allocated secondary stacks
end System.Secondary_Stack;
|
msrLi/portingSources | Ada | 912 | adb | -- Copyright 2007-2014 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Pck; use Pck;
procedure Fixed is
type Fixed_Point_Type is delta 0.001 range 0.0 .. 1000.0;
My_Var : Fixed_Point_Type := 14.0;
begin
Do_Nothing (My_Var'Address); -- STOP
end Fixed;
|
reznikmm/matreshka | Ada | 9,843 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014-2020, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Attributes;
with Matreshka.DOM_Documents;
with Matreshka.DOM_Lists;
package body Matreshka.DOM_Elements is
use type League.Strings.Universal_String;
use type Matreshka.DOM_Nodes.Node_Access;
------------------
-- Constructors --
------------------
package body Constructors is
----------------
-- Initialize --
----------------
procedure Initialize
(Self : not null access Abstract_Element_Node'Class;
Document : not null Matreshka.DOM_Nodes.Document_Access) is
begin
Matreshka.DOM_Nodes.Constructors.Initialize (Self, Document);
end Initialize;
end Constructors;
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Element_L2_Parameters)
return Element_Node is
begin
return Self : Element_Node do
Matreshka.DOM_Nodes.Constructors.Initialize
(Self'Unchecked_Access, Parameters.Document);
Self.Namespace_URI := Parameters.Namespace_URI;
Self.Prefix := Parameters.Prefix;
Self.Local_Name := Parameters.Local_Name;
end return;
end Create;
----------------
-- Enter_Node --
----------------
overriding procedure Enter_Node
(Self : not null access Abstract_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
Visitor.Enter_Element
(XML.DOM.Elements.DOM_Element_Access (Self), Control);
end Enter_Node;
---------------------------
-- Get_Attribute_Node_NS --
---------------------------
overriding function Get_Attribute_Node_NS
(Self : not null access Abstract_Element_Node;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String)
return XML.DOM.Attributes.DOM_Attribute_Access
is
Current : Matreshka.DOM_Nodes.Node_Access := Self.First_Attribute;
begin
while Current /= null loop
exit when
Current.Get_Namespace_URI = Namespace_URI
and then Current.Get_Local_Name = Local_Name;
Current := Current.Next;
end loop;
return XML.DOM.Attributes.DOM_Attribute_Access (Current);
end Get_Attribute_Node_NS;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Element_Node)
return League.Strings.Universal_String is
begin
return Self.Local_Name;
end Get_Local_Name;
-----------------------
-- Get_Namespace_URI --
-----------------------
overriding function Get_Namespace_URI
(Self : not null access constant Element_Node)
return League.Strings.Universal_String is
begin
return Self.Namespace_URI;
end Get_Namespace_URI;
-------------------
-- Get_Node_Type --
-------------------
overriding function Get_Node_Type
(Self : not null access constant Abstract_Element_Node)
return XML.DOM.Node_Type
is
pragma Unreferenced (Self);
begin
return XML.DOM.Element_Node;
end Get_Node_Type;
------------------
-- Get_Tag_Name --
------------------
overriding function Get_Tag_Name
(Self : not null access constant Abstract_Element_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
raise Program_Error;
return League.Strings.Empty_Universal_String;
end Get_Tag_Name;
----------------
-- Leave_Node --
----------------
overriding procedure Leave_Node
(Self : not null access Abstract_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
Visitor.Leave_Element
(XML.DOM.Elements.DOM_Element_Access (Self), Control);
end Leave_Node;
---------------------------
-- Set_Attribute_Node_NS --
---------------------------
overriding function Set_Attribute_Node_NS
(Self : not null access Abstract_Element_Node;
New_Attr : not null XML.DOM.Attributes.DOM_Attribute_Access)
return XML.DOM.Attributes.DOM_Attribute_Access
is
use XML.DOM.Elements;
-- use type XML.DOM.Elements.DOM_Element_Access;
New_Attribute : constant Matreshka.DOM_Nodes.Node_Access
:= Matreshka.DOM_Nodes.Node_Access (New_Attr);
Old_Attribute : Matreshka.DOM_Nodes.Node_Access
:= Self.First_Attribute;
begin
Self.Check_Wrong_Document (New_Attr);
if New_Attr.Get_Owner_Element /= null then
Self.Raise_Inuse_Attribute_Error;
end if;
-- Lookup for existing attribute.
while Old_Attribute /= null loop
if Old_Attribute.all
in Matreshka.DOM_Attributes.Abstract_Attribute_L2_Node'Class
then
if Old_Attribute = New_Attribute then
return New_Attr;
elsif Old_Attribute.Get_Local_Name = New_Attribute.Get_Local_Name
and Old_Attribute.Get_Namespace_URI
= New_Attribute.Get_Namespace_URI
then
-- Detach old attribute from the list of element's attributes
-- and attach it to the list of detached nodes of document.
Matreshka.DOM_Lists.Remove_From_Attributes (Old_Attribute);
Matreshka.DOM_Lists.Insert_Into_Detached (Old_Attribute);
exit;
end if;
end if;
Old_Attribute := Old_Attribute.Next;
end loop;
-- Append new attribute node to the list of element's attributes.
Matreshka.DOM_Lists.Remove_From_Detached (New_Attribute);
Matreshka.DOM_Lists.Insert_Into_Attributes
(Matreshka.DOM_Nodes.Element_Access (Self), New_Attribute);
return XML.DOM.Attributes.DOM_Attribute_Access (Old_Attribute);
end Set_Attribute_Node_NS;
----------------
-- Visit_Node --
----------------
overriding procedure Visit_Node
(Self : not null access Abstract_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
Iterator.Visit_Element
(Visitor, XML.DOM.Elements.DOM_Element_Access (Self), Control);
end Visit_Node;
end Matreshka.DOM_Elements;
|
zhmu/ananas | Ada | 347 | adb | -- { dg-do run }
-- { dg-options "-O" }
with Opt35_Pkg; use Opt35_Pkg;
procedure Opt35 is
I : Integer := -1;
N : Natural := 0;
begin
begin
I := F(0);
exception
when E => N := N + 1;
end;
begin
I := I + F(0);
exception
when E => N := N + 1;
end;
if N /= 2 or I = 0 then
raise Program_Error;
end if;
end;
|
albertklee/SPARKZumo | Ada | 4,717 | ads | pragma SPARK_Mode;
with Types; use Types;
-- These are visible to the spec for SPARK Globals
with Geo_Filter;
-- with Pwm;
with Zumo_LED;
with Zumo_LSM303;
with Zumo_L3gd20h;
with Zumo_Motion;
with Zumo_Motors;
with Zumo_Pushbutton;
with Zumo_QTR;
with Wire;
with Line_Finder;
-- @summary
-- The main entry point to the application
--
-- @description
-- This is the main entry point to the application. The Setup and Workloop
-- functions are called from the Arduino sketch
--
package SPARKZumo is
-- True if we have called all necessary inits
Initd : Boolean := False;
-- The mode to use to read the IR sensors
ReadMode : constant Sensor_Read_Mode := Emitters_On;
-- A quick utility test to work with the RISC board
procedure RISC_Test;
-- The main workloop of the application. This is called from the loop
-- function of the Arduino sketch
procedure WorkLoop
with Global => (Proof_In => (Initd,
Zumo_LED.Initd,
Zumo_Motors.Initd,
Zumo_QTR.Initd),
Input => (Zumo_Motors.FlipLeft,
Zumo_Motors.FlipRight,
Zumo_QTR.Calibrated_On,
Zumo_QTR.Calibrated_Off),
In_Out => (Line_Finder.BotState,
Line_Finder.Fast_Speed,
Line_Finder.Slow_Speed,
Zumo_QTR.Cal_Vals_On,
Zumo_QTR.Cal_Vals_Off,
Geo_Filter.Window,
Geo_Filter.Window_Index)),
Pre => (Initd and
Zumo_LED.Initd and
Zumo_Motors.Initd and
Zumo_QTR.Initd);
-- This setup procedure is called from the setup function in the Arduino
-- sketch
procedure Setup
with Pre => (not Initd and
not Zumo_LED.Initd and
not Zumo_Pushbutton.Initd and
not Zumo_Motors.Initd and
not Zumo_QTR.Initd and
not Zumo_Motion.Initd),
Post => (Initd and
Zumo_LED.Initd and
Zumo_Pushbutton.Initd and
Zumo_Motors.Initd and
Zumo_QTR.Initd and
Zumo_Motion.Initd);
private
-- The actual calibration sequence to run. This called calibration many
-- times while moving the robot around. The robot should be place around
-- a line so that it can calibrate on what is a line and what isnt.
procedure Calibration_Sequence
with Global => (Proof_In => (Initd,
Zumo_Motors.Initd,
Zumo_QTR.Initd),
Input => (Zumo_Motors.FlipLeft,
Zumo_Motors.FlipRight),
Output => (Zumo_QTR.Calibrated_On,
Zumo_QTR.Calibrated_Off),
In_Out => (Zumo_QTR.Cal_Vals_On,
Zumo_QTR.Cal_Vals_Off)),
Pre => (Initd and
Zumo_Motors.Initd and
Zumo_QTR.Initd);
-- This handles init'ing everything that needs to be init'd in the app
procedure Inits
with Global => (Input => (Wire.Transmission_Status),
-- Output => (Pwm.Register_State),
In_Out => (Initd,
Zumo_LED.Initd,
Zumo_LSM303.Initd,
Zumo_L3gd20h.Initd,
Zumo_Motion.Initd,
Zumo_Motors.Initd,
Zumo_Pushbutton.Initd,
Zumo_QTR.Initd)),
Pre => (not Initd and
not Zumo_LED.Initd and
not Zumo_Pushbutton.Initd and
not Zumo_Motors.Initd and
not Zumo_QTR.Initd and
not Zumo_Motion.Initd),
Post => (Initd and
Zumo_LED.Initd and
Zumo_Pushbutton.Initd and
Zumo_Motors.Initd and
Zumo_QTR.Initd and
Zumo_Motion.Initd);
-- This is the exception handler that ends in a infinite loop. This is
-- called from the Ardunio sketch when an exception is thrown.
procedure Exception_Handler
with Pre => (Zumo_LED.Initd and Zumo_Motors.Initd);
end SPARKZumo;
|
reznikmm/matreshka | Ada | 3,633 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.Elements.Generic_Hash;
function AMF.UML.Protocol_Transitions.Hash is
new AMF.Elements.Generic_Hash (UML_Protocol_Transition, UML_Protocol_Transition_Access);
|
ekoeppen/STM32_Generic_Ada_Drivers | Ada | 27,878 | ads | -- This spec has been automatically generated from STM32F303xE.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with System;
package STM32_SVD.USB_FS is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype USB_EP0R_EA_Field is STM32_SVD.UInt4;
subtype USB_EP0R_STAT_TX_Field is STM32_SVD.UInt2;
subtype USB_EP0R_DTOG_TX_Field is STM32_SVD.Bit;
subtype USB_EP0R_CTR_TX_Field is STM32_SVD.Bit;
subtype USB_EP0R_EP_KIND_Field is STM32_SVD.Bit;
subtype USB_EP0R_EP_TYPE_Field is STM32_SVD.UInt2;
subtype USB_EP0R_SETUP_Field is STM32_SVD.Bit;
subtype USB_EP0R_STAT_RX_Field is STM32_SVD.UInt2;
subtype USB_EP0R_DTOG_RX_Field is STM32_SVD.Bit;
subtype USB_EP0R_CTR_RX_Field is STM32_SVD.Bit;
-- endpoint 0 register
type USB_EP0R_Register is record
-- Endpoint address
EA : USB_EP0R_EA_Field := 16#0#;
-- Status bits, for transmission transfers
STAT_TX : USB_EP0R_STAT_TX_Field := 16#0#;
-- Data Toggle, for transmission transfers
DTOG_TX : USB_EP0R_DTOG_TX_Field := 16#0#;
-- Correct Transfer for transmission
CTR_TX : USB_EP0R_CTR_TX_Field := 16#0#;
-- Endpoint kind
EP_KIND : USB_EP0R_EP_KIND_Field := 16#0#;
-- Endpoint type
EP_TYPE : USB_EP0R_EP_TYPE_Field := 16#0#;
-- Read-only. Setup transaction completed
SETUP : USB_EP0R_SETUP_Field := 16#0#;
-- Status bits, for reception transfers
STAT_RX : USB_EP0R_STAT_RX_Field := 16#0#;
-- Data Toggle, for reception transfers
DTOG_RX : USB_EP0R_DTOG_RX_Field := 16#0#;
-- Correct transfer for reception
CTR_RX : USB_EP0R_CTR_RX_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for USB_EP0R_Register use record
EA at 0 range 0 .. 3;
STAT_TX at 0 range 4 .. 5;
DTOG_TX at 0 range 6 .. 6;
CTR_TX at 0 range 7 .. 7;
EP_KIND at 0 range 8 .. 8;
EP_TYPE at 0 range 9 .. 10;
SETUP at 0 range 11 .. 11;
STAT_RX at 0 range 12 .. 13;
DTOG_RX at 0 range 14 .. 14;
CTR_RX at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype USB_EP1R_EA_Field is STM32_SVD.UInt4;
subtype USB_EP1R_STAT_TX_Field is STM32_SVD.UInt2;
subtype USB_EP1R_DTOG_TX_Field is STM32_SVD.Bit;
subtype USB_EP1R_CTR_TX_Field is STM32_SVD.Bit;
subtype USB_EP1R_EP_KIND_Field is STM32_SVD.Bit;
subtype USB_EP1R_EP_TYPE_Field is STM32_SVD.UInt2;
subtype USB_EP1R_SETUP_Field is STM32_SVD.Bit;
subtype USB_EP1R_STAT_RX_Field is STM32_SVD.UInt2;
subtype USB_EP1R_DTOG_RX_Field is STM32_SVD.Bit;
subtype USB_EP1R_CTR_RX_Field is STM32_SVD.Bit;
-- endpoint 1 register
type USB_EP1R_Register is record
-- Endpoint address
EA : USB_EP1R_EA_Field := 16#0#;
-- Status bits, for transmission transfers
STAT_TX : USB_EP1R_STAT_TX_Field := 16#0#;
-- Data Toggle, for transmission transfers
DTOG_TX : USB_EP1R_DTOG_TX_Field := 16#0#;
-- Correct Transfer for transmission
CTR_TX : USB_EP1R_CTR_TX_Field := 16#0#;
-- Endpoint kind
EP_KIND : USB_EP1R_EP_KIND_Field := 16#0#;
-- Endpoint type
EP_TYPE : USB_EP1R_EP_TYPE_Field := 16#0#;
-- Read-only. Setup transaction completed
SETUP : USB_EP1R_SETUP_Field := 16#0#;
-- Status bits, for reception transfers
STAT_RX : USB_EP1R_STAT_RX_Field := 16#0#;
-- Data Toggle, for reception transfers
DTOG_RX : USB_EP1R_DTOG_RX_Field := 16#0#;
-- Correct transfer for reception
CTR_RX : USB_EP1R_CTR_RX_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for USB_EP1R_Register use record
EA at 0 range 0 .. 3;
STAT_TX at 0 range 4 .. 5;
DTOG_TX at 0 range 6 .. 6;
CTR_TX at 0 range 7 .. 7;
EP_KIND at 0 range 8 .. 8;
EP_TYPE at 0 range 9 .. 10;
SETUP at 0 range 11 .. 11;
STAT_RX at 0 range 12 .. 13;
DTOG_RX at 0 range 14 .. 14;
CTR_RX at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype USB_EP2R_EA_Field is STM32_SVD.UInt4;
subtype USB_EP2R_STAT_TX_Field is STM32_SVD.UInt2;
subtype USB_EP2R_DTOG_TX_Field is STM32_SVD.Bit;
subtype USB_EP2R_CTR_TX_Field is STM32_SVD.Bit;
subtype USB_EP2R_EP_KIND_Field is STM32_SVD.Bit;
subtype USB_EP2R_EP_TYPE_Field is STM32_SVD.UInt2;
subtype USB_EP2R_SETUP_Field is STM32_SVD.Bit;
subtype USB_EP2R_STAT_RX_Field is STM32_SVD.UInt2;
subtype USB_EP2R_DTOG_RX_Field is STM32_SVD.Bit;
subtype USB_EP2R_CTR_RX_Field is STM32_SVD.Bit;
-- endpoint 2 register
type USB_EP2R_Register is record
-- Endpoint address
EA : USB_EP2R_EA_Field := 16#0#;
-- Status bits, for transmission transfers
STAT_TX : USB_EP2R_STAT_TX_Field := 16#0#;
-- Data Toggle, for transmission transfers
DTOG_TX : USB_EP2R_DTOG_TX_Field := 16#0#;
-- Correct Transfer for transmission
CTR_TX : USB_EP2R_CTR_TX_Field := 16#0#;
-- Endpoint kind
EP_KIND : USB_EP2R_EP_KIND_Field := 16#0#;
-- Endpoint type
EP_TYPE : USB_EP2R_EP_TYPE_Field := 16#0#;
-- Read-only. Setup transaction completed
SETUP : USB_EP2R_SETUP_Field := 16#0#;
-- Status bits, for reception transfers
STAT_RX : USB_EP2R_STAT_RX_Field := 16#0#;
-- Data Toggle, for reception transfers
DTOG_RX : USB_EP2R_DTOG_RX_Field := 16#0#;
-- Correct transfer for reception
CTR_RX : USB_EP2R_CTR_RX_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for USB_EP2R_Register use record
EA at 0 range 0 .. 3;
STAT_TX at 0 range 4 .. 5;
DTOG_TX at 0 range 6 .. 6;
CTR_TX at 0 range 7 .. 7;
EP_KIND at 0 range 8 .. 8;
EP_TYPE at 0 range 9 .. 10;
SETUP at 0 range 11 .. 11;
STAT_RX at 0 range 12 .. 13;
DTOG_RX at 0 range 14 .. 14;
CTR_RX at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype USB_EP3R_EA_Field is STM32_SVD.UInt4;
subtype USB_EP3R_STAT_TX_Field is STM32_SVD.UInt2;
subtype USB_EP3R_DTOG_TX_Field is STM32_SVD.Bit;
subtype USB_EP3R_CTR_TX_Field is STM32_SVD.Bit;
subtype USB_EP3R_EP_KIND_Field is STM32_SVD.Bit;
subtype USB_EP3R_EP_TYPE_Field is STM32_SVD.UInt2;
subtype USB_EP3R_SETUP_Field is STM32_SVD.Bit;
subtype USB_EP3R_STAT_RX_Field is STM32_SVD.UInt2;
subtype USB_EP3R_DTOG_RX_Field is STM32_SVD.Bit;
subtype USB_EP3R_CTR_RX_Field is STM32_SVD.Bit;
-- endpoint 3 register
type USB_EP3R_Register is record
-- Endpoint address
EA : USB_EP3R_EA_Field := 16#0#;
-- Status bits, for transmission transfers
STAT_TX : USB_EP3R_STAT_TX_Field := 16#0#;
-- Data Toggle, for transmission transfers
DTOG_TX : USB_EP3R_DTOG_TX_Field := 16#0#;
-- Correct Transfer for transmission
CTR_TX : USB_EP3R_CTR_TX_Field := 16#0#;
-- Endpoint kind
EP_KIND : USB_EP3R_EP_KIND_Field := 16#0#;
-- Endpoint type
EP_TYPE : USB_EP3R_EP_TYPE_Field := 16#0#;
-- Read-only. Setup transaction completed
SETUP : USB_EP3R_SETUP_Field := 16#0#;
-- Status bits, for reception transfers
STAT_RX : USB_EP3R_STAT_RX_Field := 16#0#;
-- Data Toggle, for reception transfers
DTOG_RX : USB_EP3R_DTOG_RX_Field := 16#0#;
-- Correct transfer for reception
CTR_RX : USB_EP3R_CTR_RX_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for USB_EP3R_Register use record
EA at 0 range 0 .. 3;
STAT_TX at 0 range 4 .. 5;
DTOG_TX at 0 range 6 .. 6;
CTR_TX at 0 range 7 .. 7;
EP_KIND at 0 range 8 .. 8;
EP_TYPE at 0 range 9 .. 10;
SETUP at 0 range 11 .. 11;
STAT_RX at 0 range 12 .. 13;
DTOG_RX at 0 range 14 .. 14;
CTR_RX at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype USB_EP4R_EA_Field is STM32_SVD.UInt4;
subtype USB_EP4R_STAT_TX_Field is STM32_SVD.UInt2;
subtype USB_EP4R_DTOG_TX_Field is STM32_SVD.Bit;
subtype USB_EP4R_CTR_TX_Field is STM32_SVD.Bit;
subtype USB_EP4R_EP_KIND_Field is STM32_SVD.Bit;
subtype USB_EP4R_EP_TYPE_Field is STM32_SVD.UInt2;
subtype USB_EP4R_SETUP_Field is STM32_SVD.Bit;
subtype USB_EP4R_STAT_RX_Field is STM32_SVD.UInt2;
subtype USB_EP4R_DTOG_RX_Field is STM32_SVD.Bit;
subtype USB_EP4R_CTR_RX_Field is STM32_SVD.Bit;
-- endpoint 4 register
type USB_EP4R_Register is record
-- Endpoint address
EA : USB_EP4R_EA_Field := 16#0#;
-- Status bits, for transmission transfers
STAT_TX : USB_EP4R_STAT_TX_Field := 16#0#;
-- Data Toggle, for transmission transfers
DTOG_TX : USB_EP4R_DTOG_TX_Field := 16#0#;
-- Correct Transfer for transmission
CTR_TX : USB_EP4R_CTR_TX_Field := 16#0#;
-- Endpoint kind
EP_KIND : USB_EP4R_EP_KIND_Field := 16#0#;
-- Endpoint type
EP_TYPE : USB_EP4R_EP_TYPE_Field := 16#0#;
-- Read-only. Setup transaction completed
SETUP : USB_EP4R_SETUP_Field := 16#0#;
-- Status bits, for reception transfers
STAT_RX : USB_EP4R_STAT_RX_Field := 16#0#;
-- Data Toggle, for reception transfers
DTOG_RX : USB_EP4R_DTOG_RX_Field := 16#0#;
-- Correct transfer for reception
CTR_RX : USB_EP4R_CTR_RX_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for USB_EP4R_Register use record
EA at 0 range 0 .. 3;
STAT_TX at 0 range 4 .. 5;
DTOG_TX at 0 range 6 .. 6;
CTR_TX at 0 range 7 .. 7;
EP_KIND at 0 range 8 .. 8;
EP_TYPE at 0 range 9 .. 10;
SETUP at 0 range 11 .. 11;
STAT_RX at 0 range 12 .. 13;
DTOG_RX at 0 range 14 .. 14;
CTR_RX at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype USB_EP5R_EA_Field is STM32_SVD.UInt4;
subtype USB_EP5R_STAT_TX_Field is STM32_SVD.UInt2;
subtype USB_EP5R_DTOG_TX_Field is STM32_SVD.Bit;
subtype USB_EP5R_CTR_TX_Field is STM32_SVD.Bit;
subtype USB_EP5R_EP_KIND_Field is STM32_SVD.Bit;
subtype USB_EP5R_EP_TYPE_Field is STM32_SVD.UInt2;
subtype USB_EP5R_SETUP_Field is STM32_SVD.Bit;
subtype USB_EP5R_STAT_RX_Field is STM32_SVD.UInt2;
subtype USB_EP5R_DTOG_RX_Field is STM32_SVD.Bit;
subtype USB_EP5R_CTR_RX_Field is STM32_SVD.Bit;
-- endpoint 5 register
type USB_EP5R_Register is record
-- Endpoint address
EA : USB_EP5R_EA_Field := 16#0#;
-- Status bits, for transmission transfers
STAT_TX : USB_EP5R_STAT_TX_Field := 16#0#;
-- Data Toggle, for transmission transfers
DTOG_TX : USB_EP5R_DTOG_TX_Field := 16#0#;
-- Correct Transfer for transmission
CTR_TX : USB_EP5R_CTR_TX_Field := 16#0#;
-- Endpoint kind
EP_KIND : USB_EP5R_EP_KIND_Field := 16#0#;
-- Endpoint type
EP_TYPE : USB_EP5R_EP_TYPE_Field := 16#0#;
-- Read-only. Setup transaction completed
SETUP : USB_EP5R_SETUP_Field := 16#0#;
-- Status bits, for reception transfers
STAT_RX : USB_EP5R_STAT_RX_Field := 16#0#;
-- Data Toggle, for reception transfers
DTOG_RX : USB_EP5R_DTOG_RX_Field := 16#0#;
-- Correct transfer for reception
CTR_RX : USB_EP5R_CTR_RX_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for USB_EP5R_Register use record
EA at 0 range 0 .. 3;
STAT_TX at 0 range 4 .. 5;
DTOG_TX at 0 range 6 .. 6;
CTR_TX at 0 range 7 .. 7;
EP_KIND at 0 range 8 .. 8;
EP_TYPE at 0 range 9 .. 10;
SETUP at 0 range 11 .. 11;
STAT_RX at 0 range 12 .. 13;
DTOG_RX at 0 range 14 .. 14;
CTR_RX at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype USB_EP6R_EA_Field is STM32_SVD.UInt4;
subtype USB_EP6R_STAT_TX_Field is STM32_SVD.UInt2;
subtype USB_EP6R_DTOG_TX_Field is STM32_SVD.Bit;
subtype USB_EP6R_CTR_TX_Field is STM32_SVD.Bit;
subtype USB_EP6R_EP_KIND_Field is STM32_SVD.Bit;
subtype USB_EP6R_EP_TYPE_Field is STM32_SVD.UInt2;
subtype USB_EP6R_SETUP_Field is STM32_SVD.Bit;
subtype USB_EP6R_STAT_RX_Field is STM32_SVD.UInt2;
subtype USB_EP6R_DTOG_RX_Field is STM32_SVD.Bit;
subtype USB_EP6R_CTR_RX_Field is STM32_SVD.Bit;
-- endpoint 6 register
type USB_EP6R_Register is record
-- Endpoint address
EA : USB_EP6R_EA_Field := 16#0#;
-- Status bits, for transmission transfers
STAT_TX : USB_EP6R_STAT_TX_Field := 16#0#;
-- Data Toggle, for transmission transfers
DTOG_TX : USB_EP6R_DTOG_TX_Field := 16#0#;
-- Correct Transfer for transmission
CTR_TX : USB_EP6R_CTR_TX_Field := 16#0#;
-- Endpoint kind
EP_KIND : USB_EP6R_EP_KIND_Field := 16#0#;
-- Endpoint type
EP_TYPE : USB_EP6R_EP_TYPE_Field := 16#0#;
-- Read-only. Setup transaction completed
SETUP : USB_EP6R_SETUP_Field := 16#0#;
-- Status bits, for reception transfers
STAT_RX : USB_EP6R_STAT_RX_Field := 16#0#;
-- Data Toggle, for reception transfers
DTOG_RX : USB_EP6R_DTOG_RX_Field := 16#0#;
-- Correct transfer for reception
CTR_RX : USB_EP6R_CTR_RX_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for USB_EP6R_Register use record
EA at 0 range 0 .. 3;
STAT_TX at 0 range 4 .. 5;
DTOG_TX at 0 range 6 .. 6;
CTR_TX at 0 range 7 .. 7;
EP_KIND at 0 range 8 .. 8;
EP_TYPE at 0 range 9 .. 10;
SETUP at 0 range 11 .. 11;
STAT_RX at 0 range 12 .. 13;
DTOG_RX at 0 range 14 .. 14;
CTR_RX at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype USB_EP7R_EA_Field is STM32_SVD.UInt4;
subtype USB_EP7R_STAT_TX_Field is STM32_SVD.UInt2;
subtype USB_EP7R_DTOG_TX_Field is STM32_SVD.Bit;
subtype USB_EP7R_CTR_TX_Field is STM32_SVD.Bit;
subtype USB_EP7R_EP_KIND_Field is STM32_SVD.Bit;
subtype USB_EP7R_EP_TYPE_Field is STM32_SVD.UInt2;
subtype USB_EP7R_SETUP_Field is STM32_SVD.Bit;
subtype USB_EP7R_STAT_RX_Field is STM32_SVD.UInt2;
subtype USB_EP7R_DTOG_RX_Field is STM32_SVD.Bit;
subtype USB_EP7R_CTR_RX_Field is STM32_SVD.Bit;
-- endpoint 7 register
type USB_EP7R_Register is record
-- Endpoint address
EA : USB_EP7R_EA_Field := 16#0#;
-- Status bits, for transmission transfers
STAT_TX : USB_EP7R_STAT_TX_Field := 16#0#;
-- Data Toggle, for transmission transfers
DTOG_TX : USB_EP7R_DTOG_TX_Field := 16#0#;
-- Correct Transfer for transmission
CTR_TX : USB_EP7R_CTR_TX_Field := 16#0#;
-- Endpoint kind
EP_KIND : USB_EP7R_EP_KIND_Field := 16#0#;
-- Endpoint type
EP_TYPE : USB_EP7R_EP_TYPE_Field := 16#0#;
-- Read-only. Setup transaction completed
SETUP : USB_EP7R_SETUP_Field := 16#0#;
-- Status bits, for reception transfers
STAT_RX : USB_EP7R_STAT_RX_Field := 16#0#;
-- Data Toggle, for reception transfers
DTOG_RX : USB_EP7R_DTOG_RX_Field := 16#0#;
-- Correct transfer for reception
CTR_RX : USB_EP7R_CTR_RX_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for USB_EP7R_Register use record
EA at 0 range 0 .. 3;
STAT_TX at 0 range 4 .. 5;
DTOG_TX at 0 range 6 .. 6;
CTR_TX at 0 range 7 .. 7;
EP_KIND at 0 range 8 .. 8;
EP_TYPE at 0 range 9 .. 10;
SETUP at 0 range 11 .. 11;
STAT_RX at 0 range 12 .. 13;
DTOG_RX at 0 range 14 .. 14;
CTR_RX at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype USB_CNTR_FRES_Field is STM32_SVD.Bit;
subtype USB_CNTR_PDWN_Field is STM32_SVD.Bit;
subtype USB_CNTR_LPMODE_Field is STM32_SVD.Bit;
subtype USB_CNTR_FSUSP_Field is STM32_SVD.Bit;
subtype USB_CNTR_RESUME_Field is STM32_SVD.Bit;
subtype USB_CNTR_ESOFM_Field is STM32_SVD.Bit;
subtype USB_CNTR_SOFM_Field is STM32_SVD.Bit;
subtype USB_CNTR_RESETM_Field is STM32_SVD.Bit;
subtype USB_CNTR_SUSPM_Field is STM32_SVD.Bit;
subtype USB_CNTR_WKUPM_Field is STM32_SVD.Bit;
subtype USB_CNTR_ERRM_Field is STM32_SVD.Bit;
subtype USB_CNTR_PMAOVRM_Field is STM32_SVD.Bit;
subtype USB_CNTR_CTRM_Field is STM32_SVD.Bit;
-- control register
type USB_CNTR_Register is record
-- Force USB Reset
FRES : USB_CNTR_FRES_Field := 16#1#;
-- Power down
PDWN : USB_CNTR_PDWN_Field := 16#1#;
-- Low-power mode
LPMODE : USB_CNTR_LPMODE_Field := 16#0#;
-- Force suspend
FSUSP : USB_CNTR_FSUSP_Field := 16#0#;
-- Resume request
RESUME : USB_CNTR_RESUME_Field := 16#0#;
-- unspecified
Reserved_5_7 : STM32_SVD.UInt3 := 16#0#;
-- Expected start of frame interrupt mask
ESOFM : USB_CNTR_ESOFM_Field := 16#0#;
-- Start of frame interrupt mask
SOFM : USB_CNTR_SOFM_Field := 16#0#;
-- USB reset interrupt mask
RESETM : USB_CNTR_RESETM_Field := 16#0#;
-- Suspend mode interrupt mask
SUSPM : USB_CNTR_SUSPM_Field := 16#0#;
-- Wakeup interrupt mask
WKUPM : USB_CNTR_WKUPM_Field := 16#0#;
-- Error interrupt mask
ERRM : USB_CNTR_ERRM_Field := 16#0#;
-- Packet memory area over / underrun interrupt mask
PMAOVRM : USB_CNTR_PMAOVRM_Field := 16#0#;
-- Correct transfer interrupt mask
CTRM : USB_CNTR_CTRM_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for USB_CNTR_Register use record
FRES at 0 range 0 .. 0;
PDWN at 0 range 1 .. 1;
LPMODE at 0 range 2 .. 2;
FSUSP at 0 range 3 .. 3;
RESUME at 0 range 4 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
ESOFM at 0 range 8 .. 8;
SOFM at 0 range 9 .. 9;
RESETM at 0 range 10 .. 10;
SUSPM at 0 range 11 .. 11;
WKUPM at 0 range 12 .. 12;
ERRM at 0 range 13 .. 13;
PMAOVRM at 0 range 14 .. 14;
CTRM at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype ISTR_EP_ID_Field is STM32_SVD.UInt4;
subtype ISTR_DIR_Field is STM32_SVD.Bit;
subtype ISTR_ESOF_Field is STM32_SVD.Bit;
subtype ISTR_SOF_Field is STM32_SVD.Bit;
subtype ISTR_RESET_Field is STM32_SVD.Bit;
subtype ISTR_SUSP_Field is STM32_SVD.Bit;
subtype ISTR_WKUP_Field is STM32_SVD.Bit;
subtype ISTR_ERR_Field is STM32_SVD.Bit;
subtype ISTR_PMAOVR_Field is STM32_SVD.Bit;
subtype ISTR_CTR_Field is STM32_SVD.Bit;
-- interrupt status register
type ISTR_Register is record
-- Read-only. Endpoint Identifier
EP_ID : ISTR_EP_ID_Field := 16#0#;
-- Read-only. Direction of transaction
DIR : ISTR_DIR_Field := 16#0#;
-- unspecified
Reserved_5_7 : STM32_SVD.UInt3 := 16#0#;
-- Expected start frame
ESOF : ISTR_ESOF_Field := 16#0#;
-- start of frame
SOF : ISTR_SOF_Field := 16#0#;
-- reset request
RESET : ISTR_RESET_Field := 16#0#;
-- Suspend mode request
SUSP : ISTR_SUSP_Field := 16#0#;
-- Wakeup
WKUP : ISTR_WKUP_Field := 16#0#;
-- Error
ERR : ISTR_ERR_Field := 16#0#;
-- Packet memory area over / underrun
PMAOVR : ISTR_PMAOVR_Field := 16#0#;
-- Read-only. Correct transfer
CTR : ISTR_CTR_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for ISTR_Register use record
EP_ID at 0 range 0 .. 3;
DIR at 0 range 4 .. 4;
Reserved_5_7 at 0 range 5 .. 7;
ESOF at 0 range 8 .. 8;
SOF at 0 range 9 .. 9;
RESET at 0 range 10 .. 10;
SUSP at 0 range 11 .. 11;
WKUP at 0 range 12 .. 12;
ERR at 0 range 13 .. 13;
PMAOVR at 0 range 14 .. 14;
CTR at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype FNR_FN_Field is STM32_SVD.UInt11;
subtype FNR_LSOF_Field is STM32_SVD.UInt2;
subtype FNR_LCK_Field is STM32_SVD.Bit;
subtype FNR_RXDM_Field is STM32_SVD.Bit;
subtype FNR_RXDP_Field is STM32_SVD.Bit;
-- frame number register
type FNR_Register is record
-- Read-only. Frame number
FN : FNR_FN_Field;
-- Read-only. Lost SOF
LSOF : FNR_LSOF_Field;
-- Read-only. Locked
LCK : FNR_LCK_Field;
-- Read-only. Receive data - line status
RXDM : FNR_RXDM_Field;
-- Read-only. Receive data + line status
RXDP : FNR_RXDP_Field;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for FNR_Register use record
FN at 0 range 0 .. 10;
LSOF at 0 range 11 .. 12;
LCK at 0 range 13 .. 13;
RXDM at 0 range 14 .. 14;
RXDP at 0 range 15 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-- DADDR_ADD array element
subtype DADDR_ADD_Element is STM32_SVD.Bit;
-- DADDR_ADD array
type DADDR_ADD_Field_Array is array (1 .. 7) of DADDR_ADD_Element
with Component_Size => 1, Size => 7;
-- Type definition for DADDR_ADD
type DADDR_ADD_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- ADD as a value
Val : STM32_SVD.UInt7;
when True =>
-- ADD as an array
Arr : DADDR_ADD_Field_Array;
end case;
end record
with Unchecked_Union, Size => 7;
for DADDR_ADD_Field use record
Val at 0 range 0 .. 6;
Arr at 0 range 0 .. 6;
end record;
subtype DADDR_EF_Field is STM32_SVD.Bit;
-- device address
type DADDR_Register is record
-- Device address
ADD : DADDR_ADD_Field := (As_Array => False, Val => 16#0#);
-- Enable function
EF : DADDR_EF_Field := 16#0#;
-- unspecified
Reserved_8_31 : STM32_SVD.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for DADDR_Register use record
ADD at 0 range 0 .. 6;
EF at 0 range 7 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype BTABLE_BTABLE_Field is STM32_SVD.UInt13;
-- Buffer table address
type BTABLE_Register is record
-- unspecified
Reserved_0_2 : STM32_SVD.UInt3 := 16#0#;
-- Buffer table
BTABLE : BTABLE_BTABLE_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for BTABLE_Register use record
Reserved_0_2 at 0 range 0 .. 2;
BTABLE at 0 range 3 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Universal serial bus full-speed device interface
type USB_FS_Peripheral is record
-- endpoint 0 register
USB_EP0R : aliased USB_EP0R_Register;
-- endpoint 1 register
USB_EP1R : aliased USB_EP1R_Register;
-- endpoint 2 register
USB_EP2R : aliased USB_EP2R_Register;
-- endpoint 3 register
USB_EP3R : aliased USB_EP3R_Register;
-- endpoint 4 register
USB_EP4R : aliased USB_EP4R_Register;
-- endpoint 5 register
USB_EP5R : aliased USB_EP5R_Register;
-- endpoint 6 register
USB_EP6R : aliased USB_EP6R_Register;
-- endpoint 7 register
USB_EP7R : aliased USB_EP7R_Register;
-- control register
USB_CNTR : aliased USB_CNTR_Register;
-- interrupt status register
ISTR : aliased ISTR_Register;
-- frame number register
FNR : aliased FNR_Register;
-- device address
DADDR : aliased DADDR_Register;
-- Buffer table address
BTABLE : aliased BTABLE_Register;
end record
with Volatile;
for USB_FS_Peripheral use record
USB_EP0R at 16#0# range 0 .. 31;
USB_EP1R at 16#4# range 0 .. 31;
USB_EP2R at 16#8# range 0 .. 31;
USB_EP3R at 16#C# range 0 .. 31;
USB_EP4R at 16#10# range 0 .. 31;
USB_EP5R at 16#14# range 0 .. 31;
USB_EP6R at 16#18# range 0 .. 31;
USB_EP7R at 16#1C# range 0 .. 31;
USB_CNTR at 16#40# range 0 .. 31;
ISTR at 16#44# range 0 .. 31;
FNR at 16#48# range 0 .. 31;
DADDR at 16#4C# range 0 .. 31;
BTABLE at 16#50# range 0 .. 31;
end record;
-- Universal serial bus full-speed device interface
USB_FS_Periph : aliased USB_FS_Peripheral
with Import, Address => System'To_Address (16#40005C00#);
end STM32_SVD.USB_FS;
|
reznikmm/matreshka | Ada | 3,737 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
package AMF.Factories.DI_Factories is
pragma Preelaborate;
type DI_Factory is limited interface
and AMF.Factories.Factory;
type DI_Factory_Access is access all DI_Factory'Class;
for DI_Factory_Access'Storage_Size use 0;
end AMF.Factories.DI_Factories;
|
BrickBot/Bound-T-H8-300 | Ada | 4,803 | ads | -- Calculator.Slim (decl)
--
-- Data-flow analysis of acyclic regions in slimmed flow-graphs.
--
-- A component of the Bound-T Worst-Case Execution Time Tool.
--
-------------------------------------------------------------------------------
-- Copyright (c) 1999 .. 2015 Tidorum Ltd
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice, this
-- list of conditions and the following disclaimer.
-- 2. Redistributions in binary form must reproduce the above copyright notice,
-- this list of conditions and the following disclaimer in the documentation
-- and/or other materials provided with the distribution.
--
-- This software is provided by the copyright holders and contributors "as is" and
-- any express or implied warranties, including, but not limited to, the implied
-- warranties of merchantability and fitness for a particular purpose are
-- disclaimed. In no event shall the copyright owner or contributors be liable for
-- any direct, indirect, incidental, special, exemplary, or consequential damages
-- (including, but not limited to, procurement of substitute goods or services;
-- loss of use, data, or profits; or business interruption) however caused and
-- on any theory of liability, whether in contract, strict liability, or tort
-- (including negligence or otherwise) arising in any way out of the use of this
-- software, even if advised of the possibility of such damage.
--
-- Other modules (files) of this software composition should contain their
-- own copyright statements, which may have different copyright and usage
-- conditions. The above conditions apply to this file.
-------------------------------------------------------------------------------
--
-- $Revision: 1.8 $
-- $Date: 2015/10/24 19:36:47 $
--
-- $Log: calculator-slim.ads,v $
-- Revision 1.8 2015/10/24 19:36:47 niklas
-- Moved to free licence.
--
-- Revision 1.7 2009-10-07 19:26:10 niklas
-- BT-CH-0183: Cell-sets are a tagged-type class.
--
-- Revision 1.6 2005/02/16 21:11:41 niklas
-- BT-CH-0002.
--
-- Revision 1.5 2004/05/02 05:34:27 niklas
-- First Tidorum version.
-- Taking Cell_T stuff from Storage, not from Arithmetic.
-- Using the new function Calculator.Formulas.Adapted to match bases.
--
-- Revision 1.4 2001/01/07 22:06:06 holsti
-- Parameters for live-cell analysis added.
--
-- Revision 1.3 2000/12/29 14:40:16 holsti
-- Symbolic-constant usage deleted (part of NC_078).
--
-- Revision 1.2 2000/08/17 13:01:47 holsti
-- Changed cell-lists to cell-sets.
--
-- Revision 1.1 2000/07/14 20:34:12 holsti
-- First version.
--
with Flow.Slim;
package Calculator.Slim is
function Flux_Of_Region (
Within : Flow.Slim.Graph_T;
Nodes : Flow.Slim.Node_List_T;
Edges : Flow.Slim.Edge_List_T;
Final : Flow.Slim.Edge_List_T;
Var : Cell_Set_T;
Calc : Calc_Handle_T)
return Flux_List_T;
--
-- Using :
-- a set of nodes and edges forming an acyclic region within
-- a slimmed flow-graph,
-- a set of "final" edges from nodes in the region,
-- a set of cells to be treated as variables,
-- a calculator handle
-- Giving:
-- for each "final" edge, the flux from the region's root
-- nodes to the edge (including edge success predicates));
--
-- The region is usually determined entirely by the Edges and then
-- contains all the nodes that are the source or target of some
-- edge in Edges.
--
-- The Nodes parameter can usually be empty. In general, it can
-- contain any subset of the nodes in the region. It can contain
-- nodes that are not connected to the Edges, although this would
-- be abnormal and probably not useful for Bound-T.
--
-- However, if the region contains exactly one node, then it cannot
-- be defined by edges (because there are no internal Edges) and so
-- the single node must be given in Nodes and Edges is empty.
--
-- The set of Final edges is usually disjoint from the set of Edges
-- that define the region, but they can overlap, too.
--
-- Note that the data-flow computation for a given node in the region
-- considers only incoming edges from the Edges set and outgoing
-- edges from the Edges and Final sets. Other edges connected to this
-- node may exist in the flow-graph that contains the region, but are
-- not included in the computation. Thus, the body of a loop can be
-- considered an acyclic region by leaving out the repeat edges from
-- the Edges set and if any inner loops are already fused into single
-- fusion nodes.
end Calculator.Slim;
|
io7m/coreland-vector-ada | Ada | 497 | ads | generic package vector.sub is
-- sub, in place
procedure f
(a : in out vector_f_t;
b : in vector_f_t);
pragma inline (f);
procedure d
(a : in out vector_d_t;
b : in vector_d_t);
pragma inline (d);
-- sub, external storage
procedure f_ext
(a : in vector_f_t;
b : in vector_f_t;
x : out vector_f_t);
pragma inline (f_ext);
procedure d_ext
(a : in vector_d_t;
b : in vector_d_t;
x : out vector_d_t);
pragma inline (d_ext);
end vector.sub;
|
PeterYHChen/nyu-pl-assignments | Ada | 1,980 | adb | with adaptive_quad;
with Text_Io; -- always need these two lines for printing
use Text_Io;
with Ada.Float_Text_IO;
use Ada.Float_Text_IO;
with Ada.Numerics.Generic_Elementary_Functions;
procedure AQMain is
package FloatFunctions is new Ada.Numerics.Generic_Elementary_Functions(Float);
use FloatFunctions;
Epsilon:float := 0.000001;
function MyF(x:float) return float is
begin -- MyF
return Sin(x*x);
end MyF;
package MyAdaptiveQuad is new Adaptive_Quad(MyF);
use MyAdaptiveQuad;
task type ReadPairs is
entry Go(index:integer);
end ReadPairs;
task type ComputeArea is
entry Go(x, y:float; index:integer);
end ComputeArea;
task type PrintResults is
entry Print(x, y, z:float);
end PrintResults;
ReadPairsTask : array(1..5) of ReadPairs;
ComputeAreaTask : array(1..5) of ComputeArea;
PrintResultsTask : array(1..5) of PrintResults;
task body ReadPairs is
a, b:float;
idx:integer;
begin
accept Go(index:integer) do
Get(a);
Get(b);
idx := index;
end Go;
ComputeAreaTask(idx).Go(a, b, idx);
end ReadPairs;
task body ComputeArea is
a, b:float;
result:float;
idx:integer;
begin
accept Go(x, y:float; index:integer) do
a := x;
b := y;
idx := index;
end Go;
result := aquad(a, b, epsilon);
PrintResultsTask(idx).Print(a, b, result);
end ComputeArea;
task body PrintResults is
a, b:float;
result:float;
begin
accept Print(x, y, z:float) do
a := x;
b := y;
result := z;
end Print;
Put("The area under sin(x^2) for x = "); Put(a); Put(" to "); Put(b); Put(" is "); Put(result); New_Line;
end PrintResults;
begin -- AQMain
for i in 1..5 loop
ReadPairsTask(i).Go(i);
end loop;
end AQMain; |
faelys/ada-syslog | Ada | 4,749 | ads | ------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Syslog package is the main entry point for the library. It defines --
-- useful types, export logging procedures, and holds the common state used --
-- to craft messages (send procedure, hostname, appname, etc). --
-- Note that the common state is not thread-safe: the expected usage is to --
-- set it up before anything has a chance to call a Log procedure. --
-- However, since Transporter type is atomic, it should be safe to change --
-- it concurrently with Log calls. --
------------------------------------------------------------------------------
package Syslog is
-- Support Types --
package Facilities is
type Code is
(Kernel,
User_Level,
Mail,
Daemon,
Authorization_4,
Syslog_Internal,
Line_Printer,
News,
UUCP,
Clock_9,
Authorization_10,
FTP,
NTP,
Log_Audit,
Log_Alert,
Clock_15,
Local_0,
Local_1,
Local_2,
Local_3,
Local_4,
Local_5,
Local_6,
Local_7);
end Facilities;
package Severities is
type Code is
(Emergency,
Alert,
Critical,
Error,
Warning,
Notice,
Informational,
Debug);
end Severities;
type Priority is range 0 .. 191;
function To_Priority
(Facility : Facilities.Code;
Severity : Severities.Code)
return Priority;
package Formats is
type Format is (RFC_3164, RFC_5424);
end Formats;
type Transporter is private;
-- Write To Syslog --
procedure Log
(Facility : in Facilities.Code;
Severity : in Severities.Code;
Message : in String);
procedure Log
(Severity : in Severities.Code;
Message : in String);
procedure Log
(Facility : in Facilities.Code;
Message : in String);
procedure Log
(Pri : in Priority;
Message : in String);
procedure Log
(Message : in String);
-- Setup Writing --
procedure Set_App_Name (App_Name : in String);
procedure Set_Default_Facility (Facility : in Facilities.Code);
procedure Set_Default_Severity (Severity : in Severities.Code);
procedure Set_Format (Format : in Formats.Format);
procedure Set_Hostname (Hostname : in String);
procedure Set_Proc_ID (Proc_ID : in String);
procedure Set_Transport (Send : in Transporter);
private
-- Helper Subprograms --
procedure Append
(Output : in out String;
Last : in out Natural;
Data : in String);
function Check_Nil (Raw_Value : in String) return String;
type Transporter is access procedure (Packet : in String);
pragma Atomic (Transporter);
type Bounded_String (Max_Length : Natural) is record
Data : String (1 .. Max_Length);
Length : Natural := 0;
end record;
procedure Set (Str : out Bounded_String; Value : in String);
function Get (Str : Bounded_String) return String;
type Context_Record is record
Hostname : Bounded_String (255);
App_Name : Bounded_String (48);
Proc_ID : Bounded_String (128);
Default_Facility : Facilities.Code := Facilities.Daemon;
Default_Severity : Severities.Code := Severities.Emergency;
Format : Formats.Format;
Transport : Transporter := null;
end record;
Context : Context_Record;
end Syslog;
|
stcarrez/bbox-ada-api | Ada | 7,636 | adb | -----------------------------------------------------------------------
-- druss-commands-devices -- Print information about the devices
-- Copyright (C) 2017, 2018, 2019, 2021, 2023 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Properties;
with Util.Log.Loggers;
with Bbox.API;
with Druss.Gateways;
with Ada.Strings.Unbounded;
package body Druss.Commands.Ping is
use Ada.Strings.Unbounded;
-- The logger
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Druss.Commands.Ping");
-- ------------------------------
-- Execute the wifi 'status' command to print the Wifi current status.
-- ------------------------------
procedure Do_Ping (Command : in Command_Type;
Args : in Argument_List'Class;
Selector : in Device_Selector_Type;
Context : in out Context_Type) is
pragma Unreferenced (Command, Args);
procedure Do_Ping (Gateway : in out Druss.Gateways.Gateway_Type);
procedure Box_Status (Gateway : in out Druss.Gateways.Gateway_Type);
Console : constant Druss.Commands.Consoles.Console_Access := Context.Console;
procedure Do_Ping (Gateway : in out Druss.Gateways.Gateway_Type) is
procedure Ping_Device (Manager : in Util.Properties.Manager;
Name : in String);
Box : Bbox.API.Client_Type;
procedure Ping_Device (Manager : in Util.Properties.Manager;
Name : in String) is
Id : constant String := Manager.Get (Name & ".id", "");
begin
case Selector is
when DEVICE_ALL =>
null;
when DEVICE_ACTIVE =>
if Manager.Get (Name & ".active", "") = "0" then
return;
end if;
when DEVICE_INACTIVE =>
if Manager.Get (Name & ".active", "") = "1" then
return;
end if;
end case;
Log.Info ("Ping command on {0}", Manager.Get (Name & ".ipaddress", ""));
Box.Post ("hosts/" & Id, "action=ping");
end Ping_Device;
begin
if Ada.Strings.Unbounded.Length (Gateway.Passwd) = 0 then
return;
end if;
Gateway.Refresh;
Box.Set_Server (To_String (Gateway.Ip));
Box.Login (To_String (Gateway.Passwd));
Bbox.API.Iterate (Gateway.Hosts, "hosts.list", Ping_Device'Access);
end Do_Ping;
procedure Box_Status (Gateway : in out Druss.Gateways.Gateway_Type) is
procedure Print_Device (Manager : in Util.Properties.Manager;
Name : in String);
procedure Print_Device (Manager : in Util.Properties.Manager;
Name : in String) is
Link : constant String := Manager.Get (Name & ".link", "");
begin
if Manager.Get (Name & ".active", "") = "0" then
return;
end if;
Console.Start_Row;
Console.Print_Field (F_BBOX_IP_ADDR, To_String (Gateway.Ip));
Console.Print_Field (F_IP_ADDR, Manager.Get (Name & ".ipaddress", ""));
Console.Print_Field (F_HOSTNAME, Manager.Get (Name & ".hostname", ""));
Print_Perf (Console, F_ACTIVE, Manager.Get (Name & ".ping.average", ""));
if Link = "Ethernet" then
Console.Print_Field (F_LINK, Link & " port "
& Manager.Get (Name & ".ethernet.logicalport", ""));
else
Console.Print_Field (F_LINK, Link & " RSSI "
& Manager.Get (Name & ".wireless.rssi0", ""));
end if;
Console.End_Row;
end Print_Device;
begin
Gateway.Refresh;
Bbox.API.Iterate (Gateway.Hosts, "hosts.list", Print_Device'Access);
end Box_Status;
begin
Druss.Gateways.Iterate (Context.Gateways, Gateways.ITER_ENABLE, Do_Ping'Access);
delay 5.0;
Console.Start_Title;
Console.Print_Title (F_BBOX_IP_ADDR, "Bbox IP", 16);
Console.Print_Title (F_IP_ADDR, "Device IP", 16);
Console.Print_Title (F_HOSTNAME, "Hostname", 28);
Console.Print_Title (F_ACTIVE, "Ping", 15);
Console.Print_Title (F_LINK, "Link", 18);
Console.End_Title;
Druss.Gateways.Iterate (Context.Gateways, Gateways.ITER_ENABLE, Box_Status'Access);
end Do_Ping;
-- ------------------------------
-- Execute a ping from the gateway to each device.
-- ------------------------------
overriding
procedure Execute (Command : in out Command_Type;
Name : in String;
Args : in Argument_List'Class;
Context : in out Context_Type) is
pragma Unreferenced (Name);
begin
if Args.Get_Count > 1 then
Context.Console.Notice (N_USAGE, "Too many arguments to the command");
Druss.Commands.Driver.Usage (Args, Context);
elsif Args.Get_Count = 0 then
Command.Do_Ping (Args, DEVICE_ALL, Context);
elsif Args.Get_Argument (1) = "all" then
Command.Do_Ping (Args, DEVICE_ALL, Context);
elsif Args.Get_Argument (1) = "active" then
Command.Do_Ping (Args, DEVICE_ACTIVE, Context);
elsif Args.Get_Argument (1) = "inactive" then
Command.Do_Ping (Args, DEVICE_INACTIVE, Context);
else
Context.Console.Notice (N_USAGE, "Invalid argument: " & Args.Get_Argument (1));
Druss.Commands.Driver.Usage (Args, Context);
end if;
end Execute;
-- ------------------------------
-- Write the help associated with the command.
-- ------------------------------
overriding
procedure Help (Command : in out Command_Type;
Name : in String;
Context : in out Context_Type) is
pragma Unreferenced (Command);
Console : constant Druss.Commands.Consoles.Console_Access := Context.Console;
begin
Console.Notice (N_HELP, "ping: Ask the Bbox to ping the devices");
Console.Notice (N_HELP, "Usage: ping [all | active | inactive]");
Console.Notice (N_HELP, "");
Console.Notice (N_HELP, " Ask the Bbox to ping the devices. By default it will ping");
Console.Notice (N_HELP, " all the devices that have been discovered by the Bbox.");
Console.Notice (N_HELP, " The command will wait 5 seconds and it will list the active");
Console.Notice (N_HELP, " devices with their ping performance.");
Console.Notice (N_HELP, "");
Console.Notice (N_HELP, " all Ping all the devices");
Console.Notice (N_HELP, " active Ping the active devices only");
Console.Notice (N_HELP, " inative Ping the inactive devices only");
end Help;
end Druss.Commands.Ping;
|
charlie5/cBound | Ada | 1,348 | ads | -- This file is generated by SWIG. Please do not modify by hand.
--
with Interfaces.C;
with Interfaces.C;
with Interfaces.C.Pointers;
package xcb.xcb_glx_gen_lists_cookie_t is
-- Item
--
type Item is record
sequence : aliased Interfaces.C.unsigned;
end record;
-- Item_Array
--
type Item_Array is
array
(Interfaces.C.size_t range <>) of aliased xcb.xcb_glx_gen_lists_cookie_t
.Item;
-- Pointer
--
package C_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_gen_lists_cookie_t.Item,
Element_Array => xcb.xcb_glx_gen_lists_cookie_t.Item_Array,
Default_Terminator => (others => <>));
subtype Pointer is C_Pointers.Pointer;
-- Pointer_Array
--
type Pointer_Array is
array
(Interfaces.C.size_t range <>) of aliased xcb.xcb_glx_gen_lists_cookie_t
.Pointer;
-- Pointer_Pointer
--
package C_Pointer_Pointers is new Interfaces.C.Pointers
(Index => Interfaces.C.size_t,
Element => xcb.xcb_glx_gen_lists_cookie_t.Pointer,
Element_Array => xcb.xcb_glx_gen_lists_cookie_t.Pointer_Array,
Default_Terminator => null);
subtype Pointer_Pointer is C_Pointer_Pointers.Pointer;
end xcb.xcb_glx_gen_lists_cookie_t;
|
pmarshwx/SHARPpy | Ada | 3,216 | ads | %TITLE%
RUC 010507/0000F000 ads
LEVEL HGHT TEMP DWPT WDIR WSPD
-------------------------------------------------------------------
%RAW%
991.75, 158.79, 26.61, 22.35, 164.08, 8.53
975.00, 309.81, 25.49, 20.91, 165.43, 12.62
950.00, 538.20, 23.78, 18.97, 168.45, 17.43
925.00, 771.20, 21.79, 17.56, 178.42, 18.51
900.00, 1008.89, 19.96, 15.94, 195.98, 18.10
875.00, 1251.44, 18.13, 13.83, 212.56, 17.74
850.00, 1499.58, 16.63, 8.81, 222.94, 18.37
825.00, 1753.28, 15.29, 2.35, 230.21, 19.49
800.00, 2013.28, 13.35, 0.37, 235.84, 20.20
775.00, 2279.13, 11.71, -7.51, 239.46, 19.64
750.00, 2551.82, 9.20, -8.87, 244.10, 19.01
725.00, 2831.37, 7.08, -8.03, 252.75, 19.96
700.00, 3118.97, 5.10, -9.16, 258.32, 20.69
675.00, 3414.87, 2.93, -11.45, 262.14, 21.58
650.00, 3718.57, 0.79, -14.69, 264.65, 22.67
625.00, 4031.71, -1.28, -18.82, 265.59, 23.55
600.00, 4356.07, -3.37, -22.64, 263.54, 24.61
575.00, 4690.66, -5.61, -25.40, 259.82, 26.43
550.00, 5037.26, -8.17, -26.90, 255.42, 28.56
525.00, 5396.26, -10.97, -27.95, 251.38, 31.03
500.00, 5768.71, -13.74, -30.05, 247.76, 34.17
475.00, 6156.17, -16.26, -35.04, 244.28, 37.81
450.00, 6560.67, -19.13, -40.46, 243.32, 42.55
425.00, 6983.12, -22.26, -43.30, 243.42, 46.13
400.00, 7425.12, -25.40, -41.51, 243.91, 49.54
375.00, 7891.02, -28.87, -43.30, 244.60, 53.03
350.00, 8379.71, -32.61, -45.68, 245.24, 56.78
325.00, 8898.31, -36.04, -46.14, 245.51, 61.53
300.00, 9449.91, -39.28, -47.05, 245.58, 66.99
275.00, 10041.15, -42.66, -51.97, 244.69, 76.03
250.00, 10678.75, -46.61, -55.24, 247.44, 78.58
225.00, 11371.10, -50.85, -59.44, 253.60, 67.31
200.00, 12131.35, -54.79, -63.81, 252.71, 58.83
175.00, 12978.15, -57.75, -68.75, 248.16, 56.59
150.00, 13949.36, -58.31, -69.22, 244.20, 50.52
125.00, 15105.81, -61.13, -71.56, 245.24, 39.69
100.00, 16459.81, -66.59, -76.99, 251.27, 27.16
75.00, 18205.42, -58.31, -69.22, 244.20, 50.52
50.00, 20665.71, -58.31, -69.22, 244.20, 50.52
%END%
----- Parcel Information-----
*** 50mb MIXED LAYER PARCEL ***
LPL: P=992 T=81F Td=67F
CAPE: 2818 J/kg
CINH: -33 J/kg
LI: -10 C
LI(300mb): -8 C
3km Cape: 163 J/kg
NCAPE: 0.27 m/s2
LCL: 886mb 988m
LFC: 850mb 1341m
EL: 200mb 11973m
MPL: 118mb 15297m
All heights AGL
----- Moisture -----
Precip Water: 1.13 in
Mean W: 14.4 g/Kg
----- Lapse Rates -----
700-500mb 19 C 7.2 C/km
850-500mb 32 C 7.4 C/km
|
reznikmm/matreshka | Ada | 8,081 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This file is generated, don't edit it.
------------------------------------------------------------------------------
with AMF.CMOF.Associations;
with AMF.CMOF.Classes;
with AMF.CMOF.Comments;
with AMF.CMOF.Constraints;
with AMF.CMOF.Data_Types;
with AMF.CMOF.Element_Imports;
with AMF.CMOF.Enumeration_Literals;
with AMF.CMOF.Enumerations;
with AMF.CMOF.Expressions;
with AMF.CMOF.Opaque_Expressions;
with AMF.CMOF.Operations;
with AMF.CMOF.Package_Imports;
with AMF.CMOF.Package_Merges;
with AMF.CMOF.Packages;
with AMF.CMOF.Parameters;
with AMF.CMOF.Primitive_Types;
with AMF.CMOF.Properties;
with AMF.CMOF.Tags;
with AMF.Factories.CMOF_Factories;
with AMF.Links;
with League.Holders;
package AMF.Internals.Factories.CMOF_Factories is
type CMOF_Factory is
limited new AMF.Internals.Factories.Metamodel_Factory_Base
and AMF.Factories.CMOF_Factories.CMOF_Factory with null record;
overriding function Convert_To_String
(Self : not null access CMOF_Factory;
Data_Type : not null access AMF.CMOF.Data_Types.CMOF_Data_Type'Class;
Value : League.Holders.Holder) return League.Strings.Universal_String;
overriding function Create
(Self : not null access CMOF_Factory;
Meta_Class : not null access AMF.CMOF.Classes.CMOF_Class'Class)
return not null AMF.Elements.Element_Access;
overriding function Create_From_String
(Self : not null access CMOF_Factory;
Data_Type : not null access AMF.CMOF.Data_Types.CMOF_Data_Type'Class;
Image : League.Strings.Universal_String) return League.Holders.Holder;
overriding function Create_Link
(Self : not null access CMOF_Factory;
Association :
not null access AMF.CMOF.Associations.CMOF_Association'Class;
First_Element : not null AMF.Elements.Element_Access;
Second_Element : not null AMF.Elements.Element_Access)
return not null AMF.Links.Link_Access;
overriding function Get_Package
(Self : not null access constant CMOF_Factory)
return AMF.CMOF.Packages.Collections.Set_Of_CMOF_Package;
function Constructor
(Extent : AMF.Internals.AMF_Extent)
return not null AMF.Factories.Factory_Access;
function Get_Package return not null AMF.CMOF.Packages.CMOF_Package_Access;
function Create_Association
(Self : not null access CMOF_Factory)
return AMF.CMOF.Associations.CMOF_Association_Access;
function Create_Class
(Self : not null access CMOF_Factory)
return AMF.CMOF.Classes.CMOF_Class_Access;
function Create_Comment
(Self : not null access CMOF_Factory)
return AMF.CMOF.Comments.CMOF_Comment_Access;
function Create_Constraint
(Self : not null access CMOF_Factory)
return AMF.CMOF.Constraints.CMOF_Constraint_Access;
function Create_Data_Type
(Self : not null access CMOF_Factory)
return AMF.CMOF.Data_Types.CMOF_Data_Type_Access;
function Create_Element_Import
(Self : not null access CMOF_Factory)
return AMF.CMOF.Element_Imports.CMOF_Element_Import_Access;
function Create_Enumeration
(Self : not null access CMOF_Factory)
return AMF.CMOF.Enumerations.CMOF_Enumeration_Access;
function Create_Enumeration_Literal
(Self : not null access CMOF_Factory)
return AMF.CMOF.Enumeration_Literals.CMOF_Enumeration_Literal_Access;
function Create_Expression
(Self : not null access CMOF_Factory)
return AMF.CMOF.Expressions.CMOF_Expression_Access;
function Create_Opaque_Expression
(Self : not null access CMOF_Factory)
return AMF.CMOF.Opaque_Expressions.CMOF_Opaque_Expression_Access;
function Create_Operation
(Self : not null access CMOF_Factory)
return AMF.CMOF.Operations.CMOF_Operation_Access;
function Create_Package
(Self : not null access CMOF_Factory)
return AMF.CMOF.Packages.CMOF_Package_Access;
function Create_Package_Import
(Self : not null access CMOF_Factory)
return AMF.CMOF.Package_Imports.CMOF_Package_Import_Access;
function Create_Package_Merge
(Self : not null access CMOF_Factory)
return AMF.CMOF.Package_Merges.CMOF_Package_Merge_Access;
function Create_Parameter
(Self : not null access CMOF_Factory)
return AMF.CMOF.Parameters.CMOF_Parameter_Access;
function Create_Primitive_Type
(Self : not null access CMOF_Factory)
return AMF.CMOF.Primitive_Types.CMOF_Primitive_Type_Access;
function Create_Property
(Self : not null access CMOF_Factory)
return AMF.CMOF.Properties.CMOF_Property_Access;
function Create_Tag
(Self : not null access CMOF_Factory)
return AMF.CMOF.Tags.CMOF_Tag_Access;
end AMF.Internals.Factories.CMOF_Factories;
|
reznikmm/matreshka | Ada | 3,695 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Attributes.Table.Number_Columns_Spanned is
type ODF_Table_Number_Columns_Spanned is
new XML.DOM.Attributes.DOM_Attribute with private;
private
type ODF_Table_Number_Columns_Spanned is
new XML.DOM.Attributes.DOM_Attribute with null record;
end ODF.DOM.Attributes.Table.Number_Columns_Spanned;
|
zhmu/ananas | Ada | 6,246 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . P A C K _ 3 7 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with System.Storage_Elements;
with System.Unsigned_Types;
package body System.Pack_37 is
subtype Bit_Order is System.Bit_Order;
Reverse_Bit_Order : constant Bit_Order :=
Bit_Order'Val (1 - Bit_Order'Pos (System.Default_Bit_Order));
subtype Ofs is System.Storage_Elements.Storage_Offset;
subtype Uns is System.Unsigned_Types.Unsigned;
subtype N07 is System.Unsigned_Types.Unsigned range 0 .. 7;
use type System.Storage_Elements.Storage_Offset;
use type System.Unsigned_Types.Unsigned;
type Cluster is record
E0, E1, E2, E3, E4, E5, E6, E7 : Bits_37;
end record;
for Cluster use record
E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1;
E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1;
E5 at 0 range 5 * Bits .. 5 * Bits + Bits - 1;
E6 at 0 range 6 * Bits .. 6 * Bits + Bits - 1;
E7 at 0 range 7 * Bits .. 7 * Bits + Bits - 1;
end record;
for Cluster'Size use Bits * 8;
for Cluster'Alignment use Integer'Min (Standard'Maximum_Alignment,
1 +
1 * Boolean'Pos (Bits mod 2 = 0) +
2 * Boolean'Pos (Bits mod 4 = 0));
-- Use maximum possible alignment, given the bit field size, since this
-- will result in the most efficient code possible for the field.
type Cluster_Ref is access Cluster;
type Rev_Cluster is new Cluster
with Bit_Order => Reverse_Bit_Order,
Scalar_Storage_Order => Reverse_Bit_Order;
type Rev_Cluster_Ref is access Rev_Cluster;
------------
-- Get_37 --
------------
function Get_37
(Arr : System.Address;
N : Natural;
Rev_SSO : Boolean) return Bits_37
is
A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
C : Cluster_Ref with Address => A'Address, Import;
RC : Rev_Cluster_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => return RC.E0;
when 1 => return RC.E1;
when 2 => return RC.E2;
when 3 => return RC.E3;
when 4 => return RC.E4;
when 5 => return RC.E5;
when 6 => return RC.E6;
when 7 => return RC.E7;
end case;
else
case N07 (Uns (N) mod 8) is
when 0 => return C.E0;
when 1 => return C.E1;
when 2 => return C.E2;
when 3 => return C.E3;
when 4 => return C.E4;
when 5 => return C.E5;
when 6 => return C.E6;
when 7 => return C.E7;
end case;
end if;
end Get_37;
------------
-- Set_37 --
------------
procedure Set_37
(Arr : System.Address;
N : Natural;
E : Bits_37;
Rev_SSO : Boolean)
is
A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
C : Cluster_Ref with Address => A'Address, Import;
RC : Rev_Cluster_Ref with Address => A'Address, Import;
begin
if Rev_SSO then
case N07 (Uns (N) mod 8) is
when 0 => RC.E0 := E;
when 1 => RC.E1 := E;
when 2 => RC.E2 := E;
when 3 => RC.E3 := E;
when 4 => RC.E4 := E;
when 5 => RC.E5 := E;
when 6 => RC.E6 := E;
when 7 => RC.E7 := E;
end case;
else
case N07 (Uns (N) mod 8) is
when 0 => C.E0 := E;
when 1 => C.E1 := E;
when 2 => C.E2 := E;
when 3 => C.E3 := E;
when 4 => C.E4 := E;
when 5 => C.E5 := E;
when 6 => C.E6 := E;
when 7 => C.E7 := E;
end case;
end if;
end Set_37;
end System.Pack_37;
|
reznikmm/matreshka | Ada | 19,247 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with AMF.Internals.UML_Named_Elements;
with AMF.UML.Activities;
with AMF.UML.Activity_Edges.Collections;
with AMF.UML.Activity_Groups.Collections;
with AMF.UML.Activity_Nodes.Collections;
with AMF.UML.Activity_Partitions.Collections;
with AMF.UML.Associations;
with AMF.UML.Classifiers.Collections;
with AMF.UML.Constraints.Collections;
with AMF.UML.Dependencies.Collections;
with AMF.UML.Exception_Handlers.Collections;
with AMF.UML.Input_Pins.Collections;
with AMF.UML.Interruptible_Activity_Regions.Collections;
with AMF.UML.Link_End_Datas.Collections;
with AMF.UML.Named_Elements;
with AMF.UML.Namespaces;
with AMF.UML.Output_Pins.Collections;
with AMF.UML.Packages.Collections;
with AMF.UML.Read_Link_Actions;
with AMF.UML.Redefinable_Elements.Collections;
with AMF.UML.String_Expressions;
with AMF.UML.Structured_Activity_Nodes;
with AMF.Visitors;
package AMF.Internals.UML_Read_Link_Actions is
type UML_Read_Link_Action_Proxy is
limited new AMF.Internals.UML_Named_Elements.UML_Named_Element_Proxy
and AMF.UML.Read_Link_Actions.UML_Read_Link_Action with null record;
overriding function Get_Result
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Output_Pins.UML_Output_Pin_Access;
-- Getter of ReadLinkAction::result.
--
-- The pin on which are put the objects participating in the association
-- at the end not specified by the inputs.
overriding procedure Set_Result
(Self : not null access UML_Read_Link_Action_Proxy;
To : AMF.UML.Output_Pins.UML_Output_Pin_Access);
-- Setter of ReadLinkAction::result.
--
-- The pin on which are put the objects participating in the association
-- at the end not specified by the inputs.
overriding function Get_End_Data
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Link_End_Datas.Collections.Set_Of_UML_Link_End_Data;
-- Getter of LinkAction::endData.
--
-- Data identifying one end of a link by the objects on its ends and
-- qualifiers.
overriding function Get_Input_Value
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Input_Pins.Collections.Set_Of_UML_Input_Pin;
-- Getter of LinkAction::inputValue.
--
-- Pins taking end objects and qualifier values as input.
overriding function Get_Context
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Classifiers.UML_Classifier_Access;
-- Getter of Action::context.
--
-- The classifier that owns the behavior of which this action is a part.
overriding function Get_Input
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Input_Pins.Collections.Ordered_Set_Of_UML_Input_Pin;
-- Getter of Action::input.
--
-- The ordered set of input pins connected to the Action. These are among
-- the total set of inputs.
overriding function Get_Is_Locally_Reentrant
(Self : not null access constant UML_Read_Link_Action_Proxy)
return Boolean;
-- Getter of Action::isLocallyReentrant.
--
-- If true, the action can begin a new, concurrent execution, even if
-- there is already another execution of the action ongoing. If false, the
-- action cannot begin a new execution until any previous execution has
-- completed.
overriding procedure Set_Is_Locally_Reentrant
(Self : not null access UML_Read_Link_Action_Proxy;
To : Boolean);
-- Setter of Action::isLocallyReentrant.
--
-- If true, the action can begin a new, concurrent execution, even if
-- there is already another execution of the action ongoing. If false, the
-- action cannot begin a new execution until any previous execution has
-- completed.
overriding function Get_Local_Postcondition
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Constraints.Collections.Set_Of_UML_Constraint;
-- Getter of Action::localPostcondition.
--
-- Constraint that must be satisfied when executed is completed.
overriding function Get_Local_Precondition
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Constraints.Collections.Set_Of_UML_Constraint;
-- Getter of Action::localPrecondition.
--
-- Constraint that must be satisfied when execution is started.
overriding function Get_Output
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Output_Pins.Collections.Ordered_Set_Of_UML_Output_Pin;
-- Getter of Action::output.
--
-- The ordered set of output pins connected to the Action. The action
-- places its results onto pins in this set.
overriding function Get_Handler
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Exception_Handlers.Collections.Set_Of_UML_Exception_Handler;
-- Getter of ExecutableNode::handler.
--
-- A set of exception handlers that are examined if an uncaught exception
-- propagates to the outer level of the executable node.
overriding function Get_Activity
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Activities.UML_Activity_Access;
-- Getter of ActivityNode::activity.
--
-- Activity containing the node.
overriding procedure Set_Activity
(Self : not null access UML_Read_Link_Action_Proxy;
To : AMF.UML.Activities.UML_Activity_Access);
-- Setter of ActivityNode::activity.
--
-- Activity containing the node.
overriding function Get_In_Group
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Activity_Groups.Collections.Set_Of_UML_Activity_Group;
-- Getter of ActivityNode::inGroup.
--
-- Groups containing the node.
overriding function Get_In_Interruptible_Region
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Interruptible_Activity_Regions.Collections.Set_Of_UML_Interruptible_Activity_Region;
-- Getter of ActivityNode::inInterruptibleRegion.
--
-- Interruptible regions containing the node.
overriding function Get_In_Partition
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Activity_Partitions.Collections.Set_Of_UML_Activity_Partition;
-- Getter of ActivityNode::inPartition.
--
-- Partitions containing the node.
overriding function Get_In_Structured_Node
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Structured_Activity_Nodes.UML_Structured_Activity_Node_Access;
-- Getter of ActivityNode::inStructuredNode.
--
-- Structured activity node containing the node.
overriding procedure Set_In_Structured_Node
(Self : not null access UML_Read_Link_Action_Proxy;
To : AMF.UML.Structured_Activity_Nodes.UML_Structured_Activity_Node_Access);
-- Setter of ActivityNode::inStructuredNode.
--
-- Structured activity node containing the node.
overriding function Get_Incoming
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Activity_Edges.Collections.Set_Of_UML_Activity_Edge;
-- Getter of ActivityNode::incoming.
--
-- Edges that have the node as target.
overriding function Get_Outgoing
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Activity_Edges.Collections.Set_Of_UML_Activity_Edge;
-- Getter of ActivityNode::outgoing.
--
-- Edges that have the node as source.
overriding function Get_Redefined_Node
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Activity_Nodes.Collections.Set_Of_UML_Activity_Node;
-- Getter of ActivityNode::redefinedNode.
--
-- Inherited nodes replaced by this node in a specialization of the
-- activity.
overriding function Get_Is_Leaf
(Self : not null access constant UML_Read_Link_Action_Proxy)
return Boolean;
-- Getter of RedefinableElement::isLeaf.
--
-- Indicates whether it is possible to further redefine a
-- RedefinableElement. If the value is true, then it is not possible to
-- further redefine the RedefinableElement. Note that this property is
-- preserved through package merge operations; that is, the capability to
-- redefine a RedefinableElement (i.e., isLeaf=false) must be preserved in
-- the resulting RedefinableElement of a package merge operation where a
-- RedefinableElement with isLeaf=false is merged with a matching
-- RedefinableElement with isLeaf=true: the resulting RedefinableElement
-- will have isLeaf=false. Default value is false.
overriding procedure Set_Is_Leaf
(Self : not null access UML_Read_Link_Action_Proxy;
To : Boolean);
-- Setter of RedefinableElement::isLeaf.
--
-- Indicates whether it is possible to further redefine a
-- RedefinableElement. If the value is true, then it is not possible to
-- further redefine the RedefinableElement. Note that this property is
-- preserved through package merge operations; that is, the capability to
-- redefine a RedefinableElement (i.e., isLeaf=false) must be preserved in
-- the resulting RedefinableElement of a package merge operation where a
-- RedefinableElement with isLeaf=false is merged with a matching
-- RedefinableElement with isLeaf=true: the resulting RedefinableElement
-- will have isLeaf=false. Default value is false.
overriding function Get_Redefined_Element
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Redefinable_Elements.Collections.Set_Of_UML_Redefinable_Element;
-- Getter of RedefinableElement::redefinedElement.
--
-- The redefinable element that is being redefined by this element.
overriding function Get_Redefinition_Context
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Classifiers.Collections.Set_Of_UML_Classifier;
-- Getter of RedefinableElement::redefinitionContext.
--
-- References the contexts that this element may be redefined from.
overriding function Get_Client_Dependency
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Dependencies.Collections.Set_Of_UML_Dependency;
-- Getter of NamedElement::clientDependency.
--
-- Indicates the dependencies that reference the client.
overriding function Get_Name_Expression
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.String_Expressions.UML_String_Expression_Access;
-- Getter of NamedElement::nameExpression.
--
-- The string expression used to define the name of this named element.
overriding procedure Set_Name_Expression
(Self : not null access UML_Read_Link_Action_Proxy;
To : AMF.UML.String_Expressions.UML_String_Expression_Access);
-- Setter of NamedElement::nameExpression.
--
-- The string expression used to define the name of this named element.
overriding function Get_Namespace
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Namespaces.UML_Namespace_Access;
-- Getter of NamedElement::namespace.
--
-- Specifies the namespace that owns the NamedElement.
overriding function Get_Qualified_Name
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.Optional_String;
-- Getter of NamedElement::qualifiedName.
--
-- A name which allows the NamedElement to be identified within a
-- hierarchy of nested Namespaces. It is constructed from the names of the
-- containing namespaces starting at the root of the hierarchy and ending
-- with the name of the NamedElement itself.
overriding function Association
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Associations.UML_Association_Access;
-- Operation LinkAction::association.
--
-- The association operates on LinkAction. It returns the association of
-- the action.
overriding function Context
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Classifiers.UML_Classifier_Access;
-- Operation Action::context.
--
-- Missing derivation for Action::/context : Classifier
overriding function Is_Consistent_With
(Self : not null access constant UML_Read_Link_Action_Proxy;
Redefinee : AMF.UML.Redefinable_Elements.UML_Redefinable_Element_Access)
return Boolean;
-- Operation RedefinableElement::isConsistentWith.
--
-- The query isConsistentWith() specifies, for any two RedefinableElements
-- in a context in which redefinition is possible, whether redefinition
-- would be logically consistent. By default, this is false; this
-- operation must be overridden for subclasses of RedefinableElement to
-- define the consistency conditions.
overriding function Is_Redefinition_Context_Valid
(Self : not null access constant UML_Read_Link_Action_Proxy;
Redefined : AMF.UML.Redefinable_Elements.UML_Redefinable_Element_Access)
return Boolean;
-- Operation RedefinableElement::isRedefinitionContextValid.
--
-- The query isRedefinitionContextValid() specifies whether the
-- redefinition contexts of this RedefinableElement are properly related
-- to the redefinition contexts of the specified RedefinableElement to
-- allow this element to redefine the other. By default at least one of
-- the redefinition contexts of this element must be a specialization of
-- at least one of the redefinition contexts of the specified element.
overriding function All_Owning_Packages
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Packages.Collections.Set_Of_UML_Package;
-- Operation NamedElement::allOwningPackages.
--
-- The query allOwningPackages() returns all the directly or indirectly
-- owning packages.
overriding function Is_Distinguishable_From
(Self : not null access constant UML_Read_Link_Action_Proxy;
N : AMF.UML.Named_Elements.UML_Named_Element_Access;
Ns : AMF.UML.Namespaces.UML_Namespace_Access)
return Boolean;
-- Operation NamedElement::isDistinguishableFrom.
--
-- The query isDistinguishableFrom() determines whether two NamedElements
-- may logically co-exist within a Namespace. By default, two named
-- elements are distinguishable if (a) they have unrelated types or (b)
-- they have related types but different names.
overriding function Namespace
(Self : not null access constant UML_Read_Link_Action_Proxy)
return AMF.UML.Namespaces.UML_Namespace_Access;
-- Operation NamedElement::namespace.
--
-- Missing derivation for NamedElement::/namespace : Namespace
overriding procedure Enter_Element
(Self : not null access constant UML_Read_Link_Action_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of visitor interface.
overriding procedure Leave_Element
(Self : not null access constant UML_Read_Link_Action_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of visitor interface.
overriding procedure Visit_Element
(Self : not null access constant UML_Read_Link_Action_Proxy;
Iterator : in out AMF.Visitors.Abstract_Iterator'Class;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of iterator interface.
end AMF.Internals.UML_Read_Link_Actions;
|
charlie5/lace | Ada | 1,228 | ads | with
openGL.Program.lit.textured_skinned;
package openGL.Geometry.lit_textured_skinned
--
-- Supports per-vertex site, texture, lighting and skinning.
--
is
type Item is new openGL.Geometry.item with private;
function new_Geometry return access Geometry.lit_textured_skinned.item'Class;
procedure define_Program;
----------
-- Vertex
--
type Vertex is
record
Site : Vector_3;
Normal : Vector_3;
Coords : Coordinate_2D;
Shine : Real;
bone_Ids : Vector_4;
bone_Weights : Vector_4;
end record;
pragma Convention (C, Vertex);
type Vertex_array is array (long_Index_t range <>) of aliased Vertex;
--------------
-- Attributes
--
procedure Vertices_are (Self : in out Item; Now : in Vertex_array);
overriding
procedure Indices_are (Self : in out Item; Now : in Indices;
for_Facia : in Positive);
function Program return openGL.Program.lit.textured_skinned.view;
private
type Item is new Geometry.item with null record;
overriding
procedure enable_Texture (Self : in Item);
end openGL.Geometry.lit_textured_skinned;
|
gerr135/ada_composition | Ada | 7,106 | adb | with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
package Some_Interface is
type The_Interface is limited interface;
function f1(Self : The_Interface) return Integer is abstract;
function f2(Self : The_Interface) return Integer is abstract;
function f3(Self : The_Interface) return Integer is abstract;
generic
type Base is tagged limited private;
package Mixin is
type Derived is new Base and The_Interface with null record;
overriding function f1(Self : Derived) return Integer;
overriding function f2(Self : Derived) return Integer;
overriding function f3(Self : Derived) return Integer;
end Mixin;
end Some_Interface;
package body Some_Interface is
package body Mixin is
function f1(Self : Derived) return Integer is
begin
return 10;
end f1;
function f2(Self : Derived) return Integer is
begin
return 20;
end f2;
function f3(Self : Derived) return Integer is
begin
return Self.f1 + Self.f2;
end f3;
end Mixin;
end Some_Interface;
-- For examples using existing inheritance trees we need
-- a base type
type Third_Party_Base is tagged null record;
package Examples is
use Some_Interface;
type Example_1 is limited new The_Interface with private;
type Example_2 is new Third_Party_Base and The_Interface with private;
private
-----------------------------------------------
-- Packages
-----------------------------------------------
-- For situations where you have no regular base class,
-- this is needed for the Mixin contract
type Secret_Base is tagged limited null record;
package Example_1_Pkg is new Mixin(Base => Secret_Base);
-- For situations where you already have a base class, the
-- instantiation is simpler.
package Example_2_Pkg is new Mixin(Base => Third_Party_Base);
-- ****NOTE: You can chain multiple mixins to get defaults for
-- various interfaces. For Example:
-- package A_Pkg is new A_Mixin(Base => Some_Base);
-- package B_Pkg is new B_Mixin(Base => A_Pkg.Derived);
-- This will add both interfaces from A_Mixin and B_Mixin
-- to the base type.
-----------------------------------------------
-- Full Type Declarations
-----------------------------------------------
type Example_1 is limited new Example_1_Pkg.Derived with null record;
type Example_2 is new Example_2_Pkg.Derived with null record;
end Examples;
begin
Put_Line("Hello, world!");
end Hello;
-- *******************************************
--
-- However, note that the defaults follow the basic Ada rules. They don't
-- redispatch unless you specify that (For example in f3 you would do things
-- like The_Interface'Class(Self).f1 and so on). So you have to decide what
-- you want those defaults really do. Redispatch is fairly dangerous to do
-- in Ada since it is not the default for inherited programs. I would
-- caution against it unless you have a real need and know what you are doing.
-- And if you don't like the Mixin method, you can do something a bit closer to
-- composition and Rust's model (though Ada doesn't support traits, so
-- it has to be emulated by inheriting an interface instead):
--
-- *******************************************
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
package Some_Interface is
type The_Interface is limited interface;
function f1(Self : The_Interface) return Integer is abstract;
function f2(Self : The_Interface) return Integer is abstract;
function f3(Self : The_Interface) return Integer is abstract;
type The_Default is new The_Interface with null record;
overriding function f1(Self : The_Default) return Integer;
overriding function f2(Self : The_Default) return Integer;
overriding function f3(Self : The_Default) return Integer;
end Some_Interface;
package body Some_Interface is
function f1(Self : The_Default) return Integer is
begin
return 10;
end f1;
function f2(Self : The_Default) return Integer is
begin
return 20;
end f2;
function f3(Self : The_Default) return Integer is
begin
return Self.f1 + Self.f2;
end f3;
end Some_Interface;
-- For examples using existing inheritance trees we need
-- a base type
type Third_Party_Base is tagged null record;
package Examples is
use Some_Interface;
type Example_1 is limited new The_Interface with private;
overriding function f1(Self : Example_1) return Integer;
overriding function f2(Self : Example_1) return Integer;
overriding function f3(Self : Example_1) return Integer;
type Example_2 is new Third_Party_Base and The_Interface with private;
overriding function f1(Self : Example_2) return Integer;
overriding function f2(Self : Example_2) return Integer;
overriding function f3(Self : Example_2) return Integer;
private
-----------------------------------------------
-- Full Type Declarations
-----------------------------------------------
type Example_1 is limited new The_Interface with record
The_Interface_Impl : The_Default;
end record;
type Example_2 is new Third_Party_Base and The_Interface with record
The_Interface_Impl : The_Default;
end record;
end Examples;
package body Examples is
function f1(Self : Example_1) return Integer is (Self.The_Interface_Impl.f1);
function f2(Self : Example_1) return Integer is (Self.The_Interface_Impl.f2);
function f3(Self : Example_1) return Integer is (Self.The_Interface_Impl.f3);
function f1(Self : Example_2) return Integer is (Self.The_Interface_Impl.f1);
function f2(Self : Example_2) return Integer is (Self.The_Interface_Impl.f2);
function f3(Self : Example_2) return Integer is (Self.The_Interface_Impl.f3);
end Examples;
begin
Put_Line("Hello, world!");
end Hello;
-- *******************************************
--
-- This requires more footwork, but enforces that all
-- implementors of the interface have to specify a body for all
-- inherited abstract operations.
generic
type Base is interface ...;
package Poor_Mans_Inheritance;
type Instance is new Base with ...;
overriding procedure Inherit_Me_Please (X : in out Instance);
end Poor_Mans_Inheritance;
type My_Type_I_Cannot_Use_Yet is new Base with ...;
package Generic_Mess is new Poor_Mans_Inheritance (My_Type_I_Cannot_Use_Yet);
type My_Type is new Generic_Mess.Instance with null record;
|
zhmu/ananas | Ada | 546,810 | adb | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E X P _ C H 9 --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Aspects; use Aspects;
with Checks; use Checks;
with Einfo; use Einfo;
with Einfo.Entities; use Einfo.Entities;
with Einfo.Utils; use Einfo.Utils;
with Elists; use Elists;
with Errout; use Errout;
with Exp_Ch3; use Exp_Ch3;
with Exp_Ch6; use Exp_Ch6;
with Exp_Ch11; use Exp_Ch11;
with Exp_Dbug; use Exp_Dbug;
with Exp_Sel; use Exp_Sel;
with Exp_Smem; use Exp_Smem;
with Exp_Tss; use Exp_Tss;
with Exp_Util; use Exp_Util;
with Freeze; use Freeze;
with Hostparm;
with Itypes; use Itypes;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Restrict; use Restrict;
with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Ch5; use Sem_Ch5;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch8; use Sem_Ch8;
with Sem_Ch9; use Sem_Ch9;
with Sem_Ch11; use Sem_Ch11;
with Sem_Ch13; use Sem_Ch13;
with Sem_Elab; use Sem_Elab;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Sinfo.Nodes; use Sinfo.Nodes;
with Sinfo.Utils; use Sinfo.Utils;
with Snames; use Snames;
with Stand; use Stand;
with Targparm; use Targparm;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
with Validsw; use Validsw;
package body Exp_Ch9 is
-- The following constant establishes the upper bound for the index of
-- an entry family. It is used to limit the allocated size of protected
-- types with defaulted discriminant of an integer type, when the bound
-- of some entry family depends on a discriminant. The limitation to entry
-- families of 128K should be reasonable in all cases, and is a documented
-- implementation restriction.
Entry_Family_Bound : constant Pos := 2**16;
-----------------------
-- Local Subprograms --
-----------------------
function Actual_Index_Expression
(Sloc : Source_Ptr;
Ent : Entity_Id;
Index : Node_Id;
Tsk : Entity_Id) return Node_Id;
-- Compute the index position for an entry call. Tsk is the target task. If
-- the bounds of some entry family depend on discriminants, the expression
-- computed by this function uses the discriminants of the target task.
procedure Add_Object_Pointer
(Loc : Source_Ptr;
Conc_Typ : Entity_Id;
Decls : List_Id);
-- Prepend an object pointer declaration to the declaration list Decls.
-- This object pointer is initialized to a type conversion of the System.
-- Address pointer passed to entry barrier functions and entry body
-- procedures.
procedure Add_Formal_Renamings
(Spec : Node_Id;
Decls : List_Id;
Ent : Entity_Id;
Loc : Source_Ptr);
-- Create renaming declarations for the formals, inside the procedure that
-- implements an entry body. The renamings make the original names of the
-- formals accessible to gdb, and serve no other purpose.
-- Spec is the specification of the procedure being built.
-- Decls is the list of declarations to be enhanced.
-- Ent is the entity for the original entry body.
function Build_Accept_Body (Astat : Node_Id) return Node_Id;
-- Transform accept statement into a block with added exception handler.
-- Used both for simple accept statements and for accept alternatives in
-- select statements. Astat is the accept statement.
function Build_Barrier_Function
(N : Node_Id;
Ent : Entity_Id;
Pid : Entity_Id) return Node_Id;
-- Build the function body returning the value of the barrier expression
-- for the specified entry body.
function Build_Barrier_Function_Specification
(Loc : Source_Ptr;
Def_Id : Entity_Id) return Node_Id;
-- Build a specification for a function implementing the protected entry
-- barrier of the specified entry body.
procedure Build_Contract_Wrapper (E : Entity_Id; Decl : Node_Id);
-- Build the body of a wrapper procedure for an entry or entry family that
-- has contract cases, preconditions, or postconditions. The body gathers
-- the executable contract items and expands them in the usual way, and
-- performs the entry call itself. This way preconditions are evaluated
-- before the call is queued. E is the entry in question, and Decl is the
-- enclosing synchronized type declaration at whose freeze point the
-- generated body is analyzed.
function Build_Corresponding_Record
(N : Node_Id;
Ctyp : Entity_Id;
Loc : Source_Ptr) return Node_Id;
-- Common to tasks and protected types. Copy discriminant specifications,
-- build record declaration. N is the type declaration, Ctyp is the
-- concurrent entity (task type or protected type).
function Build_Dispatching_Tag_Check
(K : Entity_Id;
N : Node_Id) return Node_Id;
-- Utility to create the tree to check whether the dispatching call in
-- a timed entry call, a conditional entry call, or an asynchronous
-- transfer of control is a call to a primitive of a non-synchronized type.
-- K is the temporary that holds the tagged kind of the target object, and
-- N is the enclosing construct.
function Build_Entry_Count_Expression
(Concurrent_Type : Node_Id;
Component_List : List_Id;
Loc : Source_Ptr) return Node_Id;
-- Compute number of entries for concurrent object. This is a count of
-- simple entries, followed by an expression that computes the length
-- of the range of each entry family. A single array with that size is
-- allocated for each concurrent object of the type.
function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
-- Build the function that translates the entry index in the call
-- (which depends on the size of entry families) into an index into the
-- Entry_Bodies_Array, to determine the body and barrier function used
-- in a protected entry call. A pointer to this function appears in every
-- protected object.
function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
-- Build subprogram declaration for previous one
function Build_Lock_Free_Protected_Subprogram_Body
(N : Node_Id;
Prot_Typ : Node_Id;
Unprot_Spec : Node_Id) return Node_Id;
-- N denotes a subprogram body of protected type Prot_Typ. Unprot_Spec is
-- the subprogram specification of the unprotected version of N. Transform
-- N such that it invokes the unprotected version of the body.
function Build_Lock_Free_Unprotected_Subprogram_Body
(N : Node_Id;
Prot_Typ : Node_Id) return Node_Id;
-- N denotes a subprogram body of protected type Prot_Typ. Build a version
-- of N where the original statements of N are synchronized through atomic
-- actions such as compare and exchange. Prior to invoking this routine, it
-- has been established that N can be implemented in a lock-free fashion.
function Build_Parameter_Block
(Loc : Source_Ptr;
Actuals : List_Id;
Formals : List_Id;
Decls : List_Id) return Entity_Id;
-- Generate an access type for each actual parameter in the list Actuals.
-- Create an encapsulating record that contains all the actuals and return
-- its type. Generate:
-- type Ann1 is access all <actual1-type>
-- ...
-- type AnnN is access all <actualN-type>
-- type Pnn is record
-- <formal1> : Ann1;
-- ...
-- <formalN> : AnnN;
-- end record;
function Build_Protected_Entry
(N : Node_Id;
Ent : Entity_Id;
Pid : Node_Id) return Node_Id;
-- Build the procedure implementing the statement sequence of the specified
-- entry body.
function Build_Protected_Entry_Specification
(Loc : Source_Ptr;
Def_Id : Entity_Id;
Ent_Id : Entity_Id) return Node_Id;
-- Build a specification for the procedure implementing the statements of
-- the specified entry body. Add attributes associating it with the entry
-- defining identifier Ent_Id.
function Build_Protected_Spec
(N : Node_Id;
Obj_Type : Entity_Id;
Ident : Entity_Id;
Unprotected : Boolean := False) return List_Id;
-- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
-- Subprogram_Type. Builds signature of protected subprogram, adding the
-- formal that corresponds to the object itself. For an access to protected
-- subprogram, there is no object type to specify, so the parameter has
-- type Address and mode In. An indirect call through such a pointer will
-- convert the address to a reference to the actual object. The object is
-- a limited record and therefore a by_reference type.
function Build_Protected_Subprogram_Body
(N : Node_Id;
Pid : Node_Id;
N_Op_Spec : Node_Id) return Node_Id;
-- This function is used to construct the protected version of a protected
-- subprogram. Its statement sequence first defers abort, then locks the
-- associated protected object, and then enters a block that contains a
-- call to the unprotected version of the subprogram (for details, see
-- Build_Unprotected_Subprogram_Body). This block statement requires a
-- cleanup handler that unlocks the object in all cases. For details,
-- see Exp_Ch7.Expand_Cleanup_Actions.
function Build_Renamed_Formal_Declaration
(New_F : Entity_Id;
Formal : Entity_Id;
Comp : Entity_Id;
Renamed_Formal : Node_Id) return Node_Id;
-- Create a renaming declaration for a formal, within a protected entry
-- body or an accept body. The renamed object is a component of the
-- parameter block that is a parameter in the entry call.
--
-- In Ada 2012, if the formal is an incomplete tagged type, the renaming
-- does not dereference the corresponding component to prevent an illegal
-- use of the incomplete type (AI05-0151).
function Build_Selected_Name
(Prefix : Entity_Id;
Selector : Entity_Id;
Append_Char : Character := ' ') return Name_Id;
-- Build a name in the form of Prefix__Selector, with an optional character
-- appended. This is used for internal subprograms generated for operations
-- of protected types, including barrier functions. For the subprograms
-- generated for entry bodies and entry barriers, the generated name
-- includes a sequence number that makes names unique in the presence of
-- entry overloading. This is necessary because entry body procedures and
-- barrier functions all have the same signature.
procedure Build_Simple_Entry_Call
(N : Node_Id;
Concval : Node_Id;
Ename : Node_Id;
Index : Node_Id);
-- Build the call corresponding to the task entry call. N is the task entry
-- call, Concval is the concurrent object, Ename is the entry name and
-- Index is the entry family index.
-- Note that N might be expanded into an N_Block_Statement if it gets
-- inlined.
function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
-- This routine constructs a specification for the procedure that we will
-- build for the task body for task type T. The spec has the form:
--
-- procedure tnameB (_Task : access tnameV);
--
-- where name is the character name taken from the task type entity that
-- is passed as the argument to the procedure, and tnameV is the task
-- value type that is associated with the task type.
function Build_Unprotected_Subprogram_Body
(N : Node_Id;
Pid : Node_Id) return Node_Id;
-- This routine constructs the unprotected version of a protected
-- subprogram body, which contains all of the code in the original,
-- unexpanded body. This is the version of the protected subprogram that is
-- called from all protected operations on the same object, including the
-- protected version of the same subprogram.
procedure Build_Wrapper_Bodies
(Loc : Source_Ptr;
Typ : Entity_Id;
N : Node_Id);
-- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
-- record of a concurrent type. N is the insertion node where all bodies
-- will be placed. This routine builds the bodies of the subprograms which
-- serve as an indirection mechanism to overriding primitives of concurrent
-- types, entries and protected procedures. Any new body is analyzed.
procedure Build_Wrapper_Specs
(Loc : Source_Ptr;
Typ : Entity_Id;
N : in out Node_Id);
-- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
-- record of a concurrent type. N is the insertion node where all specs
-- will be placed. This routine builds the specs of the subprograms which
-- serve as an indirection mechanism to overriding primitives of concurrent
-- types, entries and protected procedures. Any new spec is analyzed.
procedure Collect_Entry_Families
(Loc : Source_Ptr;
Cdecls : List_Id;
Current_Node : in out Node_Id;
Conctyp : Entity_Id);
-- For each entry family in a concurrent type, create an anonymous array
-- type of the right size, and add a component to the corresponding_record.
function Concurrent_Object
(Spec_Id : Entity_Id;
Conc_Typ : Entity_Id) return Entity_Id;
-- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
-- the entity associated with the concurrent object in the Protected_Body_
-- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
-- denotes formal parameter _O, _object or _task.
function Copy_Result_Type (Res : Node_Id) return Node_Id;
-- Copy the result type of a function specification, when building the
-- internal operation corresponding to a protected function, or when
-- expanding an access to protected function. If the result is an anonymous
-- access to subprogram itself, we need to create a new signature with the
-- same parameter names and the same resolved types, but with new entities
-- for the formals.
function Create_Secondary_Stack_For_Task (T : Node_Id) return Boolean;
-- Return whether a secondary stack for the task T should be created by the
-- expander. The secondary stack for a task will be created by the expander
-- if the size of the stack has been specified by the Secondary_Stack_Size
-- representation aspect and either the No_Implicit_Heap_Allocations or
-- No_Implicit_Task_Allocations restrictions are in effect and the
-- No_Secondary_Stack restriction is not.
procedure Debug_Private_Data_Declarations (Decls : List_Id);
-- Decls is a list which may contain the declarations created by Install_
-- Private_Data_Declarations. All generated entities are marked as needing
-- debug info and debug nodes are manually generation where necessary. This
-- step of the expansion must to be done after private data has been moved
-- to its final resting scope to ensure proper visibility of debug objects.
procedure Ensure_Statement_Present (Loc : Source_Ptr; Alt : Node_Id);
-- If control flow optimizations are suppressed, and Alt is an accept,
-- delay, or entry call alternative with no trailing statements, insert
-- a null trailing statement with the given Loc (which is the sloc of
-- the accept, delay, or entry call statement). There might not be any
-- generated code for the accept, delay, or entry call itself (the effect
-- of these statements is part of the general processing done for the
-- enclosing selective accept, timed entry call, or asynchronous select),
-- and the null statement is there to carry the sloc of that statement to
-- the back-end for trace-based coverage analysis purposes.
procedure Extract_Dispatching_Call
(N : Node_Id;
Call_Ent : out Entity_Id;
Object : out Entity_Id;
Actuals : out List_Id;
Formals : out List_Id);
-- Given a dispatching call, extract the entity of the name of the call,
-- its actual dispatching object, its actual parameters and the formal
-- parameters of the overridden interface-level version. If the type of
-- the dispatching object is an access type then an explicit dereference
-- is returned in Object.
procedure Extract_Entry
(N : Node_Id;
Concval : out Node_Id;
Ename : out Node_Id;
Index : out Node_Id);
-- Given an entry call, returns the associated concurrent object, the entry
-- name, and the entry family index.
function Family_Offset
(Loc : Source_Ptr;
Hi : Node_Id;
Lo : Node_Id;
Ttyp : Entity_Id;
Cap : Boolean) return Node_Id;
-- Compute (Hi - Lo) for two entry family indexes. Hi is the index in an
-- accept statement, or the upper bound in the discrete subtype of an entry
-- declaration. Lo is the corresponding lower bound. Ttyp is the concurrent
-- type of the entry. If Cap is true, the result is capped according to
-- Entry_Family_Bound.
function Family_Size
(Loc : Source_Ptr;
Hi : Node_Id;
Lo : Node_Id;
Ttyp : Entity_Id;
Cap : Boolean) return Node_Id;
-- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in a
-- family, and handle properly the superflat case. This is equivalent to
-- the use of 'Length on the index type, but must use Family_Offset to
-- handle properly the case of bounds that depend on discriminants. If
-- Cap is true, the result is capped according to Entry_Family_Bound.
procedure Find_Enclosing_Context
(N : Node_Id;
Context : out Node_Id;
Context_Id : out Entity_Id;
Context_Decls : out List_Id);
-- Subsidiary routine to procedures Build_Activation_Chain_Entity and
-- Build_Master_Entity. Given an arbitrary node in the tree, find the
-- nearest enclosing body, block, package, or return statement and return
-- its constituents. Context is the enclosing construct, Context_Id is
-- the scope of Context_Id and Context_Decls is the declarative list of
-- Context.
function Index_Object (Spec_Id : Entity_Id) return Entity_Id;
-- Given a subprogram identifier, return the entity which is associated
-- with the protection entry index in the Protected_Body_Subprogram or
-- the Task_Body_Procedure of Spec_Id. The returned entity denotes formal
-- parameter _E.
function Is_Potentially_Large_Family
(Base_Index : Entity_Id;
Conctyp : Entity_Id;
Lo : Node_Id;
Hi : Node_Id) return Boolean;
-- Determine whether an entry family is potentially large because one of
-- its bounds denotes a discrminant.
function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean;
-- Determine whether Id is a function or a procedure and is marked as a
-- private primitive.
function Null_Statements (Stats : List_Id) return Boolean;
-- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
-- Allows labels, and pragma Warnings/Unreferenced in the sequence as well
-- to still count as null. Returns True for a null sequence. The argument
-- is the list of statements from the DO-END sequence.
function Parameter_Block_Pack
(Loc : Source_Ptr;
Blk_Typ : Entity_Id;
Actuals : List_Id;
Formals : List_Id;
Decls : List_Id;
Stmts : List_Id) return Entity_Id;
-- Set the components of the generated parameter block with the values
-- of the actual parameters. Generate aliased temporaries to capture the
-- values for types that are passed by copy. Otherwise generate a reference
-- to the actual's value. Return the address of the aggregate block.
-- Generate:
-- Jnn1 : alias <formal-type1>;
-- Jnn1 := <actual1>;
-- ...
-- P : Blk_Typ := (
-- Jnn1'unchecked_access;
-- <actual2>'reference;
-- ...);
function Parameter_Block_Unpack
(Loc : Source_Ptr;
P : Entity_Id;
Actuals : List_Id;
Formals : List_Id) return List_Id;
-- Retrieve the values of the components from the parameter block and
-- assign then to the original actual parameters. Generate:
-- <actual1> := P.<formal1>;
-- ...
-- <actualN> := P.<formalN>;
procedure Reset_Scopes_To (Bod : Node_Id; E : Entity_Id);
-- Reset the scope of declarations and blocks at the top level of Bod to
-- be E. Bod is either a block or a subprogram body. Used after expanding
-- various kinds of entry bodies into their corresponding constructs. This
-- is needed during unnesting to determine whether a body generated for an
-- entry or an accept alternative includes uplevel references.
function Trivial_Accept_OK return Boolean;
-- If there is no DO-END block for an accept, or if the DO-END block has
-- only null statements, then it is possible to do the Rendezvous with much
-- less overhead using the Accept_Trivial routine in the run-time library.
-- However, this is not always a valid optimization. Whether it is valid or
-- not depends on the Task_Dispatching_Policy. The issue is whether a full
-- rescheduling action is required or not. In FIFO_Within_Priorities, such
-- a rescheduling is required, so this optimization is not allowed. This
-- function returns True if the optimization is permitted.
-----------------------------
-- Actual_Index_Expression --
-----------------------------
function Actual_Index_Expression
(Sloc : Source_Ptr;
Ent : Entity_Id;
Index : Node_Id;
Tsk : Entity_Id) return Node_Id
is
Ttyp : constant Entity_Id := Etype (Tsk);
Expr : Node_Id;
Num : Node_Id;
Lo : Node_Id;
Hi : Node_Id;
Prev : Entity_Id;
S : Node_Id;
function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
-- Compute difference between bounds of entry family
--------------------------
-- Actual_Family_Offset --
--------------------------
function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
-- Replace a reference to a discriminant with a selected component
-- denoting the discriminant of the target task.
-----------------------------
-- Actual_Discriminant_Ref --
-----------------------------
function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
Typ : constant Entity_Id := Etype (Bound);
B : Node_Id;
begin
if not Is_Entity_Name (Bound)
or else Ekind (Entity (Bound)) /= E_Discriminant
then
if Nkind (Bound) = N_Attribute_Reference then
return Bound;
else
B := New_Copy_Tree (Bound);
end if;
else
B :=
Make_Selected_Component (Sloc,
Prefix => New_Copy_Tree (Tsk),
Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
Analyze_And_Resolve (B, Typ);
end if;
return
Make_Attribute_Reference (Sloc,
Attribute_Name => Name_Pos,
Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
Expressions => New_List (B));
end Actual_Discriminant_Ref;
-- Start of processing for Actual_Family_Offset
begin
return
Make_Op_Subtract (Sloc,
Left_Opnd => Actual_Discriminant_Ref (Hi),
Right_Opnd => Actual_Discriminant_Ref (Lo));
end Actual_Family_Offset;
-- Start of processing for Actual_Index_Expression
begin
-- The queues of entries and entry families appear in textual order in
-- the associated record. The entry index is computed as the sum of the
-- number of queues for all entries that precede the designated one, to
-- which is added the index expression, if this expression denotes a
-- member of a family.
-- The following is a place holder for the count of simple entries
Num := Make_Integer_Literal (Sloc, 1);
-- We construct an expression which is a series of addition operations.
-- See comments in Entry_Index_Expression, which is identical in
-- structure.
if Present (Index) then
S := Entry_Index_Type (Ent);
-- First make sure the index is in range if requested. The index type
-- has been directly set on the prefix, see Resolve_Entry.
if Do_Range_Check (Index) then
Generate_Range_Check
(Index, Etype (Prefix (Parent (Index))), CE_Range_Check_Failed);
end if;
Expr :=
Make_Op_Add (Sloc,
Left_Opnd => Num,
Right_Opnd =>
Actual_Family_Offset (
Make_Attribute_Reference (Sloc,
Attribute_Name => Name_Pos,
Prefix => New_Occurrence_Of (Base_Type (S), Sloc),
Expressions => New_List (Relocate_Node (Index))),
Type_Low_Bound (S)));
else
Expr := Num;
end if;
-- Now add lengths of preceding entries and entry families
Prev := First_Entity (Ttyp);
while Chars (Prev) /= Chars (Ent)
or else (Ekind (Prev) /= Ekind (Ent))
or else not Sem_Ch6.Type_Conformant (Ent, Prev)
loop
if Ekind (Prev) = E_Entry then
Set_Intval (Num, Intval (Num) + 1);
elsif Ekind (Prev) = E_Entry_Family then
S := Entry_Index_Type (Prev);
-- The need for the following full view retrieval stems from this
-- complex case of nested generics and tasking:
-- generic
-- type Formal_Index is range <>;
-- ...
-- package Outer is
-- type Index is private;
-- generic
-- ...
-- package Inner is
-- procedure P;
-- end Inner;
-- private
-- type Index is new Formal_Index range 1 .. 10;
-- end Outer;
-- package body Outer is
-- task type T is
-- entry Fam (Index); -- (2)
-- entry E;
-- end T;
-- package body Inner is -- (3)
-- procedure P is
-- begin
-- T.E; -- (1)
-- end P;
-- end Inner;
-- ...
-- We are currently building the index expression for the entry
-- call "T.E" (1). Part of the expansion must mention the range
-- of the discrete type "Index" (2) of entry family "Fam".
-- However only the private view of type "Index" is available to
-- the inner generic (3) because there was no prior mention of
-- the type inside "Inner". This visibility requirement is
-- implicit and cannot be detected during the construction of
-- the generic trees and needs special handling.
if In_Instance_Body
and then Is_Private_Type (S)
and then Present (Full_View (S))
then
S := Full_View (S);
end if;
Lo := Type_Low_Bound (S);
Hi := Type_High_Bound (S);
Expr :=
Make_Op_Add (Sloc,
Left_Opnd => Expr,
Right_Opnd =>
Make_Op_Add (Sloc,
Left_Opnd => Actual_Family_Offset (Hi, Lo),
Right_Opnd => Make_Integer_Literal (Sloc, 1)));
-- Other components are anonymous types to be ignored
else
null;
end if;
Next_Entity (Prev);
end loop;
return Expr;
end Actual_Index_Expression;
--------------------------
-- Add_Formal_Renamings --
--------------------------
procedure Add_Formal_Renamings
(Spec : Node_Id;
Decls : List_Id;
Ent : Entity_Id;
Loc : Source_Ptr)
is
Ptr : constant Entity_Id :=
Defining_Identifier
(Next (First (Parameter_Specifications (Spec))));
-- The name of the formal that holds the address of the parameter block
-- for the call.
Comp : Entity_Id;
Decl : Node_Id;
Formal : Entity_Id;
New_F : Entity_Id;
Renamed_Formal : Node_Id;
begin
Formal := First_Formal (Ent);
while Present (Formal) loop
Comp := Entry_Component (Formal);
New_F :=
Make_Defining_Identifier (Sloc (Formal),
Chars => Chars (Formal));
Set_Etype (New_F, Etype (Formal));
Set_Scope (New_F, Ent);
-- Now we set debug info needed on New_F even though it does not come
-- from source, so that the debugger will get the right information
-- for these generated names.
Set_Debug_Info_Needed (New_F);
if Ekind (Formal) = E_In_Parameter then
Mutate_Ekind (New_F, E_Constant);
else
Mutate_Ekind (New_F, E_Variable);
Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
end if;
Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
Renamed_Formal :=
Make_Selected_Component (Loc,
Prefix =>
Make_Explicit_Dereference (Loc,
Unchecked_Convert_To (Entry_Parameters_Type (Ent),
Make_Identifier (Loc, Chars (Ptr)))),
Selector_Name => New_Occurrence_Of (Comp, Loc));
Decl :=
Build_Renamed_Formal_Declaration
(New_F, Formal, Comp, Renamed_Formal);
Append (Decl, Decls);
Set_Renamed_Object (Formal, New_F);
Next_Formal (Formal);
end loop;
end Add_Formal_Renamings;
------------------------
-- Add_Object_Pointer --
------------------------
procedure Add_Object_Pointer
(Loc : Source_Ptr;
Conc_Typ : Entity_Id;
Decls : List_Id)
is
Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ);
Decl : Node_Id;
Obj_Ptr : Node_Id;
begin
-- Create the renaming declaration for the Protection object of a
-- protected type. _Object is used by Complete_Entry_Body.
-- ??? An attempt to make this a renaming was unsuccessful.
-- Build the entity for the access type
Obj_Ptr :=
Make_Defining_Identifier (Loc,
New_External_Name (Chars (Rec_Typ), 'P'));
-- Generate:
-- _object : poVP := poVP!O;
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Name_uObject),
Object_Definition => New_Occurrence_Of (Obj_Ptr, Loc),
Expression =>
Unchecked_Convert_To (Obj_Ptr, Make_Identifier (Loc, Name_uO)));
Set_Debug_Info_Needed (Defining_Identifier (Decl));
Prepend_To (Decls, Decl);
-- Generate:
-- type poVP is access poV;
Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier =>
Obj_Ptr,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
Subtype_Indication =>
New_Occurrence_Of (Rec_Typ, Loc)));
Set_Debug_Info_Needed (Defining_Identifier (Decl));
Prepend_To (Decls, Decl);
end Add_Object_Pointer;
-----------------------
-- Build_Accept_Body --
-----------------------
function Build_Accept_Body (Astat : Node_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (Astat);
Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
New_S : Node_Id;
Hand : Node_Id;
Call : Node_Id;
Ohandle : Node_Id;
begin
-- At the end of the statement sequence, Complete_Rendezvous is called.
-- A label skipping the Complete_Rendezvous, and all other accept
-- processing, has already been added for the expansion of requeue
-- statements. The Sloc is copied from the last statement since it
-- is really part of this last statement.
Call :=
Build_Runtime_Call
(Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous);
Insert_Before (Last (Statements (Stats)), Call);
Analyze (Call);
-- Ada 2022 (AI12-0279)
if Has_Yield_Aspect (Entity (Entry_Direct_Name (Astat)))
and then RTE_Available (RE_Yield)
then
Insert_Action_After (Call,
Make_Procedure_Call_Statement (Loc,
New_Occurrence_Of (RTE (RE_Yield), Loc)));
end if;
-- If exception handlers are present, then append Complete_Rendezvous
-- calls to the handlers, and construct the required outer block. As
-- above, the Sloc is copied from the last statement in the sequence.
if Present (Exception_Handlers (Stats)) then
Hand := First (Exception_Handlers (Stats));
while Present (Hand) loop
Call :=
Build_Runtime_Call
(Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous);
Append (Call, Statements (Hand));
Analyze (Call);
-- Ada 2022 (AI12-0279)
if Has_Yield_Aspect (Entity (Entry_Direct_Name (Astat)))
and then RTE_Available (RE_Yield)
then
Insert_Action_After (Call,
Make_Procedure_Call_Statement (Loc,
New_Occurrence_Of (RTE (RE_Yield), Loc)));
end if;
Next (Hand);
end loop;
New_S :=
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Block_Statement (Loc,
Handled_Statement_Sequence => Stats)));
else
New_S := Stats;
end if;
-- At this stage we know that the new statement sequence does
-- not have an exception handler part, so we supply one to call
-- Exceptional_Complete_Rendezvous. This handler is
-- when all others =>
-- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
-- We handle Abort_Signal to make sure that we properly catch the abort
-- case and wake up the caller.
Call :=
Make_Procedure_Call_Statement (Sloc (Stats),
Name => New_Occurrence_Of (
RTE (RE_Exceptional_Complete_Rendezvous), Sloc (Stats)),
Parameter_Associations => New_List (
Make_Function_Call (Sloc (Stats),
Name =>
New_Occurrence_Of
(RTE (RE_Get_GNAT_Exception), Sloc (Stats)))));
Ohandle := Make_Others_Choice (Loc);
Set_All_Others (Ohandle);
Set_Exception_Handlers (New_S,
New_List (
Make_Implicit_Exception_Handler (Loc,
Exception_Choices => New_List (Ohandle),
Statements => New_List (Call))));
-- Ada 2022 (AI12-0279)
if Has_Yield_Aspect (Entity (Entry_Direct_Name (Astat)))
and then RTE_Available (RE_Yield)
then
Insert_Action_After (Call,
Make_Procedure_Call_Statement (Loc,
New_Occurrence_Of (RTE (RE_Yield), Loc)));
end if;
Set_Parent (New_S, Astat); -- temp parent for Analyze call
Analyze_Exception_Handlers (Exception_Handlers (New_S));
Expand_Exception_Handlers (New_S);
-- Exceptional_Complete_Rendezvous must be called with abort still
-- deferred, which is the case for a "when all others" handler.
return New_S;
end Build_Accept_Body;
-----------------------------------
-- Build_Activation_Chain_Entity --
-----------------------------------
procedure Build_Activation_Chain_Entity (N : Node_Id) is
function Has_Activation_Chain (Stmt : Node_Id) return Boolean;
-- Determine whether an extended return statement has activation chain
--------------------------
-- Has_Activation_Chain --
--------------------------
function Has_Activation_Chain (Stmt : Node_Id) return Boolean is
Decl : Node_Id;
begin
Decl := First (Return_Object_Declarations (Stmt));
while Present (Decl) loop
if Nkind (Decl) = N_Object_Declaration
and then Chars (Defining_Identifier (Decl)) = Name_uChain
then
return True;
end if;
Next (Decl);
end loop;
return False;
end Has_Activation_Chain;
-- Local variables
Context : Node_Id;
Context_Id : Entity_Id;
Decls : List_Id;
-- Start of processing for Build_Activation_Chain_Entity
begin
-- No action needed if the run-time has no tasking support
if Global_No_Tasking then
return;
end if;
-- Activation chain is never used for sequential elaboration policy, see
-- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
if Partition_Elaboration_Policy = 'S' then
return;
end if;
Find_Enclosing_Context (N, Context, Context_Id, Decls);
-- If activation chain entity has not been declared already, create one
if Nkind (Context) = N_Extended_Return_Statement
or else No (Activation_Chain_Entity (Context))
then
-- Since extended return statements do not store the entity of the
-- chain, examine the return object declarations to avoid creating
-- a duplicate.
if Nkind (Context) = N_Extended_Return_Statement
and then Has_Activation_Chain (Context)
then
return;
end if;
declare
Loc : constant Source_Ptr := Sloc (Context);
Chain : Entity_Id;
Decl : Node_Id;
begin
Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
-- Note: An extended return statement is not really a task
-- activator, but it does have an activation chain on which to
-- store the tasks temporarily. On successful return, the tasks
-- on this chain are moved to the chain passed in by the caller.
-- We do not build an Activation_Chain_Entity for an extended
-- return statement, because we do not want to build a call to
-- Activate_Tasks. Task activation is the responsibility of the
-- caller.
if Nkind (Context) /= N_Extended_Return_Statement then
Set_Activation_Chain_Entity (Context, Chain);
end if;
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Chain,
Aliased_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Activation_Chain), Loc));
Prepend_To (Decls, Decl);
-- Ensure that _chain appears in the proper scope of the context
if Context_Id /= Current_Scope then
Push_Scope (Context_Id);
Analyze (Decl);
Pop_Scope;
else
Analyze (Decl);
end if;
end;
end if;
end Build_Activation_Chain_Entity;
----------------------------
-- Build_Barrier_Function --
----------------------------
function Build_Barrier_Function
(N : Node_Id;
Ent : Entity_Id;
Pid : Entity_Id) return Node_Id
is
Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
Cond : constant Node_Id := Condition (Ent_Formals);
Loc : constant Source_Ptr := Sloc (Cond);
Func_Id : constant Entity_Id := Barrier_Function (Ent);
Op_Decls : constant List_Id := New_List;
Stmt : Node_Id;
Func_Body : Node_Id;
begin
-- Add a declaration for the Protection object, renaming declarations
-- for the discriminals and privals and finally a declaration for the
-- entry family index (if applicable).
Install_Private_Data_Declarations (Sloc (N),
Spec_Id => Func_Id,
Conc_Typ => Pid,
Body_Nod => N,
Decls => Op_Decls,
Barrier => True,
Family => Ekind (Ent) = E_Entry_Family);
-- If compiling with -fpreserve-control-flow, make sure we insert an
-- IF statement so that the back-end knows to generate a conditional
-- branch instruction, even if the condition is just the name of a
-- boolean object. Note that Expand_N_If_Statement knows to preserve
-- such redundant IF statements under -fpreserve-control-flow
-- (whether coming from this routine, or directly from source).
if Opt.Suppress_Control_Flow_Optimizations then
Stmt :=
Make_Implicit_If_Statement (Cond,
Condition => Cond,
Then_Statements => New_List (
Make_Simple_Return_Statement (Loc,
New_Occurrence_Of (Standard_True, Loc))),
Else_Statements => New_List (
Make_Simple_Return_Statement (Loc,
New_Occurrence_Of (Standard_False, Loc))));
else
Stmt := Make_Simple_Return_Statement (Loc, Cond);
end if;
-- Note: the condition in the barrier function needs to be properly
-- processed for the C/Fortran boolean possibility, but this happens
-- automatically since the return statement does this normalization.
Func_Body :=
Make_Subprogram_Body (Loc,
Specification =>
Build_Barrier_Function_Specification (Loc,
Make_Defining_Identifier (Loc, Chars (Func_Id))),
Declarations => Op_Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Stmt)));
Set_Is_Entry_Barrier_Function (Func_Body);
return Func_Body;
end Build_Barrier_Function;
------------------------------------------
-- Build_Barrier_Function_Specification --
------------------------------------------
function Build_Barrier_Function_Specification
(Loc : Source_Ptr;
Def_Id : Entity_Id) return Node_Id
is
begin
Set_Debug_Info_Needed (Def_Id);
return
Make_Function_Specification (Loc,
Defining_Unit_Name => Def_Id,
Parameter_Specifications => New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uO),
Parameter_Type =>
New_Occurrence_Of (RTE (RE_Address), Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uE),
Parameter_Type =>
New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))),
Result_Definition =>
New_Occurrence_Of (Standard_Boolean, Loc));
end Build_Barrier_Function_Specification;
--------------------------
-- Build_Call_With_Task --
--------------------------
function Build_Call_With_Task
(N : Node_Id;
E : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (N);
begin
return
Make_Function_Call (Loc,
Name => New_Occurrence_Of (E, Loc),
Parameter_Associations => New_List (Concurrent_Ref (N)));
end Build_Call_With_Task;
-----------------------------
-- Build_Class_Wide_Master --
-----------------------------
procedure Build_Class_Wide_Master (Typ : Entity_Id) is
Loc : constant Source_Ptr := Sloc (Typ);
Master_Decl : Node_Id;
Master_Id : Entity_Id;
Master_Scope : Entity_Id;
Name_Id : Node_Id;
Related_Node : Node_Id;
Ren_Decl : Node_Id;
begin
-- No action needed if the run-time has no tasking support
if Global_No_Tasking then
return;
end if;
-- Find the declaration that created the access type, which is either a
-- type declaration, or an object declaration with an access definition,
-- in which case the type is anonymous.
if Is_Itype (Typ) then
Related_Node := Associated_Node_For_Itype (Typ);
else
Related_Node := Parent (Typ);
end if;
Master_Scope := Find_Master_Scope (Typ);
-- Nothing to do if the master scope already contains a _master entity.
-- The only exception to this is the following scenario:
-- Source_Scope
-- Transient_Scope_1
-- _master
-- Transient_Scope_2
-- use of master
-- In this case the source scope is marked as having the master entity
-- even though the actual declaration appears inside an inner scope. If
-- the second transient scope requires a _master, it cannot use the one
-- already declared because the entity is not visible.
Name_Id := Make_Identifier (Loc, Name_uMaster);
Master_Decl := Empty;
if not Has_Master_Entity (Master_Scope)
or else No (Current_Entity_In_Scope (Name_Id))
then
declare
Ins_Nod : Node_Id;
begin
Set_Has_Master_Entity (Master_Scope);
Master_Decl := Build_Master_Declaration (Loc);
-- Ensure that the master declaration is placed before its use
Ins_Nod := Find_Hook_Context (Related_Node);
while not Is_List_Member (Ins_Nod) loop
Ins_Nod := Parent (Ins_Nod);
end loop;
Insert_Before (First (List_Containing (Ins_Nod)), Master_Decl);
Analyze (Master_Decl);
-- Mark the containing scope as a task master. Masters associated
-- with return statements are already marked at this stage (see
-- Analyze_Subprogram_Body).
if Ekind (Current_Scope) /= E_Return_Statement then
declare
Par : Node_Id := Related_Node;
begin
while Nkind (Par) /= N_Compilation_Unit loop
Par := Parent (Par);
-- If we fall off the top, we are at the outer level,
-- and the environment task is our effective master,
-- so nothing to mark.
if Nkind (Par) in
N_Block_Statement | N_Subprogram_Body | N_Task_Body
then
Set_Is_Task_Master (Par);
exit;
end if;
end loop;
end;
end if;
end;
end if;
Master_Id :=
Make_Defining_Identifier (Loc, New_External_Name (Chars (Typ), 'M'));
-- Generate:
-- typeMnn renames _master;
Ren_Decl :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Master_Id,
Subtype_Mark => New_Occurrence_Of (Standard_Integer, Loc),
Name => Name_Id);
-- If the master is declared locally, add the renaming declaration
-- immediately after it, to prevent access-before-elaboration in the
-- back-end.
if Present (Master_Decl) then
Insert_After (Master_Decl, Ren_Decl);
Analyze (Ren_Decl);
else
Insert_Action (Related_Node, Ren_Decl);
end if;
Set_Master_Id (Typ, Master_Id);
end Build_Class_Wide_Master;
----------------------------
-- Build_Contract_Wrapper --
----------------------------
procedure Build_Contract_Wrapper (E : Entity_Id; Decl : Node_Id) is
Conc_Typ : constant Entity_Id := Scope (E);
Loc : constant Source_Ptr := Sloc (E);
procedure Add_Discriminant_Renamings
(Obj_Id : Entity_Id;
Decls : List_Id);
-- Add renaming declarations for all discriminants of concurrent type
-- Conc_Typ. Obj_Id is the entity of the wrapper formal parameter which
-- represents the concurrent object.
procedure Add_Matching_Formals
(Formals : List_Id;
Actuals : in out List_Id);
-- Add formal parameters that match those of entry E to list Formals.
-- The routine also adds matching actuals for the new formals to list
-- Actuals.
procedure Transfer_Pragma (Prag : Node_Id; To : in out List_Id);
-- Relocate pragma Prag to list To. The routine creates a new list if
-- To does not exist.
--------------------------------
-- Add_Discriminant_Renamings --
--------------------------------
procedure Add_Discriminant_Renamings
(Obj_Id : Entity_Id;
Decls : List_Id)
is
Discr : Entity_Id;
begin
-- Inspect the discriminants of the concurrent type and generate a
-- renaming for each one.
if Has_Discriminants (Conc_Typ) then
Discr := First_Discriminant (Conc_Typ);
while Present (Discr) loop
Prepend_To (Decls,
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Chars (Discr)),
Subtype_Mark =>
New_Occurrence_Of (Etype (Discr), Loc),
Name =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (Obj_Id, Loc),
Selector_Name =>
Make_Identifier (Loc, Chars (Discr)))));
Next_Discriminant (Discr);
end loop;
end if;
end Add_Discriminant_Renamings;
--------------------------
-- Add_Matching_Formals --
--------------------------
procedure Add_Matching_Formals
(Formals : List_Id;
Actuals : in out List_Id)
is
Formal : Entity_Id;
New_Formal : Entity_Id;
begin
-- Inspect the formal parameters of the entry and generate a new
-- matching formal with the same name for the wrapper. A reference
-- to the new formal becomes an actual in the entry call.
Formal := First_Formal (E);
while Present (Formal) loop
New_Formal := Make_Defining_Identifier (Loc, Chars (Formal));
Append_To (Formals,
Make_Parameter_Specification (Loc,
Defining_Identifier => New_Formal,
In_Present => In_Present (Parent (Formal)),
Out_Present => Out_Present (Parent (Formal)),
Parameter_Type =>
New_Occurrence_Of (Etype (Formal), Loc)));
if No (Actuals) then
Actuals := New_List;
end if;
Append_To (Actuals, New_Occurrence_Of (New_Formal, Loc));
Next_Formal (Formal);
end loop;
end Add_Matching_Formals;
---------------------
-- Transfer_Pragma --
---------------------
procedure Transfer_Pragma (Prag : Node_Id; To : in out List_Id) is
New_Prag : Node_Id;
begin
if No (To) then
To := New_List;
end if;
New_Prag := Relocate_Node (Prag);
Set_Analyzed (New_Prag, False);
Append (New_Prag, To);
end Transfer_Pragma;
-- Local variables
Items : constant Node_Id := Contract (E);
Actuals : List_Id := No_List;
Call : Node_Id;
Call_Nam : Node_Id;
Decls : List_Id := No_List;
Formals : List_Id;
Has_Pragma : Boolean := False;
Index_Id : Entity_Id;
Obj_Id : Entity_Id;
Prag : Node_Id;
Wrapper_Id : Entity_Id;
-- Start of processing for Build_Contract_Wrapper
begin
-- This routine generates a specialized wrapper for a protected or task
-- entry [family] which implements precondition/postcondition semantics.
-- Preconditions and case guards of contract cases are checked before
-- the protected action or rendezvous takes place. Postconditions and
-- consequences of contract cases are checked after the protected action
-- or rendezvous takes place. The structure of the generated wrapper is
-- as follows:
-- procedure Wrapper
-- (Obj_Id : Conc_Typ; -- concurrent object
-- [Index : Index_Typ;] -- index of entry family
-- [Formal_1 : ...; -- parameters of original entry
-- Formal_N : ...])
-- is
-- [Discr_1 : ... renames Obj_Id.Discr_1; -- discriminant
-- Discr_N : ... renames Obj_Id.Discr_N;] -- renamings
-- <precondition checks>
-- <case guard checks>
-- procedure _Postconditions is
-- begin
-- <postcondition checks>
-- <consequence checks>
-- end _Postconditions;
-- begin
-- Entry_Call (Obj_Id, [Index,] [Formal_1, Formal_N]);
-- _Postconditions;
-- end Wrapper;
-- Create the wrapper only when the entry has at least one executable
-- contract item such as contract cases, precondition or postcondition.
if Present (Items) then
-- Inspect the list of pre/postconditions and transfer all available
-- pragmas to the declarative list of the wrapper.
Prag := Pre_Post_Conditions (Items);
while Present (Prag) loop
if Pragma_Name_Unmapped (Prag) in Name_Postcondition
| Name_Precondition
and then Is_Checked (Prag)
then
Has_Pragma := True;
Transfer_Pragma (Prag, To => Decls);
end if;
Prag := Next_Pragma (Prag);
end loop;
-- Inspect the list of test/contract cases and transfer only contract
-- cases pragmas to the declarative part of the wrapper.
Prag := Contract_Test_Cases (Items);
while Present (Prag) loop
if Pragma_Name (Prag) = Name_Contract_Cases
and then Is_Checked (Prag)
then
Has_Pragma := True;
Transfer_Pragma (Prag, To => Decls);
end if;
Prag := Next_Pragma (Prag);
end loop;
end if;
-- The entry lacks executable contract items and a wrapper is not needed
if not Has_Pragma then
return;
end if;
-- Create the profile of the wrapper. The first formal parameter is the
-- concurrent object.
Obj_Id :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (Conc_Typ), 'A'));
Formals := New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => Obj_Id,
Out_Present => True,
In_Present => True,
Parameter_Type => New_Occurrence_Of (Conc_Typ, Loc)));
-- Construct the call to the original entry. The call will be gradually
-- augmented with an optional entry index and extra parameters.
Call_Nam :=
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (Obj_Id, Loc),
Selector_Name => New_Occurrence_Of (E, Loc));
-- When creating a wrapper for an entry family, the second formal is the
-- entry index.
if Ekind (E) = E_Entry_Family then
Index_Id := Make_Defining_Identifier (Loc, Name_I);
Append_To (Formals,
Make_Parameter_Specification (Loc,
Defining_Identifier => Index_Id,
Parameter_Type =>
New_Occurrence_Of (Entry_Index_Type (E), Loc)));
-- The call to the original entry becomes an indexed component to
-- accommodate the entry index.
Call_Nam :=
Make_Indexed_Component (Loc,
Prefix => Call_Nam,
Expressions => New_List (New_Occurrence_Of (Index_Id, Loc)));
end if;
-- Add formal parameters to match those of the entry and build actuals
-- for the entry call.
Add_Matching_Formals (Formals, Actuals);
Call :=
Make_Procedure_Call_Statement (Loc,
Name => Call_Nam,
Parameter_Associations => Actuals);
-- Add renaming declarations for the discriminants of the enclosing type
-- as the various contract items may reference them.
Add_Discriminant_Renamings (Obj_Id, Decls);
Wrapper_Id :=
Make_Defining_Identifier (Loc, New_External_Name (Chars (E), 'E'));
Set_Contract_Wrapper (E, Wrapper_Id);
Set_Is_Entry_Wrapper (Wrapper_Id);
-- The wrapper body is analyzed when the enclosing type is frozen
Append_Freeze_Action (Defining_Entity (Decl),
Make_Subprogram_Body (Loc,
Specification =>
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Wrapper_Id,
Parameter_Specifications => Formals),
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Call))));
end Build_Contract_Wrapper;
--------------------------------
-- Build_Corresponding_Record --
--------------------------------
function Build_Corresponding_Record
(N : Node_Id;
Ctyp : Entity_Id;
Loc : Source_Ptr) return Node_Id
is
Rec_Ent : constant Entity_Id :=
Make_Defining_Identifier
(Loc, New_External_Name (Chars (Ctyp), 'V'));
Disc : Entity_Id;
Dlist : List_Id;
New_Disc : Entity_Id;
Cdecls : List_Id;
begin
Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
Mutate_Ekind (Rec_Ent, E_Record_Type);
Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
Set_Is_Concurrent_Record_Type (Rec_Ent, True);
Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
Set_Stored_Constraint (Rec_Ent, No_Elist);
Cdecls := New_List;
-- Use discriminals to create list of discriminants for record, and
-- create new discriminals for use in default expressions, etc. It is
-- worth noting that a task discriminant gives rise to 5 entities;
-- a) The original discriminant.
-- b) The discriminal for use in the task.
-- c) The discriminant of the corresponding record.
-- d) The discriminal for the init proc of the corresponding record.
-- e) The local variable that renames the discriminant in the procedure
-- for the task body.
-- In fact the discriminals b) are used in the renaming declarations
-- for e). See details in einfo (Handling of Discriminants).
if Present (Discriminant_Specifications (N)) then
Dlist := New_List;
Disc := First_Discriminant (Ctyp);
while Present (Disc) loop
New_Disc := CR_Discriminant (Disc);
Append_To (Dlist,
Make_Discriminant_Specification (Loc,
Defining_Identifier => New_Disc,
Discriminant_Type =>
New_Occurrence_Of (Etype (Disc), Loc),
Expression =>
New_Copy (Discriminant_Default_Value (Disc))));
Next_Discriminant (Disc);
end loop;
else
Dlist := No_List;
end if;
-- Now we can construct the record type declaration. Note that this
-- record is "limited tagged". It is "limited" to reflect the underlying
-- limitedness of the task or protected object that it represents, and
-- ensuring for example that it is properly passed by reference. It is
-- "tagged" to give support to dispatching calls through interfaces. We
-- propagate here the list of interfaces covered by the concurrent type
-- (Ada 2005: AI-345).
return
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Rec_Ent,
Discriminant_Specifications => Dlist,
Type_Definition =>
Make_Record_Definition (Loc,
Component_List =>
Make_Component_List (Loc, Component_Items => Cdecls),
Tagged_Present =>
Ada_Version >= Ada_2005 and then Is_Tagged_Type (Ctyp),
Interface_List => Interface_List (N),
Limited_Present => True));
end Build_Corresponding_Record;
---------------------------------
-- Build_Dispatching_Tag_Check --
---------------------------------
function Build_Dispatching_Tag_Check
(K : Entity_Id;
N : Node_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (N);
begin
return
Make_Op_Or (Loc,
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (K, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (RE_TK_Limited_Tagged), Loc)),
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (K, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (RE_TK_Tagged), Loc)));
end Build_Dispatching_Tag_Check;
----------------------------------
-- Build_Entry_Count_Expression --
----------------------------------
function Build_Entry_Count_Expression
(Concurrent_Type : Node_Id;
Component_List : List_Id;
Loc : Source_Ptr) return Node_Id
is
Eindx : Nat;
Ent : Entity_Id;
Ecount : Node_Id;
Comp : Node_Id;
Lo : Node_Id;
Hi : Node_Id;
Typ : Entity_Id;
Large : Boolean;
begin
-- Count number of non-family entries
Eindx := 0;
Ent := First_Entity (Concurrent_Type);
while Present (Ent) loop
if Ekind (Ent) = E_Entry then
Eindx := Eindx + 1;
end if;
Next_Entity (Ent);
end loop;
Ecount := Make_Integer_Literal (Loc, Eindx);
-- Loop through entry families building the addition nodes
Ent := First_Entity (Concurrent_Type);
Comp := First (Component_List);
while Present (Ent) loop
if Ekind (Ent) = E_Entry_Family then
while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
Next (Comp);
end loop;
Typ := Entry_Index_Type (Ent);
Hi := Type_High_Bound (Typ);
Lo := Type_Low_Bound (Typ);
Large := Is_Potentially_Large_Family
(Base_Type (Typ), Concurrent_Type, Lo, Hi);
Ecount :=
Make_Op_Add (Loc,
Left_Opnd => Ecount,
Right_Opnd =>
Family_Size (Loc, Hi, Lo, Concurrent_Type, Large));
end if;
Next_Entity (Ent);
end loop;
return Ecount;
end Build_Entry_Count_Expression;
------------------------------
-- Build_Master_Declaration --
------------------------------
function Build_Master_Declaration (Loc : Source_Ptr) return Node_Id is
Master_Decl : Node_Id;
begin
-- Generate a dummy master if tasks or tasking hierarchies are
-- prohibited.
-- _Master : constant Integer := Library_Task_Level;
if not Tasking_Allowed
or else Restrictions.Set (No_Task_Hierarchy)
or else not RTE_Available (RE_Current_Master)
then
Master_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uMaster),
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (Standard_Integer, Loc),
Expression =>
Make_Integer_Literal (Loc, Library_Task_Level));
-- Generate:
-- _master : constant Integer := Current_Master.all;
else
Master_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uMaster),
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (Standard_Integer, Loc),
Expression =>
Make_Explicit_Dereference (Loc,
New_Occurrence_Of (RTE (RE_Current_Master), Loc)));
end if;
return Master_Decl;
end Build_Master_Declaration;
---------------------------
-- Build_Parameter_Block --
---------------------------
function Build_Parameter_Block
(Loc : Source_Ptr;
Actuals : List_Id;
Formals : List_Id;
Decls : List_Id) return Entity_Id
is
Actual : Entity_Id;
Comp_Nam : Node_Id;
Comps : List_Id;
Formal : Entity_Id;
Has_Comp : Boolean := False;
Rec_Nam : Node_Id;
begin
Actual := First (Actuals);
Comps := New_List;
Formal := Defining_Identifier (First (Formals));
while Present (Actual) loop
if not Is_Controlling_Actual (Actual) then
-- Generate:
-- type Ann is access all <actual-type>
Comp_Nam := Make_Temporary (Loc, 'A');
Set_Is_Param_Block_Component_Type (Comp_Nam);
Append_To (Decls,
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Comp_Nam,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
All_Present => True,
Constant_Present => Ekind (Formal) = E_In_Parameter,
Subtype_Indication =>
New_Occurrence_Of (Etype (Actual), Loc))));
-- Generate:
-- Param : Ann;
Append_To (Comps,
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Chars (Formal)),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present =>
False,
Subtype_Indication =>
New_Occurrence_Of (Comp_Nam, Loc))));
Has_Comp := True;
end if;
Next_Actual (Actual);
Next_Formal_With_Extras (Formal);
end loop;
Rec_Nam := Make_Temporary (Loc, 'P');
if Has_Comp then
-- Generate:
-- type Pnn is record
-- Param1 : Ann1;
-- ...
-- ParamN : AnnN;
-- where Pnn is a parameter wrapping record, Param1 .. ParamN are
-- the original parameter names and Ann1 .. AnnN are the access to
-- actual types.
Append_To (Decls,
Make_Full_Type_Declaration (Loc,
Defining_Identifier =>
Rec_Nam,
Type_Definition =>
Make_Record_Definition (Loc,
Component_List =>
Make_Component_List (Loc, Comps))));
else
-- Generate:
-- type Pnn is null record;
Append_To (Decls,
Make_Full_Type_Declaration (Loc,
Defining_Identifier =>
Rec_Nam,
Type_Definition =>
Make_Record_Definition (Loc,
Null_Present => True,
Component_List => Empty)));
end if;
return Rec_Nam;
end Build_Parameter_Block;
--------------------------------------
-- Build_Renamed_Formal_Declaration --
--------------------------------------
function Build_Renamed_Formal_Declaration
(New_F : Entity_Id;
Formal : Entity_Id;
Comp : Entity_Id;
Renamed_Formal : Node_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (New_F);
Decl : Node_Id;
begin
-- If the formal is a tagged incomplete type, it is already passed
-- by reference, so it is sufficient to rename the pointer component
-- that corresponds to the actual. Otherwise we need to dereference
-- the pointer component to obtain the actual.
if Is_Incomplete_Type (Etype (Formal))
and then Is_Tagged_Type (Etype (Formal))
then
Decl :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => New_F,
Subtype_Mark => New_Occurrence_Of (Etype (Comp), Loc),
Name => Renamed_Formal);
else
Decl :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => New_F,
Subtype_Mark => New_Occurrence_Of (Etype (Formal), Loc),
Name =>
Make_Explicit_Dereference (Loc, Renamed_Formal));
end if;
return Decl;
end Build_Renamed_Formal_Declaration;
--------------------------
-- Build_Wrapper_Bodies --
--------------------------
procedure Build_Wrapper_Bodies
(Loc : Source_Ptr;
Typ : Entity_Id;
N : Node_Id)
is
Rec_Typ : Entity_Id;
function Build_Wrapper_Body
(Loc : Source_Ptr;
Subp_Id : Entity_Id;
Obj_Typ : Entity_Id;
Formals : List_Id) return Node_Id;
-- Ada 2005 (AI-345): Build the body that wraps a primitive operation
-- associated with a protected or task type. Subp_Id is the subprogram
-- name which will be wrapped. Obj_Typ is the type of the new formal
-- parameter which handles dispatching and object notation. Formals are
-- the original formals of Subp_Id which will be explicitly replicated.
------------------------
-- Build_Wrapper_Body --
------------------------
function Build_Wrapper_Body
(Loc : Source_Ptr;
Subp_Id : Entity_Id;
Obj_Typ : Entity_Id;
Formals : List_Id) return Node_Id
is
Body_Spec : Node_Id;
begin
Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
-- The subprogram is not overriding or is not a primitive declared
-- between two views.
if No (Body_Spec) then
return Empty;
end if;
declare
Actuals : List_Id := No_List;
Conv_Id : Node_Id;
First_Form : Node_Id;
Formal : Node_Id;
Nam : Node_Id;
begin
-- Map formals to actuals. Use the list built for the wrapper
-- spec, skipping the object notation parameter.
First_Form := First (Parameter_Specifications (Body_Spec));
Formal := First_Form;
Next (Formal);
if Present (Formal) then
Actuals := New_List;
while Present (Formal) loop
Append_To (Actuals,
Make_Identifier (Loc,
Chars => Chars (Defining_Identifier (Formal))));
Next (Formal);
end loop;
end if;
-- Special processing for primitives declared between a private
-- type and its completion: the wrapper needs a properly typed
-- parameter if the wrapped operation has a controlling first
-- parameter. Note that this might not be the case for a function
-- with a controlling result.
if Is_Private_Primitive_Subprogram (Subp_Id) then
if No (Actuals) then
Actuals := New_List;
end if;
if Is_Controlling_Formal (First_Formal (Subp_Id)) then
Prepend_To (Actuals,
Unchecked_Convert_To
(Corresponding_Concurrent_Type (Obj_Typ),
Make_Identifier (Loc, Name_uO)));
else
Prepend_To (Actuals,
Make_Identifier (Loc,
Chars => Chars (Defining_Identifier (First_Form))));
end if;
Nam := New_Occurrence_Of (Subp_Id, Loc);
else
-- An access-to-variable object parameter requires an explicit
-- dereference in the unchecked conversion. This case occurs
-- when a protected entry wrapper must override an interface
-- level procedure with interface access as first parameter.
-- O.all.Subp_Id (Formal_1, ..., Formal_N)
if Nkind (Parameter_Type (First_Form)) =
N_Access_Definition
then
Conv_Id :=
Make_Explicit_Dereference (Loc,
Prefix => Make_Identifier (Loc, Name_uO));
else
Conv_Id := Make_Identifier (Loc, Name_uO);
end if;
Nam :=
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To
(Corresponding_Concurrent_Type (Obj_Typ), Conv_Id),
Selector_Name => New_Occurrence_Of (Subp_Id, Loc));
end if;
-- Create the subprogram body. For a function, the call to the
-- actual subprogram has to be converted to the corresponding
-- record if it is a controlling result.
if Ekind (Subp_Id) = E_Function then
declare
Res : Node_Id;
begin
Res :=
Make_Function_Call (Loc,
Name => Nam,
Parameter_Associations => Actuals);
if Has_Controlling_Result (Subp_Id) then
Res :=
Unchecked_Convert_To
(Corresponding_Record_Type (Etype (Subp_Id)), Res);
end if;
return
Make_Subprogram_Body (Loc,
Specification => Body_Spec,
Declarations => Empty_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Simple_Return_Statement (Loc, Res))));
end;
else
return
Make_Subprogram_Body (Loc,
Specification => Body_Spec,
Declarations => Empty_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Procedure_Call_Statement (Loc,
Name => Nam,
Parameter_Associations => Actuals))));
end if;
end;
end Build_Wrapper_Body;
-- Start of processing for Build_Wrapper_Bodies
begin
if Is_Concurrent_Type (Typ) then
Rec_Typ := Corresponding_Record_Type (Typ);
else
Rec_Typ := Typ;
end if;
-- Generate wrapper bodies for a concurrent type which implements an
-- interface.
if Present (Interfaces (Rec_Typ)) then
declare
Insert_Nod : Node_Id;
Prim : Entity_Id;
Prim_Elmt : Elmt_Id;
Prim_Decl : Node_Id;
Subp : Entity_Id;
Wrap_Body : Node_Id;
Wrap_Id : Entity_Id;
begin
Insert_Nod := N;
-- Examine all primitive operations of the corresponding record
-- type, looking for wrapper specs. Generate bodies in order to
-- complete them.
Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
while Present (Prim_Elmt) loop
Prim := Node (Prim_Elmt);
if (Ekind (Prim) = E_Function
or else Ekind (Prim) = E_Procedure)
and then Is_Primitive_Wrapper (Prim)
then
Subp := Wrapped_Entity (Prim);
Prim_Decl := Parent (Parent (Prim));
Wrap_Body :=
Build_Wrapper_Body (Loc,
Subp_Id => Subp,
Obj_Typ => Rec_Typ,
Formals => Parameter_Specifications (Parent (Subp)));
Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
Set_Corresponding_Spec (Wrap_Body, Prim);
Set_Corresponding_Body (Prim_Decl, Wrap_Id);
Insert_After (Insert_Nod, Wrap_Body);
Insert_Nod := Wrap_Body;
Analyze (Wrap_Body);
end if;
Next_Elmt (Prim_Elmt);
end loop;
end;
end if;
end Build_Wrapper_Bodies;
------------------------
-- Build_Wrapper_Spec --
------------------------
function Build_Wrapper_Spec
(Subp_Id : Entity_Id;
Obj_Typ : Entity_Id;
Formals : List_Id) return Node_Id
is
function Overriding_Possible
(Iface_Op : Entity_Id;
Wrapper : Entity_Id) return Boolean;
-- Determine whether a primitive operation can be overridden by Wrapper.
-- Iface_Op is the candidate primitive operation of an interface type,
-- Wrapper is the generated entry wrapper.
function Replicate_Formals
(Loc : Source_Ptr;
Formals : List_Id) return List_Id;
-- An explicit parameter replication is required due to the Is_Entry_
-- Formal flag being set for all the formals of an entry. The explicit
-- replication removes the flag that would otherwise cause a different
-- path of analysis.
-------------------------
-- Overriding_Possible --
-------------------------
function Overriding_Possible
(Iface_Op : Entity_Id;
Wrapper : Entity_Id) return Boolean
is
Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
Wrapper_Spec : constant Node_Id := Parent (Wrapper);
function Type_Conformant_Parameters
(Iface_Op_Params : List_Id;
Wrapper_Params : List_Id) return Boolean;
-- Determine whether the parameters of the generated entry wrapper
-- and those of a primitive operation are type conformant. During
-- this check, the first parameter of the primitive operation is
-- skipped if it is a controlling argument: protected functions
-- may have a controlling result.
--------------------------------
-- Type_Conformant_Parameters --
--------------------------------
function Type_Conformant_Parameters
(Iface_Op_Params : List_Id;
Wrapper_Params : List_Id) return Boolean
is
Iface_Op_Param : Node_Id;
Iface_Op_Typ : Entity_Id;
Wrapper_Param : Node_Id;
Wrapper_Typ : Entity_Id;
begin
-- Skip the first (controlling) parameter of primitive operation
Iface_Op_Param := First (Iface_Op_Params);
if Present (First_Formal (Iface_Op))
and then Is_Controlling_Formal (First_Formal (Iface_Op))
then
Next (Iface_Op_Param);
end if;
Wrapper_Param := First (Wrapper_Params);
while Present (Iface_Op_Param)
and then Present (Wrapper_Param)
loop
Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
-- The two parameters must be mode conformant
if not Conforming_Types
(Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
then
return False;
end if;
Next (Iface_Op_Param);
Next (Wrapper_Param);
end loop;
-- One of the lists is longer than the other
if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
return False;
end if;
return True;
end Type_Conformant_Parameters;
-- Start of processing for Overriding_Possible
begin
if Chars (Iface_Op) /= Chars (Wrapper) then
return False;
end if;
-- If an inherited subprogram is implemented by a protected procedure
-- or an entry, then the first parameter of the inherited subprogram
-- must be of mode OUT or IN OUT, or access-to-variable parameter.
if Ekind (Iface_Op) = E_Procedure
and then Present (Parameter_Specifications (Iface_Op_Spec))
then
declare
Obj_Param : constant Node_Id :=
First (Parameter_Specifications (Iface_Op_Spec));
begin
if not Out_Present (Obj_Param)
and then Nkind (Parameter_Type (Obj_Param)) /=
N_Access_Definition
then
return False;
end if;
end;
end if;
return
Type_Conformant_Parameters
(Parameter_Specifications (Iface_Op_Spec),
Parameter_Specifications (Wrapper_Spec));
end Overriding_Possible;
-----------------------
-- Replicate_Formals --
-----------------------
function Replicate_Formals
(Loc : Source_Ptr;
Formals : List_Id) return List_Id
is
New_Formals : constant List_Id := New_List;
Formal : Node_Id;
Param_Type : Node_Id;
begin
Formal := First (Formals);
-- Skip the object parameter when dealing with primitives declared
-- between two views.
if Is_Private_Primitive_Subprogram (Subp_Id)
and then not Has_Controlling_Result (Subp_Id)
then
Next (Formal);
end if;
while Present (Formal) loop
-- Create an explicit copy of the entry parameter
-- When creating the wrapper subprogram for a primitive operation
-- of a protected interface we must construct an equivalent
-- signature to that of the overriding operation. For regular
-- parameters we can just use the type of the formal, but for
-- access to subprogram parameters we need to reanalyze the
-- parameter type to create local entities for the signature of
-- the subprogram type. Using the entities of the overriding
-- subprogram will result in out-of-scope errors in the back-end.
if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
else
Param_Type :=
New_Occurrence_Of (Etype (Parameter_Type (Formal)), Loc);
end if;
Append_To (New_Formals,
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc,
Chars => Chars (Defining_Identifier (Formal))),
In_Present => In_Present (Formal),
Out_Present => Out_Present (Formal),
Null_Exclusion_Present => Null_Exclusion_Present (Formal),
Parameter_Type => Param_Type));
Next (Formal);
end loop;
return New_Formals;
end Replicate_Formals;
-- Local variables
Loc : constant Source_Ptr := Sloc (Subp_Id);
First_Param : Node_Id := Empty;
Iface : Entity_Id;
Iface_Elmt : Elmt_Id;
Iface_Op : Entity_Id;
Iface_Op_Elmt : Elmt_Id;
Overridden_Subp : Entity_Id;
-- Start of processing for Build_Wrapper_Spec
begin
-- No point in building wrappers for untagged concurrent types
pragma Assert (Is_Tagged_Type (Obj_Typ));
-- Check if this subprogram has a profile that matches some interface
-- primitive.
Check_Synchronized_Overriding (Subp_Id, Overridden_Subp);
if Present (Overridden_Subp) then
First_Param :=
First (Parameter_Specifications (Parent (Overridden_Subp)));
-- An entry or a protected procedure can override a routine where the
-- controlling formal is either IN OUT, OUT or is of access-to-variable
-- type. Since the wrapper must have the exact same signature as that of
-- the overridden subprogram, we try to find the overriding candidate
-- and use its controlling formal.
-- Check every implemented interface
elsif Present (Interfaces (Obj_Typ)) then
Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
Search : while Present (Iface_Elmt) loop
Iface := Node (Iface_Elmt);
-- Check every interface primitive
if Present (Primitive_Operations (Iface)) then
Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
while Present (Iface_Op_Elmt) loop
Iface_Op := Node (Iface_Op_Elmt);
-- Ignore predefined primitives
if not Is_Predefined_Dispatching_Operation (Iface_Op) then
Iface_Op := Ultimate_Alias (Iface_Op);
-- The current primitive operation can be overridden by
-- the generated entry wrapper.
if Overriding_Possible (Iface_Op, Subp_Id) then
First_Param :=
First (Parameter_Specifications (Parent (Iface_Op)));
exit Search;
end if;
end if;
Next_Elmt (Iface_Op_Elmt);
end loop;
end if;
Next_Elmt (Iface_Elmt);
end loop Search;
end if;
-- Do not generate the wrapper if no interface primitive is covered by
-- the subprogram and it is not a primitive declared between two views
-- (see Process_Full_View).
if No (First_Param)
and then not Is_Private_Primitive_Subprogram (Subp_Id)
then
return Empty;
end if;
declare
Wrapper_Id : constant Entity_Id :=
Make_Defining_Identifier (Loc, Chars (Subp_Id));
New_Formals : List_Id;
Obj_Param : Node_Id;
Obj_Param_Typ : Entity_Id;
begin
-- Minimum decoration is needed to catch the entity in
-- Sem_Ch6.Override_Dispatching_Operation.
if Ekind (Subp_Id) = E_Function then
Mutate_Ekind (Wrapper_Id, E_Function);
else
Mutate_Ekind (Wrapper_Id, E_Procedure);
end if;
Set_Is_Primitive_Wrapper (Wrapper_Id);
Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
Set_Is_Private_Primitive (Wrapper_Id,
Is_Private_Primitive_Subprogram (Subp_Id));
-- Process the formals
New_Formals := Replicate_Formals (Loc, Formals);
-- A function with a controlling result and no first controlling
-- formal needs no additional parameter.
if Has_Controlling_Result (Subp_Id)
and then
(No (First_Formal (Subp_Id))
or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
then
null;
-- Routine Subp_Id has been found to override an interface primitive.
-- If the interface operation has an access parameter, create a copy
-- of it, with the same null exclusion indicator if present.
elsif Present (First_Param) then
if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
Obj_Param_Typ :=
Make_Access_Definition (Loc,
Subtype_Mark =>
New_Occurrence_Of (Obj_Typ, Loc),
Null_Exclusion_Present =>
Null_Exclusion_Present (Parameter_Type (First_Param)),
Constant_Present =>
Constant_Present (Parameter_Type (First_Param)));
else
Obj_Param_Typ := New_Occurrence_Of (Obj_Typ, Loc);
end if;
Obj_Param :=
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc,
Chars => Name_uO),
In_Present => In_Present (First_Param),
Out_Present => Out_Present (First_Param),
Parameter_Type => Obj_Param_Typ);
Prepend_To (New_Formals, Obj_Param);
-- If we are dealing with a primitive declared between two views,
-- implemented by a synchronized operation, we need to create
-- a default parameter. The mode of the parameter must match that
-- of the primitive operation.
else
pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
Obj_Param :=
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uO),
In_Present =>
In_Present (Parent (First_Entity (Subp_Id))),
Out_Present => Ekind (Subp_Id) /= E_Function,
Parameter_Type => New_Occurrence_Of (Obj_Typ, Loc));
Prepend_To (New_Formals, Obj_Param);
end if;
-- Build the final spec. If it is a function with a controlling
-- result, it is a primitive operation of the corresponding
-- record type, so mark the spec accordingly.
if Ekind (Subp_Id) = E_Function then
declare
Res_Def : Node_Id;
begin
if Has_Controlling_Result (Subp_Id) then
Res_Def :=
New_Occurrence_Of
(Corresponding_Record_Type (Etype (Subp_Id)), Loc);
else
Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
end if;
return
Make_Function_Specification (Loc,
Defining_Unit_Name => Wrapper_Id,
Parameter_Specifications => New_Formals,
Result_Definition => Res_Def);
end;
else
return
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Wrapper_Id,
Parameter_Specifications => New_Formals);
end if;
end;
end Build_Wrapper_Spec;
-------------------------
-- Build_Wrapper_Specs --
-------------------------
procedure Build_Wrapper_Specs
(Loc : Source_Ptr;
Typ : Entity_Id;
N : in out Node_Id)
is
Def : Node_Id;
Rec_Typ : Entity_Id;
procedure Scan_Declarations (L : List_Id);
-- Common processing for visible and private declarations
-- of a protected type.
procedure Scan_Declarations (L : List_Id) is
Decl : Node_Id;
Wrap_Decl : Node_Id;
Wrap_Spec : Node_Id;
begin
if No (L) then
return;
end if;
Decl := First (L);
while Present (Decl) loop
Wrap_Spec := Empty;
if Nkind (Decl) = N_Entry_Declaration
and then Ekind (Defining_Identifier (Decl)) = E_Entry
then
Wrap_Spec :=
Build_Wrapper_Spec
(Subp_Id => Defining_Identifier (Decl),
Obj_Typ => Rec_Typ,
Formals => Parameter_Specifications (Decl));
elsif Nkind (Decl) = N_Subprogram_Declaration then
Wrap_Spec :=
Build_Wrapper_Spec
(Subp_Id => Defining_Unit_Name (Specification (Decl)),
Obj_Typ => Rec_Typ,
Formals =>
Parameter_Specifications (Specification (Decl)));
end if;
if Present (Wrap_Spec) then
Wrap_Decl :=
Make_Subprogram_Declaration (Loc,
Specification => Wrap_Spec);
Insert_After (N, Wrap_Decl);
N := Wrap_Decl;
Analyze (Wrap_Decl);
end if;
Next (Decl);
end loop;
end Scan_Declarations;
-- start of processing for Build_Wrapper_Specs
begin
if Is_Protected_Type (Typ) then
Def := Protected_Definition (Parent (Typ));
else pragma Assert (Is_Task_Type (Typ));
Def := Task_Definition (Parent (Typ));
end if;
Rec_Typ := Corresponding_Record_Type (Typ);
-- Generate wrapper specs for a concurrent type which implements an
-- interface. Operations in both the visible and private parts may
-- implement progenitor operations.
if Present (Interfaces (Rec_Typ)) and then Present (Def) then
Scan_Declarations (Visible_Declarations (Def));
Scan_Declarations (Private_Declarations (Def));
end if;
end Build_Wrapper_Specs;
---------------------------
-- Build_Find_Body_Index --
---------------------------
function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (Typ);
Ent : Entity_Id;
E_Typ : Entity_Id;
Has_F : Boolean := False;
Index : Nat;
If_St : Node_Id := Empty;
Lo : Node_Id;
Hi : Node_Id;
Decls : List_Id := New_List;
Ret : Node_Id := Empty;
Spec : Node_Id;
Siz : Node_Id := Empty;
procedure Add_If_Clause (Expr : Node_Id);
-- Add test for range of current entry
function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
-- If a bound of an entry is given by a discriminant, retrieve the
-- actual value of the discriminant from the enclosing object.
-------------------
-- Add_If_Clause --
-------------------
procedure Add_If_Clause (Expr : Node_Id) is
Cond : Node_Id;
Stats : constant List_Id :=
New_List (
Make_Simple_Return_Statement (Loc,
Expression => Make_Integer_Literal (Loc, Index + 1)));
begin
-- Index for current entry body
Index := Index + 1;
-- Compute total length of entry queues so far
if No (Siz) then
Siz := Expr;
else
Siz :=
Make_Op_Add (Loc,
Left_Opnd => Siz,
Right_Opnd => Expr);
end if;
Cond :=
Make_Op_Le (Loc,
Left_Opnd => Make_Identifier (Loc, Name_uE),
Right_Opnd => Siz);
-- Map entry queue indexes in the range of the current family
-- into the current index, that designates the entry body.
if No (If_St) then
If_St :=
Make_Implicit_If_Statement (Typ,
Condition => Cond,
Then_Statements => Stats,
Elsif_Parts => New_List);
Ret := If_St;
else
Append_To (Elsif_Parts (If_St),
Make_Elsif_Part (Loc,
Condition => Cond,
Then_Statements => Stats));
end if;
end Add_If_Clause;
------------------------------
-- Convert_Discriminant_Ref --
------------------------------
function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
B : Node_Id;
begin
if Is_Entity_Name (Bound)
and then Ekind (Entity (Bound)) = E_Discriminant
then
B :=
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To (Corresponding_Record_Type (Typ),
Make_Explicit_Dereference (Loc,
Make_Identifier (Loc, Name_uObject))),
Selector_Name => Make_Identifier (Loc, Chars (Bound)));
Set_Etype (B, Etype (Entity (Bound)));
else
B := New_Copy_Tree (Bound);
end if;
return B;
end Convert_Discriminant_Ref;
-- Start of processing for Build_Find_Body_Index
begin
Spec := Build_Find_Body_Index_Spec (Typ);
Ent := First_Entity (Typ);
while Present (Ent) loop
if Ekind (Ent) = E_Entry_Family then
Has_F := True;
exit;
end if;
Next_Entity (Ent);
end loop;
if not Has_F then
-- If the protected type has no entry families, there is a one-one
-- correspondence between entry queue and entry body.
Ret :=
Make_Simple_Return_Statement (Loc,
Expression => Make_Identifier (Loc, Name_uE));
else
-- Suppose entries e1, e2, ... have size l1, l2, ... we generate
-- the following:
-- if E <= l1 then return 1;
-- elsif E <= l1 + l2 then return 2;
-- ...
Index := 0;
Siz := Empty;
Ent := First_Entity (Typ);
Add_Object_Pointer (Loc, Typ, Decls);
while Present (Ent) loop
if Ekind (Ent) = E_Entry then
Add_If_Clause (Make_Integer_Literal (Loc, 1));
elsif Ekind (Ent) = E_Entry_Family then
E_Typ := Entry_Index_Type (Ent);
Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
end if;
Next_Entity (Ent);
end loop;
if Index = 1 then
Decls := New_List;
Ret :=
Make_Simple_Return_Statement (Loc,
Expression => Make_Integer_Literal (Loc, 1));
else
pragma Assert (Present (Ret));
if Nkind (Ret) = N_If_Statement then
-- Ranges are in increasing order, so last one doesn't need
-- guard.
declare
Nod : constant Node_Id := Last (Elsif_Parts (Ret));
begin
Remove (Nod);
Set_Else_Statements (Ret, Then_Statements (Nod));
end;
end if;
end if;
end if;
return
Make_Subprogram_Body (Loc,
Specification => Spec,
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Ret)));
end Build_Find_Body_Index;
--------------------------------
-- Build_Find_Body_Index_Spec --
--------------------------------
function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (Typ);
Id : constant Entity_Id :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (Typ), 'F'));
Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
begin
return
Make_Function_Specification (Loc,
Defining_Unit_Name => Id,
Parameter_Specifications => New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => Parm1,
Parameter_Type =>
New_Occurrence_Of (RTE (RE_Address), Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => Parm2,
Parameter_Type =>
New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))),
Result_Definition => New_Occurrence_Of (
RTE (RE_Protected_Entry_Index), Loc));
end Build_Find_Body_Index_Spec;
-----------------------------------------------
-- Build_Lock_Free_Protected_Subprogram_Body --
-----------------------------------------------
function Build_Lock_Free_Protected_Subprogram_Body
(N : Node_Id;
Prot_Typ : Node_Id;
Unprot_Spec : Node_Id) return Node_Id
is
Actuals : constant List_Id := New_List;
Loc : constant Source_Ptr := Sloc (N);
Spec : constant Node_Id := Specification (N);
Unprot_Id : constant Entity_Id := Defining_Unit_Name (Unprot_Spec);
Formal : Node_Id;
Prot_Spec : Node_Id;
Stmt : Node_Id;
begin
-- Create the protected version of the body
Prot_Spec :=
Build_Protected_Sub_Specification (N, Prot_Typ, Protected_Mode);
-- Build the actual parameters which appear in the call to the
-- unprotected version of the body.
Formal := First (Parameter_Specifications (Prot_Spec));
while Present (Formal) loop
Append_To (Actuals,
Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
Next (Formal);
end loop;
-- Function case, generate:
-- return <Unprot_Func_Call>;
if Nkind (Spec) = N_Function_Specification then
Stmt :=
Make_Simple_Return_Statement (Loc,
Expression =>
Make_Function_Call (Loc,
Name =>
Make_Identifier (Loc, Chars (Unprot_Id)),
Parameter_Associations => Actuals));
-- Procedure case, call the unprotected version
else
Stmt :=
Make_Procedure_Call_Statement (Loc,
Name =>
Make_Identifier (Loc, Chars (Unprot_Id)),
Parameter_Associations => Actuals);
end if;
return
Make_Subprogram_Body (Loc,
Declarations => Empty_List,
Specification => Prot_Spec,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Stmt)));
end Build_Lock_Free_Protected_Subprogram_Body;
-------------------------------------------------
-- Build_Lock_Free_Unprotected_Subprogram_Body --
-------------------------------------------------
-- Procedures which meet the lock-free implementation requirements and
-- reference a unique scalar component Comp are expanded in the following
-- manner:
-- procedure P (...) is
-- Expected_Comp : constant Comp_Type :=
-- Comp_Type
-- (System.Atomic_Primitives.Lock_Free_Read_N
-- (_Object.Comp'Address));
-- begin
-- loop
-- declare
-- <original declarations before the object renaming declaration
-- of Comp>
--
-- Desired_Comp : Comp_Type := Expected_Comp;
-- Comp : Comp_Type renames Desired_Comp;
--
-- <original declarations after the object renaming declaration
-- of Comp>
--
-- begin
-- <original statements>
-- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
-- (_Object.Comp'Address,
-- Interfaces.Unsigned_N (Expected_Comp),
-- Interfaces.Unsigned_N (Desired_Comp));
-- end;
-- end loop;
-- end P;
-- Each return and raise statement of P is transformed into an atomic
-- status check:
-- if System.Atomic_Primitives.Lock_Free_Try_Write_N
-- (_Object.Comp'Address,
-- Interfaces.Unsigned_N (Expected_Comp),
-- Interfaces.Unsigned_N (Desired_Comp));
-- then
-- <original statement>
-- else
-- goto L0;
-- end if;
-- Functions which meet the lock-free implementation requirements and
-- reference a unique scalar component Comp are expanded in the following
-- manner:
-- function F (...) return ... is
-- <original declarations before the object renaming declaration
-- of Comp>
--
-- Expected_Comp : constant Comp_Type :=
-- Comp_Type
-- (System.Atomic_Primitives.Lock_Free_Read_N
-- (_Object.Comp'Address));
-- Comp : Comp_Type renames Expected_Comp;
--
-- <original declarations after the object renaming declaration of
-- Comp>
--
-- begin
-- <original statements>
-- end F;
function Build_Lock_Free_Unprotected_Subprogram_Body
(N : Node_Id;
Prot_Typ : Node_Id) return Node_Id
is
function Referenced_Component (N : Node_Id) return Entity_Id;
-- Subprograms which meet the lock-free implementation criteria are
-- allowed to reference only one unique component. Return the prival
-- of the said component.
--------------------------
-- Referenced_Component --
--------------------------
function Referenced_Component (N : Node_Id) return Entity_Id is
Comp : Entity_Id;
Decl : Node_Id;
Source_Comp : Entity_Id := Empty;
begin
-- Find the unique source component which N references in its
-- statements.
for Index in 1 .. Lock_Free_Subprogram_Table.Last loop
declare
Element : Lock_Free_Subprogram renames
Lock_Free_Subprogram_Table.Table (Index);
begin
if Element.Sub_Body = N then
Source_Comp := Element.Comp_Id;
exit;
end if;
end;
end loop;
if No (Source_Comp) then
return Empty;
end if;
-- Find the prival which corresponds to the source component within
-- the declarations of N.
Decl := First (Declarations (N));
while Present (Decl) loop
-- Privals appear as object renamings
if Nkind (Decl) = N_Object_Renaming_Declaration then
Comp := Defining_Identifier (Decl);
if Present (Prival_Link (Comp))
and then Prival_Link (Comp) = Source_Comp
then
return Comp;
end if;
end if;
Next (Decl);
end loop;
return Empty;
end Referenced_Component;
-- Local variables
Comp : constant Entity_Id := Referenced_Component (N);
Loc : constant Source_Ptr := Sloc (N);
Hand_Stmt_Seq : Node_Id := Handled_Statement_Sequence (N);
Decls : List_Id := Declarations (N);
-- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
begin
-- Add renamings for the protection object, discriminals, privals, and
-- the entry index constant for use by debugger.
Debug_Private_Data_Declarations (Decls);
-- Perform the lock-free expansion when the subprogram references a
-- protected component.
if Present (Comp) then
Protected_Component_Ref : declare
Comp_Decl : constant Node_Id := Parent (Comp);
Comp_Sel_Nam : constant Node_Id := Name (Comp_Decl);
Comp_Type : constant Entity_Id := Etype (Comp);
Is_Procedure : constant Boolean :=
Ekind (Corresponding_Spec (N)) = E_Procedure;
-- Indicates if N is a protected procedure body
Block_Decls : List_Id := No_List;
Try_Write : Entity_Id;
Desired_Comp : Entity_Id;
Decl : Node_Id;
Label : Node_Id;
Label_Id : Entity_Id := Empty;
Read : Entity_Id;
Expected_Comp : Entity_Id;
Stmt : Node_Id;
Stmts : List_Id :=
New_Copy_List (Statements (Hand_Stmt_Seq));
Typ_Size : Int;
Unsigned : Entity_Id;
function Process_Node (N : Node_Id) return Traverse_Result;
-- Transform a single node if it is a return statement, a raise
-- statement or a reference to Comp.
procedure Process_Stmts (Stmts : List_Id);
-- Given a statement sequence Stmts, wrap any return or raise
-- statements in the following manner:
--
-- if System.Atomic_Primitives.Lock_Free_Try_Write_N
-- (_Object.Comp'Address,
-- Interfaces.Unsigned_N (Expected_Comp),
-- Interfaces.Unsigned_N (Desired_Comp))
-- then
-- <Stmt>;
-- else
-- goto L0;
-- end if;
------------------
-- Process_Node --
------------------
function Process_Node (N : Node_Id) return Traverse_Result is
procedure Wrap_Statement (Stmt : Node_Id);
-- Wrap an arbitrary statement inside an if statement where the
-- condition does an atomic check on the state of the object.
--------------------
-- Wrap_Statement --
--------------------
procedure Wrap_Statement (Stmt : Node_Id) is
begin
-- The first time through, create the declaration of a label
-- which is used to skip the remainder of source statements
-- if the state of the object has changed.
if No (Label_Id) then
Label_Id :=
Make_Identifier (Loc, New_External_Name ('L', 0));
Set_Entity (Label_Id,
Make_Defining_Identifier (Loc, Chars (Label_Id)));
end if;
-- Generate:
-- if System.Atomic_Primitives.Lock_Free_Try_Write_N
-- (_Object.Comp'Address,
-- Interfaces.Unsigned_N (Expected_Comp),
-- Interfaces.Unsigned_N (Desired_Comp))
-- then
-- <Stmt>;
-- else
-- goto L0;
-- end if;
Rewrite (Stmt,
Make_Implicit_If_Statement (N,
Condition =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (Try_Write, Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => Relocate_Node (Comp_Sel_Nam),
Attribute_Name => Name_Address),
Unchecked_Convert_To (Unsigned,
New_Occurrence_Of (Expected_Comp, Loc)),
Unchecked_Convert_To (Unsigned,
New_Occurrence_Of (Desired_Comp, Loc)))),
Then_Statements => New_List (Relocate_Node (Stmt)),
Else_Statements => New_List (
Make_Goto_Statement (Loc,
Name =>
New_Occurrence_Of (Entity (Label_Id), Loc)))));
end Wrap_Statement;
-- Start of processing for Process_Node
begin
-- Wrap each return and raise statement that appear inside a
-- procedure. Skip the last return statement which is added by
-- default since it is transformed into an exit statement.
if Is_Procedure
and then ((Nkind (N) = N_Simple_Return_Statement
and then N /= Last (Stmts))
or else Nkind (N) = N_Extended_Return_Statement
or else (Nkind (N) in
N_Raise_xxx_Error | N_Raise_Statement
and then Comes_From_Source (N)))
then
Wrap_Statement (N);
return Skip;
end if;
-- Force reanalysis
Set_Analyzed (N, False);
return OK;
end Process_Node;
procedure Process_Nodes is new Traverse_Proc (Process_Node);
-------------------
-- Process_Stmts --
-------------------
procedure Process_Stmts (Stmts : List_Id) is
Stmt : Node_Id;
begin
Stmt := First (Stmts);
while Present (Stmt) loop
Process_Nodes (Stmt);
Next (Stmt);
end loop;
end Process_Stmts;
-- Start of processing for Protected_Component_Ref
begin
-- Get the type size
if Known_Static_Esize (Comp_Type) then
Typ_Size := UI_To_Int (Esize (Comp_Type));
-- If the Esize (Object_Size) is unknown at compile time, look at
-- the RM_Size (Value_Size) since it may have been set by an
-- explicit representation clause.
elsif Known_Static_RM_Size (Comp_Type) then
Typ_Size := UI_To_Int (RM_Size (Comp_Type));
-- Should not happen since this has already been checked in
-- Allows_Lock_Free_Implementation (see Sem_Ch9).
else
raise Program_Error;
end if;
-- Retrieve all relevant atomic routines and types
case Typ_Size is
when 8 =>
Try_Write := RTE (RE_Lock_Free_Try_Write_8);
Read := RTE (RE_Lock_Free_Read_8);
Unsigned := RTE (RE_Uint8);
when 16 =>
Try_Write := RTE (RE_Lock_Free_Try_Write_16);
Read := RTE (RE_Lock_Free_Read_16);
Unsigned := RTE (RE_Uint16);
when 32 =>
Try_Write := RTE (RE_Lock_Free_Try_Write_32);
Read := RTE (RE_Lock_Free_Read_32);
Unsigned := RTE (RE_Uint32);
when 64 =>
Try_Write := RTE (RE_Lock_Free_Try_Write_64);
Read := RTE (RE_Lock_Free_Read_64);
Unsigned := RTE (RE_Uint64);
when others =>
raise Program_Error;
end case;
-- Generate:
-- Expected_Comp : constant Comp_Type :=
-- Comp_Type
-- (System.Atomic_Primitives.Lock_Free_Read_N
-- (_Object.Comp'Address));
Expected_Comp :=
Make_Defining_Identifier (Loc,
New_External_Name (Chars (Comp), Suffix => "_saved"));
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Expected_Comp,
Object_Definition => New_Occurrence_Of (Comp_Type, Loc),
Constant_Present => True,
Expression =>
Unchecked_Convert_To (Comp_Type,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Read, Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => Relocate_Node (Comp_Sel_Nam),
Attribute_Name => Name_Address)))));
-- Protected procedures
if Is_Procedure then
-- Move the original declarations inside the generated block
Block_Decls := Decls;
-- Reset the declarations list of the protected procedure to
-- contain only Decl.
Decls := New_List (Decl);
-- Generate:
-- Desired_Comp : Comp_Type := Expected_Comp;
Desired_Comp :=
Make_Defining_Identifier (Loc,
New_External_Name (Chars (Comp), Suffix => "_current"));
-- Insert the declarations of Expected_Comp and Desired_Comp in
-- the block declarations right before the renaming of the
-- protected component.
Insert_Before (Comp_Decl,
Make_Object_Declaration (Loc,
Defining_Identifier => Desired_Comp,
Object_Definition => New_Occurrence_Of (Comp_Type, Loc),
Expression =>
New_Occurrence_Of (Expected_Comp, Loc)));
-- Protected function
else
Desired_Comp := Expected_Comp;
-- Insert the declaration of Expected_Comp in the function
-- declarations right before the renaming of the protected
-- component.
Insert_Before (Comp_Decl, Decl);
end if;
-- Rewrite the protected component renaming declaration to be a
-- renaming of Desired_Comp.
-- Generate:
-- Comp : Comp_Type renames Desired_Comp;
Rewrite (Comp_Decl,
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier =>
Defining_Identifier (Comp_Decl),
Subtype_Mark =>
New_Occurrence_Of (Comp_Type, Loc),
Name =>
New_Occurrence_Of (Desired_Comp, Loc)));
-- Wrap any return or raise statements in Stmts in same the manner
-- described in Process_Stmts.
Process_Stmts (Stmts);
-- Generate:
-- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
-- (_Object.Comp'Address,
-- Interfaces.Unsigned_N (Expected_Comp),
-- Interfaces.Unsigned_N (Desired_Comp))
if Is_Procedure then
Stmt :=
Make_Exit_Statement (Loc,
Condition =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (Try_Write, Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => Relocate_Node (Comp_Sel_Nam),
Attribute_Name => Name_Address),
Unchecked_Convert_To (Unsigned,
New_Occurrence_Of (Expected_Comp, Loc)),
Unchecked_Convert_To (Unsigned,
New_Occurrence_Of (Desired_Comp, Loc)))));
-- Small optimization: transform the default return statement
-- of a procedure into the atomic exit statement.
if Nkind (Last (Stmts)) = N_Simple_Return_Statement then
Rewrite (Last (Stmts), Stmt);
else
Append_To (Stmts, Stmt);
end if;
end if;
-- Create the declaration of the label used to skip the rest of
-- the source statements when the object state changes.
if Present (Label_Id) then
Label := Make_Label (Loc, Label_Id);
Append_To (Decls,
Make_Implicit_Label_Declaration (Loc,
Defining_Identifier => Entity (Label_Id),
Label_Construct => Label));
Append_To (Stmts, Label);
end if;
-- Generate:
-- loop
-- declare
-- <Decls>
-- begin
-- <Stmts>
-- end;
-- end loop;
if Is_Procedure then
Stmts :=
New_List (
Make_Loop_Statement (Loc,
Statements => New_List (
Make_Block_Statement (Loc,
Declarations => Block_Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stmts))),
End_Label => Empty));
end if;
Hand_Stmt_Seq :=
Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts);
end Protected_Component_Ref;
end if;
-- Make an unprotected version of the subprogram for use within the same
-- object, with new name and extra parameter representing the object.
return
Make_Subprogram_Body (Loc,
Specification =>
Build_Protected_Sub_Specification (N, Prot_Typ, Unprotected_Mode),
Declarations => Decls,
Handled_Statement_Sequence => Hand_Stmt_Seq);
end Build_Lock_Free_Unprotected_Subprogram_Body;
-------------------------
-- Build_Master_Entity --
-------------------------
procedure Build_Master_Entity (Obj_Or_Typ : Entity_Id) is
Loc : constant Source_Ptr := Sloc (Obj_Or_Typ);
Context : Node_Id;
Context_Id : Entity_Id;
Decl : Node_Id;
Decls : List_Id;
Par : Node_Id;
begin
-- No action needed if the run-time has no tasking support
if Global_No_Tasking then
return;
end if;
if Is_Itype (Obj_Or_Typ) then
Par := Associated_Node_For_Itype (Obj_Or_Typ);
else
Par := Parent (Obj_Or_Typ);
end if;
-- For transient scopes check if the master entity is already defined
if Is_Type (Obj_Or_Typ)
and then Ekind (Scope (Obj_Or_Typ)) = E_Block
and then Is_Internal (Scope (Obj_Or_Typ))
then
declare
Master_Scope : constant Entity_Id :=
Find_Master_Scope (Obj_Or_Typ);
begin
if Has_Master_Entity (Master_Scope)
or else Is_Finalizer (Master_Scope)
then
return;
end if;
if Present (Current_Entity_In_Scope (Name_uMaster)) then
return;
end if;
end;
end if;
-- When creating a master for a record component which is either a task
-- or access-to-task, the enclosing record is the master scope and the
-- proper insertion point is the component list.
if Is_Record_Type (Current_Scope) then
Context := Par;
Context_Id := Current_Scope;
Decls := List_Containing (Context);
-- Default case for object declarations and access types. Note that the
-- context is updated to the nearest enclosing body, block, package, or
-- return statement.
else
Find_Enclosing_Context (Par, Context, Context_Id, Decls);
end if;
-- Nothing to do if the context already has a master; internally built
-- finalizers don't need a master.
if Has_Master_Entity (Context_Id)
or else Is_Finalizer (Context_Id)
then
return;
end if;
Decl := Build_Master_Declaration (Loc);
-- The master is inserted at the start of the declarative list of the
-- context.
Prepend_To (Decls, Decl);
-- In certain cases where transient scopes are involved, the immediate
-- scope is not always the proper master scope. Ensure that the master
-- declaration and entity appear in the same context.
if Context_Id /= Current_Scope then
Push_Scope (Context_Id);
Analyze (Decl);
Pop_Scope;
else
Analyze (Decl);
end if;
-- Mark the enclosing scope and its associated construct as being task
-- masters.
Set_Has_Master_Entity (Context_Id);
while Present (Context)
and then Nkind (Context) /= N_Compilation_Unit
loop
if Nkind (Context) in
N_Block_Statement | N_Subprogram_Body | N_Task_Body
then
Set_Is_Task_Master (Context);
exit;
elsif Nkind (Parent (Context)) = N_Subunit then
Context := Corresponding_Stub (Parent (Context));
end if;
Context := Parent (Context);
end loop;
end Build_Master_Entity;
---------------------------
-- Build_Master_Renaming --
---------------------------
procedure Build_Master_Renaming
(Ptr_Typ : Entity_Id;
Ins_Nod : Node_Id := Empty)
is
Loc : constant Source_Ptr := Sloc (Ptr_Typ);
Context : Node_Id;
Master_Decl : Node_Id;
Master_Id : Entity_Id;
begin
-- No action needed if the run-time has no tasking support
if Global_No_Tasking then
return;
end if;
-- Determine the proper context to insert the master renaming
if Present (Ins_Nod) then
Context := Ins_Nod;
elsif Is_Itype (Ptr_Typ) then
Context := Associated_Node_For_Itype (Ptr_Typ);
-- When the context references a discriminant or a component of a
-- private type and we are processing declarations in the private
-- part of the enclosing package, we must insert the master renaming
-- before the full declaration of the private type; otherwise the
-- master renaming would be inserted in the public part of the
-- package (and hence before the declaration of _master).
if In_Private_Part (Current_Scope) then
declare
Ctx : Node_Id := Context;
begin
if Nkind (Context) = N_Discriminant_Specification then
Ctx := Parent (Ctx);
else
while Nkind (Ctx) in
N_Component_Declaration | N_Component_List
loop
Ctx := Parent (Ctx);
end loop;
end if;
if Nkind (Ctx) in N_Private_Type_Declaration
| N_Private_Extension_Declaration
then
Context := Parent (Full_View (Defining_Identifier (Ctx)));
end if;
end;
end if;
else
Context := Parent (Ptr_Typ);
end if;
-- Generate:
-- <Ptr_Typ>M : Master_Id renames _Master;
-- and add a numeric suffix to the name to ensure that it is
-- unique in case other access types in nested constructs
-- are homonyms of this one.
Master_Id :=
Make_Defining_Identifier (Loc,
New_External_Name (Chars (Ptr_Typ), 'M', -1));
Master_Decl :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Master_Id,
Subtype_Mark =>
New_Occurrence_Of (Standard_Integer, Loc),
Name => Make_Identifier (Loc, Name_uMaster));
Insert_Action (Context, Master_Decl);
-- The renamed master now services the access type
Set_Master_Id (Ptr_Typ, Master_Id);
end Build_Master_Renaming;
---------------------------
-- Build_Protected_Entry --
---------------------------
function Build_Protected_Entry
(N : Node_Id;
Ent : Entity_Id;
Pid : Node_Id) return Node_Id
is
Bod_Decls : constant List_Id := New_List;
Decls : constant List_Id := Declarations (N);
End_Lab : constant Node_Id :=
End_Label (Handled_Statement_Sequence (N));
End_Loc : constant Source_Ptr :=
Sloc (Last (Statements (Handled_Statement_Sequence (N))));
-- Used for the generated call to Complete_Entry_Body
Loc : constant Source_Ptr := Sloc (N);
Bod_Id : Entity_Id;
Bod_Spec : Node_Id;
Bod_Stmts : List_Id;
Complete : Node_Id;
Ohandle : Node_Id;
Proc_Body : Node_Id;
EH_Loc : Source_Ptr;
-- Used for the exception handler, inserted at end of the body
begin
-- Set the source location on the exception handler only when debugging
-- the expanded code (see Make_Implicit_Exception_Handler).
if Debug_Generated_Code then
EH_Loc := End_Loc;
-- Otherwise the inserted code should not be visible to the debugger
else
EH_Loc := No_Location;
end if;
Bod_Id :=
Make_Defining_Identifier (Loc,
Chars => Chars (Protected_Body_Subprogram (Ent)));
Bod_Spec := Build_Protected_Entry_Specification (Loc, Bod_Id, Empty);
-- Add the following declarations:
-- type poVP is access poV;
-- _object : poVP := poVP (_O);
-- where _O is the formal parameter associated with the concurrent
-- object. These declarations are needed for Complete_Entry_Body.
Add_Object_Pointer (Loc, Pid, Bod_Decls);
-- Add renamings for all formals, the Protection object, discriminals,
-- privals and the entry index constant for use by debugger.
Add_Formal_Renamings (Bod_Spec, Bod_Decls, Ent, Loc);
Debug_Private_Data_Declarations (Decls);
-- Put the declarations and the statements from the entry
Bod_Stmts :=
New_List (
Make_Block_Statement (Loc,
Declarations => Decls,
Handled_Statement_Sequence => Handled_Statement_Sequence (N)));
-- Analyze now and reset scopes for declarations so that Scope fields
-- currently denoting the entry will now denote the block scope, and
-- the block's scope will be set to the new procedure entity.
Analyze_Statements (Bod_Stmts);
Set_Scope (Entity (Identifier (First (Bod_Stmts))), Bod_Id);
Reset_Scopes_To
(First (Bod_Stmts), Entity (Identifier (First (Bod_Stmts))));
case Corresponding_Runtime_Package (Pid) is
when System_Tasking_Protected_Objects_Entries =>
Append_To (Bod_Stmts,
Make_Procedure_Call_Statement (End_Loc,
Name =>
New_Occurrence_Of (RTE (RE_Complete_Entry_Body), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (End_Loc,
Prefix =>
Make_Selected_Component (End_Loc,
Prefix =>
Make_Identifier (End_Loc, Name_uObject),
Selector_Name =>
Make_Identifier (End_Loc, Name_uObject)),
Attribute_Name => Name_Unchecked_Access))));
when System_Tasking_Protected_Objects_Single_Entry =>
-- Historically, a call to Complete_Single_Entry_Body was
-- inserted, but it was a null procedure.
null;
when others =>
raise Program_Error;
end case;
-- When exceptions cannot be propagated, we never need to call
-- Exception_Complete_Entry_Body.
if No_Exception_Handlers_Set then
return
Make_Subprogram_Body (Loc,
Specification => Bod_Spec,
Declarations => Bod_Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Bod_Stmts,
End_Label => End_Lab));
else
Ohandle := Make_Others_Choice (Loc);
Set_All_Others (Ohandle);
case Corresponding_Runtime_Package (Pid) is
when System_Tasking_Protected_Objects_Entries =>
Complete :=
New_Occurrence_Of
(RTE (RE_Exceptional_Complete_Entry_Body), Loc);
when System_Tasking_Protected_Objects_Single_Entry =>
Complete :=
New_Occurrence_Of
(RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
when others =>
raise Program_Error;
end case;
-- Create body of entry procedure. The renaming declarations are
-- placed ahead of the block that contains the actual entry body.
Proc_Body :=
Make_Subprogram_Body (Loc,
Specification => Bod_Spec,
Declarations => Bod_Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Bod_Stmts,
End_Label => End_Lab,
Exception_Handlers => New_List (
Make_Implicit_Exception_Handler (EH_Loc,
Exception_Choices => New_List (Ohandle),
Statements => New_List (
Make_Procedure_Call_Statement (EH_Loc,
Name => Complete,
Parameter_Associations => New_List (
Make_Attribute_Reference (EH_Loc,
Prefix =>
Make_Selected_Component (EH_Loc,
Prefix =>
Make_Identifier (EH_Loc, Name_uObject),
Selector_Name =>
Make_Identifier (EH_Loc, Name_uObject)),
Attribute_Name => Name_Unchecked_Access),
Make_Function_Call (EH_Loc,
Name =>
New_Occurrence_Of
(RTE (RE_Get_GNAT_Exception), Loc)))))))));
-- Establish link between subprogram body and source entry body
Set_Corresponding_Entry_Body (Proc_Body, N);
Reset_Scopes_To (Proc_Body, Protected_Body_Subprogram (Ent));
return Proc_Body;
end if;
end Build_Protected_Entry;
-----------------------------------------
-- Build_Protected_Entry_Specification --
-----------------------------------------
function Build_Protected_Entry_Specification
(Loc : Source_Ptr;
Def_Id : Entity_Id;
Ent_Id : Entity_Id) return Node_Id
is
P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
begin
Set_Debug_Info_Needed (Def_Id);
if Present (Ent_Id) then
Append_Elmt (P, Accept_Address (Ent_Id));
end if;
return
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Def_Id,
Parameter_Specifications => New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uO),
Parameter_Type =>
New_Occurrence_Of (RTE (RE_Address), Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier => P,
Parameter_Type =>
New_Occurrence_Of (RTE (RE_Address), Loc)),
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uE),
Parameter_Type =>
New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))));
end Build_Protected_Entry_Specification;
--------------------------
-- Build_Protected_Spec --
--------------------------
function Build_Protected_Spec
(N : Node_Id;
Obj_Type : Entity_Id;
Ident : Entity_Id;
Unprotected : Boolean := False) return List_Id
is
Loc : constant Source_Ptr := Sloc (N);
Decl : Node_Id;
Formal : Entity_Id;
New_Plist : List_Id;
New_Param : Node_Id;
begin
New_Plist := New_List;
Formal := First_Formal (Ident);
while Present (Formal) loop
New_Param :=
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
Aliased_Present => Aliased_Present (Parent (Formal)),
In_Present => In_Present (Parent (Formal)),
Out_Present => Out_Present (Parent (Formal)),
Parameter_Type => New_Occurrence_Of (Etype (Formal), Loc));
if Unprotected then
Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
Mutate_Ekind (Defining_Identifier (New_Param), Ekind (Formal));
end if;
Append (New_Param, New_Plist);
Next_Formal (Formal);
end loop;
-- If the subprogram is a procedure and the context is not an access
-- to protected subprogram, the parameter is in-out. Otherwise it is
-- an in parameter.
Decl :=
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uObject),
In_Present => True,
Out_Present =>
(Etype (Ident) = Standard_Void_Type
and then not Is_RTE (Obj_Type, RE_Address)),
Parameter_Type =>
New_Occurrence_Of (Obj_Type, Loc));
Set_Debug_Info_Needed (Defining_Identifier (Decl));
Prepend_To (New_Plist, Decl);
return New_Plist;
end Build_Protected_Spec;
---------------------------------------
-- Build_Protected_Sub_Specification --
---------------------------------------
function Build_Protected_Sub_Specification
(N : Node_Id;
Prot_Typ : Entity_Id;
Mode : Subprogram_Protection_Mode) return Node_Id
is
Loc : constant Source_Ptr := Sloc (N);
Decl : Node_Id;
Def_Id : Entity_Id;
New_Id : Entity_Id;
New_Plist : List_Id;
New_Spec : Node_Id;
Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
(Dispatching_Mode => ' ',
Protected_Mode => 'P',
Unprotected_Mode => 'N');
begin
if Ekind (Defining_Unit_Name (Specification (N))) = E_Subprogram_Body
then
Decl := Unit_Declaration_Node (Corresponding_Spec (N));
else
Decl := N;
end if;
Def_Id := Defining_Unit_Name (Specification (Decl));
New_Plist :=
Build_Protected_Spec
(Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
Mode = Unprotected_Mode);
New_Id :=
Make_Defining_Identifier (Loc,
Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
-- Reference the original nondispatching subprogram since the analysis
-- of the object.operation notation may need its original name (see
-- Sem_Ch4.Names_Match).
if Mode = Dispatching_Mode then
Mutate_Ekind (New_Id, Ekind (Def_Id));
Set_Original_Protected_Subprogram (New_Id, Def_Id);
end if;
-- Link the protected or unprotected version to the original subprogram
-- it emulates.
Mutate_Ekind (New_Id, Ekind (Def_Id));
Set_Protected_Subprogram (New_Id, Def_Id);
-- The unprotected operation carries the user code, and debugging
-- information must be generated for it, even though this spec does
-- not come from source. It is also convenient to allow gdb to step
-- into the protected operation, even though it only contains lock/
-- unlock calls.
Set_Debug_Info_Needed (New_Id);
-- If a pragma Eliminate applies to the source entity, the internal
-- subprograms will be eliminated as well.
Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
-- It seems we should set Has_Nested_Subprogram here, but instead we
-- currently set it in Expand_N_Protected_Body, because the entity
-- created here isn't the one that Corresponding_Spec of the body
-- will later be set to, and that's the entity where it's needed. ???
Set_Has_Nested_Subprogram (New_Id, Has_Nested_Subprogram (Def_Id));
if Nkind (Specification (Decl)) = N_Procedure_Specification then
New_Spec :=
Make_Procedure_Specification (Loc,
Defining_Unit_Name => New_Id,
Parameter_Specifications => New_Plist);
-- Create a new specification for the anonymous subprogram type
else
New_Spec :=
Make_Function_Specification (Loc,
Defining_Unit_Name => New_Id,
Parameter_Specifications => New_Plist,
Result_Definition =>
Copy_Result_Type (Result_Definition (Specification (Decl))));
Set_Return_Present (Defining_Unit_Name (New_Spec));
end if;
return New_Spec;
end Build_Protected_Sub_Specification;
-------------------------------------
-- Build_Protected_Subprogram_Body --
-------------------------------------
function Build_Protected_Subprogram_Body
(N : Node_Id;
Pid : Node_Id;
N_Op_Spec : Node_Id) return Node_Id
is
Exc_Safe : constant Boolean := not Might_Raise (N);
-- True if N cannot raise an exception
Loc : constant Source_Ptr := Sloc (N);
Op_Spec : constant Node_Id := Specification (N);
P_Op_Spec : constant Node_Id :=
Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
Lock_Kind : RE_Id;
Lock_Name : Node_Id;
Lock_Stmt : Node_Id;
Object_Parm : Node_Id;
Pformal : Node_Id;
R : Node_Id;
Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
Stmts : List_Id;
Sub_Body : Node_Id;
Uactuals : List_Id;
Unprot_Call : Node_Id;
begin
-- Build a list of the formal parameters of the protected version of
-- the subprogram to use as the actual parameters of the unprotected
-- version.
Uactuals := New_List;
Pformal := First (Parameter_Specifications (P_Op_Spec));
while Present (Pformal) loop
Append_To (Uactuals,
Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))));
Next (Pformal);
end loop;
-- Make a call to the unprotected version of the subprogram built above
-- for use by the protected version built below.
if Nkind (Op_Spec) = N_Function_Specification then
if Exc_Safe then
R := Make_Temporary (Loc, 'R');
Unprot_Call :=
Make_Object_Declaration (Loc,
Defining_Identifier => R,
Constant_Present => True,
Object_Definition =>
New_Copy (Result_Definition (N_Op_Spec)),
Expression =>
Make_Function_Call (Loc,
Name =>
Make_Identifier (Loc,
Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
Parameter_Associations => Uactuals));
Return_Stmt :=
Make_Simple_Return_Statement (Loc,
Expression => New_Occurrence_Of (R, Loc));
else
Unprot_Call :=
Make_Simple_Return_Statement (Loc,
Expression =>
Make_Function_Call (Loc,
Name =>
Make_Identifier (Loc,
Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
Parameter_Associations => Uactuals));
end if;
if Has_Aspect (Pid, Aspect_Exclusive_Functions)
and then
(No (Find_Value_Of_Aspect (Pid, Aspect_Exclusive_Functions))
or else
Is_True (Static_Boolean (Find_Value_Of_Aspect
(Pid, Aspect_Exclusive_Functions))))
then
Lock_Kind := RE_Lock;
else
Lock_Kind := RE_Lock_Read_Only;
end if;
else
Unprot_Call :=
Make_Procedure_Call_Statement (Loc,
Name =>
Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))),
Parameter_Associations => Uactuals);
Lock_Kind := RE_Lock;
end if;
-- Wrap call in block that will be covered by an at_end handler
if not Exc_Safe then
Unprot_Call :=
Make_Block_Statement (Loc,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Unprot_Call)));
end if;
-- Make the protected subprogram body. This locks the protected
-- object and calls the unprotected version of the subprogram.
case Corresponding_Runtime_Package (Pid) is
when System_Tasking_Protected_Objects_Entries =>
Lock_Name := New_Occurrence_Of (RTE (RE_Lock_Entries), Loc);
when System_Tasking_Protected_Objects_Single_Entry =>
Lock_Name := New_Occurrence_Of (RTE (RE_Lock_Entry), Loc);
when System_Tasking_Protected_Objects =>
Lock_Name := New_Occurrence_Of (RTE (Lock_Kind), Loc);
when others =>
raise Program_Error;
end case;
Object_Parm :=
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uObject),
Selector_Name => Make_Identifier (Loc, Name_uObject)),
Attribute_Name => Name_Unchecked_Access);
Lock_Stmt :=
Make_Procedure_Call_Statement (Loc,
Name => Lock_Name,
Parameter_Associations => New_List (Object_Parm));
if Abort_Allowed then
Stmts := New_List (
Build_Runtime_Call (Loc, RE_Abort_Defer),
Lock_Stmt);
else
Stmts := New_List (Lock_Stmt);
end if;
if not Exc_Safe then
Append (Unprot_Call, Stmts);
else
if Nkind (Op_Spec) = N_Function_Specification then
Pre_Stmts := Stmts;
Stmts := Empty_List;
else
Append (Unprot_Call, Stmts);
end if;
-- Historical note: Previously, call to the cleanup was inserted
-- here. This is now done by Build_Protected_Subprogram_Call_Cleanup,
-- which is also shared by the 'not Exc_Safe' path.
Build_Protected_Subprogram_Call_Cleanup (Op_Spec, Pid, Loc, Stmts);
if Nkind (Op_Spec) = N_Function_Specification then
Append_To (Stmts, Return_Stmt);
Append_To (Pre_Stmts,
Make_Block_Statement (Loc,
Declarations => New_List (Unprot_Call),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stmts)));
Stmts := Pre_Stmts;
end if;
end if;
Sub_Body :=
Make_Subprogram_Body (Loc,
Declarations => Empty_List,
Specification => P_Op_Spec,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
-- Mark this subprogram as a protected subprogram body so that the
-- cleanup will be inserted. This is done only in the 'not Exc_Safe'
-- path as otherwise the cleanup has already been inserted.
if not Exc_Safe then
Set_Is_Protected_Subprogram_Body (Sub_Body);
end if;
return Sub_Body;
end Build_Protected_Subprogram_Body;
-------------------------------------
-- Build_Protected_Subprogram_Call --
-------------------------------------
procedure Build_Protected_Subprogram_Call
(N : Node_Id;
Name : Node_Id;
Rec : Node_Id;
External : Boolean := True)
is
Loc : constant Source_Ptr := Sloc (N);
Sub : constant Entity_Id := Entity (Name);
New_Sub : Node_Id;
Params : List_Id;
begin
if External then
New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
else
New_Sub :=
New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
end if;
if Present (Parameter_Associations (N)) then
Params := New_Copy_List_Tree (Parameter_Associations (N));
else
Params := New_List;
end if;
-- If the type is an untagged derived type, convert to the root type,
-- which is the one on which the operations are defined.
if Nkind (Rec) = N_Unchecked_Type_Conversion
and then not Is_Tagged_Type (Etype (Rec))
and then Is_Derived_Type (Etype (Rec))
then
Set_Etype (Rec, Root_Type (Etype (Rec)));
Set_Subtype_Mark (Rec,
New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
end if;
Prepend (Rec, Params);
if Ekind (Sub) = E_Procedure then
Rewrite (N,
Make_Procedure_Call_Statement (Loc,
Name => New_Sub,
Parameter_Associations => Params));
else
pragma Assert (Ekind (Sub) = E_Function);
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Sub,
Parameter_Associations => Params));
-- Preserve type of call for subsequent processing (required for
-- call to Wrap_Transient_Expression in the case of a shared passive
-- protected).
Set_Etype (N, Etype (New_Sub));
end if;
if External
and then Nkind (Rec) = N_Unchecked_Type_Conversion
and then Is_Entity_Name (Expression (Rec))
and then Is_Shared_Passive (Entity (Expression (Rec)))
then
Add_Shared_Var_Lock_Procs (N);
end if;
end Build_Protected_Subprogram_Call;
---------------------------------------------
-- Build_Protected_Subprogram_Call_Cleanup --
---------------------------------------------
procedure Build_Protected_Subprogram_Call_Cleanup
(Op_Spec : Node_Id;
Conc_Typ : Node_Id;
Loc : Source_Ptr;
Stmts : List_Id)
is
Nam : Node_Id;
begin
-- If the associated protected object has entries, a protected
-- procedure has to service entry queues. In this case generate:
-- Service_Entries (_object._object'Access);
if Nkind (Op_Spec) = N_Procedure_Specification
and then Has_Entries (Conc_Typ)
then
case Corresponding_Runtime_Package (Conc_Typ) is
when System_Tasking_Protected_Objects_Entries =>
Nam := New_Occurrence_Of (RTE (RE_Service_Entries), Loc);
when System_Tasking_Protected_Objects_Single_Entry =>
Nam := New_Occurrence_Of (RTE (RE_Service_Entry), Loc);
when others =>
raise Program_Error;
end case;
Append_To (Stmts,
Make_Procedure_Call_Statement (Loc,
Name => Nam,
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uObject),
Selector_Name => Make_Identifier (Loc, Name_uObject)),
Attribute_Name => Name_Unchecked_Access))));
else
-- Generate:
-- Unlock (_object._object'Access);
case Corresponding_Runtime_Package (Conc_Typ) is
when System_Tasking_Protected_Objects_Entries =>
Nam := New_Occurrence_Of (RTE (RE_Unlock_Entries), Loc);
when System_Tasking_Protected_Objects_Single_Entry =>
Nam := New_Occurrence_Of (RTE (RE_Unlock_Entry), Loc);
when System_Tasking_Protected_Objects =>
Nam := New_Occurrence_Of (RTE (RE_Unlock), Loc);
when others =>
raise Program_Error;
end case;
Append_To (Stmts,
Make_Procedure_Call_Statement (Loc,
Name => Nam,
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uObject),
Selector_Name => Make_Identifier (Loc, Name_uObject)),
Attribute_Name => Name_Unchecked_Access))));
end if;
-- Generate:
-- Abort_Undefer;
if Abort_Allowed then
Append_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Undefer));
end if;
end Build_Protected_Subprogram_Call_Cleanup;
-------------------------
-- Build_Selected_Name --
-------------------------
function Build_Selected_Name
(Prefix : Entity_Id;
Selector : Entity_Id;
Append_Char : Character := ' ') return Name_Id
is
Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
Select_Len : Natural;
begin
Get_Name_String (Chars (Selector));
Select_Len := Name_Len;
Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
Get_Name_String (Chars (Prefix));
-- If scope is anonymous type, discard suffix to recover name of
-- single protected object. Otherwise use protected type name.
if Name_Buffer (Name_Len) = 'T' then
Name_Len := Name_Len - 1;
end if;
Add_Str_To_Name_Buffer ("__");
for J in 1 .. Select_Len loop
Add_Char_To_Name_Buffer (Select_Buffer (J));
end loop;
-- Now add the Append_Char if specified. The encoding to follow
-- depends on the type of entity. If Append_Char is either 'N' or 'P',
-- then the entity is associated to a protected type subprogram.
-- Otherwise, it is a protected type entry. For each case, the
-- encoding to follow for the suffix is documented in exp_dbug.ads.
-- It would be better to encapsulate this as a routine in Exp_Dbug ???
if Append_Char /= ' ' then
if Append_Char in 'P' | 'N' then
Add_Char_To_Name_Buffer (Append_Char);
return Name_Find;
else
Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
return New_External_Name (Name_Find, ' ', -1);
end if;
else
return Name_Find;
end if;
end Build_Selected_Name;
-----------------------------
-- Build_Simple_Entry_Call --
-----------------------------
-- A task entry call is converted to a call to Call_Simple
-- declare
-- P : parms := (parm, parm, parm);
-- begin
-- Call_Simple (acceptor-task, entry-index, P'Address);
-- parm := P.param;
-- parm := P.param;
-- ...
-- end;
-- Here Pnn is an aggregate of the type constructed for the entry to hold
-- the parameters, and the constructed aggregate value contains either the
-- parameters or, in the case of non-elementary types, references to these
-- parameters. Then the address of this aggregate is passed to the runtime
-- routine, along with the task id value and the task entry index value.
-- Pnn is only required if parameters are present.
-- The assignments after the call are present only in the case of in-out
-- or out parameters for elementary types, and are used to assign back the
-- resulting values of such parameters.
-- Note: the reason that we insert a block here is that in the context
-- of selects, conditional entry calls etc. the entry call statement
-- appears on its own, not as an element of a list.
-- A protected entry call is converted to a Protected_Entry_Call:
-- declare
-- P : E1_Params := (param, param, param);
-- Pnn : Boolean;
-- Bnn : Communications_Block;
-- declare
-- P : E1_Params := (param, param, param);
-- Bnn : Communications_Block;
-- begin
-- Protected_Entry_Call (
-- Object => po._object'Access,
-- E => <entry index>;
-- Uninterpreted_Data => P'Address;
-- Mode => Simple_Call;
-- Block => Bnn);
-- parm := P.param;
-- parm := P.param;
-- ...
-- end;
procedure Build_Simple_Entry_Call
(N : Node_Id;
Concval : Node_Id;
Ename : Node_Id;
Index : Node_Id)
is
begin
Expand_Call (N);
-- If call has been inlined, nothing left to do
if Nkind (N) = N_Block_Statement then
return;
end if;
-- Convert entry call to Call_Simple call
declare
Loc : constant Source_Ptr := Sloc (N);
Parms : constant List_Id := Parameter_Associations (N);
Stats : constant List_Id := New_List;
Actual : Node_Id;
Call : Node_Id;
Comm_Name : Entity_Id;
Conctyp : Node_Id;
Decls : List_Id;
Ent : Entity_Id;
Ent_Acc : Entity_Id;
Formal : Node_Id;
Iface_Tag : Entity_Id;
Iface_Typ : Entity_Id;
N_Node : Node_Id;
N_Var : Node_Id;
P : Entity_Id;
Parm1 : Node_Id;
Parm2 : Node_Id;
Parm3 : Node_Id;
Pdecl : Node_Id;
Plist : List_Id;
X : Entity_Id;
Xdecl : Node_Id;
begin
-- Simple entry and entry family cases merge here
Ent := Entity (Ename);
Ent_Acc := Entry_Parameters_Type (Ent);
Conctyp := Etype (Concval);
-- Special case for protected subprogram calls
if Is_Protected_Type (Conctyp)
and then Is_Subprogram (Entity (Ename))
then
if not Is_Eliminated (Entity (Ename)) then
Build_Protected_Subprogram_Call
(N, Ename, Convert_Concurrent (Concval, Conctyp));
Analyze (N);
end if;
return;
end if;
-- First parameter is the Task_Id value from the task value or the
-- Object from the protected object value, obtained by selecting
-- the _Task_Id or _Object from the result of doing an unchecked
-- conversion to convert the value to the corresponding record type.
if Nkind (Concval) = N_Function_Call
and then Is_Task_Type (Conctyp)
and then Ada_Version >= Ada_2005
then
declare
ExpR : constant Node_Id := Relocate_Node (Concval);
Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
Decl : Node_Id;
begin
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Obj,
Object_Definition => New_Occurrence_Of (Conctyp, Loc),
Expression => ExpR);
Set_Etype (Obj, Conctyp);
Decls := New_List (Decl);
Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
end;
else
Decls := New_List;
end if;
Parm1 := Concurrent_Ref (Concval);
-- Second parameter is the entry index, computed by the routine
-- provided for this purpose. The value of this expression is
-- assigned to an intermediate variable to assure that any entry
-- family index expressions are evaluated before the entry
-- parameters.
if not Is_Protected_Type (Conctyp)
or else
Corresponding_Runtime_Package (Conctyp) =
System_Tasking_Protected_Objects_Entries
then
X := Make_Defining_Identifier (Loc, Name_uX);
Xdecl :=
Make_Object_Declaration (Loc,
Defining_Identifier => X,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
Expression => Actual_Index_Expression (
Loc, Entity (Ename), Index, Concval));
Append_To (Decls, Xdecl);
Parm2 := New_Occurrence_Of (X, Loc);
else
Xdecl := Empty;
Parm2 := Empty;
end if;
-- The third parameter is the packaged parameters. If there are
-- none, then it is just the null address, since nothing is passed.
if No (Parms) then
Parm3 := New_Occurrence_Of (RTE (RE_Null_Address), Loc);
P := Empty;
-- Case of parameters present, where third argument is the address
-- of a packaged record containing the required parameter values.
else
-- First build a list of parameter values, which are references to
-- objects of the parameter types.
Plist := New_List;
Actual := First_Actual (N);
Formal := First_Formal (Ent);
while Present (Actual) loop
-- If it is a by-copy type, copy it to a new variable. The
-- packaged record has a field that points to this variable.
if Is_By_Copy_Type (Etype (Actual)) then
N_Node :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Temporary (Loc, 'J'),
Aliased_Present => True,
Object_Definition =>
New_Occurrence_Of (Etype (Formal), Loc));
-- Mark the object as not needing initialization since the
-- initialization is performed separately, avoiding errors
-- on cases such as formals of null-excluding access types.
Set_No_Initialization (N_Node);
-- We must make a separate assignment statement for the
-- case of limited types. We cannot assign it unless the
-- Assignment_OK flag is set first. An out formal of an
-- access type or whose type has a Default_Value must also
-- be initialized from the actual (see RM 6.4.1 (13-13.1)),
-- but no constraint, predicate, or null-exclusion check is
-- applied before the call.
if Ekind (Formal) /= E_Out_Parameter
or else Is_Access_Type (Etype (Formal))
or else
(Is_Scalar_Type (Etype (Formal))
and then
Present (Default_Aspect_Value (Etype (Formal))))
then
N_Var :=
New_Occurrence_Of (Defining_Identifier (N_Node), Loc);
Set_Assignment_OK (N_Var);
Append_To (Stats,
Make_Assignment_Statement (Loc,
Name => N_Var,
Expression => Relocate_Node (Actual)));
-- Mark the object as internal, so we don't later reset
-- No_Initialization flag in Default_Initialize_Object,
-- which would lead to needless default initialization.
-- We don't set this outside the if statement, because
-- out scalar parameters without Default_Value do require
-- default initialization if Initialize_Scalars applies.
Set_Is_Internal (Defining_Identifier (N_Node));
-- If actual is an out parameter of a null-excluding
-- access type, there is access check on entry, so set
-- Suppress_Assignment_Checks on the generated statement
-- that assigns the actual to the parameter block.
Set_Suppress_Assignment_Checks (Last (Stats));
end if;
Append (N_Node, Decls);
Append_To (Plist,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Unchecked_Access,
Prefix =>
New_Occurrence_Of
(Defining_Identifier (N_Node), Loc)));
else
-- Interface class-wide formal
if Ada_Version >= Ada_2005
and then Ekind (Etype (Formal)) = E_Class_Wide_Type
and then Is_Interface (Etype (Formal))
then
Iface_Typ := Etype (Etype (Formal));
-- Generate:
-- formal_iface_type! (actual.iface_tag)'reference
Iface_Tag :=
Find_Interface_Tag (Etype (Actual), Iface_Typ);
pragma Assert (Present (Iface_Tag));
Append_To (Plist,
Make_Reference (Loc,
Unchecked_Convert_To (Iface_Typ,
Make_Selected_Component (Loc,
Prefix =>
Relocate_Node (Actual),
Selector_Name =>
New_Occurrence_Of (Iface_Tag, Loc)))));
else
-- Generate:
-- actual'reference
Append_To (Plist,
Make_Reference (Loc, Relocate_Node (Actual)));
end if;
end if;
Next_Actual (Actual);
Next_Formal_With_Extras (Formal);
end loop;
-- Now build the declaration of parameters initialized with the
-- aggregate containing this constructed parameter list.
P := Make_Defining_Identifier (Loc, Name_uP);
Pdecl :=
Make_Object_Declaration (Loc,
Defining_Identifier => P,
Object_Definition =>
New_Occurrence_Of (Designated_Type (Ent_Acc), Loc),
Expression =>
Make_Aggregate (Loc, Expressions => Plist));
Parm3 :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (P, Loc),
Attribute_Name => Name_Address);
Append (Pdecl, Decls);
end if;
-- Now we can create the call, case of protected type
if Is_Protected_Type (Conctyp) then
case Corresponding_Runtime_Package (Conctyp) is
when System_Tasking_Protected_Objects_Entries =>
-- Change the type of the index declaration
Set_Object_Definition (Xdecl,
New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc));
-- Some additional declarations for protected entry calls
if No (Decls) then
Decls := New_List;
end if;
-- Bnn : Communications_Block;
Comm_Name := Make_Temporary (Loc, 'B');
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Comm_Name,
Object_Definition =>
New_Occurrence_Of
(RTE (RE_Communication_Block), Loc)));
-- Some additional statements for protected entry calls
-- Protected_Entry_Call
-- (Object => po._object'Access,
-- E => <entry index>;
-- Uninterpreted_Data => P'Address;
-- Mode => Simple_Call;
-- Block => Bnn);
Call :=
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Protected_Entry_Call), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Unchecked_Access,
Prefix => Parm1),
Parm2,
Parm3,
New_Occurrence_Of (RTE (RE_Simple_Call), Loc),
New_Occurrence_Of (Comm_Name, Loc)));
when System_Tasking_Protected_Objects_Single_Entry =>
-- Protected_Single_Entry_Call
-- (Object => po._object'Access,
-- Uninterpreted_Data => P'Address);
Call :=
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(RTE (RE_Protected_Single_Entry_Call), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Unchecked_Access,
Prefix => Parm1),
Parm3));
when others =>
raise Program_Error;
end case;
-- Case of task type
else
Call :=
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Call_Simple), Loc),
Parameter_Associations => New_List (Parm1, Parm2, Parm3));
end if;
Append_To (Stats, Call);
-- If there are out or in/out parameters by copy add assignment
-- statements for the result values.
if Present (Parms) then
Actual := First_Actual (N);
Formal := First_Formal (Ent);
Set_Assignment_OK (Actual);
while Present (Actual) loop
if Is_By_Copy_Type (Etype (Actual))
and then Ekind (Formal) /= E_In_Parameter
then
N_Node :=
Make_Assignment_Statement (Loc,
Name => New_Copy (Actual),
Expression =>
Make_Explicit_Dereference (Loc,
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (P, Loc),
Selector_Name =>
Make_Identifier (Loc, Chars (Formal)))));
-- In all cases (including limited private types) we want
-- the assignment to be valid.
Set_Assignment_OK (Name (N_Node));
-- If the call is the triggering alternative in an
-- asynchronous select, or the entry_call alternative of a
-- conditional entry call, the assignments for in-out
-- parameters are incorporated into the statement list that
-- follows, so that there are executed only if the entry
-- call succeeds.
if (Nkind (Parent (N)) = N_Triggering_Alternative
and then N = Triggering_Statement (Parent (N)))
or else
(Nkind (Parent (N)) = N_Entry_Call_Alternative
and then N = Entry_Call_Statement (Parent (N)))
then
if No (Statements (Parent (N))) then
Set_Statements (Parent (N), New_List);
end if;
Prepend (N_Node, Statements (Parent (N)));
else
Insert_After (Call, N_Node);
end if;
end if;
Next_Actual (Actual);
Next_Formal_With_Extras (Formal);
end loop;
end if;
-- Finally, create block and analyze it
Rewrite (N,
Make_Block_Statement (Loc,
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stats)));
Analyze (N);
end;
end Build_Simple_Entry_Call;
--------------------------------
-- Build_Task_Activation_Call --
--------------------------------
procedure Build_Task_Activation_Call (N : Node_Id) is
function Activation_Call_Loc return Source_Ptr;
-- Find a suitable source location for the activation call
-------------------------
-- Activation_Call_Loc --
-------------------------
function Activation_Call_Loc return Source_Ptr is
begin
-- The activation call must carry the location of the "end" keyword
-- when the context is a package declaration.
if Nkind (N) = N_Package_Declaration then
return End_Keyword_Location (N);
-- Otherwise the activation call must carry the location of the
-- "begin" keyword.
else
return Begin_Keyword_Location (N);
end if;
end Activation_Call_Loc;
-- Local variables
Chain : Entity_Id;
Call : Node_Id;
Loc : Source_Ptr;
Name : Node_Id;
Owner : Node_Id;
Stmt : Node_Id;
-- Start of processing for Build_Task_Activation_Call
begin
-- For sequential elaboration policy, all the tasks will be activated at
-- the end of the elaboration.
if Partition_Elaboration_Policy = 'S' then
return;
-- Do not create an activation call for a package spec if the package
-- has a completing body. The activation call will be inserted after
-- the "begin" of the body.
elsif Nkind (N) = N_Package_Declaration
and then Present (Corresponding_Body (N))
then
return;
end if;
-- Obtain the activation chain entity. Block statements, entry bodies,
-- subprogram bodies, and task bodies keep the entity in their nodes.
-- Package bodies on the other hand store it in the declaration of the
-- corresponding package spec.
Owner := N;
if Nkind (Owner) = N_Package_Body then
Owner := Unit_Declaration_Node (Corresponding_Spec (Owner));
end if;
Chain := Activation_Chain_Entity (Owner);
-- Nothing to do when there are no tasks to activate. This is indicated
-- by a missing activation chain entity; also skip generating it when
-- it is a ghost entity.
if No (Chain) or else Is_Ignored_Ghost_Entity (Chain) then
return;
-- The availability of the activation chain entity does not ensure
-- that we have tasks to activate because it may have been declared
-- by the frontend to pass a required extra formal to a build-in-place
-- subprogram call. If we are within the scope of a protected type and
-- pragma Detect_Blocking is active we can assume that no tasks will be
-- activated; if tasks are created in a protected object and this pragma
-- is active then the frontend emits a warning and Program_Error is
-- raised at runtime.
elsif Detect_Blocking and then Within_Protected_Type (Current_Scope) then
return;
end if;
-- The location of the activation call must be as close as possible to
-- the intended semantic location of the activation because the ABE
-- mechanism relies heavily on accurate locations.
Loc := Activation_Call_Loc;
if Restricted_Profile then
Name := New_Occurrence_Of (RTE (RE_Activate_Restricted_Tasks), Loc);
else
Name := New_Occurrence_Of (RTE (RE_Activate_Tasks), Loc);
end if;
Call :=
Make_Procedure_Call_Statement (Loc,
Name => Name,
Parameter_Associations =>
New_List (Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Chain, Loc),
Attribute_Name => Name_Unchecked_Access)));
if Nkind (N) = N_Package_Declaration then
if Present (Private_Declarations (Specification (N))) then
Append (Call, Private_Declarations (Specification (N)));
else
Append (Call, Visible_Declarations (Specification (N)));
end if;
else
-- The call goes at the start of the statement sequence after the
-- start of exception range label if one is present.
if Present (Handled_Statement_Sequence (N)) then
Stmt := First (Statements (Handled_Statement_Sequence (N)));
-- A special case, skip exception range label if one is present
-- (from front end zcx processing).
if Nkind (Stmt) = N_Label and then Exception_Junk (Stmt) then
Next (Stmt);
end if;
-- Another special case, if the first statement is a block from
-- optimization of a local raise to a goto, then the call goes
-- inside this block.
if Nkind (Stmt) = N_Block_Statement
and then Exception_Junk (Stmt)
then
Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
end if;
-- Insertion point is after any exception label pushes, since we
-- want it covered by any local handlers.
while Nkind (Stmt) in N_Push_xxx_Label loop
Next (Stmt);
end loop;
-- Now we have the proper insertion point
Insert_Before (Stmt, Call);
else
Set_Handled_Statement_Sequence (N,
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Call)));
end if;
end if;
Analyze (Call);
if Legacy_Elaboration_Checks then
Check_Task_Activation (N);
end if;
end Build_Task_Activation_Call;
-------------------------------
-- Build_Task_Allocate_Block --
-------------------------------
procedure Build_Task_Allocate_Block
(Actions : List_Id;
N : Node_Id;
Args : List_Id)
is
T : constant Entity_Id := Entity (Expression (N));
Init : constant Entity_Id := Base_Init_Proc (T);
Loc : constant Source_Ptr := Sloc (N);
Chain : constant Entity_Id :=
Make_Defining_Identifier (Loc, Name_uChain);
Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
Block : Node_Id;
begin
Block :=
Make_Block_Statement (Loc,
Identifier => New_Occurrence_Of (Blkent, Loc),
Declarations => New_List (
-- _Chain : Activation_Chain;
Make_Object_Declaration (Loc,
Defining_Identifier => Chain,
Aliased_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Activation_Chain), Loc))),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
-- Init (Args);
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Init, Loc),
Parameter_Associations => Args),
-- Activate_Tasks (_Chain);
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Activate_Tasks), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Chain, Loc),
Attribute_Name => Name_Unchecked_Access))))),
Has_Created_Identifier => True,
Is_Task_Allocation_Block => True);
Append_To (Actions,
Make_Implicit_Label_Declaration (Loc,
Defining_Identifier => Blkent,
Label_Construct => Block));
Append_To (Actions, Block);
Set_Activation_Chain_Entity (Block, Chain);
end Build_Task_Allocate_Block;
-----------------------------------------------
-- Build_Task_Allocate_Block_With_Init_Stmts --
-----------------------------------------------
procedure Build_Task_Allocate_Block_With_Init_Stmts
(Actions : List_Id;
N : Node_Id;
Init_Stmts : List_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Chain : constant Entity_Id :=
Make_Defining_Identifier (Loc, Name_uChain);
Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
Block : Node_Id;
begin
Append_To (Init_Stmts,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Activate_Tasks), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Chain, Loc),
Attribute_Name => Name_Unchecked_Access))));
Block :=
Make_Block_Statement (Loc,
Identifier => New_Occurrence_Of (Blkent, Loc),
Declarations => New_List (
-- _Chain : Activation_Chain;
Make_Object_Declaration (Loc,
Defining_Identifier => Chain,
Aliased_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Activation_Chain), Loc))),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
Has_Created_Identifier => True,
Is_Task_Allocation_Block => True);
Append_To (Actions,
Make_Implicit_Label_Declaration (Loc,
Defining_Identifier => Blkent,
Label_Construct => Block));
Append_To (Actions, Block);
Set_Activation_Chain_Entity (Block, Chain);
end Build_Task_Allocate_Block_With_Init_Stmts;
-----------------------------------
-- Build_Task_Proc_Specification --
-----------------------------------
function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (T);
Spec_Id : Entity_Id;
begin
-- Case of explicit task type, suffix TB
if Comes_From_Source (T) then
Spec_Id :=
Make_Defining_Identifier (Loc, New_External_Name (Chars (T), "TB"));
-- Case of anonymous task type, suffix B
else
Spec_Id :=
Make_Defining_Identifier (Loc, New_External_Name (Chars (T), 'B'));
end if;
Set_Is_Internal (Spec_Id);
-- Associate the procedure with the task, if this is the declaration
-- (and not the body) of the procedure.
if No (Task_Body_Procedure (T)) then
Set_Task_Body_Procedure (T, Spec_Id);
end if;
return
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Spec_Id,
Parameter_Specifications => New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uTask),
Parameter_Type =>
Make_Access_Definition (Loc,
Subtype_Mark =>
New_Occurrence_Of (Corresponding_Record_Type (T), Loc)))));
end Build_Task_Proc_Specification;
---------------------------------------
-- Build_Unprotected_Subprogram_Body --
---------------------------------------
function Build_Unprotected_Subprogram_Body
(N : Node_Id;
Pid : Node_Id) return Node_Id
is
Decls : constant List_Id := Declarations (N);
begin
-- Add renamings for the Protection object, discriminals, privals, and
-- the entry index constant for use by debugger.
Debug_Private_Data_Declarations (Decls);
-- Make an unprotected version of the subprogram for use within the same
-- object, with a new name and an additional parameter representing the
-- object.
return
Make_Subprogram_Body (Sloc (N),
Specification =>
Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
Declarations => Decls,
Handled_Statement_Sequence => Handled_Statement_Sequence (N));
end Build_Unprotected_Subprogram_Body;
----------------------------
-- Collect_Entry_Families --
----------------------------
procedure Collect_Entry_Families
(Loc : Source_Ptr;
Cdecls : List_Id;
Current_Node : in out Node_Id;
Conctyp : Entity_Id)
is
Efam : Entity_Id;
Efam_Decl : Node_Id;
Efam_Type : Entity_Id;
begin
Efam := First_Entity (Conctyp);
while Present (Efam) loop
if Ekind (Efam) = E_Entry_Family then
Efam_Type := Make_Temporary (Loc, 'F');
declare
Eityp : constant Entity_Id := Entry_Index_Type (Efam);
Lo : constant Node_Id := Type_Low_Bound (Eityp);
Hi : constant Node_Id := Type_High_Bound (Eityp);
Bdecl : Node_Id;
Bityp : Entity_Id;
begin
Bityp := Base_Type (Eityp);
if Is_Potentially_Large_Family (Bityp, Conctyp, Lo, Hi) then
Bityp := Make_Temporary (Loc, 'B');
Bdecl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Bityp,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (Standard_Integer, Loc),
Constraint =>
Make_Range_Constraint (Loc,
Range_Expression => Make_Range (Loc,
Make_Integer_Literal
(Loc, -Entry_Family_Bound),
Make_Integer_Literal
(Loc, Entry_Family_Bound - 1)))));
Insert_After (Current_Node, Bdecl);
Current_Node := Bdecl;
Analyze (Bdecl);
end if;
Efam_Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Efam_Type,
Type_Definition =>
Make_Unconstrained_Array_Definition (Loc,
Subtype_Marks =>
(New_List (New_Occurrence_Of (Bityp, Loc))),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => False,
Subtype_Indication =>
New_Occurrence_Of (Standard_Character, Loc))));
end;
Insert_After (Current_Node, Efam_Decl);
Current_Node := Efam_Decl;
Analyze (Efam_Decl);
Append_To (Cdecls,
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Chars (Efam)),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => False,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (Efam_Type, Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (
New_Occurrence_Of (Entry_Index_Type (Efam),
Loc)))))));
end if;
Next_Entity (Efam);
end loop;
end Collect_Entry_Families;
-----------------------
-- Concurrent_Object --
-----------------------
function Concurrent_Object
(Spec_Id : Entity_Id;
Conc_Typ : Entity_Id) return Entity_Id
is
begin
-- Parameter _O or _object
if Is_Protected_Type (Conc_Typ) then
return First_Formal (Protected_Body_Subprogram (Spec_Id));
-- Parameter _task
else
pragma Assert (Is_Task_Type (Conc_Typ));
return First_Formal (Task_Body_Procedure (Conc_Typ));
end if;
end Concurrent_Object;
----------------------
-- Copy_Result_Type --
----------------------
function Copy_Result_Type (Res : Node_Id) return Node_Id is
New_Res : constant Node_Id := New_Copy_Tree (Res);
Par_Spec : Node_Id;
Formal : Entity_Id;
begin
-- If the result type is an access_to_subprogram, we must create new
-- entities for its spec.
if Nkind (New_Res) = N_Access_Definition
and then Present (Access_To_Subprogram_Definition (New_Res))
then
-- Provide new entities for the formals
Par_Spec := First (Parameter_Specifications
(Access_To_Subprogram_Definition (New_Res)));
while Present (Par_Spec) loop
Formal := Defining_Identifier (Par_Spec);
Set_Defining_Identifier (Par_Spec,
Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
Next (Par_Spec);
end loop;
end if;
return New_Res;
end Copy_Result_Type;
--------------------
-- Concurrent_Ref --
--------------------
-- The expression returned for a reference to a concurrent object has the
-- form:
-- taskV!(name)._Task_Id
-- for a task, and
-- objectV!(name)._Object
-- for a protected object. For the case of an access to a concurrent
-- object, there is an extra explicit dereference:
-- taskV!(name.all)._Task_Id
-- objectV!(name.all)._Object
-- here taskV and objectV are the types for the associated records, which
-- contain the required _Task_Id and _Object fields for tasks and protected
-- objects, respectively.
-- For the case of a task type name, the expression is
-- Self;
-- i.e. a call to the Self function which returns precisely this Task_Id
-- For the case of a protected type name, the expression is
-- objectR
-- which is a renaming of the _object field of the current object
-- record, passed into protected operations as a parameter.
function Concurrent_Ref (N : Node_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (N);
Ntyp : constant Entity_Id := Etype (N);
Dtyp : Entity_Id;
Sel : Name_Id;
function Is_Current_Task (T : Entity_Id) return Boolean;
-- Check whether the reference is to the immediately enclosing task
-- type, or to an outer one (rare but legal).
---------------------
-- Is_Current_Task --
---------------------
function Is_Current_Task (T : Entity_Id) return Boolean is
Scop : Entity_Id;
begin
Scop := Current_Scope;
while Present (Scop) and then Scop /= Standard_Standard loop
if Scop = T then
return True;
elsif Is_Task_Type (Scop) then
return False;
-- If this is a procedure nested within the task type, we must
-- assume that it can be called from an inner task, and therefore
-- cannot treat it as a local reference.
elsif Is_Overloadable (Scop) and then In_Open_Scopes (T) then
return False;
else
Scop := Scope (Scop);
end if;
end loop;
-- We know that we are within the task body, so should have found it
-- in scope.
raise Program_Error;
end Is_Current_Task;
-- Start of processing for Concurrent_Ref
begin
if Is_Access_Type (Ntyp) then
Dtyp := Designated_Type (Ntyp);
if Is_Protected_Type (Dtyp) then
Sel := Name_uObject;
else
Sel := Name_uTask_Id;
end if;
return
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
Make_Explicit_Dereference (Loc, N)),
Selector_Name => Make_Identifier (Loc, Sel));
elsif Is_Entity_Name (N) and then Is_Concurrent_Type (Entity (N)) then
if Is_Task_Type (Entity (N)) then
if Is_Current_Task (Entity (N)) then
return
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Self), Loc));
else
declare
Decl : Node_Id;
T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
T_Body : constant Node_Id :=
Parent (Corresponding_Body (Parent (Entity (N))));
begin
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => T_Self,
Object_Definition =>
New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
Expression =>
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Self), Loc)));
Prepend (Decl, Declarations (T_Body));
Analyze (Decl);
Set_Scope (T_Self, Entity (N));
return New_Occurrence_Of (T_Self, Loc);
end;
end if;
else
pragma Assert (Is_Protected_Type (Entity (N)));
return
New_Occurrence_Of (Find_Protection_Object (Current_Scope), Loc);
end if;
else
if Is_Protected_Type (Ntyp) then
Sel := Name_uObject;
elsif Is_Task_Type (Ntyp) then
Sel := Name_uTask_Id;
else
raise Program_Error;
end if;
return
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
New_Copy_Tree (N)),
Selector_Name => Make_Identifier (Loc, Sel));
end if;
end Concurrent_Ref;
------------------------
-- Convert_Concurrent --
------------------------
function Convert_Concurrent
(N : Node_Id;
Typ : Entity_Id) return Node_Id
is
begin
if not Is_Concurrent_Type (Typ) then
return N;
else
return
Unchecked_Convert_To
(Corresponding_Record_Type (Typ), New_Copy_Tree (N));
end if;
end Convert_Concurrent;
-------------------------------------
-- Create_Secondary_Stack_For_Task --
-------------------------------------
function Create_Secondary_Stack_For_Task (T : Node_Id) return Boolean is
begin
return
(Restriction_Active (No_Implicit_Heap_Allocations)
or else Restriction_Active (No_Implicit_Task_Allocations))
and then not Restriction_Active (No_Secondary_Stack)
and then Has_Rep_Pragma
(T, Name_Secondary_Stack_Size, Check_Parents => False);
end Create_Secondary_Stack_For_Task;
-------------------------------------
-- Debug_Private_Data_Declarations --
-------------------------------------
procedure Debug_Private_Data_Declarations (Decls : List_Id) is
Debug_Nod : Node_Id;
Decl : Node_Id;
begin
Decl := First (Decls);
while Present (Decl) and then not Comes_From_Source (Decl) loop
-- Declaration for concurrent entity _object and its access type,
-- along with the entry index subtype:
-- type prot_typVP is access prot_typV;
-- _object : prot_typVP := prot_typV (_O);
-- subtype Jnn is <Type of Index> range Low .. High;
if Nkind (Decl) in N_Full_Type_Declaration | N_Object_Declaration then
Set_Debug_Info_Needed (Defining_Identifier (Decl));
-- Declaration for the Protection object, discriminals, privals, and
-- entry index constant:
-- conc_typR : protection_typ renames _object._object;
-- discr_nameD : discr_typ renames _object.discr_name;
-- discr_nameD : discr_typ renames _task.discr_name;
-- prival_name : comp_typ renames _object.comp_name;
-- J : constant Jnn :=
-- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
elsif Nkind (Decl) = N_Object_Renaming_Declaration then
Set_Debug_Info_Needed (Defining_Identifier (Decl));
Debug_Nod := Debug_Renaming_Declaration (Decl);
if Present (Debug_Nod) then
Insert_After (Decl, Debug_Nod);
end if;
end if;
Next (Decl);
end loop;
end Debug_Private_Data_Declarations;
------------------------------
-- Ensure_Statement_Present --
------------------------------
procedure Ensure_Statement_Present (Loc : Source_Ptr; Alt : Node_Id) is
Stmt : Node_Id;
begin
if Opt.Suppress_Control_Flow_Optimizations
and then Is_Empty_List (Statements (Alt))
then
Stmt := Make_Null_Statement (Loc);
-- Mark NULL statement as coming from source so that it is not
-- eliminated by GIGI.
-- Another covert channel. If this is a requirement, it must be
-- documented in sinfo/einfo ???
Set_Comes_From_Source (Stmt, True);
Set_Statements (Alt, New_List (Stmt));
end if;
end Ensure_Statement_Present;
----------------------------
-- Entry_Index_Expression --
----------------------------
function Entry_Index_Expression
(Sloc : Source_Ptr;
Ent : Entity_Id;
Index : Node_Id;
Ttyp : Entity_Id) return Node_Id
is
Expr : Node_Id;
Num : Node_Id;
Lo : Node_Id;
Hi : Node_Id;
Prev : Entity_Id;
S : Node_Id;
begin
-- The queues of entries and entry families appear in textual order in
-- the associated record. The entry index is computed as the sum of the
-- number of queues for all entries that precede the designated one, to
-- which is added the index expression, if this expression denotes a
-- member of a family.
-- The following is a place holder for the count of simple entries
Num := Make_Integer_Literal (Sloc, 1);
-- We construct an expression which is a series of addition operations.
-- The first operand is the number of single entries that precede this
-- one, the second operand is the index value relative to the start of
-- the referenced family, and the remaining operands are the lengths of
-- the entry families that precede this entry, i.e. the constructed
-- expression is:
-- number_simple_entries +
-- (s'pos (index-value) - s'pos (family'first)) + 1 +
-- family'length + ...
-- where index-value is the given index value, and s is the index
-- subtype (we have to use pos because the subtype might be an
-- enumeration type preventing direct subtraction). Note that the task
-- entry array is one-indexed.
-- The upper bound of the entry family may be a discriminant, so we
-- retrieve the lower bound explicitly to compute offset, rather than
-- using the index subtype which may mention a discriminant.
if Present (Index) then
S := Entry_Index_Type (Ent);
-- First make sure the index is in range if requested. The index type
-- is the pristine Entry_Index_Type of the entry.
if Do_Range_Check (Index) then
Generate_Range_Check (Index, S, CE_Range_Check_Failed);
end if;
Expr :=
Make_Op_Add (Sloc,
Left_Opnd => Num,
Right_Opnd =>
Family_Offset
(Sloc,
Make_Attribute_Reference (Sloc,
Attribute_Name => Name_Pos,
Prefix => New_Occurrence_Of (Base_Type (S), Sloc),
Expressions => New_List (Relocate_Node (Index))),
Type_Low_Bound (S),
Ttyp,
False));
else
Expr := Num;
end if;
-- Now add lengths of preceding entries and entry families
Prev := First_Entity (Ttyp);
while Chars (Prev) /= Chars (Ent)
or else (Ekind (Prev) /= Ekind (Ent))
or else not Sem_Ch6.Type_Conformant (Ent, Prev)
loop
if Ekind (Prev) = E_Entry then
Set_Intval (Num, Intval (Num) + 1);
elsif Ekind (Prev) = E_Entry_Family then
S := Entry_Index_Type (Prev);
Lo := Type_Low_Bound (S);
Hi := Type_High_Bound (S);
Expr :=
Make_Op_Add (Sloc,
Left_Opnd => Expr,
Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
-- Other components are anonymous types to be ignored
else
null;
end if;
Next_Entity (Prev);
end loop;
return Expr;
end Entry_Index_Expression;
---------------------------
-- Establish_Task_Master --
---------------------------
procedure Establish_Task_Master (N : Node_Id) is
Call : Node_Id;
begin
if Restriction_Active (No_Task_Hierarchy) = False then
Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
-- The block may have no declarations (and nevertheless be a task
-- master) if it contains a call that may return an object that
-- contains tasks.
if No (Declarations (N)) then
Set_Declarations (N, New_List (Call));
else
Prepend_To (Declarations (N), Call);
end if;
Analyze (Call);
end if;
end Establish_Task_Master;
--------------------------------
-- Expand_Accept_Declarations --
--------------------------------
-- Part of the expansion of an accept statement involves the creation of
-- a declaration that can be referenced from the statement sequence of
-- the accept:
-- Ann : Address;
-- This declaration is inserted immediately before the accept statement
-- and it is important that it be inserted before the statements of the
-- statement sequence are analyzed. Thus it would be too late to create
-- this declaration in the Expand_N_Accept_Statement routine, which is
-- why there is a separate procedure to be called directly from Sem_Ch9.
-- Ann is used to hold the address of the record containing the parameters
-- (see Expand_N_Entry_Call for more details on how this record is built).
-- References to the parameters do an unchecked conversion of this address
-- to a pointer to the required record type, and then access the field that
-- holds the value of the required parameter. The entity for the address
-- variable is held as the top stack element (i.e. the last element) of the
-- Accept_Address stack in the corresponding entry entity, and this element
-- must be set in place before the statements are processed.
-- The above description applies to the case of a stand alone accept
-- statement, i.e. one not appearing as part of a select alternative.
-- For the case of an accept that appears as part of a select alternative
-- of a selective accept, we must still create the declaration right away,
-- since Ann is needed immediately, but there is an important difference:
-- The declaration is inserted before the selective accept, not before
-- the accept statement (which is not part of a list anyway, and so would
-- not accommodate inserted declarations)
-- We only need one address variable for the entire selective accept. So
-- the Ann declaration is created only for the first accept alternative,
-- and subsequent accept alternatives reference the same Ann variable.
-- We can distinguish the two cases by seeing whether the accept statement
-- is part of a list. If not, then it must be in an accept alternative.
-- To expand the requeue statement, a label is provided at the end of the
-- accept statement or alternative of which it is a part, so that the
-- statement can be skipped after the requeue is complete. This label is
-- created here rather than during the expansion of the accept statement,
-- because it will be needed by any requeue statements within the accept,
-- which are expanded before the accept.
procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
Loc : constant Source_Ptr := Sloc (N);
Stats : constant Node_Id := Handled_Statement_Sequence (N);
Ann : Entity_Id := Empty;
Adecl : Node_Id;
Lab : Node_Id;
Ldecl : Node_Id;
Ldecl2 : Node_Id;
begin
if Expander_Active then
-- If we have no handled statement sequence, we may need to build
-- a dummy sequence consisting of a null statement. This can be
-- skipped if the trivial accept optimization is permitted.
if not Trivial_Accept_OK
and then (No (Stats) or else Null_Statements (Statements (Stats)))
then
Set_Handled_Statement_Sequence (N,
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Make_Null_Statement (Loc))));
end if;
-- Create and declare two labels to be placed at the end of the
-- accept statement. The first label is used to allow requeues to
-- skip the remainder of entry processing. The second label is used
-- to skip the remainder of entry processing if the rendezvous
-- completes in the middle of the accept body.
if Present (Handled_Statement_Sequence (N)) then
declare
Ent : Entity_Id;
begin
Ent := Make_Temporary (Loc, 'L');
Lab := Make_Label (Loc, New_Occurrence_Of (Ent, Loc));
Ldecl :=
Make_Implicit_Label_Declaration (Loc,
Defining_Identifier => Ent,
Label_Construct => Lab);
Append (Lab, Statements (Handled_Statement_Sequence (N)));
Ent := Make_Temporary (Loc, 'L');
Lab := Make_Label (Loc, New_Occurrence_Of (Ent, Loc));
Ldecl2 :=
Make_Implicit_Label_Declaration (Loc,
Defining_Identifier => Ent,
Label_Construct => Lab);
Append (Lab, Statements (Handled_Statement_Sequence (N)));
end;
else
Ldecl := Empty;
Ldecl2 := Empty;
end if;
-- Case of stand alone accept statement
if Is_List_Member (N) then
if Present (Handled_Statement_Sequence (N)) then
Ann := Make_Temporary (Loc, 'A');
Adecl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Ann,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Address), Loc));
Insert_Before_And_Analyze (N, Adecl);
Insert_Before_And_Analyze (N, Ldecl);
Insert_Before_And_Analyze (N, Ldecl2);
end if;
-- Case of accept statement which is in an accept alternative
else
declare
Acc_Alt : constant Node_Id := Parent (N);
Sel_Acc : constant Node_Id := Parent (Acc_Alt);
Alt : Node_Id;
begin
pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
-- ??? Consider a single label for select statements
if Present (Handled_Statement_Sequence (N)) then
Prepend (Ldecl2,
Statements (Handled_Statement_Sequence (N)));
Analyze (Ldecl2);
Prepend (Ldecl,
Statements (Handled_Statement_Sequence (N)));
Analyze (Ldecl);
end if;
-- Find first accept alternative of the selective accept. A
-- valid selective accept must have at least one accept in it.
Alt := First (Select_Alternatives (Sel_Acc));
while Nkind (Alt) /= N_Accept_Alternative loop
Next (Alt);
end loop;
-- If this is the first accept statement, then we have to
-- create the Ann variable, as for the stand alone case, except
-- that it is inserted before the selective accept. Similarly,
-- a label for requeue expansion must be declared.
if N = Accept_Statement (Alt) then
Ann := Make_Temporary (Loc, 'A');
Adecl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Ann,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Address), Loc));
Insert_Before_And_Analyze (Sel_Acc, Adecl);
-- If this is not the first accept statement, then find the Ann
-- variable allocated by the first accept and use it.
else
Ann :=
Node (Last_Elmt (Accept_Address
(Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
end if;
end;
end if;
-- Merge here with Ann either created or referenced, and Adecl
-- pointing to the corresponding declaration. Remaining processing
-- is the same for the two cases.
if Present (Ann) then
Append_Elmt (Ann, Accept_Address (Ent));
Set_Debug_Info_Needed (Ann);
end if;
-- Create renaming declarations for the entry formals. Each reference
-- to a formal becomes a dereference of a component of the parameter
-- block, whose address is held in Ann. These declarations are
-- eventually inserted into the accept block, and analyzed there so
-- that they have the proper scope for gdb and do not conflict with
-- other declarations.
if Present (Parameter_Specifications (N))
and then Present (Handled_Statement_Sequence (N))
then
declare
Comp : Entity_Id;
Decl : Node_Id;
Formal : Entity_Id;
New_F : Entity_Id;
Renamed_Formal : Node_Id;
begin
Push_Scope (Ent);
Formal := First_Formal (Ent);
while Present (Formal) loop
Comp := Entry_Component (Formal);
New_F := Make_Defining_Identifier (Loc, Chars (Formal));
Set_Etype (New_F, Etype (Formal));
Set_Scope (New_F, Ent);
-- Now we set debug info needed on New_F even though it does
-- not come from source, so that the debugger will get the
-- right information for these generated names.
Set_Debug_Info_Needed (New_F);
if Ekind (Formal) = E_In_Parameter then
Mutate_Ekind (New_F, E_Constant);
else
Mutate_Ekind (New_F, E_Variable);
Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
end if;
Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
Renamed_Formal :=
Make_Selected_Component (Loc,
Prefix =>
Make_Explicit_Dereference (Loc,
Unchecked_Convert_To (
Entry_Parameters_Type (Ent),
New_Occurrence_Of (Ann, Loc))),
Selector_Name =>
New_Occurrence_Of (Comp, Loc));
Decl :=
Build_Renamed_Formal_Declaration
(New_F, Formal, Comp, Renamed_Formal);
if No (Declarations (N)) then
Set_Declarations (N, New_List);
end if;
Append (Decl, Declarations (N));
Set_Renamed_Object (Formal, New_F);
Next_Formal (Formal);
end loop;
End_Scope;
end;
end if;
end if;
end Expand_Accept_Declarations;
---------------------------------------------
-- Expand_Access_Protected_Subprogram_Type --
---------------------------------------------
procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
T : constant Entity_Id := Defining_Identifier (N);
D_T : constant Entity_Id := Designated_Type (T);
D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
P_List : constant List_Id :=
Build_Protected_Spec (N, RTE (RE_Address), D_T, False);
Comps : List_Id;
Decl1 : Node_Id;
Decl2 : Node_Id;
Def1 : Node_Id;
begin
-- Create access to subprogram with full signature
if Etype (D_T) /= Standard_Void_Type then
Def1 :=
Make_Access_Function_Definition (Loc,
Parameter_Specifications => P_List,
Result_Definition =>
Copy_Result_Type (Result_Definition (Type_Definition (N))));
else
Def1 :=
Make_Access_Procedure_Definition (Loc,
Parameter_Specifications => P_List);
end if;
Decl1 :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => D_T2,
Type_Definition => Def1);
-- Declare the new types before the original one since the latter will
-- refer to them through the Equivalent_Type slot.
Insert_Before_And_Analyze (N, Decl1);
-- Associate the access to subprogram with its original access to
-- protected subprogram type. Needed by the backend to know that this
-- type corresponds with an access to protected subprogram type.
Set_Original_Access_Type (D_T2, T);
-- Create Equivalent_Type, a record with two components for an access to
-- object and an access to subprogram.
Comps := New_List (
Make_Component_Declaration (Loc,
Defining_Identifier => Make_Temporary (Loc, 'P'),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => False,
Subtype_Indication =>
New_Occurrence_Of (RTE (RE_Address), Loc))),
Make_Component_Declaration (Loc,
Defining_Identifier => Make_Temporary (Loc, 'S'),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => False,
Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
Decl2 :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => E_T,
Type_Definition =>
Make_Record_Definition (Loc,
Component_List =>
Make_Component_List (Loc, Component_Items => Comps)));
Insert_Before_And_Analyze (N, Decl2);
Set_Equivalent_Type (T, E_T);
end Expand_Access_Protected_Subprogram_Type;
--------------------------
-- Expand_Entry_Barrier --
--------------------------
procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
Cond : constant Node_Id := Condition (Entry_Body_Formal_Part (N));
Prot : constant Entity_Id := Scope (Ent);
Spec_Decl : constant Node_Id := Parent (Prot);
Func_Id : Entity_Id := Empty;
-- The entity of the barrier function
function Is_Global_Entity (N : Node_Id) return Traverse_Result;
-- Check whether entity in Barrier is external to protected type.
-- If so, barrier may not be properly synchronized.
function Is_Pure_Barrier (N : Node_Id) return Traverse_Result;
-- Check whether N meets the Pure_Barriers restriction. Return OK if
-- so.
function Is_Simple_Barrier (N : Node_Id) return Boolean;
-- Check whether N meets the Simple_Barriers restriction. Return OK if
-- so.
----------------------
-- Is_Global_Entity --
----------------------
function Is_Global_Entity (N : Node_Id) return Traverse_Result is
E : Entity_Id;
S : Entity_Id;
begin
if Is_Entity_Name (N) and then Present (Entity (N)) then
E := Entity (N);
S := Scope (E);
if Ekind (E) = E_Variable then
-- If the variable is local to the barrier function generated
-- during expansion, it is ok. If expansion is not performed,
-- then Func is Empty so this test cannot succeed.
if Scope (E) = Func_Id then
null;
-- A protected call from a barrier to another object is ok
elsif Ekind (Etype (E)) = E_Protected_Type then
null;
-- If the variable is within the package body we consider
-- this safe. This is a common (if dubious) idiom.
elsif S = Scope (Prot)
and then Is_Package_Or_Generic_Package (S)
and then Nkind (Parent (E)) = N_Object_Declaration
and then Nkind (Parent (Parent (E))) = N_Package_Body
then
null;
else
Error_Msg_N ("potentially unsynchronized barrier??", N);
Error_Msg_N ("\& should be private component of type??", N);
end if;
end if;
end if;
return OK;
end Is_Global_Entity;
procedure Check_Unprotected_Barrier is
new Traverse_Proc (Is_Global_Entity);
-----------------------
-- Is_Simple_Barrier --
-----------------------
function Is_Simple_Barrier (N : Node_Id) return Boolean is
Renamed : Node_Id;
begin
if Is_Static_Expression (N) then
return True;
elsif Ada_Version >= Ada_2022
and then Nkind (N) in N_Selected_Component | N_Indexed_Component
and then Statically_Names_Object (N)
then
-- Restriction relaxed in Ada 2022 to allow statically named
-- subcomponents.
return Is_Simple_Barrier (Prefix (N));
end if;
-- Check if the name is a component of the protected object. If
-- the expander is active, the component has been transformed into a
-- renaming of _object.all.component. Original_Node is needed in case
-- validity checking is enabled, in which case the simple object
-- reference will have been rewritten.
if Expander_Active then
-- The expanded name may have been constant folded in which case
-- the original node is not necessarily an entity name (e.g. an
-- indexed component).
if not Is_Entity_Name (Original_Node (N)) then
return False;
end if;
Renamed := Renamed_Object (Entity (Original_Node (N)));
return
Present (Renamed)
and then Nkind (Renamed) = N_Selected_Component
and then Chars (Prefix (Prefix (Renamed))) = Name_uObject;
elsif not Is_Entity_Name (N) then
return False;
else
return Is_Protected_Component (Entity (N));
end if;
end Is_Simple_Barrier;
---------------------
-- Is_Pure_Barrier --
---------------------
function Is_Pure_Barrier (N : Node_Id) return Traverse_Result is
begin
case Nkind (N) is
when N_Expanded_Name
| N_Identifier
=>
-- Because of N_Expanded_Name case, return Skip instead of OK.
if No (Entity (N)) then
return Abandon;
elsif Is_Numeric_Type (Entity (N)) then
return Skip;
end if;
case Ekind (Entity (N)) is
when E_Constant
| E_Discriminant
=>
return Skip;
when E_Enumeration_Literal
| E_Named_Integer
| E_Named_Real
=>
if not Is_OK_Static_Expression (N) then
return Abandon;
end if;
return Skip;
when E_Component =>
return Skip;
when E_Variable =>
if Is_Simple_Barrier (N) then
return Skip;
end if;
when E_Function =>
-- The count attribute has been transformed into run-time
-- calls.
if Is_RTE (Entity (N), RE_Protected_Count)
or else Is_RTE (Entity (N), RE_Protected_Count_Entry)
then
return Skip;
end if;
when others =>
null;
end case;
when N_Function_Call =>
-- Function call checks are carried out as part of the analysis
-- of the function call name.
return OK;
when N_Character_Literal
| N_Integer_Literal
| N_Real_Literal
=>
return OK;
when N_Op_Boolean
| N_Op_Not
=>
if Ekind (Entity (N)) = E_Operator then
return OK;
end if;
when N_Short_Circuit
| N_If_Expression
| N_Case_Expression
=>
return OK;
when N_Indexed_Component | N_Selected_Component =>
if Statically_Names_Object (N) then
return Is_Pure_Barrier (Prefix (N));
else
return Abandon;
end if;
when N_Case_Expression_Alternative =>
-- do not traverse Discrete_Choices subtree
if Is_Pure_Barrier (Expression (N)) /= Abandon then
return Skip;
end if;
when N_Expression_With_Actions =>
-- this may occur in the case of a Count attribute reference
if Original_Node (N) /= N
and then Is_Pure_Barrier (Original_Node (N)) /= Abandon
then
return Skip;
end if;
when N_Membership_Test =>
if Is_Pure_Barrier (Left_Opnd (N)) /= Abandon
and then All_Membership_Choices_Static (N)
then
return Skip;
end if;
when N_Type_Conversion =>
-- Conversions to Universal_Integer do not raise constraint
-- errors. Likewise if the expression's type is statically
-- compatible with the target's type.
if Etype (N) = Universal_Integer
or else Subtypes_Statically_Compatible
(Etype (Expression (N)), Etype (N))
then
return OK;
end if;
when N_Unchecked_Type_Conversion =>
return OK;
when others =>
null;
end case;
return Abandon;
end Is_Pure_Barrier;
function Check_Pure_Barriers is new Traverse_Func (Is_Pure_Barrier);
-- Local variables
Cond_Id : Entity_Id;
Entry_Body : Node_Id;
Func_Body : Node_Id := Empty;
-- Start of processing for Expand_Entry_Barrier
begin
if No_Run_Time_Mode then
Error_Msg_CRT ("entry barrier", N);
return;
end if;
-- Prevent cascaded errors
if Nkind (Cond) = N_Error then
return;
end if;
-- The body of the entry barrier must be analyzed in the context of the
-- protected object, but its scope is external to it, just as any other
-- unprotected version of a protected operation. The specification has
-- been produced when the protected type declaration was elaborated. We
-- build the body, insert it in the enclosing scope, but analyze it in
-- the current context. A more uniform approach would be to treat the
-- barrier just as a protected function, and discard the protected
-- version of it because it is never called.
if Expander_Active then
Func_Body := Build_Barrier_Function (N, Ent, Prot);
Func_Id := Barrier_Function (Ent);
Set_Corresponding_Spec (Func_Body, Func_Id);
Entry_Body := Parent (Corresponding_Body (Spec_Decl));
if Nkind (Parent (Entry_Body)) = N_Subunit then
Entry_Body := Corresponding_Stub (Parent (Entry_Body));
end if;
Insert_Before_And_Analyze (Entry_Body, Func_Body);
Set_Discriminals (Spec_Decl);
Set_Scope (Func_Id, Scope (Prot));
else
Analyze_And_Resolve (Cond, Any_Boolean);
end if;
-- Check Simple_Barriers and Pure_Barriers restrictions.
-- Note that it is safe to be calling Check_Restriction from here, even
-- though this is part of the expander, since Expand_Entry_Barrier is
-- called from Sem_Ch9 even in -gnatc mode.
if not Is_Simple_Barrier (Cond) then
-- flag restriction violation
Check_Restriction (Simple_Barriers, Cond);
end if;
if Check_Pure_Barriers (Cond) = Abandon then
-- flag restriction violation
Check_Restriction (Pure_Barriers, Cond);
-- Emit warning if barrier contains global entities and is thus
-- potentially unsynchronized (if Pure_Barriers restrictions
-- are met then no need to check for this).
Check_Unprotected_Barrier (Cond);
end if;
if Is_Entity_Name (Cond) then
Cond_Id := Entity (Cond);
-- Perform a small optimization of simple barrier functions. If the
-- scope of the condition's entity is not the barrier function, then
-- the condition does not depend on any of the generated renamings.
-- If this is the case, eliminate the renamings as they are useless.
-- This optimization is not performed when the condition was folded
-- and validity checks are in effect because the original condition
-- may have produced at least one check that depends on the generated
-- renamings.
if Expander_Active
and then Scope (Cond_Id) /= Func_Id
and then not Validity_Check_Operands
then
Set_Declarations (Func_Body, Empty_List);
end if;
-- Note that after analysis variables in this context will be
-- replaced by the corresponding prival, that is to say a renaming
-- of a selected component of the form _Object.Var. If expansion is
-- disabled, as within a generic, we check that the entity appears in
-- the current scope.
end if;
end Expand_Entry_Barrier;
------------------------------
-- Expand_N_Abort_Statement --
------------------------------
-- Expand abort T1, T2, .. Tn; into:
-- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
procedure Expand_N_Abort_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Tlist : constant List_Id := Names (N);
Count : Nat;
Aggr : Node_Id;
Tasknm : Node_Id;
begin
Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
Count := 0;
Tasknm := First (Tlist);
while Present (Tasknm) loop
Count := Count + 1;
-- A task interface class-wide type object is being aborted. Retrieve
-- its _task_id by calling a dispatching routine.
if Ada_Version >= Ada_2005
and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
and then Is_Interface (Etype (Tasknm))
and then Is_Task_Interface (Etype (Tasknm))
then
Append_To (Component_Associations (Aggr),
Make_Component_Association (Loc,
Choices => New_List (Make_Integer_Literal (Loc, Count)),
Expression =>
-- Task_Id (Tasknm._disp_get_task_id)
Unchecked_Convert_To
(RTE (RO_ST_Task_Id),
Make_Selected_Component (Loc,
Prefix => New_Copy_Tree (Tasknm),
Selector_Name =>
Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
else
Append_To (Component_Associations (Aggr),
Make_Component_Association (Loc,
Choices => New_List (Make_Integer_Literal (Loc, Count)),
Expression => Concurrent_Ref (Tasknm)));
end if;
Next (Tasknm);
end loop;
Rewrite (N,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Abort_Tasks), Loc),
Parameter_Associations => New_List (
Make_Qualified_Expression (Loc,
Subtype_Mark => New_Occurrence_Of (RTE (RE_Task_List), Loc),
Expression => Aggr))));
Analyze (N);
end Expand_N_Abort_Statement;
-------------------------------
-- Expand_N_Accept_Statement --
-------------------------------
-- This procedure handles expansion of accept statements that stand alone,
-- i.e. they are not part of an accept alternative. The expansion of
-- accept statement in accept alternatives is handled by the routines
-- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
-- following description applies only to stand alone accept statements.
-- If there is no handled statement sequence, or only null statements, then
-- this is called a trivial accept, and the expansion is:
-- Accept_Trivial (entry-index)
-- If there is a handled statement sequence, then the expansion is:
-- Ann : Address;
-- {Lnn : Label}
-- begin
-- begin
-- Accept_Call (entry-index, Ann);
-- Renaming_Declarations for formals
-- <statement sequence from N_Accept_Statement node>
-- Complete_Rendezvous;
-- <<Lnn>>
--
-- exception
-- when ... =>
-- <exception handler from N_Accept_Statement node>
-- Complete_Rendezvous;
-- when ... =>
-- <exception handler from N_Accept_Statement node>
-- Complete_Rendezvous;
-- ...
-- end;
-- exception
-- when all others =>
-- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
-- end;
-- The first three declarations were already inserted ahead of the accept
-- statement by the Expand_Accept_Declarations procedure, which was called
-- directly from the semantics during analysis of the accept statement,
-- before analyzing its contained statements.
-- The declarations from the N_Accept_Statement, as noted in Sinfo, come
-- from possible expansion activity (the original source of course does
-- not have any declarations associated with the accept statement, since
-- an accept statement has no declarative part). In particular, if the
-- expander is active, the first such declaration is the declaration of
-- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
-- The two blocks are merged into a single block if the inner block has
-- no exception handlers, but otherwise two blocks are required, since
-- exceptions might be raised in the exception handlers of the inner
-- block, and Exceptional_Complete_Rendezvous must be called.
procedure Expand_N_Accept_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Stats : constant Node_Id := Handled_Statement_Sequence (N);
Ename : constant Node_Id := Entry_Direct_Name (N);
Eindx : constant Node_Id := Entry_Index (N);
Eent : constant Entity_Id := Entity (Ename);
Acstack : constant Elist_Id := Accept_Address (Eent);
Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
Ttyp : constant Entity_Id := Etype (Scope (Eent));
Blkent : Entity_Id;
Call : Node_Id;
Block : Node_Id;
begin
-- If the accept statement is not part of a list, then its parent must
-- be an accept alternative, and, as described above, we do not do any
-- expansion for such accept statements at this level.
if not Is_List_Member (N) then
pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
return;
-- Trivial accept case (no statement sequence, or null statements).
-- If the accept statement has declarations, then just insert them
-- before the procedure call.
elsif Trivial_Accept_OK
and then (No (Stats) or else Null_Statements (Statements (Stats)))
then
-- Remove declarations for renamings, because the parameter block
-- will not be assigned.
declare
D : Node_Id;
Next_D : Node_Id;
begin
D := First (Declarations (N));
while Present (D) loop
Next_D := Next (D);
if Nkind (D) = N_Object_Renaming_Declaration then
Remove (D);
end if;
D := Next_D;
end loop;
end;
if Present (Declarations (N)) then
Insert_Actions (N, Declarations (N));
end if;
Rewrite (N,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Accept_Trivial), Loc),
Parameter_Associations => New_List (
Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
Analyze (N);
-- Ada 2022 (AI12-0279)
if Has_Yield_Aspect (Eent)
and then RTE_Available (RE_Yield)
then
Insert_Action_After (N,
Make_Procedure_Call_Statement (Loc,
New_Occurrence_Of (RTE (RE_Yield), Loc)));
end if;
-- Discard Entry_Address that was created for it, so it will not be
-- emitted if this accept statement is in the statement part of a
-- delay alternative.
if Present (Stats) then
Remove_Last_Elmt (Acstack);
end if;
-- Case of statement sequence present
else
-- Construct the block, using the declarations from the accept
-- statement if any to initialize the declarations of the block.
Blkent := Make_Temporary (Loc, 'A');
Mutate_Ekind (Blkent, E_Block);
Set_Etype (Blkent, Standard_Void_Type);
Set_Scope (Blkent, Current_Scope);
Block :=
Make_Block_Statement (Loc,
Identifier => New_Occurrence_Of (Blkent, Loc),
Declarations => Declarations (N),
Handled_Statement_Sequence => Build_Accept_Body (N));
-- Reset the Scope of local entities associated with the accept
-- statement (that currently reference the entry scope) to the
-- block scope, to avoid having references to the locals treated
-- as up-level references.
Reset_Scopes_To (Block, Blkent);
-- For the analysis of the generated declarations, the parent node
-- must be properly set.
Set_Parent (Block, Parent (N));
Set_Parent (Blkent, Block);
-- Prepend call to Accept_Call to main statement sequence If the
-- accept has exception handlers, the statement sequence is wrapped
-- in a block. Insert call and renaming declarations in the
-- declarations of the block, so they are elaborated before the
-- handlers.
Call :=
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Accept_Call), Loc),
Parameter_Associations => New_List (
Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
New_Occurrence_Of (Ann, Loc)));
if Parent (Stats) = N then
Prepend (Call, Statements (Stats));
else
Set_Declarations (Parent (Stats), New_List (Call));
end if;
Analyze (Call);
Push_Scope (Blkent);
declare
D : Node_Id;
Next_D : Node_Id;
Typ : Entity_Id;
begin
D := First (Declarations (N));
while Present (D) loop
Next_D := Next (D);
if Nkind (D) = N_Object_Renaming_Declaration then
-- The renaming declarations for the formals were created
-- during analysis of the accept statement, and attached to
-- the list of declarations. Place them now in the context
-- of the accept block or subprogram.
Remove (D);
Typ := Entity (Subtype_Mark (D));
Insert_After (Call, D);
Analyze (D);
-- If the formal is class_wide, it does not have an actual
-- subtype. The analysis of the renaming declaration creates
-- one, but we need to retain the class-wide nature of the
-- entity.
if Is_Class_Wide_Type (Typ) then
Set_Etype (Defining_Identifier (D), Typ);
end if;
end if;
D := Next_D;
end loop;
end;
End_Scope;
-- Replace the accept statement by the new block
Rewrite (N, Block);
Analyze (N);
-- Last step is to unstack the Accept_Address value
Remove_Last_Elmt (Acstack);
end if;
end Expand_N_Accept_Statement;
----------------------------------
-- Expand_N_Asynchronous_Select --
----------------------------------
-- This procedure assumes that the trigger statement is an entry call or
-- a dispatching procedure call. A delay alternative should already have
-- been expanded into an entry call to the appropriate delay object Wait
-- entry.
-- If the trigger is a task entry call, the select is implemented with
-- a Task_Entry_Call:
-- declare
-- B : Boolean;
-- C : Boolean;
-- P : parms := (parm, parm, parm);
-- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
-- procedure _clean is
-- begin
-- ...
-- Cancel_Task_Entry_Call (C);
-- ...
-- end _clean;
-- begin
-- Abort_Defer;
-- Task_Entry_Call
-- (<acceptor-task>, -- Acceptor
-- <entry-index>, -- E
-- P'Address, -- Uninterpreted_Data
-- Asynchronous_Call, -- Mode
-- B); -- Rendezvous_Successful
-- begin
-- begin
-- Abort_Undefer;
-- <abortable-part>
-- at end
-- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
-- end;
-- exception
-- when Abort_Signal => Abort_Undefer;
-- end;
-- parm := P.param;
-- parm := P.param;
-- ...
-- if not C then
-- <triggered-statements>
-- end if;
-- end;
-- Note that Build_Simple_Entry_Call is used to expand the entry of the
-- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
-- as follows:
-- declare
-- P : parms := (parm, parm, parm);
-- begin
-- Call_Simple (acceptor-task, entry-index, P'Address);
-- parm := P.param;
-- parm := P.param;
-- ...
-- end;
-- so the task at hand is to convert the latter expansion into the former
-- If the trigger is a protected entry call, the select is implemented
-- with Protected_Entry_Call:
-- declare
-- P : E1_Params := (param, param, param);
-- Bnn : Communications_Block;
-- begin
-- declare
-- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
-- procedure _clean is
-- begin
-- ...
-- if Enqueued (Bnn) then
-- Cancel_Protected_Entry_Call (Bnn);
-- end if;
-- ...
-- end _clean;
-- begin
-- begin
-- Protected_Entry_Call
-- (po._object'Access, -- Object
-- <entry index>, -- E
-- P'Address, -- Uninterpreted_Data
-- Asynchronous_Call, -- Mode
-- Bnn); -- Block
-- if Enqueued (Bnn) then
-- <abortable-part>
-- end if;
-- at end
-- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
-- end;
-- exception
-- when Abort_Signal => Abort_Undefer;
-- end;
-- if not Cancelled (Bnn) then
-- <triggered-statements>
-- end if;
-- end;
-- Build_Simple_Entry_Call is used to expand the all to a simple protected
-- entry call:
-- declare
-- P : E1_Params := (param, param, param);
-- Bnn : Communications_Block;
-- begin
-- Protected_Entry_Call
-- (po._object'Access, -- Object
-- <entry index>, -- E
-- P'Address, -- Uninterpreted_Data
-- Simple_Call, -- Mode
-- Bnn); -- Block
-- parm := P.param;
-- parm := P.param;
-- ...
-- end;
-- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
-- expanded into:
-- declare
-- B : Boolean := False;
-- Bnn : Communication_Block;
-- C : Ada.Tags.Prim_Op_Kind;
-- D : System.Storage_Elements.Dummy_Communication_Block;
-- K : Ada.Tags.Tagged_Kind :=
-- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
-- P : Parameters := (Param1 .. ParamN);
-- S : Integer;
-- U : Boolean;
-- begin
-- if K = Ada.Tags.TK_Limited_Tagged
-- or else K = Ada.Tags.TK_Tagged
-- then
-- <dispatching-call>;
-- <triggering-statements>;
-- else
-- S :=
-- Ada.Tags.Get_Offset_Index
-- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
-- _Disp_Get_Prim_Op_Kind (<object>, S, C);
-- if C = POK_Protected_Entry then
-- declare
-- procedure _clean is
-- begin
-- if Enqueued (Bnn) then
-- Cancel_Protected_Entry_Call (Bnn);
-- end if;
-- end _clean;
-- begin
-- begin
-- _Disp_Asynchronous_Select
-- (<object>, S, P'Address, D, B);
-- Bnn := Communication_Block (D);
-- Param1 := P.Param1;
-- ...
-- ParamN := P.ParamN;
-- if Enqueued (Bnn) then
-- <abortable-statements>
-- end if;
-- at end
-- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
-- end;
-- exception
-- when Abort_Signal => Abort_Undefer;
-- end;
-- if not Cancelled (Bnn) then
-- <triggering-statements>
-- end if;
-- elsif C = POK_Task_Entry then
-- declare
-- procedure _clean is
-- begin
-- Cancel_Task_Entry_Call (U);
-- end _clean;
-- begin
-- Abort_Defer;
-- _Disp_Asynchronous_Select
-- (<object>, S, P'Address, D, B);
-- Bnn := Communication_Bloc (D);
-- Param1 := P.Param1;
-- ...
-- ParamN := P.ParamN;
-- begin
-- begin
-- Abort_Undefer;
-- <abortable-statements>
-- at end
-- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
-- end;
-- exception
-- when Abort_Signal => Abort_Undefer;
-- end;
-- if not U then
-- <triggering-statements>
-- end if;
-- end;
-- else
-- <dispatching-call>;
-- <triggering-statements>
-- end if;
-- end if;
-- end;
-- The job is to convert this to the asynchronous form
-- If the trigger is a delay statement, it will have been expanded into
-- a call to one of the GNARL delay procedures. This routine will convert
-- this into a protected entry call on a delay object and then continue
-- processing as for a protected entry call trigger. This requires
-- declaring a Delay_Block object and adding a pointer to this object to
-- the parameter list of the delay procedure to form the parameter list of
-- the entry call. This object is used by the runtime to queue the delay
-- request.
-- For a description of the use of P and the assignments after the call,
-- see Expand_N_Entry_Call_Statement.
procedure Expand_N_Asynchronous_Select (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Abrt : constant Node_Id := Abortable_Part (N);
Trig : constant Node_Id := Triggering_Alternative (N);
Abort_Block_Ent : Entity_Id;
Abortable_Block : Node_Id;
Actuals : List_Id;
Astats : List_Id;
Blk_Ent : constant Entity_Id := Make_Temporary (Loc, 'A');
Blk_Typ : Entity_Id;
Call : Node_Id;
Call_Ent : Entity_Id;
Cancel_Param : Entity_Id;
Cleanup_Block : Node_Id;
Cleanup_Block_Ent : Entity_Id;
Cleanup_Stmts : List_Id;
Conc_Typ_Stmts : List_Id;
Concval : Node_Id;
Dblock_Ent : Entity_Id;
Decl : Node_Id;
Decls : List_Id;
Ecall : Node_Id;
Ename : Node_Id;
Enqueue_Call : Node_Id;
Formals : List_Id;
Hdle : List_Id;
Index : Node_Id;
Lim_Typ_Stmts : List_Id;
N_Orig : Node_Id;
Obj : Entity_Id;
Param : Node_Id;
Params : List_Id;
Pdef : Entity_Id;
ProtE_Stmts : List_Id;
ProtP_Stmts : List_Id;
Stmt : Node_Id;
Stmts : List_Id;
TaskE_Stmts : List_Id;
Tstats : List_Id;
B : Entity_Id; -- Call status flag
Bnn : Entity_Id; -- Communication block
C : Entity_Id; -- Call kind
K : Entity_Id; -- Tagged kind
P : Entity_Id; -- Parameter block
S : Entity_Id; -- Primitive operation slot
T : Entity_Id; -- Additional status flag
procedure Rewrite_Abortable_Part;
-- If the trigger is a dispatching call, the expansion inserts multiple
-- copies of the abortable part. This is both inefficient, and may lead
-- to duplicate definitions that the back-end will reject, when the
-- abortable part includes loops. This procedure rewrites the abortable
-- part into a call to a generated procedure.
----------------------------
-- Rewrite_Abortable_Part --
----------------------------
procedure Rewrite_Abortable_Part is
Proc : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uA);
Decl : Node_Id;
begin
Decl :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Procedure_Specification (Loc, Defining_Unit_Name => Proc),
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Astats));
Insert_Before (N, Decl);
Analyze (Decl);
-- Rewrite abortable part into a call to this procedure
Astats :=
New_List (
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Proc, Loc)));
end Rewrite_Abortable_Part;
-- Start of processing for Expand_N_Asynchronous_Select
begin
-- Asynchronous select is not supported on restricted runtimes. Don't
-- try to expand.
if Restricted_Profile then
return;
end if;
Process_Statements_For_Controlled_Objects (Trig);
Process_Statements_For_Controlled_Objects (Abrt);
Ecall := Triggering_Statement (Trig);
Ensure_Statement_Present (Sloc (Ecall), Trig);
-- Retrieve Astats and Tstats now because the finalization machinery may
-- wrap them in blocks.
Astats := Statements (Abrt);
Tstats := Statements (Trig);
-- The arguments in the call may require dynamic allocation, and the
-- call statement may have been transformed into a block. The block
-- may contain additional declarations for internal entities, and the
-- original call is found by sequential search.
if Nkind (Ecall) = N_Block_Statement then
Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
while Nkind (Ecall) not in
N_Procedure_Call_Statement | N_Entry_Call_Statement
loop
Next (Ecall);
end loop;
end if;
-- This is either a dispatching call or a delay statement used as a
-- trigger which was expanded into a procedure call.
if Nkind (Ecall) = N_Procedure_Call_Statement then
if Ada_Version >= Ada_2005
and then
(No (Original_Node (Ecall))
or else Nkind (Original_Node (Ecall)) not in N_Delay_Statement)
then
Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
Rewrite_Abortable_Part;
Decls := New_List;
Stmts := New_List;
-- Call status flag processing, generate:
-- B : Boolean := False;
B := Build_B (Loc, Decls);
-- Communication block processing, generate:
-- Bnn : Communication_Block;
Bnn := Make_Temporary (Loc, 'B');
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Bnn,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Communication_Block), Loc)));
-- Call kind processing, generate:
-- C : Ada.Tags.Prim_Op_Kind;
C := Build_C (Loc, Decls);
-- Tagged kind processing, generate:
-- K : Ada.Tags.Tagged_Kind :=
-- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
-- Dummy communication block, generate:
-- D : Dummy_Communication_Block;
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uD),
Object_Definition =>
New_Occurrence_Of
(RTE (RE_Dummy_Communication_Block), Loc)));
K := Build_K (Loc, Decls, Obj);
-- Parameter block processing
Blk_Typ := Build_Parameter_Block
(Loc, Actuals, Formals, Decls);
P := Parameter_Block_Pack
(Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
-- Dispatch table slot processing, generate:
-- S : Integer;
S := Build_S (Loc, Decls);
-- Additional status flag processing, generate:
-- Tnn : Boolean;
T := Make_Temporary (Loc, 'T');
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => T,
Object_Definition =>
New_Occurrence_Of (Standard_Boolean, Loc)));
------------------------------
-- Protected entry handling --
------------------------------
-- Generate:
-- Param1 := P.Param1;
-- ...
-- ParamN := P.ParamN;
Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
-- Generate:
-- Bnn := Communication_Block (D);
Prepend_To (Cleanup_Stmts,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Bnn, Loc),
Expression =>
Unchecked_Convert_To
(RTE (RE_Communication_Block),
Make_Identifier (Loc, Name_uD))));
-- Generate:
-- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
Prepend_To (Cleanup_Stmts,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(Find_Prim_Op
(Etype (Etype (Obj)), Name_uDisp_Asynchronous_Select),
Loc),
Parameter_Associations =>
New_List (
New_Copy_Tree (Obj), -- <object>
New_Occurrence_Of (S, Loc), -- S
Make_Attribute_Reference (Loc, -- P'Address
Prefix => New_Occurrence_Of (P, Loc),
Attribute_Name => Name_Address),
Make_Identifier (Loc, Name_uD), -- D
New_Occurrence_Of (B, Loc)))); -- B
-- Generate:
-- if Enqueued (Bnn) then
-- <abortable-statements>
-- end if;
Append_To (Cleanup_Stmts,
Make_Implicit_If_Statement (N,
Condition =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Enqueued), Loc),
Parameter_Associations =>
New_List (New_Occurrence_Of (Bnn, Loc))),
Then_Statements =>
New_Copy_List_Tree (Astats)));
-- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
-- will then generate a _clean for the communication block Bnn.
-- Generate:
-- declare
-- procedure _clean is
-- begin
-- if Enqueued (Bnn) then
-- Cancel_Protected_Entry_Call (Bnn);
-- end if;
-- end _clean;
-- begin
-- Cleanup_Stmts
-- at end
-- _clean;
-- end;
Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
Cleanup_Block :=
Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
-- Wrap the cleanup block in an exception handling block
-- Generate:
-- begin
-- Cleanup_Block
-- exception
-- when Abort_Signal => Abort_Undefer;
-- end;
Abort_Block_Ent := Make_Temporary (Loc, 'A');
ProtE_Stmts :=
New_List (
Make_Implicit_Label_Declaration (Loc,
Defining_Identifier => Abort_Block_Ent),
Build_Abort_Block
(Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
-- Generate:
-- if not Cancelled (Bnn) then
-- <triggering-statements>
-- end if;
Append_To (ProtE_Stmts,
Make_Implicit_If_Statement (N,
Condition =>
Make_Op_Not (Loc,
Right_Opnd =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Cancelled), Loc),
Parameter_Associations =>
New_List (New_Occurrence_Of (Bnn, Loc)))),
Then_Statements =>
New_Copy_List_Tree (Tstats)));
-------------------------
-- Task entry handling --
-------------------------
-- Generate:
-- Param1 := P.Param1;
-- ...
-- ParamN := P.ParamN;
TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
-- Generate:
-- Bnn := Communication_Block (D);
Append_To (TaskE_Stmts,
Make_Assignment_Statement (Loc,
Name =>
New_Occurrence_Of (Bnn, Loc),
Expression =>
Unchecked_Convert_To
(RTE (RE_Communication_Block),
Make_Identifier (Loc, Name_uD))));
-- Generate:
-- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
Prepend_To (TaskE_Stmts,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (
Find_Prim_Op (Etype (Etype (Obj)),
Name_uDisp_Asynchronous_Select),
Loc),
Parameter_Associations => New_List (
New_Copy_Tree (Obj), -- <object>
New_Occurrence_Of (S, Loc), -- S
Make_Attribute_Reference (Loc, -- P'Address
Prefix => New_Occurrence_Of (P, Loc),
Attribute_Name => Name_Address),
Make_Identifier (Loc, Name_uD), -- D
New_Occurrence_Of (B, Loc)))); -- B
-- Generate:
-- Abort_Defer;
Prepend_To (TaskE_Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer));
-- Generate:
-- Abort_Undefer;
-- <abortable-statements>
Cleanup_Stmts := New_Copy_List_Tree (Astats);
Prepend_To
(Cleanup_Stmts, Build_Runtime_Call (Loc, RE_Abort_Undefer));
-- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
-- will generate a _clean for the additional status flag.
-- Generate:
-- declare
-- procedure _clean is
-- begin
-- Cancel_Task_Entry_Call (U);
-- end _clean;
-- begin
-- Cleanup_Stmts
-- at end
-- _clean;
-- end;
Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
Cleanup_Block :=
Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
-- Wrap the cleanup block in an exception handling block
-- Generate:
-- begin
-- Cleanup_Block
-- exception
-- when Abort_Signal => Abort_Undefer;
-- end;
Abort_Block_Ent := Make_Temporary (Loc, 'A');
Append_To (TaskE_Stmts,
Make_Implicit_Label_Declaration (Loc,
Defining_Identifier => Abort_Block_Ent));
Append_To (TaskE_Stmts,
Build_Abort_Block
(Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
-- Generate:
-- if not T then
-- <triggering-statements>
-- end if;
Append_To (TaskE_Stmts,
Make_Implicit_If_Statement (N,
Condition =>
Make_Op_Not (Loc, Right_Opnd => New_Occurrence_Of (T, Loc)),
Then_Statements =>
New_Copy_List_Tree (Tstats)));
----------------------------------
-- Protected procedure handling --
----------------------------------
-- Generate:
-- <dispatching-call>;
-- <triggering-statements>
ProtP_Stmts := New_Copy_List_Tree (Tstats);
Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
-- Generate:
-- S := Ada.Tags.Get_Offset_Index
-- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
Conc_Typ_Stmts :=
New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
-- Generate:
-- _Disp_Get_Prim_Op_Kind (<object>, S, C);
Append_To (Conc_Typ_Stmts,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(Find_Prim_Op (Etype (Etype (Obj)),
Name_uDisp_Get_Prim_Op_Kind),
Loc),
Parameter_Associations =>
New_List (
New_Copy_Tree (Obj),
New_Occurrence_Of (S, Loc),
New_Occurrence_Of (C, Loc))));
-- Generate:
-- if C = POK_Procedure_Entry then
-- ProtE_Stmts
-- elsif C = POK_Task_Entry then
-- TaskE_Stmts
-- else
-- ProtP_Stmts
-- end if;
Append_To (Conc_Typ_Stmts,
Make_Implicit_If_Statement (N,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)),
Then_Statements =>
ProtE_Stmts,
Elsif_Parts =>
New_List (
Make_Elsif_Part (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc)),
Then_Statements =>
TaskE_Stmts)),
Else_Statements =>
ProtP_Stmts));
-- Generate:
-- <dispatching-call>;
-- <triggering-statements>
Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
-- Generate:
-- if K = Ada.Tags.TK_Limited_Tagged
-- or else K = Ada.Tags.TK_Tagged
-- then
-- Lim_Typ_Stmts
-- else
-- Conc_Typ_Stmts
-- end if;
Append_To (Stmts,
Make_Implicit_If_Statement (N,
Condition => Build_Dispatching_Tag_Check (K, N),
Then_Statements => Lim_Typ_Stmts,
Else_Statements => Conc_Typ_Stmts));
Rewrite (N,
Make_Block_Statement (Loc,
Declarations =>
Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
Analyze (N);
return;
-- Delay triggering statement processing
else
-- Add a Delay_Block object to the parameter list of the delay
-- procedure to form the parameter list of the Wait entry call.
Dblock_Ent := Make_Temporary (Loc, 'D');
Pdef := Entity (Name (Ecall));
if Is_RTE (Pdef, RO_CA_Delay_For) then
Enqueue_Call :=
New_Occurrence_Of (RTE (RE_Enqueue_Duration), Loc);
elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
Enqueue_Call :=
New_Occurrence_Of (RTE (RE_Enqueue_Calendar), Loc);
else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
Enqueue_Call := New_Occurrence_Of (RTE (RE_Enqueue_RT), Loc);
end if;
Append_To (Parameter_Associations (Ecall),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Dblock_Ent, Loc),
Attribute_Name => Name_Unchecked_Access));
-- Create the inner block to protect the abortable part
Hdle := New_List (Build_Abort_Block_Handler (Loc));
Prepend_To (Astats, Build_Runtime_Call (Loc, RE_Abort_Undefer));
Abortable_Block :=
Make_Block_Statement (Loc,
Identifier => New_Occurrence_Of (Blk_Ent, Loc),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Astats),
Has_Created_Identifier => True,
Is_Asynchronous_Call_Block => True);
-- Append call to if Enqueue (When, DB'Unchecked_Access) then
Rewrite (Ecall,
Make_Implicit_If_Statement (N,
Condition =>
Make_Function_Call (Loc,
Name => Enqueue_Call,
Parameter_Associations => Parameter_Associations (Ecall)),
Then_Statements =>
New_List (Make_Block_Statement (Loc,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Implicit_Label_Declaration (Loc,
Defining_Identifier => Blk_Ent,
Label_Construct => Abortable_Block),
Abortable_Block),
Exception_Handlers => Hdle)))));
Stmts := New_List (Ecall);
-- Construct statement sequence for new block
Append_To (Stmts,
Make_Implicit_If_Statement (N,
Condition =>
Make_Function_Call (Loc,
Name => New_Occurrence_Of (
RTE (RE_Timed_Out), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Dblock_Ent, Loc),
Attribute_Name => Name_Unchecked_Access))),
Then_Statements => Tstats));
-- The result is the new block
Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
Rewrite (N,
Make_Block_Statement (Loc,
Declarations => New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Dblock_Ent,
Aliased_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Delay_Block), Loc))),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
Analyze (N);
return;
end if;
else
N_Orig := N;
end if;
Extract_Entry (Ecall, Concval, Ename, Index);
Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
Stmts := Statements (Handled_Statement_Sequence (Ecall));
Decls := Declarations (Ecall);
if Is_Protected_Type (Etype (Concval)) then
-- Get the declarations of the block expanded from the entry call
Decl := First (Decls);
while Present (Decl)
and then (Nkind (Decl) /= N_Object_Declaration
or else not Is_RTE (Etype (Object_Definition (Decl)),
RE_Communication_Block))
loop
Next (Decl);
end loop;
pragma Assert (Present (Decl));
Cancel_Param := Defining_Identifier (Decl);
-- Change the mode of the Protected_Entry_Call call
-- Protected_Entry_Call (
-- Object => po._object'Access,
-- E => <entry index>;
-- Uninterpreted_Data => P'Address;
-- Mode => Asynchronous_Call;
-- Block => Bnn);
-- Skip assignments to temporaries created for in-out parameters
-- This makes unwarranted assumptions about the shape of the expanded
-- tree for the call, and should be cleaned up ???
Stmt := First (Stmts);
while Nkind (Stmt) /= N_Procedure_Call_Statement loop
Next (Stmt);
end loop;
Call := Stmt;
Param := First (Parameter_Associations (Call));
while Present (Param)
and then not Is_RTE (Etype (Param), RE_Call_Modes)
loop
Next (Param);
end loop;
pragma Assert (Present (Param));
Rewrite (Param, New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc));
Analyze (Param);
-- Append an if statement to execute the abortable part
-- Generate:
-- if Enqueued (Bnn) then
Append_To (Stmts,
Make_Implicit_If_Statement (N,
Condition =>
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Enqueued), Loc),
Parameter_Associations => New_List (
New_Occurrence_Of (Cancel_Param, Loc))),
Then_Statements => Astats));
Abortable_Block :=
Make_Block_Statement (Loc,
Identifier => New_Occurrence_Of (Blk_Ent, Loc),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts),
Has_Created_Identifier => True,
Is_Asynchronous_Call_Block => True);
Stmts := New_List (
Make_Block_Statement (Loc,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Implicit_Label_Declaration (Loc,
Defining_Identifier => Blk_Ent,
Label_Construct => Abortable_Block),
Abortable_Block),
-- exception
Exception_Handlers => New_List (
Make_Implicit_Exception_Handler (Loc,
-- when Abort_Signal =>
-- null;
Exception_Choices =>
New_List (New_Occurrence_Of (Stand.Abort_Signal, Loc)),
Statements => New_List (Make_Null_Statement (Loc)))))),
-- if not Cancelled (Bnn) then
-- triggered statements
-- end if;
Make_Implicit_If_Statement (N,
Condition => Make_Op_Not (Loc,
Right_Opnd =>
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
Parameter_Associations => New_List (
New_Occurrence_Of (Cancel_Param, Loc)))),
Then_Statements => Tstats));
-- Asynchronous task entry call
else
if No (Decls) then
Decls := New_List;
end if;
B := Make_Defining_Identifier (Loc, Name_uB);
-- Insert declaration of B in declarations of existing block
Prepend_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => B,
Object_Definition =>
New_Occurrence_Of (Standard_Boolean, Loc)));
Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
-- Insert the declaration of C in the declarations of the existing
-- block. The variable is initialized to something (True or False,
-- does not matter) to prevent CodePeer from complaining about a
-- possible read of an uninitialized variable.
Prepend_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Cancel_Param,
Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
Expression => New_Occurrence_Of (Standard_False, Loc),
Has_Init_Expression => True));
-- Remove and save the call to Call_Simple
Stmt := First (Stmts);
-- Skip assignments to temporaries created for in-out parameters.
-- This makes unwarranted assumptions about the shape of the expanded
-- tree for the call, and should be cleaned up ???
while Nkind (Stmt) /= N_Procedure_Call_Statement loop
Next (Stmt);
end loop;
Call := Stmt;
-- Create the inner block to protect the abortable part
Hdle := New_List (Build_Abort_Block_Handler (Loc));
Prepend_To (Astats, Build_Runtime_Call (Loc, RE_Abort_Undefer));
Abortable_Block :=
Make_Block_Statement (Loc,
Identifier => New_Occurrence_Of (Blk_Ent, Loc),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Statements => Astats),
Has_Created_Identifier => True,
Is_Asynchronous_Call_Block => True);
Insert_After (Call,
Make_Block_Statement (Loc,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Implicit_Label_Declaration (Loc,
Defining_Identifier => Blk_Ent,
Label_Construct => Abortable_Block),
Abortable_Block),
Exception_Handlers => Hdle)));
-- Create new call statement
Params := Parameter_Associations (Call);
Append_To (Params,
New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc));
Append_To (Params, New_Occurrence_Of (B, Loc));
Rewrite (Call,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
Parameter_Associations => Params));
-- Construct statement sequence for new block
Append_To (Stmts,
Make_Implicit_If_Statement (N,
Condition =>
Make_Op_Not (Loc, New_Occurrence_Of (Cancel_Param, Loc)),
Then_Statements => Tstats));
-- Protected the call against abort
Prepend_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer));
end if;
Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
-- The result is the new block
Rewrite (N_Orig,
Make_Block_Statement (Loc,
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
Analyze (N_Orig);
end Expand_N_Asynchronous_Select;
-------------------------------------
-- Expand_N_Conditional_Entry_Call --
-------------------------------------
-- The conditional task entry call is converted to a call to
-- Task_Entry_Call:
-- declare
-- B : Boolean;
-- P : parms := (parm, parm, parm);
-- begin
-- Task_Entry_Call
-- (<acceptor-task>, -- Acceptor
-- <entry-index>, -- E
-- P'Address, -- Uninterpreted_Data
-- Conditional_Call, -- Mode
-- B); -- Rendezvous_Successful
-- parm := P.param;
-- parm := P.param;
-- ...
-- if B then
-- normal-statements
-- else
-- else-statements
-- end if;
-- end;
-- For a description of the use of P and the assignments after the call,
-- see Expand_N_Entry_Call_Statement. Note that the entry call of the
-- conditional entry call has already been expanded (by the Expand_N_Entry
-- _Call_Statement procedure) as follows:
-- declare
-- P : parms := (parm, parm, parm);
-- begin
-- ... info for in-out parameters
-- Call_Simple (acceptor-task, entry-index, P'Address);
-- parm := P.param;
-- parm := P.param;
-- ...
-- end;
-- so the task at hand is to convert the latter expansion into the former
-- The conditional protected entry call is converted to a call to
-- Protected_Entry_Call:
-- declare
-- P : parms := (parm, parm, parm);
-- Bnn : Communications_Block;
-- begin
-- Protected_Entry_Call
-- (po._object'Access, -- Object
-- <entry index>, -- E
-- P'Address, -- Uninterpreted_Data
-- Conditional_Call, -- Mode
-- Bnn); -- Block
-- parm := P.param;
-- parm := P.param;
-- ...
-- if Cancelled (Bnn) then
-- else-statements
-- else
-- normal-statements
-- end if;
-- end;
-- Ada 2005 (AI-345): A dispatching conditional entry call is converted
-- into:
-- declare
-- B : Boolean := False;
-- C : Ada.Tags.Prim_Op_Kind;
-- K : Ada.Tags.Tagged_Kind :=
-- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
-- P : Parameters := (Param1 .. ParamN);
-- S : Integer;
-- begin
-- if K = Ada.Tags.TK_Limited_Tagged
-- or else K = Ada.Tags.TK_Tagged
-- then
-- <dispatching-call>;
-- <triggering-statements>
-- else
-- S :=
-- Ada.Tags.Get_Offset_Index
-- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
-- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
-- if C = POK_Protected_Entry
-- or else C = POK_Task_Entry
-- then
-- Param1 := P.Param1;
-- ...
-- ParamN := P.ParamN;
-- end if;
-- if B then
-- if C = POK_Procedure
-- or else C = POK_Protected_Procedure
-- or else C = POK_Task_Procedure
-- then
-- <dispatching-call>;
-- end if;
-- <triggering-statements>
-- else
-- <else-statements>
-- end if;
-- end if;
-- end;
procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Alt : constant Node_Id := Entry_Call_Alternative (N);
Blk : Node_Id := Entry_Call_Statement (Alt);
Actuals : List_Id;
Blk_Typ : Entity_Id;
Call : Node_Id;
Call_Ent : Entity_Id;
Conc_Typ_Stmts : List_Id;
Decl : Node_Id;
Decls : List_Id;
Formals : List_Id;
Lim_Typ_Stmts : List_Id;
N_Stats : List_Id;
Obj : Entity_Id;
Param : Node_Id;
Params : List_Id;
Stmt : Node_Id;
Stmts : List_Id;
Transient_Blk : Node_Id;
Unpack : List_Id;
B : Entity_Id; -- Call status flag
C : Entity_Id; -- Call kind
K : Entity_Id; -- Tagged kind
P : Entity_Id; -- Parameter block
S : Entity_Id; -- Primitive operation slot
begin
Process_Statements_For_Controlled_Objects (N);
if Ada_Version >= Ada_2005
and then Nkind (Blk) = N_Procedure_Call_Statement
then
Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
Decls := New_List;
Stmts := New_List;
-- Call status flag processing, generate:
-- B : Boolean := False;
B := Build_B (Loc, Decls);
-- Call kind processing, generate:
-- C : Ada.Tags.Prim_Op_Kind;
C := Build_C (Loc, Decls);
-- Tagged kind processing, generate:
-- K : Ada.Tags.Tagged_Kind :=
-- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
K := Build_K (Loc, Decls, Obj);
-- Parameter block processing
Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
P := Parameter_Block_Pack
(Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
-- Dispatch table slot processing, generate:
-- S : Integer;
S := Build_S (Loc, Decls);
-- Generate:
-- S := Ada.Tags.Get_Offset_Index
-- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
Conc_Typ_Stmts :=
New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
-- Generate:
-- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
Append_To (Conc_Typ_Stmts,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (
Find_Prim_Op (Etype (Etype (Obj)),
Name_uDisp_Conditional_Select),
Loc),
Parameter_Associations =>
New_List (
New_Copy_Tree (Obj), -- <object>
New_Occurrence_Of (S, Loc), -- S
Make_Attribute_Reference (Loc, -- P'Address
Prefix => New_Occurrence_Of (P, Loc),
Attribute_Name => Name_Address),
New_Occurrence_Of (C, Loc), -- C
New_Occurrence_Of (B, Loc)))); -- B
-- Generate:
-- if C = POK_Protected_Entry
-- or else C = POK_Task_Entry
-- then
-- Param1 := P.Param1;
-- ...
-- ParamN := P.ParamN;
-- end if;
Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
-- Generate the if statement only when the packed parameters need
-- explicit assignments to their corresponding actuals.
if Present (Unpack) then
Append_To (Conc_Typ_Stmts,
Make_Implicit_If_Statement (N,
Condition =>
Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (
RE_POK_Protected_Entry), Loc)),
Right_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
Then_Statements => Unpack));
end if;
-- Generate:
-- if B then
-- if C = POK_Procedure
-- or else C = POK_Protected_Procedure
-- or else C = POK_Task_Procedure
-- then
-- <dispatching-call>
-- end if;
-- <normal-statements>
-- else
-- <else-statements>
-- end if;
N_Stats := New_Copy_Separate_List (Statements (Alt));
Prepend_To (N_Stats,
Make_Implicit_If_Statement (N,
Condition =>
Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)),
Right_Opnd =>
Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (
RE_POK_Protected_Procedure), Loc)),
Right_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (
RE_POK_Task_Procedure), Loc)))),
Then_Statements =>
New_List (Blk)));
Append_To (Conc_Typ_Stmts,
Make_Implicit_If_Statement (N,
Condition => New_Occurrence_Of (B, Loc),
Then_Statements => N_Stats,
Else_Statements => Else_Statements (N)));
-- Generate:
-- <dispatching-call>;
-- <triggering-statements>
Lim_Typ_Stmts := New_Copy_Separate_List (Statements (Alt));
Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
-- Generate:
-- if K = Ada.Tags.TK_Limited_Tagged
-- or else K = Ada.Tags.TK_Tagged
-- then
-- Lim_Typ_Stmts
-- else
-- Conc_Typ_Stmts
-- end if;
Append_To (Stmts,
Make_Implicit_If_Statement (N,
Condition => Build_Dispatching_Tag_Check (K, N),
Then_Statements => Lim_Typ_Stmts,
Else_Statements => Conc_Typ_Stmts));
Rewrite (N,
Make_Block_Statement (Loc,
Declarations =>
Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
-- As described above, the entry alternative is transformed into a
-- block that contains the gnulli call, and possibly assignment
-- statements for in-out parameters. The gnulli call may itself be
-- rewritten into a transient block if some unconstrained parameters
-- require it. We need to retrieve the call to complete its parameter
-- list.
else
Transient_Blk :=
First_Real_Statement (Handled_Statement_Sequence (Blk));
if Present (Transient_Blk)
and then Nkind (Transient_Blk) = N_Block_Statement
then
Blk := Transient_Blk;
end if;
Stmts := Statements (Handled_Statement_Sequence (Blk));
Stmt := First (Stmts);
while Nkind (Stmt) /= N_Procedure_Call_Statement loop
Next (Stmt);
end loop;
Call := Stmt;
Params := Parameter_Associations (Call);
if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
-- Substitute Conditional_Entry_Call for Simple_Call parameter
Param := First (Params);
while Present (Param)
and then not Is_RTE (Etype (Param), RE_Call_Modes)
loop
Next (Param);
end loop;
pragma Assert (Present (Param));
Rewrite (Param,
New_Occurrence_Of (RTE (RE_Conditional_Call), Loc));
Analyze (Param);
-- Find the Communication_Block parameter for the call to the
-- Cancelled function.
Decl := First (Declarations (Blk));
while Present (Decl)
and then not Is_RTE (Etype (Object_Definition (Decl)),
RE_Communication_Block)
loop
Next (Decl);
end loop;
-- Add an if statement to execute the else part if the call
-- does not succeed (as indicated by the Cancelled predicate).
Append_To (Stmts,
Make_Implicit_If_Statement (N,
Condition => Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
Parameter_Associations => New_List (
New_Occurrence_Of (Defining_Identifier (Decl), Loc))),
Then_Statements => Else_Statements (N),
Else_Statements => Statements (Alt)));
else
B := Make_Defining_Identifier (Loc, Name_uB);
-- Insert declaration of B in declarations of existing block
if No (Declarations (Blk)) then
Set_Declarations (Blk, New_List);
end if;
Prepend_To (Declarations (Blk),
Make_Object_Declaration (Loc,
Defining_Identifier => B,
Object_Definition =>
New_Occurrence_Of (Standard_Boolean, Loc)));
-- Create new call statement
Append_To (Params,
New_Occurrence_Of (RTE (RE_Conditional_Call), Loc));
Append_To (Params, New_Occurrence_Of (B, Loc));
Rewrite (Call,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
Parameter_Associations => Params));
-- Construct statement sequence for new block
Append_To (Stmts,
Make_Implicit_If_Statement (N,
Condition => New_Occurrence_Of (B, Loc),
Then_Statements => Statements (Alt),
Else_Statements => Else_Statements (N)));
end if;
-- The result is the new block
Rewrite (N,
Make_Block_Statement (Loc,
Declarations => Declarations (Blk),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
end if;
Analyze (N);
Reset_Scopes_To (N, Entity (Identifier (N)));
end Expand_N_Conditional_Entry_Call;
---------------------------------------
-- Expand_N_Delay_Relative_Statement --
---------------------------------------
-- Delay statement is implemented as a procedure call to Delay_For
-- defined in Ada.Calendar.Delays in order to reduce the overhead of
-- simple delays imposed by the use of Protected Objects.
procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Proc : Entity_Id;
begin
-- Try to use Ada.Calendar.Delays.Delay_For if available.
if RTE_Available (RO_CA_Delay_For) then
Proc := RTE (RO_CA_Delay_For);
-- Otherwise, use System.Relative_Delays.Delay_For and emit an error
-- message if not available. This is the implementation used on
-- restricted platforms when Ada.Calendar is not available.
else
Proc := RTE (RO_RD_Delay_For);
end if;
Rewrite (N,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Proc, Loc),
Parameter_Associations => New_List (Expression (N))));
Analyze (N);
end Expand_N_Delay_Relative_Statement;
------------------------------------
-- Expand_N_Delay_Until_Statement --
------------------------------------
-- Delay Until statement is implemented as a procedure call to
-- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : Entity_Id;
begin
if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
Typ := RTE (RO_CA_Delay_Until);
else
Typ := RTE (RO_RT_Delay_Until);
end if;
Rewrite (N,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Typ, Loc),
Parameter_Associations => New_List (Expression (N))));
Analyze (N);
end Expand_N_Delay_Until_Statement;
-------------------------
-- Expand_N_Entry_Body --
-------------------------
procedure Expand_N_Entry_Body (N : Node_Id) is
begin
-- Associate discriminals with the next protected operation body to be
-- expanded.
if Present (Next_Protected_Operation (N)) then
Set_Discriminals (Parent (Current_Scope));
end if;
end Expand_N_Entry_Body;
-----------------------------------
-- Expand_N_Entry_Call_Statement --
-----------------------------------
-- An entry call is expanded into GNARLI calls to implement a simple entry
-- call (see Build_Simple_Entry_Call).
procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
Concval : Node_Id;
Ename : Node_Id;
Index : Node_Id;
begin
if No_Run_Time_Mode then
Error_Msg_CRT ("entry call", N);
return;
end if;
-- If this entry call is part of an asynchronous select, don't expand it
-- here; it will be expanded with the select statement. Don't expand
-- timed entry calls either, as they are translated into asynchronous
-- entry calls.
-- ??? This whole approach is questionable; it may be better to go back
-- to allowing the expansion to take place and then attempting to fix it
-- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
-- whether the expanded call is on a task or protected entry.
if (Nkind (Parent (N)) /= N_Triggering_Alternative
or else N /= Triggering_Statement (Parent (N)))
and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
or else N /= Entry_Call_Statement (Parent (N))
or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
then
Extract_Entry (N, Concval, Ename, Index);
Build_Simple_Entry_Call (N, Concval, Ename, Index);
end if;
end Expand_N_Entry_Call_Statement;
--------------------------------
-- Expand_N_Entry_Declaration --
--------------------------------
-- If there are parameters, then first, each of the formals is marked by
-- setting Is_Entry_Formal. Next a record type is built which is used to
-- hold the parameter values. The name of this record type is entryP where
-- entry is the name of the entry, with an additional corresponding access
-- type called entryPA. The record type has matching components for each
-- formal (the component names are the same as the formal names). For
-- elementary types, the component type matches the formal type. For
-- composite types, an access type is declared (with the name formalA)
-- which designates the formal type, and the type of the component is this
-- access type. Finally the Entry_Component of each formal is set to
-- reference the corresponding record component.
procedure Expand_N_Entry_Declaration (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Entry_Ent : constant Entity_Id := Defining_Identifier (N);
Components : List_Id;
Formal : Node_Id;
Ftype : Entity_Id;
Last_Decl : Node_Id;
Component : Entity_Id;
Ctype : Entity_Id;
Decl : Node_Id;
Rec_Ent : Entity_Id;
Acc_Ent : Entity_Id;
begin
Formal := First_Formal (Entry_Ent);
Last_Decl := N;
-- Most processing is done only if parameters are present
if Present (Formal) then
Components := New_List;
-- Loop through formals
while Present (Formal) loop
Set_Is_Entry_Formal (Formal);
Component :=
Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
Set_Entry_Component (Formal, Component);
Set_Entry_Formal (Component, Formal);
Ftype := Etype (Formal);
-- Declare new access type and then append
Ctype := Make_Temporary (Loc, 'A');
Set_Is_Param_Block_Component_Type (Ctype);
Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Ctype,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
All_Present => True,
Constant_Present => Ekind (Formal) = E_In_Parameter,
Subtype_Indication => New_Occurrence_Of (Ftype, Loc)));
Insert_After (Last_Decl, Decl);
Last_Decl := Decl;
Append_To (Components,
Make_Component_Declaration (Loc,
Defining_Identifier => Component,
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => False,
Subtype_Indication => New_Occurrence_Of (Ctype, Loc))));
Next_Formal_With_Extras (Formal);
end loop;
-- Create the Entry_Parameter_Record declaration
Rec_Ent := Make_Temporary (Loc, 'P');
Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Rec_Ent,
Type_Definition =>
Make_Record_Definition (Loc,
Component_List =>
Make_Component_List (Loc,
Component_Items => Components)));
Insert_After (Last_Decl, Decl);
Last_Decl := Decl;
-- Construct and link in the corresponding access type
Acc_Ent := Make_Temporary (Loc, 'A');
Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Acc_Ent,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
All_Present => True,
Subtype_Indication => New_Occurrence_Of (Rec_Ent, Loc)));
Insert_After (Last_Decl, Decl);
end if;
end Expand_N_Entry_Declaration;
-----------------------------
-- Expand_N_Protected_Body --
-----------------------------
-- Protected bodies are expanded to the completion of the subprograms
-- created for the corresponding protected type. These are a protected and
-- unprotected version of each protected subprogram in the object, a
-- function to calculate each entry barrier, and a procedure to execute the
-- sequence of statements of each protected entry body. For example, for
-- protected type ptype:
-- function entB
-- (O : System.Address;
-- E : Protected_Entry_Index)
-- return Boolean
-- is
-- <discriminant renamings>
-- <private object renamings>
-- begin
-- return <barrier expression>;
-- end entB;
-- procedure pprocN (_object : in out poV;...) is
-- <discriminant renamings>
-- <private object renamings>
-- begin
-- <sequence of statements>
-- end pprocN;
-- procedure pprocP (_object : in out poV;...) is
-- procedure _clean is
-- Pn : Boolean;
-- begin
-- ptypeS (_object, Pn);
-- Unlock (_object._object'Access);
-- Abort_Undefer.all;
-- end _clean;
-- begin
-- Abort_Defer.all;
-- Lock (_object._object'Access);
-- pprocN (_object;...);
-- at end
-- _clean;
-- end pproc;
-- function pfuncN (_object : poV;...) return Return_Type is
-- <discriminant renamings>
-- <private object renamings>
-- begin
-- <sequence of statements>
-- end pfuncN;
-- function pfuncP (_object : poV) return Return_Type is
-- procedure _clean is
-- begin
-- Unlock (_object._object'Access);
-- Abort_Undefer.all;
-- end _clean;
-- begin
-- Abort_Defer.all;
-- Lock (_object._object'Access);
-- return pfuncN (_object);
-- at end
-- _clean;
-- end pfunc;
-- procedure entE
-- (O : System.Address;
-- P : System.Address;
-- E : Protected_Entry_Index)
-- is
-- <discriminant renamings>
-- <private object renamings>
-- type poVP is access poV;
-- _Object : ptVP := ptVP!(O);
-- begin
-- begin
-- <statement sequence>
-- Complete_Entry_Body (_Object._Object);
-- exception
-- when all others =>
-- Exceptional_Complete_Entry_Body (
-- _Object._Object, Get_GNAT_Exception);
-- end;
-- end entE;
-- The type poV is the record created for the protected type to hold
-- the state of the protected object.
procedure Expand_N_Protected_Body (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Pid : constant Entity_Id := Corresponding_Spec (N);
Lock_Free_Active : constant Boolean := Uses_Lock_Free (Pid);
-- This flag indicates whether the lock free implementation is active
Current_Node : Node_Id;
Disp_Op_Body : Node_Id;
New_Op_Body : Node_Id;
Op_Body : Node_Id;
Op_Decl : Node_Id;
Op_Id : Entity_Id;
function Build_Dispatching_Subprogram_Body
(N : Node_Id;
Pid : Node_Id;
Prot_Bod : Node_Id) return Node_Id;
-- Build a dispatching version of the protected subprogram body. The
-- newly generated subprogram contains a call to the original protected
-- body. The following code is generated:
--
-- function <protected-function-name> (Param1 .. ParamN) return
-- <return-type> is
-- begin
-- return <protected-function-name>P (Param1 .. ParamN);
-- end <protected-function-name>;
--
-- or
--
-- procedure <protected-procedure-name> (Param1 .. ParamN) is
-- begin
-- <protected-procedure-name>P (Param1 .. ParamN);
-- end <protected-procedure-name>
---------------------------------------
-- Build_Dispatching_Subprogram_Body --
---------------------------------------
function Build_Dispatching_Subprogram_Body
(N : Node_Id;
Pid : Node_Id;
Prot_Bod : Node_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (N);
Actuals : List_Id;
Formal : Node_Id;
Spec : Node_Id;
Stmts : List_Id;
begin
-- Generate a specification without a letter suffix in order to
-- override an interface function or procedure.
Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
-- The formal parameters become the actuals of the protected function
-- or procedure call.
Actuals := New_List;
Formal := First (Parameter_Specifications (Spec));
while Present (Formal) loop
Append_To (Actuals,
Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
Next (Formal);
end loop;
if Nkind (Spec) = N_Procedure_Specification then
Stmts :=
New_List (
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc),
Parameter_Associations => Actuals));
else
pragma Assert (Nkind (Spec) = N_Function_Specification);
Stmts :=
New_List (
Make_Simple_Return_Statement (Loc,
Expression =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc),
Parameter_Associations => Actuals)));
end if;
return
Make_Subprogram_Body (Loc,
Declarations => Empty_List,
Specification => Spec,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Stmts));
end Build_Dispatching_Subprogram_Body;
-- Start of processing for Expand_N_Protected_Body
begin
if No_Run_Time_Mode then
Error_Msg_CRT ("protected body", N);
return;
end if;
-- This is the proper body corresponding to a stub. The declarations
-- must be inserted at the point of the stub, which in turn is in the
-- declarative part of the parent unit.
if Nkind (Parent (N)) = N_Subunit then
Current_Node := Corresponding_Stub (Parent (N));
else
Current_Node := N;
end if;
Op_Body := First (Declarations (N));
-- The protected body is replaced with the bodies of its protected
-- operations, and the declarations for internal objects that may
-- have been created for entry family bounds.
Rewrite (N, Make_Null_Statement (Sloc (N)));
Analyze (N);
while Present (Op_Body) loop
case Nkind (Op_Body) is
when N_Subprogram_Declaration =>
null;
when N_Subprogram_Body =>
-- Do not create bodies for eliminated operations
if not Is_Eliminated (Defining_Entity (Op_Body))
and then not Is_Eliminated (Corresponding_Spec (Op_Body))
then
if Lock_Free_Active then
New_Op_Body :=
Build_Lock_Free_Unprotected_Subprogram_Body
(Op_Body, Pid);
else
New_Op_Body :=
Build_Unprotected_Subprogram_Body (Op_Body, Pid);
end if;
Insert_After (Current_Node, New_Op_Body);
Current_Node := New_Op_Body;
Analyze (New_Op_Body);
-- When the original protected body has nested subprograms,
-- the new body also has them, so set the flag accordingly
-- and reset the scopes of the top-level nested subprograms
-- and other declaration entities so that they now refer to
-- the new body's entity. (It would preferable to do this
-- within Build_Protected_Sub_Specification, which is called
-- from Build_Unprotected_Subprogram_Body, but the needed
-- subprogram entity isn't available via Corresponding_Spec
-- until after the above Analyze call.)
if Has_Nested_Subprogram (Corresponding_Spec (Op_Body)) then
Set_Has_Nested_Subprogram
(Corresponding_Spec (New_Op_Body));
Reset_Scopes_To
(New_Op_Body, Corresponding_Spec (New_Op_Body));
end if;
-- Build the corresponding protected operation. This is
-- needed only if this is a public or private operation of
-- the type.
-- Why do we need to test for Corresponding_Spec being
-- present here when it's assumed to be set further above
-- in the Is_Eliminated test???
if Present (Corresponding_Spec (Op_Body)) then
Op_Decl :=
Unit_Declaration_Node (Corresponding_Spec (Op_Body));
if Nkind (Parent (Op_Decl)) = N_Protected_Definition then
if Lock_Free_Active then
New_Op_Body :=
Build_Lock_Free_Protected_Subprogram_Body
(Op_Body, Pid, Specification (New_Op_Body));
else
New_Op_Body :=
Build_Protected_Subprogram_Body (
Op_Body, Pid, Specification (New_Op_Body));
end if;
Insert_After (Current_Node, New_Op_Body);
Analyze (New_Op_Body);
Current_Node := New_Op_Body;
-- Generate an overriding primitive operation body for
-- this subprogram if the protected type implements
-- an interface.
if Ada_Version >= Ada_2005
and then Present (Interfaces (
Corresponding_Record_Type (Pid)))
then
Disp_Op_Body :=
Build_Dispatching_Subprogram_Body (
Op_Body, Pid, New_Op_Body);
Insert_After (Current_Node, Disp_Op_Body);
Analyze (Disp_Op_Body);
Current_Node := Disp_Op_Body;
end if;
end if;
end if;
end if;
when N_Entry_Body =>
Op_Id := Defining_Identifier (Op_Body);
New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
Insert_After (Current_Node, New_Op_Body);
Current_Node := New_Op_Body;
Analyze (New_Op_Body);
when N_Implicit_Label_Declaration =>
null;
when N_Call_Marker
| N_Itype_Reference
=>
New_Op_Body := New_Copy (Op_Body);
Insert_After (Current_Node, New_Op_Body);
Current_Node := New_Op_Body;
when N_Freeze_Entity =>
New_Op_Body := New_Copy (Op_Body);
if Present (Entity (Op_Body))
and then Freeze_Node (Entity (Op_Body)) = Op_Body
then
Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
end if;
Insert_After (Current_Node, New_Op_Body);
Current_Node := New_Op_Body;
Analyze (New_Op_Body);
when N_Pragma =>
New_Op_Body := New_Copy (Op_Body);
Insert_After (Current_Node, New_Op_Body);
Current_Node := New_Op_Body;
Analyze (New_Op_Body);
when N_Object_Declaration =>
pragma Assert (not Comes_From_Source (Op_Body));
New_Op_Body := New_Copy (Op_Body);
Insert_After (Current_Node, New_Op_Body);
Current_Node := New_Op_Body;
Analyze (New_Op_Body);
when others =>
raise Program_Error;
end case;
Next (Op_Body);
end loop;
-- Finally, create the body of the function that maps an entry index
-- into the corresponding body index, except when there is no entry, or
-- in a Ravenscar-like profile.
if Corresponding_Runtime_Package (Pid) =
System_Tasking_Protected_Objects_Entries
then
New_Op_Body := Build_Find_Body_Index (Pid);
Insert_After (Current_Node, New_Op_Body);
Current_Node := New_Op_Body;
Analyze (New_Op_Body);
end if;
-- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
-- protected body. At this point all wrapper specs have been created,
-- frozen and included in the dispatch table for the protected type.
if Ada_Version >= Ada_2005 then
Build_Wrapper_Bodies (Loc, Pid, Current_Node);
end if;
end Expand_N_Protected_Body;
-----------------------------------------
-- Expand_N_Protected_Type_Declaration --
-----------------------------------------
-- First we create a corresponding record type declaration used to
-- represent values of this protected type.
-- The general form of this type declaration is
-- type poV (discriminants) is record
-- _Object : aliased <kind>Protection
-- [(<entry count> [, <handler count>])];
-- [entry_family : array (bounds) of Void;]
-- <private data fields>
-- end record;
-- The discriminants are present only if the corresponding protected type
-- has discriminants, and they exactly mirror the protected type
-- discriminants. The private data fields similarly mirror the private
-- declarations of the protected type.
-- The Object field is always present. It contains RTS specific data used
-- to control the protected object. It is declared as Aliased so that it
-- can be passed as a pointer to the RTS. This allows the protected record
-- to be referenced within RTS data structures. An appropriate Protection
-- type and discriminant are generated.
-- The Service field is present for protected objects with entries. It
-- contains sufficient information to allow the entry service procedure for
-- this object to be called when the object is not known till runtime.
-- One entry_family component is present for each entry family in the
-- task definition (see Expand_N_Task_Type_Declaration).
-- When a protected object is declared, an instance of the protected type
-- value record is created. The elaboration of this declaration creates the
-- correct bounds for the entry families, and also evaluates the priority
-- expression if needed. The initialization routine for the protected type
-- itself then calls Initialize_Protection with appropriate parameters to
-- initialize the value of the Task_Id field. Install_Handlers may be also
-- called if a pragma Attach_Handler applies.
-- Note: this record is passed to the subprograms created by the expansion
-- of protected subprograms and entries. It is an in parameter to protected
-- functions and an in out parameter to procedures and entry bodies. The
-- Entity_Id for this created record type is placed in the
-- Corresponding_Record_Type field of the associated protected type entity.
-- Next we create a procedure specifications for protected subprograms and
-- entry bodies. For each protected subprograms two subprograms are
-- created, an unprotected and a protected version. The unprotected version
-- is called from within other operations of the same protected object.
-- We also build the call to register the procedure if a pragma
-- Interrupt_Handler applies.
-- A single subprogram is created to service all entry bodies; it has an
-- additional boolean out parameter indicating that the previous entry call
-- made by the current task was serviced immediately, i.e. not by proxy.
-- The O parameter contains a pointer to a record object of the type
-- described above. An untyped interface is used here to allow this
-- procedure to be called in places where the type of the object to be
-- serviced is not known. This must be done, for example, when a call that
-- may have been requeued is cancelled; the corresponding object must be
-- serviced, but which object that is not known till runtime.
-- procedure ptypeS
-- (O : System.Address; P : out Boolean);
-- procedure pprocN (_object : in out poV);
-- procedure pproc (_object : in out poV);
-- function pfuncN (_object : poV);
-- function pfunc (_object : poV);
-- ...
-- Note that this must come after the record type declaration, since
-- the specs refer to this type.
procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
Discr_Map : constant Elist_Id := New_Elmt_List;
Loc : constant Source_Ptr := Sloc (N);
Prot_Typ : constant Entity_Id := Defining_Identifier (N);
Lock_Free_Active : constant Boolean := Uses_Lock_Free (Prot_Typ);
-- This flag indicates whether the lock free implementation is active
Pdef : constant Node_Id := Protected_Definition (N);
-- This contains two lists; one for visible and one for private decls
Current_Node : Node_Id := N;
E_Count : Int;
Entries_Aggr : Node_Id;
Rec_Decl : Node_Id;
Rec_Id : Entity_Id;
procedure Check_Inlining (Subp : Entity_Id);
-- If the original operation has a pragma Inline, propagate the flag
-- to the internal body, for possible inlining later on. The source
-- operation is invisible to the back-end and is never actually called.
procedure Expand_Entry_Declaration (Decl : Node_Id);
-- Create the entry barrier and the procedure body for entry declaration
-- Decl. All generated subprograms are added to Entry_Bodies_Array.
function Static_Component_Size (Comp : Entity_Id) return Boolean;
-- When compiling under the Ravenscar profile, private components must
-- have a static size, or else a protected object will require heap
-- allocation, violating the corresponding restriction. It is preferable
-- to make this check here, because it provides a better error message
-- than the back-end, which refers to the object as a whole.
procedure Register_Handler;
-- For a protected operation that is an interrupt handler, add the
-- freeze action that will register it as such.
procedure Replace_Access_Definition (Comp : Node_Id);
-- If a private component of the type is an access to itself, this
-- is not a reference to the current instance, but an access type out
-- of which one might construct a list. If such a component exists, we
-- create an incomplete type for the equivalent record type, and
-- a named access type for it, that replaces the access definition
-- of the original component. This is similar to what is done for
-- records in Check_Anonymous_Access_Components, but simpler, because
-- the corresponding record type has no previous declaration.
-- This needs to be done only once, even if there are several such
-- access components. The following entity stores the constructed
-- access type.
Acc_T : Entity_Id := Empty;
--------------------
-- Check_Inlining --
--------------------
procedure Check_Inlining (Subp : Entity_Id) is
begin
if Is_Inlined (Subp) then
Set_Is_Inlined (Protected_Body_Subprogram (Subp));
Set_Is_Inlined (Subp, False);
end if;
if Has_Pragma_No_Inline (Subp) then
Set_Has_Pragma_No_Inline (Protected_Body_Subprogram (Subp));
end if;
end Check_Inlining;
---------------------------
-- Static_Component_Size --
---------------------------
function Static_Component_Size (Comp : Entity_Id) return Boolean is
Typ : constant Entity_Id := Etype (Comp);
C : Entity_Id;
begin
if Is_Scalar_Type (Typ) then
return True;
elsif Is_Array_Type (Typ) then
return Compile_Time_Known_Bounds (Typ);
elsif Is_Record_Type (Typ) then
C := First_Component (Typ);
while Present (C) loop
if not Static_Component_Size (C) then
return False;
end if;
Next_Component (C);
end loop;
return True;
-- Any other type will be checked by the back-end
else
return True;
end if;
end Static_Component_Size;
------------------------------
-- Expand_Entry_Declaration --
------------------------------
procedure Expand_Entry_Declaration (Decl : Node_Id) is
Ent_Id : constant Entity_Id := Defining_Entity (Decl);
Bar_Id : Entity_Id;
Bod_Id : Entity_Id;
Subp : Node_Id;
begin
E_Count := E_Count + 1;
-- Create the protected body subprogram
Bod_Id :=
Make_Defining_Identifier (Loc,
Chars => Build_Selected_Name (Prot_Typ, Ent_Id, 'E'));
Set_Protected_Body_Subprogram (Ent_Id, Bod_Id);
Subp :=
Make_Subprogram_Declaration (Loc,
Specification =>
Build_Protected_Entry_Specification (Loc, Bod_Id, Ent_Id));
Insert_After (Current_Node, Subp);
Current_Node := Subp;
Analyze (Subp);
-- Build a wrapper procedure to handle contract cases, preconditions,
-- and postconditions.
Build_Contract_Wrapper (Ent_Id, N);
-- Create the barrier function
Bar_Id :=
Make_Defining_Identifier (Loc,
Chars => Build_Selected_Name (Prot_Typ, Ent_Id, 'B'));
Set_Barrier_Function (Ent_Id, Bar_Id);
Subp :=
Make_Subprogram_Declaration (Loc,
Specification =>
Build_Barrier_Function_Specification (Loc, Bar_Id));
Set_Is_Entry_Barrier_Function (Subp);
Insert_After (Current_Node, Subp);
Current_Node := Subp;
Analyze (Subp);
Set_Protected_Body_Subprogram (Bar_Id, Bar_Id);
Set_Scope (Bar_Id, Scope (Ent_Id));
-- Collect pointers to the protected subprogram and the barrier
-- of the current entry, for insertion into Entry_Bodies_Array.
Append_To (Expressions (Entries_Aggr),
Make_Aggregate (Loc,
Expressions => New_List (
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Bar_Id, Loc),
Attribute_Name => Name_Unrestricted_Access),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Bod_Id, Loc),
Attribute_Name => Name_Unrestricted_Access))));
end Expand_Entry_Declaration;
----------------------
-- Register_Handler --
----------------------
procedure Register_Handler is
-- All semantic checks already done in Sem_Prag
Prot_Proc : constant Entity_Id :=
Defining_Unit_Name (Specification (Current_Node));
Proc_Address : constant Node_Id :=
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Prot_Proc, Loc),
Attribute_Name => Name_Address);
RTS_Call : constant Entity_Id :=
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(RTE (RE_Register_Interrupt_Handler), Loc),
Parameter_Associations => New_List (Proc_Address));
begin
Append_Freeze_Action (Prot_Proc, RTS_Call);
end Register_Handler;
-------------------------------
-- Replace_Access_Definition --
-------------------------------
procedure Replace_Access_Definition (Comp : Node_Id) is
Loc : constant Source_Ptr := Sloc (Comp);
Inc_T : Node_Id;
Inc_D : Node_Id;
Acc_Def : Node_Id;
Acc_D : Node_Id;
begin
if No (Acc_T) then
Inc_T := Make_Defining_Identifier (Loc, Chars (Rec_Id));
Inc_D := Make_Incomplete_Type_Declaration (Loc, Inc_T);
Acc_T := Make_Temporary (Loc, 'S');
Acc_Def :=
Make_Access_To_Object_Definition (Loc,
Subtype_Indication => New_Occurrence_Of (Inc_T, Loc));
Acc_D :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Acc_T,
Type_Definition => Acc_Def);
Insert_Before (Rec_Decl, Inc_D);
Analyze (Inc_D);
Insert_Before (Rec_Decl, Acc_D);
Analyze (Acc_D);
end if;
Set_Access_Definition (Comp, Empty);
Set_Subtype_Indication (Comp, New_Occurrence_Of (Acc_T, Loc));
end Replace_Access_Definition;
-- Local variables
Body_Arr : Node_Id;
Body_Id : Entity_Id;
Cdecls : List_Id;
Comp : Node_Id;
Expr : Node_Id;
New_Priv : Node_Id;
Obj_Def : Node_Id;
Object_Comp : Node_Id;
Priv : Node_Id;
Sub : Node_Id;
-- Start of processing for Expand_N_Protected_Type_Declaration
begin
if Present (Corresponding_Record_Type (Prot_Typ)) then
return;
else
Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
Rec_Id := Defining_Identifier (Rec_Decl);
end if;
Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
Qualify_Entity_Names (N);
-- If the type has discriminants, their occurrences in the declaration
-- have been replaced by the corresponding discriminals. For components
-- that are constrained by discriminants, their homologues in the
-- corresponding record type must refer to the discriminants of that
-- record, so we must apply a new renaming to subtypes_indications:
-- protected discriminant => discriminal => record discriminant
-- This replacement is not applied to default expressions, for which
-- the discriminal is correct.
if Has_Discriminants (Prot_Typ) then
declare
Disc : Entity_Id;
Decl : Node_Id;
begin
Disc := First_Discriminant (Prot_Typ);
Decl := First (Discriminant_Specifications (Rec_Decl));
while Present (Disc) loop
Append_Elmt (Discriminal (Disc), Discr_Map);
Append_Elmt (Defining_Identifier (Decl), Discr_Map);
Next_Discriminant (Disc);
Next (Decl);
end loop;
end;
end if;
-- Fill in the component declarations
-- Add components for entry families. For each entry family, create an
-- anonymous type declaration with the same size, and analyze the type.
Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
pragma Assert (Present (Pdef));
Insert_After (Current_Node, Rec_Decl);
Current_Node := Rec_Decl;
-- Add private field components
if Present (Private_Declarations (Pdef)) then
Priv := First (Private_Declarations (Pdef));
while Present (Priv) loop
if Nkind (Priv) = N_Component_Declaration then
if not Static_Component_Size (Defining_Identifier (Priv)) then
-- When compiling for a restricted profile, the private
-- components must have a static size. If not, this is an
-- error for a single protected declaration, and rates a
-- warning on a protected type declaration.
if not Comes_From_Source (Prot_Typ) then
-- It's ok to be checking this restriction at expansion
-- time, because this is only for the restricted profile,
-- which is not subject to strict RM conformance, so it
-- is OK to miss this check in -gnatc mode.
Check_Restriction (No_Implicit_Heap_Allocations, Priv);
Check_Restriction
(No_Implicit_Protected_Object_Allocations, Priv);
elsif Restriction_Active (No_Implicit_Heap_Allocations) then
if not Discriminated_Size (Defining_Identifier (Priv))
then
-- Any object of the type will be non-static
Error_Msg_N ("component has non-static size??", Priv);
Error_Msg_NE
("\creation of protected object of type& will "
& "violate restriction "
& "No_Implicit_Heap_Allocations??", Priv, Prot_Typ);
else
-- Object will be non-static if discriminants are
Error_Msg_NE
("creation of protected object of type& with "
& "non-static discriminants will violate "
& "restriction No_Implicit_Heap_Allocations??",
Priv, Prot_Typ);
end if;
-- Likewise for No_Implicit_Protected_Object_Allocations
elsif Restriction_Active
(No_Implicit_Protected_Object_Allocations)
then
if not Discriminated_Size (Defining_Identifier (Priv))
then
-- Any object of the type will be non-static
Error_Msg_N ("component has non-static size??", Priv);
Error_Msg_NE
("\creation of protected object of type& will "
& "violate restriction "
& "No_Implicit_Protected_Object_Allocations??",
Priv, Prot_Typ);
else
-- Object will be non-static if discriminants are
Error_Msg_NE
("creation of protected object of type& with "
& "non-static discriminants will violate "
& "restriction "
& "No_Implicit_Protected_Object_Allocations??",
Priv, Prot_Typ);
end if;
end if;
end if;
-- The component definition consists of a subtype indication,
-- or (in Ada 2005) an access definition. Make a copy of the
-- proper definition.
declare
Old_Comp : constant Node_Id := Component_Definition (Priv);
Oent : constant Entity_Id := Defining_Identifier (Priv);
Nent : constant Entity_Id :=
Make_Defining_Identifier (Sloc (Oent),
Chars => Chars (Oent));
New_Comp : Node_Id;
begin
if Present (Subtype_Indication (Old_Comp)) then
New_Comp :=
Make_Component_Definition (Sloc (Oent),
Aliased_Present => False,
Subtype_Indication =>
New_Copy_Tree
(Subtype_Indication (Old_Comp), Discr_Map));
else
New_Comp :=
Make_Component_Definition (Sloc (Oent),
Aliased_Present => False,
Access_Definition =>
New_Copy_Tree
(Access_Definition (Old_Comp), Discr_Map));
-- A self-reference in the private part becomes a
-- self-reference to the corresponding record.
if Entity (Subtype_Mark (Access_Definition (New_Comp)))
= Prot_Typ
then
Replace_Access_Definition (New_Comp);
end if;
end if;
New_Priv :=
Make_Component_Declaration (Loc,
Defining_Identifier => Nent,
Component_Definition => New_Comp,
Expression => Expression (Priv));
Set_Has_Per_Object_Constraint (Nent,
Has_Per_Object_Constraint (Oent));
Append_To (Cdecls, New_Priv);
end;
elsif Nkind (Priv) = N_Subprogram_Declaration then
-- Make the unprotected version of the subprogram available
-- for expansion of intra object calls. There is need for
-- a protected version only if the subprogram is an interrupt
-- handler, otherwise this operation can only be called from
-- within the body.
Sub :=
Make_Subprogram_Declaration (Loc,
Specification =>
Build_Protected_Sub_Specification
(Priv, Prot_Typ, Unprotected_Mode));
Insert_After (Current_Node, Sub);
Analyze (Sub);
Set_Protected_Body_Subprogram
(Defining_Unit_Name (Specification (Priv)),
Defining_Unit_Name (Specification (Sub)));
Check_Inlining (Defining_Unit_Name (Specification (Priv)));
Current_Node := Sub;
Sub :=
Make_Subprogram_Declaration (Loc,
Specification =>
Build_Protected_Sub_Specification
(Priv, Prot_Typ, Protected_Mode));
Insert_After (Current_Node, Sub);
Analyze (Sub);
Current_Node := Sub;
if Is_Interrupt_Handler
(Defining_Unit_Name (Specification (Priv)))
then
if not Restricted_Profile then
Register_Handler;
end if;
end if;
end if;
Next (Priv);
end loop;
end if;
-- Except for the lock-free implementation, append the _Object field
-- with the right type to the component list. We need to compute the
-- number of entries, and in some cases the number of Attach_Handler
-- pragmas.
if not Lock_Free_Active then
declare
Entry_Count_Expr : constant Node_Id :=
Build_Entry_Count_Expression
(Prot_Typ, Cdecls, Loc);
Num_Attach_Handler : Nat := 0;
Protection_Subtype : Node_Id;
Ritem : Node_Id;
begin
if Has_Attach_Handler (Prot_Typ) then
Ritem := First_Rep_Item (Prot_Typ);
while Present (Ritem) loop
if Nkind (Ritem) = N_Pragma
and then Pragma_Name (Ritem) = Name_Attach_Handler
then
Num_Attach_Handler := Num_Attach_Handler + 1;
end if;
Next_Rep_Item (Ritem);
end loop;
end if;
-- Determine the proper protection type. There are two special
-- cases: 1) when the protected type has dynamic interrupt
-- handlers, and 2) when it has static handlers and we use a
-- restricted profile.
if Has_Attach_Handler (Prot_Typ)
and then not Restricted_Profile
then
Protection_Subtype :=
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of
(RTE (RE_Static_Interrupt_Protection), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (
Entry_Count_Expr,
Make_Integer_Literal (Loc, Num_Attach_Handler))));
elsif Has_Interrupt_Handler (Prot_Typ)
and then not Restriction_Active (No_Dynamic_Attachment)
then
Protection_Subtype :=
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of
(RTE (RE_Dynamic_Interrupt_Protection), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (Entry_Count_Expr)));
else
case Corresponding_Runtime_Package (Prot_Typ) is
when System_Tasking_Protected_Objects_Entries =>
Protection_Subtype :=
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of
(RTE (RE_Protection_Entries), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (Entry_Count_Expr)));
when System_Tasking_Protected_Objects_Single_Entry =>
Protection_Subtype :=
New_Occurrence_Of (RTE (RE_Protection_Entry), Loc);
when System_Tasking_Protected_Objects =>
Protection_Subtype :=
New_Occurrence_Of (RTE (RE_Protection), Loc);
when others =>
raise Program_Error;
end case;
end if;
Object_Comp :=
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uObject),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => True,
Subtype_Indication => Protection_Subtype));
end;
-- Put the _Object component after the private component so that it
-- be finalized early as required by 9.4 (20)
Append_To (Cdecls, Object_Comp);
end if;
-- Analyze the record declaration immediately after construction,
-- because the initialization procedure is needed for single object
-- declarations before the next entity is analyzed (the freeze call
-- that generates this initialization procedure is found below).
Analyze (Rec_Decl, Suppress => All_Checks);
-- Ada 2005 (AI-345): Construct the primitive entry wrappers before
-- the corresponding record is frozen. If any wrappers are generated,
-- Current_Node is updated accordingly.
if Ada_Version >= Ada_2005 then
Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
end if;
-- Collect pointers to entry bodies and their barriers, to be placed
-- in the Entry_Bodies_Array for the type. For each entry/family we
-- add an expression to the aggregate which is the initial value of
-- this array. The array is declared after all protected subprograms.
if Has_Entries (Prot_Typ) then
Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
else
Entries_Aggr := Empty;
end if;
-- Build two new procedure specifications for each protected subprogram;
-- one to call from outside the object and one to call from inside.
-- Build a barrier function and an entry body action procedure
-- specification for each protected entry. Initialize the entry body
-- array. If subprogram is flagged as eliminated, do not generate any
-- internal operations.
E_Count := 0;
Comp := First (Visible_Declarations (Pdef));
while Present (Comp) loop
if Nkind (Comp) = N_Subprogram_Declaration then
Sub :=
Make_Subprogram_Declaration (Loc,
Specification =>
Build_Protected_Sub_Specification
(Comp, Prot_Typ, Unprotected_Mode));
Insert_After (Current_Node, Sub);
Analyze (Sub);
Set_Protected_Body_Subprogram
(Defining_Unit_Name (Specification (Comp)),
Defining_Unit_Name (Specification (Sub)));
Check_Inlining (Defining_Unit_Name (Specification (Comp)));
-- Make the protected version of the subprogram available for
-- expansion of external calls.
Current_Node := Sub;
Sub :=
Make_Subprogram_Declaration (Loc,
Specification =>
Build_Protected_Sub_Specification
(Comp, Prot_Typ, Protected_Mode));
Insert_After (Current_Node, Sub);
Analyze (Sub);
Current_Node := Sub;
-- Generate an overriding primitive operation specification for
-- this subprogram if the protected type implements an interface
-- and Build_Wrapper_Spec did not generate its wrapper.
if Ada_Version >= Ada_2005
and then
Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
then
declare
Found : Boolean := False;
Prim_Elmt : Elmt_Id;
Prim_Op : Node_Id;
begin
Prim_Elmt :=
First_Elmt
(Primitive_Operations
(Corresponding_Record_Type (Prot_Typ)));
while Present (Prim_Elmt) loop
Prim_Op := Node (Prim_Elmt);
if Is_Primitive_Wrapper (Prim_Op)
and then Wrapped_Entity (Prim_Op) =
Defining_Entity (Specification (Comp))
then
Found := True;
exit;
end if;
Next_Elmt (Prim_Elmt);
end loop;
if not Found then
Sub :=
Make_Subprogram_Declaration (Loc,
Specification =>
Build_Protected_Sub_Specification
(Comp, Prot_Typ, Dispatching_Mode));
Insert_After (Current_Node, Sub);
Analyze (Sub);
Current_Node := Sub;
end if;
end;
end if;
-- If a pragma Interrupt_Handler applies, build and add a call to
-- Register_Interrupt_Handler to the freezing actions of the
-- protected version (Current_Node) of the subprogram:
-- system.interrupts.register_interrupt_handler
-- (prot_procP'address);
if not Restricted_Profile
and then Is_Interrupt_Handler
(Defining_Unit_Name (Specification (Comp)))
then
Register_Handler;
end if;
elsif Nkind (Comp) = N_Entry_Declaration then
Expand_Entry_Declaration (Comp);
end if;
Next (Comp);
end loop;
-- If there are some private entry declarations, expand it as if they
-- were visible entries.
if Present (Private_Declarations (Pdef)) then
Comp := First (Private_Declarations (Pdef));
while Present (Comp) loop
if Nkind (Comp) = N_Entry_Declaration then
Expand_Entry_Declaration (Comp);
end if;
Next (Comp);
end loop;
end if;
-- Create the declaration of an array object which contains the values
-- of aspect/pragma Max_Queue_Length for all entries of the protected
-- type. This object is later passed to the appropriate protected object
-- initialization routine.
if Has_Entries (Prot_Typ)
and then Corresponding_Runtime_Package (Prot_Typ) =
System_Tasking_Protected_Objects_Entries
then
declare
Count : Int;
Item : Entity_Id;
Max_Vals : Node_Id;
Maxes : List_Id;
Maxes_Id : Entity_Id;
Need_Array : Boolean := False;
begin
-- First check if there is any Max_Queue_Length pragma
Item := First_Entity (Prot_Typ);
while Present (Item) loop
if Is_Entry (Item) and then Has_Max_Queue_Length (Item) then
Need_Array := True;
exit;
end if;
Next_Entity (Item);
end loop;
-- Gather the Max_Queue_Length values of all entries in a list. A
-- value of zero indicates that the entry has no limitation on its
-- queue length.
if Need_Array then
Count := 0;
Item := First_Entity (Prot_Typ);
Maxes := New_List;
while Present (Item) loop
if Is_Entry (Item) then
Count := Count + 1;
Append_To (Maxes,
Make_Integer_Literal
(Loc, Get_Max_Queue_Length (Item)));
end if;
Next_Entity (Item);
end loop;
-- Create the declaration of the array object. Generate:
-- Maxes_Id : aliased constant
-- Protected_Entry_Queue_Max_Array
-- (1 .. Count) := (..., ...);
Maxes_Id :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (Prot_Typ), 'B'));
Max_Vals :=
Make_Object_Declaration (Loc,
Defining_Identifier => Maxes_Id,
Aliased_Present => True,
Constant_Present => True,
Object_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of
(RTE (RE_Protected_Entry_Queue_Max_Array), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (
Make_Range (Loc,
Make_Integer_Literal (Loc, 1),
Make_Integer_Literal (Loc, Count))))),
Expression => Make_Aggregate (Loc, Maxes));
-- A pointer to this array will be placed in the corresponding
-- record by its initialization procedure so this needs to be
-- analyzed here.
Insert_After (Current_Node, Max_Vals);
Current_Node := Max_Vals;
Analyze (Max_Vals);
Set_Entry_Max_Queue_Lengths_Array (Prot_Typ, Maxes_Id);
end if;
end;
end if;
-- Emit declaration for Entry_Bodies_Array, now that the addresses of
-- all protected subprograms have been collected.
if Has_Entries (Prot_Typ) then
Body_Id :=
Make_Defining_Identifier (Sloc (Prot_Typ),
Chars => New_External_Name (Chars (Prot_Typ), 'A'));
case Corresponding_Runtime_Package (Prot_Typ) is
when System_Tasking_Protected_Objects_Entries =>
Expr := Entries_Aggr;
Obj_Def :=
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of
(RTE (RE_Protected_Entry_Body_Array), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (
Make_Range (Loc,
Make_Integer_Literal (Loc, 1),
Make_Integer_Literal (Loc, E_Count)))));
when System_Tasking_Protected_Objects_Single_Entry =>
Expr := Remove_Head (Expressions (Entries_Aggr));
Obj_Def := New_Occurrence_Of (RTE (RE_Entry_Body), Loc);
when others =>
raise Program_Error;
end case;
Body_Arr :=
Make_Object_Declaration (Loc,
Defining_Identifier => Body_Id,
Aliased_Present => True,
Constant_Present => True,
Object_Definition => Obj_Def,
Expression => Expr);
-- A pointer to this array will be placed in the corresponding record
-- by its initialization procedure so this needs to be analyzed here.
Insert_After (Current_Node, Body_Arr);
Current_Node := Body_Arr;
Analyze (Body_Arr);
Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
-- Finally, build the function that maps an entry index into the
-- corresponding body. A pointer to this function is placed in each
-- object of the type. Except for a ravenscar-like profile (no abort,
-- no entry queue, 1 entry)
if Corresponding_Runtime_Package (Prot_Typ) =
System_Tasking_Protected_Objects_Entries
then
Sub :=
Make_Subprogram_Declaration (Loc,
Specification => Build_Find_Body_Index_Spec (Prot_Typ));
Insert_After (Current_Node, Sub);
Analyze (Sub);
end if;
end if;
end Expand_N_Protected_Type_Declaration;
--------------------------------
-- Expand_N_Requeue_Statement --
--------------------------------
-- A nondispatching requeue statement is expanded into one of four GNARLI
-- operations, depending on the source and destination (task or protected
-- object). A dispatching requeue statement is expanded into a call to the
-- predefined primitive _Disp_Requeue. In addition, code is generated to
-- jump around the remainder of processing for the original entry and, if
-- the destination is (different) protected object, to attempt to service
-- it. The following illustrates the various cases:
-- procedure entE
-- (O : System.Address;
-- P : System.Address;
-- E : Protected_Entry_Index)
-- is
-- <discriminant renamings>
-- <private object renamings>
-- type poVP is access poV;
-- _object : ptVP := ptVP!(O);
-- begin
-- begin
-- <start of statement sequence for entry>
-- -- Requeue from one protected entry body to another protected
-- -- entry.
-- Requeue_Protected_Entry (
-- _object._object'Access,
-- new._object'Access,
-- E,
-- Abort_Present);
-- return;
-- <some more of the statement sequence for entry>
-- -- Requeue from an entry body to a task entry
-- Requeue_Protected_To_Task_Entry (
-- New._task_id,
-- E,
-- Abort_Present);
-- return;
-- <rest of statement sequence for entry>
-- Complete_Entry_Body (_object._object);
-- exception
-- when all others =>
-- Exceptional_Complete_Entry_Body (
-- _object._object, Get_GNAT_Exception);
-- end;
-- end entE;
-- Requeue of a task entry call to a task entry
-- Accept_Call (E, Ann);
-- <start of statement sequence for accept statement>
-- Requeue_Task_Entry (New._task_id, E, Abort_Present);
-- goto Lnn;
-- <rest of statement sequence for accept statement>
-- <<Lnn>>
-- Complete_Rendezvous;
-- exception
-- when all others =>
-- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
-- Requeue of a task entry call to a protected entry
-- Accept_Call (E, Ann);
-- <start of statement sequence for accept statement>
-- Requeue_Task_To_Protected_Entry (
-- new._object'Access,
-- E,
-- Abort_Present);
-- newS (new, Pnn);
-- goto Lnn;
-- <rest of statement sequence for accept statement>
-- <<Lnn>>
-- Complete_Rendezvous;
-- exception
-- when all others =>
-- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
-- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
-- marked by pragma Implemented (XXX, By_Entry).
-- The requeue is inside a protected entry:
-- procedure entE
-- (O : System.Address;
-- P : System.Address;
-- E : Protected_Entry_Index)
-- is
-- <discriminant renamings>
-- <private object renamings>
-- type poVP is access poV;
-- _object : ptVP := ptVP!(O);
-- begin
-- begin
-- <start of statement sequence for entry>
-- _Disp_Requeue
-- (<interface class-wide object>,
-- True,
-- _object'Address,
-- Ada.Tags.Get_Offset_Index
-- (Tag (_object),
-- <interface dispatch table index of target entry>),
-- Abort_Present);
-- return;
-- <rest of statement sequence for entry>
-- Complete_Entry_Body (_object._object);
-- exception
-- when all others =>
-- Exceptional_Complete_Entry_Body (
-- _object._object, Get_GNAT_Exception);
-- end;
-- end entE;
-- The requeue is inside a task entry:
-- Accept_Call (E, Ann);
-- <start of statement sequence for accept statement>
-- _Disp_Requeue
-- (<interface class-wide object>,
-- False,
-- null,
-- Ada.Tags.Get_Offset_Index
-- (Tag (_object),
-- <interface dispatch table index of target entrt>),
-- Abort_Present);
-- newS (new, Pnn);
-- goto Lnn;
-- <rest of statement sequence for accept statement>
-- <<Lnn>>
-- Complete_Rendezvous;
-- exception
-- when all others =>
-- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
-- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
-- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
-- statement is replaced by a dispatching call with actual parameters taken
-- from the inner-most accept statement or entry body.
-- Target.Primitive (Param1, ..., ParamN);
-- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
-- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
-- at all.
-- declare
-- S : constant Offset_Index :=
-- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
-- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
-- begin
-- if C = POK_Protected_Entry
-- or else C = POK_Task_Entry
-- then
-- <statements for dispatching requeue>
-- elsif C = POK_Protected_Procedure then
-- <dispatching call equivalent>
-- else
-- raise Program_Error;
-- end if;
-- end;
procedure Expand_N_Requeue_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Conc_Typ : Entity_Id;
Concval : Node_Id;
Ename : Node_Id;
Enc_Subp : Entity_Id;
Index : Node_Id;
Old_Typ : Entity_Id;
function Build_Dispatching_Call_Equivalent return Node_Id;
-- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
-- the form Concval.Ename. It is statically known that Ename is allowed
-- to be implemented by a protected procedure. Create a dispatching call
-- equivalent of Concval.Ename taking the actual parameters from the
-- inner-most accept statement or entry body.
function Build_Dispatching_Requeue return Node_Id;
-- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
-- the form Concval.Ename. It is statically known that Ename is allowed
-- to be implemented by a protected or a task entry. Create a call to
-- primitive _Disp_Requeue which handles the low-level actions.
function Build_Dispatching_Requeue_To_Any return Node_Id;
-- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
-- the form Concval.Ename. Ename is either marked by pragma Implemented
-- (XXX, By_Any | Optional) or not marked at all. Create a block which
-- determines at runtime whether Ename denotes an entry or a procedure
-- and perform the appropriate kind of dispatching select.
function Build_Normal_Requeue return Node_Id;
-- N denotes a nondispatching requeue statement to either a task or a
-- protected entry. Build the appropriate runtime call to perform the
-- action.
function Build_Skip_Statement (Search : Node_Id) return Node_Id;
-- For a protected entry, create a return statement to skip the rest of
-- the entry body. Otherwise, create a goto statement to skip the rest
-- of a task accept statement. The lookup for the enclosing entry body
-- or accept statement starts from Search.
---------------------------------------
-- Build_Dispatching_Call_Equivalent --
---------------------------------------
function Build_Dispatching_Call_Equivalent return Node_Id is
Call_Ent : constant Entity_Id := Entity (Ename);
Obj : constant Node_Id := Original_Node (Concval);
Acc_Ent : Node_Id;
Actuals : List_Id;
Formal : Node_Id;
Formals : List_Id;
begin
-- Climb the parent chain looking for the inner-most entry body or
-- accept statement.
Acc_Ent := N;
while Present (Acc_Ent)
and then Nkind (Acc_Ent) not in N_Accept_Statement | N_Entry_Body
loop
Acc_Ent := Parent (Acc_Ent);
end loop;
-- A requeue statement should be housed inside an entry body or an
-- accept statement at some level. If this is not the case, then the
-- tree is malformed.
pragma Assert (Present (Acc_Ent));
-- Recover the list of formal parameters
if Nkind (Acc_Ent) = N_Entry_Body then
Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
end if;
Formals := Parameter_Specifications (Acc_Ent);
-- Create the actual parameters for the dispatching call. These are
-- simply copies of the entry body or accept statement formals in the
-- same order as they appear.
Actuals := No_List;
if Present (Formals) then
Actuals := New_List;
Formal := First (Formals);
while Present (Formal) loop
Append_To (Actuals,
Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
Next (Formal);
end loop;
end if;
-- Generate:
-- Obj.Call_Ent (Actuals);
return
Make_Procedure_Call_Statement (Loc,
Name =>
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Chars (Obj)),
Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))),
Parameter_Associations => Actuals);
end Build_Dispatching_Call_Equivalent;
-------------------------------
-- Build_Dispatching_Requeue --
-------------------------------
function Build_Dispatching_Requeue return Node_Id is
Params : constant List_Id := New_List;
begin
-- Process the "with abort" parameter
Prepend_To (Params,
New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc));
-- Process the entry wrapper's position in the primary dispatch
-- table parameter. Generate:
-- Ada.Tags.Get_Entry_Index
-- (T => To_Tag_Ptr (Obj'Address).all,
-- Position =>
-- Ada.Tags.Get_Offset_Index
-- (Ada.Tags.Tag (Concval),
-- <interface dispatch table position of Ename>));
-- Note that Obj'Address is recursively expanded into a call to
-- Base_Address (Obj).
if Tagged_Type_Expansion then
Prepend_To (Params,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
Parameter_Associations => New_List (
Make_Explicit_Dereference (Loc,
Unchecked_Convert_To (RTE (RE_Tag_Ptr),
Make_Attribute_Reference (Loc,
Prefix => New_Copy_Tree (Concval),
Attribute_Name => Name_Address))),
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
Parameter_Associations => New_List (
Unchecked_Convert_To (RTE (RE_Tag), Concval),
Make_Integer_Literal (Loc,
DT_Position (Entity (Ename))))))));
-- VM targets
else
Prepend_To (Params,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => Concval,
Attribute_Name => Name_Tag),
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
Parameter_Associations => New_List (
-- Obj_Tag
Make_Attribute_Reference (Loc,
Prefix => Concval,
Attribute_Name => Name_Tag),
-- Tag_Typ
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Etype (Concval), Loc),
Attribute_Name => Name_Tag),
-- Position
Make_Integer_Literal (Loc,
DT_Position (Entity (Ename))))))));
end if;
-- Specific actuals for protected to XXX requeue
if Is_Protected_Type (Old_Typ) then
Prepend_To (Params,
Make_Attribute_Reference (Loc, -- _object'Address
Prefix =>
Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
Attribute_Name => Name_Address));
Prepend_To (Params, -- True
New_Occurrence_Of (Standard_True, Loc));
-- Specific actuals for task to XXX requeue
else
pragma Assert (Is_Task_Type (Old_Typ));
Prepend_To (Params, -- null
New_Occurrence_Of (RTE (RE_Null_Address), Loc));
Prepend_To (Params, -- False
New_Occurrence_Of (Standard_False, Loc));
end if;
-- Add the object parameter
Prepend_To (Params, New_Copy_Tree (Concval));
-- Generate:
-- _Disp_Requeue (<Params>);
-- Find entity for Disp_Requeue operation, which belongs to
-- the type and may not be directly visible.
declare
Elmt : Elmt_Id;
Op : Entity_Id := Empty;
begin
Elmt := First_Elmt (Primitive_Operations (Etype (Conc_Typ)));
while Present (Elmt) loop
Op := Node (Elmt);
exit when Chars (Op) = Name_uDisp_Requeue;
Next_Elmt (Elmt);
end loop;
pragma Assert (Present (Op));
return
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Op, Loc),
Parameter_Associations => Params);
end;
end Build_Dispatching_Requeue;
--------------------------------------
-- Build_Dispatching_Requeue_To_Any --
--------------------------------------
function Build_Dispatching_Requeue_To_Any return Node_Id is
Call_Ent : constant Entity_Id := Entity (Ename);
Obj : constant Node_Id := Original_Node (Concval);
Skip : constant Node_Id := Build_Skip_Statement (N);
C : Entity_Id;
Decls : List_Id;
S : Entity_Id;
Stmts : List_Id;
begin
Decls := New_List;
Stmts := New_List;
-- Dispatch table slot processing, generate:
-- S : Integer;
S := Build_S (Loc, Decls);
-- Call kind processing, generate:
-- C : Ada.Tags.Prim_Op_Kind;
C := Build_C (Loc, Decls);
-- Generate:
-- S := Ada.Tags.Get_Offset_Index
-- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
-- Generate:
-- _Disp_Get_Prim_Op_Kind (Obj, S, C);
Append_To (Stmts,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (
Find_Prim_Op (Etype (Etype (Obj)),
Name_uDisp_Get_Prim_Op_Kind),
Loc),
Parameter_Associations => New_List (
New_Copy_Tree (Obj),
New_Occurrence_Of (S, Loc),
New_Occurrence_Of (C, Loc))));
Append_To (Stmts,
-- if C = POK_Protected_Entry
-- or else C = POK_Task_Entry
-- then
Make_Implicit_If_Statement (N,
Condition =>
Make_Op_Or (Loc,
Left_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)),
Right_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
-- Dispatching requeue equivalent
Then_Statements => New_List (
Build_Dispatching_Requeue,
Skip),
-- elsif C = POK_Protected_Procedure then
Elsif_Parts => New_List (
Make_Elsif_Part (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd =>
New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of (
RTE (RE_POK_Protected_Procedure), Loc)),
-- Dispatching call equivalent
Then_Statements => New_List (
Build_Dispatching_Call_Equivalent))),
-- else
-- raise Program_Error;
-- end if;
Else_Statements => New_List (
Make_Raise_Program_Error (Loc,
Reason => PE_Explicit_Raise))));
-- Wrap everything into a block
return
Make_Block_Statement (Loc,
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stmts));
end Build_Dispatching_Requeue_To_Any;
--------------------------
-- Build_Normal_Requeue --
--------------------------
function Build_Normal_Requeue return Node_Id is
Params : constant List_Id := New_List;
Param : Node_Id;
RT_Call : Node_Id;
begin
-- Process the "with abort" parameter
Prepend_To (Params,
New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc));
-- Add the index expression to the parameters. It is common among all
-- four cases.
Prepend_To (Params,
Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
if Is_Protected_Type (Old_Typ) then
declare
Self_Param : Node_Id;
begin
Self_Param :=
Make_Attribute_Reference (Loc,
Prefix =>
Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
Attribute_Name =>
Name_Unchecked_Access);
-- Protected to protected requeue
if Is_Protected_Type (Conc_Typ) then
RT_Call :=
New_Occurrence_Of (
RTE (RE_Requeue_Protected_Entry), Loc);
Param :=
Make_Attribute_Reference (Loc,
Prefix =>
Concurrent_Ref (Concval),
Attribute_Name =>
Name_Unchecked_Access);
-- Protected to task requeue
else pragma Assert (Is_Task_Type (Conc_Typ));
RT_Call :=
New_Occurrence_Of (
RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
Param := Concurrent_Ref (Concval);
end if;
Prepend_To (Params, Param);
Prepend_To (Params, Self_Param);
end;
else pragma Assert (Is_Task_Type (Old_Typ));
-- Task to protected requeue
if Is_Protected_Type (Conc_Typ) then
RT_Call :=
New_Occurrence_Of (
RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
Param :=
Make_Attribute_Reference (Loc,
Prefix =>
Concurrent_Ref (Concval),
Attribute_Name =>
Name_Unchecked_Access);
-- Task to task requeue
else pragma Assert (Is_Task_Type (Conc_Typ));
RT_Call :=
New_Occurrence_Of (RTE (RE_Requeue_Task_Entry), Loc);
Param := Concurrent_Ref (Concval);
end if;
Prepend_To (Params, Param);
end if;
return
Make_Procedure_Call_Statement (Loc,
Name => RT_Call,
Parameter_Associations => Params);
end Build_Normal_Requeue;
--------------------------
-- Build_Skip_Statement --
--------------------------
function Build_Skip_Statement (Search : Node_Id) return Node_Id is
Skip_Stmt : Node_Id;
begin
-- Build a return statement to skip the rest of the entire body
if Is_Protected_Type (Old_Typ) then
Skip_Stmt := Make_Simple_Return_Statement (Loc);
-- If the requeue is within a task, find the end label of the
-- enclosing accept statement and create a goto statement to it.
else
declare
Acc : Node_Id;
Label : Node_Id;
begin
-- Climb the parent chain looking for the enclosing accept
-- statement.
Acc := Parent (Search);
while Present (Acc)
and then Nkind (Acc) /= N_Accept_Statement
loop
Acc := Parent (Acc);
end loop;
-- The last statement is the second label used for completing
-- the rendezvous the usual way. The label we are looking for
-- is right before it.
Label :=
Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
pragma Assert (Nkind (Label) = N_Label);
-- Generate a goto statement to skip the rest of the accept
Skip_Stmt :=
Make_Goto_Statement (Loc,
Name =>
New_Occurrence_Of (Entity (Identifier (Label)), Loc));
end;
end if;
Set_Analyzed (Skip_Stmt);
return Skip_Stmt;
end Build_Skip_Statement;
-- Start of processing for Expand_N_Requeue_Statement
begin
-- Extract the components of the entry call
Extract_Entry (N, Concval, Ename, Index);
Conc_Typ := Etype (Concval);
-- Examine the scope stack in order to find nearest enclosing concurrent
-- type. This will constitute our invocation source.
Old_Typ := Current_Scope;
while Present (Old_Typ)
and then not Is_Concurrent_Type (Old_Typ)
loop
Old_Typ := Scope (Old_Typ);
end loop;
-- Obtain the innermost enclosing callable construct for use in
-- generating a dynamic accessibility check.
Enc_Subp := Current_Scope;
if Ekind (Enc_Subp) not in Entry_Kind | Subprogram_Kind then
Enc_Subp := Enclosing_Subprogram (Enc_Subp);
end if;
-- Generate a dynamic accessibility check on the target object
Insert_Before_And_Analyze (N,
Make_Raise_Program_Error (Loc,
Condition =>
Make_Op_Gt (Loc,
Left_Opnd => Accessibility_Level (Name (N), Dynamic_Level),
Right_Opnd => Make_Integer_Literal (Loc,
Scope_Depth (Enc_Subp))),
Reason => PE_Accessibility_Check_Failed));
-- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
-- Concval.Ename where the type of Concval is class-wide concurrent
-- interface.
if Ada_Version >= Ada_2012
and then Present (Concval)
and then Is_Class_Wide_Type (Conc_Typ)
and then Is_Concurrent_Interface (Conc_Typ)
then
declare
Has_Impl : Boolean := False;
Impl_Kind : Name_Id := No_Name;
begin
-- Check whether the Ename is flagged by pragma Implemented
if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
Has_Impl := True;
Impl_Kind := Implementation_Kind (Entity (Ename));
end if;
-- The procedure_or_entry_NAME is guaranteed to be overridden by
-- an entry. Create a call to predefined primitive _Disp_Requeue.
if Has_Impl and then Impl_Kind = Name_By_Entry then
Rewrite (N, Build_Dispatching_Requeue);
Analyze (N);
Insert_After (N, Build_Skip_Statement (N));
-- The procedure_or_entry_NAME is guaranteed to be overridden by
-- a protected procedure. In this case the requeue is transformed
-- into a dispatching call.
elsif Has_Impl
and then Impl_Kind = Name_By_Protected_Procedure
then
Rewrite (N, Build_Dispatching_Call_Equivalent);
Analyze (N);
-- The procedure_or_entry_NAME's implementation kind is either
-- By_Any, Optional, or pragma Implemented was not applied at all.
-- In this case a runtime test determines whether Ename denotes an
-- entry or a protected procedure and performs the appropriate
-- call.
else
Rewrite (N, Build_Dispatching_Requeue_To_Any);
Analyze (N);
end if;
end;
-- Processing for regular (nondispatching) requeues
else
Rewrite (N, Build_Normal_Requeue);
Analyze (N);
Insert_After (N, Build_Skip_Statement (N));
end if;
end Expand_N_Requeue_Statement;
-------------------------------
-- Expand_N_Selective_Accept --
-------------------------------
procedure Expand_N_Selective_Accept (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Alts : constant List_Id := Select_Alternatives (N);
-- Note: in the below declarations a lot of new lists are allocated
-- unconditionally which may well not end up being used. That's not
-- a good idea since it wastes space gratuitously ???
Accept_Case : List_Id;
Accept_List : constant List_Id := New_List;
Alt : Node_Id;
Alt_List : constant List_Id := New_List;
Alt_Stats : List_Id;
Ann : Entity_Id := Empty;
Check_Guard : Boolean := True;
Decls : constant List_Id := New_List;
Stats : constant List_Id := New_List;
Body_List : constant List_Id := New_List;
Trailing_List : constant List_Id := New_List;
Choices : List_Id;
Else_Present : Boolean := False;
Terminate_Alt : Node_Id := Empty;
Select_Mode : Node_Id;
Delay_Case : List_Id;
Delay_Count : Integer := 0;
Delay_Val : Entity_Id;
Delay_Index : Entity_Id;
Delay_Min : Entity_Id;
Delay_Num : Pos := 1;
Delay_Alt_List : List_Id := New_List;
Delay_List : constant List_Id := New_List;
D : Entity_Id;
M : Entity_Id;
First_Delay : Boolean := True;
Guard_Open : Entity_Id;
End_Lab : Node_Id;
Index : Pos := 1;
Lab : Node_Id;
Num_Alts : Nat;
Num_Accept : Nat := 0;
Proc : Node_Id;
Time_Type : Entity_Id := Empty;
Select_Call : Node_Id;
Qnam : constant Entity_Id :=
Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
Xnam : constant Entity_Id :=
Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
-----------------------
-- Local subprograms --
-----------------------
function Accept_Or_Raise return List_Id;
-- For the rare case where delay alternatives all have guards, and
-- all of them are closed, it is still possible that there were open
-- accept alternatives with no callers. We must reexamine the
-- Accept_List, and execute a selective wait with no else if some
-- accept is open. If none, we raise program_error.
procedure Add_Accept (Alt : Node_Id);
-- Process a single accept statement in a select alternative. Build
-- procedure for body of accept, and add entry to dispatch table with
-- expression for guard, in preparation for call to run time select.
function Make_And_Declare_Label (Num : Int) return Node_Id;
-- Manufacture a label using Num as a serial number and declare it.
-- The declaration is appended to Decls. The label marks the trailing
-- statements of an accept or delay alternative.
function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
-- Build call to Selective_Wait runtime routine
procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
-- Add code to compare value of delay with previous values, and
-- generate case entry for trailing statements.
procedure Process_Accept_Alternative
(Alt : Node_Id;
Index : Int;
Proc : Node_Id);
-- Add code to call corresponding procedure, and branch to
-- trailing statements, if any.
---------------------
-- Accept_Or_Raise --
---------------------
function Accept_Or_Raise return List_Id is
Cond : Node_Id;
Stats : List_Id;
J : constant Entity_Id := Make_Temporary (Loc, 'J');
begin
-- We generate the following:
-- for J in q'range loop
-- if q(J).S /=null_task_entry then
-- selective_wait (simple_mode,...);
-- done := True;
-- exit;
-- end if;
-- end loop;
--
-- if no rendez_vous then
-- raise program_error;
-- end if;
-- Note that the code needs to know that the selector name
-- in an Accept_Alternative is named S.
Cond := Make_Op_Ne (Loc,
Left_Opnd =>
Make_Selected_Component (Loc,
Prefix =>
Make_Indexed_Component (Loc,
Prefix => New_Occurrence_Of (Qnam, Loc),
Expressions => New_List (New_Occurrence_Of (J, Loc))),
Selector_Name => Make_Identifier (Loc, Name_S)),
Right_Opnd =>
New_Occurrence_Of (RTE (RE_Null_Task_Entry), Loc));
Stats := New_List (
Make_Implicit_Loop_Statement (N,
Iteration_Scheme =>
Make_Iteration_Scheme (Loc,
Loop_Parameter_Specification =>
Make_Loop_Parameter_Specification (Loc,
Defining_Identifier => J,
Discrete_Subtype_Definition =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Qnam, Loc),
Attribute_Name => Name_Range,
Expressions => New_List (
Make_Integer_Literal (Loc, 1))))),
Statements => New_List (
Make_Implicit_If_Statement (N,
Condition => Cond,
Then_Statements => New_List (
Make_Select_Call (
New_Occurrence_Of (RTE (RE_Simple_Mode), Loc)),
Make_Exit_Statement (Loc))))));
Append_To (Stats,
Make_Raise_Program_Error (Loc,
Condition => Make_Op_Eq (Loc,
Left_Opnd => New_Occurrence_Of (Xnam, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)),
Reason => PE_All_Guards_Closed));
return Stats;
end Accept_Or_Raise;
----------------
-- Add_Accept --
----------------
procedure Add_Accept (Alt : Node_Id) is
Acc_Stm : constant Node_Id := Accept_Statement (Alt);
Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
Eloc : constant Source_Ptr := Sloc (Ename);
Eent : constant Entity_Id := Entity (Ename);
Index : constant Node_Id := Entry_Index (Acc_Stm);
Call : Node_Id;
Expr : Node_Id;
Null_Body : Node_Id;
PB_Ent : Entity_Id;
Proc_Body : Node_Id;
-- Start of processing for Add_Accept
begin
if No (Ann) then
Ann := Node (Last_Elmt (Accept_Address (Eent)));
end if;
if Present (Condition (Alt)) then
Expr :=
Make_If_Expression (Eloc, New_List (
Condition (Alt),
Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
New_Occurrence_Of (RTE (RE_Null_Task_Entry), Eloc)));
else
Expr := Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent));
end if;
if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
Null_Body := New_Occurrence_Of (Standard_False, Eloc);
-- Always add call to Abort_Undefer when generating code, since
-- this is what the runtime expects (abort deferred in
-- Selective_Wait). In CodePeer mode this only confuses the
-- analysis with unknown calls, so don't do it.
if not CodePeer_Mode then
Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
Insert_Before
(First (Statements (Handled_Statement_Sequence
(Accept_Statement (Alt)))),
Call);
Analyze (Call);
end if;
PB_Ent :=
Make_Defining_Identifier (Eloc,
New_External_Name (Chars (Ename), 'A', Num_Accept));
-- Link the acceptor to the original receiving entry
Mutate_Ekind (PB_Ent, E_Procedure);
Set_Receiving_Entry (PB_Ent, Eent);
if Comes_From_Source (Alt) then
Set_Debug_Info_Needed (PB_Ent);
end if;
Proc_Body :=
Make_Subprogram_Body (Eloc,
Specification =>
Make_Procedure_Specification (Eloc,
Defining_Unit_Name => PB_Ent),
Declarations => Declarations (Acc_Stm),
Handled_Statement_Sequence =>
Build_Accept_Body (Accept_Statement (Alt)));
Reset_Scopes_To (Proc_Body, PB_Ent);
-- During the analysis of the body of the accept statement, any
-- zero cost exception handler records were collected in the
-- Accept_Handler_Records field of the N_Accept_Alternative node.
-- This is where we move them to where they belong, namely the
-- newly created procedure.
Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
Append (Proc_Body, Body_List);
else
Null_Body := New_Occurrence_Of (Standard_True, Eloc);
-- if accept statement has declarations, insert above, given that
-- we are not creating a body for the accept.
if Present (Declarations (Acc_Stm)) then
Insert_Actions (N, Declarations (Acc_Stm));
end if;
end if;
Append_To (Accept_List,
Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
Num_Accept := Num_Accept + 1;
end Add_Accept;
----------------------------
-- Make_And_Declare_Label --
----------------------------
function Make_And_Declare_Label (Num : Int) return Node_Id is
Lab_Id : Node_Id;
begin
Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
Lab :=
Make_Label (Loc, Lab_Id);
Append_To (Decls,
Make_Implicit_Label_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Chars (Lab_Id)),
Label_Construct => Lab));
return Lab;
end Make_And_Declare_Label;
----------------------
-- Make_Select_Call --
----------------------
function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
Params : constant List_Id := New_List;
begin
Append_To (Params,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Qnam, Loc),
Attribute_Name => Name_Unchecked_Access));
Append_To (Params, Select_Mode);
Append_To (Params, New_Occurrence_Of (Ann, Loc));
Append_To (Params, New_Occurrence_Of (Xnam, Loc));
return
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Selective_Wait), Loc),
Parameter_Associations => Params);
end Make_Select_Call;
--------------------------------
-- Process_Accept_Alternative --
--------------------------------
procedure Process_Accept_Alternative
(Alt : Node_Id;
Index : Int;
Proc : Node_Id)
is
Astmt : constant Node_Id := Accept_Statement (Alt);
Alt_Stats : List_Id;
begin
Adjust_Condition (Condition (Alt));
-- Accept with body
if Present (Handled_Statement_Sequence (Astmt)) then
Alt_Stats :=
New_List (
Make_Procedure_Call_Statement (Sloc (Proc),
Name =>
New_Occurrence_Of
(Defining_Unit_Name (Specification (Proc)),
Sloc (Proc))));
-- Accept with no body (followed by trailing statements)
else
declare
Entry_Id : constant Entity_Id :=
Entity (Entry_Direct_Name (Accept_Statement (Alt)));
begin
-- Ada 2022 (AI12-0279)
if Has_Yield_Aspect (Entry_Id)
and then RTE_Available (RE_Yield)
then
Alt_Stats :=
New_List (
Make_Procedure_Call_Statement (Sloc (Proc),
New_Occurrence_Of (RTE (RE_Yield), Sloc (Proc))));
else
Alt_Stats := Empty_List;
end if;
end;
end if;
Ensure_Statement_Present (Sloc (Astmt), Alt);
-- After the call, if any, branch to trailing statements, if any.
-- We create a label for each, as well as the corresponding label
-- declaration.
if not Is_Empty_List (Statements (Alt)) then
Lab := Make_And_Declare_Label (Index);
Append (Lab, Trailing_List);
Append_List (Statements (Alt), Trailing_List);
Append_To (Trailing_List,
Make_Goto_Statement (Loc,
Name => New_Copy (Identifier (End_Lab))));
else
Lab := End_Lab;
end if;
Append_To (Alt_Stats,
Make_Goto_Statement (Loc, Name => New_Copy (Identifier (Lab))));
Append_To (Alt_List,
Make_Case_Statement_Alternative (Loc,
Discrete_Choices => New_List (Make_Integer_Literal (Loc, Index)),
Statements => Alt_Stats));
end Process_Accept_Alternative;
-------------------------------
-- Process_Delay_Alternative --
-------------------------------
procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
Dloc : constant Source_Ptr := Sloc (Delay_Statement (Alt));
Cond : Node_Id;
Delay_Alt : List_Id;
begin
-- Deal with C/Fortran boolean as delay condition
Adjust_Condition (Condition (Alt));
-- Determine the smallest specified delay
-- for each delay alternative generate:
-- if guard-expression then
-- Delay_Val := delay-expression;
-- Guard_Open := True;
-- if Delay_Val < Delay_Min then
-- Delay_Min := Delay_Val;
-- Delay_Index := Index;
-- end if;
-- end if;
-- The enclosing if-statement is omitted if there is no guard
if Delay_Count = 1 or else First_Delay then
First_Delay := False;
Delay_Alt := New_List (
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Delay_Min, Loc),
Expression => Expression (Delay_Statement (Alt))));
if Delay_Count > 1 then
Append_To (Delay_Alt,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Delay_Index, Loc),
Expression => Make_Integer_Literal (Loc, Index)));
end if;
else
Delay_Alt := New_List (
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Delay_Val, Loc),
Expression => Expression (Delay_Statement (Alt))));
if Time_Type = Standard_Duration then
Cond :=
Make_Op_Lt (Loc,
Left_Opnd => New_Occurrence_Of (Delay_Val, Loc),
Right_Opnd => New_Occurrence_Of (Delay_Min, Loc));
else
-- The scope of the time type must define a comparison
-- operator. The scope itself may not be visible, so we
-- construct a node with entity information to insure that
-- semantic analysis can find the proper operator.
Cond :=
Make_Function_Call (Loc,
Name => Make_Selected_Component (Loc,
Prefix =>
New_Occurrence_Of (Scope (Time_Type), Loc),
Selector_Name =>
Make_Operator_Symbol (Loc,
Chars => Name_Op_Lt,
Strval => No_String)),
Parameter_Associations =>
New_List (
New_Occurrence_Of (Delay_Val, Loc),
New_Occurrence_Of (Delay_Min, Loc)));
Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
end if;
Append_To (Delay_Alt,
Make_Implicit_If_Statement (N,
Condition => Cond,
Then_Statements => New_List (
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Delay_Min, Loc),
Expression => New_Occurrence_Of (Delay_Val, Loc)),
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Delay_Index, Loc),
Expression => Make_Integer_Literal (Loc, Index)))));
end if;
if Check_Guard then
Append_To (Delay_Alt,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Guard_Open, Loc),
Expression => New_Occurrence_Of (Standard_True, Loc)));
end if;
if Present (Condition (Alt)) then
Delay_Alt := New_List (
Make_Implicit_If_Statement (N,
Condition => Condition (Alt),
Then_Statements => Delay_Alt));
end if;
Append_List (Delay_Alt, Delay_List);
Ensure_Statement_Present (Dloc, Alt);
-- If the delay alternative has a statement part, add choice to the
-- case statements for delays.
if not Is_Empty_List (Statements (Alt)) then
if Delay_Count = 1 then
Append_List (Statements (Alt), Delay_Alt_List);
else
Append_To (Delay_Alt_List,
Make_Case_Statement_Alternative (Loc,
Discrete_Choices => New_List (
Make_Integer_Literal (Loc, Index)),
Statements => Statements (Alt)));
end if;
elsif Delay_Count = 1 then
-- If the single delay has no trailing statements, add a branch
-- to the exit label to the selective wait.
Delay_Alt_List := New_List (
Make_Goto_Statement (Loc,
Name => New_Copy (Identifier (End_Lab))));
end if;
end Process_Delay_Alternative;
-- Start of processing for Expand_N_Selective_Accept
begin
Process_Statements_For_Controlled_Objects (N);
-- First insert some declarations before the select. The first is:
-- Ann : Address
-- This variable holds the parameters passed to the accept body. This
-- declaration has already been inserted by the time we get here by
-- a call to Expand_Accept_Declarations made from the semantics when
-- processing the first accept statement contained in the select. We
-- can find this entity as Accept_Address (E), where E is any of the
-- entries references by contained accept statements.
-- The first step is to scan the list of Selective_Accept_Statements
-- to find this entity, and also count the number of accepts, and
-- determine if terminated, delay or else is present:
Num_Alts := 0;
Alt := First (Alts);
while Present (Alt) loop
Process_Statements_For_Controlled_Objects (Alt);
if Nkind (Alt) = N_Accept_Alternative then
Add_Accept (Alt);
elsif Nkind (Alt) = N_Delay_Alternative then
Delay_Count := Delay_Count + 1;
-- If the delays are relative delays, the delay expressions have
-- type Standard_Duration. Otherwise they must have some time type
-- recognized by GNAT.
if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
Time_Type := Standard_Duration;
else
Time_Type := Etype (Expression (Delay_Statement (Alt)));
if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
then
null;
else
-- Move this check to sem???
Error_Msg_NE (
"& is not a time type (RM 9.6(6))",
Expression (Delay_Statement (Alt)), Time_Type);
Time_Type := Standard_Duration;
Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
end if;
end if;
if No (Condition (Alt)) then
-- This guard will always be open
Check_Guard := False;
end if;
elsif Nkind (Alt) = N_Terminate_Alternative then
Adjust_Condition (Condition (Alt));
Terminate_Alt := Alt;
end if;
Num_Alts := Num_Alts + 1;
Next (Alt);
end loop;
Else_Present := Present (Else_Statements (N));
-- At the same time (see procedure Add_Accept) we build the accept list:
-- Qnn : Accept_List (1 .. num-select) := (
-- (null-body, entry-index),
-- (null-body, entry-index),
-- ..
-- (null_body, entry-index));
-- In the above declaration, null-body is True if the corresponding
-- accept has no body, and false otherwise. The entry is either the
-- entry index expression if there is no guard, or if a guard is
-- present, then an if expression of the form:
-- (if guard then entry-index else Null_Task_Entry)
-- If a guard is statically known to be false, the entry can simply
-- be omitted from the accept list.
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Qnam,
Object_Definition => New_Occurrence_Of (RTE (RE_Accept_List), Loc),
Aliased_Present => True,
Expression =>
Make_Qualified_Expression (Loc,
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Accept_List), Loc),
Expression =>
Make_Aggregate (Loc, Expressions => Accept_List))));
-- Then we declare the variable that holds the index for the accept
-- that will be selected for service:
-- Xnn : Select_Index;
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Xnam,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Select_Index), Loc),
Expression =>
New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)));
-- After this follow procedure declarations for each accept body
-- procedure Pnn is
-- begin
-- ...
-- end;
-- where the ... are statements from the corresponding procedure body.
-- No parameters are involved, since the parameters are passed via Ann
-- and the parameter references have already been expanded to be direct
-- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
-- any embedded tasking statements (which would normally be illegal in
-- procedures), have been converted to calls to the tasking runtime so
-- there is no problem in putting them into procedures.
-- The original accept statement has been expanded into a block in
-- the same fashion as for simple accepts (see Build_Accept_Body).
-- Note: we don't really need to build these procedures for the case
-- where no delay statement is present, but it is just as easy to
-- build them unconditionally, and not significantly inefficient,
-- since if they are short they will be inlined anyway.
-- The procedure declarations have been assembled in Body_List
-- If delays are present, we must compute the required delay.
-- We first generate the declarations:
-- Delay_Index : Boolean := 0;
-- Delay_Min : Some_Time_Type.Time;
-- Delay_Val : Some_Time_Type.Time;
-- Delay_Index will be set to the index of the minimum delay, i.e. the
-- active delay that is actually chosen as the basis for the possible
-- delay if an immediate rendez-vous is not possible.
-- In the most common case there is a single delay statement, and this
-- is handled specially.
if Delay_Count > 0 then
-- Generate the required declarations
Delay_Val :=
Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
Delay_Index :=
Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
Delay_Min :=
Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
pragma Assert (Present (Time_Type));
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Delay_Val,
Object_Definition => New_Occurrence_Of (Time_Type, Loc)));
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Delay_Index,
Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
Expression => Make_Integer_Literal (Loc, 0)));
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Delay_Min,
Object_Definition => New_Occurrence_Of (Time_Type, Loc),
Expression =>
Unchecked_Convert_To (Time_Type,
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
Attribute_Name => Name_Last))));
-- Create Duration and Delay_Mode objects used for passing a delay
-- value to RTS
D := Make_Temporary (Loc, 'D');
M := Make_Temporary (Loc, 'M');
declare
Discr : Entity_Id;
begin
-- Note that these values are defined in s-osprim.ads and must
-- be kept in sync:
--
-- Relative : constant := 0;
-- Absolute_Calendar : constant := 1;
-- Absolute_RT : constant := 2;
if Time_Type = Standard_Duration then
Discr := Make_Integer_Literal (Loc, 0);
elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
Discr := Make_Integer_Literal (Loc, 1);
else
pragma Assert
(Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
Discr := Make_Integer_Literal (Loc, 2);
end if;
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => D,
Object_Definition =>
New_Occurrence_Of (Standard_Duration, Loc)));
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => M,
Object_Definition =>
New_Occurrence_Of (Standard_Integer, Loc),
Expression => Discr));
end;
if Check_Guard then
Guard_Open :=
Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => Guard_Open,
Object_Definition =>
New_Occurrence_Of (Standard_Boolean, Loc),
Expression =>
New_Occurrence_Of (Standard_False, Loc)));
end if;
-- Delay_Count is zero, don't need M and D set (suppress warning)
else
M := Empty;
D := Empty;
end if;
if Present (Terminate_Alt) then
-- If the terminate alternative guard is False, use
-- Simple_Mode; otherwise use Terminate_Mode.
if Present (Condition (Terminate_Alt)) then
Select_Mode := Make_If_Expression (Loc,
New_List (Condition (Terminate_Alt),
New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc),
New_Occurrence_Of (RTE (RE_Simple_Mode), Loc)));
else
Select_Mode := New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc);
end if;
elsif Else_Present or Delay_Count > 0 then
Select_Mode := New_Occurrence_Of (RTE (RE_Else_Mode), Loc);
else
Select_Mode := New_Occurrence_Of (RTE (RE_Simple_Mode), Loc);
end if;
Select_Call := Make_Select_Call (Select_Mode);
Append (Select_Call, Stats);
-- Now generate code to act on the result. There is an entry
-- in this case for each accept statement with a non-null body,
-- followed by a branch to the statements that follow the Accept.
-- In the absence of delay alternatives, we generate:
-- case X is
-- when No_Rendezvous => -- omitted if simple mode
-- goto Lab0;
-- when 1 =>
-- P1n;
-- goto Lab1;
-- when 2 =>
-- P2n;
-- goto Lab2;
-- when others =>
-- goto Exit;
-- end case;
--
-- Lab0: Else_Statements;
-- goto exit;
-- Lab1: Trailing_Statements1;
-- goto Exit;
--
-- Lab2: Trailing_Statements2;
-- goto Exit;
-- ...
-- Exit:
-- Generate label for common exit
End_Lab := Make_And_Declare_Label (Num_Alts + 1);
-- First entry is the default case, when no rendezvous is possible
Choices := New_List (New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc));
if Else_Present then
-- If no rendezvous is possible, the else part is executed
Lab := Make_And_Declare_Label (0);
Alt_Stats := New_List (
Make_Goto_Statement (Loc,
Name => New_Copy (Identifier (Lab))));
Append (Lab, Trailing_List);
Append_List (Else_Statements (N), Trailing_List);
Append_To (Trailing_List,
Make_Goto_Statement (Loc,
Name => New_Copy (Identifier (End_Lab))));
else
Alt_Stats := New_List (
Make_Goto_Statement (Loc,
Name => New_Copy (Identifier (End_Lab))));
end if;
Append_To (Alt_List,
Make_Case_Statement_Alternative (Loc,
Discrete_Choices => Choices,
Statements => Alt_Stats));
-- We make use of the fact that Accept_Index is an integer type, and
-- generate successive literals for entries for each accept. Only those
-- for which there is a body or trailing statements get a case entry.
Alt := First (Select_Alternatives (N));
Proc := First (Body_List);
while Present (Alt) loop
if Nkind (Alt) = N_Accept_Alternative then
Process_Accept_Alternative (Alt, Index, Proc);
Index := Index + 1;
if Present
(Handled_Statement_Sequence (Accept_Statement (Alt)))
then
Next (Proc);
end if;
elsif Nkind (Alt) = N_Delay_Alternative then
Process_Delay_Alternative (Alt, Delay_Num);
Delay_Num := Delay_Num + 1;
end if;
Next (Alt);
end loop;
-- An others choice is always added to the main case, as well
-- as the delay case (to satisfy the compiler).
Append_To (Alt_List,
Make_Case_Statement_Alternative (Loc,
Discrete_Choices =>
New_List (Make_Others_Choice (Loc)),
Statements =>
New_List (Make_Goto_Statement (Loc,
Name => New_Copy (Identifier (End_Lab))))));
Accept_Case := New_List (
Make_Case_Statement (Loc,
Expression => New_Occurrence_Of (Xnam, Loc),
Alternatives => Alt_List));
Append_List (Trailing_List, Accept_Case);
Append_List (Body_List, Decls);
-- Construct case statement for trailing statements of delay
-- alternatives, if there are several of them.
if Delay_Count > 1 then
Append_To (Delay_Alt_List,
Make_Case_Statement_Alternative (Loc,
Discrete_Choices =>
New_List (Make_Others_Choice (Loc)),
Statements =>
New_List (Make_Null_Statement (Loc))));
Delay_Case := New_List (
Make_Case_Statement (Loc,
Expression => New_Occurrence_Of (Delay_Index, Loc),
Alternatives => Delay_Alt_List));
else
Delay_Case := Delay_Alt_List;
end if;
-- If there are no delay alternatives, we append the case statement
-- to the statement list.
if Delay_Count = 0 then
Append_List (Accept_Case, Stats);
-- Delay alternatives present
else
-- If delay alternatives are present we generate:
-- find minimum delay.
-- DX := minimum delay;
-- M := <delay mode>;
-- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
-- DX, MX, X);
--
-- if X = No_Rendezvous then
-- case statement for delay statements.
-- else
-- case statement for accept alternatives.
-- end if;
declare
Cases : Node_Id;
Stmt : Node_Id;
Parms : List_Id;
Parm : Node_Id;
Conv : Node_Id;
begin
-- The type of the delay expression is known to be legal
if Time_Type = Standard_Duration then
Conv := New_Occurrence_Of (Delay_Min, Loc);
elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
Conv := Make_Function_Call (Loc,
New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc),
New_List (New_Occurrence_Of (Delay_Min, Loc)));
else
pragma Assert
(Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
Conv := Make_Function_Call (Loc,
New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc),
New_List (New_Occurrence_Of (Delay_Min, Loc)));
end if;
Stmt := Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (D, Loc),
Expression => Conv);
-- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
Parms := Parameter_Associations (Select_Call);
Parm := First (Parms);
while Present (Parm) and then Parm /= Select_Mode loop
Next (Parm);
end loop;
pragma Assert (Present (Parm));
Rewrite (Parm, New_Occurrence_Of (RTE (RE_Delay_Mode), Loc));
Analyze (Parm);
-- Prepare two new parameters of Duration and Delay_Mode type
-- which represent the value and the mode of the minimum delay.
Next (Parm);
Insert_After (Parm, New_Occurrence_Of (M, Loc));
Insert_After (Parm, New_Occurrence_Of (D, Loc));
-- Create a call to RTS
Rewrite (Select_Call,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Timed_Selective_Wait), Loc),
Parameter_Associations => Parms));
-- This new call should follow the calculation of the minimum
-- delay.
Insert_List_Before (Select_Call, Delay_List);
if Check_Guard then
Stmt :=
Make_Implicit_If_Statement (N,
Condition => New_Occurrence_Of (Guard_Open, Loc),
Then_Statements => New_List (
New_Copy_Tree (Stmt),
New_Copy_Tree (Select_Call)),
Else_Statements => Accept_Or_Raise);
Rewrite (Select_Call, Stmt);
else
Insert_Before (Select_Call, Stmt);
end if;
Cases :=
Make_Implicit_If_Statement (N,
Condition => Make_Op_Eq (Loc,
Left_Opnd => New_Occurrence_Of (Xnam, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)),
Then_Statements => Delay_Case,
Else_Statements => Accept_Case);
Append (Cases, Stats);
end;
end if;
Append (End_Lab, Stats);
-- Replace accept statement with appropriate block
Rewrite (N,
Make_Block_Statement (Loc,
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats)));
Analyze (N);
-- Note: have to worry more about abort deferral in above code ???
-- Final step is to unstack the Accept_Address entries for all accept
-- statements appearing in accept alternatives in the select statement
Alt := First (Alts);
while Present (Alt) loop
if Nkind (Alt) = N_Accept_Alternative then
Remove_Last_Elmt (Accept_Address
(Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
end if;
Next (Alt);
end loop;
end Expand_N_Selective_Accept;
-------------------------------------------
-- Expand_N_Single_Protected_Declaration --
-------------------------------------------
-- A single protected declaration should never be present after semantic
-- analysis because it is transformed into a protected type declaration
-- and an accompanying anonymous object. This routine ensures that the
-- transformation takes place.
procedure Expand_N_Single_Protected_Declaration (N : Node_Id) is
begin
raise Program_Error;
end Expand_N_Single_Protected_Declaration;
--------------------------------------
-- Expand_N_Single_Task_Declaration --
--------------------------------------
-- A single task declaration should never be present after semantic
-- analysis because it is transformed into a task type declaration and
-- an accompanying anonymous object. This routine ensures that the
-- transformation takes place.
procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
begin
raise Program_Error;
end Expand_N_Single_Task_Declaration;
------------------------
-- Expand_N_Task_Body --
------------------------
-- Given a task body
-- task body tname is
-- <declarations>
-- begin
-- <statements>
-- end x;
-- This expansion routine converts it into a procedure and sets the
-- elaboration flag for the procedure to true, to represent the fact
-- that the task body is now elaborated:
-- procedure tnameB (_Task : access tnameV) is
-- discriminal : dtype renames _Task.discriminant;
-- procedure _clean is
-- begin
-- Abort_Defer.all;
-- Complete_Task;
-- Abort_Undefer.all;
-- return;
-- end _clean;
-- begin
-- Abort_Undefer.all;
-- <declarations>
-- System.Task_Stages.Complete_Activation;
-- <statements>
-- at end
-- _clean;
-- end tnameB;
-- tnameE := True;
-- In addition, if the task body is an activator, then a call to activate
-- tasks is added at the start of the statements, before the call to
-- Complete_Activation, and if in addition the task is a master then it
-- must be established as a master. These calls are inserted and analyzed
-- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
-- expanded.
-- There is one discriminal declaration line generated for each
-- discriminant that is present to provide an easy reference point for
-- discriminant references inside the body (see Exp_Ch2.Expand_Name).
-- Note on relationship to GNARLI definition. In the GNARLI definition,
-- task body procedures have a profile (Arg : System.Address). That is
-- needed because GNARLI has to use the same access-to-subprogram type
-- for all task types. We depend here on knowing that in GNAT, passing
-- an address argument by value is identical to passing a record value
-- by access (in either case a single pointer is passed), so even though
-- this procedure has the wrong profile. In fact it's all OK, since the
-- callings sequence is identical.
procedure Expand_N_Task_Body (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Ttyp : constant Entity_Id := Corresponding_Spec (N);
Call : Node_Id;
New_N : Node_Id;
Insert_Nod : Node_Id;
-- Used to determine the proper location of wrapper body insertions
begin
-- if no task body procedure, means we had an error in configurable
-- run-time mode, and there is no point in proceeding further.
if No (Task_Body_Procedure (Ttyp)) then
return;
end if;
-- Add renaming declarations for discriminals and a declaration for the
-- entry family index (if applicable).
Install_Private_Data_Declarations
(Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
-- Add a call to Abort_Undefer at the very beginning of the task
-- body since this body is called with abort still deferred.
if Abort_Allowed then
Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
Insert_Before
(First (Statements (Handled_Statement_Sequence (N))), Call);
Analyze (Call);
end if;
-- The statement part has already been protected with an at_end and
-- cleanup actions. The call to Complete_Activation must be placed
-- at the head of the sequence of statements of that block. The
-- declarations have been merged in this sequence of statements but
-- the first real statement is accessible from the First_Real_Statement
-- field (which was set for exactly this purpose).
if Restricted_Profile then
Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
else
Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
end if;
Insert_Before
(First_Real_Statement (Handled_Statement_Sequence (N)), Call);
Analyze (Call);
New_N :=
Make_Subprogram_Body (Loc,
Specification => Build_Task_Proc_Specification (Ttyp),
Declarations => Declarations (N),
Handled_Statement_Sequence => Handled_Statement_Sequence (N));
Set_Is_Task_Body_Procedure (New_N);
-- If the task contains generic instantiations, cleanup actions are
-- delayed until after instantiation. Transfer the activation chain to
-- the subprogram, to insure that the activation call is properly
-- generated. It the task body contains inner tasks, indicate that the
-- subprogram is a task master.
if Delay_Cleanups (Ttyp) then
Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
Set_Is_Task_Master (New_N, Is_Task_Master (N));
end if;
Rewrite (N, New_N);
Analyze (N);
-- Set elaboration flag immediately after task body. If the body is a
-- subunit, the flag is set in the declarative part containing the stub.
if Nkind (Parent (N)) /= N_Subunit then
Insert_After (N,
Make_Assignment_Statement (Loc,
Name =>
Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
Expression => New_Occurrence_Of (Standard_True, Loc)));
end if;
-- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
-- the task body. At this point all wrapper specs have been created,
-- frozen and included in the dispatch table for the task type.
if Ada_Version >= Ada_2005 then
if Nkind (Parent (N)) = N_Subunit then
Insert_Nod := Corresponding_Stub (Parent (N));
else
Insert_Nod := N;
end if;
Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
end if;
end Expand_N_Task_Body;
------------------------------------
-- Expand_N_Task_Type_Declaration --
------------------------------------
-- We have several things to do. First we must create a Boolean flag used
-- to mark if the body is elaborated yet. This variable gets set to True
-- when the body of the task is elaborated (we can't rely on the normal
-- ABE mechanism for the task body, since we need to pass an access to
-- this elaboration boolean to the runtime routines).
-- taskE : aliased Boolean := False;
-- Next a variable is declared to hold the task stack size (either the
-- default : Unspecified_Size, or a value that is set by a pragma
-- Storage_Size). If the value of the pragma Storage_Size is static, then
-- the variable is initialized with this value:
-- taskZ : Size_Type := Unspecified_Size;
-- or
-- taskZ : Size_Type := Size_Type (size_expression);
-- Note: No variable is needed to hold the task relative deadline since
-- its value would never be static because the parameter is of a private
-- type (Ada.Real_Time.Time_Span).
-- Next we create a corresponding record type declaration used to represent
-- values of this task. The general form of this type declaration is
-- type taskV (discriminants) is record
-- _Task_Id : Task_Id;
-- entry_family : array (bounds) of Void;
-- _Priority : Integer := priority_expression;
-- _Size : Size_Type := size_expression;
-- _Secondary_Stack_Size : Size_Type := size_expression;
-- _Task_Info : Task_Info_Type := task_info_expression;
-- _CPU : Integer := cpu_range_expression;
-- _Relative_Deadline : Time_Span := time_span_expression;
-- _Domain : Dispatching_Domain := dd_expression;
-- end record;
-- The discriminants are present only if the corresponding task type has
-- discriminants, and they exactly mirror the task type discriminants.
-- The Id field is always present. It contains the Task_Id value, as set by
-- the call to Create_Task. Note that although the task is limited, the
-- task value record type is not limited, so there is no problem in passing
-- this field as an out parameter to Create_Task.
-- One entry_family component is present for each entry family in the task
-- definition. The bounds correspond to the bounds of the entry family
-- (which may depend on discriminants). The element type is void, since we
-- only need the bounds information for determining the entry index. Note
-- that the use of an anonymous array would normally be illegal in this
-- context, but this is a parser check, and the semantics is quite prepared
-- to handle such a case.
-- The _Size field is present only if a Storage_Size pragma appears in the
-- task definition. The expression captures the argument that was present
-- in the pragma, and is used to override the task stack size otherwise
-- associated with the task type.
-- The _Secondary_Stack_Size field is present only the task entity has a
-- Secondary_Stack_Size rep item. It will be filled at the freeze point,
-- when the record init proc is built, to capture the expression of the
-- rep item (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot
-- be filled here since aspect evaluations are delayed till the freeze
-- point.
-- The _Priority field is present only if the task entity has a Priority or
-- Interrupt_Priority rep item (pragma, aspect specification or attribute
-- definition clause). It will be filled at the freeze point, when the
-- record init proc is built, to capture the expression of the rep item
-- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
-- here since aspect evaluations are delayed till the freeze point.
-- The _Task_Info field is present only if a Task_Info pragma appears in
-- the task definition. The expression captures the argument that was
-- present in the pragma, and is used to provide the Task_Image parameter
-- to the call to Create_Task.
-- The _CPU field is present only if the task entity has a CPU rep item
-- (pragma, aspect specification or attribute definition clause). It will
-- be filled at the freeze point, when the record init proc is built, to
-- capture the expression of the rep item (see Build_Record_Init_Proc in
-- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
-- are delayed till the freeze point.
-- The _Relative_Deadline field is present only if a Relative_Deadline
-- pragma appears in the task definition. The expression captures the
-- argument that was present in the pragma, and is used to provide the
-- Relative_Deadline parameter to the call to Create_Task.
-- The _Domain field is present only if the task entity has a
-- Dispatching_Domain rep item (pragma, aspect specification or attribute
-- definition clause). It will be filled at the freeze point, when the
-- record init proc is built, to capture the expression of the rep item
-- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
-- here since aspect evaluations are delayed till the freeze point.
-- When a task is declared, an instance of the task value record is
-- created. The elaboration of this declaration creates the correct bounds
-- for the entry families, and also evaluates the size, priority, and
-- task_Info expressions if needed. The initialization routine for the task
-- type itself then calls Create_Task with appropriate parameters to
-- initialize the value of the Task_Id field.
-- Note: the address of this record is passed as the "Discriminants"
-- parameter for Create_Task. Since Create_Task merely passes this onto the
-- body procedure, it does not matter that it does not quite match the
-- GNARLI model of what is being passed (the record contains more than just
-- the discriminants, but the discriminants can be found from the record
-- value).
-- The Entity_Id for this created record type is placed in the
-- Corresponding_Record_Type field of the associated task type entity.
-- Next we create a procedure specification for the task body procedure:
-- procedure taskB (_Task : access taskV);
-- Note that this must come after the record type declaration, since
-- the spec refers to this type. It turns out that the initialization
-- procedure for the value type references the task body spec, but that's
-- fine, since it won't be generated till the freeze point for the type,
-- which is certainly after the task body spec declaration.
-- Finally, we set the task index value field of the entry attribute in
-- the case of a simple entry.
procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
TaskId : constant Entity_Id := Defining_Identifier (N);
Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
Tasknm : constant Name_Id := Chars (Tasktyp);
Taskdef : constant Node_Id := Task_Definition (N);
Body_Decl : Node_Id;
Cdecls : List_Id;
Decl_Stack : Node_Id;
Decl_SS : Node_Id;
Elab_Decl : Node_Id;
Ent_Stack : Entity_Id;
Proc_Spec : Node_Id;
Rec_Decl : Node_Id;
Rec_Ent : Entity_Id;
Size_Decl : Entity_Id;
Task_Size : Node_Id;
function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id;
-- Searches the task definition T for the first occurrence of the pragma
-- Relative Deadline. The caller has ensured that the pragma is present
-- in the task definition. Note that this routine cannot be implemented
-- with the Rep Item chain mechanism since Relative_Deadline pragmas are
-- not chained because their expansion into a procedure call statement
-- would cause a break in the chain.
----------------------------------
-- Get_Relative_Deadline_Pragma --
----------------------------------
function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id is
N : Node_Id;
begin
N := First (Visible_Declarations (T));
while Present (N) loop
if Nkind (N) = N_Pragma
and then Pragma_Name (N) = Name_Relative_Deadline
then
return N;
end if;
Next (N);
end loop;
N := First (Private_Declarations (T));
while Present (N) loop
if Nkind (N) = N_Pragma
and then Pragma_Name (N) = Name_Relative_Deadline
then
return N;
end if;
Next (N);
end loop;
raise Program_Error;
end Get_Relative_Deadline_Pragma;
-- Start of processing for Expand_N_Task_Type_Declaration
begin
-- If already expanded, nothing to do
if Present (Corresponding_Record_Type (Tasktyp)) then
return;
end if;
-- Here we will do the expansion
Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
Rec_Ent := Defining_Identifier (Rec_Decl);
Cdecls := Component_Items (Component_List
(Type_Definition (Rec_Decl)));
Qualify_Entity_Names (N);
-- First create the elaboration variable
Elab_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Sloc (Tasktyp),
Chars => New_External_Name (Tasknm, 'E')),
Aliased_Present => True,
Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
Expression => New_Occurrence_Of (Standard_False, Loc));
Insert_After (N, Elab_Decl);
-- Next create the declaration of the size variable (tasknmZ)
Set_Storage_Size_Variable (Tasktyp,
Make_Defining_Identifier (Sloc (Tasktyp),
Chars => New_External_Name (Tasknm, 'Z')));
if Present (Taskdef)
and then Has_Storage_Size_Pragma (Taskdef)
and then
Is_OK_Static_Expression
(Expression
(First (Pragma_Argument_Associations
(Get_Rep_Pragma (TaskId, Name_Storage_Size)))))
then
Size_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Storage_Size_Variable (Tasktyp),
Object_Definition =>
New_Occurrence_Of (RTE (RE_Size_Type), Loc),
Expression =>
Convert_To (RTE (RE_Size_Type),
Relocate_Node
(Expression (First (Pragma_Argument_Associations
(Get_Rep_Pragma
(TaskId, Name_Storage_Size)))))));
else
Size_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Storage_Size_Variable (Tasktyp),
Object_Definition =>
New_Occurrence_Of (RTE (RE_Size_Type), Loc),
Expression =>
New_Occurrence_Of (RTE (RE_Unspecified_Size), Loc));
end if;
Insert_After (Elab_Decl, Size_Decl);
-- Next build the rest of the corresponding record declaration. This is
-- done last, since the corresponding record initialization procedure
-- will reference the previously created entities.
-- Fill in the component declarations -- first the _Task_Id field
Append_To (Cdecls,
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uTask_Id),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => False,
Subtype_Indication => New_Occurrence_Of (RTE (RO_ST_Task_Id),
Loc))));
-- Declare static ATCB (that is, created by the expander) if we are
-- using the Restricted run time.
if Restricted_Profile then
Append_To (Cdecls,
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uATCB),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => True,
Subtype_Indication => Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Ada_Task_Control_Block), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints =>
New_List (Make_Integer_Literal (Loc, 0)))))));
end if;
-- Declare static stack (that is, created by the expander) if we are
-- using the Restricted run time on a bare board configuration.
if Restricted_Profile and then Preallocated_Stacks_On_Target then
-- First we need to extract the appropriate stack size
Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
declare
Expr_N : constant Node_Id :=
Expression (First (
Pragma_Argument_Associations (
Get_Rep_Pragma (TaskId, Name_Storage_Size))));
Etyp : constant Entity_Id := Etype (Expr_N);
P : constant Node_Id := Parent (Expr_N);
begin
-- The stack is defined inside the corresponding record.
-- Therefore if the size of the stack is set by means of
-- a discriminant, we must reference the discriminant of the
-- corresponding record type.
if Nkind (Expr_N) in N_Has_Entity
and then Present (Discriminal_Link (Entity (Expr_N)))
then
Task_Size :=
New_Occurrence_Of
(CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
Loc);
Set_Parent (Task_Size, P);
Set_Etype (Task_Size, Etyp);
Set_Analyzed (Task_Size);
else
Task_Size := New_Copy_Tree (Expr_N);
end if;
end;
else
Task_Size :=
New_Occurrence_Of (RTE (RE_Default_Stack_Size), Loc);
end if;
Decl_Stack := Make_Component_Declaration (Loc,
Defining_Identifier => Ent_Stack,
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => True,
Subtype_Indication => Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (Make_Range (Loc,
Low_Bound => Make_Integer_Literal (Loc, 1),
High_Bound => Convert_To (RTE (RE_Storage_Offset),
Task_Size)))))));
Append_To (Cdecls, Decl_Stack);
-- The appropriate alignment for the stack is ensured by the run-time
-- code in charge of task creation.
end if;
-- Declare a static secondary stack if the conditions for a statically
-- generated stack are met.
if Create_Secondary_Stack_For_Task (TaskId) then
declare
Size_Expr : constant Node_Id :=
Expression (First (
Pragma_Argument_Associations (
Get_Rep_Pragma (TaskId,
Name_Secondary_Stack_Size))));
Stack_Size : Node_Id;
begin
-- The secondary stack is defined inside the corresponding
-- record. Therefore if the size of the stack is set by means
-- of a discriminant, we must reference the discriminant of the
-- corresponding record type.
if Nkind (Size_Expr) in N_Has_Entity
and then Present (Discriminal_Link (Entity (Size_Expr)))
then
Stack_Size :=
New_Occurrence_Of
(CR_Discriminant (Discriminal_Link (Entity (Size_Expr))),
Loc);
Set_Parent (Stack_Size, Parent (Size_Expr));
Set_Etype (Stack_Size, Etype (Size_Expr));
Set_Analyzed (Stack_Size);
else
Stack_Size := New_Copy_Tree (Size_Expr);
end if;
-- Create the secondary stack for the task
Decl_SS :=
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uSecondary_Stack),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => True,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (RTE (RE_SS_Stack), Loc),
Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => New_List (
Convert_To (RTE (RE_Size_Type),
Stack_Size))))));
Append_To (Cdecls, Decl_SS);
end;
end if;
-- Add components for entry families
Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
-- Add the _Priority component if a Interrupt_Priority or Priority rep
-- item is present.
if Has_Rep_Item (TaskId, Name_Priority, Check_Parents => False) then
Append_To (Cdecls,
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uPriority),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => False,
Subtype_Indication =>
New_Occurrence_Of (Standard_Integer, Loc))));
end if;
-- Add the _Size component if a Storage_Size pragma is present
if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
Append_To (Cdecls,
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uSize),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => False,
Subtype_Indication =>
New_Occurrence_Of (RTE (RE_Size_Type), Loc)),
Expression =>
Convert_To (RTE (RE_Size_Type),
New_Copy_Tree (
Expression (First (
Pragma_Argument_Associations (
Get_Rep_Pragma (TaskId, Name_Storage_Size))))))));
end if;
-- Add the _Secondary_Stack_Size component if a Secondary_Stack_Size
-- pragma is present.
if Has_Rep_Pragma
(TaskId, Name_Secondary_Stack_Size, Check_Parents => False)
then
Append_To (Cdecls,
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uSecondary_Stack_Size),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => False,
Subtype_Indication =>
New_Occurrence_Of (RTE (RE_Size_Type), Loc))));
end if;
-- Add the _Task_Info component if a Task_Info pragma is present
if Has_Rep_Pragma (TaskId, Name_Task_Info, Check_Parents => False) then
Append_To (Cdecls,
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uTask_Info),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => False,
Subtype_Indication =>
New_Occurrence_Of (RTE (RE_Task_Info_Type), Loc)),
Expression => New_Copy (
Expression (First (
Pragma_Argument_Associations (
Get_Rep_Pragma
(TaskId, Name_Task_Info, Check_Parents => False)))))));
end if;
-- Add the _CPU component if a CPU rep item is present
if Has_Rep_Item (TaskId, Name_CPU, Check_Parents => False) then
Append_To (Cdecls,
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uCPU),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => False,
Subtype_Indication =>
New_Occurrence_Of (RTE (RE_CPU_Range), Loc))));
end if;
-- Add the _Relative_Deadline component if a Relative_Deadline pragma is
-- present. If we are using a restricted run time this component will
-- not be added (deadlines are not allowed by the Ravenscar profile),
-- unless the task dispatching policy is EDF (for GNAT_Ravenscar_EDF
-- profile).
if (not Restricted_Profile or else Task_Dispatching_Policy = 'E')
and then Present (Taskdef)
and then Has_Relative_Deadline_Pragma (Taskdef)
then
Append_To (Cdecls,
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => False,
Subtype_Indication =>
New_Occurrence_Of (RTE (RE_Time_Span), Loc)),
Expression =>
Convert_To (RTE (RE_Time_Span),
New_Copy_Tree (
Expression (First (
Pragma_Argument_Associations (
Get_Relative_Deadline_Pragma (Taskdef))))))));
end if;
-- Add the _Dispatching_Domain component if a Dispatching_Domain rep
-- item is present. If we are using a restricted run time this component
-- will not be added (dispatching domains are not allowed by the
-- Ravenscar profile).
if not Restricted_Profile
and then
Has_Rep_Item
(TaskId, Name_Dispatching_Domain, Check_Parents => False)
then
Append_To (Cdecls,
Make_Component_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uDispatching_Domain),
Component_Definition =>
Make_Component_Definition (Loc,
Aliased_Present => False,
Subtype_Indication =>
New_Occurrence_Of
(RTE (RE_Dispatching_Domain_Access), Loc))));
end if;
Insert_After (Size_Decl, Rec_Decl);
-- Analyze the record declaration immediately after construction,
-- because the initialization procedure is needed for single task
-- declarations before the next entity is analyzed.
Analyze (Rec_Decl);
-- Create the declaration of the task body procedure
Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
Body_Decl :=
Make_Subprogram_Declaration (Loc,
Specification => Proc_Spec);
Set_Is_Task_Body_Procedure (Body_Decl);
Insert_After (Rec_Decl, Body_Decl);
-- The subprogram does not comes from source, so we have to indicate the
-- need for debugging information explicitly.
if Comes_From_Source (Original_Node (N)) then
Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
end if;
-- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
-- the corresponding record has been frozen.
if Ada_Version >= Ada_2005 then
Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
end if;
-- Ada 2005 (AI-345): We must defer freezing to allow further
-- declaration of primitive subprograms covering task interfaces
if Ada_Version <= Ada_95 then
-- Now we can freeze the corresponding record. This needs manually
-- freezing, since it is really part of the task type, and the task
-- type is frozen at this stage. We of course need the initialization
-- procedure for this corresponding record type and we won't get it
-- in time if we don't freeze now.
Insert_List_After (Body_Decl, List => Freeze_Entity (Rec_Ent, N));
end if;
-- Complete the expansion of access types to the current task type, if
-- any were declared.
Expand_Previous_Access_Type (Tasktyp);
-- Create wrappers for entries that have contract cases, preconditions
-- and postconditions.
declare
Ent : Entity_Id;
begin
Ent := First_Entity (Tasktyp);
while Present (Ent) loop
if Ekind (Ent) in E_Entry | E_Entry_Family then
Build_Contract_Wrapper (Ent, N);
end if;
Next_Entity (Ent);
end loop;
end;
end Expand_N_Task_Type_Declaration;
-------------------------------
-- Expand_N_Timed_Entry_Call --
-------------------------------
-- A timed entry call in normal case is not implemented using ATC mechanism
-- anymore for efficiency reason.
-- select
-- T.E;
-- S1;
-- or
-- delay D;
-- S2;
-- end select;
-- is expanded as follows:
-- 1) When T.E is a task entry_call;
-- declare
-- B : Boolean;
-- X : Task_Entry_Index := <entry index>;
-- DX : Duration := To_Duration (D);
-- M : Delay_Mode := <discriminant>;
-- P : parms := (parm, parm, parm);
-- begin
-- Timed_Protected_Entry_Call
-- (<acceptor-task>, X, P'Address, DX, M, B);
-- if B then
-- S1;
-- else
-- S2;
-- end if;
-- end;
-- 2) When T.E is a protected entry_call;
-- declare
-- B : Boolean;
-- X : Protected_Entry_Index := <entry index>;
-- DX : Duration := To_Duration (D);
-- M : Delay_Mode := <discriminant>;
-- P : parms := (parm, parm, parm);
-- begin
-- Timed_Protected_Entry_Call
-- (<object>'unchecked_access, X, P'Address, DX, M, B);
-- if B then
-- S1;
-- else
-- S2;
-- end if;
-- end;
-- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
-- is no delay and the triggering statements are executed. We first
-- determine the kind of the triggering call and then execute a
-- synchronized operation or a direct call.
-- declare
-- B : Boolean := False;
-- C : Ada.Tags.Prim_Op_Kind;
-- DX : Duration := To_Duration (D)
-- K : Ada.Tags.Tagged_Kind :=
-- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
-- M : Integer :=...;
-- P : Parameters := (Param1 .. ParamN);
-- S : Integer;
-- begin
-- if K = Ada.Tags.TK_Limited_Tagged
-- or else K = Ada.Tags.TK_Tagged
-- then
-- <dispatching-call>;
-- B := True;
-- else
-- S :=
-- Ada.Tags.Get_Offset_Index
-- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
-- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
-- if C = POK_Protected_Entry
-- or else C = POK_Task_Entry
-- then
-- Param1 := P.Param1;
-- ...
-- ParamN := P.ParamN;
-- end if;
-- if B then
-- if C = POK_Procedure
-- or else C = POK_Protected_Procedure
-- or else C = POK_Task_Procedure
-- then
-- <dispatching-call>;
-- end if;
-- end if;
-- end if;
-- if B then
-- <triggering-statements>
-- else
-- <timed-statements>
-- end if;
-- end;
-- The triggering statement and the sequence of timed statements have not
-- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
-- global references if within an instantiation.
procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
Actuals : List_Id;
Blk_Typ : Entity_Id;
Call : Node_Id;
Call_Ent : Entity_Id;
Conc_Typ_Stmts : List_Id;
Concval : Node_Id := Empty; -- init to avoid warning
D_Alt : constant Node_Id := Delay_Alternative (N);
D_Conv : Node_Id;
D_Disc : Node_Id;
D_Stat : Node_Id := Delay_Statement (D_Alt);
D_Stats : List_Id;
D_Type : Entity_Id;
Decls : List_Id;
Dummy : Node_Id;
E_Alt : constant Node_Id := Entry_Call_Alternative (N);
E_Call : Node_Id := Entry_Call_Statement (E_Alt);
E_Stats : List_Id;
Ename : Node_Id;
Formals : List_Id;
Index : Node_Id;
Is_Disp_Select : Boolean;
Lim_Typ_Stmts : List_Id;
Loc : constant Source_Ptr := Sloc (D_Stat);
N_Stats : List_Id;
Obj : Entity_Id;
Param : Node_Id;
Params : List_Id;
Stmt : Node_Id;
Stmts : List_Id;
Unpack : List_Id;
B : Entity_Id; -- Call status flag
C : Entity_Id; -- Call kind
D : Entity_Id; -- Delay
K : Entity_Id; -- Tagged kind
M : Entity_Id; -- Delay mode
P : Entity_Id; -- Parameter block
S : Entity_Id; -- Primitive operation slot
-- Start of processing for Expand_N_Timed_Entry_Call
begin
-- Under the Ravenscar profile, timed entry calls are excluded. An error
-- was already reported on spec, so do not attempt to expand the call.
if Restriction_Active (No_Select_Statements) then
return;
end if;
Process_Statements_For_Controlled_Objects (E_Alt);
Process_Statements_For_Controlled_Objects (D_Alt);
Ensure_Statement_Present (Sloc (D_Stat), D_Alt);
-- Retrieve E_Stats and D_Stats now because the finalization machinery
-- may wrap them in blocks.
E_Stats := Statements (E_Alt);
D_Stats := Statements (D_Alt);
-- The arguments in the call may require dynamic allocation, and the
-- call statement may have been transformed into a block. The block
-- may contain additional declarations for internal entities, and the
-- original call is found by sequential search.
if Nkind (E_Call) = N_Block_Statement then
E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
while Nkind (E_Call) not in
N_Procedure_Call_Statement | N_Entry_Call_Statement
loop
Next (E_Call);
end loop;
end if;
Is_Disp_Select :=
Ada_Version >= Ada_2005
and then Nkind (E_Call) = N_Procedure_Call_Statement;
if Is_Disp_Select then
Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
Decls := New_List;
Stmts := New_List;
-- Generate:
-- B : Boolean := False;
B := Build_B (Loc, Decls);
-- Generate:
-- C : Ada.Tags.Prim_Op_Kind;
C := Build_C (Loc, Decls);
-- Because the analysis of all statements was disabled, manually
-- analyze the delay statement.
Analyze (D_Stat);
D_Stat := Original_Node (D_Stat);
else
-- Build an entry call using Simple_Entry_Call
Extract_Entry (E_Call, Concval, Ename, Index);
Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
Decls := Declarations (E_Call);
Stmts := Statements (Handled_Statement_Sequence (E_Call));
if No (Decls) then
Decls := New_List;
end if;
-- Generate:
-- B : Boolean;
B := Make_Defining_Identifier (Loc, Name_uB);
Prepend_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => B,
Object_Definition =>
New_Occurrence_Of (Standard_Boolean, Loc)));
end if;
-- Duration and mode processing
D_Type := Base_Type (Etype (Expression (D_Stat)));
-- Use the type of the delay expression (Calendar or Real_Time) to
-- generate the appropriate conversion.
if Nkind (D_Stat) = N_Delay_Relative_Statement then
D_Disc := Make_Integer_Literal (Loc, 0);
D_Conv := Relocate_Node (Expression (D_Stat));
elsif Is_RTE (D_Type, RO_CA_Time) then
D_Disc := Make_Integer_Literal (Loc, 1);
D_Conv :=
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc),
Parameter_Associations =>
New_List (New_Copy (Expression (D_Stat))));
else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
D_Disc := Make_Integer_Literal (Loc, 2);
D_Conv :=
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc),
Parameter_Associations =>
New_List (New_Copy (Expression (D_Stat))));
end if;
D := Make_Temporary (Loc, 'D');
-- Generate:
-- D : Duration;
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => D,
Object_Definition => New_Occurrence_Of (Standard_Duration, Loc)));
M := Make_Temporary (Loc, 'M');
-- Generate:
-- M : Integer := (0 | 1 | 2);
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => M,
Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
Expression => D_Disc));
-- Parameter block processing
-- Manually create the parameter block for dispatching calls. In the
-- case of entries, the block has already been created during the call
-- to Build_Simple_Entry_Call.
if Is_Disp_Select then
-- Compute the delay at this stage because the evaluation of its
-- expression must not occur earlier (see ACVC C97302A).
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (D, Loc),
Expression => D_Conv));
-- Tagged kind processing, generate:
-- K : Ada.Tags.Tagged_Kind :=
-- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
K := Build_K (Loc, Decls, Obj);
Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
P :=
Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
-- Dispatch table slot processing, generate:
-- S : Integer;
S := Build_S (Loc, Decls);
-- Generate:
-- S := Ada.Tags.Get_Offset_Index
-- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
Conc_Typ_Stmts :=
New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
-- Generate:
-- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
-- where Obj is the controlling formal parameter, S is the dispatch
-- table slot number of the dispatching operation, P is the wrapped
-- parameter block, D is the duration, M is the duration mode, C is
-- the call kind and B is the call status.
Params := New_List;
Append_To (Params, New_Copy_Tree (Obj));
Append_To (Params, New_Occurrence_Of (S, Loc));
Append_To (Params,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (P, Loc),
Attribute_Name => Name_Address));
Append_To (Params, New_Occurrence_Of (D, Loc));
Append_To (Params, New_Occurrence_Of (M, Loc));
Append_To (Params, New_Occurrence_Of (C, Loc));
Append_To (Params, New_Occurrence_Of (B, Loc));
Append_To (Conc_Typ_Stmts,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(Find_Prim_Op
(Etype (Etype (Obj)), Name_uDisp_Timed_Select), Loc),
Parameter_Associations => Params));
-- Generate:
-- if C = POK_Protected_Entry
-- or else C = POK_Task_Entry
-- then
-- Param1 := P.Param1;
-- ...
-- ParamN := P.ParamN;
-- end if;
Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
-- Generate the if statement only when the packed parameters need
-- explicit assignments to their corresponding actuals.
if Present (Unpack) then
Append_To (Conc_Typ_Stmts,
Make_Implicit_If_Statement (N,
Condition =>
Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd => New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of
(RTE (RE_POK_Protected_Entry), Loc)),
Right_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd => New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
Then_Statements => Unpack));
end if;
-- Generate:
-- if B then
-- if C = POK_Procedure
-- or else C = POK_Protected_Procedure
-- or else C = POK_Task_Procedure
-- then
-- <dispatching-call>
-- end if;
-- end if;
N_Stats := New_List (
Make_Implicit_If_Statement (N,
Condition =>
Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd => New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)),
Right_Opnd =>
Make_Or_Else (Loc,
Left_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd => New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of (RTE (
RE_POK_Protected_Procedure), Loc)),
Right_Opnd =>
Make_Op_Eq (Loc,
Left_Opnd => New_Occurrence_Of (C, Loc),
Right_Opnd =>
New_Occurrence_Of
(RTE (RE_POK_Task_Procedure), Loc)))),
Then_Statements => New_List (E_Call)));
Append_To (Conc_Typ_Stmts,
Make_Implicit_If_Statement (N,
Condition => New_Occurrence_Of (B, Loc),
Then_Statements => N_Stats));
-- Generate:
-- <dispatching-call>;
-- B := True;
Lim_Typ_Stmts :=
New_List (New_Copy_Tree (E_Call),
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (B, Loc),
Expression => New_Occurrence_Of (Standard_True, Loc)));
-- Generate:
-- if K = Ada.Tags.TK_Limited_Tagged
-- or else K = Ada.Tags.TK_Tagged
-- then
-- Lim_Typ_Stmts
-- else
-- Conc_Typ_Stmts
-- end if;
Append_To (Stmts,
Make_Implicit_If_Statement (N,
Condition => Build_Dispatching_Tag_Check (K, N),
Then_Statements => Lim_Typ_Stmts,
Else_Statements => Conc_Typ_Stmts));
-- Generate:
-- if B then
-- <triggering-statements>
-- else
-- <timed-statements>
-- end if;
Append_To (Stmts,
Make_Implicit_If_Statement (N,
Condition => New_Occurrence_Of (B, Loc),
Then_Statements => E_Stats,
Else_Statements => D_Stats));
else
-- Simple case of a nondispatching trigger. Skip assignments to
-- temporaries created for in-out parameters.
-- This makes unwarranted assumptions about the shape of the expanded
-- tree for the call, and should be cleaned up ???
Stmt := First (Stmts);
while Nkind (Stmt) /= N_Procedure_Call_Statement loop
Next (Stmt);
end loop;
-- Compute the delay at this stage because the evaluation of
-- its expression must not occur earlier (see ACVC C97302A).
Insert_Before (Stmt,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (D, Loc),
Expression => D_Conv));
Call := Stmt;
Params := Parameter_Associations (Call);
-- For a protected type, we build a Timed_Protected_Entry_Call
if Is_Protected_Type (Etype (Concval)) then
-- Create a new call statement
Param := First (Params);
while Present (Param)
and then not Is_RTE (Etype (Param), RE_Call_Modes)
loop
Next (Param);
end loop;
Dummy := Remove_Next (Next (Param));
-- Remove garbage is following the Cancel_Param if present
Dummy := Next (Param);
-- Remove the mode of the Protected_Entry_Call call, then remove
-- the Communication_Block of the Protected_Entry_Call call, and
-- finally add Duration and a Delay_Mode parameter
pragma Assert (Present (Param));
Rewrite (Param, New_Occurrence_Of (D, Loc));
Rewrite (Dummy, New_Occurrence_Of (M, Loc));
-- Add a Boolean flag for successful entry call
Append_To (Params, New_Occurrence_Of (B, Loc));
case Corresponding_Runtime_Package (Etype (Concval)) is
when System_Tasking_Protected_Objects_Entries =>
Rewrite (Call,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(RTE (RE_Timed_Protected_Entry_Call), Loc),
Parameter_Associations => Params));
when others =>
raise Program_Error;
end case;
-- For the task case, build a Timed_Task_Entry_Call
else
-- Create a new call statement
Append_To (Params, New_Occurrence_Of (D, Loc));
Append_To (Params, New_Occurrence_Of (M, Loc));
Append_To (Params, New_Occurrence_Of (B, Loc));
Rewrite (Call,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Timed_Task_Entry_Call), Loc),
Parameter_Associations => Params));
end if;
Append_To (Stmts,
Make_Implicit_If_Statement (N,
Condition => New_Occurrence_Of (B, Loc),
Then_Statements => E_Stats,
Else_Statements => D_Stats));
end if;
Rewrite (N,
Make_Block_Statement (Loc,
Declarations => Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
Analyze (N);
-- Some items in Decls used to be in the N_Block in E_Call that is
-- constructed in Expand_Entry_Call, and are now in the new Block
-- into which N has been rewritten. Adjust their scopes to reflect that.
if Nkind (E_Call) = N_Block_Statement then
Obj := First_Entity (Entity (Identifier (E_Call)));
while Present (Obj) loop
Set_Scope (Obj, Entity (Identifier (N)));
Next_Entity (Obj);
end loop;
end if;
Reset_Scopes_To (N, Entity (Identifier (N)));
end Expand_N_Timed_Entry_Call;
----------------------------------------
-- Expand_Protected_Body_Declarations --
----------------------------------------
procedure Expand_Protected_Body_Declarations
(N : Node_Id;
Spec_Id : Entity_Id)
is
begin
if No_Run_Time_Mode then
Error_Msg_CRT ("protected body", N);
return;
elsif Expander_Active then
-- Associate discriminals with the first subprogram or entry body to
-- be expanded.
if Present (First_Protected_Operation (Declarations (N))) then
Set_Discriminals (Parent (Spec_Id));
end if;
end if;
end Expand_Protected_Body_Declarations;
-------------------------
-- External_Subprogram --
-------------------------
function External_Subprogram (E : Entity_Id) return Entity_Id is
Subp : constant Entity_Id := Protected_Body_Subprogram (E);
begin
-- The internal and external subprograms follow each other on the entity
-- chain. Note that previously private operations had no separate
-- external subprogram. We now create one in all cases, because a
-- private operation may actually appear in an external call, through
-- a 'Access reference used for a callback.
-- If the operation is a function that returns an anonymous access type,
-- the corresponding itype appears before the operation, and must be
-- skipped.
-- This mechanism is fragile, there should be a real link between the
-- two versions of the operation, but there is no place to put it ???
if Is_Access_Type (Next_Entity (Subp)) then
return Next_Entity (Next_Entity (Subp));
else
return Next_Entity (Subp);
end if;
end External_Subprogram;
------------------------------
-- Extract_Dispatching_Call --
------------------------------
procedure Extract_Dispatching_Call
(N : Node_Id;
Call_Ent : out Entity_Id;
Object : out Entity_Id;
Actuals : out List_Id;
Formals : out List_Id)
is
Call_Nam : Node_Id;
begin
pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
if Present (Original_Node (N)) then
Call_Nam := Name (Original_Node (N));
else
Call_Nam := Name (N);
end if;
-- Retrieve the name of the dispatching procedure. It contains the
-- dispatch table slot number.
loop
case Nkind (Call_Nam) is
when N_Identifier =>
exit;
when N_Selected_Component =>
Call_Nam := Selector_Name (Call_Nam);
when others =>
raise Program_Error;
end case;
end loop;
Actuals := Parameter_Associations (N);
Call_Ent := Entity (Call_Nam);
Formals := Parameter_Specifications (Parent (Call_Ent));
Object := First (Actuals);
if Present (Original_Node (Object)) then
Object := Original_Node (Object);
end if;
-- If the type of the dispatching object is an access type then return
-- an explicit dereference of a copy of the object, and note that this
-- is the controlling actual of the call.
if Is_Access_Type (Etype (Object)) then
Object :=
Make_Explicit_Dereference (Sloc (N), New_Copy_Tree (Object));
Analyze (Object);
Set_Is_Controlling_Actual (Object);
end if;
end Extract_Dispatching_Call;
-------------------
-- Extract_Entry --
-------------------
procedure Extract_Entry
(N : Node_Id;
Concval : out Node_Id;
Ename : out Node_Id;
Index : out Node_Id)
is
Nam : constant Node_Id := Name (N);
begin
-- For a simple entry, the name is a selected component, with the
-- prefix being the task value, and the selector being the entry.
if Nkind (Nam) = N_Selected_Component then
Concval := Prefix (Nam);
Ename := Selector_Name (Nam);
Index := Empty;
-- For a member of an entry family, the name is an indexed component
-- where the prefix is a selected component, whose prefix in turn is
-- the task value, and whose selector is the entry family. The single
-- expression in the expressions list of the indexed component is the
-- subscript for the family.
else pragma Assert (Nkind (Nam) = N_Indexed_Component);
Concval := Prefix (Prefix (Nam));
Ename := Selector_Name (Prefix (Nam));
Index := First (Expressions (Nam));
end if;
-- Through indirection, the type may actually be a limited view of a
-- concurrent type. When compiling a call, the non-limited view of the
-- type is visible.
if From_Limited_With (Etype (Concval)) then
Set_Etype (Concval, Non_Limited_View (Etype (Concval)));
end if;
end Extract_Entry;
-------------------
-- Family_Offset --
-------------------
function Family_Offset
(Loc : Source_Ptr;
Hi : Node_Id;
Lo : Node_Id;
Ttyp : Entity_Id;
Cap : Boolean) return Node_Id
is
Ityp : Entity_Id;
Real_Hi : Node_Id;
Real_Lo : Node_Id;
function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
-- If one of the bounds is a reference to a discriminant, replace with
-- corresponding discriminal of type. Within the body of a task retrieve
-- the renamed discriminant by simple visibility, using its generated
-- name. Within a protected object, find the original discriminant and
-- replace it with the discriminal of the current protected operation.
------------------------------
-- Convert_Discriminant_Ref --
------------------------------
function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (Bound);
B : Node_Id;
D : Entity_Id;
begin
if Is_Entity_Name (Bound)
and then Ekind (Entity (Bound)) = E_Discriminant
then
if Is_Task_Type (Ttyp) and then Has_Completion (Ttyp) then
B := Make_Identifier (Loc, Chars (Entity (Bound)));
Find_Direct_Name (B);
elsif Is_Protected_Type (Ttyp) then
D := First_Discriminant (Ttyp);
while Chars (D) /= Chars (Entity (Bound)) loop
Next_Discriminant (D);
end loop;
B := New_Occurrence_Of (Discriminal (D), Loc);
else
B := New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
end if;
elsif Nkind (Bound) = N_Attribute_Reference then
return Bound;
else
B := New_Copy_Tree (Bound);
end if;
return
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Pos,
Prefix => New_Occurrence_Of (Etype (Bound), Loc),
Expressions => New_List (B));
end Convert_Discriminant_Ref;
-- Start of processing for Family_Offset
begin
Real_Hi := Convert_Discriminant_Ref (Hi);
Real_Lo := Convert_Discriminant_Ref (Lo);
if Cap then
if Is_Task_Type (Ttyp) then
Ityp := RTE (RE_Task_Entry_Index);
else
Ityp := RTE (RE_Protected_Entry_Index);
end if;
Real_Hi :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Ityp, Loc),
Attribute_Name => Name_Min,
Expressions => New_List (
Real_Hi,
Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
Real_Lo :=
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Ityp, Loc),
Attribute_Name => Name_Max,
Expressions => New_List (
Real_Lo,
Make_Integer_Literal (Loc, -Entry_Family_Bound)));
end if;
return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
end Family_Offset;
-----------------
-- Family_Size --
-----------------
function Family_Size
(Loc : Source_Ptr;
Hi : Node_Id;
Lo : Node_Id;
Ttyp : Entity_Id;
Cap : Boolean) return Node_Id
is
Ityp : Entity_Id;
begin
if Is_Task_Type (Ttyp) then
Ityp := RTE (RE_Task_Entry_Index);
else
Ityp := RTE (RE_Protected_Entry_Index);
end if;
return
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Ityp, Loc),
Attribute_Name => Name_Max,
Expressions => New_List (
Make_Op_Add (Loc,
Left_Opnd => Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
Right_Opnd => Make_Integer_Literal (Loc, 1)),
Make_Integer_Literal (Loc, 0)));
end Family_Size;
----------------------------
-- Find_Enclosing_Context --
----------------------------
procedure Find_Enclosing_Context
(N : Node_Id;
Context : out Node_Id;
Context_Id : out Entity_Id;
Context_Decls : out List_Id)
is
begin
-- Traverse the parent chain looking for an enclosing body, block,
-- package or return statement.
Context := Parent (N);
while Present (Context) loop
if Nkind (Context) in N_Entry_Body
| N_Extended_Return_Statement
| N_Package_Body
| N_Package_Declaration
| N_Subprogram_Body
| N_Task_Body
then
exit;
-- Do not consider block created to protect a list of statements with
-- an Abort_Defer / Abort_Undefer_Direct pair.
elsif Nkind (Context) = N_Block_Statement
and then not Is_Abort_Block (Context)
then
exit;
end if;
Context := Parent (Context);
end loop;
pragma Assert (Present (Context));
-- Extract the constituents of the context
if Nkind (Context) = N_Extended_Return_Statement then
Context_Decls := Return_Object_Declarations (Context);
Context_Id := Return_Statement_Entity (Context);
-- Package declarations and bodies use a common library-level activation
-- chain or task master, therefore return the package declaration as the
-- proper carrier for the appropriate flag.
elsif Nkind (Context) = N_Package_Body then
Context_Decls := Declarations (Context);
Context_Id := Corresponding_Spec (Context);
Context := Parent (Context_Id);
if Nkind (Context) = N_Defining_Program_Unit_Name then
Context := Parent (Parent (Context));
else
Context := Parent (Context);
end if;
elsif Nkind (Context) = N_Package_Declaration then
Context_Decls := Visible_Declarations (Specification (Context));
Context_Id := Defining_Unit_Name (Specification (Context));
if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
Context_Id := Defining_Identifier (Context_Id);
end if;
else
if Nkind (Context) = N_Block_Statement then
Context_Id := Entity (Identifier (Context));
if No (Declarations (Context)) then
Set_Declarations (Context, New_List);
end if;
elsif Nkind (Context) = N_Entry_Body then
Context_Id := Defining_Identifier (Context);
elsif Nkind (Context) = N_Subprogram_Body then
if Present (Corresponding_Spec (Context)) then
Context_Id := Corresponding_Spec (Context);
else
Context_Id := Defining_Unit_Name (Specification (Context));
if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
Context_Id := Defining_Identifier (Context_Id);
end if;
end if;
elsif Nkind (Context) = N_Task_Body then
Context_Id := Corresponding_Spec (Context);
else
raise Program_Error;
end if;
Context_Decls := Declarations (Context);
end if;
pragma Assert (Present (Context_Id));
pragma Assert (Present (Context_Decls));
end Find_Enclosing_Context;
-----------------------
-- Find_Master_Scope --
-----------------------
function Find_Master_Scope (E : Entity_Id) return Entity_Id is
S : Entity_Id;
begin
-- In Ada 2005, the master is the innermost enclosing scope that is not
-- transient. If the enclosing block is the rewriting of a call or the
-- scope is an extended return statement this is valid master. The
-- master in an extended return is only used within the return, and is
-- subsequently overwritten in Move_Activation_Chain, but it must exist
-- now before that overwriting occurs.
S := Scope (E);
if Ada_Version >= Ada_2005 then
while Is_Internal (S) loop
if Nkind (Parent (S)) = N_Block_Statement
and then Has_Master_Entity (S)
then
exit;
elsif Ekind (S) = E_Return_Statement then
exit;
else
S := Scope (S);
end if;
end loop;
end if;
return S;
end Find_Master_Scope;
-------------------------------
-- First_Protected_Operation --
-------------------------------
function First_Protected_Operation (D : List_Id) return Node_Id is
First_Op : Node_Id;
begin
First_Op := First (D);
while Present (First_Op)
and then Nkind (First_Op) not in N_Subprogram_Body | N_Entry_Body
loop
Next (First_Op);
end loop;
return First_Op;
end First_Protected_Operation;
---------------------------------------
-- Install_Private_Data_Declarations --
---------------------------------------
procedure Install_Private_Data_Declarations
(Loc : Source_Ptr;
Spec_Id : Entity_Id;
Conc_Typ : Entity_Id;
Body_Nod : Node_Id;
Decls : List_Id;
Barrier : Boolean := False;
Family : Boolean := False)
is
Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
Decl : Node_Id;
Def : Node_Id;
Insert_Node : Node_Id := Empty;
Obj_Ent : Entity_Id;
procedure Add (Decl : Node_Id);
-- Add a single declaration after Insert_Node. If this is the first
-- addition, Decl is added to the front of Decls and it becomes the
-- insertion node.
function Replace_Bound (Bound : Node_Id) return Node_Id;
-- The bounds of an entry index may depend on discriminants, create a
-- reference to the corresponding prival. Otherwise return a duplicate
-- of the original bound.
---------
-- Add --
---------
procedure Add (Decl : Node_Id) is
begin
if No (Insert_Node) then
Prepend_To (Decls, Decl);
else
Insert_After (Insert_Node, Decl);
end if;
Insert_Node := Decl;
end Add;
-------------------
-- Replace_Bound --
-------------------
function Replace_Bound (Bound : Node_Id) return Node_Id is
begin
if Nkind (Bound) = N_Identifier
and then Is_Discriminal (Entity (Bound))
then
return Make_Identifier (Loc, Chars (Entity (Bound)));
else
return Duplicate_Subexpr (Bound);
end if;
end Replace_Bound;
-- Start of processing for Install_Private_Data_Declarations
begin
-- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
-- formal parameter _O, _object or _task depending on the context.
Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
-- Special processing of _O for barrier functions, protected entries
-- and families.
if Barrier
or else
(Is_Protected
and then
(Ekind (Spec_Id) = E_Entry
or else Ekind (Spec_Id) = E_Entry_Family))
then
declare
Conc_Rec : constant Entity_Id :=
Corresponding_Record_Type (Conc_Typ);
Typ_Id : constant Entity_Id :=
Make_Defining_Identifier (Loc,
New_External_Name (Chars (Conc_Rec), 'P'));
begin
-- Generate:
-- type prot_typVP is access prot_typV;
Decl :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Typ_Id,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
Subtype_Indication =>
New_Occurrence_Of (Conc_Rec, Loc)));
Add (Decl);
-- Generate:
-- _object : prot_typVP := prot_typV (_O);
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, Name_uObject),
Object_Definition => New_Occurrence_Of (Typ_Id, Loc),
Expression =>
Unchecked_Convert_To (Typ_Id,
New_Occurrence_Of (Obj_Ent, Loc)));
Add (Decl);
-- Set the reference to the concurrent object
Obj_Ent := Defining_Identifier (Decl);
end;
end if;
-- Step 2: Create the Protection object and build its declaration for
-- any protected entry (family) of subprogram. Note for the lock-free
-- implementation, the Protection object is not needed anymore.
if Is_Protected and then not Uses_Lock_Free (Conc_Typ) then
declare
Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
Prot_Typ : RE_Id;
begin
Set_Protection_Object (Spec_Id, Prot_Ent);
-- Determine the proper protection type
if Has_Attach_Handler (Conc_Typ)
and then not Restricted_Profile
then
Prot_Typ := RE_Static_Interrupt_Protection;
elsif Has_Interrupt_Handler (Conc_Typ)
and then not Restriction_Active (No_Dynamic_Attachment)
then
Prot_Typ := RE_Dynamic_Interrupt_Protection;
else
case Corresponding_Runtime_Package (Conc_Typ) is
when System_Tasking_Protected_Objects_Entries =>
Prot_Typ := RE_Protection_Entries;
when System_Tasking_Protected_Objects_Single_Entry =>
Prot_Typ := RE_Protection_Entry;
when System_Tasking_Protected_Objects =>
Prot_Typ := RE_Protection;
when others =>
raise Program_Error;
end case;
end if;
-- Generate:
-- conc_typR : protection_typ renames _object._object;
Decl :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Prot_Ent,
Subtype_Mark =>
New_Occurrence_Of (RTE (Prot_Typ), Loc),
Name =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (Obj_Ent, Loc),
Selector_Name => Make_Identifier (Loc, Name_uObject)));
Add (Decl);
end;
end if;
-- Step 3: Add discriminant renamings (if any)
if Has_Discriminants (Conc_Typ) then
declare
D : Entity_Id;
begin
D := First_Discriminant (Conc_Typ);
while Present (D) loop
-- Adjust the source location
Set_Sloc (Discriminal (D), Loc);
-- Generate:
-- discr_name : discr_typ renames _object.discr_name;
-- or
-- discr_name : discr_typ renames _task.discr_name;
Decl :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Discriminal (D),
Subtype_Mark => New_Occurrence_Of (Etype (D), Loc),
Name =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (Obj_Ent, Loc),
Selector_Name => Make_Identifier (Loc, Chars (D))));
Add (Decl);
-- Set debug info needed on this renaming declaration even
-- though it does not come from source, so that the debugger
-- will get the right information for these generated names.
Set_Debug_Info_Needed (Discriminal (D));
Next_Discriminant (D);
end loop;
end;
end if;
-- Step 4: Add private component renamings (if any)
if Is_Protected then
Def := Protected_Definition (Parent (Conc_Typ));
if Present (Private_Declarations (Def)) then
declare
Comp : Node_Id;
Comp_Id : Entity_Id;
Decl_Id : Entity_Id;
Nam : Name_Id;
begin
Comp := First (Private_Declarations (Def));
while Present (Comp) loop
if Nkind (Comp) = N_Component_Declaration then
Comp_Id := Defining_Identifier (Comp);
Nam := Chars (Comp_Id);
Decl_Id := Make_Defining_Identifier (Sloc (Comp_Id), Nam);
-- Minimal decoration
if Ekind (Spec_Id) = E_Function then
Mutate_Ekind (Decl_Id, E_Constant);
else
Mutate_Ekind (Decl_Id, E_Variable);
end if;
Set_Prival (Comp_Id, Decl_Id);
Set_Prival_Link (Decl_Id, Comp_Id);
Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
Set_Is_Independent (Decl_Id, Is_Independent (Comp_Id));
-- Copy the Comes_From_Source flag of the component, as
-- the renaming may be the only entity directly seen by
-- the user in the context, but do not warn for it.
Set_Comes_From_Source
(Decl_Id, Comes_From_Source (Comp_Id));
Set_Warnings_Off (Decl_Id);
-- Generate:
-- comp_name : comp_typ renames _object.comp_name;
Decl :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => Decl_Id,
Subtype_Mark =>
New_Occurrence_Of (Etype (Comp_Id), Loc),
Name =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (Obj_Ent, Loc),
Selector_Name => Make_Identifier (Loc, Nam)));
Add (Decl);
end if;
Next (Comp);
end loop;
end;
end if;
end if;
-- Step 5: Add the declaration of the entry index and the associated
-- type for barrier functions and entry families.
if (Barrier and Family) or else Ekind (Spec_Id) = E_Entry_Family then
declare
E : constant Entity_Id := Index_Object (Spec_Id);
Index : constant Entity_Id :=
Defining_Identifier
(Entry_Index_Specification
(Entry_Body_Formal_Part (Body_Nod)));
Index_Con : constant Entity_Id :=
Make_Defining_Identifier (Loc, Chars (Index));
High : Node_Id;
Index_Typ : Entity_Id;
Low : Node_Id;
begin
-- Minimal decoration
Mutate_Ekind (Index_Con, E_Constant);
Set_Entry_Index_Constant (Index, Index_Con);
Set_Discriminal_Link (Index_Con, Index);
-- Retrieve the bounds of the entry family
High := Type_High_Bound (Etype (Index));
Low := Type_Low_Bound (Etype (Index));
-- In the simple case the entry family is given by a subtype mark
-- and the index constant has the same type.
if Is_Entity_Name (Original_Node (
Discrete_Subtype_Definition (Parent (Index))))
then
Index_Typ := Etype (Index);
-- Otherwise a new subtype declaration is required
else
High := Replace_Bound (High);
Low := Replace_Bound (Low);
Index_Typ := Make_Temporary (Loc, 'J');
-- Generate:
-- subtype Jnn is <Etype of Index> range Low .. High;
Decl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => Index_Typ,
Subtype_Indication =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Occurrence_Of (Base_Type (Etype (Index)), Loc),
Constraint =>
Make_Range_Constraint (Loc,
Range_Expression =>
Make_Range (Loc, Low, High))));
Add (Decl);
end if;
Set_Etype (Index_Con, Index_Typ);
-- Create the object which designates the index:
-- J : constant Jnn :=
-- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
--
-- where Jnn is the subtype created above or the original type of
-- the index, _E is a formal of the protected body subprogram and
-- <index expr> is the index of the first family member.
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Index_Con,
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (Index_Typ, Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Index_Typ, Loc),
Attribute_Name => Name_Val,
Expressions => New_List (
Make_Op_Add (Loc,
Left_Opnd =>
Make_Op_Subtract (Loc,
Left_Opnd => New_Occurrence_Of (E, Loc),
Right_Opnd =>
Entry_Index_Expression (Loc,
Defining_Identifier (Body_Nod),
Empty, Conc_Typ)),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Index_Typ, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Index_Typ, Loc),
Attribute_Name => Name_First)))))));
Add (Decl);
end;
end if;
end Install_Private_Data_Declarations;
---------------------------------
-- Is_Potentially_Large_Family --
---------------------------------
function Is_Potentially_Large_Family
(Base_Index : Entity_Id;
Conctyp : Entity_Id;
Lo : Node_Id;
Hi : Node_Id) return Boolean
is
begin
return Scope (Base_Index) = Standard_Standard
and then Base_Index = Base_Type (Standard_Integer)
and then Has_Defaulted_Discriminants (Conctyp)
and then
(Denotes_Discriminant (Lo, True)
or else
Denotes_Discriminant (Hi, True));
end Is_Potentially_Large_Family;
-------------------------------------
-- Is_Private_Primitive_Subprogram --
-------------------------------------
function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
begin
return
(Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
and then Is_Private_Primitive (Id);
end Is_Private_Primitive_Subprogram;
------------------
-- Index_Object --
------------------
function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
Formal : Entity_Id;
begin
Formal := First_Formal (Bod_Subp);
while Present (Formal) loop
-- Look for formal parameter _E
if Chars (Formal) = Name_uE then
return Formal;
end if;
Next_Formal (Formal);
end loop;
-- A protected body subprogram should always have the parameter in
-- question.
raise Program_Error;
end Index_Object;
--------------------------------
-- Make_Initialize_Protection --
--------------------------------
function Make_Initialize_Protection
(Protect_Rec : Entity_Id) return List_Id
is
Loc : constant Source_Ptr := Sloc (Protect_Rec);
P_Arr : Entity_Id;
Pdec : Node_Id;
Ptyp : constant Node_Id :=
Corresponding_Concurrent_Type (Protect_Rec);
Args : List_Id;
L : constant List_Id := New_List;
Has_Entry : constant Boolean := Has_Entries (Ptyp);
Prio_Type : Entity_Id;
Prio_Var : Entity_Id := Empty;
Restricted : constant Boolean := Restricted_Profile;
begin
-- We may need two calls to properly initialize the object, one to
-- Initialize_Protection, and possibly one to Install_Handlers if we
-- have a pragma Attach_Handler.
-- Get protected declaration. In the case of a task type declaration,
-- this is simply the parent of the protected type entity. In the single
-- protected object declaration, this parent will be the implicit type,
-- and we can find the corresponding single protected object declaration
-- by searching forward in the declaration list in the tree.
-- Is the test for N_Single_Protected_Declaration needed here??? Nodes
-- of this type should have been removed during semantic analysis.
Pdec := Parent (Ptyp);
while Nkind (Pdec) not in
N_Protected_Type_Declaration | N_Single_Protected_Declaration
loop
Next (Pdec);
end loop;
-- Build the parameter list for the call. Note that _Init is the name
-- of the formal for the object to be initialized, which is the task
-- value record itself.
Args := New_List;
-- For lock-free implementation, skip initializations of the Protection
-- object.
if not Uses_Lock_Free (Defining_Identifier (Pdec)) then
-- Object parameter. This is a pointer to the object of type
-- Protection used by the GNARL to control the protected object.
Append_To (Args,
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Selector_Name => Make_Identifier (Loc, Name_uObject)),
Attribute_Name => Name_Unchecked_Access));
-- Priority parameter. Set to Unspecified_Priority unless there is a
-- Priority rep item, in which case we take the value from the pragma
-- or attribute definition clause, or there is an Interrupt_Priority
-- rep item and no Priority rep item, and we set the ceiling to
-- Interrupt_Priority'Last, an implementation-defined value, see
-- (RM D.3(10)).
if Has_Rep_Item (Ptyp, Name_Priority, Check_Parents => False) then
declare
Prio_Clause : constant Node_Id :=
Get_Rep_Item
(Ptyp, Name_Priority, Check_Parents => False);
Prio : Node_Id;
begin
-- Pragma Priority
if Nkind (Prio_Clause) = N_Pragma then
Prio :=
Expression
(First (Pragma_Argument_Associations (Prio_Clause)));
-- Get_Rep_Item returns either priority pragma
if Pragma_Name (Prio_Clause) = Name_Priority then
Prio_Type := RTE (RE_Any_Priority);
else
Prio_Type := RTE (RE_Interrupt_Priority);
end if;
-- Attribute definition clause Priority
else
if Chars (Prio_Clause) = Name_Priority then
Prio_Type := RTE (RE_Any_Priority);
else
Prio_Type := RTE (RE_Interrupt_Priority);
end if;
Prio := Expression (Prio_Clause);
end if;
-- Always create a locale variable to capture the priority.
-- The priority is also passed to Install_Restriced_Handlers.
-- Note that it is really necessary to create this variable
-- explicitly. It might be thought that removing side effects
-- would the appropriate approach, but that could generate
-- declarations improperly placed in the enclosing scope.
Prio_Var := Make_Temporary (Loc, 'R', Prio);
Append_To (L,
Make_Object_Declaration (Loc,
Defining_Identifier => Prio_Var,
Object_Definition => New_Occurrence_Of (Prio_Type, Loc),
Expression => Relocate_Node (Prio)));
Append_To (Args, New_Occurrence_Of (Prio_Var, Loc));
end;
-- When no priority is specified but an xx_Handler pragma is, we
-- default to System.Interrupts.Default_Interrupt_Priority, see
-- D.3(10).
elsif Has_Attach_Handler (Ptyp)
or else Has_Interrupt_Handler (Ptyp)
then
Append_To (Args,
New_Occurrence_Of (RTE (RE_Default_Interrupt_Priority), Loc));
-- Normal case, no priority or xx_Handler specified, default priority
else
Append_To (Args,
New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc));
end if;
-- Deadline_Floor parameter for GNAT_Ravenscar_EDF runtimes
if Restricted_Profile and Task_Dispatching_Policy = 'E' then
Deadline_Floor : declare
Item : constant Node_Id :=
Get_Rep_Item
(Ptyp, Name_Deadline_Floor, Check_Parents => False);
Deadline : Node_Id;
begin
if Present (Item) then
-- Pragma Deadline_Floor
if Nkind (Item) = N_Pragma then
Deadline :=
Expression
(First (Pragma_Argument_Associations (Item)));
-- Attribute definition clause Deadline_Floor
else
pragma Assert
(Nkind (Item) = N_Attribute_Definition_Clause);
Deadline := Expression (Item);
end if;
Append_To (Args, Deadline);
-- Unusual case: default deadline
else
Append_To (Args,
New_Occurrence_Of (RTE (RE_Time_Span_Zero), Loc));
end if;
end Deadline_Floor;
end if;
-- Test for Compiler_Info parameter. This parameter allows entry body
-- procedures and barrier functions to be called from the runtime. It
-- is a pointer to the record generated by the compiler to represent
-- the protected object.
-- A protected type without entries that covers an interface and
-- overrides the abstract routines with protected procedures is
-- considered equivalent to a protected type with entries in the
-- context of dispatching select statements.
-- Protected types with interrupt handlers (when not using a
-- restricted profile) are also considered equivalent to protected
-- types with entries.
-- The types which are used (Static_Interrupt_Protection and
-- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
declare
Pkg_Id : constant RTU_Id := Corresponding_Runtime_Package (Ptyp);
Called_Subp : RE_Id;
begin
case Pkg_Id is
when System_Tasking_Protected_Objects_Entries =>
Called_Subp := RE_Initialize_Protection_Entries;
-- Argument Compiler_Info
Append_To (Args,
Make_Attribute_Reference (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Attribute_Name => Name_Address));
when System_Tasking_Protected_Objects_Single_Entry =>
Called_Subp := RE_Initialize_Protection_Entry;
-- Argument Compiler_Info
Append_To (Args,
Make_Attribute_Reference (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Attribute_Name => Name_Address));
when System_Tasking_Protected_Objects =>
Called_Subp := RE_Initialize_Protection;
when others =>
raise Program_Error;
end case;
-- Entry_Queue_Maxes parameter. This is an access to an array of
-- naturals representing the entry queue maximums for each entry
-- in the protected type. Zero represents no max. The access is
-- null if there is no limit for all entries (usual case).
if Has_Entry
and then Pkg_Id = System_Tasking_Protected_Objects_Entries
then
if Present (Entry_Max_Queue_Lengths_Array (Ptyp)) then
Append_To (Args,
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of
(Entry_Max_Queue_Lengths_Array (Ptyp), Loc),
Attribute_Name => Name_Unrestricted_Access));
else
Append_To (Args, Make_Null (Loc));
end if;
-- Edge cases exist where entry initialization functions are
-- called, but no entries exist, so null is appended.
elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
Append_To (Args, Make_Null (Loc));
end if;
-- Entry_Bodies parameter. This is a pointer to an array of
-- pointers to the entry body procedures and barrier functions of
-- the object. If the protected type has no entries this object
-- will not exist, in this case, pass a null (it can happen when
-- there are protected interrupt handlers or interfaces).
if Has_Entry then
P_Arr := Entry_Bodies_Array (Ptyp);
-- Argument Entry_Body (for single entry) or Entry_Bodies (for
-- multiple entries).
Append_To (Args,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (P_Arr, Loc),
Attribute_Name => Name_Unrestricted_Access));
if Pkg_Id = System_Tasking_Protected_Objects_Entries then
-- Find index mapping function (clumsy but ok for now)
while Ekind (P_Arr) /= E_Function loop
Next_Entity (P_Arr);
end loop;
Append_To (Args,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (P_Arr, Loc),
Attribute_Name => Name_Unrestricted_Access));
end if;
elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
-- This is the case where we have a protected object with
-- interfaces and no entries, and the single entry restriction
-- is in effect. We pass a null pointer for the entry
-- parameter because there is no actual entry.
Append_To (Args, Make_Null (Loc));
elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
-- This is the case where we have a protected object with no
-- entries and:
-- - either interrupt handlers with non restricted profile,
-- - or interfaces
-- Note that the types which are used for interrupt handlers
-- (Static/Dynamic_Interrupt_Protection) are derived from
-- Protection_Entries. We pass two null pointers because there
-- is no actual entry, and the initialization procedure needs
-- both Entry_Bodies and Find_Body_Index.
Append_To (Args, Make_Null (Loc));
Append_To (Args, Make_Null (Loc));
end if;
Append_To (L,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (Called_Subp), Loc),
Parameter_Associations => Args));
end;
end if;
if Has_Attach_Handler (Ptyp) then
-- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
-- make the following call:
-- Install_Handlers (_object,
-- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
-- or, in the case of Ravenscar:
-- Install_Restricted_Handlers
-- (Prio, ((Expr1, Proc1'access), ...., (ExprN, ProcN'access)));
declare
Args : constant List_Id := New_List;
Table : constant List_Id := New_List;
Ritem : Node_Id := First_Rep_Item (Ptyp);
begin
-- Build the Priority parameter (only for ravenscar)
if Restricted then
-- Priority comes from a pragma
if Present (Prio_Var) then
Append_To (Args, New_Occurrence_Of (Prio_Var, Loc));
-- Priority is the default one
else
Append_To (Args,
New_Occurrence_Of
(RTE (RE_Default_Interrupt_Priority), Loc));
end if;
end if;
-- Build the Attach_Handler table argument
while Present (Ritem) loop
if Nkind (Ritem) = N_Pragma
and then Pragma_Name (Ritem) = Name_Attach_Handler
then
declare
Handler : constant Node_Id :=
First (Pragma_Argument_Associations (Ritem));
Interrupt : constant Node_Id := Next (Handler);
Expr : constant Node_Id := Expression (Interrupt);
begin
Append_To (Table,
Make_Aggregate (Loc, Expressions => New_List (
Unchecked_Convert_To
(RTE (RE_System_Interrupt_Id), Expr),
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix =>
Make_Identifier (Loc, Name_uInit),
Selector_Name =>
Duplicate_Subexpr_No_Checks
(Expression (Handler))),
Attribute_Name => Name_Access))));
end;
end if;
Next_Rep_Item (Ritem);
end loop;
-- Append the table argument we just built
Append_To (Args, Make_Aggregate (Loc, Table));
-- Append the Install_Handlers (or Install_Restricted_Handlers)
-- call to the statements.
if Restricted then
-- Call a simplified version of Install_Handlers to be used
-- when the Ravenscar restrictions are in effect
-- (Install_Restricted_Handlers).
Append_To (L,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(RTE (RE_Install_Restricted_Handlers), Loc),
Parameter_Associations => Args));
else
if not Uses_Lock_Free (Defining_Identifier (Pdec)) then
-- First, prepends the _object argument
Prepend_To (Args,
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Selector_Name =>
Make_Identifier (Loc, Name_uObject)),
Attribute_Name => Name_Unchecked_Access));
end if;
-- Then, insert call to Install_Handlers
Append_To (L,
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Install_Handlers), Loc),
Parameter_Associations => Args));
end if;
end;
end if;
return L;
end Make_Initialize_Protection;
---------------------------
-- Make_Task_Create_Call --
---------------------------
function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (Task_Rec);
Args : List_Id;
Ecount : Node_Id;
Name : Node_Id;
Tdec : Node_Id;
Tdef : Node_Id;
Tnam : Name_Id;
Ttyp : Node_Id;
begin
Ttyp := Corresponding_Concurrent_Type (Task_Rec);
Tnam := Chars (Ttyp);
-- Get task declaration. In the case of a task type declaration, this is
-- simply the parent of the task type entity. In the single task
-- declaration, this parent will be the implicit type, and we can find
-- the corresponding single task declaration by searching forward in the
-- declaration list in the tree.
-- Is the test for N_Single_Task_Declaration needed here??? Nodes of
-- this type should have been removed during semantic analysis.
Tdec := Parent (Ttyp);
while Nkind (Tdec) not in
N_Task_Type_Declaration | N_Single_Task_Declaration
loop
Next (Tdec);
end loop;
-- Now we can find the task definition from this declaration
Tdef := Task_Definition (Tdec);
-- Build the parameter list for the call. Note that _Init is the name
-- of the formal for the object to be initialized, which is the task
-- value record itself.
Args := New_List;
-- Priority parameter. Set to Unspecified_Priority unless there is a
-- Priority rep item, in which case we take the value from the rep item.
-- Not used on Ravenscar_EDF profile.
if not (Restricted_Profile and then Task_Dispatching_Policy = 'E') then
if Has_Rep_Item (Ttyp, Name_Priority, Check_Parents => False) then
Append_To (Args,
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Selector_Name => Make_Identifier (Loc, Name_uPriority)));
else
Append_To (Args,
New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc));
end if;
end if;
-- Optional Stack parameter
if Restricted_Profile then
-- If the stack has been preallocated by the expander then
-- pass its address. Otherwise, pass a null address.
if Preallocated_Stacks_On_Target then
Append_To (Args,
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Selector_Name => Make_Identifier (Loc, Name_uStack)),
Attribute_Name => Name_Address));
else
Append_To (Args,
New_Occurrence_Of (RTE (RE_Null_Address), Loc));
end if;
end if;
-- Size parameter. If no Storage_Size pragma is present, then
-- the size is taken from the taskZ variable for the type, which
-- is either Unspecified_Size, or has been reset by the use of
-- a Storage_Size attribute definition clause. If a pragma is
-- present, then the size is taken from the _Size field of the
-- task value record, which was set from the pragma value.
if Present (Tdef) and then Has_Storage_Size_Pragma (Tdef) then
Append_To (Args,
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Selector_Name => Make_Identifier (Loc, Name_uSize)));
else
Append_To (Args,
New_Occurrence_Of (Storage_Size_Variable (Ttyp), Loc));
end if;
-- Secondary_Stack parameter used for restricted profiles
if Restricted_Profile then
-- If the secondary stack has been allocated by the expander then
-- pass its access pointer. Otherwise, pass null.
if Create_Secondary_Stack_For_Task (Ttyp) then
Append_To (Args,
Make_Attribute_Reference (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Selector_Name =>
Make_Identifier (Loc, Name_uSecondary_Stack)),
Attribute_Name => Name_Unrestricted_Access));
else
Append_To (Args, Make_Null (Loc));
end if;
end if;
-- Secondary_Stack_Size parameter. Set RE_Unspecified_Size unless there
-- is a Secondary_Stack_Size pragma, in which case take the value from
-- the pragma. If the restriction No_Secondary_Stack is active then a
-- size of 0 is passed regardless to prevent the allocation of the
-- unused stack.
if Restriction_Active (No_Secondary_Stack) then
Append_To (Args, Make_Integer_Literal (Loc, 0));
elsif Has_Rep_Pragma
(Ttyp, Name_Secondary_Stack_Size, Check_Parents => False)
then
Append_To (Args,
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Selector_Name =>
Make_Identifier (Loc, Name_uSecondary_Stack_Size)));
else
Append_To (Args,
New_Occurrence_Of (RTE (RE_Unspecified_Size), Loc));
end if;
-- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
-- Task_Info pragma, in which case we take the value from the pragma.
if Has_Rep_Pragma (Ttyp, Name_Task_Info, Check_Parents => False) then
Append_To (Args,
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
else
Append_To (Args,
New_Occurrence_Of (RTE (RE_Unspecified_Task_Info), Loc));
end if;
-- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
-- in which case we take the value from the rep item. The parameter is
-- passed as an Integer because in the case of unspecified CPU the
-- value is not in the range of CPU_Range.
if Has_Rep_Item (Ttyp, Name_CPU, Check_Parents => False) then
Append_To (Args,
Convert_To (Standard_Integer,
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Selector_Name => Make_Identifier (Loc, Name_uCPU))));
else
Append_To (Args,
New_Occurrence_Of (RTE (RE_Unspecified_CPU), Loc));
end if;
if not Restricted_Profile or else Task_Dispatching_Policy = 'E' then
-- Deadline parameter. If no Relative_Deadline pragma is present,
-- then the deadline is Time_Span_Zero. If a pragma is present, then
-- the deadline is taken from the _Relative_Deadline field of the
-- task value record, which was set from the pragma value. Note that
-- this parameter must not be generated for the restricted profiles
-- since Ravenscar does not allow deadlines.
-- Case where pragma Relative_Deadline applies: use given value
if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
Append_To (Args,
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Selector_Name =>
Make_Identifier (Loc, Name_uRelative_Deadline)));
-- No pragma Relative_Deadline apply to the task
else
Append_To (Args,
New_Occurrence_Of (RTE (RE_Time_Span_Zero), Loc));
end if;
end if;
if not Restricted_Profile then
-- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
-- present, then the dispatching domain is null. If a rep item is
-- present, then the dispatching domain is taken from the
-- _Dispatching_Domain field of the task value record, which was set
-- from the rep item value.
-- Case where Dispatching_Domain rep item applies: use given value
if Has_Rep_Item
(Ttyp, Name_Dispatching_Domain, Check_Parents => False)
then
Append_To (Args,
Make_Selected_Component (Loc,
Prefix =>
Make_Identifier (Loc, Name_uInit),
Selector_Name =>
Make_Identifier (Loc, Name_uDispatching_Domain)));
-- No pragma or aspect Dispatching_Domain applies to the task
else
Append_To (Args, Make_Null (Loc));
end if;
-- Number of entries. This is an expression of the form:
-- n + _Init.a'Length + _Init.a'B'Length + ...
-- where a,b... are the entry family names for the task definition
Ecount :=
Build_Entry_Count_Expression
(Ttyp,
Component_Items
(Component_List
(Type_Definition
(Parent (Corresponding_Record_Type (Ttyp))))),
Loc);
Append_To (Args, Ecount);
-- Master parameter. This is a reference to the _Master parameter of
-- the initialization procedure, except in the case of the pragma
-- Restrictions (No_Task_Hierarchy) where the value is fixed to
-- System.Tasking.Library_Task_Level.
if Restriction_Active (No_Task_Hierarchy) = False then
Append_To (Args, Make_Identifier (Loc, Name_uMaster));
else
Append_To (Args, Make_Integer_Literal (Loc, Library_Task_Level));
end if;
end if;
-- State parameter. This is a pointer to the task body procedure. The
-- required value is obtained by taking 'Unrestricted_Access of the task
-- body procedure and converting it (with an unchecked conversion) to
-- the type required by the task kernel. For further details, see the
-- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
-- than 'Address in order to avoid creating trampolines.
declare
Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
Subp_Ptr_Typ : constant Node_Id :=
Create_Itype (E_Access_Subprogram_Type, Tdec);
Ref : constant Node_Id := Make_Itype_Reference (Loc);
begin
Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
-- Be sure to freeze a reference to the access-to-subprogram type,
-- otherwise gigi will complain that it's in the wrong scope, because
-- it's actually inside the init procedure for the record type that
-- corresponds to the task type.
Set_Itype (Ref, Subp_Ptr_Typ);
Append_Freeze_Action (Task_Rec, Ref);
Append_To (Args,
Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
Make_Qualified_Expression (Loc,
Subtype_Mark => New_Occurrence_Of (Subp_Ptr_Typ, Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Body_Proc, Loc),
Attribute_Name => Name_Unrestricted_Access))));
end;
-- Discriminants parameter. This is just the address of the task
-- value record itself (which contains the discriminant values
Append_To (Args,
Make_Attribute_Reference (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Attribute_Name => Name_Address));
-- Elaborated parameter. This is an access to the elaboration Boolean
Append_To (Args,
Make_Attribute_Reference (Loc,
Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
Attribute_Name => Name_Unchecked_Access));
-- Add Chain parameter (not done for sequential elaboration policy, see
-- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
if Partition_Elaboration_Policy /= 'S' then
Append_To (Args, Make_Identifier (Loc, Name_uChain));
end if;
-- Task name parameter. Take this from the _Task_Id parameter to the
-- init call unless there is a Task_Name pragma, in which case we take
-- the value from the pragma.
if Has_Rep_Pragma (Ttyp, Name_Task_Name, Check_Parents => False) then
-- Copy expression in full, because it may be dynamic and have
-- side effects.
Append_To (Args,
New_Copy_Tree
(Expression
(First
(Pragma_Argument_Associations
(Get_Rep_Pragma
(Ttyp, Name_Task_Name, Check_Parents => False))))));
else
Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
end if;
-- Created_Task parameter. This is the _Task_Id field of the task
-- record value
Append_To (Args,
Make_Selected_Component (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
declare
Create_RE : RE_Id;
begin
if Restricted_Profile then
if Partition_Elaboration_Policy = 'S' then
Create_RE := RE_Create_Restricted_Task_Sequential;
else
Create_RE := RE_Create_Restricted_Task;
end if;
else
Create_RE := RE_Create_Task;
end if;
Name := New_Occurrence_Of (RTE (Create_RE), Loc);
end;
return
Make_Procedure_Call_Statement (Loc,
Name => Name,
Parameter_Associations => Args);
end Make_Task_Create_Call;
------------------------------
-- Next_Protected_Operation --
------------------------------
function Next_Protected_Operation (N : Node_Id) return Node_Id is
Next_Op : Node_Id;
begin
-- Check whether there is a subsequent body for a protected operation
-- in the current protected body. In Ada2012 that includes expression
-- functions that are completions.
Next_Op := Next (N);
while Present (Next_Op)
and then Nkind (Next_Op) not in
N_Subprogram_Body | N_Entry_Body | N_Expression_Function
loop
Next (Next_Op);
end loop;
return Next_Op;
end Next_Protected_Operation;
---------------------
-- Null_Statements --
---------------------
function Null_Statements (Stats : List_Id) return Boolean is
Stmt : Node_Id;
begin
Stmt := First (Stats);
while Nkind (Stmt) /= N_Empty
and then (Nkind (Stmt) in N_Null_Statement | N_Label
or else
(Nkind (Stmt) = N_Pragma
and then
Pragma_Name_Unmapped (Stmt) in Name_Unreferenced
| Name_Unmodified
| Name_Warnings))
loop
Next (Stmt);
end loop;
return Nkind (Stmt) = N_Empty;
end Null_Statements;
--------------------------
-- Parameter_Block_Pack --
--------------------------
function Parameter_Block_Pack
(Loc : Source_Ptr;
Blk_Typ : Entity_Id;
Actuals : List_Id;
Formals : List_Id;
Decls : List_Id;
Stmts : List_Id) return Entity_Id
is
Actual : Entity_Id;
Expr : Node_Id := Empty;
Formal : Entity_Id;
Has_Param : Boolean := False;
P : Entity_Id;
Params : List_Id;
Temp_Asn : Node_Id;
Temp_Nam : Node_Id;
begin
Actual := First (Actuals);
Formal := Defining_Identifier (First (Formals));
Params := New_List;
while Present (Actual) loop
if Is_By_Copy_Type (Etype (Actual)) then
-- Generate:
-- Jnn : aliased <formal-type>
Temp_Nam := Make_Temporary (Loc, 'J');
Append_To (Decls,
Make_Object_Declaration (Loc,
Aliased_Present => True,
Defining_Identifier => Temp_Nam,
Object_Definition =>
New_Occurrence_Of (Etype (Formal), Loc)));
-- The object is initialized with an explicit assignment
-- later. Indicate that it does not need an initialization
-- to prevent spurious warnings if the type excludes null.
Set_No_Initialization (Last (Decls));
if Ekind (Formal) /= E_Out_Parameter then
-- Generate:
-- Jnn := <actual>
Temp_Asn :=
New_Occurrence_Of (Temp_Nam, Loc);
Set_Assignment_OK (Temp_Asn);
Append_To (Stmts,
Make_Assignment_Statement (Loc,
Name => Temp_Asn,
Expression => New_Copy_Tree (Actual)));
end if;
-- If the actual is not controlling, generate:
-- Jnn'unchecked_access
-- and add it to aggegate for access to formals. Note that the
-- actual may be by-copy but still be a controlling actual if it
-- is an access to class-wide interface.
if not Is_Controlling_Actual (Actual) then
Append_To (Params,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Unchecked_Access,
Prefix => New_Occurrence_Of (Temp_Nam, Loc)));
Has_Param := True;
end if;
-- The controlling parameter is omitted
else
if not Is_Controlling_Actual (Actual) then
Append_To (Params,
Make_Reference (Loc, New_Copy_Tree (Actual)));
Has_Param := True;
end if;
end if;
Next_Actual (Actual);
Next_Formal_With_Extras (Formal);
end loop;
if Has_Param then
Expr := Make_Aggregate (Loc, Params);
end if;
-- Generate:
-- P : Ann := (
-- J1'unchecked_access;
-- <actual2>'reference;
-- ...);
P := Make_Temporary (Loc, 'P');
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => P,
Object_Definition => New_Occurrence_Of (Blk_Typ, Loc),
Expression => Expr));
return P;
end Parameter_Block_Pack;
----------------------------
-- Parameter_Block_Unpack --
----------------------------
function Parameter_Block_Unpack
(Loc : Source_Ptr;
P : Entity_Id;
Actuals : List_Id;
Formals : List_Id) return List_Id
is
Actual : Entity_Id;
Asnmt : Node_Id;
Formal : Entity_Id;
Has_Asnmt : Boolean := False;
Result : constant List_Id := New_List;
begin
Actual := First (Actuals);
Formal := Defining_Identifier (First (Formals));
while Present (Actual) loop
if Is_By_Copy_Type (Etype (Actual))
and then Ekind (Formal) /= E_In_Parameter
then
-- Generate:
-- <actual> := P.<formal>;
Asnmt :=
Make_Assignment_Statement (Loc,
Name =>
New_Copy (Actual),
Expression =>
Make_Explicit_Dereference (Loc,
Make_Selected_Component (Loc,
Prefix =>
New_Occurrence_Of (P, Loc),
Selector_Name =>
Make_Identifier (Loc, Chars (Formal)))));
Set_Assignment_OK (Name (Asnmt));
Append_To (Result, Asnmt);
Has_Asnmt := True;
end if;
Next_Actual (Actual);
Next_Formal_With_Extras (Formal);
end loop;
if Has_Asnmt then
return Result;
else
return New_List (Make_Null_Statement (Loc));
end if;
end Parameter_Block_Unpack;
---------------------
-- Reset_Scopes_To --
---------------------
procedure Reset_Scopes_To (Bod : Node_Id; E : Entity_Id) is
function Reset_Scope (N : Node_Id) return Traverse_Result;
-- Temporaries may have been declared during expansion of the procedure
-- created for an entry body or an accept alternative. Indicate that
-- their scope is the new body, to ensure proper generation of uplevel
-- references where needed during unnesting.
procedure Reset_Scopes is new Traverse_Proc (Reset_Scope);
-----------------
-- Reset_Scope --
-----------------
function Reset_Scope (N : Node_Id) return Traverse_Result is
Decl : Node_Id;
begin
-- If this is a block statement with an Identifier, it forms a scope,
-- so we want to reset its scope but not look inside.
if N /= Bod
and then Nkind (N) = N_Block_Statement
and then Present (Identifier (N))
then
Set_Scope (Entity (Identifier (N)), E);
return Skip;
-- Ditto for a package declaration or a full type declaration, etc.
elsif (Nkind (N) = N_Package_Declaration
and then N /= Specification (N))
or else Nkind (N) in N_Declaration
or else Nkind (N) in N_Renaming_Declaration
then
Set_Scope (Defining_Entity (N), E);
return Skip;
elsif N = Bod then
-- Scan declarations in new body. Declarations in the statement
-- part will be handled during later traversal.
Decl := First (Declarations (N));
while Present (Decl) loop
Reset_Scopes (Decl);
Next (Decl);
end loop;
elsif Nkind (N) = N_Freeze_Entity then
-- Scan the actions associated with a freeze node, which may
-- actually be declarations with entities that need to have
-- their scopes reset.
Decl := First (Actions (N));
while Present (Decl) loop
Reset_Scopes (Decl);
Next (Decl);
end loop;
elsif N /= Bod and then Nkind (N) in N_Proper_Body then
-- A subprogram without a separate declaration may be encountered,
-- and we need to reset the subprogram's entity's scope.
if Nkind (N) = N_Subprogram_Body then
Set_Scope (Defining_Entity (Specification (N)), E);
end if;
return Skip;
end if;
return OK;
end Reset_Scope;
-- Start of processing for Reset_Scopes_To
begin
Reset_Scopes (Bod);
end Reset_Scopes_To;
----------------------
-- Set_Discriminals --
----------------------
procedure Set_Discriminals (Dec : Node_Id) is
D : Entity_Id;
Pdef : Entity_Id;
D_Minal : Entity_Id;
begin
pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
Pdef := Defining_Identifier (Dec);
if Has_Discriminants (Pdef) then
D := First_Discriminant (Pdef);
while Present (D) loop
D_Minal :=
Make_Defining_Identifier (Sloc (D),
Chars => New_External_Name (Chars (D), 'D'));
Mutate_Ekind (D_Minal, E_Constant);
Set_Etype (D_Minal, Etype (D));
Set_Scope (D_Minal, Pdef);
Set_Discriminal (D, D_Minal);
Set_Discriminal_Link (D_Minal, D);
Next_Discriminant (D);
end loop;
end if;
end Set_Discriminals;
-----------------------
-- Trivial_Accept_OK --
-----------------------
function Trivial_Accept_OK return Boolean is
begin
case Opt.Task_Dispatching_Policy is
-- If we have the default task dispatching policy in effect, we can
-- definitely do the optimization (one way of looking at this is to
-- think of the formal definition of the default policy being allowed
-- to run any task it likes after a rendezvous, so even if notionally
-- a full rescheduling occurs, we can say that our dispatching policy
-- (i.e. the default dispatching policy) reorders the queue to be the
-- same as just before the call.
when ' ' =>
return True;
-- FIFO_Within_Priorities certainly does not permit this
-- optimization since the Rendezvous is a scheduling action that may
-- require some other task to be run.
when 'F' =>
return False;
-- For now, disallow the optimization for all other policies. This
-- may be over-conservative, but it is certainly not incorrect.
when others =>
return False;
end case;
end Trivial_Accept_OK;
end Exp_Ch9;
|
reznikmm/matreshka | Ada | 4,631 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Text.Database_Name_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Text_Database_Name_Attribute_Node is
begin
return Self : Text_Database_Name_Attribute_Node do
Matreshka.ODF_Text.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Text_Prefix);
end return;
end Create;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Text_Database_Name_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Database_Name_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Text_URI,
Matreshka.ODF_String_Constants.Database_Name_Attribute,
Text_Database_Name_Attribute_Node'Tag);
end Matreshka.ODF_Text.Database_Name_Attributes;
|
reznikmm/matreshka | Ada | 5,122 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
package body Matreshka.Internals.XML.Base_Scopes is
--------------
-- Base_URI --
--------------
function Base_URI
(Self : in out Base_Scope) return League.IRIs.IRI is
begin
return Self.Scopes (Self.Last).Base_URI;
end Base_URI;
--------------
-- Finalize --
--------------
procedure Finalize (Self : in out Base_Scope) is
procedure Free is
new Ada.Unchecked_Deallocation (Scope_Array, Scope_Array_Access);
begin
Free (Self.Scopes);
end Finalize;
----------------
-- Initialize --
----------------
procedure Initialize (Self : in out Base_Scope) is
begin
Self.Scopes := new Scope_Array (1 .. 16);
Self.Last := 0;
end Initialize;
---------------
-- Pop_Scope --
---------------
procedure Pop_Scope (Self : in out Base_Scope) is
begin
if Self.Scopes (Self.Last).Counter = 1 then
Self.Last := Self.Last - 1;
else
Self.Scopes (Self.LasT).Counter :=
Self.Scopes (Self.LasT).Counter - 1;
end if;
end Pop_Scope;
----------------
-- Push_Scope --
----------------
procedure Push_Scope (Self : in out Base_Scope) is
begin
Self.Scopes (Self.Last).Counter :=
Self.Scopes (Self.Last).Counter + 1;
end Push_Scope;
----------------
-- Push_Scope --
----------------
procedure Push_Scope
(Self : in out Base_Scope; Base_URI : League.IRIs.IRI) is
begin
Self.Last := Self.Last + 1;
Self.Scopes (Self.last) := (Base_URI, 1);
end Push_Scope;
-----------
-- Reset --
-----------
procedure Reset (Self : in out Base_Scope) is
begin
Self.Last := 0;
end Reset;
end Matreshka.Internals.XML.Base_Scopes;
|
reznikmm/matreshka | Ada | 3,829 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Testsuite Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- Check that Universal_String.Slice doesn't crash when Low greater when
-- High at least for 2.
------------------------------------------------------------------------------
with League.Strings;
procedure Test_150 is
A : League.Strings.Universal_String
:= League.Strings.To_Universal_String ("HKEY_CLASSES_ROOT");
B : League.Strings.Universal_String := A.Slice (A.Length + 3, A.Length);
begin
if not B.Is_Empty then
raise Program_Error;
end if;
end Test_150;
|
AdaCore/libadalang | Ada | 158 | ads | package A is
type Integer is range 1 .. 10;
Foo : Integer;
package B is
package C is
pragma Test (Foo);
end C;
end B;
end A;
|
shintakezou/adaplayground | Ada | 691 | ads | -- @summary
-- Convert to string and concatenate float-derived types.
--
-- @description
-- See its usage to get the idea. However, I don't think this
-- should be a "top" package. I would like it could be seen
-- only in Measure_Units, because Measure_Units uses it to
-- provide some functions to its clients.
--
-- Could this be a good idea as a general purpose utility?
--
package Converters is
generic
type A_Type is new Float;
function To_String (V : A_Type) return String;
generic
type A_Type is new Float;
with function String_Conv (C : A_Type) return String;
function Concat (L : String; R : A_Type) return String;
end Converters;
|
godunko/adawebpack | Ada | 18,840 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . S O F T _ L I N K S --
-- --
-- S p e c --
-- --
-- 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. --
-- --
------------------------------------------------------------------------------
-- This is the WASM version of this package
-- This package contains a set of subprogram access variables that access
-- some low-level primitives that are different depending whether tasking is
-- involved or not (e.g. the Get/Set_Jmpbuf_Address that needs to provide a
-- different value for each task). To avoid dragging in the tasking runtimes
-- all the time, we use a system of soft links where the links are
-- initialized to non-tasking versions, and then if the tasking support is
-- initialized, they are set to the real tasking versions.
pragma Style_Checks (Off);
-- with Ada.Exceptions;
-- with System.Exceptions.Machine;
-- with System.Parameters;
with System.Secondary_Stack;
-- with System.Stack_Checking;
package System.Soft_Links is
pragma Preelaborate;
package SST renames System.Secondary_Stack;
-- subtype EOA is Ada.Exceptions.Exception_Occurrence_Access;
-- subtype EO is Ada.Exceptions.Exception_Occurrence;
-- function Current_Target_Exception return EO;
-- pragma Import
-- (Ada, Current_Target_Exception, "__gnat_current_target_exception");
-- -- Import this subprogram from the private part of Ada.Exceptions
--
-- -- First we have the access subprogram types used to establish the links.
-- -- The approach is to establish variables containing access subprogram
-- -- values, which by default point to dummy no tasking versions of routines.
type No_Param_Proc is access procedure;
pragma Favor_Top_Level (No_Param_Proc);
pragma Suppress_Initialization (No_Param_Proc);
-- Some uninitialized objects of that type are initialized by the Binder
-- so it is important that such objects are not reset to null during
-- elaboration.
-- type Addr_Param_Proc is access procedure (Addr : Address);
-- pragma Favor_Top_Level (Addr_Param_Proc);
-- type EO_Param_Proc is access procedure (Excep : EO);
-- pragma Favor_Top_Level (EO_Param_Proc);
--
-- type Get_Address_Call is access function return Address;
-- pragma Favor_Top_Level (Get_Address_Call);
-- type Set_Address_Call is access procedure (Addr : Address);
-- pragma Favor_Top_Level (Set_Address_Call);
-- type Set_Address_Call2 is access procedure
-- (Self_ID : Address; Addr : Address);
-- pragma Favor_Top_Level (Set_Address_Call2);
--
-- type Get_Integer_Call is access function return Integer;
-- pragma Favor_Top_Level (Get_Integer_Call);
-- type Set_Integer_Call is access procedure (Len : Integer);
-- pragma Favor_Top_Level (Set_Integer_Call);
--
-- type Get_EOA_Call is access function return EOA;
-- pragma Favor_Top_Level (Get_EOA_Call);
-- type Set_EOA_Call is access procedure (Excep : EOA);
-- pragma Favor_Top_Level (Set_EOA_Call);
-- type Set_EO_Call is access procedure (Excep : EO);
-- pragma Favor_Top_Level (Set_EO_Call);
type Get_Stack_Call is access function return SST.SS_Stack_Ptr;
pragma Favor_Top_Level (Get_Stack_Call);
-- type Set_Stack_Call is access procedure (Stack : SST.SS_Stack_Ptr);
-- pragma Favor_Top_Level (Set_Stack_Call);
--
-- type Special_EO_Call is access
-- procedure (Excep : EO := Current_Target_Exception);
-- pragma Favor_Top_Level (Special_EO_Call);
--
-- type Timed_Delay_Call is access
-- procedure (Time : Duration; Mode : Integer);
-- pragma Favor_Top_Level (Timed_Delay_Call);
--
-- type Get_Stack_Access_Call is access
-- function return Stack_Checking.Stack_Access;
-- pragma Favor_Top_Level (Get_Stack_Access_Call);
--
-- type Task_Name_Call is access
-- function return String;
-- pragma Favor_Top_Level (Task_Name_Call);
-- Suppress checks on all these types, since we know the corresponding
-- values can never be null (the soft links are always initialized).
pragma Suppress (Access_Check, No_Param_Proc);
-- pragma Suppress (Access_Check, Addr_Param_Proc);
-- pragma Suppress (Access_Check, EO_Param_Proc);
-- pragma Suppress (Access_Check, Get_Address_Call);
-- pragma Suppress (Access_Check, Set_Address_Call);
-- pragma Suppress (Access_Check, Set_Address_Call2);
-- pragma Suppress (Access_Check, Get_Integer_Call);
-- pragma Suppress (Access_Check, Set_Integer_Call);
-- pragma Suppress (Access_Check, Get_EOA_Call);
-- pragma Suppress (Access_Check, Set_EOA_Call);
pragma Suppress (Access_Check, Get_Stack_Call);
-- pragma Suppress (Access_Check, Set_Stack_Call);
-- pragma Suppress (Access_Check, Timed_Delay_Call);
-- pragma Suppress (Access_Check, Get_Stack_Access_Call);
-- pragma Suppress (Access_Check, Task_Name_Call);
--
-- -- The following one is not related to tasking/no-tasking but to the
-- -- traceback decorators for exceptions.
--
-- type Traceback_Decorator_Wrapper_Call is access
-- function (Traceback : System.Address;
-- Len : Natural)
-- return String;
-- pragma Favor_Top_Level (Traceback_Decorator_Wrapper_Call);
--
-- -- Declarations for the no tasking versions of the required routines
--
-- procedure Abort_Defer_NT;
-- -- Defer task abort (non-tasking case, does nothing)
procedure Abort_Undefer_NT;
-- Undefer task abort (non-tasking case, does nothing)
-- procedure Abort_Handler_NT;
-- -- Handle task abort (non-tasking case, does nothing). Currently, no port
-- -- makes use of this, but we retain the interface for possible future use.
--
-- function Check_Abort_Status_NT return Integer;
-- -- Returns Boolean'Pos (True) iff abort signal should raise
-- -- Standard'Abort_Signal.
procedure Task_Lock_NT;
-- Lock out other tasks (non-tasking case, does nothing)
procedure Task_Unlock_NT;
-- Release lock set by Task_Lock (non-tasking case, does nothing)
-- procedure Task_Termination_NT (Excep : EO);
-- -- Handle task termination routines for the environment task (non-tasking
-- -- case, does nothing).
procedure Adafinal_NT;
-- Shuts down the runtime system (non-tasking case)
-- Abort_Defer : No_Param_Proc := Abort_Defer_NT'Access;
-- pragma Suppress (Access_Check, Abort_Defer);
-- -- Defer task abort (task/non-task case as appropriate)
Abort_Undefer : No_Param_Proc := Abort_Undefer_NT'Access;
pragma Suppress (Access_Check, Abort_Undefer);
-- Undefer task abort (task/non-task case as appropriate)
-- Abort_Handler : No_Param_Proc := Abort_Handler_NT'Access;
-- -- Handle task abort (task/non-task case as appropriate)
--
-- Check_Abort_Status : Get_Integer_Call := Check_Abort_Status_NT'Access;
-- -- Called when Abort_Signal is delivered to the process. Checks to
-- -- see if signal should result in raising Standard'Abort_Signal.
Lock_Task : No_Param_Proc := Task_Lock_NT'Access;
-- Locks out other tasks. Preceding a section of code by Task_Lock and
-- following it by Task_Unlock creates a critical region. This is used
-- for ensuring that a region of non-tasking code (such as code used to
-- allocate memory) is tasking safe. Note that it is valid for calls to
-- Task_Lock/Task_Unlock to be nested, and this must work properly, i.e.
-- only the corresponding outer level Task_Unlock will actually unlock.
-- This routine also prevents against asynchronous aborts (abort is
-- deferred).
Unlock_Task : No_Param_Proc := Task_Unlock_NT'Access;
-- Releases lock previously set by call to Lock_Task. In the nested case,
-- all nested locks must be released before other tasks competing for the
-- tasking lock are released.
--
-- In the non nested case, this routine terminates the protection against
-- asynchronous aborts introduced by Lock_Task (unless abort was already
-- deferred before the call to Lock_Task (e.g in a protected procedures).
--
-- Note: the recommended protocol for using Lock_Task and Unlock_Task
-- is as follows:
--
-- Locked_Processing : begin
-- System.Soft_Links.Lock_Task.all;
-- ...
-- System.Soft_Links.Unlock_Task.all;
--
-- exception
-- when others =>
-- System.Soft_Links.Unlock_Task.all;
-- raise;
-- end Locked_Processing;
--
-- This ensures that the lock is not left set if an exception is raised
-- explicitly or implicitly during the critical locked region.
-- Task_Termination_Handler : EO_Param_Proc := Task_Termination_NT'Access;
-- -- Handle task termination routines (task/non-task case as appropriate)
Finalize_Library_Objects : No_Param_Proc;
pragma Export (C, Finalize_Library_Objects,
"__gnat_finalize_library_objects");
-- Will be initialized by the binder
Adafinal : No_Param_Proc := Adafinal_NT'Access;
-- Performs the finalization of the Ada Runtime
-- function Get_Jmpbuf_Address_NT return Address;
-- procedure Set_Jmpbuf_Address_NT (Addr : Address);
--
-- Get_Jmpbuf_Address : Get_Address_Call := Get_Jmpbuf_Address_NT'Access;
-- Set_Jmpbuf_Address : Set_Address_Call := Set_Jmpbuf_Address_NT'Access;
function Get_Sec_Stack_NT return SST.SS_Stack_Ptr;
-- procedure Set_Sec_Stack_NT (Stack : SST.SS_Stack_Ptr);
Get_Sec_Stack : Get_Stack_Call := Get_Sec_Stack_NT'Access;
-- Set_Sec_Stack : Set_Stack_Call := Set_Sec_Stack_NT'Access;
--
-- function Get_Current_Excep_NT return EOA;
--
-- Get_Current_Excep : Get_EOA_Call := Get_Current_Excep_NT'Access;
--
-- function Get_Stack_Info_NT return Stack_Checking.Stack_Access;
--
-- Get_Stack_Info : Get_Stack_Access_Call := Get_Stack_Info_NT'Access;
--
-- --------------------------
-- -- Master_Id Soft-Links --
-- --------------------------
--
-- -- Soft-Links are used for procedures that manipulate Master_Ids because
-- -- a Master_Id must be generated for access to limited class-wide types,
-- -- whose root may be extended with task components.
--
-- function Current_Master_NT return Integer;
-- procedure Enter_Master_NT;
-- procedure Complete_Master_NT;
--
-- Current_Master : Get_Integer_Call := Current_Master_NT'Access;
-- Enter_Master : No_Param_Proc := Enter_Master_NT'Access;
-- Complete_Master : No_Param_Proc := Complete_Master_NT'Access;
--
-- ----------------------
-- -- Delay Soft-Links --
-- ----------------------
--
-- -- Soft-Links are used for procedures that manipulate time to avoid
-- -- dragging the tasking run time when using delay statements.
--
-- Timed_Delay : Timed_Delay_Call;
--
-- --------------------------
-- -- Task Name Soft-Links --
-- --------------------------
--
-- function Task_Name_NT return String;
--
-- Task_Name : Task_Name_Call := Task_Name_NT'Access;
--
-- -------------------------------------
-- -- Exception Tracebacks Soft-Links --
-- -------------------------------------
--
-- Library_Exception : EO;
-- -- Library-level finalization routines use this common reference to store
-- -- the first library-level exception which occurs during finalization.
--
-- Library_Exception_Set : Boolean := False;
-- -- Used in conjunction with Library_Exception, set when an exception has
-- -- been stored.
--
-- Traceback_Decorator_Wrapper : Traceback_Decorator_Wrapper_Call;
-- -- Wrapper to the possible user specified traceback decorator to be
-- -- called during automatic output of exception data.
--
-- -- The null value of this wrapper corresponds to the null value of the
-- -- current actual decorator. This is ensured first by the null initial
-- -- value of the corresponding variables, and then by Set_Trace_Decorator
-- -- in g-exctra.adb.
--
-- pragma Atomic (Traceback_Decorator_Wrapper);
-- -- Since concurrent read/write operations may occur on this variable.
-- -- See the body of Tailored_Exception_Traceback in
-- -- Ada.Exceptions.Exception_Data for a more detailed description of the
-- -- potential problems.
-- procedure Save_Library_Occurrence (E : EOA);
-- When invoked, this routine saves an exception occurrence into a hidden
-- reference. Subsequent calls will have no effect.
------------------------
-- Task Specific Data --
------------------------
-- Here we define a single type that encapsulates the various task
-- specific data. This type is used to store the necessary data into the
-- Task_Control_Block or into a global variable in the non tasking case.
type TSD is record
-- Pri_Stack_Info : aliased Stack_Checking.Stack_Info;
-- -- Information on stack (Base/Limit/Size) used by System.Stack_Checking.
-- -- If this TSD does not belong to the environment task, the Size field
-- -- must be initialized to the tasks requested stack size before the task
-- -- can do its first stack check.
--
-- Jmpbuf_Address : System.Address;
-- -- Address of jump buffer used to store the address of the current
-- -- longjmp/setjmp buffer for exception management. These buffers are
-- -- threaded into a stack, and the address here is the top of the stack.
-- -- A null address means that no exception handler is currently active.
Sec_Stack_Ptr : SST.SS_Stack_Ptr;
-- Pointer of the allocated secondary stack
-- Current_Excep : aliased EO;
-- -- Exception occurrence that contains the information for the current
-- -- exception. Note that any exception in the same task destroys this
-- -- information, so the data in this variable must be copied out before
-- -- another exception can occur.
-- --
-- -- Also act as a list of the active exceptions in the case of the GCC
-- -- exception mechanism, organized as a stack with the most recent first.
end record;
-- procedure Create_TSD
-- (New_TSD : in out TSD;
-- Sec_Stack : SST.SS_Stack_Ptr;
-- Sec_Stack_Size : System.Parameters.Size_Type);
-- pragma Inline (Create_TSD);
-- -- Called from s-tassta when a new thread is created to perform
-- -- any required initialization of the TSD.
--
-- procedure Destroy_TSD (Old_TSD : in out TSD);
-- pragma Inline (Destroy_TSD);
-- -- Called from s-tassta just before a thread is destroyed to perform
-- -- any required finalization.
--
-- function Get_GNAT_Exception return Ada.Exceptions.Exception_Id;
-- pragma Inline (Get_GNAT_Exception);
-- -- This function obtains the Exception_Id from the Exception_Occurrence
-- -- referenced by the Current_Excep field of the task specific data, i.e.
-- -- the call is equivalent to
-- -- Exception_Identity (Get_Current_Exception.all)
--
-- -- Export the Get/Set routines for the various Task Specific Data (TSD)
-- -- elements as callable subprograms instead of objects of access to
-- -- subprogram types.
--
-- function Get_Jmpbuf_Address_Soft return Address;
-- procedure Set_Jmpbuf_Address_Soft (Addr : Address);
-- pragma Inline (Get_Jmpbuf_Address_Soft);
-- pragma Inline (Set_Jmpbuf_Address_Soft);
--
-- function Get_Sec_Stack_Soft return SST.SS_Stack_Ptr;
-- procedure Set_Sec_Stack_Soft (Stack : SST.SS_Stack_Ptr);
-- pragma Inline (Get_Sec_Stack_Soft);
-- pragma Inline (Set_Sec_Stack_Soft);
-- The following is a dummy record designed to mimic Communication_Block as
-- defined in s-tpobop.ads:
-- type Communication_Block is record
-- Self : Task_Id; -- An access type
-- Enqueued : Boolean := True;
-- Cancelled : Boolean := False;
-- end record;
-- The record is used in the construction of the predefined dispatching
-- primitive _disp_asynchronous_select in order to avoid the import of
-- System.Tasking.Protected_Objects.Operations. Note that this package
-- is always imported in the presence of interfaces since the dispatch
-- table uses entities from here.
type Dummy_Communication_Block is record
Comp_1 : Address; -- Address and access have the same size
Comp_2 : Boolean;
Comp_3 : Boolean;
end record;
private
NT_TSD : aliased TSD;
-- The task specific data for the main task when the Ada tasking run-time
-- is not used. It relies on the default initialization of NT_TSD. It is
-- placed here and not the body to ensure the default initialization does
-- not clobber the secondary stack initialization that occurs as part of
-- System.Soft_Links.Initialization.
end System.Soft_Links;
|
reznikmm/matreshka | Ada | 18,293 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Web API Definition --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014-2015, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
-- This package provides binding to interface Node.
------------------------------------------------------------------------------
limited with WebAPI.DOM.Documents;
limited with WebAPI.DOM.Elements;
with WebAPI.DOM.Event_Targets;
limited with WebAPI.DOM.Node_Lists;
package WebAPI.DOM.Nodes is
pragma Preelaborate;
type Node is limited interface
and WebAPI.DOM.Event_Targets.Event_Target;
type Node_Access is access all Node'Class
with Storage_Size => 0;
-- XXX Not binded yet:
-- const unsigned short ELEMENT_NODE = 1;
-- const unsigned short ATTRIBUTE_NODE = 2; // historical
-- const unsigned short TEXT_NODE = 3;
-- const unsigned short CDATA_SECTION_NODE = 4; // historical
-- const unsigned short ENTITY_REFERENCE_NODE = 5; // historical
-- const unsigned short ENTITY_NODE = 6; // historical
-- const unsigned short PROCESSING_INSTRUCTION_NODE = 7;
-- const unsigned short COMMENT_NODE = 8;
-- const unsigned short DOCUMENT_NODE = 9;
-- const unsigned short DOCUMENT_TYPE_NODE = 10;
-- const unsigned short DOCUMENT_FRAGMENT_NODE = 11;
-- const unsigned short NOTATION_NODE = 12; // historical
-- readonly attribute unsigned short nodeType;
not overriding function Get_Node_Name
(Self : not null access constant Node) return WebAPI.DOM_String is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "nodeName";
-- Returns a string appropriate for the type of node, as follows:
--
-- Element
-- Its tagName attribute value.
-- Text
-- "#text".
-- ProcessingInstruction
-- Its target.
-- Comment
-- "#comment".
-- Document
-- "#document".
-- DocumentType
-- Its name.
-- DocumentFragment
-- "#document-fragment".
not overriding function Get_Base_URI
(Self : not null access constant Node) return WebAPI.DOM_String is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "baseURI";
-- Returns the base URL.
not overriding function Get_Owner_Document
(Self : not null access constant Node)
return WebAPI.DOM.Documents.Document_Access is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "ownerDocument";
-- Returns the node document.
--
-- Returns null for documents.
not overriding function Get_Parent_Node
(Self : not null access constant Node)
return WebAPI.DOM.Nodes.Node_Access is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "parentNode";
-- Returns the parent.
not overriding function Get_Parent_Element
(Self : not null access constant Node)
return WebAPI.DOM.Elements.Element_Access is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "parentElement";
-- Returns the parent element.
not overriding function Has_Child_Nodes
(Self : not null access constant Node) return Boolean is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "hasChildNodes";
-- Returns whether node has children.
not overriding function Get_Child_Nodes
(Self : not null access constant Node)
return WebAPI.DOM.Node_Lists.Node_List is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "childNodes";
-- Returns the children.
not overriding function Get_First_Child
(Self : not null access constant Node)
return WebAPI.DOM.Nodes.Node_Access is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "firstChild";
-- Returns the first child.
not overriding function Get_Last_Child
(Self : not null access constant Node)
return WebAPI.DOM.Nodes.Node_Access is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "lastChild";
-- Returns the last child.
not overriding function Get_Previous_Sibling
(Self : not null access constant Node)
return WebAPI.DOM.Nodes.Node_Access is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "previousSibling";
-- Returns the previous sibling.
not overriding function Get_Next_Sibling
(Self : not null access constant Node)
return WebAPI.DOM.Nodes.Node_Access is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "nextSibling";
-- Returns the next sibling.
not overriding function Get_Node_Value
(Self : not null access constant Node) return WebAPI.DOM_String is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "nodeValue";
-- The nodeValue attribute must return the following, depending on the
-- context object:
--
-- Text
-- Comment
-- ProcessingInstruction
--
-- The context object's data.
--
-- Any other node
--
-- Null.
not overriding procedure Set_Node_Value
(Self : not null access Node;
To : WebAPI.DOM_String) is abstract
with Import => True,
Convention => JavaScript_Property_Setter,
Link_Name => "nodeValue";
-- The nodeValue attribute must, on setting, if the new value is null, act
-- as if it was the empty string instead, and then do as described below,
-- depending on the context object:
--
-- Text
-- Comment
-- ProcessingInstruction
--
-- Replace data with node context object, offset 0, count length
-- attribute value, and data new value.
--
-- Any other node
--
-- Do nothing.
not overriding function Get_Text_Content
(Self : not null access constant Node) return WebAPI.DOM_String is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "textContent";
-- The textContent attribute must return the following, depending on the
-- context object:
--
-- DocumentFragment
-- Element
--
-- The concatenation of data of all the Text node descendants of the
-- context object, in tree order.
--
-- Text
-- ProcessingInstruction
-- Comment
--
-- The context object's data.
--
-- Any other node
--
-- Null.
not overriding procedure Set_Text_Content
(Self : not null access Node;
To : WebAPI.DOM_String) is abstract
with Import => True,
Convention => JavaScript_Property_Setter,
Link_Name => "textContent";
-- The textContent attribute must, on setting, if the new value is null,
-- act as if it was the empty string instead, and then do as described
-- below, depending on the context object:
--
-- DocumentFragment
-- Element
--
-- 1. Let node be null.
--
-- 2. If new value is not the empty string, set node to a new Text node
-- whose data is new value.
--
-- 3. Replace all with node within the context object.
--
-- Text
-- ProcessingInstruction
-- Comment
--
-- Replace data with node context object, offset 0, count length
-- attribute value, and data new value.
--
-- Any other node
--
-- Do nothing.
not overriding procedure Normalize (Self : not null access Node) is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "normalize";
-- Removes empty Text nodes and concatenates the data of remaining
-- contiguous Text nodes into the first of their nodes.
not overriding function Clone_Node
(Self : not null access Node;
Deep : Boolean := False)
return not null WebAPI.DOM.Nodes.Node_Access is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "cloneNode";
-- Returns a copy of node. If deep is true, the copy also includes the
-- node's descendants.
not overriding function Is_Equal_Node
(Self : not null access constant Node;
Other : access Node'Class) return Boolean is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "isEqualNode";
-- Returns whether node and other have the same properties.
-- XXX Not bindied yet:
-- const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01;
-- const unsigned short DOCUMENT_POSITION_PRECEDING = 0x02;
-- const unsigned short DOCUMENT_POSITION_FOLLOWING = 0x04;
-- const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08;
-- const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10;
-- const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20;
-- unsigned short compareDocumentPosition(Node other);
not overriding function Contains
(Self : not null access constant Node;
Other : access Node'Class) return Boolean is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "contains";
-- Returns true if other is an inclusive descendant of node, and false
-- otherwise.
not overriding function Lookup_Prefix
(Self : not null access constant Node;
Namespace_URI : WebAPI.DOM_String) return WebAPI.DOM_String is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "lookupPrefix";
-- The lookupPrefix(namespace) method must run these steps:
--
-- 1. If namespace is null or the empty string, return null.
--
-- 2. Otherwise it depends on the context object:
--
-- Element
--
-- Return the result of locating a namespace prefix for the node
-- using namespace.
--
-- Document
--
-- Return the result of locating a namespace prefix for its document
-- element, if that is not null, and null otherwise.
--
-- DocumentType
-- DocumentFragment
--
-- Return null.
--
-- Any other node
--
-- Return the result of locating a namespace prefix for its parent
-- element, or if that is null, null.
not overriding function Lookup_Namespace_URI
(Self : not null access constant Node;
Prefix : WebAPI.DOM_String) return WebAPI.DOM_String is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "lookupNamespaceURI";
-- The lookupNamespaceURI(prefix) method must run these steps:
--
-- 1. If prefix is the empty string, set it to null.
--
-- 2. Return the result of running locate a namespace for the context
-- object using prefix.
not overriding function Is_Default_Namespace
(Self : not null access constant Node;
Namespace_URI : WebAPI.DOM_String) return Boolean is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "isDefaultNamespace";
-- The isDefaultNamespace(namespace) method must run these steps:
--
-- 1. If namespace is the empty string, set it to null.
--
-- 2. Let defaultNamespace be the result of running locate a namespace for
-- the context object using null.
--
-- 3. Return true if defaultNamespace is the same as namespace, and false
-- otherwise.
not overriding function Insert_Before
(Self : not null access Node;
Node : not null access WebAPI.DOM.Nodes.Node'Class;
Child : access WebAPI.DOM.Nodes.Node'Class)
return WebAPI.DOM.Nodes.Node_Access is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "insertBefore";
procedure Insert_Before
(Self : not null access Node'Class;
Node : not null access WebAPI.DOM.Nodes.Node'Class;
Child : access WebAPI.DOM.Nodes.Node'Class)
with Import => True,
Convention => JavaScript_Method,
Link_Name => "insertBefore";
-- The insertBefore(node, child) method must return the result of
-- pre-inserting node into the context object before child.
not overriding function Append_Child
(Self : not null access Node;
Node : not null access WebAPI.DOM.Nodes.Node'Class)
return Node_Access is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "appendChild";
procedure Append_Child
(Self : not null access Node'Class;
Node : not null access WebAPI.DOM.Nodes.Node'Class)
with Import => True,
Convention => JavaScript_Method,
Link_Name => "appendChild";
-- The appendChild(node) method must return the result of appending node to
-- the context object.
not overriding function Replace_Child
(Self : not null access Node;
Node : not null access WebAPI.DOM.Nodes.Node'Class;
Child : not null access WebAPI.DOM.Nodes.Node'Class)
return WebAPI.DOM.Nodes.Node_Access is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "replaceChild";
procedure Replace_Child
(Self : not null access Node'Class;
Node : not null access WebAPI.DOM.Nodes.Node'Class;
Child : not null access WebAPI.DOM.Nodes.Node'Class)
with Import => True,
Convention => JavaScript_Method,
Link_Name => "replaceChild";
-- The replaceChild(node, child) method must return the result of replacing
-- child with node within the context object.
not overriding function Remove_Child
(Self : not null access Node;
Node : not null access WebAPI.DOM.Nodes.Node'Class)
return Node_Access is abstract
with Import => True,
Convention => JavaScript_Method,
Link_Name => "removeChild";
procedure Remove_Child
(Self : not null access Node'Class;
Node : not null access WebAPI.DOM.Nodes.Node'Class)
with Import => True,
Convention => JavaScript_Method,
Link_Name => "removeChild";
-- The removeChild(child) method must return the result of pre-removing
-- child from the context object.
end WebAPI.DOM.Nodes;
|
stcarrez/ada-el | Ada | 4,233 | adb | -----------------------------------------------------------------------
-- el-methods-proc_in -- Procedure Binding with 1 in argument
-- Copyright (C) 2010, 2011, 2012, 2020, 2021 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Beans.Objects;
package body EL.Methods.Proc_In is
use EL.Expressions;
-- ------------------------------
-- Returns True if the method is a valid method which accepts the arguments
-- defined by the package instantiation.
-- ------------------------------
function Is_Valid (Method : in EL.Expressions.Method_Info) return Boolean is
begin
if Method.Binding = null then
return False;
else
return Method.Binding.all in Binding'Class;
end if;
end Is_Valid;
-- ------------------------------
-- Execute the method describe by the method binding object.
-- The method signature is:
--
-- procedure F (Obj : in out <Bean>;
-- Param : in Param1_Type);
--
-- where <Bean> inherits from <b>Readonly_Bean</b>
-- (See <b>Bind</b> package)
--
-- Raises <b>Invalid_Method</b> if the method referenced by
-- the method expression does not exist or does not match
-- the signature.
-- ------------------------------
procedure Execute (Method : in EL.Expressions.Method_Info;
Param : in Param1_Type) is
begin
if Method.Binding = null then
raise EL.Expressions.Invalid_Method with "Method not found";
end if;
-- If the binding has the wrong type, we are trying to invoke
-- a method with a different signature.
if not (Method.Binding.all in Binding'Class) then
raise EL.Expressions.Invalid_Method
with "Invalid signature for method '" & Method.Binding.Name.all & "'";
end if;
declare
Proxy : constant Binding_Access := Binding (Method.Binding.all)'Access;
begin
Proxy.Method (Util.Beans.Objects.To_Bean (Method.Object), Param);
end;
end Execute;
-- ------------------------------
-- Execute the method describe by the method expression
-- and with the given context. The method signature is:
--
-- procedure F (Obj : in out <Bean>;
-- Param : in Param1_Type);
--
-- where <Bean> inherits from <b>Readonly_Bean</b>
-- (See <b>Bind</b> package)
--
-- Raises <b>Invalid_Method</b> if the method referenced by
-- the method expression does not exist or does not match
-- the signature.
-- ------------------------------
procedure Execute (Method : in EL.Expressions.Method_Expression'Class;
Param : in Param1_Type;
Context : in EL.Contexts.ELContext'Class) is
Info : constant Method_Info := Method.Get_Method_Info (Context);
begin
Execute (Info, Param);
end Execute;
-- ------------------------------
-- Proxy for the binding.
-- The proxy declares the binding definition that links
-- the name to the function and it implements the necessary
-- object conversion to translate the <b>Readonly_Bean</b>
-- object to the target object type.
-- ------------------------------
package body Bind is
procedure Method_Access (O : access Util.Beans.Basic.Readonly_Bean'Class;
P1 : in Param1_Type) is
Object : constant access Bean := Bean (O.all)'Access;
begin
Method (Object.all, P1);
end Method_Access;
end Bind;
end EL.Methods.Proc_In;
|
DrenfongWong/tkm-rpc | Ada | 1,742 | ads | with Tkmrpc.Types;
with Tkmrpc.Operations.Ees;
package Tkmrpc.Request.Ees.Esa_Expire is
Data_Size : constant := 13;
type Data_Type is record
Sp_Id : Types.Sp_Id_Type;
Spi_Rem : Types.Esp_Spi_Type;
Protocol : Types.Protocol_Type;
Hard : Types.Expiry_Flag_Type;
end record;
for Data_Type use record
Sp_Id at 0 range 0 .. (4 * 8) - 1;
Spi_Rem at 4 range 0 .. (4 * 8) - 1;
Protocol at 8 range 0 .. (4 * 8) - 1;
Hard at 12 range 0 .. (1 * 8) - 1;
end record;
for Data_Type'Size use Data_Size * 8;
Padding_Size : constant := Request.Body_Size - Data_Size;
subtype Padding_Range is Natural range 1 .. Padding_Size;
subtype Padding_Type is Types.Byte_Sequence (Padding_Range);
type Request_Type is record
Header : Request.Header_Type;
Data : Data_Type;
Padding : Padding_Type;
end record;
for Request_Type use record
Header at 0 range 0 .. (Request.Header_Size * 8) - 1;
Data at Request.Header_Size range 0 .. (Data_Size * 8) - 1;
Padding at Request.Header_Size + Data_Size range
0 .. (Padding_Size * 8) - 1;
end record;
for Request_Type'Size use Request.Request_Size * 8;
Null_Request : constant Request_Type :=
Request_Type'
(Header =>
Request.Header_Type'(Operation => Operations.Ees.Esa_Expire,
Request_Id => 0),
Data =>
Data_Type'(Sp_Id => Types.Sp_Id_Type'First,
Spi_Rem => Types.Esp_Spi_Type'First,
Protocol => Types.Protocol_Type'First,
Hard => Types.Expiry_Flag_Type'First),
Padding => Padding_Type'(others => 0));
end Tkmrpc.Request.Ees.Esa_Expire;
|
persan/A-gst | Ada | 25,593 | ads | pragma Ada_2005;
pragma Style_Checks (Off);
pragma Warnings (Off);
with Interfaces.C; use Interfaces.C;
with GStreamer.GST_Low_Level.gstreamer_0_10_gst_base_gstbytereader_h;
with glib;
with glib.Values;
with System;
with GLIB; -- with GStreamer.GST_Low_Level.glibconfig_h;
limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstbuffer_h;
package GStreamer.GST_Low_Level.gstreamer_0_10_gst_base_gstbytewriter_h is
-- arg-macro: function GST_BYTE_WRITER (writer)
-- return (GstByteWriter *) (writer);
-- arg-macro: procedure gst_byte_writer_put_string (writer, data)
-- gst_byte_writer_put_string_utf8(writer, data)
-- arg-macro: procedure gst_byte_writer_ensure_free_space (writer, size)
-- G_LIKELY (_gst_byte_writer_ensure_free_space_inline (writer, size))
-- arg-macro: procedure gst_byte_writer_put_uint8 (writer, val)
-- G_LIKELY (_gst_byte_writer_put_uint8_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_int8 (writer, val)
-- G_LIKELY (_gst_byte_writer_put_int8_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_uint16_be (writer, val)
-- G_LIKELY (_gst_byte_writer_put_uint16_be_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_uint16_le (writer, val)
-- G_LIKELY (_gst_byte_writer_put_uint16_le_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_int16_be (writer, val)
-- G_LIKELY (_gst_byte_writer_put_int16_be_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_int16_le (writer, val)
-- G_LIKELY (_gst_byte_writer_put_int16_le_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_uint24_be (writer, val)
-- G_LIKELY (_gst_byte_writer_put_uint24_be_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_uint24_le (writer, val)
-- G_LIKELY (_gst_byte_writer_put_uint24_le_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_int24_be (writer, val)
-- G_LIKELY (_gst_byte_writer_put_int24_be_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_int24_le (writer, val)
-- G_LIKELY (_gst_byte_writer_put_int24_le_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_uint32_be (writer, val)
-- G_LIKELY (_gst_byte_writer_put_uint32_be_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_uint32_le (writer, val)
-- G_LIKELY (_gst_byte_writer_put_uint32_le_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_int32_be (writer, val)
-- G_LIKELY (_gst_byte_writer_put_int32_be_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_int32_le (writer, val)
-- G_LIKELY (_gst_byte_writer_put_int32_le_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_uint64_be (writer, val)
-- G_LIKELY (_gst_byte_writer_put_uint64_be_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_uint64_le (writer, val)
-- G_LIKELY (_gst_byte_writer_put_uint64_le_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_int64_be (writer, val)
-- G_LIKELY (_gst_byte_writer_put_int64_be_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_int64_le (writer, val)
-- G_LIKELY (_gst_byte_writer_put_int64_le_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_float32_be (writer, val)
-- G_LIKELY (_gst_byte_writer_put_float32_be_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_float32_le (writer, val)
-- G_LIKELY (_gst_byte_writer_put_float32_le_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_float64_be (writer, val)
-- G_LIKELY (_gst_byte_writer_put_float64_be_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_float64_le (writer, val)
-- G_LIKELY (_gst_byte_writer_put_float64_le_inline (writer, val))
-- arg-macro: procedure gst_byte_writer_put_data (writer, data, size)
-- G_LIKELY (_gst_byte_writer_put_data_inline (writer, data, size))
-- arg-macro: procedure gst_byte_writer_fill (writer, val, size)
-- G_LIKELY (_gst_byte_writer_fill_inline (writer, val, size))
-- GStreamer byte writer
-- *
-- * Copyright (C) 2009 Sebastian Dröge <[email protected]>.
-- *
-- * This library is free software; you can redistribute it and/or
-- * modify it under the terms of the GNU Library General Public
-- * License as published by the Free Software Foundation; either
-- * version 2 of the License, or (at your option) any later version.
-- *
-- * This library is distributed in the hope that it will be useful,
-- * but WITHOUT ANY WARRANTY; without even the implied warranty of
-- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- * Library General Public License for more details.
-- *
-- * You should have received a copy of the GNU Library General Public
-- * License along with this library; if not, write to the
-- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-- * Boston, MA 02111-1307, USA.
--
--*
-- * GstByteWriter:
-- * @parent: #GstByteReader parent
-- * @alloc_size: Allocation size of the data
-- * @fixed: If %TRUE no reallocations are allowed
-- * @owned: If %FALSE no reallocations are allowed and copies of data are returned
-- *
-- * A byte writer instance.
--
type GstByteWriter is record
parent : aliased GStreamer.GST_Low_Level.gstreamer_0_10_gst_base_gstbytereader_h.GstByteReader; -- gst/base/gstbytewriter.h:43
alloc_size : aliased GLIB.guint; -- gst/base/gstbytewriter.h:45
fixed : aliased GLIB.gboolean; -- gst/base/gstbytewriter.h:47
owned : aliased GLIB.gboolean; -- gst/base/gstbytewriter.h:48
end record;
pragma Convention (C_Pass_By_Copy, GstByteWriter); -- gst/base/gstbytewriter.h:49
-- skipped anonymous struct anon_310
function gst_byte_writer_new return access GstByteWriter; -- gst/base/gstbytewriter.h:51
pragma Import (C, gst_byte_writer_new, "gst_byte_writer_new");
function gst_byte_writer_new_with_size (size : GLIB.guint; fixed : GLIB.gboolean) return access GstByteWriter; -- gst/base/gstbytewriter.h:52
pragma Import (C, gst_byte_writer_new_with_size, "gst_byte_writer_new_with_size");
function gst_byte_writer_new_with_data
(data : access GLIB.guint8;
size : GLIB.guint;
initialized : GLIB.gboolean) return access GstByteWriter; -- gst/base/gstbytewriter.h:53
pragma Import (C, gst_byte_writer_new_with_data, "gst_byte_writer_new_with_data");
function gst_byte_writer_new_with_buffer (buffer : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstbuffer_h.GstBuffer; initialized : GLIB.gboolean) return access GstByteWriter; -- gst/base/gstbytewriter.h:54
pragma Import (C, gst_byte_writer_new_with_buffer, "gst_byte_writer_new_with_buffer");
procedure gst_byte_writer_init (writer : access GstByteWriter); -- gst/base/gstbytewriter.h:56
pragma Import (C, gst_byte_writer_init, "gst_byte_writer_init");
procedure gst_byte_writer_init_with_size
(writer : access GstByteWriter;
size : GLIB.guint;
fixed : GLIB.gboolean); -- gst/base/gstbytewriter.h:57
pragma Import (C, gst_byte_writer_init_with_size, "gst_byte_writer_init_with_size");
procedure gst_byte_writer_init_with_data
(writer : access GstByteWriter;
data : access GLIB.guint8;
size : GLIB.guint;
initialized : GLIB.gboolean); -- gst/base/gstbytewriter.h:58
pragma Import (C, gst_byte_writer_init_with_data, "gst_byte_writer_init_with_data");
procedure gst_byte_writer_init_with_buffer
(writer : access GstByteWriter;
buffer : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstbuffer_h.GstBuffer;
initialized : GLIB.gboolean); -- gst/base/gstbytewriter.h:59
pragma Import (C, gst_byte_writer_init_with_buffer, "gst_byte_writer_init_with_buffer");
procedure gst_byte_writer_free (writer : access GstByteWriter); -- gst/base/gstbytewriter.h:61
pragma Import (C, gst_byte_writer_free, "gst_byte_writer_free");
function gst_byte_writer_free_and_get_data (writer : access GstByteWriter) return access GLIB.guint8; -- gst/base/gstbytewriter.h:62
pragma Import (C, gst_byte_writer_free_and_get_data, "gst_byte_writer_free_and_get_data");
function gst_byte_writer_free_and_get_buffer (writer : access GstByteWriter) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstbuffer_h.GstBuffer; -- gst/base/gstbytewriter.h:63
pragma Import (C, gst_byte_writer_free_and_get_buffer, "gst_byte_writer_free_and_get_buffer");
procedure gst_byte_writer_reset (writer : access GstByteWriter); -- gst/base/gstbytewriter.h:65
pragma Import (C, gst_byte_writer_reset, "gst_byte_writer_reset");
function gst_byte_writer_reset_and_get_data (writer : access GstByteWriter) return access GLIB.guint8; -- gst/base/gstbytewriter.h:66
pragma Import (C, gst_byte_writer_reset_and_get_data, "gst_byte_writer_reset_and_get_data");
function gst_byte_writer_reset_and_get_buffer (writer : access GstByteWriter) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_gstbuffer_h.GstBuffer; -- gst/base/gstbytewriter.h:67
pragma Import (C, gst_byte_writer_reset_and_get_buffer, "gst_byte_writer_reset_and_get_buffer");
--*
-- * gst_byte_writer_get_pos:
-- * @writer: #GstByteWriter instance
-- *
-- * Returns: The current position of the read/write cursor
-- *
-- * Since: 0.10.26
--
--*
-- * gst_byte_writer_set_pos:
-- * @writer: #GstByteWriter instance
-- * @pos: new position
-- *
-- * Sets the current read/write cursor of @writer. The new position
-- * can only be between 0 and the current size.
-- *
-- * Returns: %TRUE if the new position could be set
-- *
-- * Since: 0.10.26
--
--*
-- * gst_byte_writer_get_size:
-- * @writer: #GstByteWriter instance
-- *
-- * Returns: The current, initialized size of the data
-- *
-- * Since: 0.10.26
--
function gst_byte_writer_get_pos (writer : access constant GstByteWriter) return GLIB.guint; -- gst/base/gstbytewriter.h:103
pragma Import (C, gst_byte_writer_get_pos, "gst_byte_writer_get_pos");
function gst_byte_writer_set_pos (writer : access GstByteWriter; pos : GLIB.guint) return GLIB.gboolean; -- gst/base/gstbytewriter.h:109
pragma Import (C, gst_byte_writer_set_pos, "gst_byte_writer_set_pos");
function gst_byte_writer_get_size (writer : access constant GstByteWriter) return GLIB.guint; -- gst/base/gstbytewriter.h:115
pragma Import (C, gst_byte_writer_get_size, "gst_byte_writer_get_size");
function gst_byte_writer_get_remaining (writer : access constant GstByteWriter) return GLIB.guint; -- gst/base/gstbytewriter.h:121
pragma Import (C, gst_byte_writer_get_remaining, "gst_byte_writer_get_remaining");
function gst_byte_writer_ensure_free_space (writer : access GstByteWriter; size : GLIB.guint) return GLIB.gboolean; -- gst/base/gstbytewriter.h:122
pragma Import (C, gst_byte_writer_ensure_free_space, "gst_byte_writer_ensure_free_space");
function gst_byte_writer_put_uint8 (writer : access GstByteWriter; val : GLIB.guint8) return GLIB.gboolean; -- gst/base/gstbytewriter.h:124
pragma Import (C, gst_byte_writer_put_uint8, "gst_byte_writer_put_uint8");
function gst_byte_writer_put_int8 (writer : access GstByteWriter; val : GLIB.gint8) return GLIB.gboolean; -- gst/base/gstbytewriter.h:125
pragma Import (C, gst_byte_writer_put_int8, "gst_byte_writer_put_int8");
function gst_byte_writer_put_uint16_be (writer : access GstByteWriter; val : GLIB.guint16) return GLIB.gboolean; -- gst/base/gstbytewriter.h:126
pragma Import (C, gst_byte_writer_put_uint16_be, "gst_byte_writer_put_uint16_be");
function gst_byte_writer_put_uint16_le (writer : access GstByteWriter; val : GLIB.guint16) return GLIB.gboolean; -- gst/base/gstbytewriter.h:127
pragma Import (C, gst_byte_writer_put_uint16_le, "gst_byte_writer_put_uint16_le");
function gst_byte_writer_put_int16_be (writer : access GstByteWriter; val : GLIB.gint16) return GLIB.gboolean; -- gst/base/gstbytewriter.h:128
pragma Import (C, gst_byte_writer_put_int16_be, "gst_byte_writer_put_int16_be");
function gst_byte_writer_put_int16_le (writer : access GstByteWriter; val : GLIB.gint16) return GLIB.gboolean; -- gst/base/gstbytewriter.h:129
pragma Import (C, gst_byte_writer_put_int16_le, "gst_byte_writer_put_int16_le");
function gst_byte_writer_put_uint24_be (writer : access GstByteWriter; val : GLIB.guint32) return GLIB.gboolean; -- gst/base/gstbytewriter.h:130
pragma Import (C, gst_byte_writer_put_uint24_be, "gst_byte_writer_put_uint24_be");
function gst_byte_writer_put_uint24_le (writer : access GstByteWriter; val : GLIB.guint32) return GLIB.gboolean; -- gst/base/gstbytewriter.h:131
pragma Import (C, gst_byte_writer_put_uint24_le, "gst_byte_writer_put_uint24_le");
function gst_byte_writer_put_int24_be (writer : access GstByteWriter; val : GLIB.gint32) return GLIB.gboolean; -- gst/base/gstbytewriter.h:132
pragma Import (C, gst_byte_writer_put_int24_be, "gst_byte_writer_put_int24_be");
function gst_byte_writer_put_int24_le (writer : access GstByteWriter; val : GLIB.gint32) return GLIB.gboolean; -- gst/base/gstbytewriter.h:133
pragma Import (C, gst_byte_writer_put_int24_le, "gst_byte_writer_put_int24_le");
function gst_byte_writer_put_uint32_be (writer : access GstByteWriter; val : GLIB.guint32) return GLIB.gboolean; -- gst/base/gstbytewriter.h:134
pragma Import (C, gst_byte_writer_put_uint32_be, "gst_byte_writer_put_uint32_be");
function gst_byte_writer_put_uint32_le (writer : access GstByteWriter; val : GLIB.guint32) return GLIB.gboolean; -- gst/base/gstbytewriter.h:135
pragma Import (C, gst_byte_writer_put_uint32_le, "gst_byte_writer_put_uint32_le");
function gst_byte_writer_put_int32_be (writer : access GstByteWriter; val : GLIB.gint32) return GLIB.gboolean; -- gst/base/gstbytewriter.h:136
pragma Import (C, gst_byte_writer_put_int32_be, "gst_byte_writer_put_int32_be");
function gst_byte_writer_put_int32_le (writer : access GstByteWriter; val : GLIB.gint32) return GLIB.gboolean; -- gst/base/gstbytewriter.h:137
pragma Import (C, gst_byte_writer_put_int32_le, "gst_byte_writer_put_int32_le");
function gst_byte_writer_put_uint64_be (writer : access GstByteWriter; val : GLIB.guint64) return GLIB.gboolean; -- gst/base/gstbytewriter.h:138
pragma Import (C, gst_byte_writer_put_uint64_be, "gst_byte_writer_put_uint64_be");
function gst_byte_writer_put_uint64_le (writer : access GstByteWriter; val : GLIB.guint64) return GLIB.gboolean; -- gst/base/gstbytewriter.h:139
pragma Import (C, gst_byte_writer_put_uint64_le, "gst_byte_writer_put_uint64_le");
function gst_byte_writer_put_int64_be (writer : access GstByteWriter; val : GLIB.gint64) return GLIB.gboolean; -- gst/base/gstbytewriter.h:140
pragma Import (C, gst_byte_writer_put_int64_be, "gst_byte_writer_put_int64_be");
function gst_byte_writer_put_int64_le (writer : access GstByteWriter; val : GLIB.gint64) return GLIB.gboolean; -- gst/base/gstbytewriter.h:141
pragma Import (C, gst_byte_writer_put_int64_le, "gst_byte_writer_put_int64_le");
function gst_byte_writer_put_float32_be (writer : access GstByteWriter; val : GLIB.gfloat) return GLIB.gboolean; -- gst/base/gstbytewriter.h:143
pragma Import (C, gst_byte_writer_put_float32_be, "gst_byte_writer_put_float32_be");
function gst_byte_writer_put_float32_le (writer : access GstByteWriter; val : GLIB.gfloat) return GLIB.gboolean; -- gst/base/gstbytewriter.h:144
pragma Import (C, gst_byte_writer_put_float32_le, "gst_byte_writer_put_float32_le");
function gst_byte_writer_put_float64_be (writer : access GstByteWriter; val : GLIB.gdouble) return GLIB.gboolean; -- gst/base/gstbytewriter.h:145
pragma Import (C, gst_byte_writer_put_float64_be, "gst_byte_writer_put_float64_be");
function gst_byte_writer_put_float64_le (writer : access GstByteWriter; val : GLIB.gdouble) return GLIB.gboolean; -- gst/base/gstbytewriter.h:146
pragma Import (C, gst_byte_writer_put_float64_le, "gst_byte_writer_put_float64_le");
function gst_byte_writer_put_data
(writer : access GstByteWriter;
data : access GLIB.guint8;
size : GLIB.guint) return GLIB.gboolean; -- gst/base/gstbytewriter.h:148
pragma Import (C, gst_byte_writer_put_data, "gst_byte_writer_put_data");
function gst_byte_writer_fill
(writer : access GstByteWriter;
value : GLIB.guint8;
size : GLIB.guint) return GLIB.gboolean; -- gst/base/gstbytewriter.h:149
pragma Import (C, gst_byte_writer_fill, "gst_byte_writer_fill");
function gst_byte_writer_put_string_utf8 (writer : access GstByteWriter; data : access GLIB.gchar) return GLIB.gboolean; -- gst/base/gstbytewriter.h:150
pragma Import (C, gst_byte_writer_put_string_utf8, "gst_byte_writer_put_string_utf8");
function gst_byte_writer_put_string_utf16 (writer : access GstByteWriter; data : access GLIB.guint16) return GLIB.gboolean; -- gst/base/gstbytewriter.h:151
pragma Import (C, gst_byte_writer_put_string_utf16, "gst_byte_writer_put_string_utf16");
function gst_byte_writer_put_string_utf32 (writer : access GstByteWriter; data : access GLIB.guint32) return GLIB.gboolean; -- gst/base/gstbytewriter.h:152
pragma Import (C, gst_byte_writer_put_string_utf32, "gst_byte_writer_put_string_utf32");
--*
-- * gst_byte_writer_put_string:
-- * @writer: #GstByteWriter instance
-- * @data: (in) (array zero-terminated=1): Null terminated string
-- *
-- * Write a NUL-terminated string to @writer (including the terminator). The
-- * string is assumed to be in an 8-bit encoding (e.g. ASCII,UTF-8 or
-- * ISO-8859-1).
-- *
-- * Returns: %TRUE if the string could be written
-- *
-- * Since: 0.10.26
--
-- skipped func _gst_byte_writer_next_pow2
-- We start with 16, smaller allocations make no sense
-- skipped func _gst_byte_writer_ensure_free_space_inline
-- skipped func _gst_byte_writer_put_uint8_inline
procedure gst_byte_writer_put_uint8_unchecked (writer : access GstByteWriter; val : GLIB.guint8); -- gst/base/gstbytewriter.h:230
pragma Import (C, gst_byte_writer_put_uint8_unchecked, "gst_byte_writer_put_uint8_unchecked");
-- skipped func _gst_byte_writer_put_int8_inline
procedure gst_byte_writer_put_int8_unchecked (writer : access GstByteWriter; val : GLIB.gint8); -- gst/base/gstbytewriter.h:231
pragma Import (C, gst_byte_writer_put_int8_unchecked, "gst_byte_writer_put_int8_unchecked");
-- skipped func _gst_byte_writer_put_uint16_le_inline
procedure gst_byte_writer_put_uint16_le_unchecked (writer : access GstByteWriter; val : GLIB.guint16); -- gst/base/gstbytewriter.h:232
pragma Import (C, gst_byte_writer_put_uint16_le_unchecked, "gst_byte_writer_put_uint16_le_unchecked");
-- skipped func _gst_byte_writer_put_uint16_be_inline
procedure gst_byte_writer_put_uint16_be_unchecked (writer : access GstByteWriter; val : GLIB.guint16); -- gst/base/gstbytewriter.h:233
pragma Import (C, gst_byte_writer_put_uint16_be_unchecked, "gst_byte_writer_put_uint16_be_unchecked");
-- skipped func _gst_byte_writer_put_int16_le_inline
procedure gst_byte_writer_put_int16_le_unchecked (writer : access GstByteWriter; val : GLIB.gint16); -- gst/base/gstbytewriter.h:234
pragma Import (C, gst_byte_writer_put_int16_le_unchecked, "gst_byte_writer_put_int16_le_unchecked");
-- skipped func _gst_byte_writer_put_int16_be_inline
procedure gst_byte_writer_put_int16_be_unchecked (writer : access GstByteWriter; val : GLIB.gint16); -- gst/base/gstbytewriter.h:235
pragma Import (C, gst_byte_writer_put_int16_be_unchecked, "gst_byte_writer_put_int16_be_unchecked");
-- skipped func _gst_byte_writer_put_uint24_le_inline
procedure gst_byte_writer_put_uint24_le_unchecked (writer : access GstByteWriter; val : GLIB.guint32); -- gst/base/gstbytewriter.h:236
pragma Import (C, gst_byte_writer_put_uint24_le_unchecked, "gst_byte_writer_put_uint24_le_unchecked");
-- skipped func _gst_byte_writer_put_uint24_be_inline
procedure gst_byte_writer_put_uint24_be_unchecked (writer : access GstByteWriter; val : GLIB.guint32); -- gst/base/gstbytewriter.h:237
pragma Import (C, gst_byte_writer_put_uint24_be_unchecked, "gst_byte_writer_put_uint24_be_unchecked");
-- skipped func _gst_byte_writer_put_int24_le_inline
procedure gst_byte_writer_put_int24_le_unchecked (writer : access GstByteWriter; val : GLIB.gint32); -- gst/base/gstbytewriter.h:238
pragma Import (C, gst_byte_writer_put_int24_le_unchecked, "gst_byte_writer_put_int24_le_unchecked");
-- skipped func _gst_byte_writer_put_int24_be_inline
procedure gst_byte_writer_put_int24_be_unchecked (writer : access GstByteWriter; val : GLIB.gint32); -- gst/base/gstbytewriter.h:239
pragma Import (C, gst_byte_writer_put_int24_be_unchecked, "gst_byte_writer_put_int24_be_unchecked");
-- skipped func _gst_byte_writer_put_uint32_le_inline
procedure gst_byte_writer_put_uint32_le_unchecked (writer : access GstByteWriter; val : GLIB.guint32); -- gst/base/gstbytewriter.h:240
pragma Import (C, gst_byte_writer_put_uint32_le_unchecked, "gst_byte_writer_put_uint32_le_unchecked");
-- skipped func _gst_byte_writer_put_uint32_be_inline
procedure gst_byte_writer_put_uint32_be_unchecked (writer : access GstByteWriter; val : GLIB.guint32); -- gst/base/gstbytewriter.h:241
pragma Import (C, gst_byte_writer_put_uint32_be_unchecked, "gst_byte_writer_put_uint32_be_unchecked");
-- skipped func _gst_byte_writer_put_int32_le_inline
procedure gst_byte_writer_put_int32_le_unchecked (writer : access GstByteWriter; val : GLIB.gint32); -- gst/base/gstbytewriter.h:242
pragma Import (C, gst_byte_writer_put_int32_le_unchecked, "gst_byte_writer_put_int32_le_unchecked");
-- skipped func _gst_byte_writer_put_int32_be_inline
procedure gst_byte_writer_put_int32_be_unchecked (writer : access GstByteWriter; val : GLIB.gint32); -- gst/base/gstbytewriter.h:243
pragma Import (C, gst_byte_writer_put_int32_be_unchecked, "gst_byte_writer_put_int32_be_unchecked");
-- skipped func _gst_byte_writer_put_uint64_le_inline
procedure gst_byte_writer_put_uint64_le_unchecked (writer : access GstByteWriter; val : GLIB.guint64); -- gst/base/gstbytewriter.h:244
pragma Import (C, gst_byte_writer_put_uint64_le_unchecked, "gst_byte_writer_put_uint64_le_unchecked");
-- skipped func _gst_byte_writer_put_uint64_be_inline
procedure gst_byte_writer_put_uint64_be_unchecked (writer : access GstByteWriter; val : GLIB.guint64); -- gst/base/gstbytewriter.h:245
pragma Import (C, gst_byte_writer_put_uint64_be_unchecked, "gst_byte_writer_put_uint64_be_unchecked");
-- skipped func _gst_byte_writer_put_int64_le_inline
procedure gst_byte_writer_put_int64_le_unchecked (writer : access GstByteWriter; val : GLIB.gint64); -- gst/base/gstbytewriter.h:246
pragma Import (C, gst_byte_writer_put_int64_le_unchecked, "gst_byte_writer_put_int64_le_unchecked");
-- skipped func _gst_byte_writer_put_int64_be_inline
procedure gst_byte_writer_put_int64_be_unchecked (writer : access GstByteWriter; val : GLIB.gint64); -- gst/base/gstbytewriter.h:247
pragma Import (C, gst_byte_writer_put_int64_be_unchecked, "gst_byte_writer_put_int64_be_unchecked");
-- skipped func _gst_byte_writer_put_float32_be_inline
procedure gst_byte_writer_put_float32_be_unchecked (writer : access GstByteWriter; val : GLIB.gfloat); -- gst/base/gstbytewriter.h:249
pragma Import (C, gst_byte_writer_put_float32_be_unchecked, "gst_byte_writer_put_float32_be_unchecked");
-- skipped func _gst_byte_writer_put_float32_le_inline
procedure gst_byte_writer_put_float32_le_unchecked (writer : access GstByteWriter; val : GLIB.gfloat); -- gst/base/gstbytewriter.h:250
pragma Import (C, gst_byte_writer_put_float32_le_unchecked, "gst_byte_writer_put_float32_le_unchecked");
-- skipped func _gst_byte_writer_put_float64_be_inline
procedure gst_byte_writer_put_float64_be_unchecked (writer : access GstByteWriter; val : GLIB.gdouble); -- gst/base/gstbytewriter.h:251
pragma Import (C, gst_byte_writer_put_float64_be_unchecked, "gst_byte_writer_put_float64_be_unchecked");
-- skipped func _gst_byte_writer_put_float64_le_inline
procedure gst_byte_writer_put_float64_le_unchecked (writer : access GstByteWriter; val : GLIB.gdouble); -- gst/base/gstbytewriter.h:252
pragma Import (C, gst_byte_writer_put_float64_le_unchecked, "gst_byte_writer_put_float64_le_unchecked");
procedure gst_byte_writer_put_data_unchecked
(writer : access GstByteWriter;
data : access GLIB.guint8;
size : GLIB.guint); -- gst/base/gstbytewriter.h:257
pragma Import (C, gst_byte_writer_put_data_unchecked, "gst_byte_writer_put_data_unchecked");
-- skipped func _gst_byte_writer_put_data_inline
procedure gst_byte_writer_fill_unchecked
(writer : access GstByteWriter;
value : GLIB.guint8;
size : GLIB.guint); -- gst/base/gstbytewriter.h:280
pragma Import (C, gst_byte_writer_fill_unchecked, "gst_byte_writer_fill_unchecked");
-- skipped func _gst_byte_writer_fill_inline
-- we use defines here so we can add the G_LIKELY()
end GStreamer.GST_Low_Level.gstreamer_0_10_gst_base_gstbytewriter_h;
|
reznikmm/matreshka | Ada | 4,695 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Visitors;
with ODF.DOM.Draw_Gradient_Elements;
package Matreshka.ODF_Draw.Gradient_Elements is
type Draw_Gradient_Element_Node is
new Matreshka.ODF_Draw.Abstract_Draw_Element_Node
and ODF.DOM.Draw_Gradient_Elements.ODF_Draw_Gradient
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Draw_Gradient_Element_Node;
overriding function Get_Local_Name
(Self : not null access constant Draw_Gradient_Element_Node)
return League.Strings.Universal_String;
overriding procedure Enter_Node
(Self : not null access Draw_Gradient_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
overriding procedure Leave_Node
(Self : not null access Draw_Gradient_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
overriding procedure Visit_Node
(Self : not null access Draw_Gradient_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control);
end Matreshka.ODF_Draw.Gradient_Elements;
|
alexcamposruiz/dds-requestreply | Ada | 105 | ads | package DDS.Request_Reply.connext_c_requestreply_treqtrepsimplereplier is
pragma Elaborate_Body;
end;
|
AdaCore/gpr | Ada | 9,503 | adb | ------------------------------------------------------------------------------
-- --
-- GPR2 PROJECT MANAGER --
-- --
-- Copyright (C) 2019-2023, AdaCore --
-- --
-- This 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. This software is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. 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, --
-- see <http://www.gnu.org/licenses/>. --
-- --
------------------------------------------------------------------------------
with Ada.Command_Line;
with Ada.Exceptions;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
with GNATCOLL.Traces;
with GNATCOLL.Tribooleans;
with GPRtools.Command_Line;
with GPRtools.Util;
with GPRtools.Options;
with GPR2.Path_Name;
with GPR2.Project.Source.Artifact;
pragma Warnings (Off, "*is not referenced");
with GPR2.Project.Source.Part_Set;
pragma Warnings (On, "*is not referenced");
with GPR2.Project.Tree;
with GPR2.Project.View;
with GPR2.Project.Unit_Info;
with GPR2.Unit;
procedure GPRdump is
use Ada;
use Ada.Exceptions;
use Ada.Strings.Unbounded;
use GNATCOLL.Tribooleans;
use GPR2;
type GPRdump_Options is new GPRtools.Options.Base_Options with record
Display_Sources : Boolean := False;
Display_All_Sources : Boolean := False;
Display_Artifacts : Boolean := False;
Display_Units : Boolean := False;
All_Projects : Boolean := False;
Source : Unbounded_String;
end record;
procedure On_Switch
(Parser : GPRtools.Command_Line.Command_Line_Parser'Class;
Res : not null access GPRtools.Command_Line.Command_Line_Result'Class;
Arg : GPRtools.Command_Line.Switch_Type;
Index : String;
Param : String);
procedure Sources (View : Project.View.Object);
-- Display view sources
procedure Full_Closure (Tree : Project.Tree.Object; Filename : String);
procedure Parse_Command_Line;
-- Parse command line parameters
Project_Tree : GPR2.Project.Tree.Object;
Options : GPRdump_Options;
------------------
-- Full_Closure --
------------------
procedure Full_Closure (Tree : Project.Tree.Object; Filename : String) is
File : constant GPR2.Path_Name.Object :=
GPR2.Path_Name.Create_File
(Filename_Type (Filename), GPR2.Path_Name.No_Resolution);
View : constant GPR2.Project.View.Object :=
Tree.Get_View (File);
begin
if not View.Is_Defined then
Text_IO.Put_Line ("view for " & Filename & " not found.");
else
declare
Source : constant GPR2.Project.Source.Object :=
View.Source (File);
begin
if Source.Has_Units then
for CU of Source.Units loop
for S of Source.Dependencies (Index => CU.Index) loop
Text_IO.Put_Line
(S.Source.Path_Name.Value &
(if S.Index in Multi_Unit_Index
then S.Index'Image
else ""));
end loop;
end loop;
end if;
end;
end if;
end Full_Closure;
---------------
-- On_Switch --
---------------
procedure On_Switch
(Parser : GPRtools.Command_Line.Command_Line_Parser'Class;
Res : not null access GPRtools.Command_Line.Command_Line_Result'Class;
Arg : GPRtools.Command_Line.Switch_Type;
Index : String;
Param : String)
is
pragma Unreferenced (Parser, Index);
use type GPRtools.Command_Line.Switch_Type;
Result : constant access GPRdump_Options :=
GPRdump_Options (Res.all)'Access;
begin
if Arg = "-s" then
Result.Display_Sources := True;
elsif Arg = "-a" then
Result.Display_All_Sources := True;
elsif Arg = "-u" then
Result.Display_Units := True;
elsif Arg = "-r" then
Result.All_Projects := True;
elsif Arg = "--artifacts" then
Result.Display_Artifacts := True;
elsif Arg = "-d" then
Result.Source := To_Unbounded_String (Param);
end if;
end On_Switch;
------------------------
-- Parse_Command_Line --
------------------------
procedure Parse_Command_Line is
use GPRtools.Command_Line;
Parser : GPRtools.Options.Command_Line_Parser :=
GPRtools.Options.Create
("2019",
Allow_Autoconf => True,
Allow_Distributed => False);
Dump_Group : constant GPRtools.Command_Line.Argument_Group :=
Parser.Add_Argument_Group ("dump",
On_Switch'Unrestricted_Access);
begin
GPRtools.Options.Setup (GPRtools.Ls);
Parser.Add_Argument
(Dump_Group,
Create ("-s", "--sources",
Help => "display sources"));
Parser.Add_Argument
(Dump_Group,
Create ("-a", "--all-sources",
Help => "display all sources"));
Parser.Add_Argument
(Dump_Group,
Create ("-u", "--units",
Help => "display units"));
Parser.Add_Argument
(Dump_Group,
Create ("-r", "--recursive",
Help => "all non externally built project recursively"));
Parser.Add_Argument
(Dump_Group,
Create ("--artifacts",
Help => "display compilation artifacts"));
Parser.Add_Argument
(Dump_Group,
Create
("-d", "--depth",
Delimiter => Space,
Parameter => "<source>",
Help => "display the full closure of 'source'"));
Options.Tree := Project_Tree.Reference;
Parser.Get_Opt (Options);
if not GPRtools.Options.Load_Project
(Options, Absent_Dir_Error => Project.Tree.Warning)
then
GPRtools.Command_Line.Try_Help;
end if;
end Parse_Command_Line;
-------------
-- Sources --
-------------
procedure Sources (View : Project.View.Object) is
Is_Empty : Boolean := True;
begin
for S of View.Sources
(Compilable_Only => not Options.Display_All_Sources)
loop
Is_Empty := False;
if Options.Display_Sources
or else Options.Display_All_Sources
then
Text_IO.Put_Line (S.Path_Name.Value);
if Options.Display_Units and then S.Has_Units then
for U of S.Units loop
Text_IO.Put_Line
(ASCII.HT & String (U.Name)
& ASCII.HT & U.Kind'Img);
end loop;
end if;
end if;
if Options.Display_Artifacts then
for A of S.Artifacts.List loop
Text_IO.Put_Line (A.Value);
end loop;
end if;
end loop;
if Is_Empty then
Text_IO.Put_Line ("no sources");
end if;
if Options.Display_Units then
for U of View.Units loop
Text_IO.Put_Line
(String (U.Name) & ' '
& (if U.Has_Spec then U.Spec.Source.Value else "-")
& ' '
& (if U.Has_Body then U.Main_Body.Source.Value
else "-")
);
end loop;
end if;
end Sources;
begin
GNATCOLL.Traces.Parse_Config_File;
GPRtools.Util.Set_Program_Name ("gprdump");
Parse_Command_Line;
if Options.Display_Sources
or else Options.Display_All_Sources
or else Options.Display_Artifacts
or else Options.Display_Units
then
for V in Project_Tree.Iterate
(Kind => (Project.I_Recursive => Options.All_Projects,
Project.I_Imported => Options.All_Projects,
Project.I_Aggregated => Options.All_Projects,
others => True),
Status => (Project.S_Externally_Built => False),
Filter => (Project.F_Abstract | Project.F_Aggregate => False,
others => True))
loop
Sources (Project.Tree.Element (V));
end loop;
end if;
if Options.Source /= Null_Unbounded_String then
Full_Closure (Project_Tree, To_String (Options.Source));
end if;
for M of Project_Tree.Log_Messages.all loop
M.Output;
end loop;
exception
when E : others =>
Text_IO.Put_Line ("cannot parse project: " & Exception_Information (E));
Command_Line.Set_Exit_Status (Command_Line.Failure);
end GPRdump;
|
AdaCore/Ada_Drivers_Library | Ada | 2,645 | ads | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 2019, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- Bit-bang a sequence of color LED values to a one-pin LED strip (WS2812B
-- or similar).
with HAL; use HAL;
package MicroBit.IOs.NeoPixel is
procedure Write (Pin : Pin_Id; Values : UInt8_Array)
with Pre => Supports (Pin, Digital);
end MicroBit.IOs.NeoPixel;
|
reznikmm/matreshka | Ada | 4,599 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Dr3d.End_Angle_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Dr3d_End_Angle_Attribute_Node is
begin
return Self : Dr3d_End_Angle_Attribute_Node do
Matreshka.ODF_Dr3d.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Dr3d_Prefix);
end return;
end Create;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Dr3d_End_Angle_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.End_Angle_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Dr3d_URI,
Matreshka.ODF_String_Constants.End_Angle_Attribute,
Dr3d_End_Angle_Attribute_Node'Tag);
end Matreshka.ODF_Dr3d.End_Angle_Attributes;
|
reznikmm/matreshka | Ada | 6,203 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.Constants;
with ODF.DOM.Elements.Style.Footnote_Sep.Internals;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Elements.Style.Footnote_Sep is
-------------------
-- Enter_Element --
-------------------
overriding procedure Enter_Element
(Self : not null access Style_Footnote_Sep_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.ODF_Visitor'Class then
ODF.DOM.Visitors.ODF_Visitor'Class
(Visitor).Enter_Style_Footnote_Sep
(ODF.DOM.Elements.Style.Footnote_Sep.Internals.Create
(Style_Footnote_Sep_Access (Self)),
Control);
else
Matreshka.DOM_Nodes.Elements.Abstract_Element
(Self.all).Enter_Element (Visitor, Control);
end if;
end Enter_Element;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Style_Footnote_Sep_Node)
return League.Strings.Universal_String is
begin
return ODF.Constants.Footnote_Sep_Name;
end Get_Local_Name;
-------------------
-- Leave_Element --
-------------------
overriding procedure Leave_Element
(Self : not null access Style_Footnote_Sep_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.ODF_Visitor'Class then
ODF.DOM.Visitors.ODF_Visitor'Class
(Visitor).Leave_Style_Footnote_Sep
(ODF.DOM.Elements.Style.Footnote_Sep.Internals.Create
(Style_Footnote_Sep_Access (Self)),
Control);
else
Matreshka.DOM_Nodes.Elements.Abstract_Element
(Self.all).Leave_Element (Visitor, Control);
end if;
end Leave_Element;
-------------------
-- Visit_Element --
-------------------
overriding procedure Visit_Element
(Self : not null access Style_Footnote_Sep_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Iterator in ODF.DOM.Iterators.ODF_Iterator'Class then
ODF.DOM.Iterators.ODF_Iterator'Class
(Iterator).Visit_Style_Footnote_Sep
(Visitor,
ODF.DOM.Elements.Style.Footnote_Sep.Internals.Create
(Style_Footnote_Sep_Access (Self)),
Control);
else
Matreshka.DOM_Nodes.Elements.Abstract_Element
(Self.all).Visit_Element (Iterator, Visitor, Control);
end if;
end Visit_Element;
end Matreshka.ODF_Elements.Style.Footnote_Sep;
|
reznikmm/matreshka | Ada | 4,027 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.DOM.Table_Field_Number_Attributes;
package Matreshka.ODF_Table.Field_Number_Attributes is
type Table_Field_Number_Attribute_Node is
new Matreshka.ODF_Table.Abstract_Table_Attribute_Node
and ODF.DOM.Table_Field_Number_Attributes.ODF_Table_Field_Number_Attribute
with null record;
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Table_Field_Number_Attribute_Node;
overriding function Get_Local_Name
(Self : not null access constant Table_Field_Number_Attribute_Node)
return League.Strings.Universal_String;
end Matreshka.ODF_Table.Field_Number_Attributes;
|
BrickBot/Bound-T-H8-300 | Ada | 48,766 | ads | -- Calculator (decl)
--
-- A component of the Bound-T Worst-Case Execution Time Tool.
--
-------------------------------------------------------------------------------
-- Copyright (c) 1999 .. 2015 Tidorum Ltd
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice, this
-- list of conditions and the following disclaimer.
-- 2. Redistributions in binary form must reproduce the above copyright notice,
-- this list of conditions and the following disclaimer in the documentation
-- and/or other materials provided with the distribution.
--
-- This software is provided by the copyright holders and contributors "as is" and
-- any express or implied warranties, including, but not limited to, the implied
-- warranties of merchantability and fitness for a particular purpose are
-- disclaimed. In no event shall the copyright owner or contributors be liable for
-- any direct, indirect, incidental, special, exemplary, or consequential damages
-- (including, but not limited to, procurement of substitute goods or services;
-- loss of use, data, or profits; or business interruption) however caused and
-- on any theory of liability, whether in contract, strict liability, or tort
-- (including negligence or otherwise) arising in any way out of the use of this
-- software, even if advised of the possibility of such damage.
--
-- Other modules (files) of this software composition should contain their
-- own copyright statements, which may have different copyright and usage
-- conditions. The above conditions apply to this file.
-------------------------------------------------------------------------------
--
-- $Revision: 1.43 $
-- $Date: 2015/10/24 19:36:47 $
--
-- $Log: calculator.ads,v $
-- Revision 1.43 2015/10/24 19:36:47 niklas
-- Moved to free licence.
--
-- Revision 1.42 2013/12/22 20:14:56 niklas
-- Value enumerators obey Storage.Bounds.Opt.Max_Listed_Values and raise
-- Unbounded_Set or Storage.Bounds.Unbounded if more values are offered;
-- they do not return a truncated list.
--
-- Revision 1.41 2009-11-27 11:28:07 niklas
-- BT-CH-0184: Bit-widths, Word_T, failed modular analysis.
--
-- Revision 1.40 2009-10-07 19:26:10 niklas
-- BT-CH-0183: Cell-sets are a tagged-type class.
--
-- Revision 1.39 2009-01-18 08:03:18 niklas
-- Moved context clause to body.
--
-- Revision 1.38 2008/06/20 10:11:53 niklas
-- BT-CH-0132: Data pointers using Difference (Expr, Cell, Bounds).
--
-- Revision 1.37 2008/06/18 20:52:55 niklas
-- BT-CH-0130: Data pointers relative to initial-value cells.
--
-- Revision 1.36 2008/05/03 09:22:06 niklas
-- BT-CH-0126: Combining joint-counter and each-counter analysis.
--
-- Revision 1.35 2008/04/28 08:40:11 niklas
-- BT-CH-0125: Fix loop-until-equal analysis.
--
-- Revision 1.34 2008/04/26 19:19:44 niklas
-- BT-CH-0124: Joint loop counters and induction variables.
--
-- Revision 1.33 2008/04/22 12:51:27 niklas
-- Extended Pool_To_Steps to optionally find edges that have a null
-- (empty) data pool, and to mark those edges infeasible. Added the
-- nested procedures Mark_Infeasible and Check_Null_Flow.
--
-- Revision 1.32 2007/08/27 16:22:08 niklas
-- Added nicer Image for Pool_T.
--
-- Revision 1.31 2006/04/28 09:46:14 niklas
-- Added functions Values (Expr, Pool or Flux) to override the
-- inherited functions Values (Expr, Arithmetic.Bounds_T).
--
-- Revision 1.30 2005/10/20 19:34:01 niklas
-- BT-CH-0016.
--
-- Revision 1.29 2005/10/20 11:28:30 niklas
-- BT-CH-0015.
--
-- Revision 1.28 2005/09/17 14:42:06 niklas
-- BT-CH-0009.
--
-- Revision 1.27 2005/09/16 14:19:11 niklas
-- Added Calc_Image functions for Pool_T and Flux_T, for easier
-- cross-referencing to Omega files. Note that Flux_T already
-- inherits an Image function from Arithmetic.Bounds_T but this has
-- a different purpose.
--
-- Revision 1.26 2005/07/01 10:58:02 niklas
-- Changed the Interval functions for Flux_T to propagate
-- Flow.False_Path instead of Empty_Flux, since these functions
-- may be called through dynamic dispatch in contexts that are not
-- aware of the actual (derived) type of the bounds.
--
-- Revision 1.25 2005/02/16 21:11:41 niklas
-- BT-CH-0002.
--
-- Revision 1.24 2004/05/01 20:23:01 niklas
-- First Tidorum version.
-- Taking Cell_T stuff from Storage, not from Arithmetic. Removed "use" for
-- Arithmetic, added some "use type" for Storage types.
-- Added variant of Range_Bounded_Flux that takes the bounds from Range_Pre
-- assignment constraints.
-- Changed Constrain_Range and Restrict_Domain_Of_Cells to use the new
-- functions Adapted and Warp and the modified Apply function from
-- Calculator.Formulas, for simpler code and calculator expressions.
-- Corrected Propagate.Handle_Loop_Head to make variant cells unknown.
-- Changed Bounds_After_Step to use the new function Transformation from
-- Calculator.Formulas.
--
-- Revision 1.23 2001/01/19 08:50:20 saarinen
-- NC_041 Special handling of loop-exit edges.
-- NC_084 Flux_To_Steps review issues.
--
-- Revision 1.22 2001/01/13 11:10:37 holsti
-- Removed Limits_From_Flux in favour of Bounds_From_Flux (with
-- no "Inv" parameter, which was unused anyway).
-- Renamed Limits_From_Complement to Bounds_From_Complement (and
-- removed the unused "Inv" parameter).
-- Removed to-be's in favour of NC's.
--
-- Revision 1.21 2001/01/07 22:05:12 holsti
-- Comment parameter added to Start.
-- Comments on calculation steps added.
-- Parameters for live-cell analysis added.
-- Owner_Of operations added to support commenting.
--
-- Revision 1.20 2000/12/28 13:29:48 saarinen
-- Added function Limits_From_Complement.
--
-- Revision 1.19 2000/11/24 12:06:01 sihvo
-- Added stack height analysis.
--
-- Revision 1.18 2000/11/23 12:46:58 saarinen
-- Deleted Flux_To_Steps, Flux_Of_Region, Flux_To_Nodes.
-- Fixed joining of fluxes with different bases (NC_029).
--
-- Revision 1.17 2000/11/06 11:52:28 saarinen
-- Added exception Empty_Flux.
--
-- Revision 1.16 2000/10/06 14:02:09 saarinen
-- Added function Restrict_Domain_Of_Cells, and
-- commented out unused functions Flux_To_Steps and Flux_To_Nodes.
--
-- Revision 1.15 2000/09/20 18:58:56 saarinen
-- Modified Calc_Handle_T.
-- Fixed some problems with different Cell_Sets in some procedures.
-- Changed Flux_To_Step not to use transitive closure.
--
-- Revision 1.14 2000/08/17 13:00:54 holsti
-- Bounds_From_Flux for expression added.
--
-- Revision 1.13 2000/07/24 22:42:37 holsti
-- Flux_To_Steps over acyclic region added.
--
-- Revision 1.12 2000/07/17 21:00:11 holsti
-- Cell_Set_T instead of Cell_List_T for domains and ranges.
--
-- Revision 1.11 2000/07/16 18:42:33 holsti
-- Flux_To_Nodes uses loop-repeat fluxes as designed.
--
-- Revision 1.10 2000/07/16 13:10:56 holsti
-- Cells_Of (Flux) added.
--
-- Revision 1.9 2000/07/14 20:35:51 holsti
-- Using Arithmetic.Cell_List_Ref instead of own.
--
-- Revision 1.8 2000/07/12 20:46:01 holsti
-- Data-flow in regions uses only region edges.
--
-- Revision 1.7 2000/07/12 12:26:15 holsti
-- Calculator.Formulas added and used.
--
-- Revision 1.6 2000/06/16 10:42:03 saarinen
-- Added function Flux_To_Steps and removed Function Cells_In_Graph
--
-- Revision 1.5 2000/06/11 19:03:14 holsti
-- Arithmetic package separated from Calculator.
--
-- Revision 1.4 2000/06/02 08:38:31 saarinen
-- Added many local procedures and implemented some of the visible ones
--
-- Revision 1.3 2000/05/18 10:27:02 saarinen
-- Added expression and cell_set types
--
-- Revision 1.2 2000/05/12 11:06:37 saarinen
-- first implementations
--
with Arithmetic;
with Exec_Cmd;
with Flow;
with Flow.Life;
with Loops;
with Storage;
with Storage.Bounds;
with Storage.List_Cell_Sets;
package Calculator is
--
-- Data-flow analysis through calculation of data-flow relations,
-- invariants and data ranges.
--
-- Attempts to hide the choice of the calculation engine (e.g.
-- whether the Omega Calculator or the Omega Library is used, or
-- some quite different mechanism).
--
--
--- Calculator instances
--
type Calc_Handle_T is private;
--
-- An access to an instance of the calculation engine,
-- able to compute fluxes and other things.
--
-- In the present implementation, a calculator handle
-- refers to a child process running the Omega Calculator.
--
--- Cell sets, as used here
--
package Cell_Sets renames Storage.List_Cell_Sets;
--
-- The implementation of cell sets that we use.
subtype Cell_Set_T is Cell_Sets.Set_T;
--
-- A set of cells somehow involved with a calculation.
procedure Add (
Cells : in Storage.Cell_List_T;
To : in out Cell_Set_T)
renames Cell_Sets.Add;
function Intersection (Left, Right : Cell_Set_T)
return Storage.Cell_Set_T
renames Cell_Sets.Intersection;
function Copy (Item : Storage.Cell_Set_T) return Cell_Set_T
renames Cell_Sets.Copy;
function Image (Item : Cell_Set_T) return String
renames Cell_Sets.Image;
--
--- Common properties of data pools and data fluxes
--
type Bounds_T is abstract new Arithmetic.Bounds_T with private;
--
-- A root type for data pools and data fluxes.
-- overriding
function Basis (Item : Bounds_T) return Storage.Cell_List_T;
--
-- The cells that the Item bounds are just the cells of the pool
-- or the flux.
-- overriding
function Difference (To, From : Storage.Cell_T; Under : Bounds_T)
return Storage.Bounds.Interval_T;
--
-- The interval (range) of values of the difference To - From,
-- permitted Under the given bounds.
--
-- If both To and From are in the Basis of the bounds, the
-- default implementation uses Interval (Expr, Under) with
-- an expression that computes the difference To - From, and
-- redispatching on Under. Otherwise, that is if one or both
-- of the cells is not in the Basis, the default implementation
-- returns Universal_Interval.
-- overriding
function Difference (
To : Arithmetic.Expr_Ref;
From : Storage.Cell_T;
Under : Bounds_T)
return Storage.Bounds.Interval_T;
--
-- The interval (range) of values of the difference To - From,
-- permitted Under the given bounds.
--
-- If From is in the Basis of the bounds, the default implementation
-- uses Interval (Expr, Under) with an expression that computes the
-- difference To - From, and redispatching on Under. Otherwise, that
-- is if From is not in the Basis, the default implementation returns
-- Universal_Interval.
function Cells_Of (Item : Bounds_T) return Storage.Cell_Set_T;
--
-- The cells that form the basis of the pool or the flux.
function Owner_Of (Item : Bounds_T) return Calc_Handle_T;
--
-- The calculator in which the pool or the flux was calculated,
-- and which thus "owns" the pool or the flux.
--
--- Data pools
--
type Pool_T is new Bounds_T with private;
--
-- A reference to a constrained set of data-states, where
-- a data-state is the association of an integer value
-- with each cell in a set of cells (the basis of the pool).
-- The set is computed by a calculator and contains within
-- itself a calculator-handle and the basis-set of cells.
--
-- The possible data-states at a certain location in the
-- program (e.g. on entry to a loop) are often represented
-- as a pool.
--
-- The term "pool" is meant to suggest, firstly, that there
-- are many items (data states), but limited by a boundary
-- (the constraints as a "shoreline), secondly that the
-- set of data is (often) located at a specific point
-- in the subprogram), and thirdly that two pools can be
-- joined by a stream (a flux, see below) that transports
-- items from one pool to the other, perhaps with some
-- transformation on the way.
--
-- The pool type is derived from Arithmetic.Bounds_T since one of
-- the major roles of a pool object is to place bounds on the values
-- of arithmetic cells and expressions in the data-state.
--
-- The bounds in a pool may be contradictory which means that the
-- pool is "empty" (no data states). This usually means that the
-- program path or point to which the pool applies is unreachable
-- (infeasible).
--
-- In the present implementation, a pool contains the
-- identifier of the Omega Calculator variable that
-- contains the set of data-states.
-- overriding
function Image (Item : Pool_T) return String;
--
-- A brief identification of the pool.
-- overriding
function Interval (Cell : Storage.Cell_T; Under : Pool_T)
return Storage.Bounds.Interval_T;
--
-- The interval (range) of values of the Cell, permitted Under
-- the given pool.
--
-- Propagates Flow.False_Path if the pool is empty.
-- overriding
function Interval (Expr : Arithmetic.Expr_Ref; Under : Pool_T)
return Storage.Bounds.Interval_T;
--
-- The interval (range) of values of the Expr, permitted Under the
-- given pool. Note that the Expr does not necessarily take on
-- every value in this interval. The function does not propagate
-- Storage.Bounds.Unbounded but may return an interval where either
-- or both Min and Max are unlimited.
--
-- Propagates Flow.False_Path if the pool is empty.
-- overriding
function Values (Expr : Arithmetic.Expr_Ref; Under : Pool_T)
return Storage.Bounds.Value_List_T;
--
-- The list of possible values of the Expr, permitted Under the
-- given pool. This list contains all and only the possible
-- values of the Expr. If such a list cannot be derived from the
-- bounds, the function propagates Storage.Bounds.Unbounded.
--
-- The length of the returned list is bounded by
-- Storage.Bounds.Opt.Max_Listed_Values. If there are more
-- values, the function propagates Storage.Bounds.Unbounded.
function Calc_Image (Item : Pool_T) return String;
--
-- A readable description (as far as we can) of the pool,
-- possibly referring to some calculator-specific identifier.
type Pool_List_T is array (Positive range <>) of Pool_T;
--
-- A list of pools.
--
--- Data fluxes
--
type Flux_T is new Bounds_T with private;
--
-- A reference to a "data flux", or the relation between the
-- input-data-state and output-data-state of a program
-- region, computed by a calculator. It contains within itself
-- a calculator-handle and a set of cells (the basis of the
-- data state).
--
-- The term "flux" is intended to connote both "change", as
-- in "changes to variables", and "flow", as in "data-state
-- that flows from this region to its successors".
--
-- The flux type is derived from Arithmetic.Bounds_T since one of
-- the major roles of a flux object is to place bounds on the values
-- of arithmetic cells and expressions in the output-data-state.
--
-- The bounds in a flux may be contradictory which means that the
-- flux is "empty" (no data states). This usually means that the
-- program path or point to which the flux applies is unreachable
-- (infeasible).
--
-- In the present implementation, a flux contains the
-- identifier of the Omega Calculator variable that
-- contains the computed relation.
function Interval (Cell : Storage.Cell_T; Under : Flux_T)
return Storage.Bounds.Interval_T;
--
-- The interval (range) of values of the Cell, permitted Under
-- the given flux.
--
-- Propagates Flow.False_Path if the flux is empty.
--
-- Overrides Arithmetic.Interval.
function Interval (Expr : Arithmetic.Expr_Ref; Under : Flux_T)
return Storage.Bounds.Interval_T;
--
-- The interval (range) of values of the Expr, permitted Under the
-- given flux. Note that the Expr does not necessarily take on
-- every value in this interval. The function does not propagate
-- Storage.Bounds.Unbounded but may return an interval where either
-- or both Min and Max are unlimited.
--
-- Propagates Flow.False_Path if the flux is empty.
--
-- Overrides (implements) Arithmetic.Interval.
function Values (Expr : Arithmetic.Expr_Ref; Under : Flux_T)
return Storage.Bounds.Value_List_T;
--
-- The list of possible values of the Expr, permitted Under the range
-- of the given flux. This list contains all and only the possible
-- values of the Expr. If such a list cannot be derived from the
-- bounds, the function propagates Storage.Bounds.Unbounded.
--
-- The length of the returned list is bounded by
-- Storage.Bounds.Opt.Max_Listed_Values. If there are more
-- values, the function propagates Storage.Bounds.Unbounded.
--
-- Overrides Arithmetic.Values.
function Calc_Image (Item : Flux_T) return String;
--
-- A readable description (as far as we can) of the flux,
-- possibly referring to some calculator-specific identifier.
--
-- Note that this does *not* override the inherited Image function
-- from Arithmetic.Bounds_T.
type Flux_List_T is array (Positive range <>) of Flux_T;
--
-- A list of fluxes.
--
--- Loop summaries
--
type Loop_Summary_T is record
Repeat : Flux_T;
Variant : Cell_Set_T;
Invariant : Cell_Set_T;
end record;
--
-- A summary of the effect of a loop body.
--
-- Repeat
-- The flux on the repeat edges, from and including the loop-head
-- to and including the precondition of the repeat edges.
-- Variant
-- The set of cells that, as far as we know, can vary (change their
-- value) in an execution of the loop-body up to a repeat edge.
-- Invariant
-- The set of cells that are invariant in an execution of the
-- loop-body up to a repeat edge.
--
-- The Repeat flux shall include the effect of the loop-head node and
-- the paths within the loop to any repeat edge, including the
-- precondition on the repeat edge. If there are several repeat
-- edges, the Repeat flux shall express the union of their fluxes
-- computed in this way. Note that the Repeat flux shall _not_
-- include anything from the path _to_ the loop-head from outside
-- the loop.
--
-- The Variant and Invariant cells shall be disjoint and together
-- form the Cells_Of (Repeat).
type Loop_Summary_List_T is array (Positive range <>) of Loop_Summary_T;
--
-- A list of loop-body summaries, for some list of loops (known by
-- other means).
--
-- Exceptions
--
Calculator_Error : exception;
--
-- To be raised when some error occurs in the communication with a
-- calculator instance. This is usually due to a fault in the
-- emitted calculator formulae, or an error detected in the
-- calculator itself.
Null_Set_Error : exception;
--
-- To be raised when queries are made on an empty set (an empty
-- pool or flux). This is usually due to an unreachable (infeasible)
-- execution path, which may be intrinsic to the program under
-- analysis or made infeasible by assertions.
-- PROVIDED OPERATIONS:
function Start (Comment_Text : in String)
return Calc_Handle_T;
--
-- Starts a calculator instance.
--
-- Using : comment text, purely descriptive, may be empty.
-- Giving : calculator handle.
procedure Stop (Calc : in out Calc_Handle_T);
--
-- Stops a calculator instance.
--
-- Using : calculator-handle
-- Giving : updated (now invalid) calculator handle.
--
-- No pools or fluxes associated with this calculator
-- instance can be used after the calculator is stopped.
procedure Comment (
Text : in String;
Calc : in Calc_Handle_T);
--
-- Provides a textual comment or description of the calculation about to
-- be performed, or of the result(s) just calculated.
-- This has no effect on the calculation, but may help the user understand
-- problems and correct them.
function Bounded_Pool (
Cells : Cell_Set_T'Class;
Bounds : Storage.Bounds.Cell_Interval_List_T;
Calc : Calc_Handle_T)
return Pool_T;
--
-- The pool based on the given Cells and constrained with
-- the given Bounds.
--
-- The Cells parameter is class-wide to make only the result type
-- controlling.
function Bounded_Pool (
Pool : Pool_T;
Bounds : Storage.Bounds.Cell_Interval_List_T)
return Pool_T;
--
-- The given Pool, further constrained by the given Bounds on
-- cells in the pool.
--
-- If the Bounds list is empty or places no bounds on the cells
-- in the Pool, the Pool is returned unchanged.
function Bounded_Pool (
Pool : Pool_T;
Pre : Arithmetic.Effect_T)
return Pool_T;
--
-- The given Pool, further constrained by the all the Range_Pre
-- assignment constraints in Pre.
--
-- If there are no Range_Pre assignment constraints, the Pool
-- is returned unchanged. Note that all assignments of any other
-- type in Pre are ignored.
--
-- This function can be used for example in the following case:
-- Pool is the data-pool into a step and Pre is the effect of the step.
-- The Range_Pre constraints in Pre act to constrain the values
-- that are actually used in the step, so the Pool is first passed
-- through these constraints before the step is executed.
function Intersection (Left, Right : Pool_T) return Pool_T;
--
-- The intersection of the two Pools, which are assumed to have
-- the same set of cells (and exist in the same calculator instance).
function Complement (Pool : Pool_T) return Pool_T;
--
-- The complement set of the given Pool.
function Range_Bounded_Flux (
Flux : Flux_T;
Bounds : Storage.Bounds.Cell_Interval_List_T)
return Flux_T;
--
-- Using :
-- flux,
-- set of bounds on (some of) the basis cells
-- Giving:
-- the flux, range-constrained with the pool
-- defined by the given bounds.
--
-- If the Bounds list is empty or places no bounds on the cells
-- in the Flux, the Flux is returned unchanged.
function Range_Bounded_Flux (
Flux : Flux_T;
Pre : Arithmetic.Effect_T)
return Flux_T;
--
-- Using :
-- flux,
-- set of assignments where only the Range_Pre assignment
-- constraints are significant.
-- Giving:
-- the flux, range-constrained with the pool defined by
-- all the Range_Pre assignment constraints in Pre.
--
-- If there are no Range_Pre assignment constraints, the Flux
-- is returned unchanged. Note again that all assignments of
-- any other type in Pre are ignored.
--
-- This function can be used for example in the following case:
-- Flux is the flux into a step and Pre is the effect of the step.
-- The Range_Pre constraints in Pre act to constrain the values
-- that are actually used in the step, so the Flux is first passed
-- through these constraints before the step is executed.
function Identity_Flux (Pool : Pool_T'Class) return Flux_T;
--
-- Using :
-- pool
-- Giving:
-- a flux with the same basis-set of cells as
-- the pool, domain-constrained to the pool,
-- and implementing the identity mapping (no
-- change in cell values).
function Domain_Of (Flux : Flux_T'Class)
return Pool_T;
--
-- The domain pool of the given flux.
function Constrain_Range (
Flux : Flux_T;
Pool : Pool_T'Class)
return Flux_T;
--
-- Using :
-- flux,
-- pool
-- Giving:
-- the same flux, with the constraint that
-- the output-data-state is in the pool.
--
-- NOTE: The Flux and the Pool can have different cell_sets.
procedure Flux_To_Steps (
Nodes : in Flow.Node_List_T;
Edges : in Flow.Edge_List_T;
Living : in Flow.Life.Living_T;
Root : in Flux_T;
Luups : in Loops.Loop_List_T;
Summaries : in Loop_Summary_List_T;
Steps : in Flow.Step_List_T;
Into_Luups : out Flux_List_T;
Repeats : out Flux_List_T;
Into_Steps : out Flux_List_T;
Exit_Flux : out Flux_T);
--
-- Propages data-flow flux within an acyclic region of a flow-graph
-- to compute the flux into certain interesting steps within the region.
-- The region can contain collapsed loops with associated repeat-fluxes.
--
-- The interesting steps for which "into" fluxes are computed are the
-- loop-head steps and some explicitly listed Steps. Improved repeat-
-- fluxes are computed for the loops. The exit flux from the whole
-- region is also computed.
--
-- Nodes, Edges
-- Define the acyclic flow-graph region to be processed.
-- The set of nodes in the region is the union of the sources
-- and targets of the given Edges and the given Nodes. Thus, the
-- trivial case of a one-node region would have an empty Edges
-- list and the single node in the Nodes list. The Nodes parameter
-- has no other significance.
--
-- The data-flow computation for a given node in the region considers
-- only incoming and outgoing edges from the Edges set. Other edges
-- connected to this node may exist in the flow-graph that contains
-- the region, but are not included in the computation. Thus, the body
-- of a loop can be considered an acyclic region by leaving out the
-- repeat edges from the Edges set. Moreover, infeasible edges can
-- be left out.
--
-- Living
-- A computation model and live-assignment map for the flow-graph.
-- It defines the (live) effect of each step and the precondition
-- of each edge. The underlying flow-graph shows how many steps and
-- nodes must be handled which sets the size of some local data.
--
-- Root
-- The root-flux assumed to enter the region's root(s).
--
-- Luups
-- Loops to be considered in the calculation. This list should
-- contain exactly the collapsed loops within the region and must
-- be sorted in bottom-up nesting order (inner loop before outer).
--
-- Summaries
-- The summary effects of the Luups, for each loop giving the flux
-- on the repeat-edges and the set of loop-invariant cells, for
-- example as generated by Loops.Slim.Approximate_Loops.
--
-- The indexing equals that of the Luups list: the summary for
-- Luups(I) is Summaries(I).
--
-- Steps
-- Lists the "interesting" steps in the region, that is, those
-- for which we will compute the flux into the step. The same
-- step may occur several times in the list, but the flux will
-- anyway be computed once for each listed step.
--
-- Into_Luups
-- The flux into the loop-head steps of the Luups from outside
-- the loop, propagated along the region from the assumed Root flux
-- at the root nodes and including the transitive closure of the
-- collapsed loops but _excluding_ the repeat flux from the body
-- of this loop back to the loop-head. Thus, this flux shows the
-- initial values for the loop on entry to the loop.
--
-- The indexing equals that of the Luups list: the flux into the
-- head of Luups(L) is Into_Luups(L).
--
-- Repeats
-- An improved version of the repeat-flux for the Luups. This is
-- Summaries.Repeat but domain-constrained to a better model of the
-- data-pool at the start of the loop-head. Note that this repeat-
-- flux, unlike Summaries.Repeat, depends on the computation that
-- leads to the loop (Into_Luups).
--
-- The indexing equals that of the Luups list: the repeat-flux for
-- Luups(L) is Repeats(L).
--
-- Into_Steps
-- The flux into each of the given Steps, propagated along the
-- region from the assumed Root flux at the root nodes, including
-- the transitive closure of the collapsed loops.
--
-- The indexing equals that of the Steps list: the flux into Steps(I)
-- is Into_Steps(I).
--
-- If Steps(I) is a loop-head step, Into_Steps(I) contains the flux
-- from all edges to the step, including the repeat edges. Thus,
-- Into_Steps(I) is probably different from Into_Luups() for this
-- loop.
--
-- Exit_Flux
-- The flux that exits the region, which is the combined flux on
-- all edges from the region to outside the region.
--
-- The total data-flow into a loop-head is taken as the flow along the
-- entry edges (from outside the loop, computed in the normal way and
-- returned as Into_Luups), united with the flow along the repeat edges,
-- which is computed as Into_Luups . Z . Repeats where Z is a "fuzz"
-- relation that keeps loop-invariant cells unchanged and makes
-- loop-variant cells unknown (opaque).
--
-- All explorations of the flow-graph use only the given Edges. Thus,
-- to omit infeasible edges (and nodes) the Edges list should include
-- only feasible edges.
--
-- If some of the given steps do not belong to the region, a fault
-- message is emitted and Constraint_Error is raised.
--
-- Into_Luups and Repeats will contain only the fluxes for those Luups
-- where the loop-head is included in the region.
procedure Pool_To_Steps (
Nodes : in Flow.Node_List_T;
Edges : in Flow.Edge_List_T;
Living : in Flow.Life.Living_T;
Root : in Pool_T;
Luups : in Loops.Loop_List_T;
Summaries : in Loop_Summary_List_T;
Steps : in Flow.Step_List_T;
Into_Luups : out Pool_List_T;
Repeats : out Flux_List_T;
Into_Steps : out Pool_List_T;
Exit_Pool : out Pool_T);
--
-- Propages data-flow flux within an acyclic region of a flow-graph
-- to compute the data-pools into certain interesting steps within the
-- region. The region can contain collapsed loops with associated
-- repeat-fluxes.
--
-- The interesting steps for which "into" pools are computed are the
-- loop-head steps and some explicitly listed Steps. Improved repeat-
-- fluxes are computed for the loops. The exit pool from the whole
-- region is also computed.
--
-- Nodes, Edges
-- Define the acyclic flow-graph region to be processed.
-- The set of nodes in the region is the union of the sources
-- and targets of the given Edges and the given Nodes. Thus, the
-- trivial case of a one-node region would have an empty Edges
-- list and the single node in the Nodes list. The Nodes parameter
-- has no other significance.
--
-- The data-flow computation for a given node in the region considers
-- only incoming and outgoing edges from the Edges set. Other edges
-- connected to this node may exist in the flow-graph that contains
-- the region, but are not included in the computation. Thus, the body
-- of a loop can be considered an acyclic region by leaving out the
-- repeat edges from the Edges set. Moreover, infeasible edges can
-- be left out.
--
-- Living
-- A computation model and live-assignment map for the flow-graph.
-- It defines the (live) effect of each step and the precondition
-- of each edge. The underlying flow-graph shows how many steps and
-- nodes must be handled which sets the size of some local data.
-- If the data-flux propagation finds some empty pools, the
-- corresponding flow-graph elements are marked infeasible, and
-- the computation model is pruned. However, checking for null pools
-- is optional, per Calculator.Opt.Find_Null_Flow.
--
-- Root
-- The root-pool assumed to enter the region's root(s).
--
-- Luups
-- Loops to be considered in the calculation. This list should
-- contain exactly the collapsed loops within the region and must
-- be sorted in bottom-up nesting order (inner loop before outer).
--
-- Summaries
-- The summary effects of the Luups, for each loop giving the flux
-- on the repeat-edges and the set of loop-invariant cells, for
-- example as generated by Loops.Slim.Approximate_Loops.
--
-- The indexing equals that of the Luups list: the summary for
-- Luups(I) is Summaries(I).
--
-- Steps
-- Lists the "interesting" steps in the region, that is, those
-- for which we will compute the pool into the step. The same
-- step may occur several times in the list, but the pool will
-- anyway be computed once for each listed step.
--
-- Into_Luups
-- The pool into the loop-head steps of the Luups from outside
-- the loop, propagated along the region from the assumed Root pool
-- at the root nodes and including the transitive closure of the
-- collapsed loops but _excluding_ the repeat flux from the body
-- of this loop back to the loop-head. Thus, this pool shows the
-- initial values for the loop on entry to the loop.
--
-- The indexing equals that of the Luups list: the pool into the
-- head of Luups(L) is Into_Luups(L).
--
-- Repeats
-- An improved version of the repeat-flux for the Luups. This is
-- Summaries.Repeat but domain-constrained to a better model of the
-- data-pool at the start of the loop-head. Note that this repeat-
-- flux, unlike Summaries.Repeat, depends on the computation that
-- leads to the loop (Into_Luups).
--
-- The indexing equals that of the Luups list: the repeat-flux for
-- Luups(L) is Repeats(L).
--
-- Into_Steps
-- The pool into each of the given Steps, propagated along the
-- region from the assumed Root pool at the root nodes, including
-- the approximated transitive closure of the collapsed loops.
--
-- The indexing equals that of the Steps list: the pool into Steps(I)
-- is Into_Steps(I).
--
-- If Steps(I) is a loop-head step, Into_Steps(I) contains the data
-- from all edges to the step, including the repeat edges. Thus,
-- Into_Steps(I) is probably different from Into_Luups() for this
-- loop.
--
-- Exit_Pool
-- The pool that exits the region, which is the combined data-pool
-- on all edges from the region to outside the region.
--
-- The total data-flow into a loop-head is taken as the flow along the
-- entry edges (from outside the loop, computed in the normal way and
-- returned as Into_Luups), united with the flow along the repeat edges,
-- which is computed as Into_Luups . Z . Repeats where Z is a "fuzz"
-- relation that keeps loop-invariant cells unchanged and makes
-- loop-variant cells unknown (opaque).
--
-- All explorations of the flow-graph use only the given Edges. Thus,
-- to omit infeasible edges (and nodes) the Edges list should include
-- only feasible edges.
--
-- If some of the given steps do not belong to the region, a fault
-- message is emitted and Constraint_Error is raised.
--
-- Into_Luups and Repeats will contain only the pools for those Luups
-- where the loop-head is included in the region.
function Union (Fluxes : Flux_List_T) return Flux_T;
--
-- Using :
-- a set of fluxes (all from the same calculator)
-- Giving:
-- the united flux being the "union" of the given fluxes.
function Invariants_In_Flux (Flux : Flux_T)
return Storage.Cell_List_T;
--
-- The set of variables that the given Flux does not modify.
function Flux_To_Vary (
Basis : Cell_Set_T'Class;
Var : Cell_Set_T'Class;
Calc : Calc_Handle_T)
return Flux_T;
--
-- A flux, with the given Basis, that varies the Varying
-- variables in an undefined (hidden) manner and keeps
-- all other basis variables invariant.
--
-- The Basis and Var parameters are class-wide to make only
-- the result type controlling.
function Repeat_With_Induction (
Initial : Pool_T'Class;
Invariant : Cell_Set_T'Class;
Induction : Storage.Cell_List_T;
Step : Storage.Bounds.Interval_List_T;
Repeat : Flux_T'Class)
return Flux_T;
--
-- A flux that models the Repeat flux of a loop constrained by
-- the dependence of the values of Induction variables on their
-- Initial values, their Steps, and a joint (synthetic) counter
-- variable. We assume that the Repeat flux is the "improved"
-- repeat flux from Pool_To_Steps, with a domain constrained to
-- the full pool at the start of the loop body (including the
-- raw repeat flux from the repeat edges). The Invariant cells
-- are all the loop-invariant cells. No Induction cell shall
-- be an Invariant.
--
-- The domain space and range space of the Initial flux may be
-- larger than those of the Repeat flux. The Repeat flux concerns
-- only the cells involved in the loop, but includes all Induction
-- variables.
--
-- The resulting flux is the composition of two fluxes: the
-- induction model and the given Repeat flux. The composition
-- is then projected on the domain side to have only the joint
-- iteration counter in its domain.
--
-- The domain space of the induction-model flux is that of the
-- Repeat flux, extended with the joint iteration counter C.
-- The domain of the induction-model flux constrains the values
-- of the Induction variables to their Initial values.
--
-- The range space of the induction-model flux is the domain space
-- of the Repeat flux; the joint iteration counter is left out.
-- The range of the induction-model flux constrains each Induction
-- variable to its Initial value (from the domain) plus C times
-- its Step. Tthe other non-Invariant variables are unconstrained.
--
-- The domain of the resulting flux contains those values of
-- the joint iteration counter, at the start of the loop body,
-- that allow the loop to repeat. If the domain is empty, the
-- loop is unrepeatable. If the domain has an upper bound M,
-- M+1 is an upper bound on loop repetitions.
--
-- Note that the resulting flux is unusual in that its domain has
-- no cells, only the iteration counter.
--
-- The Invariant parameter is class-wide to make only the
-- return type controlling.
function Is_In (Value : Arithmetic.Value_T; Pool : Pool_T)
return Boolean;
--
-- Whether the given Value is in the given one-dimensional Pool.
function Smallest_Value (
Pool : Pool_T;
Min : Arithmetic.Value_T)
return Arithmetic.Value_T;
--
-- The smallest value in the given one-dimensional Pool, no less
-- than Min. Propagates Null_Set_Error if such a value cannot be found
-- (perhaps because it is larger than Opt.Max_Int_Calc).
function Largest_Value (
Pool : Pool_T;
Max : Arithmetic.Value_T)
return Arithmetic.Value_T;
--
-- The largest value in the given one-dimensional Pool, no greater
-- than Max. Propagates Null_Set_Error if such a value cannot be found
-- (perhaps because it is less than Opt.Min_Int_Calc).
function Smallest_Hole (
Pool : Pool_T;
Min : Arithmetic.Value_T)
return Arithmetic.Value_T;
--
-- The smallest value that is not in the given one-dimensional Pool,
-- and is no less than Min. Propagates Null_Set_Error if such a value
-- cannot be found (perhaps because it is larger than Opt.Max_Int_Calc).
--
-- This should be the same as Smallest_Value (Complement (Pool), Min).
-- However, this operation always uses a binary-search method, not
-- a method based on hull/convexhull.
function Largest_Hole (
Pool : Pool_T;
Max : Arithmetic.Value_T)
return Arithmetic.Value_T;
--
-- The largest value that is not in the given one-dimensional Pool,
-- and is no greater than Max. Propagates Null_Set_Error if such a value
-- cannot be found (perhaps because it is less than Opt.Min_Int_Calc).
--
-- This should be the same as Largest_Value (Complement (Pool), Max).
-- However, this operation always uses a binary-search method, not
-- a method based on hull/convexhull.
function Bounds_Of (Pool : Pool_T)
return Storage.Bounds.Interval_T;
--
-- The bounds, if any, on the values in the given one-dimensional Pool.
--
-- Raises exception Null_Set_Error if the Pool is empty.
function Bounds_Of_Complement (
Pool : Pool_T;
Within : Storage.Bounds.Interval_T)
return Storage.Bounds.Interval_T;
--
-- The bounds, if any, on the complement of the given one-dimensional
-- Pool, including only the values Within the given interval.
--
-- Raises exception Null_Set_Error if the complement of the Pool
-- has no elements Within the desired interval.
function Bounds_Of_Domain (Flux : Flux_T)
return Storage.Bounds.Interval_T;
--
-- The bounds, if any, on the domain of the Flux, which is
-- assumed to be one-dimensional (possibly containing only
-- a synthetic variable, not necessarily a cell).
--
-- Raises exception Null_Set_Error if the Flux is empty (infeasible).
function Is_In_Domain (Value : Arithmetic.Value_T; Flux : Flux_T)
return Boolean;
--
-- Whether the given Value is a member of the one-dimensional
-- domain of the given Flux.
function Bounds_From_Pool (
Pool : Pool_T;
Cell : Storage.Cell_T)
return Storage.Bounds.Interval_T;
--
-- Using :
-- a pool,
-- a cell which is in the basis of the pool.
-- Giving:
-- the range of the variable cell, implied by the pool, with a
-- lower-bound and upper-bound of known (literal) value,
-- or "unlimited".
--
-- Raises exception Null_Set_Error if Pool is empty (unreachable).
function Bounds_From_Pool (
Pool : Pool_T;
Expr : Arithmetic.Expr_Ref)
return Storage.Bounds.Interval_T;
--
-- Using :
-- a pool,
-- an expression of cells in the pool
-- Giving:
-- the range of the expression, implied by the pool, with a
-- lower-bound and upper-bound of known (literal) value,
-- or "unlimited".
--
-- Raises exception Null_Set_Error if Pool is empty (unreachable).
function Bounds_From_Flux (
Flux : Flux_T;
Cell : Storage.Cell_T)
return Storage.Bounds.Interval_T;
--
-- Using :
-- a flux,
-- a cell which is a variable in the flux
-- Giving:
-- the range of the variable cell, implied by the flux, with a
-- lower-bound and upper-bound of known (literal) value,
-- or "unlimited".
--
-- Raises exception Null_Set_Error if Flux is empty (unreachable).
function Bounds_From_Complement (
Flux : Flux_T;
Cell : Storage.Cell_T)
return Storage.Bounds.Interval_T;
--
-- Using :
-- a flux,
-- a cell which is a variable in the flux
-- Giving:
-- limits (lower bound and upper bound) for the variable cell,
-- implied by the complement of the flux.
--
-- Raises exception Null_Set_Error if the complemenet of the
-- Flux is empty (unreachable).
function Bounds_From_Flux (
Flux : Flux_T;
Expr : Arithmetic.Expr_Ref)
return Storage.Bounds.Interval_T;
--
-- Using :
-- a flux,
-- an expression of cells in the flux
-- Giving:
-- the range of the expression, implied by the flux, with a
-- lower-bound and upper-bound of known (literal) value,
-- or "unlimited".
--
-- Raises exception Null_Set_Error if Flux is empty (unreachable).
function Is_In_Range (
Value : Arithmetic.Value_T;
Flux : Flux_T;
Cell : Storage.Cell_T)
return Boolean;
--
-- Whether the given Cell can have the given Value, in the
-- range of the given Flux.
function Step_From_Flux (
Flux : Flux_T;
Cell : Storage.Cell_T)
return Storage.Bounds.Interval_T;
--
-- Using :
-- a flux,
-- a cell which is a variable in the flux
-- Giving:
-- the range of the change in the value of the cell, caused
-- by the flux, with a lower-bound and upper-bound of known
-- literal) value, or "unlimited".
--
-- Raises exception Null_Set_Error if Flux is empty (unreachable).
function Pool_After_Effect (
Pool : Pool_T;
Effect : Arithmetic.Effect_T)
return Pool_T;
--
-- The pool that result from a given Pool after mapping (transforming)
-- the Pool with an Effect. For example, if Pool is the data-pool into
-- a step, and Effect is the effect of the step, then the result is the
-- data-pool out from the step.
function Flux_After_Effect (
Flux : Flux_T;
Effect : Arithmetic.Effect_T)
return Flux_T;
--
-- The flux that result from a given Flux joined (on the Range side)
-- to an Effect that transforms the data state. For example, if
-- Flux is the flux into a step, and Effect is the effect of the
-- step, then the result is the flux out from the step.
function Bounds_After_Step (
Into_Step : Pool_T;
Effect : Arithmetic.Effect_T;
Cell : Storage.Cell_T)
return Storage.Bounds.Interval_T;
--
-- The bounds (interval), if any, on the given Cell, implied by the
-- data-pool that results when the given Effect is applied to the
-- given Into_Step data-pool.
function Bounds_After_Step (
Into_Step : Flux_T;
Effect : Arithmetic.Effect_T;
Cell : Storage.Cell_T)
return Storage.Bounds.Interval_T;
--
-- Using :
-- a flux into a step,
-- the effect of the step,
-- a cell which is a variable in the flux
-- Giving:
-- lower bound and upper bound, or "unlimited", for the value
-- of the cell caused by the flux and the execution of the step.
--
-- Raises exception Null_Set_Error if Flux is empty (unreachable).
function Values_In_Domain (
Flux : Flux_T'Class;
Cell : Storage.Cell_T)
return Pool_T;
--
-- The pool of Cell values in the domain of the Flux.
function Value_Pool (
Flux : Flux_T'Class;
Expr : Arithmetic.Expr_Ref;
Var : Storage.Cell_T)
return Pool_T;
--
-- The pool of values of the Expr, in the range of the Flux, using
-- Var cell to represent the value of the Expr in the pool. In
-- other words, the basis of the pool is {Var}. The Var cell can
-- occur in the expression, but this has no effect on the result,
-- where Var is used only as a place-holder.
function Values (Within : Pool_T) return Storage.Bounds.Value_List_T;
--
-- The list of all values Within a given one-dimensional pool.
--
-- The length of the returned list is bounded by
-- Storage.Bounds.Opt.Max_Listed_Values. If there are more
-- values, or if the pool is not bounded, the function propagates
-- Storage.Bounds.Unbounded.
private
type Calc_Id_T is new Positive;
--
-- A unique sequential number to identify a calculator instance.
type Pool_Id_T is new Positive;
--
-- A unique sequential number to identify a pool
-- (within a calculator).
type Flux_Id_T is new Positive;
--
-- A unique sequential number to identify a flux
-- (within a calculator).
type Calc_Object_T is record
Exec : Exec_Cmd.Execution_T;
Calc_ID : Calc_Id_T;
Next_Pool_Id : Pool_Id_T := 1;
-- The next pool identifier to be used by New_Pool.
Next_Flux_Id : Flux_Id_T := 1;
-- The next flux identifier to be used by New_Flux.
end record;
type Calc_Handle_T is access Calc_Object_T;
--
-- By using an access type, we can use functions with
-- Calc_Handle parameters, yet update the calculator status
-- accessible to all users of that calculator.
type Bounds_T is new Arithmetic.Bounds_T with record
Cells : Cell_Set_T;
Calc : Calc_Handle_T;
end record;
type Pool_T is new Bounds_T with record
Id : Pool_Id_T;
end record;
type Flux_T is new Bounds_T with record
Id : Flux_Id_T;
end record;
end Calculator;
|
AdaDoom3/oto | Ada | 4,613 | ads | ------------------------------------------------------------------------------
-- EMAIL: <[email protected]> --
-- License: ISC --
-- --
-- Copyright © 2014 - 2015 darkestkhan --
------------------------------------------------------------------------------
-- Permission to use, copy, modify, and/or distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- The software is provided "as is" and the author disclaims all warranties --
-- with regard to this software including all implied warranties of --
-- merchantability and fitness. In no event shall the author be liable for --
-- any special, direct, indirect, or consequential damages or any damages --
-- whatsoever resulting from loss of use, data or profits, whether in an --
-- action of contract, negligence or other tortious action, arising out of --
-- or in connection with the use or performance of this software. --
------------------------------------------------------------------------------
--------------------------------------------------------------------------
-- This package is based on Lumen.Binary package from Lumen library. --
--------------------------------------------------------------------------
package Oto.Binary is
--------------------------------------------------------------------------
pragma Pure;
--------------------------------------------------------------------------
-----------------------
-- C O N S T A N T S --
-----------------------
--------------------------------------------------------------------------
-- Basic sizes of fundamental binary data types.
Byte_Bits : constant := 8;
Short_Bits: constant := 16;
Word_Bits : constant := 32;
Long_Bits : constant := 64;
--------------------------------------------------------------------------
-- Derived sizes.
Short_Bytes: constant := Short_Bits / Byte_Bits;
Word_Bytes : constant := Word_Bits / Byte_Bits;
Long_Bytes : constant := Long_Bits / Byte_Bits;
--------------------------------------------------------------------------
-- "Last-bit" values for use in rep clauses.
Byte_LB : constant := Byte_Bits - 1;
Short_LB: constant := Short_Bits - 1;
Word_LB : constant := Word_Bits - 1;
Long_LB : constant := Long_Bits - 1;
--------------------------------------------------------------------------
---------------
-- T Y P E S --
---------------
--------------------------------------------------------------------------
-- Unsigned types.
type Byte is mod 2 ** Byte_Bits;
type Short is mod 2 ** Short_Bits;
type Word is mod 2 ** Word_Bits;
type Long is mod 2 ** Long_Bits;
for Byte'Size use Byte_Bits;
for Short'Size use Short_Bits;
for Word'Size use Word_Bits;
for Long'Size use Long_Bits;
--------------------------------------------------------------------------
-- Signed types.
type S_Byte is new Integer range -(2 ** Byte_LB) .. (2 ** Byte_LB) - 1;
type S_Short is new Integer range -(2 ** Short_LB) .. (2 ** Short_LB) - 1;
type S_Word is new Integer range -(2 ** Word_LB) .. (2 ** Word_LB) - 1;
type S_Long is new Long_Integer range -(2 ** Long_LB) .. (2 ** Long_LB) - 1;
for S_Byte'Size use Byte_Bits;
for S_Short'Size use Short_Bits;
for S_Word'Size use Word_Bits;
for S_Long'Size use Long_Bits;
--------------------------------------------------------------------------
-- Array types.
type Byte_Array is array (Natural range <>) of Byte;
type Short_Array is array (Natural range <>) of Short;
type Word_Array is array (Natural range <>) of Word;
type Long_Array is array (Natural range <>) of Long;
type S_Byte_Array is array (Natural range <>) of S_Byte;
type S_Short_Array is array (Natural range <>) of S_Short;
type S_Word_Array is array (Natural range <>) of S_Word;
type S_Long_Array is array (Natural range <>) of S_Long;
---------------------------------------------------------------------------
end Oto.Binary;
|
onox/orka | Ada | 1,610 | adb | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2013 Felix Krause <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with GL.API;
package body GL.Errors is
procedure Raise_Exception_On_OpenGL_Error is
begin
case API.Get_Error.Ref.all is
when Errors.Invalid_Operation => raise Errors.Invalid_Operation_Error;
when Errors.Invalid_Value => raise Errors.Invalid_Value_Error;
when Errors.Invalid_Framebuffer_Operation =>
raise Errors.Invalid_Framebuffer_Operation_Error;
when Errors.Out_Of_Memory => raise Errors.Out_Of_Memory_Error;
when Errors.Stack_Overflow => raise Errors.Stack_Overflow_Error;
when Errors.Stack_Underflow => raise Errors.Stack_Underflow_Error;
when Errors.Invalid_Enum => raise Errors.Internal_Error;
when Errors.Context_Lost => raise Errors.Context_Lost_Error;
when Errors.No_Error => null;
end case;
exception
when Constraint_Error => raise Errors.Internal_Error;
end Raise_Exception_On_OpenGL_Error;
end GL.Errors;
|
AdaCore/langkit | Ada | 663 | adb | with Langkit_Support.Cheap_Sets;
procedure Main is
package Int_Sets is new Langkit_Support.Cheap_Sets
(Integer, No_Element => -1);
Int_Set : Int_Sets.Set;
use Int_Sets;
begin
pragma Assert (Add (Int_Set, 2));
pragma Assert (Remove (Int_Set, 2));
pragma Assert (Add (Int_Set, 3));
pragma Assert (Add (Int_Set, 7));
pragma Assert (Add (Int_Set, 9));
pragma Assert (Add (Int_Set, 12));
pragma Assert (Has (Int_Set, 2) = False);
pragma Assert (Remove (Int_Set, 22) = False);
pragma Assert (Add (Int_Set, 22));
pragma Assert (Has (Int_Set, 22));
pragma Assert (Remove (Int_Set, 22));
Destroy (Int_Set);
end Main;
|
reznikmm/matreshka | Ada | 4,688 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Table.Link_To_Source_Data_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Table_Link_To_Source_Data_Attribute_Node is
begin
return Self : Table_Link_To_Source_Data_Attribute_Node do
Matreshka.ODF_Table.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Table_Prefix);
end return;
end Create;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Table_Link_To_Source_Data_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Link_To_Source_Data_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Table_URI,
Matreshka.ODF_String_Constants.Link_To_Source_Data_Attribute,
Table_Link_To_Source_Data_Attribute_Node'Tag);
end Matreshka.ODF_Table.Link_To_Source_Data_Attributes;
|
stcarrez/ada-asf | Ada | 12,763 | ads | -----------------------------------------------------------------------
-- asf-views-nodes -- Facelet node tree representation
-- Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2018, 2022 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
-- The <b>ASF.Views.Nodes</b> package defines the nodes and attributes
-- the represent the facelet node tree used to create the component tree.
--
-- The facelet node tree is composed of nodes represented by <b>Tag_Node</b>
-- and attributes represented by <b>Tag_Attribute</b>. In a sense, this
-- is very close to an XML DOM tree.
with Ada.Strings.Unbounded;
with EL.Expressions;
with EL.Objects;
with Util.Strings;
with ASF.Components.Base;
with ASF.Contexts.Faces;
with ASF.Contexts.Facelets;
package ASF.Views.Nodes is
use Ada.Strings.Unbounded;
use ASF.Components.Base;
use ASF.Contexts.Faces;
use ASF.Contexts.Facelets;
type Expression_Access_Array is array (Natural range <>) of EL.Expressions.Expression_Access;
type Expression_Access_Array_Access is access Expression_Access_Array;
-- ------------------------------
-- Attribute of a node.
-- ------------------------------
-- The attribute has a name and a value. When the value is not
-- a literal, an EL expression is created to allow its evaluation.
type Tag_Attribute is limited private;
type Tag_Attribute_Access is access all Tag_Attribute;
type Tag_Attribute_Array is array (Natural range <>) of aliased Tag_Attribute;
type Tag_Attribute_Array_Access is access Tag_Attribute_Array;
function "=" (Left : in Tag_Attribute; Right : in String) return Boolean;
function "=" (Left, Right : in Tag_Attribute) return Boolean;
-- Get the attribute name.
function Get_Name (Attribute : Tag_Attribute) return String;
-- Returns True if the attribute is static (not an EL expression).
function Is_Static (Attribute : Tag_Attribute) return Boolean;
-- Get the attribute value. If the attribute is an EL expression
-- evaluate that expression in the context of the given UI component.
function Get_Value (Attribute : Tag_Attribute;
UI : UIComponent'Class) return EL.Objects.Object;
function Get_Value (Attribute : Tag_Attribute;
Context : Faces_Context'Class) return EL.Objects.Object;
function Get_Value (Attribute : Tag_Attribute;
Context : Facelet_Context'Class) return EL.Objects.Object;
-- Get the value from the attribute. If the attribute is null or evaluates to
-- a NULL object, returns the default value. Convert the value into a string.
function Get_Value (Attribute : in Tag_Attribute_Access;
Context : in Facelet_Context'Class;
Default : in String) return String;
-- Get the EL expression associated with the given tag attribute.
function Get_Expression (Attribute : in Tag_Attribute)
return EL.Expressions.Expression;
function Get_Value_Expression (Attribute : Tag_Attribute)
return EL.Expressions.Value_Expression;
function Get_Method_Expression (Attribute : Tag_Attribute)
return EL.Expressions.Method_Expression;
-- Reduce the expression by eliminating known variables and computing
-- constant expressions. The result expression is either another
-- expression or a computed constant value.
function Reduce_Expression (Attribute : Tag_Attribute;
Context : Facelet_Context'Class)
return EL.Expressions.Expression;
-- Find the tag attribute having the given name.
-- Returns an access to the attribute cell within the array or null
-- if the no attribute matches the name.
function Find_Attribute (Attributes : Tag_Attribute_Array_Access;
Name : String) return Tag_Attribute_Access;
-- Report an error message for the attribute.
procedure Error (Attribute : in Tag_Attribute;
Message : in String;
Param1 : in String;
Param2 : in String := "");
-- ------------------------------
-- XHTML node
-- ------------------------------
-- The <b>Tag_Node</b> represents a UI component node in a view.
type Tag_Node is tagged limited private;
type Tag_Node_Access is access all Tag_Node'Class;
-- Get the node attribute with the given name.
-- Returns null if the node does not have such attribute.
function Get_Attribute (Node : Tag_Node;
Name : String) return Tag_Attribute_Access;
-- Get the line information where the tag node is defined.
function Get_Line_Info (Node : Tag_Node) return Line_Info;
-- Get the line information as a string.
function Get_Line_Info (Node : Tag_Node) return String;
-- Get the relative path name of the XHTML file in which this tag is defined.
function Get_File_Name (Node : in Tag_Node) return String;
-- Append a child tag node.
procedure Append_Tag (Node : in Tag_Node_Access;
Child : in Tag_Node_Access);
-- Freeze the tag node tree and perform any initialization steps
-- necessary to build the components efficiently. After this call
-- the tag node tree should not be modified and it represents a read-only
-- tree.
procedure Freeze (Node : access Tag_Node);
-- Build the component attributes from the facelet tag node and the facelet context.
procedure Build_Attributes (UI : in out UIComponent'Class;
Node : in Tag_Node'Class;
Context : in out Facelet_Context'Class);
-- Build the component tree from the tag node and attach it as
-- the last child of the given parent. Calls recursively the
-- method to create children.
procedure Build_Components (Node : access Tag_Node;
Parent : in UIComponent_Access;
Context : in out Facelet_Context'Class);
-- Build the component tree from the tag node and attach it as
-- the last child of the given parent. Calls recursively the
-- method to create children.
procedure Build_Children (Node : access Tag_Node;
Parent : in UIComponent_Access;
Context : in out Facelet_Context'Class);
-- Delete the node and its children freeing the memory as necessary
procedure Delete (Node : access Tag_Node);
procedure Destroy (Node : in out Tag_Node_Access);
-- Report an error message
procedure Error (Node : in Tag_Node'Class;
Message : in String;
Param1 : in String := "";
Param2 : in String := "");
-- Iterate over the attributes defined on the node and
-- execute the <b>Process</b> procedure.
generic
with procedure Process (Attr : in Tag_Attribute_Access);
procedure Iterate_Attributes (Node : in Tag_Node'Class);
-- ------------------------------
-- Text nodes mixed with EL expressions.
-- ------------------------------
-- The text node is used when the XHTML reader does not recognize an entity.
-- The reader appends the content to a text node until an entity is recognized.
-- The text node can contain attributes associated with the unrecognize entities.
-- Attributes and raw text may contain EL expressions that will be evaluated
-- when the component is rendered. The <b>Text_Tag_Node</b> contains a list
-- of raw text and EL expression to evaluate.
type Text_Tag_Node is new Tag_Node with private;
type Text_Tag_Node_Access is access all Text_Tag_Node;
-- Encode the content represented by this text node.
-- The expressions are evaluated if necessary.
procedure Encode_All (Node : in Text_Tag_Node;
Expr : in Expression_Access_Array_Access;
Context : in Faces_Context'Class);
overriding
procedure Build_Components (Node : access Text_Tag_Node;
Parent : in UIComponent_Access;
Context : in out Facelet_Context'Class);
-- Freeze the tag node tree.
-- Count the number of Tag_Content represented by this node.
overriding
procedure Freeze (Node : access Text_Tag_Node);
-- Delete the node and its children freeing the memory as necessary
overriding
procedure Delete (Node : access Text_Tag_Node);
type Cursor is private;
function First (Node : in Tag_Node_Access) return Cursor;
function Has_Element (C : Cursor) return Boolean;
function Element (Position : Cursor) return Tag_Node_Access;
procedure Next (Position : in out Cursor);
type Binding_Type;
type Binding_Access is access constant Binding_Type;
-- Create function to build a UIComponent
type Create_Access is access function return ASF.Components.Base.UIComponent_Access;
-- Create function to build a tag node
type Tag_Node_Create_Access is access
function (Binding : in Binding_Type;
Line : in Line_Info;
Parent : in Tag_Node_Access;
Attributes : in Tag_Attribute_Array_Access) return Tag_Node_Access;
-- Create the When Tag
function Create_Component_Node (Binding : in Binding_Type;
Line : in Line_Info;
Parent : in Tag_Node_Access;
Attributes : in Tag_Attribute_Array_Access)
return Tag_Node_Access;
-- Binding name
type Name_Access is new Util.Strings.Name_Access;
-- ------------------------------
-- Binding definition.
-- ------------------------------
-- The binding links an XHTML entity name to a tag node implementation
-- and a component creation handler. When the XHTML entity is found,
-- the associated binding is searched and when found the node is created
-- by using the <b>Tag</b> create function.
type Binding_Type is record
Name : Name_Access;
Component : ASF.Views.Nodes.Create_Access;
Tag : ASF.Views.Nodes.Tag_Node_Create_Access;
end record;
Null_Binding : constant Binding_Type := Binding_Type '(null, null, null);
private
type Cursor is record
Node : Tag_Node_Access;
end record;
type Tag_Attribute is record
Tag : Tag_Node_Access;
Binding : EL.Expressions.Expression_Access;
Name : Unbounded_String;
Value : Unbounded_String;
end record;
type Tag_Node is tagged limited record
-- The parent node.
Parent : Tag_Node_Access;
-- Attributes associated with this node.
Attributes : Tag_Attribute_Array_Access;
-- The UIComponent factory that must be used to create the component.
Factory : Create_Access;
Next : Tag_Node_Access;
First_Child : Tag_Node_Access;
Last_Child : Tag_Node_Access;
-- Source line information where the tag node is defined (for error messages)
Line : Line_Info;
end record;
-- Initialize the node
procedure Initialize (Node : in Tag_Node_Access;
Binding : in Binding_Type;
Line : in Line_Info;
Parent : in Tag_Node_Access;
Attributes : in Tag_Attribute_Array_Access);
type Tag_Content;
type Tag_Content_Access is access all Tag_Content;
type Tag_Content is record
Next : Tag_Content_Access := null;
Text : Unbounded_String;
Expr : EL.Expressions.Expression;
end record;
type Text_Tag_Node is new Tag_Node with record
Count : Natural := 0;
Last : Tag_Content_Access := null;
Content : aliased Tag_Content;
end record;
end ASF.Views.Nodes;
|
micahwelf/FLTK-Ada | Ada | 5,943 | adb |
with
Interfaces.C.Strings,
System;
use type
System.Address;
package body FLTK.Widgets.Valuators.Sliders.Value is
procedure value_slider_set_draw_hook
(W, D : in System.Address);
pragma Import (C, value_slider_set_draw_hook, "value_slider_set_draw_hook");
pragma Inline (value_slider_set_draw_hook);
procedure value_slider_set_handle_hook
(W, H : in System.Address);
pragma Import (C, value_slider_set_handle_hook, "value_slider_set_handle_hook");
pragma Inline (value_slider_set_handle_hook);
function new_fl_value_slider
(X, Y, W, H : in Interfaces.C.int;
Text : in Interfaces.C.char_array)
return System.Address;
pragma Import (C, new_fl_value_slider, "new_fl_value_slider");
pragma Inline (new_fl_value_slider);
procedure free_fl_value_slider
(D : in System.Address);
pragma Import (C, free_fl_value_slider, "free_fl_value_slider");
pragma Inline (free_fl_value_slider);
function fl_value_slider_get_textcolor
(S : in System.Address)
return Interfaces.C.unsigned;
pragma Import (C, fl_value_slider_get_textcolor, "fl_value_slider_get_textcolor");
pragma Inline (fl_value_slider_get_textcolor);
procedure fl_value_slider_set_textcolor
(S : in System.Address;
C : in Interfaces.C.unsigned);
pragma Import (C, fl_value_slider_set_textcolor, "fl_value_slider_set_textcolor");
pragma Inline (fl_value_slider_set_textcolor);
function fl_value_slider_get_textfont
(S : in System.Address)
return Interfaces.C.int;
pragma Import (C, fl_value_slider_get_textfont, "fl_value_slider_get_textfont");
pragma Inline (fl_value_slider_get_textfont);
procedure fl_value_slider_set_textfont
(S : in System.Address;
F : in Interfaces.C.int);
pragma Import (C, fl_value_slider_set_textfont, "fl_value_slider_set_textfont");
pragma Inline (fl_value_slider_set_textfont);
function fl_value_slider_get_textsize
(S : in System.Address)
return Interfaces.C.int;
pragma Import (C, fl_value_slider_get_textsize, "fl_value_slider_get_textsize");
pragma Inline (fl_value_slider_get_textsize);
procedure fl_value_slider_set_textsize
(S : in System.Address;
F : in Interfaces.C.int);
pragma Import (C, fl_value_slider_set_textsize, "fl_value_slider_set_textsize");
pragma Inline (fl_value_slider_set_textsize);
procedure fl_value_slider_draw
(W : in System.Address);
pragma Import (C, fl_value_slider_draw, "fl_value_slider_draw");
pragma Inline (fl_value_slider_draw);
function fl_value_slider_handle
(W : in System.Address;
E : in Interfaces.C.int)
return Interfaces.C.int;
pragma Import (C, fl_value_slider_handle, "fl_value_slider_handle");
pragma Inline (fl_value_slider_handle);
procedure Finalize
(This : in out Value_Slider) is
begin
if This.Void_Ptr /= System.Null_Address and then
This in Value_Slider'Class
then
free_fl_value_slider (This.Void_Ptr);
This.Void_Ptr := System.Null_Address;
end if;
Finalize (Slider (This));
end Finalize;
package body Forge is
function Create
(X, Y, W, H : in Integer;
Text : in String)
return Value_Slider is
begin
return This : Value_Slider do
This.Void_Ptr := new_fl_value_slider
(Interfaces.C.int (X),
Interfaces.C.int (Y),
Interfaces.C.int (W),
Interfaces.C.int (H),
Interfaces.C.To_C (Text));
fl_widget_set_user_data
(This.Void_Ptr,
Widget_Convert.To_Address (This'Unchecked_Access));
value_slider_set_draw_hook (This.Void_Ptr, Draw_Hook'Address);
value_slider_set_handle_hook (This.Void_Ptr, Handle_Hook'Address);
end return;
end Create;
end Forge;
function Get_Text_Color
(This : in Value_Slider)
return Color is
begin
return Color (fl_value_slider_get_textcolor (This.Void_Ptr));
end Get_Text_Color;
procedure Set_Text_Color
(This : in out Value_Slider;
To : in Color) is
begin
fl_value_slider_set_textcolor (This.Void_Ptr, Interfaces.C.unsigned (To));
end Set_Text_Color;
function Get_Text_Font
(This : in Value_Slider)
return Font_Kind is
begin
return Font_Kind'Val (fl_value_slider_get_textfont (This.Void_Ptr));
end Get_Text_Font;
procedure Set_Text_Font
(This : in out Value_Slider;
To : in Font_Kind) is
begin
fl_value_slider_set_textfont (This.Void_Ptr, Font_Kind'Pos (To));
end Set_Text_Font;
function Get_Text_Size
(This : in Value_Slider)
return Font_Size is
begin
return Font_Size (fl_value_slider_get_textsize (This.Void_Ptr));
end Get_Text_Size;
procedure Set_Text_Size
(This : in out Value_Slider;
To : in Font_Size) is
begin
fl_value_slider_set_textsize (This.Void_Ptr, Interfaces.C.int (To));
end Set_Text_Size;
procedure Draw
(This : in out Value_Slider) is
begin
fl_value_slider_draw (This.Void_Ptr);
end Draw;
function Handle
(This : in out Value_Slider;
Event : in Event_Kind)
return Event_Outcome is
begin
return Event_Outcome'Val
(fl_value_slider_handle (This.Void_Ptr, Event_Kind'Pos (Event)));
end Handle;
end FLTK.Widgets.Valuators.Sliders.Value;
|
tum-ei-rcs/StratoX | Ada | 25,202 | adb |
with PX4IO.Driver;
with Servo;
with Generic_PID_Controller;
with Logger;
with Profiler;
with Config.Software; use Config.Software;
--with Units.Numerics; use Units.Numerics;
with Ada.Numerics.Elementary_Functions;
with Bounded_Image; use Bounded_Image;
with Interfaces; use Interfaces;
with ULog;
with Types; use Types;
with Ada.Real_Time; use Ada.Real_Time;
pragma Elaborate_All(Ada.Real_Time);
with Helper;
package body Controller with SPARK_Mode is
--------------------
-- TYPES
--------------------
type Logger_Call_Type is mod Config.Software.CFG_LOGGER_CALL_SKIP with Default_Value => 0;
type Control_Mode_T is (MODE_UNKNOWN,
MODE_POSHOLD, -- impossible to perform homing...holding position
MODE_HOMING, -- currently steering towards home
MODE_COURSEHOLD, -- temporarily lost navigation; hold last known course
MODE_ARRIVED); -- close enough to home
type State_Type is record
-- logging info
logger_calls : Logger_Call_Type;
logger_console_calls : Logger_Call_Type;
control_profiler : Profiler.Profile_Tag;
detach_animation_time : Time_Type := 0.0 * Second;
-- homimg information:
once_had_my_pos : Boolean := False;
distance_to_home : Length_Type := 0.0 * Meter;
course_to_home : Yaw_Type := 0.0 * Degree;
controller_mode : Control_Mode_T := MODE_UNKNOWN;
end record;
--------------------
-- STATES
--------------------
package Pitch_PID_Controller is new Generic_PID_Controller(Angle_Type,
Elevator_Angle_Type,
Unit_Type,
-50.0*Degree,
50.0*Degree,
Elevator_Angle_Type'First,
Elevator_Angle_Type'Last);
PID_Pitch : Pitch_PID_Controller.Pid_Object;
package Roll_PID_Controller is new Generic_PID_Controller(Angle_Type,
Aileron_Angle_Type,
Unit_Type,
-50.0*Degree,
50.0*Degree,
Aileron_Angle_Type'First,
Aileron_Angle_Type'Last);
PID_Roll : Roll_PID_Controller.Pid_Object;
package Yaw_PID_Controller is new Generic_PID_Controller( Angle_Type,
Roll_Type,
Unit_Type,
-50.0*Degree,
50.0*Degree,
-Config.MAX_ROLL,
Config.MAX_ROLL);
PID_Yaw : Yaw_PID_Controller.Pid_Object;
G_Object_Orientation : Orientation_Type := (0.0 * Degree, 0.0 * Degree, 0.0 * Degree);
G_Object_Position : GPS_Loacation_Type := (0.0 * Degree, 0.0 * Degree, 0.0 * Meter);
G_Target_Position : GPS_Loacation_Type := (0.0 * Degree, 0.0 * Degree, 0.0 * Meter);
G_Target_Orientation : Orientation_Type := (0.0 * Degree, Config.TARGET_PITCH, 0.0 * Degree);
G_Target_Orientation_Prev : Orientation_Type := G_Target_Orientation;
G_state : State_Type;
G_Last_Pitch_Control : Ada.Real_Time.Time := Ada.Real_Time.Clock;
G_Last_Roll_Control : Ada.Real_Time.Time := Ada.Real_Time.Clock;
G_Last_Yaw_Control : Ada.Real_Time.Time := Ada.Real_Time.Clock;
G_Plane_Control : Plane_Control_Type := (others => 0.0 * Degree);
G_Elevon_Angles : Elevon_Angle_Array := (others => 0.0 * Degree);
--------------------
-- PROTOTYPES
--------------------
procedure Limit_Target_Attitude with Inline,
Global => (In_Out => (G_Target_Orientation));
function Have_My_Position return Boolean with
Global => (Input => G_Object_Position);
function Have_Home_Position return Boolean with
Global => (Input => G_Target_Position);
function Have_Course return Boolean is
( Have_Home_Position and (G_state.once_had_my_pos or Have_My_Position) );
function FR_poshold_iff_no_course return Boolean is
( (Have_Course and G_state.controller_mode /= MODE_POSHOLD) or
(not Have_Course and G_state.controller_mode = MODE_POSHOLD) ) with
Ghost;
--Contract_Cases => ((Have_Course and G_state.controller_mode /= MODE_POSHOLD) => FR_poshold_iff_no_course'Result,
-- (not Have_Course and G_state.controller_mode = MODE_POSHOLD) => FR_poshold_iff_no_course'Result);
function FR_arrive_iff_near_target return Boolean is
( if (Have_Home_Position and Have_My_Position) then
(G_state.distance_to_home < Config.TARGET_AREA_RADIUS and G_state.controller_mode = MODE_ARRIVED) or
(G_state.distance_to_home >= Config.TARGET_AREA_RADIUS and G_state.distance_to_home <= 2.0*Config.TARGET_AREA_RADIUS) or
(G_state.distance_to_home > 2.0*Config.TARGET_AREA_RADIUS and G_state.controller_mode /= MODE_ARRIVED)
else True ) with Ghost;
-- Contract_Cases => ((Have_Home_Position and Have_My_Position and G_state.distance_to_home < Config.TARGET_AREA_RADIUS and G_state.controller_mode = MODE_ARRIVED) => FR_arrive_iff_near_target'Result,
-- (Have_Home_Position and Have_My_Position and G_state.distance_to_home >= Config.TARGET_AREA_RADIUS and G_state.distance_to_home <= 2.0*Config.TARGET_AREA_RADIUS) => FR_arrive_iff_near_target'Result,
-- (Have_Home_Position and Have_My_Position and G_state.distance_to_home > 2.0*Config.TARGET_AREA_RADIUS and G_state.controller_mode /= MODE_ARRIVED) => FR_arrive_iff_near_target'Result,
-- others => FR_arrive_iff_near_target'Result );
-- Pre => G_state.distance_to_home >= 0.1*Meter and G_state.distance_to_home < 100.0*Kilo*Meter;
procedure Update_Homing with
Global => (Input => (G_Object_Position, G_Target_Position),
In_Out => (G_state)),
Depends => (G_state => (G_state, G_Object_Position, G_Target_Position)),
Contract_Cases => ( --Have_Course => G_state.controller_mode /= MODE_POSHOLD,
not Have_Course => G_state.controller_mode = MODE_POSHOLD,
(Have_Home_Position and Have_My_Position and Distance (G_Object_Position, G_Target_Position) < Config.TARGET_AREA_RADIUS) => G_state.controller_mode = MODE_ARRIVED,
(Have_Home_Position and Have_My_Position and Distance (G_Object_Position, G_Target_Position) > 2.0*Config.TARGET_AREA_RADIUS) => G_state.controller_mode = MODE_HOMING,
(Have_Home_Position and not Have_My_Position and G_state.once_had_my_pos) => G_state.controller_mode = MODE_COURSEHOLD
),
Post => G_state.controller_mode /= MODE_UNKNOWN and FR_arrive_iff_near_target and FR_poshold_iff_no_course;
-- update distance and bearing to home coordinate, and decide what to do
procedure Compute_Target_Attitude with
Global => (Input => (G_state, G_Object_Orientation, Ada.Real_Time.Clock_Time, G_Target_Position),
In_Out => (G_Last_Yaw_Control, PID_Yaw, G_Target_Orientation_Prev, G_Target_Orientation),
Output => null ),
-- Depends => (G_Last_Yaw_Control => (G_Last_Yaw_Control, G_state, Ada.Real_Time.Clock_Time),
-- G_Target_Orientation => (G_state, PID_Yaw, G_Object_Orientation, G_Target_Orientation_Prev,
-- G_Last_Yaw_Control, Ada.Real_Time.Clock_Time),
-- PID_Yaw => (PID_Yaw, G_Object_Orientation, G_Last_Yaw_Control, G_Target_Orientation_Prev,
-- G_state, Ada.Real_Time.Clock_Time),
-- G_Target_Orientation_Prev => (G_Target_Orientation_Prev, G_state, PID_Yaw,
-- Ada.Real_Time.Clock_Time, G_Object_Orientation, G_Last_Yaw_Control)),
Contract_Cases => ((G_state.controller_mode = MODE_COURSEHOLD) =>
G_Target_Orientation.Yaw = G_Target_Orientation_Prev.Yaw,
(G_state.controller_mode = MODE_HOMING) =>
G_Target_Orientation.Yaw = G_state.course_to_home,
(G_state.controller_mode not in MODE_HOMING | MODE_COURSEHOLD) =>
G_Target_Orientation.Yaw = G_Object_Orientation.Yaw,
others => True),
Post => G_Target_Orientation_Prev = G_Target_Orientation;
-- decide vehicle attitude depending on mode
-- contract seems extensive, but it enforces that the attitude is always updated, and that
-- homing works.
----------------
-- initialize
----------------
procedure initialize is
begin
Servo.initialize;
Pitch_PID_Controller.initialize(PID_Pitch,
Unit_Type( Config.Software.CFG_PID_PITCH_P ),
Unit_Type( Config.Software.CFG_PID_PITCH_I ),
Unit_Type( Config.Software.CFG_PID_PITCH_D ));
Roll_PID_Controller.initialize(PID_Roll,
Unit_Type( Config.Software.CFG_PID_ROLL_P ),
Unit_Type( Config.Software.CFG_PID_ROLL_I ),
Unit_Type( Config.Software.CFG_PID_ROLL_D ));
Yaw_PID_Controller.initialize(PID_Yaw,
Unit_Type( Config.Software.CFG_PID_YAW_P ),
Unit_Type( Config.Software.CFG_PID_YAW_I ),
Unit_Type( Config.Software.CFG_PID_YAW_D ));
G_state.control_profiler.init("Control");
Logger.log_console(Logger.DEBUG, "Controller initialized");
end initialize;
--------------
-- activate
--------------
procedure activate is
begin
Servo.activate;
end activate;
----------------
-- deactivate
----------------
procedure deactivate is
begin
Servo.deactivate;
end deactivate;
--------------------------
-- set_Current_Position
--------------------------
procedure set_Current_Position(location : GPS_Loacation_Type) is
begin
G_Object_Position := location;
end set_Current_Position;
-------------------------
-- set_Target_Position
-------------------------
procedure set_Target_Position (location : GPS_Loacation_Type) is
begin
G_Target_Position := location;
Logger.log (Logger.SENSOR, "Home=" & Integer_Img ( Integer (100000.0 * To_Degree (G_Target_Position.Latitude)))
& ", " & Integer_Img ( Integer (100000.0 * To_Degree (G_Target_Position.Longitude)))
& ", " & Integer_Img ( Sat_Cast_Int ( Float (G_Target_Position.Altitude))));
end set_Target_Position;
-----------------------------
-- set_Current_Orientation
-----------------------------
procedure set_Current_Orientation (orientation : Orientation_Type) is
begin
G_Object_Orientation := orientation;
end set_Current_Orientation;
--------------
-- log_Info
--------------
procedure log_Info is
controller_msg : ULog.Message (Typ => ULog.CONTROLLER);
nav_msg : ULog.Message (Typ => ULog.NAV);
now : constant Ada.Real_Time.Time := Ada.Real_Time.Clock;
function Sat_Sub_Alt is new Saturated_Subtraction (Altitude_Type);
begin
G_state.logger_console_calls := Logger_Call_Type'Succ( G_state.logger_console_calls );
if G_state.logger_console_calls = 0 then
Logger.log_console(Logger.DEBUG,
"Pos " & AImage( G_Object_Position.Longitude ) &
", " & AImage( G_Object_Position.Latitude ) &
", " & Image( G_Object_Position.Altitude ) &
", d=" & Integer_Img (Sat_Cast_Int ( Float (G_state.distance_to_home))) &
", crs=" & AImage (G_state.course_to_home));
Logger.log_console(Logger.DEBUG,
"TY: " & AImage( G_Target_Orientation.Yaw ) &
", TR: " & AImage( G_Target_Orientation.Roll ) &
" Elev: " & AImage( G_Elevon_Angles(LEFT) ) & ", " & AImage( G_Elevon_Angles(RIGHT) )
);
end if;
-- log to SD
controller_msg := ( Typ => ULog.CONTROLLER,
t => now,
target_yaw => Float (G_Target_Orientation.Yaw),
target_roll => Float (G_Target_Orientation.Roll),
target_pitch => Float (G_Target_Orientation.Pitch),
elevon_left => Float (G_Elevon_Angles(LEFT)),
elevon_right => Float (G_Elevon_Angles(RIGHT)),
ctrl_mode => Unsigned_8 (Control_Mode_T'Pos (G_state.controller_mode)));
nav_msg := ( Typ => ULog.NAV,
t=> now,
home_dist => Float (G_state.distance_to_home),
home_course => Float (G_state.course_to_home),
home_altdiff => Float (Sat_Sub_Alt (G_Object_Position.Altitude, G_Target_Position.Altitude)));
Logger.log_sd (Logger.INFO, controller_msg);
Logger.log_sd (Logger.SENSOR, nav_msg);
end log_Info;
--------------
-- set_hold
--------------
procedure set_hold is
begin
-- hold glider in position
Servo.Set_Critical_Angle (Servo.LEFT_ELEVON, 38.0 * Degree );
Servo.Set_Critical_Angle (Servo.RIGHT_ELEVON, 38.0 * Degree );
end set_hold;
----------------
-- set_detach
----------------
procedure set_detach is
begin
Servo.Set_Critical_Angle (Servo.LEFT_ELEVON, -40.0 * Degree );
Servo.Set_Critical_Angle (Servo.RIGHT_ELEVON, -40.0 * Degree );
end set_detach;
----------
-- sync
----------
procedure sync is
begin
PX4IO.Driver.sync_Outputs;
end sync;
----------
-- bark
----------
procedure bark is
angle : constant Servo.Servo_Angle_Type := 35.0 * Degree;
begin
for k in Integer range 1 .. 20 loop
Servo.set_Angle(Servo.LEFT_ELEVON, angle);
Servo.set_Angle(Servo.RIGHT_ELEVON, angle);
PX4IO.Driver.sync_Outputs;
Helper.delay_ms( 10 );
end loop;
for k in Integer range 1 .. 20 loop
Servo.set_Angle(Servo.LEFT_ELEVON, angle+3.0*Degree);
Servo.set_Angle(Servo.RIGHT_ELEVON, angle+3.0*Degree);
PX4IO.Driver.sync_Outputs;
Helper.delay_ms( 10 );
end loop;
end bark;
------------------
-- control_Roll
------------------
procedure control_Roll is
error : constant Angle_Type := (G_Target_Orientation.Roll - G_Object_Orientation.Roll);
now : constant Ada.Real_Time.Time := Ada.Real_Time.Clock;
dt : constant Time_Type := Time_Type (Float((now - G_Last_Roll_Control) / Ada.Real_Time.Milliseconds(1)) * 1.0e-3);
begin
G_Last_Roll_Control := now;
Roll_PID_Controller.step (PID_Roll, error, dt, G_Plane_Control.Aileron);
end control_Roll;
-------------------
-- control_Pitch
-------------------
procedure control_Pitch is
error : constant Angle_Type := (G_Target_Orientation.Pitch - G_Object_Orientation.Pitch);
now : constant Ada.Real_Time.Time := Ada.Real_Time.Clock;
dt : constant Time_Type := Time_Type (Float((now - G_Last_Pitch_Control) / Ada.Real_Time.Milliseconds(1)) * 1.0e-3);
begin
G_Last_Pitch_Control := now;
Pitch_PID_Controller.step (PID_Pitch, error, dt, G_Plane_Control.Elevator);
end control_Pitch;
------------------------
-- Have_Home_Position
------------------------
function Have_Home_Position return Boolean is
begin
return G_Target_Position.Longitude /= 0.0 * Degree and G_Target_Position.Latitude /= 0.0 * Degree;
end Have_Home_Position;
----------------------
-- Have_My_Position
----------------------
function Have_My_Position return Boolean is
begin
return G_Object_Position.Longitude /= 0.0 * Degree and G_Object_Position.Latitude /= 0.0 * Degree;
end Have_My_Position;
-------------------
-- Update_Homing
-------------------
procedure Update_Homing is
have_my_pos : constant Boolean := Have_My_Position;
have_home_pos : constant Boolean := Have_Home_Position;
begin
G_state.once_had_my_pos := G_state.once_had_my_pos or have_my_pos;
if have_my_pos and then have_home_pos then
-- compute relative location to target
G_state.distance_to_home := Distance (G_Object_Position, G_Target_Position);
G_state.course_to_home := Yaw_Type (Bearing (G_Object_Position, G_Target_Position));
-- pos hold or homing, depending on distance
if G_state.distance_to_home < Config.TARGET_AREA_RADIUS then
-- we are at home
G_state.controller_mode := MODE_ARRIVED;
else
-- some distance to target
if G_state.controller_mode = MODE_ARRIVED then
-- hysteresis if we already had arrived
if G_state.distance_to_home > 2.0*Config.TARGET_AREA_RADIUS then
G_state.controller_mode := MODE_HOMING;
else
G_state.controller_mode := MODE_ARRIVED;
end if;
else
-- otherwise immediate homing
G_state.controller_mode := MODE_HOMING;
end if;
end if;
elsif have_home_pos and then (not have_my_pos and G_state.once_had_my_pos) then
-- temporarily don't have my position => keep old bearing
G_state.controller_mode := MODE_COURSEHOLD;
else
pragma Assert (not have_home_pos or not G_state.once_had_my_pos);
-- don't know where to go => hold position
G_state.controller_mode := MODE_POSHOLD;
end if;
end Update_Homing;
-----------------------------
-- Compute_Target_Attitude
-----------------------------
procedure Compute_Target_Attitude is
error : Angle_Type;
now : constant Ada.Real_Time.Time := Ada.Real_Time.Clock;
dt : constant Time_Type := Time_Type (Float ((now - G_Last_Yaw_Control) / Ada.Real_Time.Milliseconds(1)) * 1.0e-3);
begin
------------
-- Pitch
------------
-- we cannot afford a (fail-safe) airspeed sensor, thus we rely on the polar:
-- assuming that a certain pitch angle results in stable flight
G_Target_Orientation.Pitch := Config.TARGET_PITCH;
pragma Assert (G_Target_Orientation.Pitch < 0.0 * Degree); -- as long as this is constant, assert nose down
---------------
-- Roll, Yaw
---------------
case G_state.controller_mode is
when MODE_UNKNOWN | MODE_POSHOLD =>
-- circle right when we have no target
G_Target_Orientation.Roll := -Config.CIRCLE_TRAJECTORY_ROLL;
G_Target_Orientation.Yaw := G_Object_Orientation.Yaw;
when MODE_HOMING | MODE_COURSEHOLD =>
-- control yaw by setting roll
if G_state.controller_mode = MODE_HOMING then
G_Target_Orientation.Yaw := G_state.course_to_home;
else
G_Target_Orientation.Yaw := G_Target_Orientation_Prev.Yaw;
end if;
error := delta_Angle (G_Object_Orientation.Yaw, G_Target_Orientation.Yaw);
Yaw_PID_Controller.step (PID_Yaw, error, dt, G_Target_Orientation.Roll);
G_Last_Yaw_Control := now;
when MODE_ARRIVED =>
-- circle left when we are there
G_Target_Orientation.Roll := Config.CIRCLE_TRAJECTORY_ROLL;
G_Target_Orientation.Yaw := G_Object_Orientation.Yaw;
end case;
G_Target_Orientation_Prev := G_Target_Orientation;
end Compute_Target_Attitude;
------------------
-- Elevon_Angles
------------------
function Elevon_Angles( elevator : Elevator_Angle_Type; aileron : Aileron_Angle_Type;
priority : Control_Priority_Type ) return Elevon_Angle_Array is
balance : Float range 0.0 .. 2.0;-- := 1.0;
scale : Float range 0.0 .. 1.0 := 1.0;
balanced_elevator : Elevator_Angle_Type;
balanced_aileron : Aileron_Angle_Type;
begin
-- dynamic sharing of rudder angles between elevator and ailerons
case (priority) is
when EQUAL => balance := 1.0;
when PITCH_FIRST => balance := 1.3;
when ROLL_FIRST => balance := 0.7;
end case;
balanced_elevator := Elevator_Angle_Type( Helper.Saturate( Float(elevator) * balance,
Float(Elevator_Angle_Type'First), Float(Elevator_Angle_Type'Last)) );
balanced_aileron := Aileron_Angle_Type( Helper.Saturate( Float(aileron) * (2.0 - balance),
Float(Aileron_Angle_Type'First), Float(Aileron_Angle_Type'Last)) );
-- scaling (only if necessary)
if abs(balanced_elevator) + abs(balanced_aileron) > Elevon_Angle_Type'Last then
scale := 0.95 * Float(Elevon_Angle_Type'Last) / ( abs(Float(balanced_elevator)) + abs(Float(balanced_aileron)) );
end if;
-- mixing
return (LEFT => (balanced_elevator - balanced_aileron) * Unit_Type(scale),
RIGHT => (balanced_elevator + balanced_aileron) * Unit_Type(scale));
end Elevon_Angles;
---------------------------
-- Limit_Target_Attitude
---------------------------
procedure Limit_Target_Attitude is
function Sat_Pitch is new Saturate (Pitch_Type);
function Sat_Roll is new Saturate (Roll_Type);
begin
G_Target_Orientation.Roll := Sat_Roll (val => G_Target_Orientation.Roll, min => -Config.MAX_ROLL, max => Config.MAX_ROLL);
G_Target_Orientation.Pitch := Sat_Pitch (val => G_Target_Orientation.Pitch, min => -Config.MAX_PITCH, max => Config.MAX_PITCH);
end Limit_Target_Attitude;
-----------------
-- runOneCycle
-----------------
procedure runOneCycle is
Control_Priority : Control_Priority_Type := EQUAL;
oldmode : constant Control_Mode_T := G_state.controller_mode;
begin
Update_Homing;
if G_state.controller_mode /= oldmode then
Logger.log_console (Logger.DEBUG, "Homing mode=" & Unsigned8_Img (Control_Mode_T'Pos (G_state.controller_mode)));
end if;
Compute_Target_Attitude;
-- TEST: overwrite roll with a fixed value
-- G_Target_Orientation.Roll := Config.CIRCLE_TRAJECTORY_ROLL; -- TEST: Omakurve
-- evelope protection
Limit_Target_Attitude;
-- compute elevon position
if not Config.Software.TEST_MODE_ACTIVE then
control_Pitch;
control_Roll;
else
-- fake elevon waving for ground tests
G_Plane_Control.Elevator := Elevator_Angle_Type (0.0);
declare
now : constant Ada.Real_Time.Time := Ada.Real_Time.Clock;
t_abs : constant Time_Type := Units.To_Time (now);
sinval : constant Unit_Type := Unit_Type (Ada.Numerics.Elementary_Functions.Sin (2.0 * Float (t_abs)));
pragma Assume (sinval in -1.0 .. 1.0);
FAKE_ROLL_MAGNITUDE : constant Angle_Type := 20.0 * Degree;
begin
G_Plane_Control.Aileron := FAKE_ROLL_MAGNITUDE * sinval;
end;
end if;
G_state.control_profiler.start;
-- mix
if abs( G_Object_Orientation.Roll ) > CFG_CONTROLL_UNSTABLE_ROLL_THRESHOLD then
Control_Priority := ROLL_FIRST;
end if;
if abs( G_Object_Orientation.Pitch ) > CFG_CONTROLL_UNSTABLE_PITCH_THRESHOLD then
Control_Priority := PITCH_FIRST;
end if;
G_Elevon_Angles := Elevon_Angles(G_Plane_Control.Elevator, G_Plane_Control.Aileron, Control_Priority);
-- set servos
Servo.set_Angle(Servo.LEFT_ELEVON, G_Elevon_Angles(LEFT) );
Servo.set_Angle(Servo.RIGHT_ELEVON, G_Elevon_Angles(RIGHT) );
-- Output
PX4IO.Driver.sync_Outputs;
G_state.control_profiler.stop;
-- log
G_state.logger_calls := Logger_Call_Type'Succ( G_state.logger_calls );
if G_state.logger_calls = 0 then
log_Info;
end if;
end runOneCycle;
----------------
-- get_Elevons
----------------
function get_Elevons return Elevon_Angle_Array is
begin
return G_Elevon_Angles;
end get_Elevons;
end Controller;
|
AdaCore/libadalang | Ada | 320 | adb | procedure Test is
package P is
type T is tagged null record;
procedure Foo (X : T) is null;
end P;
package Q is
type U is new P.T with null record;
overriding procedure Foo (X : U) is null;
end Q;
X : Q.U := Q.U'(null record);
begin
X.Foo;
pragma Test_Statement;
end Test;
|
melwyncarlo/ProjectEuler | Ada | 303 | adb | with Ada.Text_IO;
with Ada.Integer_Text_IO;
-- Copyright 2021 Melwyn Francis Carlo
procedure A097 is
use Ada.Text_IO;
use Ada.Integer_Text_IO;
Str : constant String (1 .. 12) := "Hello World ";
Num : constant Integer := 2021;
begin
Put (Str);
Put (Num, Width => 0);
end A097;
|
AdaCore/libadalang | Ada | 653 | adb | procedure Test is
A : constant Character := 'l';
B : constant Character := ASCII.NUL;
E : constant String := "oiy";
C : constant String := 'c' & "lol";
D : constant String := C & "lol";
F : constant String := A & D;
G : constant String := "lol" & B;
H : constant String := String ("lol" & G);
I : constant String := "a" & "a" & "a";
J : constant String := String ("lol" & G & "hihi");
package With_Subtype is
subtype T is String;
K : constant T := "a" & "b";
L : constant T := T (K & 'c' & K);
M : constant T := T (K & K);
end With_Subtype;
begin
null;
end Test;
pragma Test_Block;
|
zhmu/ananas | Ada | 175 | ads | package Unroll2 is
type Sarray is array (1 .. 4) of Float;
function "+" (X, Y : Sarray) return Sarray;
procedure Add (X, Y : Sarray; R : out Sarray);
end Unroll2;
|
reznikmm/matreshka | Ada | 6,801 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Chart.Domain_Elements is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters)
return Chart_Domain_Element_Node is
begin
return Self : Chart_Domain_Element_Node do
Matreshka.ODF_Chart.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Chart_Prefix);
end return;
end Create;
----------------
-- Enter_Node --
----------------
overriding procedure Enter_Node
(Self : not null access Chart_Domain_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Enter_Chart_Domain
(ODF.DOM.Chart_Domain_Elements.ODF_Chart_Domain_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Enter_Node (Visitor, Control);
end if;
end Enter_Node;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Chart_Domain_Element_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Domain_Element;
end Get_Local_Name;
----------------
-- Leave_Node --
----------------
overriding procedure Leave_Node
(Self : not null access Chart_Domain_Element_Node;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then
ODF.DOM.Visitors.Abstract_ODF_Visitor'Class
(Visitor).Leave_Chart_Domain
(ODF.DOM.Chart_Domain_Elements.ODF_Chart_Domain_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Leave_Node (Visitor, Control);
end if;
end Leave_Node;
----------------
-- Visit_Node --
----------------
overriding procedure Visit_Node
(Self : not null access Chart_Domain_Element_Node;
Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class;
Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class;
Control : in out XML.DOM.Visitors.Traverse_Control) is
begin
if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then
ODF.DOM.Iterators.Abstract_ODF_Iterator'Class
(Iterator).Visit_Chart_Domain
(Visitor,
ODF.DOM.Chart_Domain_Elements.ODF_Chart_Domain_Access
(Self),
Control);
else
Matreshka.DOM_Elements.Abstract_Element_Node
(Self.all).Visit_Node (Iterator, Visitor, Control);
end if;
end Visit_Node;
begin
Matreshka.DOM_Documents.Register_Element
(Matreshka.ODF_String_Constants.Chart_URI,
Matreshka.ODF_String_Constants.Domain_Element,
Chart_Domain_Element_Node'Tag);
end Matreshka.ODF_Chart.Domain_Elements;
|
sungyeon/drake | Ada | 205 | ads | pragma License (Unrestricted);
with Ada.Numerics.Generic_Complex_Types;
package Ada.Numerics.Long_Complex_Types is
new Generic_Complex_Types (Long_Float);
pragma Pure (Ada.Numerics.Long_Complex_Types);
|
zhmu/ananas | Ada | 6,577 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- K R U N C H --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This procedure implements file name crunching
-- First, the name is divided into segments separated by minus signs and
-- underscores, then all minus signs and underscores are eliminated. If
-- this leaves the name short enough, we are done.
-- If not, then the longest segment is located (left-most if there are
-- two of equal length), and shortened by dropping its last character.
-- This is repeated until the name is short enough.
-- As an example, consider the krunch of our-strings-wide_fixed.adb
-- to fit the name into 8 characters as required by DOS:
-- our-strings-wide_fixed 22
-- our strings wide fixed 19
-- our string wide fixed 18
-- our strin wide fixed 17
-- our stri wide fixed 16
-- our stri wide fixe 15
-- our str wide fixe 14
-- our str wid fixe 13
-- our str wid fix 12
-- ou str wid fix 11
-- ou st wid fix 10
-- ou st wi fix 9
-- ou st wi fi 8
-- Final file name: OUSTWIFX.ADB
-- A special rule applies for children of System, Ada, Gnat, and Interfaces.
-- In these cases, the following special prefix replacements occur:
-- ada- replaced by a-
-- gnat- replaced by g-
-- interfaces- replaced by i-
-- system- replaced by s-
-- The rest of the name is krunched in the usual manner described above.
-- In addition, these names, as well as the names of the renamed packages
-- from the obsolescent features annex, are always krunched to 8 characters
-- regardless of the setting of Maxlen.
-- As an example of this special rule, consider ada-strings-wide_fixed.adb
-- which gets krunched as follows:
-- ada-strings-wide_fixed 22
-- a- strings wide fixed 18
-- a- string wide fixed 17
-- a- strin wide fixed 16
-- a- stri wide fixed 15
-- a- stri wide fixe 14
-- a- str wide fixe 13
-- a- str wid fixe 12
-- a- str wid fix 11
-- a- st wid fix 10
-- a- st wi fix 9
-- a- st wi fi 8
-- Final file name: A-STWIFX.ADB
-- Since children of units named A, G, I or S might conflict with the names
-- of predefined units, the naming rule in that case is that the first hyphen
-- is replaced by a tilde sign.
-- Note: as described below, this special treatment of predefined library
-- unit file names can be inhibited by setting the No_Predef flag.
-- Of course there is no guarantee that this algorithm results in uniquely
-- crunched names (nor, obviously, is there any algorithm which would do so)
-- In fact we run into such a case in the standard library routines with
-- children of Wide_Text_IO, so a special rule is applied to deal with this
-- clash, namely the prefix ada-wide_text_io- is replaced by a-wt- and then
-- the normal crunching rules are applied, so that for example, the unit:
-- Ada.Wide_Text_IO.Float_IO
-- has the file name
-- a-wtflio
-- More problems arise with Wide_Wide, so we replace this sequence by
-- a z (which is not used much) and also (as in the Wide_Text_IO case),
-- we replace the prefix ada.wide_wide_text_io- by a-zt- and then
-- the normal crunching rules are applied.
-- An additional trick is used for Ada.Long_Long_Long_Integer_*_IO, where
-- the Integer word is dropped.
-- The units implementing the support of 128-bit types are crunched to 9 and
-- System.Compare_Array_* is replaced with System.CA_* before crunching.
-- These are the only irregularity required (so far) to keep the file names
-- unique in the standard predefined libraries.
procedure Krunch
(Buffer : in out String;
Len : in out Natural;
Maxlen : Natural;
No_Predef : Boolean);
pragma Elaborate_Body (Krunch);
-- The full file name is stored in Buffer (1 .. Len) on entry. The file
-- name is crunched in place and on return Len is updated, so that the
-- resulting krunched name is in Buffer (1 .. Len) where Len <= Maxlen.
-- Note that Len may be less than or equal to Maxlen on entry, in which
-- case it may be possible that Krunch does not modify Buffer. The fourth
-- parameter, No_Predef, is a switch which, if set to True, disables the
-- normal special treatment of predefined library unit file names.
--
-- Note: the string Buffer must have a lower bound of 1, and may not
-- contain any blanks (in particular, it must not have leading blanks).
|
io7m/coreland-vector-ada | Ada | 2,004 | adb | with ada.text_io;
with vector;
with vector.div_scalar;
procedure divsc_single is
package io renames ada.text_io;
package v16 is new vector (16);
package v16_divsc is new v16.div_scalar;
use type v16.scalar_f_t;
base_sc : constant v16.scalar_f_t := 10.0;
base_a : constant v16.vector_f_t := (others => 50.0);
base_r : v16.vector_f_t := (others => 5.0);
testno : integer := 0;
procedure sys_exit (e: integer);
pragma import (c, sys_exit, "exit");
procedure fail (want, got : v16.scalar_f_t; index: integer) is
s_tnum : constant string := integer'image (testno);
s_index : constant string := integer'image (index);
s_want : constant string := v16.scalar_f_t'image (want);
s_got : constant string := v16.scalar_f_t'image (got);
begin
io.put_line ("[" & s_tnum & "][" & s_index & "] fail " & s_want & " /= " & s_got);
sys_exit (1);
end fail;
procedure pass (want, got : v16.scalar_f_t; index: integer) is
s_tnum : constant string := integer'image (testno);
s_index : constant string := integer'image (index);
s_want : constant string := v16.scalar_f_t'image (want);
s_got : constant string := v16.scalar_f_t'image (got);
begin
io.put_line ("[" & s_tnum & "][" & s_index & "] " & s_want & " = " & s_got);
end pass;
procedure check (vec : v16.vector_f_t) is
begin
for index in vec'range loop
if vec (index) /= base_r (index) then
fail (want => base_r (index), got => vec (index), index => index);
else
pass (want => base_r (index), got => vec (index), index => index);
end if;
end loop;
testno := testno + 1;
end check;
begin
--
-- divsc, in place
--
declare
tmp_a : v16.vector_f_t := base_a;
begin
v16_divsc.f (tmp_a, base_sc);
check (tmp_a);
end;
--
-- divsc, external storage
--
declare
tmp_a : v16.vector_f_t := base_a;
begin
v16_divsc.f_ext (base_a, tmp_a, base_sc);
check (tmp_a);
end;
end divsc_single;
|
zhmu/ananas | Ada | 2,277 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . D I S P A T C H I N G . E D F --
-- --
-- S p e c --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. In accordance with the copyright of that document, you can freely --
-- copy and modify this specification, provided that if you redistribute a --
-- modified version, any changes that you have made are clearly indicated. --
-- --
------------------------------------------------------------------------------
-- This unit is not implemented in typical GNAT implementations that lie on
-- top of operating systems, because it is infeasible to implement in such
-- environments.
-- If a target environment provides appropriate support for this package,
-- then the Unimplemented_Unit pragma should be removed from this spec and
-- an appropriate body provided.
with Ada.Real_Time;
with Ada.Task_Identification;
package Ada.Dispatching.EDF is
pragma Preelaborate;
pragma Unimplemented_Unit;
subtype Deadline is Ada.Real_Time.Time;
Default_Deadline : constant Deadline := Ada.Real_Time.Time_Last;
procedure Set_Deadline
(D : Deadline;
T : Ada.Task_Identification.Task_Id :=
Ada.Task_Identification.Current_Task);
procedure Delay_Until_And_Set_Deadline
(Delay_Until_Time : Ada.Real_Time.Time;
Deadline_Offset : Ada.Real_Time.Time_Span);
function Get_Deadline
(T : Ada.Task_Identification.Task_Id :=
Ada.Task_Identification.Current_Task)
return Deadline
with
SPARK_Mode,
Volatile_Function,
Global => Ada.Task_Identification.Tasking_State;
end Ada.Dispatching.EDF;
|
ekoeppen/STM32_Generic_Ada_Drivers | Ada | 18,456 | ads | -- This spec has been automatically generated from STM32F030.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with System;
package STM32_SVD.DMA is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype ISR_GIF1_Field is STM32_SVD.Bit;
subtype ISR_TCIF1_Field is STM32_SVD.Bit;
subtype ISR_HTIF1_Field is STM32_SVD.Bit;
subtype ISR_TEIF1_Field is STM32_SVD.Bit;
subtype ISR_GIF2_Field is STM32_SVD.Bit;
subtype ISR_TCIF2_Field is STM32_SVD.Bit;
subtype ISR_HTIF2_Field is STM32_SVD.Bit;
subtype ISR_TEIF2_Field is STM32_SVD.Bit;
subtype ISR_GIF3_Field is STM32_SVD.Bit;
subtype ISR_TCIF3_Field is STM32_SVD.Bit;
subtype ISR_HTIF3_Field is STM32_SVD.Bit;
subtype ISR_TEIF3_Field is STM32_SVD.Bit;
subtype ISR_GIF4_Field is STM32_SVD.Bit;
subtype ISR_TCIF4_Field is STM32_SVD.Bit;
subtype ISR_HTIF4_Field is STM32_SVD.Bit;
subtype ISR_TEIF4_Field is STM32_SVD.Bit;
subtype ISR_GIF5_Field is STM32_SVD.Bit;
subtype ISR_TCIF5_Field is STM32_SVD.Bit;
subtype ISR_HTIF5_Field is STM32_SVD.Bit;
subtype ISR_TEIF5_Field is STM32_SVD.Bit;
subtype ISR_GIF6_Field is STM32_SVD.Bit;
subtype ISR_TCIF6_Field is STM32_SVD.Bit;
subtype ISR_HTIF6_Field is STM32_SVD.Bit;
subtype ISR_TEIF6_Field is STM32_SVD.Bit;
subtype ISR_GIF7_Field is STM32_SVD.Bit;
subtype ISR_TCIF7_Field is STM32_SVD.Bit;
subtype ISR_HTIF7_Field is STM32_SVD.Bit;
subtype ISR_TEIF7_Field is STM32_SVD.Bit;
-- DMA interrupt status register (DMA_ISR)
type ISR_Register is record
-- Read-only. Channel 1 Global interrupt flag
GIF1 : ISR_GIF1_Field;
-- Read-only. Channel 1 Transfer Complete flag
TCIF1 : ISR_TCIF1_Field;
-- Read-only. Channel 1 Half Transfer Complete flag
HTIF1 : ISR_HTIF1_Field;
-- Read-only. Channel 1 Transfer Error flag
TEIF1 : ISR_TEIF1_Field;
-- Read-only. Channel 2 Global interrupt flag
GIF2 : ISR_GIF2_Field;
-- Read-only. Channel 2 Transfer Complete flag
TCIF2 : ISR_TCIF2_Field;
-- Read-only. Channel 2 Half Transfer Complete flag
HTIF2 : ISR_HTIF2_Field;
-- Read-only. Channel 2 Transfer Error flag
TEIF2 : ISR_TEIF2_Field;
-- Read-only. Channel 3 Global interrupt flag
GIF3 : ISR_GIF3_Field;
-- Read-only. Channel 3 Transfer Complete flag
TCIF3 : ISR_TCIF3_Field;
-- Read-only. Channel 3 Half Transfer Complete flag
HTIF3 : ISR_HTIF3_Field;
-- Read-only. Channel 3 Transfer Error flag
TEIF3 : ISR_TEIF3_Field;
-- Read-only. Channel 4 Global interrupt flag
GIF4 : ISR_GIF4_Field;
-- Read-only. Channel 4 Transfer Complete flag
TCIF4 : ISR_TCIF4_Field;
-- Read-only. Channel 4 Half Transfer Complete flag
HTIF4 : ISR_HTIF4_Field;
-- Read-only. Channel 4 Transfer Error flag
TEIF4 : ISR_TEIF4_Field;
-- Read-only. Channel 5 Global interrupt flag
GIF5 : ISR_GIF5_Field;
-- Read-only. Channel 5 Transfer Complete flag
TCIF5 : ISR_TCIF5_Field;
-- Read-only. Channel 5 Half Transfer Complete flag
HTIF5 : ISR_HTIF5_Field;
-- Read-only. Channel 5 Transfer Error flag
TEIF5 : ISR_TEIF5_Field;
-- Read-only. Channel 6 Global interrupt flag
GIF6 : ISR_GIF6_Field;
-- Read-only. Channel 6 Transfer Complete flag
TCIF6 : ISR_TCIF6_Field;
-- Read-only. Channel 6 Half Transfer Complete flag
HTIF6 : ISR_HTIF6_Field;
-- Read-only. Channel 6 Transfer Error flag
TEIF6 : ISR_TEIF6_Field;
-- Read-only. Channel 7 Global interrupt flag
GIF7 : ISR_GIF7_Field;
-- Read-only. Channel 7 Transfer Complete flag
TCIF7 : ISR_TCIF7_Field;
-- Read-only. Channel 7 Half Transfer Complete flag
HTIF7 : ISR_HTIF7_Field;
-- Read-only. Channel 7 Transfer Error flag
TEIF7 : ISR_TEIF7_Field;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for ISR_Register use record
GIF1 at 0 range 0 .. 0;
TCIF1 at 0 range 1 .. 1;
HTIF1 at 0 range 2 .. 2;
TEIF1 at 0 range 3 .. 3;
GIF2 at 0 range 4 .. 4;
TCIF2 at 0 range 5 .. 5;
HTIF2 at 0 range 6 .. 6;
TEIF2 at 0 range 7 .. 7;
GIF3 at 0 range 8 .. 8;
TCIF3 at 0 range 9 .. 9;
HTIF3 at 0 range 10 .. 10;
TEIF3 at 0 range 11 .. 11;
GIF4 at 0 range 12 .. 12;
TCIF4 at 0 range 13 .. 13;
HTIF4 at 0 range 14 .. 14;
TEIF4 at 0 range 15 .. 15;
GIF5 at 0 range 16 .. 16;
TCIF5 at 0 range 17 .. 17;
HTIF5 at 0 range 18 .. 18;
TEIF5 at 0 range 19 .. 19;
GIF6 at 0 range 20 .. 20;
TCIF6 at 0 range 21 .. 21;
HTIF6 at 0 range 22 .. 22;
TEIF6 at 0 range 23 .. 23;
GIF7 at 0 range 24 .. 24;
TCIF7 at 0 range 25 .. 25;
HTIF7 at 0 range 26 .. 26;
TEIF7 at 0 range 27 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype IFCR_CGIF1_Field is STM32_SVD.Bit;
subtype IFCR_CTCIF1_Field is STM32_SVD.Bit;
subtype IFCR_CHTIF1_Field is STM32_SVD.Bit;
subtype IFCR_CTEIF1_Field is STM32_SVD.Bit;
subtype IFCR_CGIF2_Field is STM32_SVD.Bit;
subtype IFCR_CTCIF2_Field is STM32_SVD.Bit;
subtype IFCR_CHTIF2_Field is STM32_SVD.Bit;
subtype IFCR_CTEIF2_Field is STM32_SVD.Bit;
subtype IFCR_CGIF3_Field is STM32_SVD.Bit;
subtype IFCR_CTCIF3_Field is STM32_SVD.Bit;
subtype IFCR_CHTIF3_Field is STM32_SVD.Bit;
subtype IFCR_CTEIF3_Field is STM32_SVD.Bit;
subtype IFCR_CGIF4_Field is STM32_SVD.Bit;
subtype IFCR_CTCIF4_Field is STM32_SVD.Bit;
subtype IFCR_CHTIF4_Field is STM32_SVD.Bit;
subtype IFCR_CTEIF4_Field is STM32_SVD.Bit;
subtype IFCR_CGIF5_Field is STM32_SVD.Bit;
subtype IFCR_CTCIF5_Field is STM32_SVD.Bit;
subtype IFCR_CHTIF5_Field is STM32_SVD.Bit;
subtype IFCR_CTEIF5_Field is STM32_SVD.Bit;
subtype IFCR_CGIF6_Field is STM32_SVD.Bit;
subtype IFCR_CTCIF6_Field is STM32_SVD.Bit;
subtype IFCR_CHTIF6_Field is STM32_SVD.Bit;
subtype IFCR_CTEIF6_Field is STM32_SVD.Bit;
subtype IFCR_CGIF7_Field is STM32_SVD.Bit;
subtype IFCR_CTCIF7_Field is STM32_SVD.Bit;
subtype IFCR_CHTIF7_Field is STM32_SVD.Bit;
subtype IFCR_CTEIF7_Field is STM32_SVD.Bit;
-- DMA interrupt flag clear register (DMA_IFCR)
type IFCR_Register is record
-- Write-only. Channel 1 Global interrupt clear
CGIF1 : IFCR_CGIF1_Field := 16#0#;
-- Write-only. Channel 1 Transfer Complete clear
CTCIF1 : IFCR_CTCIF1_Field := 16#0#;
-- Write-only. Channel 1 Half Transfer clear
CHTIF1 : IFCR_CHTIF1_Field := 16#0#;
-- Write-only. Channel 1 Transfer Error clear
CTEIF1 : IFCR_CTEIF1_Field := 16#0#;
-- Write-only. Channel 2 Global interrupt clear
CGIF2 : IFCR_CGIF2_Field := 16#0#;
-- Write-only. Channel 2 Transfer Complete clear
CTCIF2 : IFCR_CTCIF2_Field := 16#0#;
-- Write-only. Channel 2 Half Transfer clear
CHTIF2 : IFCR_CHTIF2_Field := 16#0#;
-- Write-only. Channel 2 Transfer Error clear
CTEIF2 : IFCR_CTEIF2_Field := 16#0#;
-- Write-only. Channel 3 Global interrupt clear
CGIF3 : IFCR_CGIF3_Field := 16#0#;
-- Write-only. Channel 3 Transfer Complete clear
CTCIF3 : IFCR_CTCIF3_Field := 16#0#;
-- Write-only. Channel 3 Half Transfer clear
CHTIF3 : IFCR_CHTIF3_Field := 16#0#;
-- Write-only. Channel 3 Transfer Error clear
CTEIF3 : IFCR_CTEIF3_Field := 16#0#;
-- Write-only. Channel 4 Global interrupt clear
CGIF4 : IFCR_CGIF4_Field := 16#0#;
-- Write-only. Channel 4 Transfer Complete clear
CTCIF4 : IFCR_CTCIF4_Field := 16#0#;
-- Write-only. Channel 4 Half Transfer clear
CHTIF4 : IFCR_CHTIF4_Field := 16#0#;
-- Write-only. Channel 4 Transfer Error clear
CTEIF4 : IFCR_CTEIF4_Field := 16#0#;
-- Write-only. Channel 5 Global interrupt clear
CGIF5 : IFCR_CGIF5_Field := 16#0#;
-- Write-only. Channel 5 Transfer Complete clear
CTCIF5 : IFCR_CTCIF5_Field := 16#0#;
-- Write-only. Channel 5 Half Transfer clear
CHTIF5 : IFCR_CHTIF5_Field := 16#0#;
-- Write-only. Channel 5 Transfer Error clear
CTEIF5 : IFCR_CTEIF5_Field := 16#0#;
-- Write-only. Channel 6 Global interrupt clear
CGIF6 : IFCR_CGIF6_Field := 16#0#;
-- Write-only. Channel 6 Transfer Complete clear
CTCIF6 : IFCR_CTCIF6_Field := 16#0#;
-- Write-only. Channel 6 Half Transfer clear
CHTIF6 : IFCR_CHTIF6_Field := 16#0#;
-- Write-only. Channel 6 Transfer Error clear
CTEIF6 : IFCR_CTEIF6_Field := 16#0#;
-- Write-only. Channel 7 Global interrupt clear
CGIF7 : IFCR_CGIF7_Field := 16#0#;
-- Write-only. Channel 7 Transfer Complete clear
CTCIF7 : IFCR_CTCIF7_Field := 16#0#;
-- Write-only. Channel 7 Half Transfer clear
CHTIF7 : IFCR_CHTIF7_Field := 16#0#;
-- Write-only. Channel 7 Transfer Error clear
CTEIF7 : IFCR_CTEIF7_Field := 16#0#;
-- unspecified
Reserved_28_31 : STM32_SVD.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for IFCR_Register use record
CGIF1 at 0 range 0 .. 0;
CTCIF1 at 0 range 1 .. 1;
CHTIF1 at 0 range 2 .. 2;
CTEIF1 at 0 range 3 .. 3;
CGIF2 at 0 range 4 .. 4;
CTCIF2 at 0 range 5 .. 5;
CHTIF2 at 0 range 6 .. 6;
CTEIF2 at 0 range 7 .. 7;
CGIF3 at 0 range 8 .. 8;
CTCIF3 at 0 range 9 .. 9;
CHTIF3 at 0 range 10 .. 10;
CTEIF3 at 0 range 11 .. 11;
CGIF4 at 0 range 12 .. 12;
CTCIF4 at 0 range 13 .. 13;
CHTIF4 at 0 range 14 .. 14;
CTEIF4 at 0 range 15 .. 15;
CGIF5 at 0 range 16 .. 16;
CTCIF5 at 0 range 17 .. 17;
CHTIF5 at 0 range 18 .. 18;
CTEIF5 at 0 range 19 .. 19;
CGIF6 at 0 range 20 .. 20;
CTCIF6 at 0 range 21 .. 21;
CHTIF6 at 0 range 22 .. 22;
CTEIF6 at 0 range 23 .. 23;
CGIF7 at 0 range 24 .. 24;
CTCIF7 at 0 range 25 .. 25;
CHTIF7 at 0 range 26 .. 26;
CTEIF7 at 0 range 27 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype CCR_EN_Field is STM32_SVD.Bit;
subtype CCR_TCIE_Field is STM32_SVD.Bit;
subtype CCR_HTIE_Field is STM32_SVD.Bit;
subtype CCR_TEIE_Field is STM32_SVD.Bit;
subtype CCR_DIR_Field is STM32_SVD.Bit;
subtype CCR_CIRC_Field is STM32_SVD.Bit;
subtype CCR_PINC_Field is STM32_SVD.Bit;
subtype CCR_MINC_Field is STM32_SVD.Bit;
subtype CCR_PSIZE_Field is STM32_SVD.UInt2;
subtype CCR_MSIZE_Field is STM32_SVD.UInt2;
subtype CCR_PL_Field is STM32_SVD.UInt2;
subtype CCR_MEM2MEM_Field is STM32_SVD.Bit;
-- DMA channel configuration register (DMA_CCR)
type CCR_Register is record
-- Channel enable
EN : CCR_EN_Field := 16#0#;
-- Transfer complete interrupt enable
TCIE : CCR_TCIE_Field := 16#0#;
-- Half Transfer interrupt enable
HTIE : CCR_HTIE_Field := 16#0#;
-- Transfer error interrupt enable
TEIE : CCR_TEIE_Field := 16#0#;
-- Data transfer direction
DIR : CCR_DIR_Field := 16#0#;
-- Circular mode
CIRC : CCR_CIRC_Field := 16#0#;
-- Peripheral increment mode
PINC : CCR_PINC_Field := 16#0#;
-- Memory increment mode
MINC : CCR_MINC_Field := 16#0#;
-- Peripheral size
PSIZE : CCR_PSIZE_Field := 16#0#;
-- Memory size
MSIZE : CCR_MSIZE_Field := 16#0#;
-- Channel Priority level
PL : CCR_PL_Field := 16#0#;
-- Memory to memory mode
MEM2MEM : CCR_MEM2MEM_Field := 16#0#;
-- unspecified
Reserved_15_31 : STM32_SVD.UInt17 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CCR_Register use record
EN at 0 range 0 .. 0;
TCIE at 0 range 1 .. 1;
HTIE at 0 range 2 .. 2;
TEIE at 0 range 3 .. 3;
DIR at 0 range 4 .. 4;
CIRC at 0 range 5 .. 5;
PINC at 0 range 6 .. 6;
MINC at 0 range 7 .. 7;
PSIZE at 0 range 8 .. 9;
MSIZE at 0 range 10 .. 11;
PL at 0 range 12 .. 13;
MEM2MEM at 0 range 14 .. 14;
Reserved_15_31 at 0 range 15 .. 31;
end record;
subtype CNDTR_NDT_Field is STM32_SVD.UInt16;
-- DMA channel 1 number of data register
type CNDTR_Register is record
-- Number of data to transfer
NDT : CNDTR_NDT_Field := 16#0#;
-- unspecified
Reserved_16_31 : STM32_SVD.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CNDTR_Register use record
NDT at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- DMA controller
type DMA_Peripheral is record
-- DMA interrupt status register (DMA_ISR)
ISR : aliased ISR_Register;
-- DMA interrupt flag clear register (DMA_IFCR)
IFCR : aliased IFCR_Register;
-- DMA channel configuration register (DMA_CCR)
CCR1 : aliased CCR_Register;
-- DMA channel 1 number of data register
CNDTR1 : aliased CNDTR_Register;
-- DMA channel 1 peripheral address register
CPAR1 : aliased STM32_SVD.UInt32;
-- DMA channel 1 memory address register
CMAR1 : aliased STM32_SVD.UInt32;
-- DMA channel configuration register (DMA_CCR)
CCR2 : aliased CCR_Register;
-- DMA channel 2 number of data register
CNDTR2 : aliased CNDTR_Register;
-- DMA channel 2 peripheral address register
CPAR2 : aliased STM32_SVD.UInt32;
-- DMA channel 2 memory address register
CMAR2 : aliased STM32_SVD.UInt32;
-- DMA channel configuration register (DMA_CCR)
CCR3 : aliased CCR_Register;
-- DMA channel 3 number of data register
CNDTR3 : aliased CNDTR_Register;
-- DMA channel 3 peripheral address register
CPAR3 : aliased STM32_SVD.UInt32;
-- DMA channel 3 memory address register
CMAR3 : aliased STM32_SVD.UInt32;
-- DMA channel configuration register (DMA_CCR)
CCR4 : aliased CCR_Register;
-- DMA channel 4 number of data register
CNDTR4 : aliased CNDTR_Register;
-- DMA channel 4 peripheral address register
CPAR4 : aliased STM32_SVD.UInt32;
-- DMA channel 4 memory address register
CMAR4 : aliased STM32_SVD.UInt32;
-- DMA channel configuration register (DMA_CCR)
CCR5 : aliased CCR_Register;
-- DMA channel 5 number of data register
CNDTR5 : aliased CNDTR_Register;
-- DMA channel 5 peripheral address register
CPAR5 : aliased STM32_SVD.UInt32;
-- DMA channel 5 memory address register
CMAR5 : aliased STM32_SVD.UInt32;
-- DMA channel configuration register (DMA_CCR)
CCR6 : aliased CCR_Register;
-- DMA channel 6 number of data register
CNDTR6 : aliased CNDTR_Register;
-- DMA channel 6 peripheral address register
CPAR6 : aliased STM32_SVD.UInt32;
-- DMA channel 6 memory address register
CMAR6 : aliased STM32_SVD.UInt32;
-- DMA channel configuration register (DMA_CCR)
CCR7 : aliased CCR_Register;
-- DMA channel 7 number of data register
CNDTR7 : aliased CNDTR_Register;
-- DMA channel 7 peripheral address register
CPAR7 : aliased STM32_SVD.UInt32;
-- DMA channel 7 memory address register
CMAR7 : aliased STM32_SVD.UInt32;
end record
with Volatile;
for DMA_Peripheral use record
ISR at 16#0# range 0 .. 31;
IFCR at 16#4# range 0 .. 31;
CCR1 at 16#8# range 0 .. 31;
CNDTR1 at 16#C# range 0 .. 31;
CPAR1 at 16#10# range 0 .. 31;
CMAR1 at 16#14# range 0 .. 31;
CCR2 at 16#1C# range 0 .. 31;
CNDTR2 at 16#20# range 0 .. 31;
CPAR2 at 16#24# range 0 .. 31;
CMAR2 at 16#28# range 0 .. 31;
CCR3 at 16#30# range 0 .. 31;
CNDTR3 at 16#34# range 0 .. 31;
CPAR3 at 16#38# range 0 .. 31;
CMAR3 at 16#3C# range 0 .. 31;
CCR4 at 16#44# range 0 .. 31;
CNDTR4 at 16#48# range 0 .. 31;
CPAR4 at 16#4C# range 0 .. 31;
CMAR4 at 16#50# range 0 .. 31;
CCR5 at 16#58# range 0 .. 31;
CNDTR5 at 16#5C# range 0 .. 31;
CPAR5 at 16#60# range 0 .. 31;
CMAR5 at 16#64# range 0 .. 31;
CCR6 at 16#6C# range 0 .. 31;
CNDTR6 at 16#70# range 0 .. 31;
CPAR6 at 16#74# range 0 .. 31;
CMAR6 at 16#78# range 0 .. 31;
CCR7 at 16#80# range 0 .. 31;
CNDTR7 at 16#84# range 0 .. 31;
CPAR7 at 16#88# range 0 .. 31;
CMAR7 at 16#8C# range 0 .. 31;
end record;
-- DMA controller
DMA_Periph : aliased DMA_Peripheral
with Import, Address => System'To_Address (16#40020000#);
end STM32_SVD.DMA;
|
AaronC98/PlaneSystem | Ada | 2,844 | ads | ------------------------------------------------------------------------------
-- Ada Web Server --
-- --
-- Copyright (C) 2000-2012, AdaCore --
-- --
-- This library is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 3, or (at your option) any --
-- later version. This library is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
------------------------------------------------------------------------------
with AWS.Response;
package AWS.Communication.Client is
function Send_Message
(Server : String;
Port : Positive;
Name : String;
Parameters : Parameter_Set := Null_Parameter_Set)
return Response.Data;
-- Send a message to server with a set of parameters. The destination is
-- server is http://Server:Port, the message name is Name and the set of
-- parameters is to be found into Parameters.
--
-- The complete message format is:
--
-- http://<Server>:<Port>/AWS_Com?HOST=<host>&NAME=<name>
-- &P1=<param1>&P2=<param2>
end AWS.Communication.Client;
|
reznikmm/matreshka | Ada | 9,016 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with League.Application;
with League.Characters;
with Matreshka.Internals.Settings.Fallbacks;
with Matreshka.Internals.Settings.Registry;
package body Matreshka.Internals.Settings.Registry_Managers is
Unknown_Organization : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("\Unknown Organization");
Organization_Defaults : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("\OrganizationDefaults");
HKEY_CURRENT_USER_Prefix : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("\HKEY_CURRENT_USER");
HKEY_LOCAL_MACHINE_Prefix : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("\HKEY_LOCAL_MACHINE");
------------
-- Create --
------------
overriding function Create
(Self : not null access Registry_Manager)
return not null Settings_Access
is
use type League.Strings.Universal_String;
Prefix : League.Strings.Universal_String
:= League.Strings.To_Universal_String ("\Software");
Organization_Path : League.Strings.Universal_String;
Application_Path : League.Strings.Universal_String;
begin
if League.Application.Organization_Name.Is_Empty then
Prefix.Append (Unknown_Organization);
else
Prefix.Append ('\');
Prefix.Append (League.Application.Organization_Name);
end if;
Organization_Path := Prefix;
Organization_Path.Append (Organization_Defaults);
Application_Path := Prefix;
Application_Path.Append ('\');
Application_Path.Append (League.Application.Application_Name);
return Aux : constant not null Settings_Access
:= Matreshka.Internals.Settings.Fallbacks.Create (Self)
do
declare
Proxy : Fallbacks.Fallback_Settings'Class
renames Fallbacks.Fallback_Settings'Class (Aux.all);
begin
if not League.Application.Application_Name.Is_Empty then
Proxy.Add
(Matreshka.Internals.Settings.Registry.Create
(Self, HKEY_CURRENT_USER_Prefix & Application_Path, False));
end if;
Proxy.Add
(Matreshka.Internals.Settings.Registry.Create
(Self, HKEY_CURRENT_USER_Prefix & Organization_Path, True));
if not League.Application.Application_Name.Is_Empty then
Proxy.Add
(Matreshka.Internals.Settings.Registry.Create
(Self,
HKEY_LOCAL_MACHINE_Prefix & Application_Path,
True));
end if;
Proxy.Add
(Matreshka.Internals.Settings.Registry.Create
(Self, HKEY_LOCAL_MACHINE_Prefix & Organization_Path, True));
end;
end return;
end Create;
------------
-- Create --
------------
overriding function Create
(Self : not null access Registry_Manager;
File_Name : League.Strings.Universal_String)
return not null Settings_Access is
begin
return
Matreshka.Internals.Settings.Registry.Create (Self, File_Name, True);
end Create;
------------
-- Create --
------------
overriding function Create
(Self : not null access Registry_Manager;
Organization_Name : League.Strings.Universal_String;
Organization_Domain : League.Strings.Universal_String;
Application_Name : League.Strings.Universal_String)
return not null Settings_Access
is
pragma Unreferenced (Organization_Domain);
use type League.Strings.Universal_String;
Prefix : League.Strings.Universal_String
:= League.Strings.To_Universal_String ("\Software");
Organization_Path : League.Strings.Universal_String;
Application_Path : League.Strings.Universal_String;
begin
if Organization_Name.Is_Empty then
Prefix.Append (Unknown_Organization);
else
Prefix.Append ('\');
Prefix.Append (Organization_Name);
end if;
Organization_Path := Prefix;
Organization_Path.Append (Organization_Defaults);
Application_Path := Prefix;
Application_Path.Append ('\');
Application_Path.Append (Application_Name);
if not Application_Name.Is_Empty then
return
Matreshka.Internals.Settings.Registry.Create
(Self, HKEY_CURRENT_USER_Prefix & Application_Path, False);
else
return
Matreshka.Internals.Settings.Registry.Create
(Self, HKEY_CURRENT_USER_Prefix & Organization_Path, False);
end if;
end Create;
--------------------
-- To_Storage_Key --
--------------------
overriding function To_Storage_Key
(Self : not null access Registry_Manager;
Key : League.Strings.Universal_String)
return League.Strings.Universal_String
is
use type League.Characters.Universal_Character;
Backslash : Boolean := False;
begin
return Result : League.Strings.Universal_String do
for J in 1 .. Key.Length loop
if Key.Element (J) = '/' or Key.Element (J) = '\' then
Backslash := True;
else
if Backslash then
if not Result.Is_Empty then
Result.Append ('\');
end if;
Backslash := False;
end if;
Result.Append (Key.Element (J));
end if;
end loop;
end return;
end To_Storage_Key;
end Matreshka.Internals.Settings.Registry_Managers;
|
zhmu/ananas | Ada | 959 | adb | -- { dg-do run }
with Init4; use Init4;
with Ada.Numerics; use Ada.Numerics;
with Text_IO; use Text_IO;
with Dump;
procedure Q4 is
A1 : R1 := My_R1;
B1 : R1 := My_R1;
A2 : R2 := My_R2;
B2 : R2 := My_R2;
begin
Put ("A1 :");
Dump (A1'Address, R1'Max_Size_In_Storage_Elements);
New_Line;
-- { dg-output "A1 : db 0f 49 40.*\n" }
Put ("B1 :");
Dump (B1'Address, R1'Max_Size_In_Storage_Elements);
New_Line;
-- { dg-output "B1 : db 0f 49 40.*\n" }
Put ("A2 :");
Dump (A2'Address, R2'Max_Size_In_Storage_Elements);
New_Line;
-- { dg-output "A2 : 40 49 0f db.*\n" }
Put ("B2 :");
Dump (B2'Address, R2'Max_Size_In_Storage_Elements);
New_Line;
-- { dg-output "B2 : 40 49 0f db.*\n" }
if A1.F /= B1.F then
raise Program_Error;
end if;
if A1.F /= Pi then
raise Program_Error;
end if;
if A2.F /= B2.F then
raise Program_Error;
end if;
if A2.F /= Pi then
raise Program_Error;
end if;
end;
|
BrickBot/Bound-T-H8-300 | Ada | 12,755 | ads | -- Flow.Origins (decl)
--
-- Propagation of value origins (definitions) in a a flow-graph associated
-- with a computation model that attaches definitions and uses of cells to
-- flow steps and arithmetic preconditions to flow edges. The result is
-- information about the overall transfer relation of the computation, in
-- particular about the invariance of certain cells across the whole
-- computation (entry to exit) and over loop bodies (separately for repeat
-- iterations and overall).
--
-- This analysis concentrates on "copy" assignments of the form x := y
-- where the right-hand-side (y) is a single cell. The target cell (x)
-- is then considered to have the same origin as the right-hand-side (y).
--
-- Any assignment where the right-hand-side is a more complex expression is
-- considered to yield an unknown value and becomes the origin for the
-- target cell at this point.
--
-- When two or more different origins for the same cell flow into the
-- same point in the flow-graph, a "merge" origin is defined for this cell
-- at this point. (This corresponds to "phi" functions in "static single
-- assignment" form.)
--
-- This analysis has four main purposes:
--
-- > To detect cells that are preserved (invariant) in any execution of
-- the flow-graph (any call of the subprogram), even though the
-- computation uses and assigns these cells. Such cells are often
-- "callee-save" registers. The analysis of the caller often depends
-- critically on knowing which caller cells are preserved across the
-- call.
--
-- > To detect cells that are preserved (invariant) in a loop, so that
-- the loop can be analysed using the initial values of these cells.
--
-- > To bound certain boundable elements of the subprogram based on
-- knowing that some relevant cells hold certain values from the
-- entry to the subprogram. For example, a dynamic jump to a register
-- that holds the return address can be resolved into a return from
-- the subprogram.
--
-- > Finally, the analysis results can be passed to a target-specific
-- procedure that may use them for any purpose.
--
-- The analysis can also report that the input value of a cell ends up
-- as the output value of another cell (invariance of value but change
-- of storage location). For example, the effect of a function that swaps
-- the values of its two input parameters can be reported exactly.
--
-- The result of this analysis is valid only for the given control-
-- flow graph. If the flow-graph contains unresolved dynamic flow,
-- which is later resolved to add edges that create more paths from
-- some (new or existing) value assignments to existing value uses,
-- these new paths may invalidate the results of this analysis. To
-- be precise, the origins in the old analysis should still be possible
-- origins in the new flow-graph, but new origins may appear, too.
--
-- This analysis is path-sensitive but not context-sensitive. It does
-- not use any information about the numerical values of cells on
-- entry to the flow-graph or within the flow-graph, nor does it use
-- the edge preconditions but assumes that all feasible edges can be
-- taken (that is, only edges with "Never" preconditions are omitted
-- from the analysed paths).
--
-- Volatile cells are almost completely omitted from this analysis.
-- The origins of volatile cells are not analysed. If a non-volatile
-- cell is assigned the value of a volatile cell, this assignment
-- becomes the origin of the value of the target cell, and the value
-- assigned is considered unknown (that is, the volatile cell is
-- considered a "complex expression", not a simple copy).
--
-- A component of the Bound-T Worst-Case Execution Time Tool.
--
-------------------------------------------------------------------------------
-- Copyright (c) 1999 .. 2015 Tidorum Ltd
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice, this
-- list of conditions and the following disclaimer.
-- 2. Redistributions in binary form must reproduce the above copyright notice,
-- this list of conditions and the following disclaimer in the documentation
-- and/or other materials provided with the distribution.
--
-- This software is provided by the copyright holders and contributors "as is" and
-- any express or implied warranties, including, but not limited to, the implied
-- warranties of merchantability and fitness for a particular purpose are
-- disclaimed. In no event shall the copyright owner or contributors be liable for
-- any direct, indirect, incidental, special, exemplary, or consequential damages
-- (including, but not limited to, procurement of substitute goods or services;
-- loss of use, data, or profits; or business interruption) however caused and
-- on any theory of liability, whether in contract, strict liability, or tort
-- (including negligence or otherwise) arising in any way out of the use of this
-- software, even if advised of the possibility of such damage.
--
-- Other modules (files) of this software composition should contain their
-- own copyright statements, which may have different copyright and usage
-- conditions. The above conditions apply to this file.
-------------------------------------------------------------------------------
--
-- $Revision: 1.11 $
-- $Date: 2015/10/24 19:36:49 $
--
-- $Log: flow-origins.ads,v $
-- Revision 1.11 2015/10/24 19:36:49 niklas
-- Moved to free licence.
--
-- Revision 1.10 2013/12/08 22:05:57 niklas
-- BT-CH-0259: Storing value-origin analysis results in execution bounds.
--
-- Revision 1.9 2013-02-19 09:17:26 niklas
-- BT-CH-0245 clean-up. Only descriptions changed.
--
-- Revision 1.8 2013-02-12 08:47:19 niklas
-- BT-CH-0245: Global volatile cells and "volatile" assertions.
--
-- Revision 1.7 2008-12-25 09:00:34 niklas
-- Moved context clause for Storage.Cell_Numbering to body.
--
-- Revision 1.6 2007/04/18 18:34:39 niklas
-- BT-CH-0057.
--
-- Revision 1.5 2007/03/29 15:18:03 niklas
-- BT-CH-0056.
--
-- Revision 1.4 2007/01/13 13:51:04 niklas
-- BT-CH-0041.
--
-- Revision 1.3 2006/11/20 20:20:19 niklas
-- BT-CH-0037.
--
-- Revision 1.2 2006/10/24 08:44:31 niklas
-- BT-CH-0028.
--
-- Revision 1.1 2005/05/09 15:24:23 niklas
-- First version.
--
--:dbpool with GNAT.Debug_Pools;
with Flow.Computation;
with Programs;
with Symbols;
package Flow.Origins is
--
--- Results of the analysis
--
type Origin_Kind_T is (
Initial,
Assigned,
Merged);
--
-- We consider three kinds of origins (sources) for the values
-- of cells.
--
-- Initial
-- The value is the initial value of the cell on entry to the
-- subprogram under analysis.
-- Assigned
-- The value is computed in a step and assigned to the cell in
-- the step's effect.
-- Merged
-- The value flows into a step from several predecessor steps
-- such that not all predecessors have the same origin for
-- the value. In other words, the value has multiple origins
-- from the multiple paths into this step.
type Origin_T is record
Kind : Origin_Kind_T;
Cell : Storage.Cell_T;
Step : Step_T;
end record;
--
-- The origin of a value.
--
-- Kind
-- The kind of origin (how the value is defined).
-- Cell
-- The original cell that holds the value, at the point of origin.
-- Step
-- The point of origin.
-- When Kind = Initial this is the entry step of the flow-graph.
-- When Kind = Assigned this is the step that assigns the value
-- to the Cell.
-- When Kind = Merged this is the step at which the multiple
-- origins converge and are merged.
function Image (Item : Origin_T) return String;
--
-- Displaying the origin for tracing purposes.
type Map_Ref is private;
--
-- The results of the value-origin analysis: a mapping of cells to the
-- origins of their values.
--
-- This type has reference semantics. It represents several
-- dynamically (heap-) allocated objects and therefore needs
-- to be discarded when no longer needed.
--
-- The analysis results can be null, that is, absent.
function Is_Valid (Item : Map_Ref) return Boolean;
--
-- Whether the given analysis results are valid and not "null".
procedure Analyse (
Computation : in Flow.Computation.Model_Ref;
Giving : out Map_Ref);
--
-- Finds the origin of each cell at each step in the subprogram under
-- the given Computation model. The analysis is controlled by the options
-- in Flow.Origins.Opt and can be entirely disabled by those options.
--
-- The effect of any calls from the subprogram is assumed to be represented
-- in the effect of the call-steps under the model.
--
-- Only those parts of the flow-graph that are feasible in this Computation
-- model are used and represented in the analysis result.
--
-- Responsibility for the dynamically allocated memory holding the
-- analysis results is given to the caller, who should Discard the
-- analysis when the caller no longer needs it.
--
-- The result can be non-valid, in particular if the options entirely
-- disable value-origin analysis. In that case, a Discard is not
-- necessary (but does no harm).
procedure Discard (Item : in out Map_Ref);
--
-- Discards (deallocates) all the dynamically allocated memory forming
-- the given value-origin map. The map becomes non-valid and must not
-- be used thereafter, until the object is reconstructed with the
-- Analyse procedure.
function Computation (Under : Map_Ref)
return Flow.Computation.Model_Handle_T;
--
-- The computation model Underlying the given value-origin results.
-- Note that if the computation model is changed, throught the handle
-- here returned, the results of the value-origin analysis may become
-- invalid for the new computation model.
function Symbol_Table (Under : Map_Ref)
return Symbols.Symbol_Table_T;
--
-- The symbol-table for the program which contains the subprogram on
-- which the given value-origin was applied.
function All_Cells (Under : Map_Ref)
return Storage.Cell_List_T;
--
-- All the cells for which Origin_Is_Known, Under the given
-- value-origin map, listed in some unspecified order.
function Origin_Is_Known (
Cell : Storage.Cell_T;
From : Map_Ref)
return Boolean;
--
-- Whether the origin of the given Cell is known From the given
-- value-origin map (at each and every step in the flow-graph).
function Origin_After (
Step : Step_T;
Cell : Storage.Cell_T;
From : Map_Ref)
return Origin_T;
--
-- The origin of the value of the given Cell, after the execution
-- of the given Step (on exit from the Step), as derived From the
-- value-origin map.
--
-- Precondition: Origin_Is_Known (Cell, From).
function Origin_Before (
Step : Step_T;
Cell : Storage.Cell_T;
From : Map_Ref)
return Origin_T;
--
-- The origin of the value of the given Cell, before the execution
-- of the given Step (on entry to the Step), as derived From the
-- value-origin map.
--
-- Precondition: Origin_Is_Known (Cell, From).
--
-- Note that the returned Origin_T is not necessarily one of the
-- origins listed in From. If the Step has more than one feasible
-- predecessor, and different origins of the cell flow from some
-- predecessors, a new Merged origin is returned.
function Has_Same_Value (
After : Step_T;
Before : Step_T;
Expr : Arithmetic.Expr_Ref;
From : Map_Ref)
return Boolean;
--
-- Whether the given Expr is sure to have the same value when
-- evaluated After a given step as when evaluated Before another
-- step. This is the case iff every cell used in the Expr has the
-- same Origin_After After as its Origin_Before (Before), and
-- moreover the Expr has no unresolved dynamic references (we
-- could not check if the unknown target of the unresolved
-- reference has the same value after After and before Before).
private
type Map_Object_T (Steps : Positive);
--
-- The results of value-origin analysis.
--
-- Steps
-- The number of steps in the flow-graph that was analysed.
type Map_Ref is access Map_Object_T;
--:dbpool Map_Pool : GNAT.Debug_Pools.Debug_Pool;
--:dbpool for Map_Ref'Storage_Pool use Map_Pool;
end Flow.Origins;
|
msrLi/portingSources | Ada | 832 | adb | -- Copyright 2010-2014 Free Software Foundation, Inc.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Pck; use Pck;
procedure Foo is
Q: Rec;
begin
Q := Bar; -- STOP HERE
Do_Nothing (Q'Address);
end Foo;
|
BrickBot/Bound-T-H8-300 | Ada | 2,826 | adb | -- Options.Files (body)
--
-- A component of the Bound-T Worst-Case Execution Time Tool.
--
-------------------------------------------------------------------------------
-- Copyright (c) 1999 .. 2015 Tidorum Ltd
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice, this
-- list of conditions and the following disclaimer.
-- 2. Redistributions in binary form must reproduce the above copyright notice,
-- this list of conditions and the following disclaimer in the documentation
-- and/or other materials provided with the distribution.
--
-- This software is provided by the copyright holders and contributors "as is" and
-- any express or implied warranties, including, but not limited to, the implied
-- warranties of merchantability and fitness for a particular purpose are
-- disclaimed. In no event shall the copyright owner or contributors be liable for
-- any direct, indirect, incidental, special, exemplary, or consequential damages
-- (including, but not limited to, procurement of substitute goods or services;
-- loss of use, data, or profits; or business interruption) however caused and
-- on any theory of liability, whether in contract, strict liability, or tort
-- (including negligence or otherwise) arising in any way out of the use of this
-- software, even if advised of the possibility of such damage.
--
-- Other modules (files) of this software composition should contain their
-- own copyright statements, which may have different copyright and usage
-- conditions. The above conditions apply to this file.
-------------------------------------------------------------------------------
--
-- $Revision: 1.3 $
-- $Date: 2015/10/24 20:05:50 $
--
-- $Log: options-files.adb,v $
-- Revision 1.3 2015/10/24 20:05:50 niklas
-- Moved to free licence.
--
-- Revision 1.2 2012-02-05 19:33:14 niklas
-- Added Set function. Default can be non-null.
--
-- Revision 1.1 2011-09-06 17:41:10 niklas
-- First version.
--
with Ada.Strings.Unbounded;
package body Options.Files is
use Ada.Strings.Unbounded;
overriding
function Type_And_Default (Option : access Option_T)
return String
is
begin
if Length (Option.Default) = 0 then
return "A file-name, default none";
else
return "A file-name, default """ & To_String (Option.Default) & '"';
end if;
end Type_And_Default;
overriding
function Set (Value : String) return Option_T
is
begin
return (
Set => True,
Default => To_Unbounded_String (Value),
Value => To_Unbounded_String (Value));
end Set;
end Options.Files;
|
reznikmm/gela | Ada | 3,977 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2012, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.Internals.Unicode;
package Abstract_Sources is
pragma Preelaborate;
subtype Code_Unit_32 is Matreshka.Internals.Unicode.Code_Unit_32;
type Abstract_Source is limited interface;
Error : constant Code_Unit_32 := 16#7FFFFFFF#;
End_Of_Input : constant Code_Unit_32 := 16#7FFFFFFE#;
End_Of_Data : constant Code_Unit_32 := 16#7FFFFFFD#;
End_Of_Buffer : constant Code_Unit_32 := 16#7FFFFFFC#;
type Source_Access is access all Abstract_Source'Class;
not overriding function Get_Next
(Self : not null access Abstract_Source) return Code_Unit_32 is abstract;
end Abstract_Sources;
|
reznikmm/matreshka | Ada | 4,696 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Table.Use_First_Row_Styles_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Table_Use_First_Row_Styles_Attribute_Node is
begin
return Self : Table_Use_First_Row_Styles_Attribute_Node do
Matreshka.ODF_Table.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Table_Prefix);
end return;
end Create;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Table_Use_First_Row_Styles_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Use_First_Row_Styles_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Table_URI,
Matreshka.ODF_String_Constants.Use_First_Row_Styles_Attribute,
Table_Use_First_Row_Styles_Attribute_Node'Tag);
end Matreshka.ODF_Table.Use_First_Row_Styles_Attributes;
|
jrcarter/Ada_GUI | Ada | 4,094 | ads | -- --
-- package Strings_Edit.Quoted Copyright (c) Dmitry A. Kazakov --
-- Interface Luebeck --
-- Summer, 2004 --
-- --
-- Last revision : 11:50 30 May 2014 --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU General Public License as --
-- published by the Free Software Foundation; either version 2 of --
-- the License, or (at your option) any later version. This library --
-- is distributed in the hope that it will be useful, but WITHOUT --
-- ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. You should have --
-- received a copy of the GNU General Public License along with --
-- this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- 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. --
--____________________________________________________________________--
package Strings_Edit.Quoted is
--
-- Get_Quoted -- Get a quoted text from string
--
-- Source - The string
-- Pointer - To where the name begins (a pointer to)
-- Mark - Quotation marks character
--
-- This function is used to get a quoted string. String (Pointer.all) is
-- the first character of the string. Pointer is advanced to the the
-- first character following the input. The parameter Marks specifies
-- the quotation marks to use. Within the string body this character is
-- GDoubled.
--
-- Returns :
--
-- The quoted string with quotation marks stripped off
--
-- Exceptions :
--
-- Data_Error - Syntax error
-- Layout_Error - Pointer.all is not in Source'First..Source'Last + 1
--
function Get_Quoted
( Source : String;
Pointer : access Integer;
Mark : Character := '"'
) return String;
--
-- Put_Quoted -- Put a quoted string
--
-- Destination - The output string
-- Pointer - To where the name to put
-- Text - The text to be put
-- Mark - The quotation mark character
--
-- This procedure puts Text in Mark quotes and stores it starting with
-- String (Pointer). Pointer value is advanced to the the first
-- character following the output. Mark characters are GDoubled within
-- the string body.
--
-- Exceptions :
--
-- Layout_Error - No room for output or Pointer is not in
-- Source'First..Source'Last + 1
--
procedure Put_Quoted
( Destination : in out String;
Pointer : in out Integer;
Text : String;
Mark : Character := '"';
Field : Natural := 0;
Justify : Alignment := Left;
Fill : Character := ' '
);
--
-- Quote -- A string
--
-- Text - The string
-- Mark - The quotation mark character
--
-- Returns :
--
-- Quited text
--
function Quote (Text : String; Mark : Character := '"')
return String;
end Strings_Edit.Quoted;
|
reznikmm/matreshka | Ada | 3,739 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with XML.DOM.Attributes;
package ODF.DOM.Table_Contains_Error_Attributes is
pragma Preelaborate;
type ODF_Table_Contains_Error_Attribute is limited interface
and XML.DOM.Attributes.DOM_Attribute;
type ODF_Table_Contains_Error_Attribute_Access is
access all ODF_Table_Contains_Error_Attribute'Class
with Storage_Size => 0;
end ODF.DOM.Table_Contains_Error_Attributes;
|
reznikmm/matreshka | Ada | 3,738 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with ODF.Constants;
package body Matreshka.ODF_Attributes.SVG is
-----------------------
-- Get_Namespace_URI --
-----------------------
overriding function Get_Namespace_URI
(Self : not null access constant SVG_Node_Base)
return League.Strings.Universal_String is
begin
return ODF.Constants.SVG_URI;
end Get_Namespace_URI;
end Matreshka.ODF_Attributes.SVG;
|
HackInvent/Ada_Drivers_Library | Ada | 26,209 | ads | -- This spec has been automatically generated from STM32H7x3.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with System;
package STM32_SVD.CRYP is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype CR_ALGOMODE0_Field is STM32_SVD.UInt3;
subtype CR_DATATYPE_Field is STM32_SVD.UInt2;
subtype CR_KEYSIZE_Field is STM32_SVD.UInt2;
subtype CR_GCM_CCMPH_Field is STM32_SVD.UInt2;
-- control register
type CR_Register is record
-- unspecified
Reserved_0_1 : STM32_SVD.UInt2 := 16#0#;
-- Algorithm direction
ALGODIR : Boolean := False;
-- Algorithm mode
ALGOMODE0 : CR_ALGOMODE0_Field := 16#0#;
-- Data type selection
DATATYPE : CR_DATATYPE_Field := 16#0#;
-- Key size selection (AES mode only)
KEYSIZE : CR_KEYSIZE_Field := 16#0#;
-- unspecified
Reserved_10_13 : STM32_SVD.UInt4 := 16#0#;
-- Write-only. FIFO flush
FFLUSH : Boolean := False;
-- Cryptographic processor enable
CRYPEN : Boolean := False;
-- GCM_CCMPH
GCM_CCMPH : CR_GCM_CCMPH_Field := 16#0#;
-- unspecified
Reserved_18_18 : STM32_SVD.Bit := 16#0#;
-- ALGOMODE
ALGOMODE3 : Boolean := False;
-- unspecified
Reserved_20_31 : STM32_SVD.UInt12 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CR_Register use record
Reserved_0_1 at 0 range 0 .. 1;
ALGODIR at 0 range 2 .. 2;
ALGOMODE0 at 0 range 3 .. 5;
DATATYPE at 0 range 6 .. 7;
KEYSIZE at 0 range 8 .. 9;
Reserved_10_13 at 0 range 10 .. 13;
FFLUSH at 0 range 14 .. 14;
CRYPEN at 0 range 15 .. 15;
GCM_CCMPH at 0 range 16 .. 17;
Reserved_18_18 at 0 range 18 .. 18;
ALGOMODE3 at 0 range 19 .. 19;
Reserved_20_31 at 0 range 20 .. 31;
end record;
-- status register
type SR_Register is record
-- Read-only. Input FIFO empty
IFEM : Boolean;
-- Read-only. Input FIFO not full
IFNF : Boolean;
-- Read-only. Output FIFO not empty
OFNE : Boolean;
-- Read-only. Output FIFO full
OFFU : Boolean;
-- Read-only. Busy bit
BUSY : Boolean;
-- unspecified
Reserved_5_31 : STM32_SVD.UInt27;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for SR_Register use record
IFEM at 0 range 0 .. 0;
IFNF at 0 range 1 .. 1;
OFNE at 0 range 2 .. 2;
OFFU at 0 range 3 .. 3;
BUSY at 0 range 4 .. 4;
Reserved_5_31 at 0 range 5 .. 31;
end record;
-- DMA control register
type DMACR_Register is record
-- DMA input enable
DIEN : Boolean := False;
-- DMA output enable
DOEN : Boolean := False;
-- unspecified
Reserved_2_31 : STM32_SVD.UInt30 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for DMACR_Register use record
DIEN at 0 range 0 .. 0;
DOEN at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-- interrupt mask set/clear register
type IMSCR_Register is record
-- Input FIFO service interrupt mask
INIM : Boolean := False;
-- Output FIFO service interrupt mask
OUTIM : Boolean := False;
-- unspecified
Reserved_2_31 : STM32_SVD.UInt30 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for IMSCR_Register use record
INIM at 0 range 0 .. 0;
OUTIM at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-- raw interrupt status register
type RISR_Register is record
-- Read-only. Input FIFO service raw interrupt status
INRIS : Boolean;
-- Read-only. Output FIFO service raw interrupt status
OUTRIS : Boolean;
-- unspecified
Reserved_2_31 : STM32_SVD.UInt30;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for RISR_Register use record
INRIS at 0 range 0 .. 0;
OUTRIS at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-- masked interrupt status register
type MISR_Register is record
-- Read-only. Input FIFO service masked interrupt status
INMIS : Boolean;
-- Read-only. Output FIFO service masked interrupt status
OUTMIS : Boolean;
-- unspecified
Reserved_2_31 : STM32_SVD.UInt30;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MISR_Register use record
INMIS at 0 range 0 .. 0;
OUTMIS at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-- K0LR_b array
type K0LR_b_Field_Array is array (224 .. 255) of Boolean
with Component_Size => 1, Size => 32;
-- key registers
type K0LR_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- b as a value
Val : STM32_SVD.UInt32;
when True =>
-- b as an array
Arr : K0LR_b_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for K0LR_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- K0RR_b array
type K0RR_b_Field_Array is array (192 .. 223) of Boolean
with Component_Size => 1, Size => 32;
-- key registers
type K0RR_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- b as a value
Val : STM32_SVD.UInt32;
when True =>
-- b as an array
Arr : K0RR_b_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for K0RR_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- K1LR_b array
type K1LR_b_Field_Array is array (160 .. 191) of Boolean
with Component_Size => 1, Size => 32;
-- key registers
type K1LR_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- b as a value
Val : STM32_SVD.UInt32;
when True =>
-- b as an array
Arr : K1LR_b_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for K1LR_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- K1RR_b array
type K1RR_b_Field_Array is array (128 .. 159) of Boolean
with Component_Size => 1, Size => 32;
-- key registers
type K1RR_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- b as a value
Val : STM32_SVD.UInt32;
when True =>
-- b as an array
Arr : K1RR_b_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for K1RR_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- K2LR_b array
type K2LR_b_Field_Array is array (96 .. 127) of Boolean
with Component_Size => 1, Size => 32;
-- key registers
type K2LR_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- b as a value
Val : STM32_SVD.UInt32;
when True =>
-- b as an array
Arr : K2LR_b_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for K2LR_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- K2RR_b array
type K2RR_b_Field_Array is array (64 .. 95) of Boolean
with Component_Size => 1, Size => 32;
-- key registers
type K2RR_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- b as a value
Val : STM32_SVD.UInt32;
when True =>
-- b as an array
Arr : K2RR_b_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for K2RR_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- K3LR_b array
type K3LR_b_Field_Array is array (32 .. 63) of Boolean
with Component_Size => 1, Size => 32;
-- key registers
type K3LR_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- b as a value
Val : STM32_SVD.UInt32;
when True =>
-- b as an array
Arr : K3LR_b_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for K3LR_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- K3RR_b array
type K3RR_b_Field_Array is array (0 .. 31) of Boolean
with Component_Size => 1, Size => 32;
-- key registers
type K3RR_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- b as a value
Val : STM32_SVD.UInt32;
when True =>
-- b as an array
Arr : K3RR_b_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for K3RR_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
-- initialization vector registers
type IV0LR_Register is record
-- IV31
IV31 : Boolean := False;
-- IV30
IV30 : Boolean := False;
-- IV29
IV29 : Boolean := False;
-- IV28
IV28 : Boolean := False;
-- IV27
IV27 : Boolean := False;
-- IV26
IV26 : Boolean := False;
-- IV25
IV25 : Boolean := False;
-- IV24
IV24 : Boolean := False;
-- IV23
IV23 : Boolean := False;
-- IV22
IV22 : Boolean := False;
-- IV21
IV21 : Boolean := False;
-- IV20
IV20 : Boolean := False;
-- IV19
IV19 : Boolean := False;
-- IV18
IV18 : Boolean := False;
-- IV17
IV17 : Boolean := False;
-- IV16
IV16 : Boolean := False;
-- IV15
IV15 : Boolean := False;
-- IV14
IV14 : Boolean := False;
-- IV13
IV13 : Boolean := False;
-- IV12
IV12 : Boolean := False;
-- IV11
IV11 : Boolean := False;
-- IV10
IV10 : Boolean := False;
-- IV9
IV9 : Boolean := False;
-- IV8
IV8 : Boolean := False;
-- IV7
IV7 : Boolean := False;
-- IV6
IV6 : Boolean := False;
-- IV5
IV5 : Boolean := False;
-- IV4
IV4 : Boolean := False;
-- IV3
IV3 : Boolean := False;
-- IV2
IV2 : Boolean := False;
-- IV1
IV1 : Boolean := False;
-- IV0
IV0 : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for IV0LR_Register use record
IV31 at 0 range 0 .. 0;
IV30 at 0 range 1 .. 1;
IV29 at 0 range 2 .. 2;
IV28 at 0 range 3 .. 3;
IV27 at 0 range 4 .. 4;
IV26 at 0 range 5 .. 5;
IV25 at 0 range 6 .. 6;
IV24 at 0 range 7 .. 7;
IV23 at 0 range 8 .. 8;
IV22 at 0 range 9 .. 9;
IV21 at 0 range 10 .. 10;
IV20 at 0 range 11 .. 11;
IV19 at 0 range 12 .. 12;
IV18 at 0 range 13 .. 13;
IV17 at 0 range 14 .. 14;
IV16 at 0 range 15 .. 15;
IV15 at 0 range 16 .. 16;
IV14 at 0 range 17 .. 17;
IV13 at 0 range 18 .. 18;
IV12 at 0 range 19 .. 19;
IV11 at 0 range 20 .. 20;
IV10 at 0 range 21 .. 21;
IV9 at 0 range 22 .. 22;
IV8 at 0 range 23 .. 23;
IV7 at 0 range 24 .. 24;
IV6 at 0 range 25 .. 25;
IV5 at 0 range 26 .. 26;
IV4 at 0 range 27 .. 27;
IV3 at 0 range 28 .. 28;
IV2 at 0 range 29 .. 29;
IV1 at 0 range 30 .. 30;
IV0 at 0 range 31 .. 31;
end record;
-- initialization vector registers
type IV0RR_Register is record
-- IV63
IV63 : Boolean := False;
-- IV62
IV62 : Boolean := False;
-- IV61
IV61 : Boolean := False;
-- IV60
IV60 : Boolean := False;
-- IV59
IV59 : Boolean := False;
-- IV58
IV58 : Boolean := False;
-- IV57
IV57 : Boolean := False;
-- IV56
IV56 : Boolean := False;
-- IV55
IV55 : Boolean := False;
-- IV54
IV54 : Boolean := False;
-- IV53
IV53 : Boolean := False;
-- IV52
IV52 : Boolean := False;
-- IV51
IV51 : Boolean := False;
-- IV50
IV50 : Boolean := False;
-- IV49
IV49 : Boolean := False;
-- IV48
IV48 : Boolean := False;
-- IV47
IV47 : Boolean := False;
-- IV46
IV46 : Boolean := False;
-- IV45
IV45 : Boolean := False;
-- IV44
IV44 : Boolean := False;
-- IV43
IV43 : Boolean := False;
-- IV42
IV42 : Boolean := False;
-- IV41
IV41 : Boolean := False;
-- IV40
IV40 : Boolean := False;
-- IV39
IV39 : Boolean := False;
-- IV38
IV38 : Boolean := False;
-- IV37
IV37 : Boolean := False;
-- IV36
IV36 : Boolean := False;
-- IV35
IV35 : Boolean := False;
-- IV34
IV34 : Boolean := False;
-- IV33
IV33 : Boolean := False;
-- IV32
IV32 : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for IV0RR_Register use record
IV63 at 0 range 0 .. 0;
IV62 at 0 range 1 .. 1;
IV61 at 0 range 2 .. 2;
IV60 at 0 range 3 .. 3;
IV59 at 0 range 4 .. 4;
IV58 at 0 range 5 .. 5;
IV57 at 0 range 6 .. 6;
IV56 at 0 range 7 .. 7;
IV55 at 0 range 8 .. 8;
IV54 at 0 range 9 .. 9;
IV53 at 0 range 10 .. 10;
IV52 at 0 range 11 .. 11;
IV51 at 0 range 12 .. 12;
IV50 at 0 range 13 .. 13;
IV49 at 0 range 14 .. 14;
IV48 at 0 range 15 .. 15;
IV47 at 0 range 16 .. 16;
IV46 at 0 range 17 .. 17;
IV45 at 0 range 18 .. 18;
IV44 at 0 range 19 .. 19;
IV43 at 0 range 20 .. 20;
IV42 at 0 range 21 .. 21;
IV41 at 0 range 22 .. 22;
IV40 at 0 range 23 .. 23;
IV39 at 0 range 24 .. 24;
IV38 at 0 range 25 .. 25;
IV37 at 0 range 26 .. 26;
IV36 at 0 range 27 .. 27;
IV35 at 0 range 28 .. 28;
IV34 at 0 range 29 .. 29;
IV33 at 0 range 30 .. 30;
IV32 at 0 range 31 .. 31;
end record;
-- initialization vector registers
type IV1LR_Register is record
-- IV95
IV95 : Boolean := False;
-- IV94
IV94 : Boolean := False;
-- IV93
IV93 : Boolean := False;
-- IV92
IV92 : Boolean := False;
-- IV91
IV91 : Boolean := False;
-- IV90
IV90 : Boolean := False;
-- IV89
IV89 : Boolean := False;
-- IV88
IV88 : Boolean := False;
-- IV87
IV87 : Boolean := False;
-- IV86
IV86 : Boolean := False;
-- IV85
IV85 : Boolean := False;
-- IV84
IV84 : Boolean := False;
-- IV83
IV83 : Boolean := False;
-- IV82
IV82 : Boolean := False;
-- IV81
IV81 : Boolean := False;
-- IV80
IV80 : Boolean := False;
-- IV79
IV79 : Boolean := False;
-- IV78
IV78 : Boolean := False;
-- IV77
IV77 : Boolean := False;
-- IV76
IV76 : Boolean := False;
-- IV75
IV75 : Boolean := False;
-- IV74
IV74 : Boolean := False;
-- IV73
IV73 : Boolean := False;
-- IV72
IV72 : Boolean := False;
-- IV71
IV71 : Boolean := False;
-- IV70
IV70 : Boolean := False;
-- IV69
IV69 : Boolean := False;
-- IV68
IV68 : Boolean := False;
-- IV67
IV67 : Boolean := False;
-- IV66
IV66 : Boolean := False;
-- IV65
IV65 : Boolean := False;
-- IV64
IV64 : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for IV1LR_Register use record
IV95 at 0 range 0 .. 0;
IV94 at 0 range 1 .. 1;
IV93 at 0 range 2 .. 2;
IV92 at 0 range 3 .. 3;
IV91 at 0 range 4 .. 4;
IV90 at 0 range 5 .. 5;
IV89 at 0 range 6 .. 6;
IV88 at 0 range 7 .. 7;
IV87 at 0 range 8 .. 8;
IV86 at 0 range 9 .. 9;
IV85 at 0 range 10 .. 10;
IV84 at 0 range 11 .. 11;
IV83 at 0 range 12 .. 12;
IV82 at 0 range 13 .. 13;
IV81 at 0 range 14 .. 14;
IV80 at 0 range 15 .. 15;
IV79 at 0 range 16 .. 16;
IV78 at 0 range 17 .. 17;
IV77 at 0 range 18 .. 18;
IV76 at 0 range 19 .. 19;
IV75 at 0 range 20 .. 20;
IV74 at 0 range 21 .. 21;
IV73 at 0 range 22 .. 22;
IV72 at 0 range 23 .. 23;
IV71 at 0 range 24 .. 24;
IV70 at 0 range 25 .. 25;
IV69 at 0 range 26 .. 26;
IV68 at 0 range 27 .. 27;
IV67 at 0 range 28 .. 28;
IV66 at 0 range 29 .. 29;
IV65 at 0 range 30 .. 30;
IV64 at 0 range 31 .. 31;
end record;
-- initialization vector registers
type IV1RR_Register is record
-- IV127
IV127 : Boolean := False;
-- IV126
IV126 : Boolean := False;
-- IV125
IV125 : Boolean := False;
-- IV124
IV124 : Boolean := False;
-- IV123
IV123 : Boolean := False;
-- IV122
IV122 : Boolean := False;
-- IV121
IV121 : Boolean := False;
-- IV120
IV120 : Boolean := False;
-- IV119
IV119 : Boolean := False;
-- IV118
IV118 : Boolean := False;
-- IV117
IV117 : Boolean := False;
-- IV116
IV116 : Boolean := False;
-- IV115
IV115 : Boolean := False;
-- IV114
IV114 : Boolean := False;
-- IV113
IV113 : Boolean := False;
-- IV112
IV112 : Boolean := False;
-- IV111
IV111 : Boolean := False;
-- IV110
IV110 : Boolean := False;
-- IV109
IV109 : Boolean := False;
-- IV108
IV108 : Boolean := False;
-- IV107
IV107 : Boolean := False;
-- IV106
IV106 : Boolean := False;
-- IV105
IV105 : Boolean := False;
-- IV104
IV104 : Boolean := False;
-- IV103
IV103 : Boolean := False;
-- IV102
IV102 : Boolean := False;
-- IV101
IV101 : Boolean := False;
-- IV100
IV100 : Boolean := False;
-- IV99
IV99 : Boolean := False;
-- IV98
IV98 : Boolean := False;
-- IV97
IV97 : Boolean := False;
-- IV96
IV96 : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for IV1RR_Register use record
IV127 at 0 range 0 .. 0;
IV126 at 0 range 1 .. 1;
IV125 at 0 range 2 .. 2;
IV124 at 0 range 3 .. 3;
IV123 at 0 range 4 .. 4;
IV122 at 0 range 5 .. 5;
IV121 at 0 range 6 .. 6;
IV120 at 0 range 7 .. 7;
IV119 at 0 range 8 .. 8;
IV118 at 0 range 9 .. 9;
IV117 at 0 range 10 .. 10;
IV116 at 0 range 11 .. 11;
IV115 at 0 range 12 .. 12;
IV114 at 0 range 13 .. 13;
IV113 at 0 range 14 .. 14;
IV112 at 0 range 15 .. 15;
IV111 at 0 range 16 .. 16;
IV110 at 0 range 17 .. 17;
IV109 at 0 range 18 .. 18;
IV108 at 0 range 19 .. 19;
IV107 at 0 range 20 .. 20;
IV106 at 0 range 21 .. 21;
IV105 at 0 range 22 .. 22;
IV104 at 0 range 23 .. 23;
IV103 at 0 range 24 .. 24;
IV102 at 0 range 25 .. 25;
IV101 at 0 range 26 .. 26;
IV100 at 0 range 27 .. 27;
IV99 at 0 range 28 .. 28;
IV98 at 0 range 29 .. 29;
IV97 at 0 range 30 .. 30;
IV96 at 0 range 31 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Cryptographic processor
type CRYP_Peripheral is record
-- control register
CR : aliased CR_Register;
-- status register
SR : aliased SR_Register;
-- data input register
DIN : aliased STM32_SVD.UInt32;
-- data output register
DOUT : aliased STM32_SVD.UInt32;
-- DMA control register
DMACR : aliased DMACR_Register;
-- interrupt mask set/clear register
IMSCR : aliased IMSCR_Register;
-- raw interrupt status register
RISR : aliased RISR_Register;
-- masked interrupt status register
MISR : aliased MISR_Register;
-- key registers
K0LR : aliased K0LR_Register;
-- key registers
K0RR : aliased K0RR_Register;
-- key registers
K1LR : aliased K1LR_Register;
-- key registers
K1RR : aliased K1RR_Register;
-- key registers
K2LR : aliased K2LR_Register;
-- key registers
K2RR : aliased K2RR_Register;
-- key registers
K3LR : aliased K3LR_Register;
-- key registers
K3RR : aliased K3RR_Register;
-- initialization vector registers
IV0LR : aliased IV0LR_Register;
-- initialization vector registers
IV0RR : aliased IV0RR_Register;
-- initialization vector registers
IV1LR : aliased IV1LR_Register;
-- initialization vector registers
IV1RR : aliased IV1RR_Register;
-- context swap register
CSGCMCCM0R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCMCCM1R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCMCCM2R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCMCCM3R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCMCCM4R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCMCCM5R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCMCCM6R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCMCCM7R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCM0R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCM1R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCM2R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCM3R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCM4R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCM5R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCM6R : aliased STM32_SVD.UInt32;
-- context swap register
CSGCM7R : aliased STM32_SVD.UInt32;
end record
with Volatile;
for CRYP_Peripheral use record
CR at 16#0# range 0 .. 31;
SR at 16#4# range 0 .. 31;
DIN at 16#8# range 0 .. 31;
DOUT at 16#C# range 0 .. 31;
DMACR at 16#10# range 0 .. 31;
IMSCR at 16#14# range 0 .. 31;
RISR at 16#18# range 0 .. 31;
MISR at 16#1C# range 0 .. 31;
K0LR at 16#20# range 0 .. 31;
K0RR at 16#24# range 0 .. 31;
K1LR at 16#28# range 0 .. 31;
K1RR at 16#2C# range 0 .. 31;
K2LR at 16#30# range 0 .. 31;
K2RR at 16#34# range 0 .. 31;
K3LR at 16#38# range 0 .. 31;
K3RR at 16#3C# range 0 .. 31;
IV0LR at 16#40# range 0 .. 31;
IV0RR at 16#44# range 0 .. 31;
IV1LR at 16#48# range 0 .. 31;
IV1RR at 16#4C# range 0 .. 31;
CSGCMCCM0R at 16#50# range 0 .. 31;
CSGCMCCM1R at 16#54# range 0 .. 31;
CSGCMCCM2R at 16#58# range 0 .. 31;
CSGCMCCM3R at 16#5C# range 0 .. 31;
CSGCMCCM4R at 16#60# range 0 .. 31;
CSGCMCCM5R at 16#64# range 0 .. 31;
CSGCMCCM6R at 16#68# range 0 .. 31;
CSGCMCCM7R at 16#6C# range 0 .. 31;
CSGCM0R at 16#70# range 0 .. 31;
CSGCM1R at 16#74# range 0 .. 31;
CSGCM2R at 16#78# range 0 .. 31;
CSGCM3R at 16#7C# range 0 .. 31;
CSGCM4R at 16#80# range 0 .. 31;
CSGCM5R at 16#84# range 0 .. 31;
CSGCM6R at 16#88# range 0 .. 31;
CSGCM7R at 16#8C# range 0 .. 31;
end record;
-- Cryptographic processor
CRYP_Periph : aliased CRYP_Peripheral
with Import, Address => CRYP_Base;
end STM32_SVD.CRYP;
|
Ximalas/synth | Ada | 1,904 | adb | -- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
with Ada.Text_IO;
with Ada.Characters.Latin_1;
package body Signals is
package TIO renames Ada.Text_IO;
package LAT renames Ada.Characters.Latin_1;
-----------------------------------
-- graceful_shutdown_requested --
-----------------------------------
function graceful_shutdown_requested return Boolean
is
caught_char : Character;
got_one : Boolean;
begin
TIO.Get_Immediate (Item => caught_char, Available => got_one);
-- Although the variable is called control_c, it's Control-Q that
-- we are catching. It was the ESCAPE key after control-C, but that
-- one was getting triggered by terminal ANSI codes. Control-Q
-- requires the IXON TTY flag off (disabled output flow control).
if got_one and then caught_char = LAT.DC1 then
control_c_break := True;
end if;
return control_c_break;
exception
when others => return control_c_break;
end graceful_shutdown_requested;
---------------------------------------
-- immediate_termination_requested --
---------------------------------------
function immediate_termination_requested return Boolean is
begin
return seriously_break;
end immediate_termination_requested;
-- ----------------------
-- -- Signal_Handler --
-- ----------------------
-- protected body Signal_Handler is
--
-- -------------------------
-- -- capture_control_c --
-- -------------------------
-- procedure capture_control_c is
-- begin
-- if control_c_break then
-- seriously_break := True;
-- else
-- control_c_break := True;
-- end if;
-- end capture_control_c;
--
-- end Signal_Handler;
end Signals;
|
melwyncarlo/ProjectEuler | Ada | 4,165 | adb | with Ada.Text_IO;
with Ada.Integer_Text_IO;
-- Copyright 2021 Melwyn Francis Carlo
procedure A049 is
use Ada.Text_IO;
use Ada.Integer_Text_IO;
-- File Reference: http://www.naturalnumbers.org/primes.html
N : constant Integer := 10;
FT : File_Type;
Last_Index : Natural;
Prime_Num : String (1 .. 10);
File_Name : constant String :=
"problems/003/PrimeNumbers_Upto_1000000";
Primes_Nums : array (Integer range 1 .. 1200,
Integer range 1 .. N) of Integer
:= (others => (others => 0));
Primes_Digits_Occurrences : array (Integer range 1 .. 1200) of Integer
:= (others => 0);
Prime_Digits : String (1 .. N) := (others => Character'Val (0));
Primes_Digits : array (Integer range 1 .. 1200) of String (1 .. N)
:= (others => (others => Character'Val (0)));
Duplicate_Found : Boolean;
I, J, K, L, M : Integer;
begin
I := 1;
Open (FT, In_File, File_Name);
while not End_Of_File (FT) loop
Get_Line (FT, Prime_Num, Last_Index);
if Integer'Value (Prime_Num (1 .. Last_Index)) >= 1000 then
if Integer'Value (Prime_Num (1 .. Last_Index)) <= 9999 then
Prime_Digits := "0000000000";
Prime_Digits (Integer'Value (Prime_Num (1 .. 1)) + 1) := '1';
Prime_Digits (Integer'Value (Prime_Num (2 .. 2)) + 1) := '1';
Prime_Digits (Integer'Value (Prime_Num (3 .. 3)) + 1) := '1';
Prime_Digits (Integer'Value (Prime_Num (4 .. 4)) + 1) := '1';
Duplicate_Found := False;
for J in 1 .. I loop
if Primes_Digits (J) = Prime_Digits then
if Primes_Nums (J, N) = 0 then
for K in 2 .. N loop
if Primes_Nums (J, K) = 0 then
Primes_Nums (J, K) := Integer'Value (
Prime_Num (1 .. Last_Index));
exit;
end if;
end loop;
Primes_Digits_Occurrences (J) :=
Primes_Digits_Occurrences (J) + 1;
end if;
Duplicate_Found := True;
exit;
end if;
end loop;
if not Duplicate_Found then
Primes_Digits_Occurrences (I) := 0;
Primes_Nums (I, 1) := Integer'Value (
Prime_Num (1 .. Last_Index));
Primes_Digits (I) := Prime_Digits;
I := I + 1;
end if;
end if;
end if;
end loop;
Close (FT);
J := 1;
K := 1;
L := 1;
M := 1;
J_Loop :
while J <= I loop
if Primes_Digits_Occurrences (J) >= 3 then
K := 1;
while K <= (N - 2) loop
if Primes_Nums (J, K) = 0 then
exit;
end if;
if Primes_Nums (J, K) /= 1487 then
L := K + 1;
while L <= (N - 1) loop
if Primes_Nums (J, L) = 0 then
exit;
end if;
M := L + 1;
while M <= N loop
if Primes_Nums (J, M) = 0 then
exit;
end if;
if (Primes_Nums (J, M) - Primes_Nums (J, L)) =
(Primes_Nums (J, L) - Primes_Nums (J, K))
then
exit J_Loop;
end if;
M := M + 1;
end loop;
L := L + 1;
end loop;
end if;
K := K + 1;
end loop;
end if;
J := J + 1;
end loop J_Loop;
Put (Primes_Nums (J, K), Width => 0);
Put (Primes_Nums (J, L), Width => 0);
Put (Primes_Nums (J, M), Width => 0);
end A049;
|
onox/orka | Ada | 5,190 | adb | -- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2017 onox <[email protected]>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with System;
with Interfaces.C.Strings;
with Ada.Unchecked_Deallocation;
with GL.API;
with GL.Enums.Getter;
package body GL.Debug is
Any : constant Low_Level.Enum := 16#1100#;
Current_Callback : Callback_Reference := null;
procedure Debug_Callback
(From : Source;
Kind : Message_Type;
ID : GL.Types.UInt;
Level : Severity;
Length : GL.Types.Size;
C_Message : C.Strings.chars_ptr;
Unused_User_Data : System.Address)
with Convention => StdCall;
procedure Debug_Callback
(From : Source;
Kind : Message_Type;
ID : GL.Types.UInt;
Level : Severity;
Length : GL.Types.Size;
C_Message : C.Strings.chars_ptr;
Unused_User_Data : System.Address)
is
Message : constant String := C.Strings.Value (C_Message, C.size_t (Length));
begin
if Current_Callback /= null then
Current_Callback (From, Kind, Level, ID, Message);
end if;
end Debug_Callback;
procedure Set_Message_Callback (Callback : not null Callback_Reference) is
begin
API.Debug_Message_Callback.Ref (Debug_Callback'Address, System.Null_Address);
Current_Callback := Callback;
end Set_Message_Callback;
procedure Disable_Message_Callback is
begin
API.Debug_Message_Callback.Ref (System.Null_Address, System.Null_Address);
Current_Callback := null;
end Disable_Message_Callback;
procedure Set (From : Source; Kind : Message_Type; Level : Severity;
Enabled : Boolean) is
Identifiers : Orka.Unsigned_32_Array (1 .. 0);
begin
API.Debug_Message_Control.Ref
(From, Kind, Level, 0, Identifiers, Low_Level.Bool (Enabled));
end Set;
procedure Set (Level : Severity; Enabled : Boolean) is
Identifiers : Orka.Unsigned_32_Array (1 .. 0);
begin
API.Debug_Message_Control_Level.Ref
(Any, Any, Level, 0, Identifiers, Low_Level.Bool (Enabled));
end Set;
procedure Set (From : Source; Kind : Message_Type; Identifiers : Orka.Unsigned_32_Array;
Enabled : Boolean) is
begin
API.Debug_Message_Control_Any_Level.Ref
(From, Kind, Any, Types.Size (Identifiers'Length),
Identifiers, Low_Level.Bool (Enabled));
end Set;
procedure Insert_Message (From : Source; Kind : Message_Type; Level : Severity;
Identifier : UInt; Message : String) is
begin
API.Debug_Message_Insert.Ref (From, Kind, Identifier, Level,
Types.Size (Message'Length), C.To_C (Message));
end Insert_Message;
function Push_Debug_Group (From : Source; Identifier : UInt; Message : String)
return Active_Group'Class is
begin
API.Push_Debug_Group.Ref (From, Identifier,
Types.Size (Message'Length), C.To_C (Message));
return Active_Group'(Ada.Finalization.Limited_Controlled with Finalized => False);
end Push_Debug_Group;
overriding
procedure Finalize (Object : in out Active_Group) is
begin
if not Object.Finalized then
API.Pop_Debug_Group.Ref.all;
Object.Finalized := True;
end if;
end Finalize;
procedure Annotate (Object : GL.Objects.GL_Object'Class; Message : String) is
begin
API.Object_Label.Ref
(Object.Identifier, Object.Raw_Id, Types.Size (Message'Length), C.To_C (Message));
end Annotate;
function Get_Label (Object : GL.Objects.GL_Object'Class) return String is
procedure Free is new Ada.Unchecked_Deallocation
(Object => Types.Size, Name => GL.Low_Level.Size_Access);
C_Size : GL.Low_Level.Size_Access := new Types.Size'(0);
Label_Size : Types.Size := 0;
begin
API.Get_Object_Label_Length.Ref
(Object.Identifier, Object.Raw_Id, 0,
C_Size, Interfaces.C.Strings.Null_Ptr);
-- Deallocate before potentially raising an exception
Label_Size := C_Size.all;
Free (C_Size);
if Label_Size = 0 then
return "";
end if;
declare
Label : String (1 .. Integer (Label_Size));
begin
API.Get_Object_Label.Ref
(Object.Identifier, Object.Raw_Id, Label_Size, Label_Size, Label);
return Label;
end;
end Get_Label;
function Max_Message_Length return Size is
Result : Int := 0;
begin
API.Get_Integer.Ref (Enums.Getter.Max_Debug_Message_Length, Result);
return Result;
end Max_Message_Length;
end GL.Debug;
|
reznikmm/matreshka | Ada | 3,693 | ads | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision: 3824 $ $Date: 2013-03-28 20:15:46 +0200 (Чт., 28 марта 2013) $
------------------------------------------------------------------------------
with League.Strings;
with League.JSON.Documents;
package Matreshka.JSON_Parser is
pragma Preelaborate;
procedure Parse
(Text : League.Strings.Universal_String;
Value : out League.JSON.Documents.JSON_Document;
Success : out Boolean);
end Matreshka.JSON_Parser;
|
stcarrez/ada-mail | Ada | 1,785 | ads | -----------------------------------------------------------------------
-- mgrep-matcher -- Print mail grep results
-- Copyright (C) 2020 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with GNAT.Regpat;
with Mail.Parsers;
with Mgrep.Printer;
package Mgrep.Matcher is
type Mail_Rule is limited record
Collector : Mgrep.Printer.Printer_Access;
Pattern : GNAT.Regpat.Pattern_Matcher (1000);
end record;
type Mail_Processor (Match : access Mail_Rule) is new Mail.Parsers.Processor with record
Print_Header : Boolean := True;
Header_Count : Natural := 0;
Line_Count : Natural := 0;
Match_Found : Boolean := False;
Result : Mgrep.Printer.Mail_Result_Access;
end record;
overriding
procedure New_Mail (Handler : in out Mail_Processor);
overriding
procedure Read_Header (Handler : in out Mail_Processor;
Name : in String;
Content : in String);
overriding
procedure Read_Body (Handler : in out Mail_Processor;
Line : in String);
end Mgrep.Matcher;
|
esbullington/aflex | Ada | 2,156 | ads | pragma Style_Checks (Off);
package Parse_Goto is
type Small_Integer is range -32_000 .. 32_000;
type Goto_Entry is record
Nonterm : Small_Integer;
Newstate : Small_Integer;
end record;
--pragma suppress(index_check);
subtype Row is Integer range -1 .. Integer'Last;
type Goto_Parse_Table is array (Row range <>) of Goto_Entry;
Goto_Matrix : constant Goto_Parse_Table :=
((-1,-1) -- Dummy Entry.
-- State 0
,(-3,1),(-2,2)
-- State 1
,(-4,3)
-- State 3
,(-8,10),(-5,9)
-- State 9
,(-6,13)
-- State 13
,(-7,16)
-- State 14
,(-9,17)
-- State 15
,(-10,22)
-- State 16
,(-19,33),(-18,31),(-17,29),(-16,30),(-13,25),(-12,23),(-11,39)
-- State 23
,(-19,33),(-18,31),(-17,29),(-16,30),(-13,43)
-- State 24
,(-19,33),(-18,31),(-17,29),(-16,30),(-13,46)
-- State 25
,(-14,48)
-- State 28
,(-15,51)
-- State 29
,(-19,33),(-18,31),(-16,54)
-- State 30
,(-19,33),(-18,55)
-- State 35
,(-20,60)
-- State 36
,(-19,33),(-18,31),(-17,29),(-16,30),(-13,61)
-- State 38
,(-21,62)
-- State 43
,(-14,66)
-- State 44
,(-19,33),(-18,31),(-17,29),(-16,30),(-13,67)
-- State 46
,(-14,68)
-- State 49
,(-19,33),(-18,31),(-16,69)
-- State 54
,(-19,33),(-18,55)
-- State 63
,(-21,78)
-- State 67
,(-14,79)
-- State 69
,(-19,33),(-18,55)
);
-- The offset vector
GOTO_OFFSET : array (0.. 88) of Integer :=
(0,
2,3,3,5,5,5,5,5,5,6,6,6,6,7,8,9,16,
16,16,16,16,16,16,21,26,27,27,27,28,31,33,33,33,33,
33,34,39,39,40,40,40,40,40,41,46,46,47,47,47,50,50,
50,50,50,52,52,52,52,52,52,52,52,52,53,53,53,53,54,
54,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,
56,56, 56);
subtype Rule is Natural;
subtype Nonterminal is Integer;
Rule_Length : array (Rule range 0 .. 55) of Natural := (2,
5,0,5,5,0,2,1,1,1,1,1,3,1,1,4,0,0,4,3,3,2,2,1,1,3,3,1,1,1,0,3,2,1,2,2,1,2,
2,2,6,5,4,1,1,1,3,3,1,3,4,4,2,0,2,0);
Get_LHS_Rule: array (Rule range 0 .. 55) of Nonterminal := (-1,
-2,-3,-4,-4,-4,-4,-10,-10,-5,-8,-8,-9,-9,-9,
-6,-6,-7,-11,-11,-11,-11,-11,-11,-11,-12,-15,-15,-15,
-14,-14,-13,-13,-13,-17,-16,-16,-18,-18,-18,-18,-18,-18,
-18,-18,-18,-18,-18,-18,-19,-19,-21,-21,-21,-20,-20);
end Parse_Goto;
|
persan/A-gst | Ada | 10,740 | ads | pragma Ada_2005;
pragma Style_Checks (Off);
pragma Warnings (Off);
with Interfaces.C; use Interfaces.C;
with glib;
with glib.Values;
with System;
with glib;
with System;
-- limited with GStreamer.GST_Low_Level.glib_2_0_glib_glist_h;
limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h;
limited with GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunernorm_h;
package GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tuner_h is
-- unsupported macro: GST_TYPE_TUNER (gst_tuner_get_type ())
-- arg-macro: function GST_TUNER (obj)
-- return GST_IMPLEMENTS_INTERFACE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_TUNER, GstTuner);
-- arg-macro: function GST_TUNER_CLASS (klass)
-- return G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_TUNER, GstTunerClass);
-- arg-macro: function GST_IS_TUNER (obj)
-- return GST_IMPLEMENTS_INTERFACE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_TUNER);
-- arg-macro: function GST_IS_TUNER_CLASS (klass)
-- return G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_TUNER);
-- arg-macro: function GST_TUNER_GET_CLASS (inst)
-- return G_TYPE_INSTANCE_GET_INTERFACE ((inst), GST_TYPE_TUNER, GstTunerClass);
-- GStreamer Tuner
-- * Copyright (C) 2003 Ronald Bultje <[email protected]>
-- *
-- * tuner.h: tuner interface design
-- *
-- * This library is free software; you can redistribute it and/or
-- * modify it under the terms of the GNU Library General Public
-- * License as published by the Free Software Foundation; either
-- * version 2 of the License, or (at your option) any later version.
-- *
-- * This library is distributed in the hope that it will be useful,
-- * but WITHOUT ANY WARRANTY; without even the implied warranty of
-- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- * Library General Public License for more details.
-- *
-- * You should have received a copy of the GNU Library General Public
-- * License along with this library; if not, write to the
-- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-- * Boston, MA 02111-1307, USA.
--
-- skipped empty struct u_GstTuner
-- skipped empty struct GstTuner
type GstTunerClass;
type u_GstTunerClass_u_gst_reserved_array is array (0 .. 3) of System.Address;
--subtype GstTunerClass is u_GstTunerClass; -- gst/interfaces/tuner.h:46
--*
-- * GstTunerClass:
-- * @klass: the parent interface
-- * @list_channels: list available channels
-- * @set_channel: set to a channel
-- * @get_channel: return the current channel
-- * @list_norms: list available norms
-- * @set_norm: set a norm
-- * @get_norm: return the current norm
-- * @set_frequency: set the frequency
-- * @get_frequency: return the current frequency
-- * @signal_strength: get the signal strength
-- * @channel_changed: default handler for channel changed notification
-- * @norm_changed: default handler for norm changed notification
-- * @frequency_changed: default handler for frequency changed notification
-- * @signal_changed: default handler for signal-strength changed notification
-- *
-- * Tuner interface.
--
type GstTunerClass is record
klass : aliased GStreamer.GST_Low_Level.glib_2_0_gobject_gtype_h.GTypeInterface; -- gst/interfaces/tuner.h:68
list_channels : access function (arg1 : System.Address) return access constant GStreamer.GST_Low_Level.glib_2_0_glib_glist_h.GList; -- gst/interfaces/tuner.h:71
set_channel : access procedure (arg1 : System.Address; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel); -- gst/interfaces/tuner.h:73
get_channel : access function (arg1 : System.Address) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel; -- gst/interfaces/tuner.h:75
list_norms : access function (arg1 : System.Address) return access constant GStreamer.GST_Low_Level.glib_2_0_glib_glist_h.GList; -- gst/interfaces/tuner.h:77
set_norm : access procedure (arg1 : System.Address; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunernorm_h.GstTunerNorm); -- gst/interfaces/tuner.h:79
get_norm : access function (arg1 : System.Address) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunernorm_h.GstTunerNorm; -- gst/interfaces/tuner.h:80
set_frequency : access procedure
(arg1 : System.Address;
arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel;
arg3 : GLIB.gulong); -- gst/interfaces/tuner.h:84
get_frequency : access function (arg1 : System.Address; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel) return GLIB.gulong; -- gst/interfaces/tuner.h:86
signal_strength : access function (arg1 : System.Address; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel) return GLIB.gint; -- gst/interfaces/tuner.h:88
channel_changed : access procedure (arg1 : System.Address; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel); -- gst/interfaces/tuner.h:92
norm_changed : access procedure (arg1 : System.Address; arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunernorm_h.GstTunerNorm); -- gst/interfaces/tuner.h:94
frequency_changed : access procedure
(arg1 : System.Address;
arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel;
arg3 : GLIB.gulong); -- gst/interfaces/tuner.h:97
signal_changed : access procedure
(arg1 : System.Address;
arg2 : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel;
arg3 : GLIB.gint); -- gst/interfaces/tuner.h:100
u_gst_reserved : u_GstTunerClass_u_gst_reserved_array; -- gst/interfaces/tuner.h:103
end record;
pragma Convention (C_Pass_By_Copy, GstTunerClass); -- gst/interfaces/tuner.h:67
-- virtual functions
-- signals
--< private >
function gst_tuner_get_type return GLIB.GType; -- gst/interfaces/tuner.h:106
pragma Import (C, gst_tuner_get_type, "gst_tuner_get_type");
-- virtual class function wrappers
function gst_tuner_list_channels (tuner : System.Address) return access constant GStreamer.GST_Low_Level.glib_2_0_glib_glist_h.GList; -- gst/interfaces/tuner.h:109
pragma Import (C, gst_tuner_list_channels, "gst_tuner_list_channels");
procedure gst_tuner_set_channel (tuner : System.Address; channel : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel); -- gst/interfaces/tuner.h:110
pragma Import (C, gst_tuner_set_channel, "gst_tuner_set_channel");
function gst_tuner_get_channel (tuner : System.Address) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel; -- gst/interfaces/tuner.h:113
pragma Import (C, gst_tuner_get_channel, "gst_tuner_get_channel");
function gst_tuner_list_norms (tuner : System.Address) return access constant GStreamer.GST_Low_Level.glib_2_0_glib_glist_h.GList; -- gst/interfaces/tuner.h:115
pragma Import (C, gst_tuner_list_norms, "gst_tuner_list_norms");
procedure gst_tuner_set_norm (tuner : System.Address; norm : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunernorm_h.GstTunerNorm); -- gst/interfaces/tuner.h:116
pragma Import (C, gst_tuner_set_norm, "gst_tuner_set_norm");
function gst_tuner_get_norm (tuner : System.Address) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunernorm_h.GstTunerNorm; -- gst/interfaces/tuner.h:118
pragma Import (C, gst_tuner_get_norm, "gst_tuner_get_norm");
procedure gst_tuner_set_frequency
(tuner : System.Address;
channel : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel;
frequency : GLIB.gulong); -- gst/interfaces/tuner.h:120
pragma Import (C, gst_tuner_set_frequency, "gst_tuner_set_frequency");
function gst_tuner_get_frequency (tuner : System.Address; channel : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel) return GLIB.gulong; -- gst/interfaces/tuner.h:123
pragma Import (C, gst_tuner_get_frequency, "gst_tuner_get_frequency");
function gst_tuner_signal_strength (tuner : System.Address; channel : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel) return GLIB.gint; -- gst/interfaces/tuner.h:125
pragma Import (C, gst_tuner_signal_strength, "gst_tuner_signal_strength");
-- helper functions
function gst_tuner_find_norm_by_name (tuner : System.Address; norm : access GLIB.gchar) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunernorm_h.GstTunerNorm; -- gst/interfaces/tuner.h:129
pragma Import (C, gst_tuner_find_norm_by_name, "gst_tuner_find_norm_by_name");
function gst_tuner_find_channel_by_name (tuner : System.Address; channel : access GLIB.gchar) return access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel; -- gst/interfaces/tuner.h:131
pragma Import (C, gst_tuner_find_channel_by_name, "gst_tuner_find_channel_by_name");
-- trigger signals
procedure gst_tuner_channel_changed (tuner : System.Address; channel : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel); -- gst/interfaces/tuner.h:135
pragma Import (C, gst_tuner_channel_changed, "gst_tuner_channel_changed");
procedure gst_tuner_norm_changed (tuner : System.Address; norm : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunernorm_h.GstTunerNorm); -- gst/interfaces/tuner.h:137
pragma Import (C, gst_tuner_norm_changed, "gst_tuner_norm_changed");
procedure gst_tuner_frequency_changed
(tuner : System.Address;
channel : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel;
frequency : GLIB.gulong); -- gst/interfaces/tuner.h:139
pragma Import (C, gst_tuner_frequency_changed, "gst_tuner_frequency_changed");
procedure gst_tuner_signal_changed
(tuner : System.Address;
channel : access GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tunerchannel_h.GstTunerChannel;
signal : GLIB.gint); -- gst/interfaces/tuner.h:142
pragma Import (C, gst_tuner_signal_changed, "gst_tuner_signal_changed");
end GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_tuner_h;
|
meowthsli/veriflight_boards | Ada | 465 | ads | with STM32.GPIO; use STM32.GPIO;
with STM32.Device; use STM32.Device;
with STM32.SPI; use STM32.SPI;
package Config is
SIGNAL_LED : GPIO_Point renames PB5; -- blue led
SPI_Accel_Port : SPI_Port renames STM32.Device.SPI_1;
SCLK : GPIO_Point renames STM32.Device.PA5;
MISO : GPIO_Point renames STM32.Device.PA6;
MOSI : GPIO_Point renames STM32.Device.PA7;
CS_ACCEL : GPIO_Point renames STM32.Device.PA4;
Disco : Boolean := False;
end Config;
|
zhmu/ananas | Ada | 3,227 | ads | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . P A C K _ 3 3 --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- 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. --
-- --
------------------------------------------------------------------------------
-- Handling of packed arrays with Component_Size = 33
package System.Pack_33 is
pragma Preelaborate;
Bits : constant := 33;
type Bits_33 is mod 2 ** Bits;
for Bits_33'Size use Bits;
-- In all subprograms below, Rev_SSO is set True if the array has the
-- non-default scalar storage order.
function Get_33
(Arr : System.Address;
N : Natural;
Rev_SSO : Boolean) return Bits_33 with Inline;
-- Arr is the address of the packed array, N is the zero-based
-- subscript. This element is extracted and returned.
procedure Set_33
(Arr : System.Address;
N : Natural;
E : Bits_33;
Rev_SSO : Boolean) with Inline;
-- Arr is the address of the packed array, N is the zero-based
-- subscript. This element is set to the given value.
end System.Pack_33;
|
kjseefried/web-ada | Ada | 539 | adb | with Ada.Calendar.Formatting;
with Ada.Calendar.Time_Zones;
with Ada.Text_IO;
with Web;
procedure test_time is
use type Ada.Calendar.Time;
use type Ada.Calendar.Time_Zones.Time_Offset;
S : constant String := Web.Image (Ada.Calendar.Clock);
begin
Ada.Text_IO.Put_Line (S);
if S /= Web.Image (Web.Value (S)) then
raise Program_Error;
end if;
if Web.Value ("Thu, 21 Jul 2005 14:46:19 +0900")
/= Ada.Calendar.Formatting.Time_Of (
2005, 7, 21, 14, 46, 19, Time_Zone => 9 * 60)
then
raise Program_Error;
end if;
end test_time;
|
reznikmm/matreshka | Ada | 4,616 | adb | ------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Open Document Toolkit --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014, Vadim Godunko <[email protected]> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Matreshka.DOM_Documents;
with Matreshka.ODF_String_Constants;
with ODF.DOM.Iterators;
with ODF.DOM.Visitors;
package body Matreshka.ODF_Style.Page_Usage_Attributes is
------------
-- Create --
------------
overriding function Create
(Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters)
return Style_Page_Usage_Attribute_Node is
begin
return Self : Style_Page_Usage_Attribute_Node do
Matreshka.ODF_Style.Constructors.Initialize
(Self'Unchecked_Access,
Parameters.Document,
Matreshka.ODF_String_Constants.Style_Prefix);
end return;
end Create;
--------------------
-- Get_Local_Name --
--------------------
overriding function Get_Local_Name
(Self : not null access constant Style_Page_Usage_Attribute_Node)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return Matreshka.ODF_String_Constants.Page_Usage_Attribute;
end Get_Local_Name;
begin
Matreshka.DOM_Documents.Register_Attribute
(Matreshka.ODF_String_Constants.Style_URI,
Matreshka.ODF_String_Constants.Page_Usage_Attribute,
Style_Page_Usage_Attribute_Node'Tag);
end Matreshka.ODF_Style.Page_Usage_Attributes;
|
jhumphry/aLua | Ada | 2,164 | ads | -- Lua.LibInternal
-- Contains the routines for loading the standard Lua library
-- Generated from lualib.h and then manually tidied up
-- Copyright (c) 2015, James Humphry
-- Derived from the original Lua work
-- Copyright (C) 1994-2015 Lua.org, PUC-Rio.
-- See LICENSE for details
with Interfaces.C; use Interfaces.C;
with System;
private package Lua.LibInternal is
function luaopen_base (arg1 : System.Address) return int; -- /usr/include/lualib.h:15
pragma Import (C, luaopen_base, "luaopen_base");
function luaopen_coroutine (arg1 : System.Address) return int; -- /usr/include/lualib.h:18
pragma Import (C, luaopen_coroutine, "luaopen_coroutine");
function luaopen_table (arg1 : System.Address) return int; -- /usr/include/lualib.h:21
pragma Import (C, luaopen_table, "luaopen_table");
function luaopen_io (arg1 : System.Address) return int; -- /usr/include/lualib.h:24
pragma Import (C, luaopen_io, "luaopen_io");
function luaopen_os (arg1 : System.Address) return int; -- /usr/include/lualib.h:27
pragma Import (C, luaopen_os, "luaopen_os");
function luaopen_string (arg1 : System.Address) return int; -- /usr/include/lualib.h:30
pragma Import (C, luaopen_string, "luaopen_string");
function luaopen_utf8 (arg1 : System.Address) return int; -- /usr/include/lualib.h:33
pragma Import (C, luaopen_utf8, "luaopen_utf8");
function luaopen_bit32 (arg1 : System.Address) return int; -- /usr/include/lualib.h:36
pragma Import (C, luaopen_bit32, "luaopen_bit32");
function luaopen_math (arg1 : System.Address) return int; -- /usr/include/lualib.h:39
pragma Import (C, luaopen_math, "luaopen_math");
function luaopen_debug (arg1 : System.Address) return int; -- /usr/include/lualib.h:42
pragma Import (C, luaopen_debug, "luaopen_debug");
function luaopen_package (arg1 : System.Address) return int; -- /usr/include/lualib.h:45
pragma Import (C, luaopen_package, "luaopen_package");
-- open all previous libraries
procedure luaL_openlibs (arg1 : System.Address); -- /usr/include/lualib.h:49
pragma Import (C, luaL_openlibs, "luaL_openlibs");
end Lua.LibInternal;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.